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