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