Salome HOME
12a09de26f7c217b5a29912ed612dccd0a82405a
[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   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments, 1, 0);
229
230   /* Initialisations */
231   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
232   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
233   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
234
235   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
236   SpinBox_NbSteps->setValidator(anIntValidator);
237   SpinBox_NbSteps->setRange(1, 999999);
238
239   GroupArguments->show();
240   RadioButton1->setChecked(TRUE);
241
242   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
243
244   mySMESHGUI->SetActiveDialogBox(this);
245
246   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
247   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
248   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
249
250   QPtrList<SUIT_SelectionFilter> aListOfFilters;
251   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
252   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
253
254   myMeshOrSubMeshOrGroupFilter =
255     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
256
257   myHelpFileName = "extrusion.htm";
258
259   Init();
260
261   /***************************************************************/
262   // signals and slots connections
263   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
264   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
265   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
266   connect(buttonHelp, SIGNAL(clicked()),  this, SLOT(ClickOnHelp()));
267
268   // to update state of the Ok & Apply buttons
269   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
270   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
271   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
272
273   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
274   connect(SelectElementsButton, SIGNAL (clicked()),            this, SLOT(SetEditCurrentArgument()));
275   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
276   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
277   /* to close dialog if study change */
278   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
279   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
280   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
281
282   /***************************************************************/
283   
284   this->show(); // displays Dialog
285
286   ConstructorsClicked(0);
287   SelectionIntoArgument();
288 }
289
290 //=================================================================================
291 // function : ~SMESHGUI_ExtrusionDlg()
292 // purpose  : destructor
293 //=================================================================================
294 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
295 {
296   // no need to delete child widgets, Qt does it all for us
297 }
298
299 //=================================================================================
300 // function : Init()
301 // purpose  : initialization
302 //=================================================================================
303 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
304 {
305   myBusy = false;
306
307   LineEditElements->clear();
308   myElementsId = "";
309   myNbOkElements = 0;
310
311   myActor = 0;
312   myMesh = SMESH::SMESH_Mesh::_nil();
313
314   if (ResetControls) {
315     SpinBox_NbSteps->setValue(1);
316     SpinBox_Dx->SetValue(0);
317     SpinBox_Dy->SetValue(0);
318     SpinBox_Dz->SetValue(0);
319
320     CheckBoxMesh->setChecked(false);
321     onSelectMesh(false);
322   }
323
324   CheckIsEnable();
325 }
326
327 //=================================================================================
328 // function : CheckIsEnable()
329 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
330 //=================================================================================
331 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
332 {
333   double aX = SpinBox_Dx->GetValue();
334   double aY = SpinBox_Dy->GetValue();
335   double aZ = SpinBox_Dz->GetValue();
336   double aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
337   
338   bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
339
340   buttonOk->setEnabled(anIsEnable);
341   buttonApply->setEnabled(anIsEnable);
342 }
343
344 //=================================================================================
345 // function : ConstructorsClicked()
346 // purpose  : Radio button management
347 //=================================================================================
348 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
349 {
350   disconnect(mySelectionMgr, 0, this, 0);
351
352   switch (constructorId) {
353   case 0:
354     {
355       GroupArguments->setTitle(tr("EXTRUSION_1D"));
356       if (!CheckBoxMesh->isChecked())
357         {
358           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
359             aViewWindow->SetSelectionMode(EdgeSelection);
360         }
361       break;
362     }
363   case 1:
364     {
365       GroupArguments->setTitle(tr("EXTRUSION_2D"));
366       if (!CheckBoxMesh->isChecked())
367         {
368           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
369             aViewWindow->SetSelectionMode(FaceSelection);
370         }
371       break;
372     }
373   }
374
375   myEditCurrentArgument = LineEditElements;
376   LineEditElements->setFocus();
377
378   if (CheckBoxMesh->isChecked())
379     onSelectMesh(true);
380
381   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
382 }
383
384 //=================================================================================
385 // function : ClickOnApply()
386 // purpose  : Called when user presses <Apply> button
387 //=================================================================================
388 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
389 {
390   if (mySMESHGUI->isActiveStudyLocked())
391     return false;
392
393   if (myNbOkElements) {
394     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
395
396     SMESH::long_array_var anElementsId = new SMESH::long_array;
397
398     anElementsId->length(aListElementsId.count());
399     for (int i = 0; i < aListElementsId.count(); i++)
400       anElementsId[i] = aListElementsId[i].toInt();
401
402     SMESH::DirStruct aVector;
403     aVector.PS.x = SpinBox_Dx->GetValue();
404     aVector.PS.y = SpinBox_Dy->GetValue();
405     aVector.PS.z = SpinBox_Dz->GetValue();
406
407     long aNbSteps = (long)SpinBox_NbSteps->value();
408
409     try {
410       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
411       QApplication::setOverrideCursor(Qt::waitCursor);
412       aMeshEditor->ExtrusionSweep(anElementsId.inout(), aVector, aNbSteps);
413       QApplication::restoreOverrideCursor();
414     } catch (...) {
415     }
416
417     SMESH::UpdateView();
418     Init(false);
419     ConstructorsClicked(GetConstructorId());
420     SelectionIntoArgument();
421   }
422   return true;
423 }
424
425 //=================================================================================
426 // function : ClickOnOk()
427 // purpose  : Called when user presses <OK> button
428 //=================================================================================
429 void SMESHGUI_ExtrusionDlg::ClickOnOk()
430 {
431   if (ClickOnApply())
432     ClickOnCancel();
433 }
434
435 //=================================================================================
436 // function : ClickOnCancel()
437 // purpose  : Called when dialog box is closed
438 //=================================================================================
439 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
440 {
441   disconnect(mySelectionMgr, 0, this, 0);
442   mySelectionMgr->clearFilters();
443   //mySelectionMgr->clearSelected();
444   SMESH::SetPickable(); // ???
445   SMESH::SetPointRepresentation(false);
446   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
447     aViewWindow->SetSelectionMode(ActorSelection);
448   mySMESHGUI->ResetState();
449   reject();
450 }
451
452 //=================================================================================
453 // function : ClickOnHelp()
454 // purpose  :
455 //=================================================================================
456 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
457 {
458   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
459   if (app) 
460     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
461   else {
462     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
463                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
464                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
465                            QObject::tr("BUT_OK"));
466   }
467 }
468
469 //=================================================================================
470 // function : onTextChange()
471 // purpose  :
472 //=================================================================================
473 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
474 {
475   QLineEdit* send = (QLineEdit*)sender();
476
477   // return if busy
478   if (myBusy) return;
479
480   // set busy flag
481   myBusy = true;
482
483   if (send == LineEditElements)
484     myNbOkElements = 0;
485
486   // hilight entered elements/nodes
487   SMDS_Mesh* aMesh = 0;
488   if (myActor)
489     aMesh = myActor->GetObject()->GetMesh();
490
491   if (aMesh) {
492     QStringList aListId = QStringList::split(" ", theNewText, false);
493
494     if (send == LineEditElements) {
495       const Handle(SALOME_InteractiveObject)& anIO = myActor->getIO();
496       TColStd_MapOfInteger newIndices;
497       for (int i = 0; i < aListId.count(); i++) {
498         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
499         if (e)
500           newIndices.Add(e->GetID());
501         myNbOkElements++;
502       }
503       mySelector->AddOrRemoveIndex(anIO, newIndices, false);
504       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
505         aViewWindow->highlight( anIO, true, true );
506       myElementsId = theNewText;
507     }
508   }
509
510   CheckIsEnable();
511
512   myBusy = false;
513 }
514
515 //=================================================================================
516 // function : SelectionIntoArgument()
517 // purpose  : Called when selection as changed or other case
518 //=================================================================================
519 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
520 {
521   if (myBusy) return;
522
523   // return if dialog box is inactive
524   if (!GroupButtons->isEnabled())
525     return;
526
527   // clear
528   myActor = 0;
529   QString aString = "";
530
531   // set busy flag
532   myBusy = true;
533
534   myEditCurrentArgument->setText(aString);
535   myNbOkElements = 0;
536   myBusy = false;
537
538   // get selected mesh
539   SALOME_ListIO aList;
540   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
541   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
542   if (nbSel != 1)
543     return;
544
545   Handle(SALOME_InteractiveObject) IO = aList.First();
546   myMesh = SMESH::GetMeshByIO(IO);
547   if (myMesh->_is_nil())
548     return;
549
550   myActor = SMESH::FindActorByObject(myMesh);
551   if (!myActor)
552     return;
553
554   if (myEditCurrentArgument == LineEditElements) {
555     int aNbElements = 0;
556     myElementsId = "";
557
558     if (CheckBoxMesh->isChecked()) {
559       int aConstructorId = GetConstructorId();
560
561       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
562
563       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
564         // get IDs from mesh
565         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
566         if (!aSMDSMesh)
567           return;
568
569         if (aConstructorId == 0) {
570           SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
571
572           while (anIter->more()) {
573             const SMDS_MeshEdge * edge = anIter->next();
574             if (edge) {
575               myElementsId += QString(" %1").arg(edge->GetID());
576               aNbElements++;
577             }
578           }
579         } else if (aConstructorId == 1) {
580           SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();
581           while (anIter->more()) {
582             const SMDS_MeshFace * face = anIter->next();
583             if (face) {
584               myElementsId += QString(" %1").arg(face->GetID());
585               aNbElements++;
586             }
587           }
588         }
589       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
590         // get submesh
591         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
592
593         // get IDs from submesh
594         SMESH::long_array_var anElementsIds = new SMESH::long_array;
595         if (aConstructorId == 0)
596           anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
597         else if (aConstructorId == 1)
598           anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
599
600         for (int i = 0; i < anElementsIds->length(); i++)
601           myElementsId += QString(" %1").arg(anElementsIds[i]);
602         aNbElements = anElementsIds->length();
603       } else { // GROUP
604         // get smesh group
605         SMESH::SMESH_GroupBase_var aGroup =
606           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
607         if (aGroup->_is_nil())
608           return;
609
610         if ((aConstructorId == 0 && aGroup->GetType() != SMESH::EDGE) ||
611             (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE))
612           return;
613
614         // get IDs from smesh group
615         SMESH::long_array_var anElementsIds = new SMESH::long_array;
616         anElementsIds = aGroup->GetListOfID();
617         for (int i = 0; i < anElementsIds->length(); i++)
618           myElementsId += QString(" %1").arg(anElementsIds[i]);
619         aNbElements = anElementsIds->length();
620       }
621     } else {
622       aNbElements = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
623       myElementsId = aString;
624     }
625
626     if (aNbElements < 1)
627       return;
628
629     myNbOkElements = true;
630   }
631
632   myBusy = true;
633   myEditCurrentArgument->setText(aString);
634   myBusy = false;
635
636   // OK
637   CheckIsEnable();
638 }
639
640 //=================================================================================
641 // function : SetEditCurrentArgument()
642 // purpose  :
643 //=================================================================================
644 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
645 {
646   QPushButton* send = (QPushButton*)sender();
647
648   disconnect(mySelectionMgr, 0, this, 0);
649   mySelectionMgr->clearSelected();
650   mySelectionMgr->clearFilters();
651
652   if (send == SelectElementsButton) {
653     myEditCurrentArgument = LineEditElements;
654     if (CheckBoxMesh->isChecked()) {
655       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
656         aViewWindow->SetSelectionMode(ActorSelection);
657       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
658     } else {
659       int aConstructorId = GetConstructorId();
660       if (aConstructorId == 0)
661         {
662           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
663             aViewWindow->SetSelectionMode(EdgeSelection);
664         }
665       else if (aConstructorId == 1)
666         {
667           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
668             aViewWindow->SetSelectionMode(FaceSelection);
669         }
670     }
671   }
672
673   myEditCurrentArgument->setFocus();
674   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
675   SelectionIntoArgument();
676 }
677
678 //=================================================================================
679 // function : DeactivateActiveDialog()
680 // purpose  : Deactivates this dialog
681 //=================================================================================
682 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
683 {
684   if (GroupConstructors->isEnabled()) {
685     GroupConstructors->setEnabled(false);
686     GroupArguments->setEnabled(false);
687     GroupButtons->setEnabled(false);
688     mySMESHGUI->ResetState();
689     mySMESHGUI->SetActiveDialogBox(0);
690   }
691 }
692
693 //=================================================================================
694 // function : ActivateThisDialog()
695 // purpose  : Activates this dialog
696 //=================================================================================
697 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
698 {
699   // Emit a signal to deactivate the active dialog
700   mySMESHGUI->EmitSignalDeactivateDialog();
701   GroupConstructors->setEnabled(true);
702   GroupArguments->setEnabled(true);
703   GroupButtons->setEnabled(true);
704
705   mySMESHGUI->SetActiveDialogBox(this);
706
707   ConstructorsClicked(GetConstructorId());
708   SelectionIntoArgument();
709 }
710
711 //=================================================================================
712 // function : enterEvent()
713 // purpose  : Mouse enter event
714 //=================================================================================
715 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
716 {
717   if (!GroupConstructors->isEnabled())
718     ActivateThisDialog();
719 }
720
721 //=================================================================================
722 // function : closeEvent()
723 // purpose  :
724 //=================================================================================
725 //void SMESHGUI_ExtrusionDlg::closeEvent (QCloseEvent*)
726 //{
727 //  /* same than click on cancel button */
728 //  this->ClickOnCancel();
729 //}
730 //
731 //=================================================================================
732 // function : hideEvent()
733 // purpose  : caused by ESC key
734 //=================================================================================
735 //void SMESHGUI_ExtrusionDlg::hideEvent (QHideEvent*)
736 //{
737 //  if (!isMinimized())
738 //    ClickOnCancel();
739 //}
740
741 //=================================================================================
742 // function : onSelectMesh()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
746 {
747   if (toSelectMesh)
748     TextLabelElements->setText(tr("SMESH_NAME"));
749   else
750     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
751
752   if (myEditCurrentArgument != LineEditElements) {
753     LineEditElements->clear();
754     return;
755   }
756
757   mySelectionMgr->clearFilters();
758
759   if (toSelectMesh) {
760     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
761       aViewWindow->SetSelectionMode(ActorSelection);
762     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
763     LineEditElements->setReadOnly(true);
764   } else {
765     int aConstructorId = GetConstructorId();
766     if (aConstructorId == 0)
767       {
768         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
769           aViewWindow->SetSelectionMode(EdgeSelection);
770       }
771     else if (aConstructorId == 0)
772       {
773         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
774           aViewWindow->SetSelectionMode(FaceSelection);
775       }
776
777     LineEditElements->setReadOnly(false);
778     onTextChange(LineEditElements->text());
779   }
780
781   SelectionIntoArgument();
782 }
783
784 //=================================================================================
785 // function : GetConstructorId()
786 // purpose  :
787 //=================================================================================
788 int SMESHGUI_ExtrusionDlg::GetConstructorId()
789 {
790   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
791     return GroupConstructors->id(GroupConstructors->selected());
792   return -1;
793 }
794
795 //=================================================================================
796 // function : keyPressEvent()
797 // purpose  :
798 //=================================================================================
799 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
800 {
801   QDialog::keyPressEvent( e );
802   if ( e->isAccepted() )
803     return;
804
805   if ( e->key() == Key_F1 )
806     {
807       e->accept();
808       ClickOnHelp();
809     }
810 }