Salome HOME
0020847: EDF 1378 SMESH : Selection problem with symetry + translation
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ScaleDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_ScaleDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_ScaleDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
55
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
58
59 // OCCT includes
60 #include <TColStd_MapOfInteger.hxx>
61
62 // Qt includes
63 #include <QApplication>
64 #include <QButtonGroup>
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QCheckBox>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
74 #include <QSpinBox>
75 #include <QKeyEvent>
76
77 // IDL includes
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
83
84 /*!
85   \class BusyLocker
86   \brief Simple 'busy state' flag locker.
87   \internal
88 */
89
90 class BusyLocker
91 {
92 public:
93   //! Constructor. Sets passed boolean flag to \c true.
94   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96   ~BusyLocker() { myBusy = false; }
97 private:
98   bool& myBusy; //! External 'busy state' boolean flag
99 };
100
101 #define SPACING 6
102 #define MARGIN  11
103
104 //=================================================================================
105 // class    : SMESHGUI_ScaleDlg()
106 // purpose  :
107 //=================================================================================
108 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
109   : QDialog( SMESH::GetDesktop( theModule ) ),
110     mySMESHGUI( theModule ),
111     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
112     myFilterDlg(0),
113     mySelectedObject(SMESH::SMESH_IDSource::_nil())
114 {
115   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
116   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
117   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
118
119   setModal(false);
120   setAttribute(Qt::WA_DeleteOnClose, true);
121   setWindowTitle(tr("SMESH_SCALE_TITLE"));
122   setSizeGripEnabled(true);
123
124   QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
125   SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
126   SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
127
128   /***************************************************************/
129   ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
130   GroupConstructors = new QButtonGroup(this);
131   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132   ConstructorsBoxLayout->setSpacing(SPACING);
133   ConstructorsBoxLayout->setMargin(MARGIN);
134
135   RadioButton1= new QRadioButton(ConstructorsBox);
136   RadioButton1->setIcon(image0);
137   RadioButton2= new QRadioButton(ConstructorsBox);
138   RadioButton2->setIcon(image1);
139
140   ConstructorsBoxLayout->addWidget(RadioButton1);
141   ConstructorsBoxLayout->addWidget(RadioButton2);
142   GroupConstructors->addButton(RadioButton1, 0);
143   GroupConstructors->addButton(RadioButton2, 1);
144
145   /***************************************************************/
146   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148   GroupArgumentsLayout->setSpacing(SPACING);
149   GroupArgumentsLayout->setMargin(MARGIN);
150
151   myIdValidator = new SMESHGUI_IdValidator(this);
152
153   // Controls for elements selection
154   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155   SelectElementsButton = new QPushButton(GroupArguments);
156   SelectElementsButton->setIcon(image2);
157   LineEditElements = new QLineEdit(GroupArguments);
158   LineEditElements->setValidator(myIdValidator);
159   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
160   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
161
162   // Control for the whole mesh selection
163   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
164
165   // Controls for vector and points selection
166   TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
167   SelectButton1 = new QPushButton(GroupArguments);
168   SelectButton1->setIcon(image2);
169
170   TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
171   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
172   TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
173   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
174   TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
175   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
176
177   TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
178   SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
179
180   TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
181   SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
182
183   TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
184   SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
185
186
187   // switch of action type
188   ActionBox = new QGroupBox(GroupArguments);
189   ActionGroup = new QButtonGroup(GroupArguments);
190   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
191   ActionBoxLayout->addSpacing(SPACING);
192   ActionBoxLayout->setMargin(MARGIN);
193
194   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
195   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
196   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
197
198   ActionBoxLayout->addWidget(aMoveElements);
199   ActionBoxLayout->addWidget(aCopyElements);
200   ActionBoxLayout->addWidget(aCreateMesh);
201   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
202   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
203   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
204
205   // CheckBox for groups generation
206   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
207   MakeGroupsCheck->setChecked(false);
208
209   // Name of a mesh to create
210   LineEditNewMesh = new QLineEdit(GroupArguments);
211
212   // layout
213   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
214   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
216   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
217   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
218   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
219   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
220   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
221   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
222   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
223   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
224   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
225   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
226   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
227   GroupArgumentsLayout->addWidget(SpinBox_FX,           3, 3);
228   GroupArgumentsLayout->addWidget(TextLabel3,           4, 0);
229   GroupArgumentsLayout->addWidget(SpinBox_FY,           4, 3);
230   GroupArgumentsLayout->addWidget(TextLabel4,           5, 0);
231   GroupArgumentsLayout->addWidget(SpinBox_FZ,           5, 3);
232   GroupArgumentsLayout->addWidget(ActionBox,            7, 0, 3, 4);
233   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      7, 5, 1, 4);
234   GroupArgumentsLayout->addWidget(LineEditNewMesh,      8, 5, 1, 4);
235
236   /***************************************************************/
237   GroupButtons = new QGroupBox(this);
238   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
239   GroupButtonsLayout->setSpacing(SPACING);
240   GroupButtonsLayout->setMargin(MARGIN);
241
242   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
243   buttonOk->setAutoDefault(true);
244   buttonOk->setDefault(true);
245   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
246   buttonApply->setAutoDefault(true);
247   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
248   buttonCancel->setAutoDefault(true);
249   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
250   buttonHelp->setAutoDefault(true);
251
252   GroupButtonsLayout->addWidget(buttonOk);
253   GroupButtonsLayout->addSpacing(10);
254   GroupButtonsLayout->addWidget(buttonApply);
255   GroupButtonsLayout->addSpacing(10);
256   GroupButtonsLayout->addStretch();
257   GroupButtonsLayout->addWidget(buttonCancel);
258   GroupButtonsLayout->addWidget(buttonHelp);
259
260   /***************************************************************/
261   SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
262   SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
263   SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
264
265   /* Initialisations */
266   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269   SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
270   SpinBox_FX->SetStep(0.1);
271   SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
272   SpinBox_FY->SetStep(0.1);
273   SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
274   SpinBox_FZ->SetStep(0.1);
275
276   RadioButton1->setChecked(true);
277
278   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279
280   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
281
282   // Costruction of the logical filter
283   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
284   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
285
286   QList<SUIT_SelectionFilter*> aListOfFilters;
287   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
288   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
289
290   myMeshOrSubMeshOrGroupFilter =
291     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
292
293   myHelpFileName = "scale_page.html";
294
295   Init();
296
297   /* signals and slots connections */
298   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
299   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
300   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
301   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
302   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
303
304   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306
307   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
309   /* to close dialog if study change */
310   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
312   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
313   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
314
315   ConstructorsClicked(0);
316   SelectionIntoArgument();
317   onActionClicked(MOVE_ELEMS_BUTTON);
318 }
319
320 //=================================================================================
321 // function : ~SMESHGUI_ScaleDlg()
322 // purpose  : Destroys the object and frees any allocated resources
323 //=================================================================================
324 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
325 {
326   if ( myFilterDlg ) {
327     myFilterDlg->setParent( 0 );
328     delete myFilterDlg;
329     myFilterDlg = 0;
330   }
331 }
332
333 //=================================================================================
334 // function : Init()
335 // purpose  :
336 //=================================================================================
337 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
338 {
339   myBusy = false;
340
341   myEditCurrentArgument = 0;
342   LineEditElements->clear();
343   myElementsId = "";
344   myNbOkElements = 0;
345
346   buttonOk->setEnabled(false);
347   buttonApply->setEnabled(false);
348
349   myActor = 0;
350   myMesh = SMESH::SMESH_Mesh::_nil();
351
352   if (ResetControls) {
353     SpinBox1_1->SetValue(0.0);
354     SpinBox1_2->SetValue(0.0);
355     SpinBox1_3->SetValue(0.0);
356     SpinBox_FX->SetValue(1.0);
357     SpinBox_FY->SetValue(1.0);
358     SpinBox_FZ->SetValue(1.0);
359
360     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
361     CheckBoxMesh->setChecked(false);
362     onSelectMesh(false);
363   }
364 }
365
366 //=================================================================================
367 // function : ConstructorsClicked()
368 // purpose  : Radio button management
369 //=================================================================================
370 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
371 {
372   disconnect(mySelectionMgr, 0, this, 0);
373
374   switch (constructorId) {
375   case 0:
376     {
377       TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
378       TextLabel3->hide();
379       TextLabel4->hide();
380       SpinBox_FY->hide();
381       SpinBox_FZ->hide();
382       break;
383     }
384   case 1:
385     {
386       TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
387       TextLabel3->show();
388       TextLabel4->show();
389       SpinBox_FY->show();
390       SpinBox_FZ->show();
391       break;
392     }
393   }
394
395   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
396     SMESH::SetPointRepresentation(false);
397     if (!CheckBoxMesh->isChecked())
398       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
399         aViewWindow->SetSelectionMode( CellSelection );
400   }
401
402   myEditCurrentArgument = (QWidget*)LineEditElements;
403   LineEditElements->setFocus();
404
405   if (CheckBoxMesh->isChecked())
406     onSelectMesh(true);
407
408   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
409
410   QApplication::instance()->processEvents();
411   updateGeometry();
412   resize(100,100);
413 }
414
415 //=================================================================================
416 // function : ClickOnApply()
417 // purpose  :
418 //=================================================================================
419 bool SMESHGUI_ScaleDlg::ClickOnApply()
420 {
421   if (mySMESHGUI->isActiveStudyLocked())
422     return false;
423
424   if( !isValid() )
425     return false;
426
427   if (myNbOkElements) {
428     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
429
430     SMESH::long_array_var anElementsId = new SMESH::long_array;
431
432     anElementsId->length(aListElementsId.count());
433     for (int i = 0; i < aListElementsId.count(); i++)
434       anElementsId[i] = aListElementsId[i].toInt();
435
436     SMESH::PointStruct aPoint;
437     aPoint.x = SpinBox1_1->GetValue();
438     aPoint.y = SpinBox1_2->GetValue();
439     aPoint.z = SpinBox1_3->GetValue();
440     SMESH::double_array_var aScaleFact = new SMESH::double_array;
441     aScaleFact->length(3);
442     aScaleFact[0] = SpinBox_FX->GetValue();
443     if (GetConstructorId() == 0) {
444       aScaleFact[1] = SpinBox_FX->GetValue();
445       aScaleFact[2] = SpinBox_FX->GetValue();
446     }
447     else {
448       aScaleFact[1] = SpinBox_FY->GetValue();
449       aScaleFact[2] = SpinBox_FZ->GetValue();
450     }
451
452     QStringList aParameters;
453     aParameters << SpinBox1_1->text();
454     aParameters << SpinBox1_2->text();
455     aParameters << SpinBox1_3->text();
456     aParameters << SpinBox_FX->text();
457     if (GetConstructorId() == 1) {
458       aParameters << SpinBox_FX->text();
459       aParameters << SpinBox_FX->text();
460     }
461     else {
462       aParameters << SpinBox_FY->text();
463       aParameters << SpinBox_FZ->text();
464     }
465
466     int actionButton = ActionGroup->checkedId();
467     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
468     try {
469       SUIT_OverrideCursor aWaitCursor;
470       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
471       switch ( actionButton ) {
472       case MOVE_ELEMS_BUTTON:
473         if(CheckBoxMesh->isChecked()) {
474           aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
475         }
476         else {
477           SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
478           aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
479         }
480         if( !myMesh->_is_nil())
481           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
482         break;
483       case COPY_ELEMS_BUTTON:
484         if ( makeGroups ) {
485           SMESH::ListOfGroups_var groups; 
486           if(CheckBoxMesh->isChecked()) {
487             groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
488           }
489           else {
490             groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
491                                                   aPoint, aScaleFact);
492           }
493         }
494         else {
495           if(CheckBoxMesh->isChecked()) {
496             aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
497           }
498           else {
499             aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
500                                aPoint, aScaleFact, true);
501           }
502         }
503         if( !myMesh->_is_nil())
504           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
505         break;
506       case MAKE_MESH_BUTTON:
507         SMESH::SMESH_Mesh_var mesh; 
508         if(CheckBoxMesh->isChecked()) {
509           mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
510                                             LineEditNewMesh->text().toLatin1().data());
511         }
512         else {
513           mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
514                                             aPoint, aScaleFact, makeGroups,
515                                             LineEditNewMesh->text().toLatin1().data());
516         }
517         if( !mesh->_is_nil())
518           mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
519       }
520     } catch (...) {
521     }
522     
523     SMESH::UpdateView();
524     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
525          actionButton == MAKE_MESH_BUTTON )
526       mySMESHGUI->updateObjBrowser(true); // new groups may appear
527     Init(false);
528     ConstructorsClicked(GetConstructorId());
529     mySelectedObject = SMESH::SMESH_IDSource::_nil();
530     SelectionIntoArgument();
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 }