Salome HOME
restoring fam with old id
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MG_ADAPTDRIVER.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File : SMESHGUI_MG_ADAPTDRIVER.cxx
23
24 #include "SMESHGUI_MG_ADAPTDRIVER.h"
25
26 #include "SUIT_Desktop.h"
27 #include "SUIT_Application.h"
28 #include "SUIT_Session.h"
29
30 #include "SalomeApp_Application.h"
31 #include "SalomeApp_Module.h"
32 #include "SalomeApp_Study.h"
33
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Actor.h"
36 #include "SMESHGUI.h"
37 #include "SMESHGUI_FilterDlg.h"
38 #include "SMESHGUI_Selection.h"
39 #include <SUIT_MessageBox.h>
40 #include "SMESHGUI_IdValidator.h"
41 #include "SMESHGUI_Utils.h"
42 #include "SMESHGUI_MeshEditPreview.h"
43 #include "SMESHGUI_VTKUtils.h"
44 #include <SMESH_TypeFilter.hxx>
45 #include <SMESH_MeshAlgos.hxx>
46 #include <SMESH_LogicalFilter.hxx>
47 #include <SMDS_Mesh.hxx>
48 #include <SMDS_MeshNode.hxx>
49 #include "SMESHGUI_SpinBox.h"
50
51 #include <LightApp_SelectionMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
56 #include <SUIT_FileDlg.h>
57 #include "SMESHGUI_MeshUtils.h"
58
59
60 #include <QApplication>
61 #include <QButtonGroup>
62 #include <QGridLayout>
63 #include <QGroupBox>
64 #include <QHBoxLayout>
65 #include <QKeyEvent>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QCheckBox>
69 #include <QPushButton>
70 #include <QRadioButton>
71 #include <QTabWidget>
72 #include <QVBoxLayout>
73 #include <QDoubleSpinBox>
74 #include <QSpinBox>
75 #include <QTreeWidget>
76 #include <QTreeWidgetItem>
77 #include <QSpacerItem>
78 #include <QString>
79 #include <QHeaderView>
80 #include <QItemDelegate>
81 #include <QFileDialog>
82 #include <QMessageBox>
83 #include <QComboBox>
84
85 #include <vtkPoints.h>
86 #include <vtkUnstructuredGrid.h>
87 #include <vtkIdList.h>
88 #include <vtkCellArray.h>
89 #include <vtkUnsignedCharArray.h>
90 #include <vtkDataSetMapper.h>
91 #include <VTKViewer_CellLocationsArray.h>
92 #include <vtkProperty.h>
93
94 #include <ElCLib.hxx>
95 // SALOME KERNEL includes
96 #include <SALOMEDS_SComponent.hxx>
97 #include <SALOMEDS_SObject.hxx>
98 #include <SALOMEDS_Study.hxx>
99 #include <SALOMEDS_wrap.hxx>
100 #include "SalomeApp_Tools.h"
101 #include <SALOMEconfig.h>
102 #include <med.h>
103 #include <utilities.h>
104
105 #include <TCollection_AsciiString.hxx>
106
107 const int SPACING = 6;            // layout spacing
108 const int MARGIN  = 9;            // layout margin
109
110 SALOME_ListIO mySelected;
111
112
113 //================================================================
114 // Function : firstIObject
115 // Purpose  :  Return the first selected object in the selected object list
116 //================================================================
117 Handle(SALOME_InteractiveObject) firstIObject()
118 {
119     const SALOME_ListIO& aList = selectedIO();
120     return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
121 }
122 //================================================================
123 // Function : selectedIO
124 // Return the list of selected SALOME_InteractiveObject's
125 //================================================================
126 const SALOME_ListIO& selectedIO()
127 {
128     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
129     LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
130     if( aSelectionMgr )
131     {
132         aSelectionMgr->selectedObjects( mySelected );
133         for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
134             SCRUTE(it.Value()->getEntry());
135     };
136     return mySelected;
137 }
138 //================================================================
139 // Function : getStudy
140 // Returne un pointeur sur l'etude active
141 //================================================================
142 _PTR(Study) getStudy()
143 {
144     static _PTR(Study) _study;
145     if(!_study)
146         _study = SalomeApp_Application::getStudy();
147     return _study;
148 }
149
150 bool createAndPublishMed(QString fileName)
151 {
152
153     SMESH::DriverMED_ReadStatus res;
154     SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
155     // SMESHGUI aGui;
156
157     aMeshes = SMESHGUI::GetSMESHGen()->CreateMeshesFromMED( fileName.toUtf8().constData(), res );
158     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[0] );
159     _PTR(Study) aStudy = SMESH::getStudy();
160     QStringList anEntryList;
161     // bool isEmpty;
162     if ( aMeshSO ) {
163         _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
164         _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
165         aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
166         anEntryList.append( aMeshSO->GetID().c_str() );
167     }
168     else {
169         // isEmpty = true;
170         return false;
171     }
172     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
173
174     // browse to the published meshes
175     if( LightApp_Application* anApp =
176                 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
177         anApp->browseObjects( anEntryList );
178     return true;
179 }
180 bool createMgAdaptObject(MgAdapt *myMgAdapt )
181 {
182     // SMESH::SMESH_Mesh_var newMesh = SMESHGUI::GetSMESHGen()->CreateEmptyMesh();
183
184     // _PTR(SObject) aHypothesis;
185     _PTR(Study) aStudy = SMESH::getStudy();
186     QStringList anEntryList;
187     _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
188     _PTR(SComponent) mgadapt = aStudy->FindComponent("MG-ADAPT");
189     _PTR(GenericAttribute) ga;
190     if (!aBuilder->FindAttribute(mgadapt, ga, "AttributeName") )
191     {
192         mgadapt = aBuilder->NewComponent("MG-ADAPT");
193         _PTR(AttributeName) Name = aBuilder->FindOrCreateAttribute(mgadapt, "AttributeName");
194         Name->SetValue("MG-ADAPT");
195         _PTR(AttributePixMap) myPixmap = aBuilder->FindOrCreateAttribute( mgadapt, "AttributePixMap" );
196         myPixmap->SetPixMap( "ICON_MG_ADAPT" );
197         anEntryList.append( mgadapt->GetID().c_str() );
198     }
199
200     _PTR(SObject) obj =  aBuilder->NewObject(mgadapt);
201     _PTR(AttributeName) myName = aBuilder->FindOrCreateAttribute(obj, "AttributeName");
202     myName->SetValue("hypo");
203     _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( obj, "AttributePixMap" );
204     aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" );
205     anEntryList.append( obj->GetID().c_str() );
206
207     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
208
209     // // browse to the published meshes
210     if( LightApp_Application* anApp =
211                 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
212         anApp->browseObjects( anEntryList );
213     return true;
214 }
215
216
217 // MG ADAPT UTILS
218 //================================================================
219 // Function : IObjectCount
220 // Return the number of selected objects
221 //================================================================
222 int IObjectCount()
223 {
224     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
225     LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
226     if( aSelectionMgr )
227     {
228         aSelectionMgr->selectedObjects( mySelected );
229         SCRUTE(mySelected.Extent());
230         return mySelected.Extent();
231     }
232     return 0;
233 }
234
235
236 SMESHGUI_MG_AdaptComputeDlg_QThread::SMESHGUI_MG_AdaptComputeDlg_QThread(MgAdapt* aModel)
237 {
238     model = aModel;
239     myResult = -1;
240 }
241
242 void SMESHGUI_MG_AdaptComputeDlg_QThread::run()
243 {
244
245     int err;
246     std::string errStr;
247     errStr = model->compute(errStr);
248     std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+ errStr;
249     exec();
250 }
251
252 int SMESHGUI_MG_AdaptComputeDlg_QThread::result()
253 {
254     return myResult;
255 }
256
257 void SMESHGUI_MG_AdaptComputeDlg_QThread::cancel()
258 {
259     //~model->cancel();
260 }
261
262 SMESHGUI_MG_ADAPTDRIVER::SMESHGUI_MG_ADAPTDRIVER( SMESHGUI* theModule, MgAdapt* myModel, bool isCreation )
263     : mySMESHGUI( theModule ),
264       myFilterDlg(0),
265       myIsApplyAndClose( false ),
266       SMESHGUI_MgAdaptDlg((SalomeApp_Module*)theModule, myModel, SMESHGUI::desktop(), isCreation)
267 {
268
269     resMgr = resourceMgr();
270
271     selMgr = selectionMgr();
272
273     // connections
274     connect(myArgs, SIGNAL(updateSelection()), this, SLOT(updateSelection()));
275     connect(myArgs, SIGNAL(toExportMED(const char*)), this, SLOT(exportMED(const char*)));
276 }
277
278 SUIT_ResourceMgr* SMESHGUI_MG_ADAPTDRIVER::resourceMgr()
279 {
280     return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
281 }
282
283 LightApp_SelectionMgr* SMESHGUI_MG_ADAPTDRIVER::selectionMgr()
284 {
285     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
286     if( anApp )
287         return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
288     else
289         return 0;
290 }
291
292 void SMESHGUI_MG_ADAPTDRIVER::updateSelection()
293 {
294     disconnect( selMgr, 0, this, 0 );
295     selMgr->clearFilters();
296
297     SMESH::SetPointRepresentation( true );
298     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
299         aViewWindow->SetSelectionMode( ActorSelection );
300     if (myArgs->aBrowser->isChecked())
301     {
302         connect( selMgr,  SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
303         selectionChanged();
304     }
305
306 }
307 void SMESHGUI_MG_ADAPTDRIVER::selectionChanged()
308 {
309     //~ get selected mesh
310     SALOME_ListIO aList;
311     selMgr->selectedObjects(aList);
312     QString aString = "";
313     int nbSel = aList.Extent();
314     if (nbSel != 1)
315         return;
316
317     Handle(SALOME_InteractiveObject) IO = aList.First();
318     SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
319     if ( !mesh->_is_nil() )
320     {
321         myMesh  = mesh;
322
323         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
324         if ( mySelectedObject->_is_nil() )
325             return;
326
327     }
328     else
329         return;
330
331     SMESH::GetNameOfSelectedIObjects( selMgr, aString );
332     if ( aString.isEmpty() ) aString = " ";
333     else                     aString = aString.trimmed();
334
335
336     bool ok = !aString.isEmpty();
337     if ( !mesh->_is_nil() )
338     {
339         myArgs->aBrowserObject->setText( aString );
340         myArgs->meshNameLineEdit->setText( aString );
341         myArgs->selectOutMedFileLineEdit->setText(aString+QString(".med"));
342     }
343
344 }
345 void SMESHGUI_MG_ADAPTDRIVER::exportMED(const char* tmp_file)
346 {
347     bool toOverwrite  = true;
348     bool toFindOutDim = true;
349     myMesh->ExportMED(tmp_file, false, -1, toOverwrite, toFindOutDim);
350 }
351 void SMESHGUI_MG_ADAPTDRIVER::setMyMesh(SMESH::SMESH_Mesh_var mesh)
352 {
353     myMesh = mesh;
354 }
355 SMESH::SMESH_Mesh_var SMESHGUI_MG_ADAPTDRIVER::getMyMesh()
356 {
357     return myMesh;
358 }
359
360 //=================================================================================
361 // function : ClickOnOk()
362 // purpose  :
363 //=================================================================================
364 void SMESHGUI_MG_ADAPTDRIVER::clickOnOk()
365 {
366     setIsApplyAndClose( true );
367     clickOnApply();
368     reject();
369 }
370 bool SMESHGUI_MG_ADAPTDRIVER::clickOnApply()
371 {
372
373     if ( SMESHGUI::isStudyLocked() )
374         return false;
375     if( !isValid() )
376         return false;
377
378     SMESHGUI_MgAdaptDlg::clickOnApply();
379
380     bool ok = execute();
381     //~SMESHGUI_MG_AdaptComputeDlg_QThread atest(getModel());
382     //~atest.start();
383     //~atest.quit();
384     if (getModel()->getPublish()) this->createMeshInObjectBrowser();
385
386     return ok;
387 }
388
389 bool SMESHGUI_MG_ADAPTDRIVER::execute()
390 {
391
392     int err;
393     std::string errStr;
394     try
395     {
396         err = getModel()->compute(errStr);
397         std::string msg =  err == 0 ? " ok" : std::string("Not ok \n")+errStr ;
398     }
399     catch (const std::exception& e)
400     {
401         std::cerr<<e.what();
402     }
403     return err == 0? true: false;
404 }
405
406 //=================================================================================
407 // function : Init()
408 // purpose  :
409 //=================================================================================
410 void SMESHGUI_MG_ADAPTDRIVER::Init (bool ResetControls)
411 {
412     myBusy = false;
413
414     if ( ResetControls )
415     {
416         myLineEditElements->clear();
417         myNbOkElements = 0;
418
419         buttonOk->setEnabled(false);
420         buttonApply->setEnabled(false);
421
422         //~myActor = 0;
423         myMesh = SMESH::SMESH_Mesh::_nil();
424
425         myIdSourceCheck->setChecked(true);
426
427         onConstructor( 0 );
428     }
429
430 }
431
432 //=======================================================================
433 //function : onConstructor
434 //purpose  : switch operation mode
435 //=======================================================================
436
437 void SMESHGUI_MG_ADAPTDRIVER::onConstructor( int withGeom )
438 {
439
440     myGeomLabel        ->setVisible( withGeom );
441     myGeomNameEdit     ->setVisible( withGeom );
442     myReuseHypCheck    ->setVisible( withGeom );
443     myCopyElementsCheck->setVisible( withGeom );
444     myFilterBtn        ->setVisible( !withGeom );
445     myIdSourceCheck    ->setVisible( !withGeom );
446
447     if ( !withGeom )
448         myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
449
450 }
451
452
453 //~void SMESHGUI_MG_ADAPTDRIVER::onSelectIdSource( bool )
454 //~{}
455
456
457 //=================================================================================
458 // function : enterEvent()
459 // purpose  :
460 //=================================================================================
461 void SMESHGUI_MG_ADAPTDRIVER::enterEvent (QEvent*)
462 {
463
464     // if ( !ConstructorsBox->isEnabled() ) {
465     //   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
466     //   if ( aViewWindow && !mySelector ) {
467     //     mySelector = aViewWindow->GetSelector();
468     //   }
469     //   activateThisDialog();
470     // }
471
472 }
473
474 //=================================================================================
475 // function : keyPressEvent()
476 // purpose  :
477 //=================================================================================
478 void SMESHGUI_MG_ADAPTDRIVER::keyPressEvent( QKeyEvent* e )
479 {
480
481     QDialog::keyPressEvent( e );
482     if ( e->isAccepted() )
483         return;
484
485     if ( e->key() == Qt::Key_F1 ) {
486         e->accept();
487         clickOnHelp();
488     }
489
490 }
491
492 //=================================================================================
493 // function : clickOnHelp()
494 // purpose  :
495 //=================================================================================
496 void SMESHGUI_MG_ADAPTDRIVER::clickOnHelp()
497 {
498
499     LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
500     if (app)
501         app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
502     else {
503         QString platform;
504 #ifdef WIN32
505         platform = "winapplication";
506 #else
507         platform = "application";
508 #endif
509         SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
510                                  tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
511                                  arg(app->resourceMgr()->stringValue("ExternalBrowser",
512                                          platform)).
513                                  arg(myHelpFileName));
514     }
515
516 }
517
518 //=======================================================================
519 //function : getErrorMsg
520 //purpose  : Return an error message and entries of invalid smesh object
521 //=======================================================================
522
523 QString SMESHGUI_MG_ADAPTDRIVER::getErrorMsg( SMESH::string_array_var theInvalidEntries,
524         QStringList &           theEntriesToBrowse )
525 {
526
527     if ( theInvalidEntries->length() == 0 )
528         return tr("OPERATION_FAILED");
529
530     // theInvalidEntries - SObject's that hold geometry objects whose
531     // counterparts are not found in the newGeometry, followed by SObject's
532     // holding mesh sub-objects that are invalid because they depend on a not found
533     // preceding sub-shape
534
535     QString msg = tr("SUBSHAPES_NOT_FOUND_MSG") + "\n";
536
537     QString objString;
538     for ( CORBA::ULong i = 0; i < theInvalidEntries->length(); ++i )
539     {
540         _PTR(SObject) so = SMESH::getStudy()->FindObjectID( theInvalidEntries[i].in() );
541
542         int objType = SMESHGUI_Selection::type( theInvalidEntries[i].in() );
543         if ( objType < 0 ) // geom object
544         {
545             objString += "\n";
546             if ( so )
547                 objString += so->GetName().c_str();
548             else
549                 objString += theInvalidEntries[i].in(); // it's something like "FACE #2"
550         }
551         else // smesh object
552         {
553             theEntriesToBrowse.push_back( theInvalidEntries[i].in() );
554
555             objString += "\n   ";
556             switch ( objType ) {
557             case SMESH::MESH:
558                 objString += tr("SMESH_MESH");
559                 break;
560             case SMESH::HYPOTHESIS:
561                 objString += tr("SMESH_HYPOTHESIS");
562                 break;
563             case SMESH::ALGORITHM:
564                 objString += tr("SMESH_ALGORITHM");
565                 break;
566             case SMESH::SUBMESH_VERTEX:
567             case SMESH::SUBMESH_EDGE:
568             case SMESH::SUBMESH_FACE:
569             case SMESH::SUBMESH_SOLID:
570             case SMESH::SUBMESH_COMPOUND:
571             case SMESH::SUBMESH:
572                 objString += tr("SMESH_SUBMESH");
573                 break;
574             case SMESH::GROUP:
575                 objString += tr("SMESH_GROUP");
576                 break;
577             default:
578                 ;
579             }
580             objString += " \"";
581             if ( so )
582                 objString += so->GetName().c_str();
583             objString += "\" (";
584             objString += theInvalidEntries[i].in();
585             objString += ")";
586         }
587     }
588     if ( !objString.isEmpty() )
589         msg += objString;
590
591     return msg;
592 }
593
594 //=================================================================================
595 // function : isValid
596 // purpose  :
597 //=================================================================================
598
599 bool SMESHGUI_MG_ADAPTDRIVER::isValid()
600 {
601     bool ok = true;
602     return ok;
603 }
604
605 bool SMESHGUI_MG_ADAPTDRIVER::createMeshInObjectBrowser()
606 {
607     QString filename(getModel()->getMedFileOut().c_str());
608     QStringList errors;
609     QStringList anEntryList;
610     bool isEmpty = false;
611     bool ok = false;
612     SMESH::SMESH_Gen_var SMESH_Gen_ptr = SMESHGUI::GetSMESHGen();
613     if (!SMESH_Gen_ptr) {
614         std::cerr << "Could not retrieve SMESH_Gen_ptr" << std::endl;
615         throw SALOME_Exception(LOCALIZED("Could not retrieve SMESH::GetSMESHGen()"));
616     }
617     SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
618     aMeshes->length( 1 ); // one mesh only
619     SMESH::DriverMED_ReadStatus res;
620     aMeshes = SMESH_Gen_ptr->CreateMeshesFromMED( filename.toUtf8().constData(), res );
621     if ( res != SMESH::DRS_OK ) {
622         errors.append( QString( "%1 :\n\t%2" ).arg( filename ).arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
623     }
624     _PTR(Study) aStudy = SMESH::getStudy();
625     for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
626     {
627         _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
628         if ( aMeshSO ) {
629             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
630             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
631             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); // put REFINED mesh ico
632             anEntryList.append( aMeshSO->GetID().c_str() );
633         }
634         else {
635             isEmpty = true;
636         }
637     }
638     // update Object browser
639     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
640     // browse to the published meshes
641     if( LightApp_Application* anApp =
642                 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
643         anApp->browseObjects( anEntryList );
644
645     // show Error message box if there were errors
646     if ( errors.count() > 0 ) {
647         SUIT_MessageBox::critical( SMESHGUI::desktop(),
648                                    QObject::tr( "SMESH_ERROR" ),
649                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
650     }
651
652     // show warning message box, if some imported mesh is empty
653     if ( isEmpty ) {
654         SUIT_MessageBox::warning( SMESHGUI::desktop(),
655                                   QObject::tr( "SMESH_WRN_WARNING" ),
656                                   QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
657     }
658     return true;
659 }
660
661 //================================================================
662 // function : setIsApplyAndClose
663 // Purpose  : Set value of the flag indicating that the dialog is
664 //            accepted by Apply & Close button
665 //================================================================
666 void SMESHGUI_MG_ADAPTDRIVER::setIsApplyAndClose( const bool theFlag )
667 {
668     myIsApplyAndClose = theFlag;
669 }//================================================================
670 // function : isApplyAndClose
671 // Purpose  : Get value of the flag indicating that the dialog is
672 //            accepted by Apply & Close button
673 //================================================================
674 bool SMESHGUI_MG_ADAPTDRIVER::isApplyAndClose() const
675 {
676     return myIsApplyAndClose;
677 }
678
679 //=================================================================================
680 // function : DeactivateActiveDialog()
681 // purpose  :
682 //=================================================================================
683 void SMESHGUI_MG_ADAPTDRIVER::deactivateActiveDialog()
684 {
685
686     if (ConstructorsBox->isEnabled()) {
687         ConstructorsBox->setEnabled(false);
688         GroupArguments->setEnabled(false);
689         GroupButtons->setEnabled(false);
690         mySMESHGUI->ResetState();
691         mySMESHGUI->SetActiveDialogBox(0);
692         if ( selMgr )
693             selMgr->removeFilter( myIdSourceFilter );
694     }
695 }
696
697 //=================================================================================
698 // function : ActivateThisDialog()
699 // purpose  :
700 //=================================================================================
701 void SMESHGUI_MG_ADAPTDRIVER::activateThisDialog()
702 {
703
704     /* Emit a signal to deactivate the active dialog */
705     // mySMESHGUI->EmitSignalDeactivateDialog();
706     // ConstructorsBox->setEnabled(true);
707     // GroupArguments->setEnabled(true);
708     // GroupButtons->setEnabled(true);
709
710     // mySMESHGUI->SetActiveDialogBox((QDialog*)this);
711
712     // onSelectIdSource( myIdSourceCheck->isChecked() );
713
714     // SelectionIntoArgument();
715 }
716
717 //=================================================================================
718 // function : setFilters()
719 // purpose  : SLOT. Called when "Filter" button pressed.
720 //=================================================================================
721 void SMESHGUI_MG_ADAPTDRIVER::setFilters()
722 {
723     if(myMesh->_is_nil()) {
724         SUIT_MessageBox::critical(this,
725                                   tr("SMESH_ERROR"),
726                                   tr("NO_MESH_SELECTED"));
727         return;
728     }
729     if ( !myFilterDlg )
730         myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
731
732     QList<int> types;
733     if ( myMesh->NbEdges()     ) types << SMESH::EDGE;
734     if ( myMesh->NbFaces()     ) types << SMESH::FACE;
735     if ( myMesh->NbVolumes()   ) types << SMESH::VOLUME;
736     if ( myMesh->NbBalls()     ) types << SMESH::BALL;
737     if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
738     if ( types.count() > 1 )     types << SMESH::ALL;
739
740     myFilterDlg->Init( types );
741     myFilterDlg->SetSelection();
742     myFilterDlg->SetMesh( myMesh );
743     myFilterDlg->SetSourceWg( myLineEditElements );
744
745     myFilterDlg->show();
746 }
747
748 //=================================================================================
749 // function : onOpenView()
750 // purpose  :
751 //=================================================================================
752 void SMESHGUI_MG_ADAPTDRIVER::onOpenView()
753 {
754     if ( mySelector ) {
755         SMESH::SetPointRepresentation(false);
756     }
757     else {
758         mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
759         activateThisDialog();
760     }
761 }
762
763 //=================================================================================
764 // function : onCloseView()
765 // purpose  :
766 //=================================================================================
767 void SMESHGUI_MG_ADAPTDRIVER::onCloseView()
768 {
769     deactivateActiveDialog();
770     mySelector = 0;
771 }