Salome HOME
Redesign SALOME documentation
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CopyMeshDlg.cxx
1 // Copyright (C) 2007-2016  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_CopyMeshDlg.cxx
23
24 #include "SMESHGUI_CopyMeshDlg.h"
25
26 #include "SMESHGUI.h"
27 #include "SMESHGUI_SpinBox.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_IdValidator.h"
32 #include "SMESHGUI_FilterDlg.h"
33
34 #include <SMESH_Actor.h>
35 #include <SMESH_TypeFilter.hxx>
36 #include <SMDS_Mesh.hxx>
37
38 // SALOME GUI includes
39 #include <SUIT_Desktop.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_OverrideCursor.h>
44
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50 #include <SALOME_ListIO.hxx>
51
52 // SALOME KERNEL includes
53 #include <SALOMEDSClient_SObject.hxx>
54
55 // OCCT includes
56 #include <TColStd_MapOfInteger.hxx>
57
58 // Qt includes
59 #include <QApplication>
60 #include <QButtonGroup>
61 #include <QGroupBox>
62 #include <QLabel>
63 #include <QLineEdit>
64 #include <QPushButton>
65 #include <QRadioButton>
66 #include <QCheckBox>
67 #include <QHBoxLayout>
68 #include <QVBoxLayout>
69 #include <QGridLayout>
70 #include <QSpinBox>
71 #include <QKeyEvent>
72
73 // IDL includes
74 #include <SALOMEconfig.h>
75 #include CORBA_SERVER_HEADER(SMESH_Group)
76 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
77
78 /*!
79   \class BusyLocker
80   \brief Simple 'busy state' flag locker.
81   \internal
82 */
83
84 namespace
85 {
86   class BusyLocker
87   {
88   public:
89     //! Constructor. Sets passed boolean flag to \c true.
90     BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
91     //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
92     ~BusyLocker() { myBusy = false; }
93   private:
94     bool& myBusy; //! External 'busy state' boolean flag
95   };
96 }
97
98 #define SPACING 6
99 #define MARGIN  11
100
101
102 //================================================================================
103 /*!
104  * \brief Constructor
105  */
106 //================================================================================
107
108 SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( SMESHGUI* theModule )
109   : QDialog( SMESH::GetDesktop( theModule ) ),
110     mySMESHGUI( theModule ),
111     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
112     mySelectedObject(SMESH::SMESH_IDSource::_nil()),
113     myFilterDlg(0),
114     myIsApplyAndClose( false )
115 {
116   QPixmap image (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_COPY_MESH")));
117
118   setModal(false);
119   setAttribute(Qt::WA_DeleteOnClose, true);
120   setWindowTitle(tr("SMESH_COPY_MESH_TITLE"));
121   setSizeGripEnabled(true);
122
123   QVBoxLayout* SMESHGUI_CopyMeshDlgLayout = new QVBoxLayout(this);
124   SMESHGUI_CopyMeshDlgLayout->setSpacing(SPACING);
125   SMESHGUI_CopyMeshDlgLayout->setMargin(MARGIN);
126
127   /***************************************************************/
128   ConstructorsBox = new QGroupBox(tr("SMESH_COPY_MESH_TITLE"), this);
129   QButtonGroup* GroupConstructors = new QButtonGroup(this);
130   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
131   ConstructorsBoxLayout->setSpacing(SPACING);
132   ConstructorsBoxLayout->setMargin(MARGIN);
133
134   QRadioButton* RadioButton1= new QRadioButton(ConstructorsBox);
135   RadioButton1->setIcon(image);
136   GroupConstructors->addButton(RadioButton1, 0);
137
138   ConstructorsBoxLayout->addWidget(RadioButton1);
139   RadioButton1->setChecked(true);
140   GroupConstructors->addButton(RadioButton1, 0);
141
142   /***************************************************************/
143   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
144   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
145   GroupArgumentsLayout->setSpacing(SPACING);
146   GroupArgumentsLayout->setMargin(MARGIN);
147
148   myIdValidator = new SMESHGUI_IdValidator(this);
149
150   // Controls for idSource/elements selection
151   myTextLabelElements = new QLabel(tr("OBJECT_NAME"), GroupArguments);
152   myLineEditElements = new QLineEdit(GroupArguments);
153   myLineEditElements->setValidator(myIdValidator);
154   myLineEditElements->setMaxLength(-1);
155   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
156   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
157
158   // Control for the mesh objects selection
159   myIdSourceCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
160
161   // Name of a mesh to create
162   QLabel* meshNameLabel = new QLabel(tr("NEW_NAME"), GroupArguments);
163   myMeshNameEdit = new QLineEdit(GroupArguments);
164
165   // CheckBox for copying groups
166   myCopyGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
167   myCopyGroupsCheck->setChecked(false);
168
169   // CheckBox for keeping ids ( OBSOLETE )
170   myKeepIdsCheck = new QCheckBox(tr("SMESH_KEEP_IDS"), GroupArguments);
171   myKeepIdsCheck->setChecked(true);
172   myKeepIdsCheck->hide();
173
174   // layout
175   GroupArgumentsLayout->addWidget(myTextLabelElements,  0, 0);
176   GroupArgumentsLayout->addWidget(myLineEditElements,   0, 1, 1, 5);
177   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 6);
178   GroupArgumentsLayout->addWidget(myIdSourceCheck,      1, 0, 1, 6);
179   GroupArgumentsLayout->addWidget(meshNameLabel,        2, 0);
180   GroupArgumentsLayout->addWidget(myMeshNameEdit,       2, 1, 1, 5);
181   GroupArgumentsLayout->addWidget(myCopyGroupsCheck,    3, 0, 1, 6);
182   // GroupArgumentsLayout->addWidget(myKeepIdsCheck,       4, 0, 1, 6);
183
184   /***************************************************************/
185   GroupButtons = new QGroupBox(this);
186   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
187   GroupButtonsLayout->setSpacing(SPACING);
188   GroupButtonsLayout->setMargin(MARGIN);
189
190   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
191   buttonOk->setAutoDefault(true);
192   buttonOk->setDefault(true);
193   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
194   buttonApply->setAutoDefault(true);
195   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
196   buttonCancel->setAutoDefault(true);
197   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
198   buttonHelp->setAutoDefault(true);
199
200   GroupButtonsLayout->addWidget(buttonOk);
201   GroupButtonsLayout->addSpacing(10);
202   GroupButtonsLayout->addWidget(buttonApply);
203   GroupButtonsLayout->addSpacing(10);
204   GroupButtonsLayout->addStretch();
205   GroupButtonsLayout->addWidget(buttonCancel);
206   GroupButtonsLayout->addWidget(buttonHelp);
207
208   /***************************************************************/
209   SMESHGUI_CopyMeshDlgLayout->addWidget(ConstructorsBox);
210   SMESHGUI_CopyMeshDlgLayout->addWidget(GroupArguments);
211   SMESHGUI_CopyMeshDlgLayout->addWidget(GroupButtons);
212
213   /* Initialisations */
214   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
215
216   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
217
218   // Selection filter
219   myIdSourceFilter = new SMESH_TypeFilter( SMESH::IDSOURCE );
220
221   myHelpFileName = "copy_mesh.html";
222
223   Init();
224
225   /* signals and slots connections */
226   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
227   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
228   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
229   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
230
231   connect(mySMESHGUI,     SIGNAL (SignalDeactivateActiveDialog()),
232           this,           SLOT   (DeactivateActiveDialog()));
233   connect(mySelectionMgr, SIGNAL (currentSelectionChanged()),
234           this,           SLOT   (SelectionIntoArgument()));
235   connect(mySMESHGUI,     SIGNAL (SignalCloseAllDialogs()),/* to close dialog if study change */
236           this,           SLOT   (reject()));
237   connect(mySMESHGUI,     SIGNAL (SignalActivatedViewManager()),
238           this,           SLOT   (onOpenView()));
239   connect(mySMESHGUI,     SIGNAL (SignalCloseView()),
240           this,           SLOT   (onCloseView()));
241
242   connect(myLineEditElements, SIGNAL(textChanged(const QString&)),
243           this,               SLOT  (onTextChange(const QString&)));
244   connect(myIdSourceCheck,    SIGNAL(toggled(bool)),
245           this,               SLOT  (onSelectIdSource(bool)));
246
247   SelectionIntoArgument();
248 }
249
250 //=================================================================================
251 // function : ~SMESHGUI_CopyMeshDlg()
252 // purpose  : Destroys the object and frees any allocated resources
253 //=================================================================================
254
255 SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg()
256 {
257   if ( myFilterDlg )
258   {
259     myFilterDlg->setParent( 0 );
260     delete myFilterDlg; myFilterDlg = 0;
261   }
262   if ( myIdSourceFilter )
263   {
264     if ( mySelectionMgr )
265       mySelectionMgr->removeFilter( myIdSourceFilter );
266     delete myIdSourceFilter; myIdSourceFilter=0;
267   }
268 }
269
270 //=================================================================================
271 // function : Init()
272 // purpose  :
273 //=================================================================================
274 void SMESHGUI_CopyMeshDlg::Init (bool ResetControls)
275 {
276   myBusy = false;
277
278   myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
279   if ( ResetControls )
280   {
281     myLineEditElements->clear();
282     //myElementsId = "";
283     myNbOkElements = 0;
284
285     buttonOk->setEnabled(false);
286     buttonApply->setEnabled(false);
287
288     myActor = 0;
289     myMesh = SMESH::SMESH_Mesh::_nil();
290
291     myIdSourceCheck->setChecked(true);
292     myCopyGroupsCheck->setChecked(false);
293     myKeepIdsCheck->setChecked(false);
294
295     onSelectIdSource( myIdSourceCheck->isChecked() );
296   }
297 }
298
299 //=================================================================================
300 // function : ClickOnApply()
301 // purpose  :
302 //=================================================================================
303
304 bool SMESHGUI_CopyMeshDlg::ClickOnApply()
305 {
306   if (mySMESHGUI->isActiveStudyLocked())
307     return false;
308
309   if( !isValid() )
310     return false;
311
312   QStringList anEntryList;
313   try
314   {
315     SUIT_OverrideCursor aWaitCursor;
316
317     SMESH::IDSource_wrap aPartToCopy;
318     if ( myIdSourceCheck->isChecked())
319     {
320       aPartToCopy = mySelectedObject;
321       aPartToCopy->Register();
322     }
323     else
324     {
325       QStringList aListElementsId = myLineEditElements->text().split(" ", QString::SkipEmptyParts);
326       SMESH::long_array_var anElementsId = new SMESH::long_array;
327       anElementsId->length(aListElementsId.count());
328       for (int i = 0; i < aListElementsId.count(); i++)
329         anElementsId[i] = aListElementsId[i].toInt();
330
331       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
332       aPartToCopy = aMeshEditor->MakeIDSource( anElementsId, SMESH::ALL );
333     }
334     QByteArray meshName = myMeshNameEdit->text().toLatin1();
335     bool toCopyGroups = ( myCopyGroupsCheck->isChecked() );
336     bool toKeepIDs    = ( myKeepIdsCheck->isChecked() );
337
338     SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
339     SMESH::SMESH_Mesh_var newMesh =
340       gen->CopyMesh(aPartToCopy, meshName.constData(), toCopyGroups, toKeepIDs);
341     if( !newMesh->_is_nil() )
342       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
343         anEntryList.append( aSObject->GetID().c_str() );
344   }
345   catch (...) {
346   }
347
348   mySMESHGUI->updateObjBrowser(true);
349   SMESHGUI::Modified();
350
351   if( LightApp_Application* anApp =
352       dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
353     anApp->browseObjects( anEntryList, isApplyAndClose() );
354
355   Init(false);
356   mySelectedObject = SMESH::SMESH_IDSource::_nil();
357   SelectionIntoArgument();
358
359   return true;
360 }
361
362 //=================================================================================
363 // function : ClickOnOk()
364 // purpose  :
365 //=================================================================================
366 void SMESHGUI_CopyMeshDlg::ClickOnOk()
367 {
368   setIsApplyAndClose( true );
369   if( ClickOnApply() )
370     reject();
371 }
372
373 //=================================================================================
374 // function : reject()
375 // purpose  :
376 //=================================================================================
377 void SMESHGUI_CopyMeshDlg::reject()
378 {
379   disconnect(mySelectionMgr, 0, this, 0);
380   if ( mySelectionMgr )
381     mySelectionMgr->removeFilter( myIdSourceFilter );
382   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
383     aViewWindow->SetSelectionMode( ActorSelection );
384   mySMESHGUI->ResetState();
385   QDialog::reject();
386 }
387
388 //=================================================================================
389 // function : onOpenView()
390 // purpose  :
391 //=================================================================================
392 void SMESHGUI_CopyMeshDlg::onOpenView()
393 {
394   if ( mySelector ) {
395     SMESH::SetPointRepresentation(false);
396   }
397   else {
398     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
399     ActivateThisDialog();
400   }
401 }
402
403 //=================================================================================
404 // function : onCloseView()
405 // purpose  :
406 //=================================================================================
407 void SMESHGUI_CopyMeshDlg::onCloseView()
408 {
409   DeactivateActiveDialog();
410   mySelector = 0;
411 }
412
413 //=================================================================================
414 // function : ClickOnHelp()
415 // purpose  :
416 //=================================================================================
417 void SMESHGUI_CopyMeshDlg::ClickOnHelp()
418 {
419   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
420   if (app)
421     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
422   else {
423     QString platform;
424 #ifdef WIN32
425     platform = "winapplication";
426 #else
427     platform = "application";
428 #endif
429     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
430                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
431                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
432                                                                  platform)).
433                              arg(myHelpFileName));
434   }
435 }
436
437 //=======================================================================
438 // function : onTextChange()
439 // purpose  :
440 //=======================================================================
441
442 void SMESHGUI_CopyMeshDlg::onTextChange (const QString& theNewText)
443 {
444   QLineEdit* send = (QLineEdit*)sender();
445
446   if (myBusy) return;
447   BusyLocker lock( myBusy );
448
449   //if (send == myLineEditElements)
450   myNbOkElements = 0;
451
452   buttonOk->setEnabled(false);
453   buttonApply->setEnabled(false);
454
455   // highlight entered elements
456   SMDS_Mesh* aMesh = 0;
457   if (myActor)
458     aMesh = myActor->GetObject()->GetMesh();
459
460   QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
461   if (myActor && aMesh)
462   {
463     TColStd_MapOfInteger newIndices;
464     if (send == myLineEditElements) {
465       for (int i = 0; i < aListId.count(); i++)
466         if ( const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt()))
467         {
468           newIndices.Add(e->GetID());
469         }
470     }
471     myNbOkElements = newIndices.Extent();
472
473     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
474     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
475     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
476       aViewWindow->highlight( anIO, true, true );
477   }
478   else
479   {
480     myNbOkElements = aListId.count();
481   }
482
483   if (myNbOkElements) {
484     buttonOk->setEnabled(true);
485     buttonApply->setEnabled(true);
486   }
487 }
488
489 //=================================================================================
490 // function : SelectionIntoArgument()
491 // purpose  : Called when selection as changed or other case
492 //=================================================================================
493
494 void SMESHGUI_CopyMeshDlg::SelectionIntoArgument()
495 {
496   if (myBusy) return;
497   if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
498   if (!GroupButtons->isEnabled()) return;              // inactive
499
500   BusyLocker lock( myBusy );
501
502   // clear
503   myActor = 0;
504   QString aString = "";
505
506   myLineEditElements->setText(aString);
507   myNbOkElements = 0;
508   buttonOk->setEnabled(false);
509   buttonApply->setEnabled(false);
510   myFilterBtn->setEnabled(false);
511
512   // get selected mesh
513   SALOME_ListIO aList;
514   mySelectionMgr->selectedObjects(aList);
515   int nbSel = aList.Extent();
516   if (nbSel != 1)
517     return;
518
519   Handle(SALOME_InteractiveObject) IO = aList.First();
520   mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
521   if ( mySelectedObject->_is_nil() )
522     return;
523
524   myMesh = SMESH::GetMeshByIO(IO);
525   if (myMesh->_is_nil())
526     return;
527
528   myActor = SMESH::FindActorByEntry(IO->getEntry());
529   if (!myActor)
530     myActor = SMESH::FindActorByObject(myMesh);
531
532   if (myIdSourceCheck->isChecked())
533   {
534     SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
535     if ( aString.isEmpty() ) aString = " ";
536     else                     aString = aString.trimmed(); // issue 0021327
537   }
538   else
539   {
540     SMESH::GetNameOfSelectedElements( mySelector, IO, aString );
541     myNbOkElements = aString.size();
542     myFilterBtn->setEnabled(true);
543   }
544   myLineEditElements->setText( aString );
545   bool ok = !aString.isEmpty();
546
547   buttonOk->setEnabled(ok);
548   buttonApply->setEnabled(ok);
549 }
550
551 //=======================================================================
552 //function : onSelectIdSource
553 //purpose  :
554 //=======================================================================
555 void SMESHGUI_CopyMeshDlg::onSelectIdSource (bool toSelectMesh)
556 {
557   if (toSelectMesh)
558     myTextLabelElements->setText(tr("OBJECT_NAME"));
559   else
560     myTextLabelElements->setText(tr("ELEM_IDS"));
561
562   if (toSelectMesh) {
563     myLineEditElements->clear();
564   }
565
566   mySelectionMgr->clearFilters();
567   mySelectionMgr->installFilter(myIdSourceFilter);
568   SMESH::SetPointRepresentation(false);
569
570   if (toSelectMesh) {
571     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
572       aViewWindow->SetSelectionMode( ActorSelection );
573     myLineEditElements->setReadOnly(true);
574     myLineEditElements->setValidator(0);
575   }
576   else
577   {
578     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
579       aViewWindow->SetSelectionMode( CellSelection );
580     myLineEditElements->setReadOnly(false);
581     myLineEditElements->setValidator(myIdValidator);
582     onTextChange(myLineEditElements->text());
583   }
584
585   SelectionIntoArgument();
586 }
587
588 //=================================================================================
589 // function : isValid
590 // purpose  :
591 //=================================================================================
592
593 bool SMESHGUI_CopyMeshDlg::isValid()
594 {
595   if ( myIdSourceCheck->isChecked() )
596     return !mySelectedObject->_is_nil();
597
598   return myNbOkElements > 0;
599 }
600
601 //=================================================================================
602 // function : DeactivateActiveDialog()
603 // purpose  :
604 //=================================================================================
605 void SMESHGUI_CopyMeshDlg::DeactivateActiveDialog()
606 {
607   if (ConstructorsBox->isEnabled()) {
608     ConstructorsBox->setEnabled(false);
609     GroupArguments->setEnabled(false);
610     GroupButtons->setEnabled(false);
611     mySMESHGUI->ResetState();
612     mySMESHGUI->SetActiveDialogBox(0);
613     if ( mySelectionMgr )
614       mySelectionMgr->removeFilter( myIdSourceFilter );
615   }
616 }
617
618 //=================================================================================
619 // function : ActivateThisDialog()
620 // purpose  :
621 //=================================================================================
622 void SMESHGUI_CopyMeshDlg::ActivateThisDialog()
623 {
624   /* Emit a signal to deactivate the active dialog */
625   mySMESHGUI->EmitSignalDeactivateDialog();
626   ConstructorsBox->setEnabled(true);
627   GroupArguments->setEnabled(true);
628   GroupButtons->setEnabled(true);
629
630   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
631
632   onSelectIdSource( myIdSourceCheck->isChecked() );
633
634   SelectionIntoArgument();
635 }
636
637
638 //=================================================================================
639 // function : enterEvent()
640 // purpose  :
641 //=================================================================================
642 void SMESHGUI_CopyMeshDlg::enterEvent (QEvent*)
643 {
644   if ( !ConstructorsBox->isEnabled() ) {
645     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
646     if ( aViewWindow && !mySelector ) {
647       mySelector = aViewWindow->GetSelector();
648     }
649     ActivateThisDialog();
650   }
651 }
652 //=================================================================================
653 // function : keyPressEvent()
654 // purpose  :
655 //=================================================================================
656 void SMESHGUI_CopyMeshDlg::keyPressEvent( QKeyEvent* e )
657 {
658   QDialog::keyPressEvent( e );
659   if ( e->isAccepted() )
660     return;
661
662   if ( e->key() == Qt::Key_F1 ) {
663     e->accept();
664     ClickOnHelp();
665   }
666 }
667
668 //=================================================================================
669 // function : setFilters()
670 // purpose  : SLOT. Called when "Filter" button pressed.
671 //=================================================================================
672 void SMESHGUI_CopyMeshDlg::setFilters()
673 {
674   if(myMesh->_is_nil()) {
675     SUIT_MessageBox::critical(this,
676                               tr("SMESH_ERROR"),
677                               tr("NO_MESH_SELECTED"));
678    return;
679   }
680   if ( !myFilterDlg )
681     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
682
683   QList<int> types;
684   if ( myMesh->NbEdges()     ) types << SMESH::EDGE;
685   if ( myMesh->NbFaces()     ) types << SMESH::FACE;
686   if ( myMesh->NbVolumes()   ) types << SMESH::VOLUME;
687   if ( myMesh->NbBalls()     ) types << SMESH::BALL;
688   if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
689   if ( types.count() > 1 )     types << SMESH::ALL;
690
691   myFilterDlg->Init( types );
692   myFilterDlg->SetSelection();
693   myFilterDlg->SetMesh( myMesh );
694   myFilterDlg->SetSourceWg( myLineEditElements );
695
696   myFilterDlg->show();
697 }
698
699 //================================================================
700 // function : setIsApplyAndClose
701 // Purpose  : Set value of the flag indicating that the dialog is
702 //            accepted by Apply & Close button
703 //================================================================
704 void SMESHGUI_CopyMeshDlg::setIsApplyAndClose( const bool theFlag )
705 {
706   myIsApplyAndClose = theFlag;
707 }
708
709 //================================================================
710 // function : isApplyAndClose
711 // Purpose  : Get value of the flag indicating that the dialog is
712 //            accepted by Apply & Close button
713 //================================================================
714 bool SMESHGUI_CopyMeshDlg::isApplyAndClose() const
715 {
716   return myIsApplyAndClose;
717 }