Salome HOME
Fix regression (SIGSEGV) caused by improvement 0022099
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ScaleDlg.cxx
1 // Copyright (C) 2007-2013  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 //  File   : SMESHGUI_ScaleDlg.cxx
20 //  Author : Michael ZORIN, Open CASCADE S.A.S.
21 //  SMESH includes
22
23 #include "SMESHGUI_ScaleDlg.h"
24
25 #include "SMESHGUI.h"
26 #include "SMESHGUI_SpinBox.h"
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESHGUI_MeshUtils.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_MeshEditPreview.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 #include <SALOME_ListIteratorOfListIO.hxx>
53
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient.hxx>
56 #include <SALOMEDSClient_SObject.hxx>
57
58 // OCCT includes
59 #include <TColStd_MapOfInteger.hxx>
60
61 // Qt includes
62 #include <QApplication>
63 #include <QButtonGroup>
64 #include <QGroupBox>
65 #include <QLabel>
66 #include <QLineEdit>
67 #include <QPushButton>
68 #include <QRadioButton>
69 #include <QCheckBox>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
73 #include <QSpinBox>
74 #include <QKeyEvent>
75
76 // IDL includes
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
82
83 /*!
84   \class BusyLocker
85   \brief Simple 'busy state' flag locker.
86   \internal
87 */
88
89 class BusyLocker
90 {
91 public:
92   //! Constructor. Sets passed boolean flag to \c true.
93   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
94   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
95   ~BusyLocker() { myBusy = false; }
96 private:
97   bool& myBusy; //! External 'busy state' boolean flag
98 };
99
100 #define SPACING 6
101 #define MARGIN  11
102
103 //To disable automatic genericobj management, the following line should be commented.
104 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
105 #define WITHGENERICOBJ
106
107 //=================================================================================
108 // class    : SMESHGUI_ScaleDlg()
109 // purpose  :
110 //=================================================================================
111 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule ) : 
112     SMESHGUI_MultiPreviewDlg( theModule ),
113     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114     myFilterDlg(0)
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   //Preview check box
215   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
216
217   // layout
218   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
219   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
221   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
222   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
223   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
224   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
225   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
226   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
227   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
228   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
229   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
230   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
231   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
232   GroupArgumentsLayout->addWidget(SpinBox_FX,           3, 3);
233   GroupArgumentsLayout->addWidget(TextLabel3,           4, 0);
234   GroupArgumentsLayout->addWidget(SpinBox_FY,           4, 3);
235   GroupArgumentsLayout->addWidget(TextLabel4,           5, 0);
236   GroupArgumentsLayout->addWidget(SpinBox_FZ,           5, 3);
237   GroupArgumentsLayout->addWidget(ActionBox,            7, 0, 3, 4);
238   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      8, 5, 1, 4);
239   GroupArgumentsLayout->addWidget(LineEditNewMesh,      9, 5, 1, 4);
240   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    10, 0);
241
242   /***************************************************************/
243   GroupButtons = new QGroupBox(this);
244   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
245   GroupButtonsLayout->setSpacing(SPACING);
246   GroupButtonsLayout->setMargin(MARGIN);
247
248   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
249   buttonOk->setAutoDefault(true);
250   buttonOk->setDefault(true);
251   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
252   buttonApply->setAutoDefault(true);
253   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
254   buttonCancel->setAutoDefault(true);
255   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
256   buttonHelp->setAutoDefault(true);
257
258   GroupButtonsLayout->addWidget(buttonOk);
259   GroupButtonsLayout->addSpacing(10);
260   GroupButtonsLayout->addWidget(buttonApply);
261   GroupButtonsLayout->addSpacing(10);
262   GroupButtonsLayout->addStretch();
263   GroupButtonsLayout->addWidget(buttonCancel);
264   GroupButtonsLayout->addWidget(buttonHelp);
265
266   /***************************************************************/
267   SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
268   SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
269   SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
270
271   /* Initialisations */
272   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275   SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
276   SpinBox_FX->SetStep(0.1);
277   SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
278   SpinBox_FY->SetStep(0.1);
279   SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
280   SpinBox_FZ->SetStep(0.1);
281
282   RadioButton1->setChecked(true);
283
284   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285
286   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287
288   // Costruction of the logical filter
289   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
290   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
291
292   QList<SUIT_SelectionFilter*> aListOfFilters;
293   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
294   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
295
296   myMeshOrSubMeshOrGroupFilter =
297     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
298
299   myHelpFileName = "scale_page.html";
300
301   Init();
302
303   /* signals and slots connections */
304   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
305   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
306   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
307   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
308   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309
310   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
312
313   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
315   /* to close dialog if study change */
316   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
317   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
318   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
319   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
320
321   connect(SpinBox1_1,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322   connect(SpinBox1_2,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323   connect(SpinBox1_3,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324
325   connect(SpinBox_FX,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326   connect(SpinBox_FY,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327   connect(SpinBox_FZ,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328
329   //To Connect preview check box
330   connectPreviewControl();
331
332   ConstructorsClicked(0);
333   SelectionIntoArgument();
334   onActionClicked(MOVE_ELEMS_BUTTON);
335 }
336
337 //=================================================================================
338 // function : ~SMESHGUI_ScaleDlg()
339 // purpose  : Destroys the object and frees any allocated resources
340 //=================================================================================
341 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
342 {
343   if ( myFilterDlg ) {
344     myFilterDlg->setParent( 0 );
345     delete myFilterDlg;
346     myFilterDlg = 0;
347   }
348 }
349
350 //=================================================================================
351 // function : Init()
352 // purpose  :
353 //=================================================================================
354 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
355 {
356   myBusy = false;
357   myObjects.clear();
358   myObjectsNames.clear();
359   myMeshes.clear();
360
361   myEditCurrentArgument = 0;
362   LineEditElements->clear();
363   myElementsId = "";
364   myNbOkElements = 0;
365
366   buttonOk->setEnabled(false);
367   buttonApply->setEnabled(false);
368
369   myActor = 0;
370
371   if (ResetControls) {
372     SpinBox1_1->SetValue(0.0);
373     SpinBox1_2->SetValue(0.0);
374     SpinBox1_3->SetValue(0.0);
375     SpinBox_FX->SetValue(1.0);
376     SpinBox_FY->SetValue(1.0);
377     SpinBox_FZ->SetValue(1.0);
378     myPreviewCheckBox->setChecked(false);
379     onDisplaySimulation(false);
380
381     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
382     CheckBoxMesh->setChecked(false);
383     onSelectMesh(false);
384   }
385 }
386
387 //=================================================================================
388 // function : ConstructorsClicked()
389 // purpose  : Radio button management
390 //=================================================================================
391 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
392 {
393   disconnect(mySelectionMgr, 0, this, 0);
394
395   switch (constructorId) {
396   case 0:
397     {
398       TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
399       TextLabel3->hide();
400       TextLabel4->hide();
401       SpinBox_FY->hide();
402       SpinBox_FZ->hide();
403       break;
404     }
405   case 1:
406     {
407       TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
408       TextLabel3->show();
409       TextLabel4->show();
410       SpinBox_FY->show();
411       SpinBox_FZ->show();
412       break;
413     }
414   }
415
416   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
417     SMESH::SetPointRepresentation(false);
418     if (!CheckBoxMesh->isChecked())
419       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420         aViewWindow->SetSelectionMode( CellSelection );
421   }
422
423   myEditCurrentArgument = (QWidget*)LineEditElements;
424   LineEditElements->setFocus();
425
426   if (CheckBoxMesh->isChecked())
427     onSelectMesh(true);
428
429   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
430
431   QApplication::instance()->processEvents();
432   updateGeometry();
433   resize(100,100);
434 }
435
436 //=================================================================================
437 // function : ClickOnApply()
438 // purpose  :
439 //=================================================================================
440 bool SMESHGUI_ScaleDlg::ClickOnApply()
441 {
442   if (mySMESHGUI->isActiveStudyLocked())
443     return false;
444
445   if( !isValid() )
446     return false;
447
448   if (myNbOkElements) {
449     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
450
451     SMESH::long_array_var anElementsId = new SMESH::long_array;
452
453     anElementsId->length(aListElementsId.count());
454     for (int i = 0; i < aListElementsId.count(); i++)
455       anElementsId[i] = aListElementsId[i].toInt();
456
457     SMESH::PointStruct aPoint;
458     SMESH::double_array_var aScaleFact = new SMESH::double_array;
459     getScale(aPoint, aScaleFact);
460
461     QStringList aParameters;
462     aParameters << SpinBox1_1->text();
463     aParameters << SpinBox1_2->text();
464     aParameters << SpinBox1_3->text();
465     aParameters << SpinBox_FX->text();
466     if (GetConstructorId() == 1) {
467       aParameters << SpinBox_FX->text();
468       aParameters << SpinBox_FX->text();
469     }
470     else {
471       aParameters << SpinBox_FY->text();
472       aParameters << SpinBox_FZ->text();
473     }
474
475     int actionButton = ActionGroup->checkedId();
476     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
477     QStringList anEntryList;
478     try {
479       SUIT_OverrideCursor aWaitCursor;
480      
481       switch ( actionButton ) {
482
483       case MOVE_ELEMS_BUTTON:
484         if ( CheckBoxMesh->isChecked() )
485           for ( int i = 0; i < myObjects.count(); i++ ) {
486             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
487             myMeshes[i]->SetParameters( aParameters.join( ":" ).toLatin1().constData() );
488             aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, false);
489           }
490         else {
491           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
492           myMeshes[0]->SetParameters( aParameters.join( ":" ).toLatin1().constData() );
493           aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, false);
494         }
495         break;
496
497       case COPY_ELEMS_BUTTON:
498         if ( makeGroups ) {
499           SMESH::ListOfGroups_var groups;
500           if(CheckBoxMesh->isChecked())
501             for ( int i = 0; i < myObjects.count(); i++ ) {
502               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
503               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
504               groups = aMeshEditor->ScaleMakeGroups(myObjects[i], aPoint, aScaleFact);
505             }
506           else {
507             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
508             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
509             groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact);
510           }
511         }
512         else {
513           if(CheckBoxMesh->isChecked()) {
514             for ( int i = 0; i < myObjects.count(); i++ ) {
515               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
516               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
517               aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, true);
518             }
519           }
520           else {
521             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
522             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
523             aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, true);
524           }
525         }
526         break;
527
528       case MAKE_MESH_BUTTON: {
529         SMESH::SMESH_Mesh_var mesh;
530         if (CheckBoxMesh->isChecked()) {
531           for ( int i = 0; i < myObjects.count(); i++ ) {
532             QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
533             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
534             myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
535             mesh = aMeshEditor->ScaleMakeMesh(myObjects[i], aPoint, aScaleFact, makeGroups,
536                                               aName.toLatin1().data());
537             if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
538               anEntryList.append( aSObject->GetID().c_str() );
539 #ifdef WITHGENERICOBJ
540             // obj has been published in study. Its refcount has been incremented.
541             // It is safe to decrement its refcount
542             // so that it will be destroyed when the entry in study will be removed
543             mesh->UnRegister();
544 #endif
545           }
546         }
547         else {
548           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
549           myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
550           mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, makeGroups,
551                                               LineEditNewMesh->text().toLatin1().data());
552           if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
553             anEntryList.append( aSObject->GetID().c_str() );
554 #ifdef WITHGENERICOBJ
555           // obj has been published in study. Its refcount has been incremented.
556           // It is safe to decrement its refcount
557           // so that it will be destroyed when the entry in study will be removed
558           mesh->UnRegister();
559 #endif
560         }
561         break;
562       }
563       }
564     } catch (...) {
565     }
566
567     for ( int i = 0; i < myObjects.count(); i++ ) {
568       SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
569       if ( actor ) SMESH::Update( actor->getIO(), true );
570     }
571
572     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
573          actionButton == MAKE_MESH_BUTTON ) {
574       mySMESHGUI->updateObjBrowser(true); // new groups may appear
575       if( LightApp_Application* anApp =
576           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
577         anApp->browseObjects( anEntryList, isApplyAndClose() );
578     }
579     Init(false);
580     ConstructorsClicked(GetConstructorId());
581     SelectionIntoArgument();
582
583     SMESHGUI::Modified();
584   }
585
586   return true;
587 }
588
589 //=================================================================================
590 // function : ClickOnOk()
591 // purpose  :
592 //=================================================================================
593 void SMESHGUI_ScaleDlg::ClickOnOk()
594 {
595   setIsApplyAndClose( true );
596   if( ClickOnApply() )
597     reject();
598 }
599
600 //=================================================================================
601 // function : reject()
602 // purpose  :
603 //=================================================================================
604 void SMESHGUI_ScaleDlg::reject()
605 {
606   disconnect(mySelectionMgr, 0, this, 0);
607   mySelectionMgr->clearFilters();
608   //mySelectionMgr->clearSelected();
609   if (SMESH::GetCurrentVtkView()) {
610     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
611     SMESH::SetPointRepresentation(false);
612   }
613   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
614     aViewWindow->SetSelectionMode( ActorSelection );
615   mySMESHGUI->ResetState();
616   QDialog::reject();
617 }
618
619 //=================================================================================
620 // function : ClickOnHelp()
621 // purpose  :
622 //=================================================================================
623 void SMESHGUI_ScaleDlg::ClickOnHelp()
624 {
625   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
626   if (app)
627     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
628   else {
629     QString platform;
630 #ifdef WIN32
631     platform = "winapplication";
632 #else
633     platform = "application";
634 #endif
635     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
636                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
637                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
638                                                                  platform)).
639                              arg(myHelpFileName));
640   }
641 }
642
643 //=======================================================================
644 // function : onTextChange()
645 // purpose  :
646 //=======================================================================
647 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
648 {
649   QLineEdit* send = (QLineEdit*)sender();
650
651   if (myBusy) return;
652   BusyLocker lock( myBusy );
653
654   if (send == LineEditElements)
655     myNbOkElements = 0;
656
657   buttonOk->setEnabled(false);
658   buttonApply->setEnabled(false);
659
660   // hilight entered elements
661   SMDS_Mesh* aMesh = 0;
662   if (myActor)
663     aMesh = myActor->GetObject()->GetMesh();
664
665   if (aMesh) {
666     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
667
668     TColStd_MapOfInteger newIndices;
669
670     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
671
672     if (send == LineEditElements) {
673       for (int i = 0; i < aListId.count(); i++) {
674         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
675         if (e)
676           newIndices.Add(e->GetID());
677         myNbOkElements++;
678       }
679     }
680
681     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
682     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
683       aViewWindow->highlight( anIO, true, true );
684
685     myElementsId = theNewText;
686   }
687
688   if (myNbOkElements) {
689     buttonOk->setEnabled(true);
690     buttonApply->setEnabled(true);
691   }
692 }
693
694 //=================================================================================
695 // function : SelectionIntoArgument()
696 // purpose  : Called when selection as changed or other case
697 //=================================================================================
698 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
699 {
700   if (myBusy) return;
701   BusyLocker lock( myBusy );
702   // clear
703   myActor = 0;
704   QString aString = "";
705   onDisplaySimulation(false);
706
707   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
708     LineEditElements->setText(aString);
709     myNbOkElements = 0;
710     buttonOk->setEnabled(false);
711     buttonApply->setEnabled(false);
712   }
713
714   if (!GroupButtons->isEnabled()) // inactive
715     return;
716
717   // get selected mesh
718   SALOME_ListIO aList;
719   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
720
721   int nbSel = aList.Extent();
722   if (nbSel < 1)
723     return;
724
725   int aNbUnits = 0;
726
727   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
728     myElementsId = "";
729     myObjects.clear();
730     myObjectsNames.clear();
731     myMeshes.clear();
732
733     for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
734       Handle(SALOME_InteractiveObject) IO = it.Value();
735       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
736       if ( aMesh->_is_nil() )
737         return;
738   
739       myActor = SMESH::FindActorByObject( aMesh );
740       if ( !myActor )
741         myActor = SMESH::FindActorByEntry( IO->getEntry() );
742       if ( !myActor && !CheckBoxMesh->isChecked() )
743         return;
744
745       if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
746         if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
747           _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
748           _PTR(GenericAttribute) anAttr;
749           if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
750             _PTR(AttributeName) aNameAttr( anAttr );
751             myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
752             myObjectsNames << aNameAttr->Value().c_str();
753             myMeshes << aMesh;
754           }
755         }
756       }
757     }
758       
759     // MakeGroups is available if there are groups and "Copy"
760     int aNbGroups = 0;
761     for ( int i = 0; i < myMeshes.count(); i++ )
762       aNbGroups += myMeshes[i]->NbGroups();
763
764     if ( aNbGroups == 0 ) {
765       MakeGroupsCheck->setChecked(false);
766       MakeGroupsCheck->setEnabled(false);
767     }
768     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
769       MakeGroupsCheck->setEnabled(true);
770     }
771
772     if (CheckBoxMesh->isChecked()) {
773       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
774       if (myMeshes.isEmpty())
775         return;
776         // get IDs from mesh
777         /*
778         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
779         if (!aSMDSMesh)
780           return;
781
782         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
783           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
784           if (e) {
785             myElementsId += QString(" %1").arg(i);
786             aNbUnits++;
787           }
788         }
789       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
790         // get submesh
791         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
792
793         // get IDs from submesh
794         SMESH::long_array_var anElementsIds = new SMESH::long_array;
795         anElementsIds = aSubMesh->GetElementsId();
796         for (int i = 0; i < anElementsIds->length(); i++) {
797           myElementsId += QString(" %1").arg(anElementsIds[i]);
798         }
799         aNbUnits = anElementsIds->length();
800       } else { // GROUP
801         // get smesh group
802         SMESH::SMESH_GroupBase_var aGroup =
803           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
804         if (aGroup->_is_nil())
805           return;
806
807         // get IDs from smesh group
808         SMESH::long_array_var anElementsIds = new SMESH::long_array;
809         anElementsIds = aGroup->GetListOfID();
810         for (int i = 0; i < anElementsIds->length(); i++) {
811           myElementsId += QString(" %1").arg(anElementsIds[i]);
812         }
813         aNbUnits = anElementsIds->length();
814       }
815         */
816     } else {
817       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
818       myElementsId = aString;
819       if (aNbUnits < 1)
820         return;
821     }
822
823     myNbOkElements = true;
824   } else {
825     Handle(SALOME_InteractiveObject) IO = aList.First();
826     if ((SMESH::GetMeshByIO(IO))->_is_nil())
827       return;
828
829     SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
830     if (!anActor)
831       anActor = SMESH::FindActorByEntry(IO->getEntry());
832     if (!anActor && !CheckBoxMesh->isChecked())
833       return;
834
835     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
836     if (aNbUnits != 1)
837       return;
838
839     SMDS_Mesh* aMesh =  anActor->GetObject()->GetMesh();
840     if (!aMesh)
841       return;
842
843     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
844     if (!n)
845       return;
846
847     double x = n->X();
848     double y = n->Y();
849     double z = n->Z();
850
851     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
852       SpinBox1_1->SetValue(x);
853       SpinBox1_2->SetValue(y);
854       SpinBox1_3->SetValue(z);
855     }
856     else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
857       SpinBox_FX->SetValue(x);
858       SpinBox_FY->SetValue(y);
859       SpinBox_FZ->SetValue(z);
860     }
861   }
862
863   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
864     LineEditElements->setText(aString);
865     LineEditElements->repaint();
866     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
867     LineEditElements->setEnabled(true);
868     setNewMeshName();
869   }
870
871   // OK
872   if (myNbOkElements) {
873     buttonOk->setEnabled(true);
874     buttonApply->setEnabled(true);
875   }
876   
877   onDisplaySimulation(true);
878 }
879
880 //=================================================================================
881 // function : SetEditCurrentArgument()
882 // purpose  :
883 //=================================================================================
884 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
885 {
886   QPushButton* send = (QPushButton*)sender();
887
888   disconnect(mySelectionMgr, 0, this, 0);
889   mySelectionMgr->clearSelected();
890   mySelectionMgr->clearFilters();
891
892   if (send == SelectElementsButton) {
893     myEditCurrentArgument = (QWidget*)LineEditElements;
894     SMESH::SetPointRepresentation(false);
895     if (CheckBoxMesh->isChecked()) {
896       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
897         aViewWindow->SetSelectionMode( ActorSelection );
898       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
899     }
900     else {
901       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
902         aViewWindow->SetSelectionMode( CellSelection );
903     }
904   }
905   else if (send == SelectButton1) {
906     myEditCurrentArgument = (QWidget*)SpinBox1_1;
907     SMESH::SetPointRepresentation(true);
908     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
909       aViewWindow->SetSelectionMode( NodeSelection );
910   }
911
912   myEditCurrentArgument->setFocus();
913   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
914   SelectionIntoArgument();
915 }
916
917 //=================================================================================
918 // function : DeactivateActiveDialog()
919 // purpose  :
920 //=================================================================================
921 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
922 {
923   if (ConstructorsBox->isEnabled()) {
924     ConstructorsBox->setEnabled(false);
925     GroupArguments->setEnabled(false);
926     GroupButtons->setEnabled(false);
927     mySMESHGUI->ResetState();
928     mySMESHGUI->SetActiveDialogBox(0);
929   }
930 }
931
932 //=================================================================================
933 // function : ActivateThisDialog()
934 // purpose  :
935 //=================================================================================
936 void SMESHGUI_ScaleDlg::ActivateThisDialog()
937 {
938   /* Emit a signal to deactivate the active dialog */
939   mySMESHGUI->EmitSignalDeactivateDialog();
940   ConstructorsBox->setEnabled(true);
941   GroupArguments->setEnabled(true);
942   GroupButtons->setEnabled(true);
943
944   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
945
946   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
947     aViewWindow->SetSelectionMode( CellSelection );
948
949   SelectionIntoArgument();
950 }
951
952 //=================================================================================
953 // function : enterEvent()
954 // purpose  :
955 //=================================================================================
956 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
957 {
958   if (!ConstructorsBox->isEnabled())
959     ActivateThisDialog();
960 }
961
962 //=======================================================================
963 //function : onSelectMesh
964 //purpose  :
965 //=======================================================================
966 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
967 {
968   if (toSelectMesh)
969     TextLabelElements->setText(tr("SMESH_NAME"));
970   else
971     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
972   myFilterBtn->setEnabled(!toSelectMesh);
973
974   if (myEditCurrentArgument != LineEditElements) {
975     LineEditElements->clear();
976     return;
977   }
978
979   mySelectionMgr->clearFilters();
980   SMESH::SetPointRepresentation(false);
981
982   if (toSelectMesh) {
983     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
984       aViewWindow->SetSelectionMode( ActorSelection );
985     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
986     LineEditElements->setReadOnly(true);
987     LineEditElements->setValidator(0);
988   } else {
989     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
990       aViewWindow->SetSelectionMode( CellSelection );
991     LineEditElements->setReadOnly(false);
992     LineEditElements->setValidator(myIdValidator);
993     onTextChange(LineEditElements->text());
994     hidePreview();
995   }
996
997   SelectionIntoArgument();
998 }
999
1000 //=======================================================================
1001 //function : onActionClicked
1002 //purpose  : slot called when an action type changed
1003 //=======================================================================
1004
1005 void SMESHGUI_ScaleDlg::onActionClicked(int button)
1006 {
1007   int aNbGroups = 0;
1008   for ( int i = 0; i < myMeshes.count(); i++ )
1009     aNbGroups += myMeshes[i]->NbGroups();
1010
1011   switch ( button ) {
1012   case MOVE_ELEMS_BUTTON:
1013     MakeGroupsCheck->setEnabled(false);
1014     LineEditNewMesh->setEnabled(false);
1015     break;
1016   case COPY_ELEMS_BUTTON:
1017     LineEditNewMesh->setEnabled(false);
1018     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1019     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1020     break;
1021   case MAKE_MESH_BUTTON:
1022     LineEditNewMesh->setEnabled(true);
1023     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1024     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1025     break;
1026   }
1027   setNewMeshName();
1028   toDisplaySimulation();
1029 }
1030
1031 //=======================================================================
1032 //function : setNewMeshName
1033 //purpose  : update contents of LineEditNewMesh
1034 //=======================================================================
1035
1036 void SMESHGUI_ScaleDlg::setNewMeshName()
1037 {
1038   LineEditNewMesh->setText("");
1039   if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1040     QString name;
1041     if ( CheckBoxMesh->isChecked() ) {
1042       name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1043     }
1044     else {
1045       _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1046       name = meshSO->GetName().c_str();
1047     }
1048     if ( !name.isEmpty() )
1049       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1050   }
1051 }
1052
1053 //=================================================================================
1054 // function : GetConstructorId()
1055 // purpose  :
1056 //=================================================================================
1057 int SMESHGUI_ScaleDlg::GetConstructorId()
1058 {
1059   return GroupConstructors->checkedId();
1060 }
1061
1062 //=================================================================================
1063 // function : keyPressEvent()
1064 // purpose  :
1065 //=================================================================================
1066 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1067 {
1068   QDialog::keyPressEvent( e );
1069   if ( e->isAccepted() )
1070     return;
1071
1072   if ( e->key() == Qt::Key_F1 ) {
1073     e->accept();
1074     ClickOnHelp();
1075   }
1076 }
1077
1078 //=================================================================================
1079 // function : setFilters()
1080 // purpose  : SLOT. Called when "Filter" button pressed.
1081 //=================================================================================
1082 void SMESHGUI_ScaleDlg::setFilters()
1083 {
1084   if(myMeshes.isEmpty()) {
1085     SUIT_MessageBox::critical(this,
1086                               tr("SMESH_ERROR"),
1087                               tr("NO_MESH_SELECTED"));
1088    return;
1089   }
1090   if ( !myFilterDlg )
1091     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1092
1093   myFilterDlg->SetSelection();
1094   myFilterDlg->SetMesh( myMeshes[0] );
1095   myFilterDlg->SetSourceWg( LineEditElements );
1096
1097   myFilterDlg->show();
1098 }
1099
1100 //=================================================================================
1101 // function : isValid
1102 // purpose  :
1103 //=================================================================================
1104 bool SMESHGUI_ScaleDlg::isValid()
1105 {
1106   bool ok = true;
1107   QString msg;
1108
1109   ok = SpinBox1_1->isValid( msg, true ) && ok;
1110   ok = SpinBox1_2->isValid( msg, true ) && ok;
1111   ok = SpinBox1_3->isValid( msg, true ) && ok;
1112   ok = SpinBox_FX->isValid( msg, true ) && ok;
1113   if (GetConstructorId() == 1) {
1114     ok = SpinBox_FY->isValid( msg, true ) && ok;
1115     ok = SpinBox_FZ->isValid( msg, true ) && ok;
1116   }
1117
1118   if( !ok ) {
1119     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1120     if ( !msg.isEmpty() )
1121       str += "\n" + msg;
1122     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1123     return false;
1124   }
1125   return true;
1126 }
1127
1128 //=================================================================================
1129 // function : onDisplaySimulation
1130 // purpose  : Show/Hide preview
1131 //=================================================================================
1132 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1133   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {    
1134     if ( myNbOkElements && isValid() ) {
1135       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1136
1137       SMESH::long_array_var anElementsId = new SMESH::long_array;
1138       
1139       anElementsId->length(aListElementsId.count());
1140       for (int i = 0; i < aListElementsId.count(); i++)
1141         anElementsId[i] = aListElementsId[i].toInt();
1142       
1143       SMESH::PointStruct aPoint;
1144       SMESH::double_array_var aScaleFact = new SMESH::double_array;
1145       getScale(aPoint, aScaleFact);
1146       
1147       try {
1148         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1149                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1150         SUIT_OverrideCursor aWaitCursor;
1151         QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1152
1153         if(CheckBoxMesh->isChecked())
1154           for ( int i = 0; i < myObjects.count(); i++ ) {
1155             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1156             aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, copy);
1157             aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1158           }
1159         else {
1160           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1161           aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, copy);
1162           aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1163         }
1164         setSimulationPreview(aMeshPreviewStruct);
1165       } catch (...) {
1166         hidePreview();
1167       }
1168     } else {
1169       hidePreview();
1170     } 
1171   } else {
1172     hidePreview();
1173   }
1174 }
1175
1176 //=================================================================================
1177 // function : getScale
1178 // purpose  : get scale parameters
1179 //=================================================================================
1180 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint ,  SMESH::double_array_var& theScaleFact) {
1181   thePoint.x = SpinBox1_1->GetValue();
1182   thePoint.y = SpinBox1_2->GetValue();
1183   thePoint.z = SpinBox1_3->GetValue();
1184   
1185   theScaleFact->length(3);
1186   theScaleFact[0] = SpinBox_FX->GetValue();
1187   if (GetConstructorId() == 0) {
1188     theScaleFact[1] = SpinBox_FX->GetValue();
1189     theScaleFact[2] = SpinBox_FX->GetValue();
1190   }
1191   else {
1192     theScaleFact[1] = SpinBox_FY->GetValue();
1193     theScaleFact[2] = SpinBox_FZ->GetValue();
1194   } 
1195 }