Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CopyMeshDlg.cxx
1 // Copyright (C) 2007-2013  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 //  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 //To disable automatic genericobj management, the following line should be commented.
102 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
103 #define WITHGENERICOBJ
104
105
106 //================================================================================
107 /*!
108  * \brief Constructor
109  */
110 //================================================================================
111
112 SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( SMESHGUI* theModule )
113   : QDialog( SMESH::GetDesktop( theModule ) ),
114     mySMESHGUI( theModule ),
115     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
116     myFilterDlg(0),
117     mySelectedObject(SMESH::SMESH_IDSource::_nil()),
118     myIsApplyAndClose( false )
119 {
120   QPixmap image (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_COPY_MESH")));
121
122   setModal(false);
123   setAttribute(Qt::WA_DeleteOnClose, true);
124   setWindowTitle(tr("SMESH_COPY_MESH_TITLE"));
125   setSizeGripEnabled(true);
126
127   QVBoxLayout* SMESHGUI_CopyMeshDlgLayout = new QVBoxLayout(this);
128   SMESHGUI_CopyMeshDlgLayout->setSpacing(SPACING);
129   SMESHGUI_CopyMeshDlgLayout->setMargin(MARGIN);
130
131   /***************************************************************/
132   ConstructorsBox = new QGroupBox(tr("SMESH_COPY_MESH_TITLE"), this);
133   QButtonGroup* GroupConstructors = new QButtonGroup(this);
134   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
135   ConstructorsBoxLayout->setSpacing(SPACING);
136   ConstructorsBoxLayout->setMargin(MARGIN);
137
138   QRadioButton* RadioButton1= new QRadioButton(ConstructorsBox);
139   RadioButton1->setIcon(image);
140   GroupConstructors->addButton(RadioButton1, 0);
141
142   ConstructorsBoxLayout->addWidget(RadioButton1);
143   RadioButton1->setChecked(true);
144   GroupConstructors->addButton(RadioButton1, 0);
145
146   /***************************************************************/
147   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149   GroupArgumentsLayout->setSpacing(SPACING);
150   GroupArgumentsLayout->setMargin(MARGIN);
151
152   myIdValidator = new SMESHGUI_IdValidator(this);
153
154   // Controls for idSource/elements selection
155   myTextLabelElements = new QLabel(tr("OBJECT_NAME"), GroupArguments);
156   myLineEditElements = new QLineEdit(GroupArguments);
157   myLineEditElements->setValidator(myIdValidator);
158   myLineEditElements->setMaxLength(-1);
159   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
160   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
161
162   // Control for the mesh objects selection
163   myIdSourceCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
164
165   // Name of a mesh to create
166   QLabel* meshNameLabel = new QLabel(tr("NEW_NAME"), GroupArguments);
167   myMeshNameEdit = new QLineEdit(GroupArguments);
168
169   // CheckBox for copying groups
170   myCopyGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
171   myCopyGroupsCheck->setChecked(false);
172
173   // CheckBox for keeping ids
174   myKeepIdsCheck = new QCheckBox(tr("SMESH_KEEP_IDS"), GroupArguments);
175   myKeepIdsCheck->setChecked(true);
176
177   // layout
178   GroupArgumentsLayout->addWidget(myTextLabelElements,  0, 0);
179   GroupArgumentsLayout->addWidget(myLineEditElements,   0, 1, 1, 5);
180   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 6);
181   GroupArgumentsLayout->addWidget(myIdSourceCheck,      1, 0, 1, 6);
182   GroupArgumentsLayout->addWidget(meshNameLabel,        2, 0);
183   GroupArgumentsLayout->addWidget(myMeshNameEdit,       2, 1, 1, 5);
184   GroupArgumentsLayout->addWidget(myCopyGroupsCheck,    3, 0, 1, 6);
185   GroupArgumentsLayout->addWidget(myKeepIdsCheck,       4, 0, 1, 6);
186
187   /***************************************************************/
188   GroupButtons = new QGroupBox(this);
189   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
190   GroupButtonsLayout->setSpacing(SPACING);
191   GroupButtonsLayout->setMargin(MARGIN);
192
193   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
194   buttonOk->setAutoDefault(true);
195   buttonOk->setDefault(true);
196   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
197   buttonApply->setAutoDefault(true);
198   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
199   buttonCancel->setAutoDefault(true);
200   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
201   buttonHelp->setAutoDefault(true);
202
203   GroupButtonsLayout->addWidget(buttonOk);
204   GroupButtonsLayout->addSpacing(10);
205   GroupButtonsLayout->addWidget(buttonApply);
206   GroupButtonsLayout->addSpacing(10);
207   GroupButtonsLayout->addStretch();
208   GroupButtonsLayout->addWidget(buttonCancel);
209   GroupButtonsLayout->addWidget(buttonHelp);
210
211   /***************************************************************/
212   SMESHGUI_CopyMeshDlgLayout->addWidget(ConstructorsBox);
213   SMESHGUI_CopyMeshDlgLayout->addWidget(GroupArguments);
214   SMESHGUI_CopyMeshDlgLayout->addWidget(GroupButtons);
215
216   /* Initialisations */
217   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
218
219   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
220
221   // Selection filter
222   myIdSourceFilter = new SMESH_TypeFilter( SMESH::IDSOURCE );
223
224   myHelpFileName = "copy_mesh_page.html";
225
226   Init();
227
228   /* signals and slots connections */
229   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
230   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
231   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
232   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
233
234   connect(mySMESHGUI,     SIGNAL (SignalDeactivateActiveDialog()),
235           this,           SLOT   (DeactivateActiveDialog()));
236   connect(mySelectionMgr, SIGNAL (currentSelectionChanged()),
237           this,           SLOT   (SelectionIntoArgument()));
238   connect(mySMESHGUI,     SIGNAL (SignalCloseAllDialogs()),/* to close dialog if study change */
239           this,           SLOT   (reject()));
240
241   connect(myLineEditElements, SIGNAL(textChanged(const QString&)),
242           this,               SLOT  (onTextChange(const QString&)));
243   connect(myIdSourceCheck,    SIGNAL(toggled(bool)),
244           this,               SLOT  (onSelectIdSource(bool)));
245
246   SelectionIntoArgument();
247 }
248
249 //=================================================================================
250 // function : ~SMESHGUI_CopyMeshDlg()
251 // purpose  : Destroys the object and frees any allocated resources
252 //=================================================================================
253
254 SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg()
255 {
256   if ( myFilterDlg )
257   {
258     myFilterDlg->setParent( 0 );
259     delete myFilterDlg; myFilterDlg = 0;
260   }
261   if ( myIdSourceFilter )
262   {
263     if ( mySelectionMgr )
264       mySelectionMgr->removeFilter( myIdSourceFilter );
265     delete myIdSourceFilter; myIdSourceFilter=0;
266   }
267 }
268
269 //=================================================================================
270 // function : Init()
271 // purpose  :
272 //=================================================================================
273 void SMESHGUI_CopyMeshDlg::Init (bool ResetControls)
274 {
275   myBusy = false;
276
277   myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
278   if ( ResetControls )
279   {
280     myLineEditElements->clear();
281     //myElementsId = "";
282     myNbOkElements = 0;
283
284     buttonOk->setEnabled(false);
285     buttonApply->setEnabled(false);
286
287     myActor = 0;
288     myMesh = SMESH::SMESH_Mesh::_nil();
289
290     myIdSourceCheck->setChecked(true);
291     myCopyGroupsCheck->setChecked(false);
292     myKeepIdsCheck->setChecked(false);
293
294     onSelectIdSource( myIdSourceCheck->isChecked() );
295   }
296 }
297
298 //=================================================================================
299 // function : ClickOnApply()
300 // purpose  :
301 //=================================================================================
302
303 bool SMESHGUI_CopyMeshDlg::ClickOnApply()
304 {
305   if (mySMESHGUI->isActiveStudyLocked())
306     return false;
307
308   if( !isValid() )
309     return false;
310
311   QStringList anEntryList;
312   try
313   {
314     SUIT_OverrideCursor aWaitCursor;
315     SMESH::SMESH_IDSource_var aPartToCopy;
316     if ( myIdSourceCheck->isChecked())
317     {
318       aPartToCopy = mySelectedObject;
319     }
320     else
321     {
322       QStringList aListElementsId = myLineEditElements->text().split(" ", QString::SkipEmptyParts);
323       SMESH::long_array_var anElementsId = new SMESH::long_array;
324       anElementsId->length(aListElementsId.count());
325       for (int i = 0; i < aListElementsId.count(); i++)
326         anElementsId[i] = aListElementsId[i].toInt();
327
328       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
329       aPartToCopy = aMeshEditor->MakeIDSource( anElementsId, SMESH::ALL );
330     }
331     QByteArray meshName = myMeshNameEdit->text().toLatin1();
332     bool toCopyGroups = ( myCopyGroupsCheck->isChecked() );
333     bool toKeepIDs    = ( myKeepIdsCheck->isChecked() );
334
335     SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
336     SMESH::SMESH_Mesh_var newMesh =
337       gen->CopyMesh(aPartToCopy, meshName.constData(), toCopyGroups, toKeepIDs);
338     if( !newMesh->_is_nil() )
339       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
340         anEntryList.append( aSObject->GetID().c_str() );
341 #ifdef WITHGENERICOBJ
342     // obj has been published in study. Its refcount has been incremented.
343     // It is safe to decrement its refcount
344     // so that it will be destroyed when the entry in study will be removed
345     newMesh->UnRegister();
346 #endif
347   } catch (...) {
348   }
349
350   mySMESHGUI->updateObjBrowser(true);
351   SMESHGUI::Modified();
352
353   if( LightApp_Application* anApp =
354       dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
355     anApp->browseObjects( anEntryList, isApplyAndClose() );
356
357   Init(false);
358   mySelectedObject = SMESH::SMESH_IDSource::_nil();
359   SelectionIntoArgument();
360
361   return true;
362 }
363
364 //=================================================================================
365 // function : ClickOnOk()
366 // purpose  :
367 //=================================================================================
368 void SMESHGUI_CopyMeshDlg::ClickOnOk()
369 {
370   setIsApplyAndClose( true );
371   if( ClickOnApply() )
372     reject();
373 }
374
375 //=================================================================================
376 // function : reject()
377 // purpose  :
378 //=================================================================================
379 void SMESHGUI_CopyMeshDlg::reject()
380 {
381   disconnect(mySelectionMgr, 0, this, 0);
382   if ( mySelectionMgr )
383     mySelectionMgr->removeFilter( myIdSourceFilter );
384   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
385     aViewWindow->SetSelectionMode( ActorSelection );
386   mySMESHGUI->ResetState();
387   QDialog::reject();
388 }
389
390 //=================================================================================
391 // function : ClickOnHelp()
392 // purpose  :
393 //=================================================================================
394 void SMESHGUI_CopyMeshDlg::ClickOnHelp()
395 {
396   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
397   if (app)
398     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
399   else {
400     QString platform;
401 #ifdef WIN32
402     platform = "winapplication";
403 #else
404     platform = "application";
405 #endif
406     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
407                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
408                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
409                                                                  platform)).
410                              arg(myHelpFileName));
411   }
412 }
413
414 //=======================================================================
415 // function : onTextChange()
416 // purpose  :
417 //=======================================================================
418
419 void SMESHGUI_CopyMeshDlg::onTextChange (const QString& theNewText)
420 {
421   QLineEdit* send = (QLineEdit*)sender();
422
423   if (myBusy) return;
424   BusyLocker lock( myBusy );
425
426   //if (send == myLineEditElements)
427   myNbOkElements = 0;
428
429   buttonOk->setEnabled(false);
430   buttonApply->setEnabled(false);
431
432   // hilight entered elements
433   SMDS_Mesh* aMesh = 0;
434   if (myActor)
435     aMesh = myActor->GetObject()->GetMesh();
436
437   QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
438   if (myActor && aMesh)
439   {
440     TColStd_MapOfInteger newIndices;
441     if (send == myLineEditElements) {
442       for (int i = 0; i < aListId.count(); i++)
443         if ( const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt()))
444         {
445           newIndices.Add(e->GetID());
446         }
447     }
448     myNbOkElements = newIndices.Extent();
449
450     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
451     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
452     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453       aViewWindow->highlight( anIO, true, true );
454   }
455   else
456   {
457     myNbOkElements = aListId.count();
458   }
459
460   if (myNbOkElements) {
461     buttonOk->setEnabled(true);
462     buttonApply->setEnabled(true);
463   }
464 }
465
466 //=================================================================================
467 // function : SelectionIntoArgument()
468 // purpose  : Called when selection as changed or other case
469 //=================================================================================
470
471 void SMESHGUI_CopyMeshDlg::SelectionIntoArgument()
472 {
473   if (myBusy) return;
474   BusyLocker lock( myBusy );
475
476   // clear
477   myActor = 0;
478   QString aString = "";
479
480   myLineEditElements->setText(aString);
481   myNbOkElements = 0;
482   buttonOk->setEnabled(false);
483   buttonApply->setEnabled(false);
484   myFilterBtn->setEnabled(false);
485
486   // get selected mesh
487   SALOME_ListIO aList;
488   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
489   int nbSel = aList.Extent();
490   if (nbSel != 1)
491     return;
492
493   Handle(SALOME_InteractiveObject) IO = aList.First();
494   mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
495   if ( mySelectedObject->_is_nil() )
496     return;
497
498   myMesh = SMESH::GetMeshByIO(IO);
499   if (myMesh->_is_nil())
500     return;
501
502   myActor = SMESH::FindActorByEntry(IO->getEntry());
503   if (!myActor)
504     myActor = SMESH::FindActorByObject(myMesh);
505
506   if (myIdSourceCheck->isChecked())
507   {
508     SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
509     if ( aString.isEmpty() ) aString = " ";
510     else                     aString = aString.trimmed(); // issue 0021327
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 : keyPressEvent()
623 // purpose  :
624 //=================================================================================
625 void SMESHGUI_CopyMeshDlg::keyPressEvent( QKeyEvent* e )
626 {
627   QDialog::keyPressEvent( e );
628   if ( e->isAccepted() )
629     return;
630
631   if ( e->key() == Qt::Key_F1 ) {
632     e->accept();
633     ClickOnHelp();
634   }
635 }
636
637 //=================================================================================
638 // function : setFilters()
639 // purpose  : SLOT. Called when "Filter" button pressed.
640 //=================================================================================
641 void SMESHGUI_CopyMeshDlg::setFilters()
642 {
643   if(myMesh->_is_nil()) {
644     SUIT_MessageBox::critical(this,
645                               tr("SMESH_ERROR"),
646                               tr("NO_MESH_SELECTED"));
647    return;
648   }
649   if ( !myFilterDlg )
650     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
651
652   myFilterDlg->SetSelection();
653   myFilterDlg->SetMesh( myMesh );
654   myFilterDlg->SetSourceWg( myLineEditElements );
655
656   myFilterDlg->show();
657 }
658
659 //================================================================
660 // function : setIsApplyAndClose
661 // Purpose  : Set value of the flag indicating that the dialog is
662 //            accepted by Apply & Close button
663 //================================================================
664 void SMESHGUI_CopyMeshDlg::setIsApplyAndClose( const bool theFlag )
665 {
666   myIsApplyAndClose = theFlag;
667 }
668
669 //================================================================
670 // function : isApplyAndClose
671 // Purpose  : Get value of the flag indicating that the dialog is
672 //            accepted by Apply & Close button
673 //================================================================
674 bool SMESHGUI_CopyMeshDlg::isApplyAndClose() const
675 {
676   return myIsApplyAndClose;
677 }