Salome HOME
Dump Python extension
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SmoothingDlg.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 // File   : SMESHGUI_SmoothingDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_SmoothingDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_OverrideCursor.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51
52 #include <SalomeApp_IntSpinBox.h>
53
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_Selector.h>
56 #include <SVTK_ViewWindow.h>
57 #include <SVTK_Selection.h>
58 #include <SALOME_ListIO.hxx>
59
60 // OCCT includes
61 #include <TColStd_MapOfInteger.hxx>
62
63 // Qt includes
64 #include <QApplication>
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QComboBox>
71 #include <QCheckBox>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
75 #include <QKeyEvent>
76 #include <QButtonGroup>
77
78 // IDL includes
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82
83 #define SPACING 6
84 #define MARGIN  11
85
86 //=================================================================================
87 // function : SMESHGUI_SmoothingDlg()
88 // purpose  : constructor
89 //=================================================================================
90 SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
91   : QDialog( SMESH::GetDesktop( theModule ) ),
92     mySMESHGUI( theModule ),
93     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
94 {
95   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
96   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97
98   setModal(false);
99   setAttribute(Qt::WA_DeleteOnClose, true);
100   setWindowTitle(tr("SMESH_SMOOTHING"));
101   setSizeGripEnabled(true);
102
103   /***************************************************************/
104   QVBoxLayout* SMESHGUI_SmoothingDlgLayout = new QVBoxLayout(this);
105   SMESHGUI_SmoothingDlgLayout->setSpacing(SPACING);
106   SMESHGUI_SmoothingDlgLayout->setMargin(MARGIN);
107
108   /***************************************************************/
109   GroupConstructors = new QGroupBox(tr("SMESH_SMOOTHING"), this);
110   QButtonGroup* ButtonGroup = new QButtonGroup(this);
111   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
112   GroupConstructorsLayout->setSpacing(SPACING);
113   GroupConstructorsLayout->setMargin(MARGIN);
114
115   Constructor1 = new QRadioButton(GroupConstructors);
116   Constructor1->setIcon(image0);
117   Constructor1->setChecked(true);
118   GroupConstructorsLayout->addWidget(Constructor1);
119   ButtonGroup->addButton(Constructor1, 0);
120
121   /***************************************************************/
122   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
123   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
124   GroupArgumentsLayout->setSpacing(SPACING);
125   GroupArgumentsLayout->setMargin(MARGIN);
126
127   myIdValidator = new SMESHGUI_IdValidator(this);
128
129   // Controls for elements selection
130   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
131
132   SelectElementsButton = new QPushButton(GroupArguments);
133   SelectElementsButton->setIcon(image1);
134
135   LineEditElements = new QLineEdit(GroupArguments);
136   LineEditElements->setValidator(myIdValidator);
137
138   // Control for the whole mesh selection
139   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
140
141   // Controls for nodes selection
142   TextLabelNodes = new QLabel(tr("FIXED_NODES_IDS"), GroupArguments);
143
144   SelectNodesButton  = new QPushButton(GroupArguments);
145   SelectNodesButton->setIcon(image1);
146
147   LineEditNodes  = new QLineEdit(GroupArguments);
148   LineEditNodes->setValidator(myIdValidator);
149
150   // Controls for method selection
151   TextLabelMethod = new QLabel(tr("METHOD"), GroupArguments);
152
153   ComboBoxMethod = new QComboBox(GroupArguments);
154
155   // Controls for iteration limit defining
156   TextLabelLimit = new QLabel(tr("ITERATION_LIMIT"), GroupArguments);
157
158   SpinBox_IterationLimit = new SalomeApp_IntSpinBox(GroupArguments);
159
160   // Controls for max. aspect ratio defining
161   TextLabelAspectRatio = new QLabel(tr("MAX_ASPECT_RATIO"), GroupArguments);
162
163   SpinBox_AspectRatio = new SMESHGUI_SpinBox(GroupArguments);
164
165   // Check box "Is Parametric"
166   CheckBoxParametric = new QCheckBox( tr("IS_PARAMETRIC"), GroupArguments );
167
168   GroupArgumentsLayout->addWidget(TextLabelElements,      0, 0);
169   GroupArgumentsLayout->addWidget(SelectElementsButton,   0, 1);
170   GroupArgumentsLayout->addWidget(LineEditElements,       0, 2);
171   GroupArgumentsLayout->addWidget(CheckBoxMesh,           1, 0, 1, 3);
172   GroupArgumentsLayout->addWidget(TextLabelNodes,         2, 0);
173   GroupArgumentsLayout->addWidget(SelectNodesButton,      2, 1);
174   GroupArgumentsLayout->addWidget(LineEditNodes,          2, 2);
175   GroupArgumentsLayout->addWidget(TextLabelMethod,        3, 0);
176   GroupArgumentsLayout->addWidget(ComboBoxMethod,         3, 2);
177   GroupArgumentsLayout->addWidget(TextLabelLimit,         4, 0);
178   GroupArgumentsLayout->addWidget(SpinBox_IterationLimit, 4, 2);
179   GroupArgumentsLayout->addWidget(TextLabelAspectRatio,   5, 0);
180   GroupArgumentsLayout->addWidget(SpinBox_AspectRatio,    5, 2);
181   GroupArgumentsLayout->addWidget(CheckBoxParametric,     6, 0, 1, 3);
182
183   /***************************************************************/
184   GroupButtons = new QGroupBox(this);
185   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
186   GroupButtonsLayout->setSpacing(SPACING);
187   GroupButtonsLayout->setMargin(MARGIN);
188
189   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
190   buttonOk->setAutoDefault(true);
191   buttonOk->setDefault(true);
192   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
193   buttonApply->setAutoDefault(true);
194   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
195   buttonCancel->setAutoDefault(true);
196   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
197   buttonHelp->setAutoDefault(true);
198
199   GroupButtonsLayout->addWidget(buttonOk);
200   GroupButtonsLayout->addSpacing(10);
201   GroupButtonsLayout->addWidget(buttonApply);
202   GroupButtonsLayout->addSpacing(10);
203   GroupButtonsLayout->addStretch();
204   GroupButtonsLayout->addWidget(buttonCancel);
205   GroupButtonsLayout->addWidget(buttonHelp);
206
207   /***************************************************************/
208   SMESHGUI_SmoothingDlgLayout->addWidget(GroupConstructors);
209   SMESHGUI_SmoothingDlgLayout->addWidget(GroupArguments);
210   SMESHGUI_SmoothingDlgLayout->addWidget(GroupButtons);
211
212   /***************************************************************/
213   /* Initialisations */
214   ComboBoxMethod->addItem(tr("LAPLACIAN"));
215   ComboBoxMethod->addItem(tr("CENTROIDAL"));
216
217   ComboBoxMethod->setCurrentIndex(0);
218
219   CheckBoxParametric->setChecked( true );
220   
221   SpinBox_IterationLimit->setRange(1, 999999);
222   SpinBox_IterationLimit->setValue(20);
223   SpinBox_AspectRatio->RangeStepAndValidator(0.0, +999999.999, 0.1, 3);
224   SpinBox_AspectRatio->SetValue(1.1);
225
226   GroupArguments->show();
227   myConstructorId = 0;
228   Constructor1->setChecked(true);
229   
230   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
231
232   mySMESHGUI->SetActiveDialogBox(this);
233
234   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
235   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
236   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
237
238   QList<SUIT_SelectionFilter*> aListOfFilters;
239   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
240   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
241
242   myMeshOrSubMeshOrGroupFilter =
243     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
244
245   myHelpFileName = "smoothing_page.html";
246
247   Init();
248
249   /***************************************************************/
250   // signals and slots connections
251   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
252   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
253   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
254   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
255
256   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
257   connect(SelectNodesButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
258   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
259   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260   /* to close dialog if study change */
261   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
262   connect(LineEditElements, SIGNAL(textChanged(const QString&)),
263            SLOT(onTextChange(const QString&)));
264   connect(LineEditNodes, SIGNAL(textChanged(const QString&)),
265            SLOT(onTextChange(const QString&)));
266   connect(CheckBoxMesh, SIGNAL(toggled(bool)),
267            SLOT(onSelectMesh(bool)));
268 }
269
270 //=================================================================================
271 // function : ~SMESHGUI_SmoothingDlg()
272 // purpose  : destructor
273 //=================================================================================
274 SMESHGUI_SmoothingDlg::~SMESHGUI_SmoothingDlg()
275 {
276   // no need to delete child widgets, Qt does it all for us
277 }
278
279 //=================================================================================
280 // function : Init()
281 // purpose  : initialization
282 //=================================================================================
283 void SMESHGUI_SmoothingDlg::Init()
284 {
285   myBusy = false;
286
287 //   ComboBoxMethod->setCurrentItem(0);
288
289 //   SpinBox_IterationLimit->setValue(20);
290 //   SpinBox_AspectRatio->SetValue(1.1);
291
292   myEditCurrentArgument = LineEditElements;
293   LineEditElements->setFocus();
294   LineEditElements->clear();
295   LineEditNodes->clear();
296   myElementsId = "";
297   myNbOkElements = 0;
298   myNbOkNodes = 0;
299   myActor     = 0;
300   myMesh = SMESH::SMESH_Mesh::_nil();
301
302   CheckBoxMesh->setChecked(false);
303   onSelectMesh(false);
304 }
305
306 //=================================================================================
307 // function : ClickOnApply()
308 // purpose  : Called when user presses <Apply> button
309 //=================================================================================
310 bool SMESHGUI_SmoothingDlg::ClickOnApply()
311 {
312   if (mySMESHGUI->isActiveStudyLocked())
313     return false;
314
315   if (!isValid())
316     return false;
317
318   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
319     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
320     QStringList aListNodesId    = LineEditNodes->text().split(" ", QString::SkipEmptyParts);
321
322     SMESH::long_array_var anElementsId = new SMESH::long_array;
323     SMESH::long_array_var aNodesId = new SMESH::long_array;
324
325     anElementsId->length(aListElementsId.count());
326     for (int i = 0; i < aListElementsId.count(); i++)
327       anElementsId[i] = aListElementsId[i].toInt();
328
329     if ( myNbOkNodes && aListNodesId.count() > 0 ) {
330       aNodesId->length(aListNodesId.count());
331       for (int i = 0; i < aListNodesId.count(); i++)
332         aNodesId[i] = aListNodesId[i].toInt();
333     } else {
334       aNodesId->length(0);
335     }
336
337     long anIterationLimit = (long)SpinBox_IterationLimit->value();
338     double aMaxAspectRatio = SpinBox_AspectRatio->GetValue();
339
340     QStringList aParameters;
341     aParameters << SpinBox_IterationLimit->text();
342     aParameters << SpinBox_AspectRatio->text();
343
344     SMESH::SMESH_MeshEditor::Smooth_Method aMethod = SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH;
345     if (ComboBoxMethod->currentIndex() > 0)
346       aMethod =  SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH;
347
348     bool aResult = false;
349     try {
350       SUIT_OverrideCursor aWaitCursor;
351       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
352
353       if ( CheckBoxParametric->isChecked() )
354         aResult = aMeshEditor->SmoothParametric(anElementsId.inout(), aNodesId.inout(),
355                                                 anIterationLimit, aMaxAspectRatio, aMethod);
356       else
357         aResult = aMeshEditor->Smooth(anElementsId.inout(), aNodesId.inout(),
358                                       anIterationLimit, aMaxAspectRatio, aMethod);
359
360       myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
361
362     } catch (...) {
363     }
364
365     if (aResult) {
366       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
367
368       SALOME_ListIO aList;
369       aList.Append(anIO);
370       mySelectionMgr->setSelectedObjects(aList, false);
371       SMESH::UpdateView();
372       Init();
373     }
374   }
375
376   return true;
377 }
378
379 //=================================================================================
380 // function : ClickOnOk()
381 // purpose  : Called when user presses <OK> button
382 //=================================================================================
383 void SMESHGUI_SmoothingDlg::ClickOnOk()
384 {
385   if( ClickOnApply() )
386     ClickOnCancel();
387 }
388
389 //=================================================================================
390 // function : ClickOnCancel()
391 // purpose  : Called when dialog box is closed
392 //=================================================================================
393 void SMESHGUI_SmoothingDlg::ClickOnCancel()
394 {
395   disconnect(mySelectionMgr, 0, this, 0);
396   mySelectionMgr->clearFilters();
397   //mySelectionMgr->clearSelected();
398   SMESH::SetPickable(); // ???
399   SMESH::SetPointRepresentation(false);
400   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
401     aViewWindow->SetSelectionMode(ActorSelection);
402   mySMESHGUI->ResetState();
403   reject();
404 }
405
406 //=================================================================================
407 // function : ClickOnHelp()
408 // purpose  :
409 //=================================================================================
410 void SMESHGUI_SmoothingDlg::ClickOnHelp()
411 {
412   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
413   if (app) 
414     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
415   else {
416     QString platform;
417 #ifdef WIN32
418     platform = "winapplication";
419 #else
420     platform = "application";
421 #endif
422     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
423                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
424                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
425                                                                  platform)).
426                              arg(myHelpFileName));
427   }
428 }
429
430 //=======================================================================
431 // function : onTextChange()
432 // purpose  :
433 //=======================================================================
434 void SMESHGUI_SmoothingDlg::onTextChange (const QString& theNewText)
435 {
436   QLineEdit* send = (QLineEdit*)sender();
437
438   // return if busy
439   if (myBusy) return;
440
441   // set busy flag
442   myBusy = true;
443
444   if (send == LineEditElements)
445     myNbOkElements = 0;
446   else if (send == LineEditNodes)
447     myNbOkNodes = 0;
448
449   buttonOk->setEnabled(false);
450   buttonApply->setEnabled(false);
451
452   // hilight entered elements/nodes
453   SMDS_Mesh* aMesh = 0;
454   if (myActor)
455     aMesh = myActor->GetObject()->GetMesh();
456
457   if (aMesh) {
458     
459     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
460
461     if (send == LineEditElements) {
462       const Handle(SALOME_InteractiveObject)& anIO = myActor->getIO();
463       TColStd_MapOfInteger newIndices;
464       for (int i = 0; i < aListId.count(); i++) {
465         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
466         if (e)
467           newIndices.Add(e->GetID());
468         myNbOkElements++;
469       }
470       mySelector->AddOrRemoveIndex(anIO, newIndices, false);
471       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
472         aViewWindow->highlight( anIO, true, true );
473       myElementsId = theNewText;
474
475     } else if (send == LineEditNodes) {
476       TColStd_MapOfInteger newIndices;
477       
478       for (int i = 0; i < aListId.count(); i++) {
479         const SMDS_MeshNode * n = aMesh->FindNode(aListId[ i ].toInt());
480         if (n)
481           newIndices.Add(n->GetID());
482         myNbOkNodes++;
483       }
484       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
485       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
486         aViewWindow->highlight( myActor->getIO(), true, true );
487     }
488   }
489
490   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
491     buttonOk->setEnabled(true);
492     buttonApply->setEnabled(true);
493   }
494
495   myBusy = false;
496 }
497
498 //=================================================================================
499 // function : SelectionIntoArgument()
500 // purpose  : Called when selection as changed or other case
501 //=================================================================================
502 void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
503 {
504   if (myBusy) return;
505
506   // clear
507   QString aString = "";
508
509   myBusy = true;
510   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
511     LineEditElements->setText(aString);
512     myNbOkElements = 0;
513     buttonOk->setEnabled(false);
514     buttonApply->setEnabled(false);
515     myActor = 0;
516   }
517   myBusy = false;
518
519   if (!GroupButtons->isEnabled()) // inactive
520     return;
521
522   // get selected mesh
523   SALOME_ListIO aList;
524   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
525   int nbSel = aList.Extent();
526   if (nbSel != 1)
527     return;
528
529   Handle(SALOME_InteractiveObject) IO = aList.First();
530   myMesh = SMESH::GetMeshByIO(IO);
531   if (myMesh->_is_nil())
532     return;
533
534   myActor = SMESH::FindActorByObject(myMesh);
535   if (!myActor)
536     return;
537
538   int aNbUnits = 0;
539
540   if (myEditCurrentArgument == LineEditElements) {
541     myElementsId = "";
542
543     if (CheckBoxMesh->isChecked()) {
544       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
545
546       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
547         // get IDs from mesh
548         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
549         if (!aSMDSMesh)
550           return;
551
552         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++ ) {
553           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
554           if (e) {
555             myElementsId += QString(" %1").arg(i);
556             aNbUnits++;
557           }
558         }
559       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
560         // get submesh
561         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
562
563         // get IDs from submesh
564         SMESH::long_array_var anElementsIds = new SMESH::long_array;
565         anElementsIds = aSubMesh->GetElementsId();
566         for (int i = 0; i < anElementsIds->length(); i++) {
567           myElementsId += QString(" %1").arg(anElementsIds[i]);
568         }
569         aNbUnits = anElementsIds->length();
570       } else { // GROUP
571         // get smesh group
572         SMESH::SMESH_GroupBase_var aGroup =
573           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
574         if (aGroup->_is_nil())
575           return;
576
577         // get IDs from smesh group
578         SMESH::long_array_var anElementsIds = new SMESH::long_array;
579         anElementsIds = aGroup->GetListOfID();
580         for (int i = 0; i < anElementsIds->length(); i++) {
581           myElementsId += QString(" %1").arg(anElementsIds[i]);
582         }
583         aNbUnits = anElementsIds->length();
584       }
585     } else {
586       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
587       myElementsId = aString;
588     }
589   } else if (myEditCurrentArgument == LineEditNodes && !myMesh->_is_nil() && myActor) {
590     myNbOkNodes = 0;
591     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
592   } else {
593   }
594
595   if (aNbUnits < 1)
596     return;
597
598   myBusy = true;
599   myEditCurrentArgument->setText(aString);
600   myBusy = false;
601
602   // OK
603   if (myEditCurrentArgument == LineEditElements)
604     myNbOkElements = true;
605   else if (myEditCurrentArgument == LineEditNodes)
606     myNbOkNodes = true;
607
608   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
609     buttonOk->setEnabled(true);
610     buttonApply->setEnabled(true);
611   }
612 }
613
614 //=================================================================================
615 // function : SetEditCurrentArgument()
616 // purpose  :
617 //=================================================================================
618 void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
619 {
620   QPushButton* send = (QPushButton*)sender();
621
622   switch (myConstructorId) {
623   case 0: /* default constructor */
624     {
625       disconnect(mySelectionMgr, 0, this, 0);
626       mySelectionMgr->clearSelected();
627       mySelectionMgr->clearFilters();
628
629       if (send == SelectElementsButton) {
630         myEditCurrentArgument = LineEditElements;
631         SMESH::SetPointRepresentation(false);
632         if (CheckBoxMesh->isChecked()) {
633           //          mySelectionMgr->setSelectionModes(ActorSelection);
634           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
635             aViewWindow->SetSelectionMode(ActorSelection);
636           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
637         } else {
638           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
639             aViewWindow->SetSelectionMode(FaceSelection);
640         }
641       } else if (send == SelectNodesButton) {
642         LineEditNodes->clear();
643         myEditCurrentArgument = LineEditNodes;
644         SMESH::SetPointRepresentation(true);
645         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
646           aViewWindow->SetSelectionMode(NodeSelection);
647         }
648       }
649
650       myEditCurrentArgument->setFocus();
651       connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
652       SelectionIntoArgument();
653       break;
654     }
655   }
656 }
657
658 //=================================================================================
659 // function : DeactivateActiveDialog()
660 // purpose  : Deactivates this dialog
661 //=================================================================================
662 void SMESHGUI_SmoothingDlg::DeactivateActiveDialog()
663 {
664   if (GroupConstructors->isEnabled()) {
665     GroupConstructors->setEnabled(false);
666     GroupArguments->setEnabled(false);
667     GroupButtons->setEnabled(false);
668     mySMESHGUI->ResetState();
669     mySMESHGUI->SetActiveDialogBox(0);
670   }
671 }
672
673 //=================================================================================
674 // function : ActivateThisDialog()
675 // purpose  : Activates this dialog
676 //=================================================================================
677 void SMESHGUI_SmoothingDlg::ActivateThisDialog()
678 {
679   // Emit a signal to deactivate the active dialog
680   mySMESHGUI->EmitSignalDeactivateDialog();
681   GroupConstructors->setEnabled(true);
682   GroupArguments->setEnabled(true);
683   GroupButtons->setEnabled(true);
684
685   mySMESHGUI->SetActiveDialogBox(this);
686   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
687     aViewWindow->SetSelectionMode(FaceSelection);
688   SelectionIntoArgument();
689 }
690
691 //=================================================================================
692 // function : enterEvent()
693 // purpose  : Mouse enter event
694 //=================================================================================
695 void SMESHGUI_SmoothingDlg::enterEvent (QEvent*)
696 {
697   if (!GroupConstructors->isEnabled())
698     ActivateThisDialog();
699 }
700
701 //=================================================================================
702 // function : closeEvent()
703 // purpose  :
704 //=================================================================================
705 void SMESHGUI_SmoothingDlg::closeEvent (QCloseEvent*)
706 {
707   /* same than click on cancel button */
708   ClickOnCancel();
709 }
710
711 //=======================================================================
712 // function : hideEvent()
713 // purpose  : caused by ESC key
714 //=======================================================================
715 void SMESHGUI_SmoothingDlg::hideEvent (QHideEvent*)
716 {
717   if (!isMinimized())
718     ClickOnCancel();
719 }
720
721 //=======================================================================
722 // function : onSelectMesh()
723 // purpose  :
724 //=======================================================================
725 void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
726 {
727   if (toSelectMesh)
728     TextLabelElements->setText(tr("SMESH_NAME"));
729   else
730     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
731
732   if (myEditCurrentArgument != LineEditElements) {
733     LineEditElements->clear();
734     return;
735   }
736
737   mySelectionMgr->clearFilters();
738   SMESH::SetPointRepresentation(false);
739
740   if (toSelectMesh) {
741     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
742       aViewWindow->SetSelectionMode(ActorSelection);
743     //    mySelectionMgr->setSelectionModes(ActorSelection);
744     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
745     LineEditElements->setReadOnly(true);
746     LineEditElements->setValidator(0);
747   } else {
748     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
749       aViewWindow->SetSelectionMode(FaceSelection);
750     LineEditElements->setReadOnly(false);
751     LineEditElements->setValidator(myIdValidator);
752     onTextChange(LineEditElements->text());
753   }
754
755   SelectionIntoArgument();
756 }
757
758 //=================================================================================
759 // function : keyPressEvent()
760 // purpose  :
761 //=================================================================================
762 void SMESHGUI_SmoothingDlg::keyPressEvent( QKeyEvent* e )
763 {
764   QDialog::keyPressEvent( e );
765   if ( e->isAccepted() )
766     return;
767
768   if ( e->key() == Qt::Key_F1 ) {
769     e->accept();
770     ClickOnHelp();
771   }
772 }
773
774 //=================================================================================
775 // function : isValid
776 // purpose  :
777 //=================================================================================
778 bool SMESHGUI_SmoothingDlg::isValid()
779 {
780   QString msg;
781   bool ok = true;
782   ok = SpinBox_IterationLimit->isValid( msg, true ) && ok;
783   ok = SpinBox_AspectRatio->isValid( msg, true ) && ok;
784
785   if( !ok ) {
786     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
787     if ( !msg.isEmpty() )
788       str += "\n" + msg;
789     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
790     return false;
791   }
792   return true;
793 }