Salome HOME
3eb8b7138757bd22bc5e208a87015bab4d5ce271
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ScaleDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // SMESH SMESHGUI : GUI for SMESH component
21 // File   : SMESHGUI_ScaleDlg.cxx
22 // Author : Michael ZORIN, Open CASCADE S.A.S.
23 // SMESH includes
24 //
25 #include "SMESHGUI_ScaleDlg.h"
26
27 #include "SMESHGUI.h"
28 #include "SMESHGUI_SpinBox.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_FilterDlg.h"
34
35 #include <SMESH_Actor.h>
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_LogicalFilter.hxx>
38 #include <SMDS_Mesh.hxx>
39
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
46
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
53
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
56
57 // OCCT includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // Qt includes
61 #include <QApplication>
62 #include <QButtonGroup>
63 #include <QGroupBox>
64 #include <QLabel>
65 #include <QLineEdit>
66 #include <QPushButton>
67 #include <QRadioButton>
68 #include <QCheckBox>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
72 #include <QSpinBox>
73 #include <QKeyEvent>
74
75 // IDL includes
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
81
82 /*!
83   \class BusyLocker
84   \brief Simple 'busy state' flag locker.
85   \internal
86 */
87
88 class BusyLocker
89 {
90 public:
91   //! Constructor. Sets passed boolean flag to \c true.
92   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
93   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
94   ~BusyLocker() { myBusy = false; }
95 private:
96   bool& myBusy; //! External 'busy state' boolean flag
97 };
98
99 #define SPACING 6
100 #define MARGIN  11
101
102 //=================================================================================
103 // class    : SMESHGUI_ScaleDlg()
104 // purpose  :
105 //=================================================================================
106 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
107   : QDialog( SMESH::GetDesktop( theModule ) ),
108     mySMESHGUI( theModule ),
109     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
110     myFilterDlg(0),
111     mySelectedObject(SMESH::SMESH_IDSource::_nil())
112 {
113   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
114   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
115   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
116
117   setModal(false);
118   setAttribute(Qt::WA_DeleteOnClose, true);
119   setWindowTitle(tr("SMESH_SCALE_TITLE"));
120   setSizeGripEnabled(true);
121
122   QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
123   SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
124   SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
125
126   /***************************************************************/
127   ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
128   GroupConstructors = new QButtonGroup(this);
129   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
130   ConstructorsBoxLayout->setSpacing(SPACING);
131   ConstructorsBoxLayout->setMargin(MARGIN);
132
133   RadioButton1= new QRadioButton(ConstructorsBox);
134   RadioButton1->setIcon(image0);
135   RadioButton2= new QRadioButton(ConstructorsBox);
136   RadioButton2->setIcon(image1);
137
138   ConstructorsBoxLayout->addWidget(RadioButton1);
139   ConstructorsBoxLayout->addWidget(RadioButton2);
140   GroupConstructors->addButton(RadioButton1, 0);
141   GroupConstructors->addButton(RadioButton2, 1);
142
143   /***************************************************************/
144   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
145   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
146   GroupArgumentsLayout->setSpacing(SPACING);
147   GroupArgumentsLayout->setMargin(MARGIN);
148
149   myIdValidator = new SMESHGUI_IdValidator(this);
150
151   // Controls for elements selection
152   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
153   SelectElementsButton = new QPushButton(GroupArguments);
154   SelectElementsButton->setIcon(image2);
155   LineEditElements = new QLineEdit(GroupArguments);
156   LineEditElements->setValidator(myIdValidator);
157   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
158   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
159
160   // Control for the whole mesh selection
161   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
162
163   // Controls for vector and points selection
164   TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
165   SelectButton1 = new QPushButton(GroupArguments);
166   SelectButton1->setIcon(image2);
167
168   TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
169   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
170   TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
171   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
172   TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
173   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
174
175   TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
176   SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
177
178   TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
179   SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
180
181   TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
182   SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
183
184
185   // switch of action type
186   ActionBox = new QGroupBox(GroupArguments);
187   ActionGroup = new QButtonGroup(GroupArguments);
188   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
189   ActionBoxLayout->addSpacing(SPACING);
190   ActionBoxLayout->setMargin(MARGIN);
191
192   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
193   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
194   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
195
196   ActionBoxLayout->addWidget(aMoveElements);
197   ActionBoxLayout->addWidget(aCopyElements);
198   ActionBoxLayout->addWidget(aCreateMesh);
199   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
200   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
201   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
202
203   // CheckBox for groups generation
204   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
205   MakeGroupsCheck->setChecked(false);
206
207   // Name of a mesh to create
208   LineEditNewMesh = new QLineEdit(GroupArguments);
209
210   // layout
211   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
212   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
213   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
214   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
215   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
216   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
217   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
218   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
219   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
220   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
221   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
222   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
223   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
224   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
225   GroupArgumentsLayout->addWidget(SpinBox_FX,           3, 3);
226   GroupArgumentsLayout->addWidget(TextLabel3,           4, 0);
227   GroupArgumentsLayout->addWidget(SpinBox_FY,           4, 3);
228   GroupArgumentsLayout->addWidget(TextLabel4,           5, 0);
229   GroupArgumentsLayout->addWidget(SpinBox_FZ,           5, 3);
230   GroupArgumentsLayout->addWidget(ActionBox,            7, 0, 3, 4);
231   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      7, 5, 1, 4);
232   GroupArgumentsLayout->addWidget(LineEditNewMesh,      8, 5, 1, 4);
233
234   /***************************************************************/
235   GroupButtons = new QGroupBox(this);
236   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
237   GroupButtonsLayout->setSpacing(SPACING);
238   GroupButtonsLayout->setMargin(MARGIN);
239
240   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
241   buttonOk->setAutoDefault(true);
242   buttonOk->setDefault(true);
243   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
244   buttonApply->setAutoDefault(true);
245   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
246   buttonCancel->setAutoDefault(true);
247   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
248   buttonHelp->setAutoDefault(true);
249
250   GroupButtonsLayout->addWidget(buttonOk);
251   GroupButtonsLayout->addSpacing(10);
252   GroupButtonsLayout->addWidget(buttonApply);
253   GroupButtonsLayout->addSpacing(10);
254   GroupButtonsLayout->addStretch();
255   GroupButtonsLayout->addWidget(buttonCancel);
256   GroupButtonsLayout->addWidget(buttonHelp);
257
258   /***************************************************************/
259   SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
260   SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
261   SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
262
263   /* Initialisations */
264   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267   SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
268   SpinBox_FX->SetStep(0.1);
269   SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
270   SpinBox_FY->SetStep(0.1);
271   SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
272   SpinBox_FZ->SetStep(0.1);
273
274   RadioButton1->setChecked(true);
275
276   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
277
278   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
279
280   // Costruction of the logical filter
281   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
282   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
283
284   QList<SUIT_SelectionFilter*> aListOfFilters;
285   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
286   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
287
288   myMeshOrSubMeshOrGroupFilter =
289     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
290
291   myHelpFileName = "scale_page.html";
292
293   Init();
294
295   /* signals and slots connections */
296   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
297   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
298   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
299   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
300   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
301
302   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304
305   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
306   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
307   /* to close dialog if study change */
308   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
309   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
310   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
311   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
312
313   ConstructorsClicked(0);
314   SelectionIntoArgument();
315   onActionClicked(MOVE_ELEMS_BUTTON);
316 }
317
318 //=================================================================================
319 // function : ~SMESHGUI_ScaleDlg()
320 // purpose  : Destroys the object and frees any allocated resources
321 //=================================================================================
322 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
323 {
324   if ( myFilterDlg ) {
325     myFilterDlg->setParent( 0 );
326     delete myFilterDlg;
327     myFilterDlg = 0;
328   }
329 }
330
331 //=================================================================================
332 // function : Init()
333 // purpose  :
334 //=================================================================================
335 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
336 {
337   myBusy = false;
338
339   myEditCurrentArgument = 0;
340   LineEditElements->clear();
341   myElementsId = "";
342   myNbOkElements = 0;
343
344   buttonOk->setEnabled(false);
345   buttonApply->setEnabled(false);
346
347   myActor = 0;
348   myMesh = SMESH::SMESH_Mesh::_nil();
349
350   if (ResetControls) {
351     SpinBox1_1->SetValue(0.0);
352     SpinBox1_2->SetValue(0.0);
353     SpinBox1_3->SetValue(0.0);
354     SpinBox_FX->SetValue(1.0);
355     SpinBox_FY->SetValue(1.0);
356     SpinBox_FZ->SetValue(1.0);
357
358     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
359     CheckBoxMesh->setChecked(false);
360     onSelectMesh(false);
361   }
362 }
363
364 //=================================================================================
365 // function : ConstructorsClicked()
366 // purpose  : Radio button management
367 //=================================================================================
368 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
369 {
370   disconnect(mySelectionMgr, 0, this, 0);
371
372   switch (constructorId) {
373   case 0:
374     {
375       TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
376       TextLabel3->hide();
377       TextLabel4->hide();
378       SpinBox_FY->hide();
379       SpinBox_FZ->hide();
380       break;
381     }
382   case 1:
383     {
384       TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
385       TextLabel3->show();
386       TextLabel4->show();
387       SpinBox_FY->show();
388       SpinBox_FZ->show();
389       break;
390     }
391   }
392
393   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
394     SMESH::SetPointRepresentation(false);
395     if (!CheckBoxMesh->isChecked())
396       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
397         aViewWindow->SetSelectionMode( CellSelection );
398   }
399
400   myEditCurrentArgument = (QWidget*)LineEditElements;
401   LineEditElements->setFocus();
402
403   if (CheckBoxMesh->isChecked())
404     onSelectMesh(true);
405
406   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
407
408   QApplication::instance()->processEvents();
409   updateGeometry();
410   resize(100,100);
411 }
412
413 //=================================================================================
414 // function : ClickOnApply()
415 // purpose  :
416 //=================================================================================
417 bool SMESHGUI_ScaleDlg::ClickOnApply()
418 {
419   if (mySMESHGUI->isActiveStudyLocked())
420     return false;
421
422   if( !isValid() )
423     return false;
424
425   if (myNbOkElements) {
426     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
427
428     SMESH::long_array_var anElementsId = new SMESH::long_array;
429
430     anElementsId->length(aListElementsId.count());
431     for (int i = 0; i < aListElementsId.count(); i++)
432       anElementsId[i] = aListElementsId[i].toInt();
433
434     SMESH::PointStruct aPoint;
435     aPoint.x = SpinBox1_1->GetValue();
436     aPoint.y = SpinBox1_2->GetValue();
437     aPoint.z = SpinBox1_3->GetValue();
438     SMESH::double_array_var aScaleFact = new SMESH::double_array;
439     aScaleFact->length(3);
440     aScaleFact[0] = SpinBox_FX->GetValue();
441     if (GetConstructorId() == 0) {
442       aScaleFact[1] = SpinBox_FX->GetValue();
443       aScaleFact[2] = SpinBox_FX->GetValue();
444     }
445     else {
446       aScaleFact[1] = SpinBox_FY->GetValue();
447       aScaleFact[2] = SpinBox_FZ->GetValue();
448     }
449
450     QStringList aParameters;
451     aParameters << SpinBox1_1->text();
452     aParameters << SpinBox1_2->text();
453     aParameters << SpinBox1_3->text();
454     aParameters << SpinBox_FX->text();
455     if (GetConstructorId() == 1) {
456       aParameters << SpinBox_FX->text();
457       aParameters << SpinBox_FX->text();
458     }
459     else {
460       aParameters << SpinBox_FY->text();
461       aParameters << SpinBox_FZ->text();
462     }
463
464     int actionButton = ActionGroup->checkedId();
465     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
466     try {
467       SUIT_OverrideCursor aWaitCursor;
468       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
469       switch ( actionButton ) {
470       case MOVE_ELEMS_BUTTON:
471         if(CheckBoxMesh->isChecked()) {
472           aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
473         }
474         else {
475           SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
476           aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
477         }
478         if( !myMesh->_is_nil())
479           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
480         break;
481       case COPY_ELEMS_BUTTON:
482         if ( makeGroups ) {
483           SMESH::ListOfGroups_var groups; 
484           if(CheckBoxMesh->isChecked()) {
485             groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
486           }
487           else {
488             groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
489                                                   aPoint, aScaleFact);
490           }
491         }
492         else {
493           if(CheckBoxMesh->isChecked()) {
494             aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
495           }
496           else {
497             aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
498                                aPoint, aScaleFact, true);
499           }
500         }
501         if( !myMesh->_is_nil())
502           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
503         break;
504       case MAKE_MESH_BUTTON:
505         SMESH::SMESH_Mesh_var mesh; 
506         if(CheckBoxMesh->isChecked()) {
507           mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
508                                             LineEditNewMesh->text().toLatin1().data());
509         }
510         else {
511           mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
512                                             aPoint, aScaleFact, makeGroups,
513                                             LineEditNewMesh->text().toLatin1().data());
514         }
515         if( !mesh->_is_nil())
516           mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
517       }
518     } catch (...) {
519     }
520     
521     SMESH::UpdateView();
522     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
523          actionButton == MAKE_MESH_BUTTON )
524       mySMESHGUI->updateObjBrowser(true); // new groups may appear
525     Init(false);
526     ConstructorsClicked(GetConstructorId());
527     mySelectedObject = SMESH::SMESH_IDSource::_nil();
528     SelectionIntoArgument();
529
530     SMESHGUI::Modified();
531   }
532   
533   return true;
534 }
535
536 //=================================================================================
537 // function : ClickOnOk()
538 // purpose  :
539 //=================================================================================
540 void SMESHGUI_ScaleDlg::ClickOnOk()
541 {
542   if( ClickOnApply() )
543     ClickOnCancel();
544 }
545
546 //=================================================================================
547 // function : ClickOnCancel()
548 // purpose  :
549 //=================================================================================
550 void SMESHGUI_ScaleDlg::ClickOnCancel()
551 {
552   disconnect(mySelectionMgr, 0, this, 0);
553   mySelectionMgr->clearFilters();
554   //mySelectionMgr->clearSelected();
555   if (SMESH::GetCurrentVtkView()) {
556     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
557     SMESH::SetPointRepresentation(false);
558   }
559   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560     aViewWindow->SetSelectionMode( ActorSelection );
561   mySMESHGUI->ResetState();
562   reject();
563 }
564
565 //=================================================================================
566 // function : ClickOnHelp()
567 // purpose  :
568 //=================================================================================
569 void SMESHGUI_ScaleDlg::ClickOnHelp()
570 {
571   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
572   if (app) 
573     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
574   else {
575     QString platform;
576 #ifdef WIN32
577     platform = "winapplication";
578 #else
579     platform = "application";
580 #endif
581     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
582                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
583                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
584                                                                  platform)).
585                              arg(myHelpFileName));
586   }
587 }
588
589 //=======================================================================
590 // function : onTextChange()
591 // purpose  :
592 //=======================================================================
593 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
594 {
595   QLineEdit* send = (QLineEdit*)sender();
596
597   if (myBusy) return;
598   BusyLocker lock( myBusy );
599
600   if (send == LineEditElements)
601     myNbOkElements = 0;
602
603   buttonOk->setEnabled(false);
604   buttonApply->setEnabled(false);
605
606   // hilight entered elements
607   SMDS_Mesh* aMesh = 0;
608   if (myActor)
609     aMesh = myActor->GetObject()->GetMesh();
610
611   if (aMesh) {
612     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
613     
614     TColStd_MapOfInteger newIndices;
615
616     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
617
618     if (send == LineEditElements) {
619       for (int i = 0; i < aListId.count(); i++) {
620         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
621         if (e)
622           newIndices.Add(e->GetID());
623         myNbOkElements++;
624       }
625     }
626
627     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
628     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
629       aViewWindow->highlight( anIO, true, true );
630     
631     myElementsId = theNewText;
632   }
633
634   if (myNbOkElements) {
635     buttonOk->setEnabled(true);
636     buttonApply->setEnabled(true);
637   }
638 }
639
640 //=================================================================================
641 // function : SelectionIntoArgument()
642 // purpose  : Called when selection as changed or other case
643 //=================================================================================
644 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
645 {
646   if (myBusy) return;
647   BusyLocker lock( myBusy );
648   // clear
649   myActor = 0;
650   QString aString = "";
651
652   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
653     LineEditElements->setText(aString);
654     myNbOkElements = 0;
655     buttonOk->setEnabled(false);
656     buttonApply->setEnabled(false);
657   }
658
659   if (!GroupButtons->isEnabled()) // inactive
660     return;
661
662   // get selected mesh
663   SALOME_ListIO aList;
664   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
665
666   int nbSel = aList.Extent();
667   if (nbSel != 1)
668     return;
669
670   Handle(SALOME_InteractiveObject) IO = aList.First();
671   myMesh = SMESH::GetMeshByIO(IO);
672   if (myMesh->_is_nil())
673     return;
674
675   myActor = SMESH::FindActorByObject(myMesh);
676   if (!myActor)
677     myActor = SMESH::FindActorByEntry(IO->getEntry());
678   if (!myActor && !CheckBoxMesh->isChecked())
679     return;
680
681   int aNbUnits = 0;
682
683   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
684     myElementsId = "";
685
686     // MakeGroups is available if there are groups and "Copy"
687     if ( myMesh->NbGroups() == 0 ) {
688       MakeGroupsCheck->setChecked(false);
689       MakeGroupsCheck->setEnabled(false);
690     }
691     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
692       MakeGroupsCheck->setEnabled(true);
693     }
694
695     if (CheckBoxMesh->isChecked()) {
696       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
697
698       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
699         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
700       }
701       else
702         return;
703         // get IDs from mesh
704         /*
705         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
706         if (!aSMDSMesh)
707           return;
708
709         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
710           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
711           if (e) {
712             myElementsId += QString(" %1").arg(i);
713             aNbUnits++;
714           }
715         }
716       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
717         // get submesh
718         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
719
720         // get IDs from submesh
721         SMESH::long_array_var anElementsIds = new SMESH::long_array;
722         anElementsIds = aSubMesh->GetElementsId();
723         for (int i = 0; i < anElementsIds->length(); i++) {
724           myElementsId += QString(" %1").arg(anElementsIds[i]);
725         }
726         aNbUnits = anElementsIds->length();
727       } else { // GROUP
728         // get smesh group
729         SMESH::SMESH_GroupBase_var aGroup =
730           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
731         if (aGroup->_is_nil())
732           return;
733
734         // get IDs from smesh group
735         SMESH::long_array_var anElementsIds = new SMESH::long_array;
736         anElementsIds = aGroup->GetListOfID();
737         for (int i = 0; i < anElementsIds->length(); i++) {
738           myElementsId += QString(" %1").arg(anElementsIds[i]);
739         }
740         aNbUnits = anElementsIds->length();
741       }
742         */
743     } else {
744       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
745       myElementsId = aString;
746       if (aNbUnits < 1)
747         return;  
748     }
749
750     myNbOkElements = true;
751   } else {
752     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
753     if (aNbUnits != 1)
754       return;
755
756     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
757     if (!aMesh)
758       return;
759
760     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
761     if (!n)
762       return;
763
764     double x = n->X();
765     double y = n->Y();
766     double z = n->Z();
767
768     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
769       SpinBox1_1->SetValue(x);
770       SpinBox1_2->SetValue(y);
771       SpinBox1_3->SetValue(z);
772     }
773     else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
774       SpinBox_FX->SetValue(x);
775       SpinBox_FY->SetValue(y);
776       SpinBox_FZ->SetValue(z);
777     }
778   }
779
780   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
781     LineEditElements->setText(aString);
782     LineEditElements->repaint();
783     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
784     LineEditElements->setEnabled(true); 
785     setNewMeshName();
786   }
787
788   // OK
789   if (myNbOkElements) {
790     buttonOk->setEnabled(true);
791     buttonApply->setEnabled(true);
792   }
793 }
794
795 //=================================================================================
796 // function : SetEditCurrentArgument()
797 // purpose  :
798 //=================================================================================
799 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
800 {
801   QPushButton* send = (QPushButton*)sender();
802
803   disconnect(mySelectionMgr, 0, this, 0);
804   mySelectionMgr->clearSelected();
805   mySelectionMgr->clearFilters();
806
807   if (send == SelectElementsButton) {
808     myEditCurrentArgument = (QWidget*)LineEditElements;
809     SMESH::SetPointRepresentation(false);
810     if (CheckBoxMesh->isChecked()) {
811       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812         aViewWindow->SetSelectionMode( ActorSelection );
813       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
814     }
815     else {
816       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817         aViewWindow->SetSelectionMode( CellSelection );
818     }
819   }
820   else if (send == SelectButton1) {
821     myEditCurrentArgument = (QWidget*)SpinBox1_1;
822     SMESH::SetPointRepresentation(true);
823     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824       aViewWindow->SetSelectionMode( NodeSelection );
825   }
826
827   myEditCurrentArgument->setFocus();
828   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
829   SelectionIntoArgument();
830 }
831
832 //=================================================================================
833 // function : DeactivateActiveDialog()
834 // purpose  :
835 //=================================================================================
836 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
837 {
838   if (ConstructorsBox->isEnabled()) {
839     ConstructorsBox->setEnabled(false);
840     GroupArguments->setEnabled(false);
841     GroupButtons->setEnabled(false);
842     mySMESHGUI->ResetState();
843     mySMESHGUI->SetActiveDialogBox(0);
844   }
845 }
846
847 //=================================================================================
848 // function : ActivateThisDialog()
849 // purpose  :
850 //=================================================================================
851 void SMESHGUI_ScaleDlg::ActivateThisDialog()
852 {
853   /* Emit a signal to deactivate the active dialog */
854   mySMESHGUI->EmitSignalDeactivateDialog();
855   ConstructorsBox->setEnabled(true);
856   GroupArguments->setEnabled(true);
857   GroupButtons->setEnabled(true);
858
859   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
860
861   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
862     aViewWindow->SetSelectionMode( CellSelection );
863
864   SelectionIntoArgument();
865 }
866
867 //=================================================================================
868 // function : enterEvent()
869 // purpose  :
870 //=================================================================================
871 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
872 {
873   if (!ConstructorsBox->isEnabled())
874     ActivateThisDialog();
875 }
876
877 //=================================================================================
878 // function : closeEvent()
879 // purpose  :
880 //=================================================================================
881 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
882 {
883   /* same than click on cancel button */
884   ClickOnCancel();
885 }
886
887 //=======================================================================
888 //function : hideEvent
889 //purpose  : caused by ESC key
890 //=======================================================================
891 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
892 {
893   if (!isMinimized())
894     ClickOnCancel();
895 }
896
897 //=======================================================================
898 //function : onSelectMesh
899 //purpose  :
900 //=======================================================================
901 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
902 {
903   if (toSelectMesh)
904     TextLabelElements->setText(tr("SMESH_NAME"));
905   else
906     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
907   myFilterBtn->setEnabled(!toSelectMesh);
908
909   if (myEditCurrentArgument != LineEditElements) {
910     LineEditElements->clear();
911     return;
912   }
913
914   mySelectionMgr->clearFilters();
915   SMESH::SetPointRepresentation(false);
916
917   if (toSelectMesh) {
918     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919       aViewWindow->SetSelectionMode( ActorSelection );
920     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
921     LineEditElements->setReadOnly(true);
922     LineEditElements->setValidator(0);
923   } else {
924     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925       aViewWindow->SetSelectionMode( CellSelection );
926     LineEditElements->setReadOnly(false);
927     LineEditElements->setValidator(myIdValidator);
928     onTextChange(LineEditElements->text());
929   }
930
931   SelectionIntoArgument();
932 }
933
934 //=======================================================================
935 //function : onActionClicked
936 //purpose  : slot called when an action type changed
937 //=======================================================================
938
939 void SMESHGUI_ScaleDlg::onActionClicked(int button)
940 {
941   switch ( button ) {
942   case MOVE_ELEMS_BUTTON:
943     MakeGroupsCheck->setEnabled(false);
944     LineEditNewMesh->setEnabled(false);
945     break;
946   case COPY_ELEMS_BUTTON:
947     LineEditNewMesh->setEnabled(false);
948     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
949     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
950       MakeGroupsCheck->setEnabled(true);
951     else
952       MakeGroupsCheck->setEnabled(false);
953     break;
954   case MAKE_MESH_BUTTON:
955     LineEditNewMesh->setEnabled(true);
956     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
957     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
958       MakeGroupsCheck->setEnabled(true);
959     else
960       MakeGroupsCheck->setEnabled(false);
961     break;
962   }
963   setNewMeshName();
964 }
965
966 //=======================================================================
967 //function : setNewMeshName
968 //purpose  : update contents of LineEditNewMesh
969 //=======================================================================
970
971 void SMESHGUI_ScaleDlg::setNewMeshName()
972 {
973   LineEditNewMesh->setText("");
974   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
975     QString name;
976     if ( CheckBoxMesh->isChecked() ) {
977       name = LineEditElements->text();
978     }
979     else {
980       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
981       name = meshSO->GetName().c_str();
982     }
983     if ( !name.isEmpty() )
984       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
985   }
986 }
987
988 //=================================================================================
989 // function : GetConstructorId()
990 // purpose  :
991 //=================================================================================
992 int SMESHGUI_ScaleDlg::GetConstructorId()
993 {
994   return GroupConstructors->checkedId();
995 }
996
997 //=================================================================================
998 // function : keyPressEvent()
999 // purpose  :
1000 //=================================================================================
1001 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1002 {
1003   QDialog::keyPressEvent( e );
1004   if ( e->isAccepted() )
1005     return;
1006
1007   if ( e->key() == Qt::Key_F1 ) {
1008     e->accept();
1009     ClickOnHelp();
1010   }
1011 }
1012
1013 //=================================================================================
1014 // function : setFilters()
1015 // purpose  : SLOT. Called when "Filter" button pressed.
1016 //=================================================================================
1017 void SMESHGUI_ScaleDlg::setFilters()
1018 {
1019   if(myMesh->_is_nil()) {
1020     SUIT_MessageBox::critical(this,
1021                               tr("SMESH_ERROR"),
1022                               tr("NO_MESH_SELECTED"));
1023    return;
1024   }
1025   if ( !myFilterDlg )
1026     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1027
1028   myFilterDlg->SetSelection();
1029   myFilterDlg->SetMesh( myMesh );
1030   myFilterDlg->SetSourceWg( LineEditElements );
1031
1032   myFilterDlg->show();
1033 }
1034
1035 //=================================================================================
1036 // function : isValid
1037 // purpose  :
1038 //=================================================================================
1039 bool SMESHGUI_ScaleDlg::isValid()
1040 {
1041   bool ok = true;
1042   QString msg;
1043
1044   ok = SpinBox1_1->isValid( msg, true ) && ok;
1045   ok = SpinBox1_2->isValid( msg, true ) && ok;
1046   ok = SpinBox1_3->isValid( msg, true ) && ok;
1047   ok = SpinBox_FX->isValid( msg, true ) && ok;
1048   if (GetConstructorId() == 1) {
1049     ok = SpinBox_FY->isValid( msg, true ) && ok;
1050     ok = SpinBox_FZ->isValid( msg, true ) && ok;
1051   }
1052
1053   if( !ok ) {
1054     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1055     if ( !msg.isEmpty() )
1056       str += "\n" + msg;
1057     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1058     return false;
1059   }
1060   return true;
1061 }