Salome HOME
77ccb41d2010ab7ed225663ba020e98aa1bba044
[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   {
164     _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
165     _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
166     aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
167     anEntryList.append( aMeshSO->GetID().c_str() );
168   }
169   else
170   {
171       // isEmpty = true;
172       return false;
173   }
174   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
175
176   // browse to the published meshes
177   if( LightApp_Application* anApp =
178               dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
179       anApp->browseObjects( anEntryList );
180   return true;
181 }
182 bool createMgAdaptObject(MgAdapt *myMgAdapt )
183 {
184   // SMESH::SMESH_Mesh_var newMesh = SMESHGUI::GetSMESHGen()->CreateEmptyMesh();
185
186   // _PTR(SObject) aHypothesis;
187   _PTR(Study) aStudy = SMESH::getStudy();
188   QStringList anEntryList;
189   _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
190   _PTR(SComponent) mgadapt = aStudy->FindComponent("MG-ADAPT");
191   _PTR(GenericAttribute) ga;
192   if (!aBuilder->FindAttribute(mgadapt, ga, "AttributeName") )
193   {
194     mgadapt = aBuilder->NewComponent("MG-ADAPT");
195     _PTR(AttributeName) Name = aBuilder->FindOrCreateAttribute(mgadapt, "AttributeName");
196     Name->SetValue("MG-ADAPT");
197     _PTR(AttributePixMap) myPixmap = aBuilder->FindOrCreateAttribute( mgadapt, "AttributePixMap" );
198     myPixmap->SetPixMap( "ICON_MG_ADAPT" );
199     anEntryList.append( mgadapt->GetID().c_str() );
200   }
201
202   _PTR(SObject) obj = aBuilder->NewObject(mgadapt);
203   _PTR(AttributeName) myName = aBuilder->FindOrCreateAttribute(obj, "AttributeName");
204   myName->SetValue("hypo");
205   _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( obj, "AttributePixMap" );
206   aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" );
207   anEntryList.append( obj->GetID().c_str() );
208
209   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
210
211   // // browse to the published meshes
212   if( LightApp_Application* anApp =
213               dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
214       anApp->browseObjects( anEntryList );
215   return true;
216 }
217
218
219 // MG ADAPT UTILS
220 //================================================================
221 // Function : IObjectCount
222 // Return the number of selected objects
223 //================================================================
224 int IObjectCount()
225 {
226   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
227   LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
228   if( aSelectionMgr )
229   {
230       aSelectionMgr->selectedObjects( mySelected );
231       SCRUTE(mySelected.Extent());
232       return mySelected.Extent();
233   }
234   return 0;
235 }
236
237
238
239 SMESHGUI_MG_ADAPTDRIVER::SMESHGUI_MG_ADAPTDRIVER( SMESHGUI* theModule, SMESH::MG_ADAPT_ptr myModel, bool isCreation )
240   : mySMESHGUI( theModule ),
241     myFilterDlg(0),
242     myIsApplyAndClose( false ),
243     SMESHGUI_MgAdaptDlg((SalomeApp_Module*)theModule, myModel, SMESHGUI::desktop(), isCreation)
244 {
245
246   resMgr = resourceMgr();
247
248   selMgr = selectionMgr();
249
250   // connections
251   connect(myArgs, SIGNAL(updateSelection()), this, SLOT(updateSelection()));
252   connect(myArgs, SIGNAL(toExportMED(const char*)), this, SLOT(exportMED(const char*)));
253 }
254
255 SUIT_ResourceMgr* SMESHGUI_MG_ADAPTDRIVER::resourceMgr()
256 {
257   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
258 }
259
260 LightApp_SelectionMgr* SMESHGUI_MG_ADAPTDRIVER::selectionMgr()
261 {
262   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
263   if( anApp )
264     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
265   else
266     return 0;
267 }
268
269 void SMESHGUI_MG_ADAPTDRIVER::updateSelection()
270 {
271   disconnect( selMgr, 0, this, 0 );
272   selMgr->clearFilters();
273
274   SMESH::SetPointRepresentation( true );
275   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
276       aViewWindow->SetSelectionMode( ActorSelection );
277   if (myArgs->aBrowser->isChecked())
278   {
279     connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
280     selectionChanged();
281   }
282
283 }
284 void SMESHGUI_MG_ADAPTDRIVER::selectionChanged()
285 {
286   //~ get selected mesh
287   SALOME_ListIO aList;
288   selMgr->selectedObjects(aList);
289   QString aString = "";
290   int nbSel = aList.Extent();
291   if (nbSel != 1)
292     return;
293
294   Handle(SALOME_InteractiveObject) IO = aList.First();
295   SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
296   if ( !mesh->_is_nil() )
297   {
298     myMesh = mesh;
299
300     mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
301     if ( mySelectedObject->_is_nil() )
302         return;
303   }
304   else
305       return;
306
307   SMESH::GetNameOfSelectedIObjects( selMgr, aString );
308   if ( aString.isEmpty() ) aString = " ";
309   else                     aString = aString.trimmed();
310
311
312   bool ok = !aString.isEmpty();
313   if ( !mesh->_is_nil() )
314   {
315     myArgs->aBrowserObject->setText( aString );
316     myArgs->meshNameLineEdit->setText( aString );
317     myArgs->selectOutMedFileLineEdit->setText(aString+QString(".med"));
318     ADAPTATION_MODE aMode;
319     int nbVolumes = myMesh->NbVolumes();
320     int nbFaces = myMesh->NbFaces();
321     if(nbFaces > 0 && nbVolumes > 0) aMode = ADAPTATION_MODE::BOTH;
322     else if(nbFaces > 0) aMode = ADAPTATION_MODE::SURFACE;
323     else aMode = ADAPTATION_MODE::VOLUME;
324     emit myArgs->meshDimSignal(aMode);
325   }
326
327 }
328 void SMESHGUI_MG_ADAPTDRIVER::exportMED(const char* tmp_file)
329 {
330   bool toOverwrite = true;
331   bool toFindOutDim = true;
332   myMesh->ExportMED(tmp_file, false, -1, toOverwrite, toFindOutDim);
333 }
334 void SMESHGUI_MG_ADAPTDRIVER::setMyMesh(SMESH::SMESH_Mesh_var mesh)
335 {
336   myMesh = mesh;
337 }
338 SMESH::SMESH_Mesh_var SMESHGUI_MG_ADAPTDRIVER::getMyMesh()
339 {
340   return myMesh;
341 }
342
343 //=================================================================================
344 // function : ClickOnOk()
345 // purpose  :
346 //=================================================================================
347 void SMESHGUI_MG_ADAPTDRIVER::clickOnOk()
348 {
349   setIsApplyAndClose( true );
350   clickOnApply();
351   reject();
352 }
353 bool SMESHGUI_MG_ADAPTDRIVER::clickOnApply()
354 {
355
356   if ( SMESHGUI::isStudyLocked() )
357     return false;
358   if( !isValid() )
359     return false;
360
361   SMESHGUI_MgAdaptDlg::clickOnApply();
362
363   bool ok = execute();
364   if (getModel()->getPublish()) this->createMeshInObjectBrowser();
365
366   return ok;
367 }
368
369 bool SMESHGUI_MG_ADAPTDRIVER::execute()
370 {
371   int err;
372   //~std::string errStr;
373   char* errStr;
374   try
375   {
376     err = getModel()->compute();
377     errStr = getModel()->getErrMsg();
378     std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+CORBA::string_dup(errStr) ;
379   }
380   catch (const std::exception& e)
381   {
382     std::cerr<<e.what();
383   }
384   return err == 0? true: false;
385 }
386
387 //=================================================================================
388 // function : Init()
389 // purpose  :
390 //=================================================================================
391 void SMESHGUI_MG_ADAPTDRIVER::Init (bool ResetControls)
392 {
393   myBusy = false;
394
395   if ( ResetControls )
396   {
397     myLineEditElements->clear();
398     myNbOkElements = 0;
399
400     buttonOk->setEnabled(false);
401     buttonApply->setEnabled(false);
402
403     //~myActor = 0;
404     myMesh = SMESH::SMESH_Mesh::_nil();
405
406     myIdSourceCheck->setChecked(true);
407
408     onConstructor( 0 );
409   }
410
411 }
412
413 //=======================================================================
414 //function : onConstructor
415 //purpose  : switch operation mode
416 //=======================================================================
417
418 void SMESHGUI_MG_ADAPTDRIVER::onConstructor( int withGeom )
419 {
420
421   myGeomLabel        ->setVisible( withGeom );
422   myGeomNameEdit     ->setVisible( withGeom );
423   myReuseHypCheck    ->setVisible( withGeom );
424   myCopyElementsCheck->setVisible( withGeom );
425   myFilterBtn        ->setVisible( !withGeom );
426   myIdSourceCheck    ->setVisible( !withGeom );
427
428   if ( !withGeom )
429       myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
430
431 }
432
433 //~void SMESHGUI_MG_ADAPTDRIVER::onSelectIdSource( bool )
434 //~{}
435
436 //=================================================================================
437 // function : enterEvent()
438 // purpose  :
439 //=================================================================================
440 void SMESHGUI_MG_ADAPTDRIVER::enterEvent (QEvent*)
441 {
442
443   // if ( !ConstructorsBox->isEnabled() ) {
444   //   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
445   //   if ( aViewWindow && !mySelector ) {
446   //     mySelector = aViewWindow->GetSelector();
447   //   }
448   //   activateThisDialog();
449   // }
450
451 }
452
453 //=================================================================================
454 // function : keyPressEvent()
455 // purpose  :
456 //=================================================================================
457 void SMESHGUI_MG_ADAPTDRIVER::keyPressEvent( QKeyEvent* e )
458 {
459
460   QDialog::keyPressEvent( e );
461   if ( e->isAccepted() )
462       return;
463
464   if ( e->key() == Qt::Key_F1 )
465   {
466     e->accept();
467     clickOnHelp();
468   }
469
470 }
471
472 //=================================================================================
473 // function : clickOnHelp()
474 // purpose  :
475 //=================================================================================
476 void SMESHGUI_MG_ADAPTDRIVER::clickOnHelp()
477 {
478
479   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
480   if (app)
481     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
482   else {
483     QString platform;
484 #ifdef WIN32
485     platform = "winapplication";
486 #else
487     platform = "application";
488 #endif
489     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
490                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
491                               arg(app->resourceMgr()->stringValue("ExternalBrowser",platform)).
492                               arg(myHelpFileName));
493   }
494
495 }
496
497 //=======================================================================
498 //function : getErrorMsg
499 //purpose  : Return an error message and entries of invalid smesh object
500 //=======================================================================
501
502 QString SMESHGUI_MG_ADAPTDRIVER::getErrorMsg( SMESH::string_array_var theInvalidEntries,
503         QStringList & theEntriesToBrowse )
504 {
505
506   if ( theInvalidEntries->length() == 0 )
507       return tr("OPERATION_FAILED");
508
509   // theInvalidEntries - SObject's that hold geometry objects whose
510   // counterparts are not found in the newGeometry, followed by SObject's
511   // holding mesh sub-objects that are invalid because they depend on a not found
512   // preceding sub-shape
513
514   QString msg = tr("SUBSHAPES_NOT_FOUND_MSG") + "\n";
515
516   QString objString;
517   for ( CORBA::ULong i = 0; i < theInvalidEntries->length(); ++i )
518   {
519     _PTR(SObject) so = SMESH::getStudy()->FindObjectID( theInvalidEntries[i].in() );
520
521     int objType = SMESHGUI_Selection::type( theInvalidEntries[i].in() );
522     if ( objType < 0 ) // geom object
523     {
524       objString += "\n";
525       if ( so )
526           objString += so->GetName().c_str();
527       else
528           objString += theInvalidEntries[i].in(); // it's something like "FACE #2"
529     }
530     else // smesh object
531     {
532       theEntriesToBrowse.push_back( theInvalidEntries[i].in() );
533
534       objString += "\n ";
535       switch ( objType ) {
536       case SMESH::MESH:
537           objString += tr("SMESH_MESH");
538           break;
539       case SMESH::HYPOTHESIS:
540           objString += tr("SMESH_HYPOTHESIS");
541           break;
542       case SMESH::ALGORITHM:
543           objString += tr("SMESH_ALGORITHM");
544           break;
545       case SMESH::SUBMESH_VERTEX:
546       case SMESH::SUBMESH_EDGE:
547       case SMESH::SUBMESH_FACE:
548       case SMESH::SUBMESH_SOLID:
549       case SMESH::SUBMESH_COMPOUND:
550       case SMESH::SUBMESH:
551           objString += tr("SMESH_SUBMESH");
552           break;
553       case SMESH::GROUP:
554           objString += tr("SMESH_GROUP");
555           break;
556       default:
557           ;
558       }
559       objString += " \"";
560       if ( so )
561           objString += so->GetName().c_str();
562       objString += "\" (";
563       objString += theInvalidEntries[i].in();
564       objString += ")";
565     }
566   }
567   if ( !objString.isEmpty() )
568       msg += objString;
569
570   return msg;
571 }
572
573 //=================================================================================
574 // function : isValid
575 // purpose  :
576 //=================================================================================
577
578 bool SMESHGUI_MG_ADAPTDRIVER::isValid()
579 {
580   bool ok = true;
581   return ok;
582 }
583
584 bool SMESHGUI_MG_ADAPTDRIVER::createMeshInObjectBrowser()
585 {
586   QString filename(getModel()->getMedFileOut());
587   QStringList errors;
588   QStringList anEntryList;
589   bool isEmpty = false;
590   bool ok = false;
591   SMESH::SMESH_Gen_var SMESH_Gen_ptr = SMESHGUI::GetSMESHGen();
592   if (!SMESH_Gen_ptr) {
593     std::cerr << "Could not retrieve SMESH_Gen_ptr" << std::endl;
594     throw SALOME_Exception(LOCALIZED("Could not retrieve SMESH::GetSMESHGen()"));
595   }
596   SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
597   aMeshes->length( 1 ); // one mesh only
598   SMESH::DriverMED_ReadStatus res;
599   aMeshes = SMESH_Gen_ptr->CreateMeshesFromMED( filename.toUtf8().constData(), res );
600   if ( res != SMESH::DRS_OK ) {
601     errors.append( QString( "%1 :\n\t%2" ).arg( filename ).arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
602   }
603   _PTR(Study) aStudy = SMESH::getStudy();
604   for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
605   {
606     _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
607     if ( aMeshSO )
608     {
609       _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
610       _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
611       aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); // put REFINED mesh ico
612       anEntryList.append( aMeshSO->GetID().c_str() );
613     }
614     else
615     {
616       isEmpty = true;
617     }
618   }
619   // update Object browser
620   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
621   // browse to the published meshes
622   if( LightApp_Application* anApp =
623               dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
624       anApp->browseObjects( anEntryList );
625
626   // show Error message box if there were errors
627   if ( errors.count() > 0 ) {
628     SUIT_MessageBox::critical( SMESHGUI::desktop(),
629                                 QObject::tr( "SMESH_ERROR" ),
630                                 QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
631   }
632
633   // show warning message box, if some imported mesh is empty
634   if ( isEmpty ) {
635     SUIT_MessageBox::warning( SMESHGUI::desktop(),
636                                 QObject::tr( "SMESH_WRN_WARNING" ),
637                                 QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
638   }
639   return true;
640 }
641
642 //================================================================
643 // function : setIsApplyAndClose
644 // Purpose  : Set value of the flag indicating that the dialog is
645 //            accepted by Apply & Close button
646 //================================================================
647 void SMESHGUI_MG_ADAPTDRIVER::setIsApplyAndClose( const bool theFlag )
648 {
649   myIsApplyAndClose = theFlag;
650 }//================================================================
651 // function : isApplyAndClose
652 // Purpose  : Get value of the flag indicating that the dialog is
653 //            accepted by Apply & Close button
654 //================================================================
655 bool SMESHGUI_MG_ADAPTDRIVER::isApplyAndClose() const
656 {
657   return myIsApplyAndClose;
658 }
659
660 //=================================================================================
661 // function : DeactivateActiveDialog()
662 // purpose  :
663 //=================================================================================
664 void SMESHGUI_MG_ADAPTDRIVER::deactivateActiveDialog()
665 {
666   if (ConstructorsBox->isEnabled())
667   {
668     ConstructorsBox->setEnabled(false);
669     GroupArguments->setEnabled(false);
670     GroupButtons->setEnabled(false);
671     mySMESHGUI->ResetState();
672     mySMESHGUI->SetActiveDialogBox(0);
673     if ( selMgr )
674         selMgr->removeFilter( myIdSourceFilter );
675   }
676 }
677
678 //=================================================================================
679 // function : ActivateThisDialog()
680 // purpose  :
681 //=================================================================================
682 void SMESHGUI_MG_ADAPTDRIVER::activateThisDialog()
683 {
684
685   /* Emit a signal to deactivate the active dialog */
686   // mySMESHGUI->EmitSignalDeactivateDialog();
687   // ConstructorsBox->setEnabled(true);
688   // GroupArguments->setEnabled(true);
689   // GroupButtons->setEnabled(true);
690
691   // mySMESHGUI->SetActiveDialogBox((QDialog*)this);
692
693   // onSelectIdSource( myIdSourceCheck->isChecked() );
694
695   // SelectionIntoArgument();
696 }
697
698 //=================================================================================
699 // function : setFilters()
700 // purpose  : SLOT. Called when "Filter" button pressed.
701 //=================================================================================
702 void SMESHGUI_MG_ADAPTDRIVER::setFilters()
703 {
704   if(myMesh->_is_nil())
705   {
706     SUIT_MessageBox::critical(this,
707                                 tr("SMESH_ERROR"),
708                                 tr("NO_MESH_SELECTED"));
709     return;
710   }
711   if ( !myFilterDlg )
712       myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
713
714   QList<int> types;
715   if ( myMesh->NbEdges()     ) types << SMESH::EDGE;
716   if ( myMesh->NbFaces()     ) types << SMESH::FACE;
717   if ( myMesh->NbVolumes()   ) types << SMESH::VOLUME;
718   if ( myMesh->NbBalls()     ) types << SMESH::BALL;
719   if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
720   if ( types.count() > 1 )     types << SMESH::ALL;
721
722   myFilterDlg->Init( types );
723   myFilterDlg->SetSelection();
724   myFilterDlg->SetMesh( myMesh );
725   myFilterDlg->SetSourceWg( myLineEditElements );
726
727   myFilterDlg->show();
728 }
729
730 //=================================================================================
731 // function : onOpenView()
732 // purpose  :
733 //=================================================================================
734 void SMESHGUI_MG_ADAPTDRIVER::onOpenView()
735 {
736   if ( mySelector ) {
737     SMESH::SetPointRepresentation(false);
738   }
739   else {
740     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
741     activateThisDialog();
742   }
743 }
744
745 //=================================================================================
746 // function : onCloseView()
747 // purpose  :
748 //=================================================================================
749 void SMESHGUI_MG_ADAPTDRIVER::onCloseView()
750 {
751   deactivateActiveDialog();
752   mySelector = 0;
753 }