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