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