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