Salome HOME
PR: merged from V5_1_4rc1
[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   
531   return true;
532 }
533
534 //=================================================================================
535 // function : ClickOnOk()
536 // purpose  :
537 //=================================================================================
538 void SMESHGUI_ScaleDlg::ClickOnOk()
539 {
540   if( ClickOnApply() )
541     ClickOnCancel();
542 }
543
544 //=================================================================================
545 // function : ClickOnCancel()
546 // purpose  :
547 //=================================================================================
548 void SMESHGUI_ScaleDlg::ClickOnCancel()
549 {
550   disconnect(mySelectionMgr, 0, this, 0);
551   mySelectionMgr->clearFilters();
552   //mySelectionMgr->clearSelected();
553   if (SMESH::GetCurrentVtkView()) {
554     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
555     SMESH::SetPointRepresentation(false);
556   }
557   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
558     aViewWindow->SetSelectionMode( ActorSelection );
559   mySMESHGUI->ResetState();
560   reject();
561 }
562
563 //=================================================================================
564 // function : ClickOnHelp()
565 // purpose  :
566 //=================================================================================
567 void SMESHGUI_ScaleDlg::ClickOnHelp()
568 {
569   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
570   if (app) 
571     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
572   else {
573     QString platform;
574 #ifdef WIN32
575     platform = "winapplication";
576 #else
577     platform = "application";
578 #endif
579     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
580                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
581                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
582                                                                  platform)).
583                              arg(myHelpFileName));
584   }
585 }
586
587 //=======================================================================
588 // function : onTextChange()
589 // purpose  :
590 //=======================================================================
591 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
592 {
593   QLineEdit* send = (QLineEdit*)sender();
594
595   if (myBusy) return;
596   BusyLocker lock( myBusy );
597
598   if (send == LineEditElements)
599     myNbOkElements = 0;
600
601   buttonOk->setEnabled(false);
602   buttonApply->setEnabled(false);
603
604   // hilight entered elements
605   SMDS_Mesh* aMesh = 0;
606   if (myActor)
607     aMesh = myActor->GetObject()->GetMesh();
608
609   if (aMesh) {
610     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
611     
612     TColStd_MapOfInteger newIndices;
613
614     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
615
616     if (send == LineEditElements) {
617       for (int i = 0; i < aListId.count(); i++) {
618         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
619         if (e)
620           newIndices.Add(e->GetID());
621         myNbOkElements++;
622       }
623     }
624
625     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
626     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
627       aViewWindow->highlight( anIO, true, true );
628     
629     myElementsId = theNewText;
630   }
631
632   if (myNbOkElements) {
633     buttonOk->setEnabled(true);
634     buttonApply->setEnabled(true);
635   }
636 }
637
638 //=================================================================================
639 // function : SelectionIntoArgument()
640 // purpose  : Called when selection as changed or other case
641 //=================================================================================
642 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
643 {
644   if (myBusy) return;
645   BusyLocker lock( myBusy );
646   // clear
647   myActor = 0;
648   QString aString = "";
649
650   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
651     LineEditElements->setText(aString);
652     myNbOkElements = 0;
653     buttonOk->setEnabled(false);
654     buttonApply->setEnabled(false);
655   }
656
657   if (!GroupButtons->isEnabled()) // inactive
658     return;
659
660   // get selected mesh
661   SALOME_ListIO aList;
662   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
663
664   int nbSel = aList.Extent();
665   if (nbSel != 1)
666     return;
667
668   Handle(SALOME_InteractiveObject) IO = aList.First();
669   myMesh = SMESH::GetMeshByIO(IO);
670   if (myMesh->_is_nil())
671     return;
672
673   myActor = SMESH::FindActorByObject(myMesh);
674   if (!myActor)
675     myActor = SMESH::FindActorByEntry(IO->getEntry());
676   if (!myActor && !CheckBoxMesh->isChecked())
677     return;
678
679   int aNbUnits = 0;
680
681   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
682     myElementsId = "";
683
684     // MakeGroups is available if there are groups and "Copy"
685     if ( myMesh->NbGroups() == 0 ) {
686       MakeGroupsCheck->setChecked(false);
687       MakeGroupsCheck->setEnabled(false);
688     }
689     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
690       MakeGroupsCheck->setEnabled(true);
691     }
692
693     if (CheckBoxMesh->isChecked()) {
694       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
695
696       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
697         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
698       }
699       else
700         return;
701         // get IDs from mesh
702         /*
703         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
704         if (!aSMDSMesh)
705           return;
706
707         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
708           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
709           if (e) {
710             myElementsId += QString(" %1").arg(i);
711             aNbUnits++;
712           }
713         }
714       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
715         // get submesh
716         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
717
718         // get IDs from submesh
719         SMESH::long_array_var anElementsIds = new SMESH::long_array;
720         anElementsIds = aSubMesh->GetElementsId();
721         for (int i = 0; i < anElementsIds->length(); i++) {
722           myElementsId += QString(" %1").arg(anElementsIds[i]);
723         }
724         aNbUnits = anElementsIds->length();
725       } else { // GROUP
726         // get smesh group
727         SMESH::SMESH_GroupBase_var aGroup =
728           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
729         if (aGroup->_is_nil())
730           return;
731
732         // get IDs from smesh group
733         SMESH::long_array_var anElementsIds = new SMESH::long_array;
734         anElementsIds = aGroup->GetListOfID();
735         for (int i = 0; i < anElementsIds->length(); i++) {
736           myElementsId += QString(" %1").arg(anElementsIds[i]);
737         }
738         aNbUnits = anElementsIds->length();
739       }
740         */
741     } else {
742       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
743       myElementsId = aString;
744       if (aNbUnits < 1)
745         return;  
746     }
747
748     myNbOkElements = true;
749   } else {
750     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
751     if (aNbUnits != 1)
752       return;
753
754     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
755     if (!aMesh)
756       return;
757
758     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
759     if (!n)
760       return;
761
762     double x = n->X();
763     double y = n->Y();
764     double z = n->Z();
765
766     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
767       SpinBox1_1->SetValue(x);
768       SpinBox1_2->SetValue(y);
769       SpinBox1_3->SetValue(z);
770     }
771     else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
772       SpinBox_FX->SetValue(x);
773       SpinBox_FY->SetValue(y);
774       SpinBox_FZ->SetValue(z);
775     }
776   }
777
778   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
779     LineEditElements->setText(aString);
780     LineEditElements->repaint();
781     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
782     LineEditElements->setEnabled(true); 
783     setNewMeshName();
784   }
785
786   // OK
787   if (myNbOkElements) {
788     buttonOk->setEnabled(true);
789     buttonApply->setEnabled(true);
790   }
791 }
792
793 //=================================================================================
794 // function : SetEditCurrentArgument()
795 // purpose  :
796 //=================================================================================
797 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
798 {
799   QPushButton* send = (QPushButton*)sender();
800
801   disconnect(mySelectionMgr, 0, this, 0);
802   mySelectionMgr->clearSelected();
803   mySelectionMgr->clearFilters();
804
805   if (send == SelectElementsButton) {
806     myEditCurrentArgument = (QWidget*)LineEditElements;
807     SMESH::SetPointRepresentation(false);
808     if (CheckBoxMesh->isChecked()) {
809       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
810         aViewWindow->SetSelectionMode( ActorSelection );
811       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
812     }
813     else {
814       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815         aViewWindow->SetSelectionMode( CellSelection );
816     }
817   }
818   else if (send == SelectButton1) {
819     myEditCurrentArgument = (QWidget*)SpinBox1_1;
820     SMESH::SetPointRepresentation(true);
821     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822       aViewWindow->SetSelectionMode( NodeSelection );
823   }
824
825   myEditCurrentArgument->setFocus();
826   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
827   SelectionIntoArgument();
828 }
829
830 //=================================================================================
831 // function : DeactivateActiveDialog()
832 // purpose  :
833 //=================================================================================
834 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
835 {
836   if (ConstructorsBox->isEnabled()) {
837     ConstructorsBox->setEnabled(false);
838     GroupArguments->setEnabled(false);
839     GroupButtons->setEnabled(false);
840     mySMESHGUI->ResetState();
841     mySMESHGUI->SetActiveDialogBox(0);
842   }
843 }
844
845 //=================================================================================
846 // function : ActivateThisDialog()
847 // purpose  :
848 //=================================================================================
849 void SMESHGUI_ScaleDlg::ActivateThisDialog()
850 {
851   /* Emit a signal to deactivate the active dialog */
852   mySMESHGUI->EmitSignalDeactivateDialog();
853   ConstructorsBox->setEnabled(true);
854   GroupArguments->setEnabled(true);
855   GroupButtons->setEnabled(true);
856
857   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
858
859   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
860     aViewWindow->SetSelectionMode( CellSelection );
861
862   SelectionIntoArgument();
863 }
864
865 //=================================================================================
866 // function : enterEvent()
867 // purpose  :
868 //=================================================================================
869 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
870 {
871   if (!ConstructorsBox->isEnabled())
872     ActivateThisDialog();
873 }
874
875 //=================================================================================
876 // function : closeEvent()
877 // purpose  :
878 //=================================================================================
879 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
880 {
881   /* same than click on cancel button */
882   ClickOnCancel();
883 }
884
885 //=======================================================================
886 //function : hideEvent
887 //purpose  : caused by ESC key
888 //=======================================================================
889 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
890 {
891   if (!isMinimized())
892     ClickOnCancel();
893 }
894
895 //=======================================================================
896 //function : onSelectMesh
897 //purpose  :
898 //=======================================================================
899 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
900 {
901   if (toSelectMesh)
902     TextLabelElements->setText(tr("SMESH_NAME"));
903   else
904     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
905   myFilterBtn->setEnabled(!toSelectMesh);
906
907   if (myEditCurrentArgument != LineEditElements) {
908     LineEditElements->clear();
909     return;
910   }
911
912   mySelectionMgr->clearFilters();
913   SMESH::SetPointRepresentation(false);
914
915   if (toSelectMesh) {
916     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
917       aViewWindow->SetSelectionMode( ActorSelection );
918     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
919     LineEditElements->setReadOnly(true);
920     LineEditElements->setValidator(0);
921   } else {
922     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923       aViewWindow->SetSelectionMode( CellSelection );
924     LineEditElements->setReadOnly(false);
925     LineEditElements->setValidator(myIdValidator);
926     onTextChange(LineEditElements->text());
927   }
928
929   SelectionIntoArgument();
930 }
931
932 //=======================================================================
933 //function : onActionClicked
934 //purpose  : slot called when an action type changed
935 //=======================================================================
936
937 void SMESHGUI_ScaleDlg::onActionClicked(int button)
938 {
939   switch ( button ) {
940   case MOVE_ELEMS_BUTTON:
941     MakeGroupsCheck->setEnabled(false);
942     LineEditNewMesh->setEnabled(false);
943     break;
944   case COPY_ELEMS_BUTTON:
945     LineEditNewMesh->setEnabled(false);
946     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
947     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
948       MakeGroupsCheck->setEnabled(true);
949     else
950       MakeGroupsCheck->setEnabled(false);
951     break;
952   case MAKE_MESH_BUTTON:
953     LineEditNewMesh->setEnabled(true);
954     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
955     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
956       MakeGroupsCheck->setEnabled(true);
957     else
958       MakeGroupsCheck->setEnabled(false);
959     break;
960   }
961   setNewMeshName();
962 }
963
964 //=======================================================================
965 //function : setNewMeshName
966 //purpose  : update contents of LineEditNewMesh
967 //=======================================================================
968
969 void SMESHGUI_ScaleDlg::setNewMeshName()
970 {
971   LineEditNewMesh->setText("");
972   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
973     QString name;
974     if ( CheckBoxMesh->isChecked() ) {
975       name = LineEditElements->text();
976     }
977     else {
978       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
979       name = meshSO->GetName().c_str();
980     }
981     if ( !name.isEmpty() )
982       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
983   }
984 }
985
986 //=================================================================================
987 // function : GetConstructorId()
988 // purpose  :
989 //=================================================================================
990 int SMESHGUI_ScaleDlg::GetConstructorId()
991 {
992   return GroupConstructors->checkedId();
993 }
994
995 //=================================================================================
996 // function : keyPressEvent()
997 // purpose  :
998 //=================================================================================
999 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1000 {
1001   QDialog::keyPressEvent( e );
1002   if ( e->isAccepted() )
1003     return;
1004
1005   if ( e->key() == Qt::Key_F1 ) {
1006     e->accept();
1007     ClickOnHelp();
1008   }
1009 }
1010
1011 //=================================================================================
1012 // function : setFilters()
1013 // purpose  : SLOT. Called when "Filter" button pressed.
1014 //=================================================================================
1015 void SMESHGUI_ScaleDlg::setFilters()
1016 {
1017   if(myMesh->_is_nil()) {
1018     SUIT_MessageBox::critical(this,
1019                               tr("SMESH_ERROR"),
1020                               tr("NO_MESH_SELECTED"));
1021    return;
1022   }
1023   if ( !myFilterDlg )
1024     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1025
1026   myFilterDlg->SetSelection();
1027   myFilterDlg->SetMesh( myMesh );
1028   myFilterDlg->SetSourceWg( LineEditElements );
1029
1030   myFilterDlg->show();
1031 }
1032
1033 //=================================================================================
1034 // function : isValid
1035 // purpose  :
1036 //=================================================================================
1037 bool SMESHGUI_ScaleDlg::isValid()
1038 {
1039   bool ok = true;
1040   QString msg;
1041
1042   ok = SpinBox1_1->isValid( msg, true ) && ok;
1043   ok = SpinBox1_2->isValid( msg, true ) && ok;
1044   ok = SpinBox1_3->isValid( msg, true ) && ok;
1045   ok = SpinBox_FX->isValid( msg, true ) && ok;
1046   if (GetConstructorId() == 1) {
1047     ok = SpinBox_FY->isValid( msg, true ) && ok;
1048     ok = SpinBox_FZ->isValid( msg, true ) && ok;
1049   }
1050
1051   if( !ok ) {
1052     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1053     if ( !msg.isEmpty() )
1054       str += "\n" + msg;
1055     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1056     return false;
1057   }
1058   return true;
1059 }