Salome HOME
0022108: EDF 2547 SMESH: Duplicate elements only
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_DuplicateNodesDlg.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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_DuplicateNodesDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26
27 // SMESH includes
28 #include "SMESHGUI_DuplicateNodesDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_VTKUtils.h"
34
35 #include <SMESH_TypeFilter.hxx>
36
37 // SALOME GUI includes
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
46
47 #include <SalomeApp_Tools.h>
48
49 #include <SVTK_ViewWindow.h>
50 #include <SALOME_ListIO.hxx>
51 #include <SALOME_ListIteratorOfListIO.hxx>
52
53 // Qt includes
54 #include <QApplication>
55 #include <QButtonGroup>
56 #include <QGroupBox>
57 #include <QLabel>
58 #include <QLineEdit>
59 #include <QPushButton>
60 #include <QRadioButton>
61 #include <QCheckBox>
62 #include <QHBoxLayout>
63 #include <QVBoxLayout>
64 #include <QKeyEvent>
65
66 #include <utilities.h>
67 #include <SALOMEDSClient_SObject.hxx>
68
69 // IDL includes
70 #include <SALOMEconfig.h>
71 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
72
73 #define SPACING 6
74 #define MARGIN  11
75
76 /*!
77   \class BusyLocker
78   \brief Simple 'busy state' flag locker.
79   \internal
80 */
81
82 class BusyLocker
83 {
84 public:
85   //! Constructor. Sets passed boolean flag to \c true.
86   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
87   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
88   ~BusyLocker() { myBusy = false; }
89 private:
90   bool& myBusy; //! External 'busy state' boolean flag
91 };
92
93 /*!
94   \brief Constructor
95   \param theModule Mesh module instance
96 */
97 SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
98   : QDialog( SMESH::GetDesktop( theModule ) ),
99     mySMESHGUI( theModule ),
100     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
101 {
102   // Dialog attributes
103   setModal(false);
104   setAttribute(Qt::WA_DeleteOnClose, true);
105   setWindowTitle(tr("SMESH_DUPLICATE_TITLE"));
106   setSizeGripEnabled(true);
107
108   // Icons for the dialog operation modes and selection button
109   SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
110   QPixmap iconWithoutElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES")));
111   QPixmap iconWithElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES_WITH_ELEM")));
112   QPixmap iconElemOnly (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_ELEM_ONLY")));
113   QPixmap iconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
114
115   // Main layout
116   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
117   aMainLayout->setSpacing(SPACING);
118   aMainLayout->setMargin(MARGIN);
119
120   // Operation modes selector
121   QGroupBox* aConstructorsBox = new QGroupBox(tr("DUPLICATION_MODE"), this);
122   myGroupConstructors = new QButtonGroup(this);
123   QHBoxLayout* aConstructorsBoxLayout = new QHBoxLayout(aConstructorsBox);
124   aConstructorsBoxLayout->setSpacing(SPACING);
125   aConstructorsBoxLayout->setMargin(MARGIN);
126
127   QRadioButton* aRadioButton1 = new QRadioButton(aConstructorsBox);
128   aRadioButton1->setIcon(iconWithoutElem);
129   QRadioButton* aRadioButton2 = new QRadioButton(aConstructorsBox);
130   aRadioButton2->setIcon(iconWithElem);
131   QRadioButton* aRadioButton3 = new QRadioButton(aConstructorsBox);
132   aRadioButton3->setIcon(iconElemOnly);
133   
134   aConstructorsBoxLayout->addWidget(aRadioButton1);
135   aConstructorsBoxLayout->addWidget(aRadioButton2);
136   aConstructorsBoxLayout->addWidget(aRadioButton3);
137   myGroupConstructors->addButton(aRadioButton1, 0);
138   myGroupConstructors->addButton(aRadioButton2, 1);
139   myGroupConstructors->addButton(aRadioButton3, 2);
140
141   // Arguments
142   myGroupArguments = new QGroupBox(this);
143   QGridLayout* aGroupArgumentsLayout = new QGridLayout(myGroupArguments);
144   aGroupArgumentsLayout->setSpacing(SPACING);
145   aGroupArgumentsLayout->setMargin(MARGIN);
146     
147   myTextLabel1 = new QLabel(myGroupArguments);
148   mySelectButton1 = new QPushButton(myGroupArguments);
149   mySelectButton1->setIcon(iconSelect);
150   myLineEdit1 = new QLineEdit(myGroupArguments);
151   myLineEdit1->setReadOnly(true);
152
153   myTextLabel2 = new QLabel(myGroupArguments);
154   mySelectButton2 = new QPushButton(myGroupArguments);
155   mySelectButton2->setIcon(iconSelect);
156   myLineEdit2 = new QLineEdit(myGroupArguments);
157   myLineEdit2->setReadOnly(true);
158
159   myTextLabel3 = new QLabel(myGroupArguments);
160   mySelectButton3 = new QPushButton(myGroupArguments);
161   mySelectButton3->setIcon(iconSelect);
162   myLineEdit3 = new QLineEdit(myGroupArguments);
163   myLineEdit3->setReadOnly(true);
164
165   myCheckBoxNewElemGroup = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_ELEMENTS"), myGroupArguments);
166   myCheckBoxNewNodeGroup = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_NODES"), myGroupArguments);
167
168   aGroupArgumentsLayout->addWidget(myTextLabel1,    0, 0);
169   aGroupArgumentsLayout->addWidget(mySelectButton1, 0, 1);
170   aGroupArgumentsLayout->addWidget(myLineEdit1,     0, 2);
171   aGroupArgumentsLayout->addWidget(myTextLabel2,    1, 0);
172   aGroupArgumentsLayout->addWidget(mySelectButton2, 1, 1);
173   aGroupArgumentsLayout->addWidget(myLineEdit2,     1, 2);
174   aGroupArgumentsLayout->addWidget(myTextLabel3,    2, 0);
175   aGroupArgumentsLayout->addWidget(mySelectButton3, 2, 1);
176   aGroupArgumentsLayout->addWidget(myLineEdit3,     2, 2);
177   aGroupArgumentsLayout->addWidget(myCheckBoxNewElemGroup, 3, 0);
178   aGroupArgumentsLayout->addWidget(myCheckBoxNewNodeGroup, 4, 0);
179   aGroupArgumentsLayout->setRowStretch(5, 1);
180   
181   // Buttons
182   QGroupBox* aGroupButtons = new QGroupBox(this);
183   QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(aGroupButtons);
184   aGroupButtonsLayout->setSpacing(SPACING);
185   aGroupButtonsLayout->setMargin(MARGIN);
186
187   myButtonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGroupButtons);
188   myButtonOk->setAutoDefault(true);
189   myButtonOk->setDefault(true);
190   myButtonApply = new QPushButton(tr("SMESH_BUT_APPLY"), aGroupButtons);
191   myButtonApply->setAutoDefault(true);
192   myButtonClose = new QPushButton(tr("SMESH_BUT_CLOSE"), aGroupButtons);
193   myButtonClose->setAutoDefault(true);
194   myButtonHelp = new QPushButton(tr("SMESH_BUT_HELP"), aGroupButtons);
195   myButtonHelp->setAutoDefault(true);
196
197   aGroupButtonsLayout->addWidget(myButtonOk);
198   aGroupButtonsLayout->addSpacing(10);
199   aGroupButtonsLayout->addWidget(myButtonApply);
200   aGroupButtonsLayout->addSpacing(10);
201   aGroupButtonsLayout->addStretch();
202   aGroupButtonsLayout->addWidget(myButtonClose);
203   aGroupButtonsLayout->addWidget(myButtonHelp);
204
205   // Add mode selector, arguments and buttons to the main layout
206   aMainLayout->addWidget(aConstructorsBox);
207   aMainLayout->addWidget(myGroupArguments);
208   aMainLayout->addWidget(aGroupButtons);
209   
210   myCheckBoxNewElemGroup->setChecked(true);
211   myCheckBoxNewNodeGroup->setChecked(true);
212
213   // Initialize the dialog
214   Init();
215
216   // Help file name
217   myHelpFileName = "double_nodes_page.html";
218
219   // Signals and slots connections
220   connect(myGroupConstructors, SIGNAL(buttonClicked(int)), SLOT(onConstructorsClicked(int)));
221      
222   connect(mySelectButton1, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
223   connect(mySelectButton2, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
224   connect(mySelectButton3, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
225
226   connect(myButtonOk,     SIGNAL(clicked()), this, SLOT(onOk()));
227   connect(myButtonClose,  SIGNAL(clicked()), this, SLOT(reject()));
228   connect(myButtonApply,  SIGNAL(clicked()), this, SLOT(onApply()));
229   connect(myButtonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
230   
231   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionChanged()));
232
233   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
234   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
235 }
236
237 /*!
238   \brief Destructor
239 */
240 SMESHGUI_DuplicateNodesDlg::~SMESHGUI_DuplicateNodesDlg()
241 {
242 }
243
244 /*!
245   \brief Destructor
246 */
247 void SMESHGUI_DuplicateNodesDlg::Init()
248 {
249   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
250
251   // Set initial parameters
252   myBusy = false;
253   myCurrentLineEdit = myLineEdit1;
254
255   myGroups1.clear();
256   myGroups2.clear();
257   myGroups3.clear();
258   
259   // Set selection mode
260   mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
261   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
262     aViewWindow->SetSelectionMode(ActorSelection);
263   
264   // Set construction mode
265   int operationMode = myGroupConstructors->checkedId();
266   if (operationMode < 0) {
267     // The dialog has been just displayed
268     operationMode = 0;
269     myGroupConstructors->button(0)->setChecked(true);
270   }
271   onConstructorsClicked(operationMode);
272 }
273
274 /*!
275   \brief SLOT called to change the dialog operation mode.
276   \param constructorId id of the radio button in mode selector button group
277 */
278 void SMESHGUI_DuplicateNodesDlg::onConstructorsClicked (int constructorId)
279 {
280   // Clear all fields
281   myLineEdit1->clear();
282   myLineEdit2->clear();
283   myLineEdit3->clear();
284
285   myGroups1.clear();
286   myGroups2.clear();
287   myGroups3.clear();
288
289   // Set the first field as current
290   myCurrentLineEdit = myLineEdit1;
291   myCurrentLineEdit->setFocus();
292
293   switch (constructorId) {
294   case 0:
295     {
296       // Set text to the group of arguments and to the first two labels
297       myGroupArguments->setTitle(tr("DUPLICATION_WITHOUT_ELEMS"));
298       myTextLabel1->setText(tr("GROUP_NODES_TO_DUPLICATE"));
299       myTextLabel2->setText(tr("GROUP_NODES_TO_REPLACE"));
300
301       myCheckBoxNewElemGroup->hide();
302       myCheckBoxNewNodeGroup->show();
303       
304       // Hide the third field
305       myTextLabel3->hide();
306       mySelectButton3->hide();
307       myLineEdit3->hide();
308       
309       break;
310     }
311   case 1:
312     {
313       // Set text to the group of arguments and to all the labels
314       myGroupArguments->setTitle(tr("DUPLICATION_WITH_ELEMS"));
315       myTextLabel1->setText(tr("GROUP_ELEMS_TO_DUPLICATE"));
316       myTextLabel2->setText(tr("GROUP_NODES_NOT_DUPLICATE"));
317       myTextLabel3->setText(tr("GROUP_ELEMS_TO_REPLACE"));
318       
319       myCheckBoxNewElemGroup->show();
320       myCheckBoxNewNodeGroup->show();
321
322       // Show the third field
323       myTextLabel3->show();
324       mySelectButton3->show();
325       myLineEdit3->show();
326
327       break;
328     }
329   case 2:
330     {
331       // Set text to the group of arguments and to all the labels
332       myGroupArguments->setTitle(tr("DUPLICATION_ONLY_ELEMS"));
333       myTextLabel1->setText(tr("GROUP_ELEMS_TO_DUPLICATE"));
334       
335       myCheckBoxNewElemGroup->show();
336       myCheckBoxNewNodeGroup->hide();
337
338       // Hide the second and the third field
339       myTextLabel2->hide();
340       mySelectButton2->hide();
341       myLineEdit2->hide();
342       myTextLabel3->hide();
343       mySelectButton3->hide();
344       myLineEdit3->hide();
345
346       break;
347     }
348   }
349   
350   // Process selection
351   onSelectionChanged();
352 }
353
354 /*!
355   \brief SLOT called to apply changes.
356 */
357 bool SMESHGUI_DuplicateNodesDlg::onApply()
358 {
359   if ( mySMESHGUI->isActiveStudyLocked() || !isValid() )
360     return false;
361
362   BusyLocker lock( myBusy );
363  
364   bool toCreateElemGroup = myCheckBoxNewElemGroup->isChecked();
365   bool toCreateNodeGroup = myCheckBoxNewNodeGroup->isChecked();
366   int operationMode      = myGroupConstructors->checkedId();
367   
368   // Apply changes
369   bool result = false;
370   SUIT_OverrideCursor aWaitCursor;
371   QStringList anEntryList;
372
373   try {
374     SMESH::SMESH_Mesh_var aMesh = myGroups1[0]->GetMesh();
375     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
376
377     switch ( operationMode ) {
378     case 0:
379     {
380       SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
381       g1->length( myGroups1.count() );
382       for ( int i = 0; i < myGroups1.count(); i++ )
383         g1[i] = myGroups1[i];
384       SMESH::ListOfGroups_var g2 = new SMESH::ListOfGroups();
385       g2->length( myGroups2.count() );
386       for ( int i = 0; i < myGroups2.count(); i++ )
387         g2[i] = myGroups2[i];
388
389       if ( toCreateNodeGroup ) {
390         SMESH::SMESH_GroupBase_var aNewGroup = 
391           aMeshEditor->DoubleNodeGroupsNew( g1.in(), g2.in() );
392         result = !CORBA::is_nil( aNewGroup );
393       }
394       else {
395         result = aMeshEditor->DoubleNodeGroups( g1.in(), g2.in() );
396       }
397       break;
398     }
399     case 1:
400     {
401       SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
402       g1->length( myGroups1.count() );
403       for ( int i = 0; i < myGroups1.count(); i++ )
404         g1[i] = myGroups1[i];
405       SMESH::ListOfGroups_var g2 = new SMESH::ListOfGroups();
406       g2->length( myGroups2.count() );
407       for ( int i = 0; i < myGroups2.count(); i++ )
408         g2[i] = myGroups2[i];
409       SMESH::ListOfGroups_var g3 = new SMESH::ListOfGroups();
410       g3->length( myGroups3.count() );
411
412       for ( int i = 0; i < myGroups3.count(); i++ )
413         g3[i] = myGroups3[i];
414       if ( toCreateElemGroup || toCreateNodeGroup ) {
415         SMESH::ListOfGroups_var aNewGroups = 
416           aMeshEditor->DoubleNodeElemGroups2New( g1.in(), g2.in(), g3.in(),
417                                                  toCreateElemGroup, toCreateNodeGroup );
418         result = ( aNewGroups[ !toCreateElemGroup ].in() );
419       }
420       else {
421         result = aMeshEditor->DoubleNodeElemGroups( g1.in(), g2.in(), g3.in() );
422       }
423       break;
424     }
425     case 2:
426     {
427       result = true;
428       QString groupName;
429       if ( toCreateElemGroup )
430         groupName = SMESH::UniqueName("DoubleElements");
431       for ( int i = 0; i < myGroups1.count(); i++ )
432       {
433         SMESH::SMESH_Group_var group =
434           aMeshEditor->DoubleElements( myGroups1[i], groupName.toLatin1().data() );
435         if ( group->_is_nil() )
436         {
437           if ( toCreateElemGroup )
438             result = false;
439         }
440         else
441         {
442           if ( _PTR(SObject) so = SMESH::FindSObject( group ))
443             anEntryList.append( so->GetID().c_str() );
444         }
445       }
446       break;
447     }
448     }
449   }
450   catch (const SALOME::SALOME_Exception& S_ex) {
451     SalomeApp_Tools::QtCatchCorbaException(S_ex);
452   }
453   catch ( const std::exception& exc ) {
454     INFOS( "Follow exception was cought:\n\t" << exc.what() );
455   } 
456   catch (...) {
457     INFOS( "Unknown exception was cought !!!" );
458   }
459
460   if (!result) {
461     SUIT_MessageBox::warning(this,
462                              tr("SMESH_WRN_WARNING"),
463                              tr("SMESH_OPERATION_FAILED"));
464     return false;
465   }
466
467   // Update GUI
468   mySelectionMgr->clearSelected();
469   SMESH::UpdateView();
470   SMESHGUI::Modified();
471   mySMESHGUI->updateObjBrowser(true);
472
473   if ( !anEntryList.isEmpty())
474     if( LightApp_Application* anApp =
475         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ))
476       anApp->browseObjects( anEntryList, true, false );
477
478   // Reinitialize the dialog
479   Init();
480
481   return true;
482 }
483
484 /*!
485   \brief SLOT called to apply changes and close the dialog.
486 */
487 void SMESHGUI_DuplicateNodesDlg::onOk()
488 {
489   if (onApply())
490     reject();
491 }
492
493 /*!
494   \brief SLOT called to close the dialog.
495 */
496 void SMESHGUI_DuplicateNodesDlg::reject()
497 {
498   disconnect(mySelectionMgr, 0, this, 0);
499   disconnect(mySMESHGUI, 0, this, 0);
500   mySMESHGUI->ResetState();
501   mySelectionMgr->clearFilters();
502   QDialog::reject();
503 }
504
505 /*!
506   \brief  SLOT called when selection changed.
507 */
508 void SMESHGUI_DuplicateNodesDlg::onSelectionChanged()
509 {
510   if ( myBusy || !isEnabled() ) return;
511   
512   int operationMode = myGroupConstructors->checkedId();
513
514   SALOME_ListIO aList;
515   mySelectionMgr->selectedObjects( aList );
516   //int aNbSel = aList.Extent();
517
518   QList<SMESH::SMESH_GroupBase_var> aGroups;
519
520   SALOME_ListIteratorOfListIO anIter ( aList );
521   bool ok = true;
522   for ( ; anIter.More() && ok; anIter.Next()) {
523     SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( anIter.Value() );
524     // check group is selected
525     ok = !CORBA::is_nil( aGroup );
526     // check groups of the same mesh are selected
527     if ( ok ) {
528       SMESH::SMESH_Mesh_var aMesh1;
529       if ( !aGroups.isEmpty() ) aMesh1 = aGroups[0]->GetMesh();
530       SMESH::SMESH_Mesh_var aMesh2 = aGroup->GetMesh();
531       ok = CORBA::is_nil( aMesh1 ) || aMesh1->_is_equivalent( aMesh2 );
532     }
533     // check group of proper type is selected
534     if ( ok ) {
535       SMESH::ElementType aGroupType = aGroup->GetType();
536       switch ( operationMode ) {
537       case 0:
538         ok = ( myCurrentLineEdit == myLineEdit1 && aGroupType == SMESH::NODE ) ||
539              ( myCurrentLineEdit == myLineEdit2 && aGroupType != SMESH::NODE );
540         break;
541       case 1:
542         ok = ( myCurrentLineEdit == myLineEdit1 && ( aGroupType == SMESH::EDGE ||
543                                                      aGroupType == SMESH::FACE ) ) ||
544              ( myCurrentLineEdit == myLineEdit2 && aGroupType == SMESH::NODE )     ||
545              ( myCurrentLineEdit == myLineEdit3 && aGroupType != SMESH::NODE );
546         break;
547       case 2:
548         ok = ( aGroupType != SMESH::NODE );
549         break;
550       }
551     }
552     if ( ok ) aGroups << aGroup;
553   }
554
555   // Clear current field
556   myCurrentLineEdit->clear();
557
558   if ( ok && !aGroups.isEmpty() ) {
559     if      ( myCurrentLineEdit == myLineEdit1 ) myGroups1 = aGroups;
560     else if ( myCurrentLineEdit == myLineEdit2 ) myGroups2 = aGroups;
561     else if ( myCurrentLineEdit == myLineEdit3 ) myGroups3 = aGroups;
562     CORBA::String_var name = aGroups[0]->GetName();
563     myCurrentLineEdit->setText( aGroups.count() == 1 ? QString(name).trimmed() : 
564                                 QObject::tr( "SMESH_OBJECTS_SELECTED" ).arg( aGroups.count() ) );
565   }
566   else {
567     if      ( myCurrentLineEdit == myLineEdit1 ) myGroups1.clear();
568     else if ( myCurrentLineEdit == myLineEdit2 ) myGroups2.clear();
569     else if ( myCurrentLineEdit == myLineEdit3 ) myGroups3.clear();
570     myCurrentLineEdit->clear();
571   }
572
573   // Enable/disable "Apply and Close" and "Apply" buttons
574   bool isDataValid = isValid();
575   myButtonOk->setEnabled( isDataValid );
576   myButtonApply->setEnabled( isDataValid );
577 }
578
579 /*!
580   \brief  SLOT called when selection button clicked.
581 */
582 void SMESHGUI_DuplicateNodesDlg::onEditCurrentArgument()
583 {
584   QPushButton* send = (QPushButton*)sender();
585   
586   // Set current field for edition
587   if (send == mySelectButton1) {
588     myCurrentLineEdit = myLineEdit1;
589   } 
590   else if (send == mySelectButton2) {
591     myCurrentLineEdit = myLineEdit2;
592   }
593   else if (send == mySelectButton3) {
594     myCurrentLineEdit = myLineEdit3;
595   }
596   
597   myCurrentLineEdit->setFocus();
598   onSelectionChanged();
599 }
600
601 /*!
602   \brief Check if the input data is valid.
603   \return \c true if the data is valid
604 */
605 bool SMESHGUI_DuplicateNodesDlg::isValid()
606 {
607   return myGroupConstructors->checkedId() == 1 ?
608     ( !myGroups1.isEmpty() && !myGroups3.isEmpty()  ) :
609     ( !myGroups1.isEmpty() );
610 }
611
612
613 /*!
614   \brief SLOT called when dialog shoud be deativated.
615 */
616 void SMESHGUI_DuplicateNodesDlg::onDeactivate()
617 {
618   if (isEnabled()) {
619     mySelectionMgr->clearFilters();
620     setEnabled(false);
621     mySMESHGUI->ResetState();
622     mySMESHGUI->SetActiveDialogBox(0);
623   }
624 }
625
626 /*!
627   \brief Receive dialog enter events.
628   Activates the dialog when the mouse cursor enters.
629   Reimplemented from QWidget class.
630 */
631 void SMESHGUI_DuplicateNodesDlg::enterEvent (QEvent*)
632 {
633   if ( !isEnabled() ) {
634     mySMESHGUI->EmitSignalDeactivateDialog();
635     setEnabled(true);
636     mySMESHGUI->SetActiveDialogBox((QDialog*)this);
637     
638     // Set selection mode
639     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
640       aViewWindow->SetSelectionMode(ActorSelection);
641     mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
642   }
643 }
644
645 /*!
646   \brief Receive key press events.
647   Reimplemented from QWidget class.
648 */
649 void SMESHGUI_DuplicateNodesDlg::keyPressEvent( QKeyEvent* e )
650 {
651   QDialog::keyPressEvent( e );
652   if ( e->isAccepted() )
653     return;
654
655   if ( e->key() == Qt::Key_F1 ) {
656     e->accept();
657     onHelp();
658   }
659 }
660
661 /*!
662   \brief Show the dialog help page.
663 */
664 void SMESHGUI_DuplicateNodesDlg::onHelp()
665 {
666   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
667   if (app) 
668     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
669   else {
670     QString platform;
671 #ifdef WIN32
672     platform = "winapplication";
673 #else
674     platform = "application";
675 #endif
676     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
677                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
678                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
679                                                                  platform)).
680                              arg(myHelpFileName));
681   }
682 }