Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESHGUI_ExtrusionDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_ExtrusionDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESHGUI_IdValidator.h"
37
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_NumberFilter.hxx"
41 #include "SMESH_LogicalFilter.hxx"
42
43 #include "SMDS_Mesh.hxx"
44
45 #include "SUIT_ResourceMgr.h"
46 #include "SUIT_OverrideCursor.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_MessageBox.h"
49 #include "SUIT_Session.h"
50
51 #include "LightApp_Application.h"
52
53 #include "SVTK_ViewModel.h"
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
56 #include "SVTK_Selection.h"
57 #include "SALOME_ListIO.hxx"
58
59 #include "utilities.h"
60
61 // OCCT Includes
62 #include <TColStd_MapOfInteger.hxx>
63 #include <TColStd_IndexedMapOfInteger.hxx>
64
65 // QT Includes
66 #include <qapplication.h>
67 #include <qbuttongroup.h>
68 #include <qgroupbox.h>
69 #include <qlabel.h>
70 #include <qlineedit.h>
71 #include <qpushbutton.h>
72 #include <qradiobutton.h>
73 #include <qcheckbox.h>
74 #include <qspinbox.h>
75 #include <qlayout.h>
76 #include <qvalidator.h>
77 #include <qpixmap.h>
78
79 // IDL Headers
80 #include "SALOMEconfig.h"
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83
84 using namespace std;
85
86 //=================================================================================
87 // function : SMESHGUI_ExtrusionDlg()
88 // purpose  : constructor
89 //=================================================================================
90 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule,
91                                               bool modal)
92      : QDialog( SMESH::GetDesktop( theModule ), "SMESHGUI_ExtrusionDlg", modal, WStyle_Customize |
93                 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
94      mySMESHGUI( theModule ),
95      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
96 {
97   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
98   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
99   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100
101   resize(303, 185);
102   setCaption(tr("EXTRUSION_ALONG_LINE"));
103   setSizeGripEnabled(TRUE);
104
105   QGridLayout* SMESHGUI_ExtrusionDlgLayout = new QGridLayout(this);
106   SMESHGUI_ExtrusionDlgLayout->setSpacing(6);
107   SMESHGUI_ExtrusionDlgLayout->setMargin(11);
108
109   /***************************************************************/
110   GroupConstructors = new QButtonGroup("GroupConstructors", this);
111   GroupConstructors->setTitle(tr("SMESH_EXTRUSION"));
112   GroupConstructors->setExclusive(TRUE);
113   GroupConstructors->setColumnLayout(0, Qt::Vertical);
114   GroupConstructors->layout()->setSpacing(0);
115   GroupConstructors->layout()->setMargin(0);
116   QGridLayout* GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
117   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
118   GroupConstructorsLayout->setSpacing(6);
119   GroupConstructorsLayout->setMargin(11);
120   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
121   RadioButton1->setText(tr(""));
122   RadioButton1->setPixmap(image0);
123   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
124   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
125   RadioButton2->setText(tr(""));
126   RadioButton2->setPixmap(image1);
127   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2);
128   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupConstructors, 0, 0);
129
130   /***************************************************************/
131   GroupButtons = new QGroupBox(this, "GroupButtons");
132   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
133   GroupButtons->setTitle(tr(""));
134   GroupButtons->setColumnLayout(0, Qt::Vertical);
135   GroupButtons->layout()->setSpacing(0);
136   GroupButtons->layout()->setMargin(0);
137   QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
138   GroupButtonsLayout->setAlignment(Qt::AlignTop);
139   GroupButtonsLayout->setSpacing(6);
140   GroupButtonsLayout->setMargin(11);
141   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
142   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
143   buttonHelp->setAutoDefault(TRUE);
144   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
145   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
146   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
147   buttonCancel->setAutoDefault(TRUE);
148   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
149   buttonApply = new QPushButton(GroupButtons, "buttonApply");
150   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
151   buttonApply->setAutoDefault(TRUE);
152   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
153   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
154   GroupButtonsLayout->addItem(spacer_9, 0, 2);
155   buttonOk = new QPushButton(GroupButtons, "buttonOk");
156   buttonOk->setText(tr("SMESH_BUT_OK" ));
157   buttonOk->setAutoDefault(TRUE);
158   buttonOk->setDefault(TRUE);
159   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
160   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons, 2, 0);
161
162   /***************************************************************/
163   GroupArguments = new QGroupBox(this, "GroupArguments");
164   GroupArguments->setTitle(tr("EXTRUSION_1D"));
165   GroupArguments->setColumnLayout(0, Qt::Vertical);
166   GroupArguments->layout()->setSpacing(0);
167   GroupArguments->layout()->setMargin(0);
168   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
169   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
170   GroupArgumentsLayout->setSpacing(6);
171   GroupArgumentsLayout->setMargin(11);
172
173   // Controls for elements selection
174   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
175   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
176   TextLabelElements->setFixedWidth(74);
177   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
178
179   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
180   SelectElementsButton->setText(tr("" ));
181   SelectElementsButton->setPixmap(image2);
182   SelectElementsButton->setToggleButton(FALSE);
183   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
184
185   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
186   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
187   GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
188
189   // Control for the whole mesh selection
190   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
191   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
192   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
193
194   // Controls for vector selection
195   TextLabelVector = new QLabel(GroupArguments, "TextLabelVector");
196   TextLabelVector->setText(tr("SMESH_VECTOR"));
197   GroupArgumentsLayout->addWidget(TextLabelVector, 2, 0);
198
199   TextLabelDx = new QLabel(GroupArguments, "TextLabelDx");
200   TextLabelDx->setText(tr("SMESH_DX"));
201   GroupArgumentsLayout->addWidget(TextLabelDx, 2, 2);
202
203   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dx");
204   GroupArgumentsLayout->addWidget(SpinBox_Dx, 2, 3);
205
206   TextLabelDy = new QLabel(GroupArguments, "TextLabelDy");
207   TextLabelDy->setText(tr("SMESH_DY"));
208   GroupArgumentsLayout->addWidget(TextLabelDy, 2, 4);
209
210   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dy");
211   GroupArgumentsLayout->addWidget(SpinBox_Dy, 2, 5);
212
213   TextLabelDz = new QLabel(GroupArguments, "TextLabelDz");
214   TextLabelDz->setText(tr("SMESH_DZ"));
215   GroupArgumentsLayout->addWidget(TextLabelDz, 2, 6);
216
217   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dz");
218   GroupArgumentsLayout->addWidget(SpinBox_Dz, 2, 7);
219
220   // Controls for nb. steps defining
221   TextLabelNbSteps = new QLabel(GroupArguments, "TextLabelNbSteps");
222   TextLabelNbSteps->setText(tr("SMESH_NUMBEROFSTEPS" ));
223   GroupArgumentsLayout->addMultiCellWidget(TextLabelNbSteps, 3, 3, 0, 1);
224
225   SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
226   GroupArgumentsLayout->addMultiCellWidget(SpinBox_NbSteps, 3, 3,  2, 7);
227
228   // CheckBox for groups generation
229   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
230   MakeGroupsCheck->setChecked(true);
231   GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 4, 4,  0, 7);
232
233
234   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments, 1, 0);
235
236   /* Initialisations */
237   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
238   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
239   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
240
241   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
242   SpinBox_NbSteps->setValidator(anIntValidator);
243   SpinBox_NbSteps->setRange(1, 999999);
244
245   GroupArguments->show();
246   RadioButton1->setChecked(TRUE);
247
248   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
249
250   mySMESHGUI->SetActiveDialogBox(this);
251
252   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
253   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
254   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
255
256   QPtrList<SUIT_SelectionFilter> aListOfFilters;
257   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
258   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
259
260   myMeshOrSubMeshOrGroupFilter =
261     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
262
263   myHelpFileName = "extrusion_page.html";
264
265   Init();
266
267   /***************************************************************/
268   // signals and slots connections
269   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
270   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
271   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
272   connect(buttonHelp, SIGNAL(clicked()),  this, SLOT(ClickOnHelp()));
273
274   // to update state of the Ok & Apply buttons
275   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
276   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
277   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
278
279   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
280   connect(SelectElementsButton, SIGNAL (clicked()),            this, SLOT(SetEditCurrentArgument()));
281   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
282   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
283   /* to close dialog if study change */
284   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
285   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
286   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
287
288   /***************************************************************/
289   
290   this->show(); // displays Dialog
291
292   ConstructorsClicked(0);
293   SelectionIntoArgument();
294 }
295
296 //=================================================================================
297 // function : ~SMESHGUI_ExtrusionDlg()
298 // purpose  : destructor
299 //=================================================================================
300 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
301 {
302   // no need to delete child widgets, Qt does it all for us
303 }
304
305 //=================================================================================
306 // function : Init()
307 // purpose  : initialization
308 //=================================================================================
309 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
310 {
311   myBusy = false;
312
313   LineEditElements->clear();
314   myNbOkElements = 0;
315
316   myActor = 0;
317   myMesh = SMESH::SMESH_Mesh::_nil();
318
319   if (ResetControls) {
320     SpinBox_NbSteps->setValue(1);
321     SpinBox_Dx->SetValue(0);
322     SpinBox_Dy->SetValue(0);
323     SpinBox_Dz->SetValue(0);
324
325     CheckBoxMesh->setChecked(false);
326     onSelectMesh(false);
327   }
328
329   CheckIsEnable();
330 }
331
332 //=================================================================================
333 // function : CheckIsEnable()
334 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
335 //=================================================================================
336 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
337 {
338   double aX = SpinBox_Dx->GetValue();
339   double aY = SpinBox_Dy->GetValue();
340   double aZ = SpinBox_Dz->GetValue();
341   double aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
342   
343   bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
344
345   buttonOk->setEnabled(anIsEnable);
346   buttonApply->setEnabled(anIsEnable);
347 }
348
349 //=================================================================================
350 // function : ConstructorsClicked()
351 // purpose  : Radio button management
352 //=================================================================================
353 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
354 {
355   disconnect(mySelectionMgr, 0, this, 0);
356
357   switch (constructorId) {
358   case 0:
359     {
360       GroupArguments->setTitle(tr("EXTRUSION_1D"));
361       if (!CheckBoxMesh->isChecked())
362         {
363           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
364             aViewWindow->SetSelectionMode(EdgeSelection);
365         }
366       break;
367     }
368   case 1:
369     {
370       GroupArguments->setTitle(tr("EXTRUSION_2D"));
371       if (!CheckBoxMesh->isChecked())
372         {
373           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
374             aViewWindow->SetSelectionMode(FaceSelection);
375         }
376       break;
377     }
378   }
379
380   myEditCurrentArgument = LineEditElements;
381   LineEditElements->setFocus();
382
383   if (CheckBoxMesh->isChecked())
384     onSelectMesh(true);
385
386   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
387 }
388
389 //=================================================================================
390 // function : ClickOnApply()
391 // purpose  : Called when user presses <Apply> button
392 //=================================================================================
393 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
394 {
395   if (mySMESHGUI->isActiveStudyLocked())
396     return false;
397
398   if (myNbOkElements) {
399
400     SMESH::DirStruct aVector;
401     aVector.PS.x = SpinBox_Dx->GetValue();
402     aVector.PS.y = SpinBox_Dy->GetValue();
403     aVector.PS.z = SpinBox_Dz->GetValue();
404
405     long aNbSteps = (long)SpinBox_NbSteps->value();
406
407     try {
408       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
409       QApplication::setOverrideCursor(Qt::waitCursor);
410
411       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
412         SMESH::ListOfGroups_var groups = 
413           aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
414       else
415         aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
416
417       QApplication::restoreOverrideCursor();
418     } catch (...) {
419     }
420
421     SMESH::UpdateView();
422     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
423       mySMESHGUI->updateObjBrowser(true); // new groups may appear
424     Init(false);
425     ConstructorsClicked(GetConstructorId());
426     SelectionIntoArgument();
427   }
428   return true;
429 }
430
431 //=================================================================================
432 // function : ClickOnOk()
433 // purpose  : Called when user presses <OK> button
434 //=================================================================================
435 void SMESHGUI_ExtrusionDlg::ClickOnOk()
436 {
437   if (ClickOnApply())
438     ClickOnCancel();
439 }
440
441 //=================================================================================
442 // function : ClickOnCancel()
443 // purpose  : Called when dialog box is closed
444 //=================================================================================
445 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
446 {
447   disconnect(mySelectionMgr, 0, this, 0);
448   mySelectionMgr->clearFilters();
449   //mySelectionMgr->clearSelected();
450   SMESH::SetPickable(); // ???
451   SMESH::SetPointRepresentation(false);
452   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453     aViewWindow->SetSelectionMode(ActorSelection);
454   mySMESHGUI->ResetState();
455   reject();
456 }
457
458 //=================================================================================
459 // function : ClickOnHelp()
460 // purpose  :
461 //=================================================================================
462 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
463 {
464   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
465   if (app) 
466     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
467   else {
468                 QString platform;
469 #ifdef WIN32
470                 platform = "winapplication";
471 #else
472                 platform = "application";
473 #endif
474     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
475                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
476                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
477                            QObject::tr("BUT_OK"));
478   }
479 }
480
481 //=================================================================================
482 // function : onTextChange()
483 // purpose  :
484 //=================================================================================
485 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
486 {
487   QLineEdit* send = (QLineEdit*)sender();
488
489   // return if busy
490   if (myBusy) return;
491
492   // set busy flag
493   myBusy = true;
494
495   if (send == LineEditElements)
496     myNbOkElements = 0;
497
498   // hilight entered elements/nodes
499
500   if (!myIO.IsNull()) {
501     QStringList aListId = QStringList::split(" ", theNewText, false);
502
503     if (send == LineEditElements)
504     {
505       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
506       SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
507       SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
508
509       myElementsId = new SMESH::long_array;
510       myElementsId->length( aListId.count() );
511       TColStd_MapOfInteger newIndices;
512       for (int i = 0; i < aListId.count(); i++) {
513         int id = aListId[ i ].toInt();
514         bool validId = false;
515         if ( id > 0 ) {
516           if ( aMesh ) {
517             const SMDS_MeshElement * e = aMesh->FindElement( id );
518             validId = ( e && e->GetType() == SMDSType );
519           } else {
520             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
521           }
522         }
523         if ( validId && newIndices.Add( id ))
524           myElementsId[ newIndices.Extent()-1 ] = id;
525       }
526       myElementsId->length( myNbOkElements = newIndices.Extent() );
527       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
528       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
529         aViewWindow->highlight( myIO, true, true );
530     }
531   }
532
533   CheckIsEnable();
534
535   myBusy = false;
536 }
537
538 //=================================================================================
539 // function : SelectionIntoArgument()
540 // purpose  : Called when selection as changed or other case
541 //=================================================================================
542 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
543 {
544   if (myBusy) return;
545
546   // return if dialog box is inactive
547   if (!GroupButtons->isEnabled())
548     return;
549
550   // clear
551   myActor = 0;
552   myIO.Nullify();
553   QString aString = "";
554
555   // set busy flag
556   myBusy = true;
557
558   myEditCurrentArgument->setText(aString);
559   myNbOkElements = 0;
560   myBusy = false;
561
562   // get selected mesh
563   SALOME_ListIO aList;
564   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
565   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
566   if (nbSel != 1)
567     return;
568
569   Handle(SALOME_InteractiveObject) IO = aList.First();
570   myMesh = SMESH::GetMeshByIO(IO);
571   if (myMesh->_is_nil())
572     return;
573   myIO = IO;
574   myActor = SMESH::FindActorByObject(myMesh);
575
576   if (myEditCurrentArgument == LineEditElements) {
577     int aNbElements = 0;
578
579     // MakeGroups is available if there are groups
580     if ( myMesh->NbGroups() == 0 ) {
581       MakeGroupsCheck->setChecked(false);
582       MakeGroupsCheck->setEnabled(false);
583     } else {
584       MakeGroupsCheck->setEnabled(true);
585     }
586
587     if (CheckBoxMesh->isChecked()) {
588       SMESH::ElementType neededType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
589
590       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
591
592       SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
593
594       if (!mesh->_is_nil()) { //MESH
595         // get elements from mesh
596           myElementsId = mesh->GetElementsByType(neededType);
597           aNbElements = myElementsId->length();
598       } else {
599         SMESH::SMESH_subMesh_var aSubMesh =
600           SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
601         
602         if (!aSubMesh->_is_nil()) { //SUBMESH
603           // get IDs from submesh
604           myElementsId = aSubMesh->GetElementsByType(neededType);
605           aNbElements = myElementsId->length();
606         } else {
607           SMESH::SMESH_GroupBase_var aGroup = 
608             SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
609
610           if (!aGroup->_is_nil() && aGroup->GetType() == neededType) { // GROUP
611             // get IDs from smesh group
612             myElementsId = aGroup->GetListOfID();
613             aNbElements = myElementsId->length();
614           }
615         }
616       }
617     } else {
618       // get indices of selcted elements
619       TColStd_IndexedMapOfInteger aMapIndex;
620       mySelector->GetIndex(IO,aMapIndex);
621       aNbElements = aMapIndex.Extent();
622
623       myElementsId = new SMESH::long_array;
624       myElementsId->length( aNbElements );
625       aString = "";
626       for ( int i = 0; i < aNbElements; ++i )
627         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
628     }
629
630     if (aNbElements < 1)
631       return;
632
633     myNbOkElements = true;
634   }
635
636   myBusy = true;
637   myEditCurrentArgument->setText(aString);
638   myBusy = false;
639
640   // OK
641   CheckIsEnable();
642 }
643
644 //=================================================================================
645 // function : SetEditCurrentArgument()
646 // purpose  :
647 //=================================================================================
648 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
649 {
650   QPushButton* send = (QPushButton*)sender();
651
652   disconnect(mySelectionMgr, 0, this, 0);
653   mySelectionMgr->clearSelected();
654   mySelectionMgr->clearFilters();
655
656   if (send == SelectElementsButton) {
657     myEditCurrentArgument = LineEditElements;
658     if (CheckBoxMesh->isChecked()) {
659       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
660         aViewWindow->SetSelectionMode(ActorSelection);
661       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
662     } else {
663       int aConstructorId = GetConstructorId();
664       if (aConstructorId == 0)
665         {
666           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
667             aViewWindow->SetSelectionMode(EdgeSelection);
668         }
669       else if (aConstructorId == 1)
670         {
671           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
672             aViewWindow->SetSelectionMode(FaceSelection);
673         }
674     }
675   }
676
677   myEditCurrentArgument->setFocus();
678   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
679   SelectionIntoArgument();
680 }
681
682 //=================================================================================
683 // function : DeactivateActiveDialog()
684 // purpose  : Deactivates this dialog
685 //=================================================================================
686 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
687 {
688   if (GroupConstructors->isEnabled()) {
689     GroupConstructors->setEnabled(false);
690     GroupArguments->setEnabled(false);
691     GroupButtons->setEnabled(false);
692     mySMESHGUI->ResetState();
693     mySMESHGUI->SetActiveDialogBox(0);
694   }
695 }
696
697 //=================================================================================
698 // function : ActivateThisDialog()
699 // purpose  : Activates this dialog
700 //=================================================================================
701 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
702 {
703   // Emit a signal to deactivate the active dialog
704   mySMESHGUI->EmitSignalDeactivateDialog();
705   GroupConstructors->setEnabled(true);
706   GroupArguments->setEnabled(true);
707   GroupButtons->setEnabled(true);
708
709   mySMESHGUI->SetActiveDialogBox(this);
710
711   ConstructorsClicked(GetConstructorId());
712   SelectionIntoArgument();
713 }
714
715 //=================================================================================
716 // function : enterEvent()
717 // purpose  : Mouse enter event
718 //=================================================================================
719 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
720 {
721   if (!GroupConstructors->isEnabled())
722     ActivateThisDialog();
723 }
724
725 //=================================================================================
726 // function : closeEvent()
727 // purpose  :
728 //=================================================================================
729 //void SMESHGUI_ExtrusionDlg::closeEvent (QCloseEvent*)
730 //{
731 //  /* same than click on cancel button */
732 //  this->ClickOnCancel();
733 //}
734 //
735 //=================================================================================
736 // function : hideEvent()
737 // purpose  : caused by ESC key
738 //=================================================================================
739 //void SMESHGUI_ExtrusionDlg::hideEvent (QHideEvent*)
740 //{
741 //  if (!isMinimized())
742 //    ClickOnCancel();
743 //}
744
745 //=================================================================================
746 // function : onSelectMesh()
747 // purpose  :
748 //=================================================================================
749 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
750 {
751   if (toSelectMesh)
752     TextLabelElements->setText(tr("SMESH_NAME"));
753   else
754     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
755
756   if (myEditCurrentArgument != LineEditElements) {
757     LineEditElements->clear();
758     return;
759   }
760
761   mySelectionMgr->clearFilters();
762
763   if (toSelectMesh) {
764     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
765       aViewWindow->SetSelectionMode(ActorSelection);
766     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
767     LineEditElements->setReadOnly(true);
768   } else {
769     int aConstructorId = GetConstructorId();
770     if (aConstructorId == 0)
771       {
772         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773           aViewWindow->SetSelectionMode(EdgeSelection);
774       }
775     else if (aConstructorId == 0)
776       {
777         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
778           aViewWindow->SetSelectionMode(FaceSelection);
779       }
780
781     LineEditElements->setReadOnly(false);
782     onTextChange(LineEditElements->text());
783   }
784
785   SelectionIntoArgument();
786 }
787
788 //=================================================================================
789 // function : GetConstructorId()
790 // purpose  :
791 //=================================================================================
792 int SMESHGUI_ExtrusionDlg::GetConstructorId()
793 {
794   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
795     return GroupConstructors->id(GroupConstructors->selected());
796   return -1;
797 }
798
799 //=================================================================================
800 // function : keyPressEvent()
801 // purpose  :
802 //=================================================================================
803 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
804 {
805   QDialog::keyPressEvent( e );
806   if ( e->isAccepted() )
807     return;
808
809   if ( e->key() == Key_F1 )
810     {
811       e->accept();
812       ClickOnHelp();
813     }
814 }