Salome HOME
52943: "Apply and Close" button does not active on symmetry dialog box
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ScaleDlg.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
53 // SALOME KERNEL includes
54 #include <SALOMEDSClient.hxx>
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     SMESHGUI_MultiPreviewDlg( theModule ),
108     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
109     myFilterDlg(0)
110 {
111   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
112   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
113   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
114
115   setModal(false);
116   setAttribute(Qt::WA_DeleteOnClose, true);
117   setWindowTitle(tr("SMESH_SCALE_TITLE"));
118   setSizeGripEnabled(true);
119
120   QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
121   SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
122   SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
123
124   /***************************************************************/
125   ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
126   GroupConstructors = new QButtonGroup(this);
127   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
128   ConstructorsBoxLayout->setSpacing(SPACING);
129   ConstructorsBoxLayout->setMargin(MARGIN);
130
131   RadioButton1= new QRadioButton(ConstructorsBox);
132   RadioButton1->setIcon(image0);
133   RadioButton2= new QRadioButton(ConstructorsBox);
134   RadioButton2->setIcon(image1);
135
136   ConstructorsBoxLayout->addWidget(RadioButton1);
137   ConstructorsBoxLayout->addWidget(RadioButton2);
138   GroupConstructors->addButton(RadioButton1, 0);
139   GroupConstructors->addButton(RadioButton2, 1);
140
141   /***************************************************************/
142   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
143   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
144   GroupArgumentsLayout->setSpacing(SPACING);
145   GroupArgumentsLayout->setMargin(MARGIN);
146
147   myIdValidator = new SMESHGUI_IdValidator(this);
148
149   // Controls for elements selection
150   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
151   SelectElementsButton = new QPushButton(GroupArguments);
152   SelectElementsButton->setIcon(image2);
153   LineEditElements = new QLineEdit(GroupArguments);
154   LineEditElements->setValidator(myIdValidator);
155   LineEditElements->setMaxLength(-1);
156   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
157   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
158
159   // Control for the whole mesh selection
160   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
161
162   // Controls for vector and points selection
163   TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
164   SelectButton1 = new QPushButton(GroupArguments);
165   SelectButton1->setIcon(image2);
166
167   TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
168   SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
169   TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
170   SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
171   TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
172   SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
173
174   TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
175   SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
176
177   TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
178   SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
179
180   TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
181   SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
182
183
184   // switch of action type
185   ActionBox = new QGroupBox(GroupArguments);
186   ActionGroup = new QButtonGroup(GroupArguments);
187   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
188   ActionBoxLayout->addSpacing(SPACING);
189   ActionBoxLayout->setMargin(MARGIN);
190
191   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
192   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
193   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
194
195   ActionBoxLayout->addWidget(aMoveElements);
196   ActionBoxLayout->addWidget(aCopyElements);
197   ActionBoxLayout->addWidget(aCreateMesh);
198   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
199   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
200   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
201
202   // CheckBox for groups generation
203   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
204   MakeGroupsCheck->setChecked(false);
205
206   // Name of a mesh to create
207   LineEditNewMesh = new QLineEdit(GroupArguments);
208
209   //Preview check box
210   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
211
212   // layout
213   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
214   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
216   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
217   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
218   GroupArgumentsLayout->addWidget(TextLabel1,           2, 0);
219   GroupArgumentsLayout->addWidget(SelectButton1,        2, 1);
220   GroupArgumentsLayout->addWidget(TextLabel1_1,         2, 2);
221   GroupArgumentsLayout->addWidget(SpinBox1_1,           2, 3);
222   GroupArgumentsLayout->addWidget(TextLabel1_2,         2, 4);
223   GroupArgumentsLayout->addWidget(SpinBox1_2,           2, 5);
224   GroupArgumentsLayout->addWidget(TextLabel1_3,         2, 6);
225   GroupArgumentsLayout->addWidget(SpinBox1_3,           2, 7);
226   GroupArgumentsLayout->addWidget(TextLabel2,           3, 0);
227   GroupArgumentsLayout->addWidget(SpinBox_FX,           3, 3);
228   GroupArgumentsLayout->addWidget(TextLabel3,           4, 0);
229   GroupArgumentsLayout->addWidget(SpinBox_FY,           4, 3);
230   GroupArgumentsLayout->addWidget(TextLabel4,           5, 0);
231   GroupArgumentsLayout->addWidget(SpinBox_FZ,           5, 3);
232   GroupArgumentsLayout->addWidget(ActionBox,            7, 0, 3, 4);
233   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      8, 5, 1, 4);
234   GroupArgumentsLayout->addWidget(LineEditNewMesh,      9, 5, 1, 4);
235   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    10, 0);
236
237   /***************************************************************/
238   GroupButtons = new QGroupBox(this);
239   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
240   GroupButtonsLayout->setSpacing(SPACING);
241   GroupButtonsLayout->setMargin(MARGIN);
242
243   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
244   buttonOk->setAutoDefault(true);
245   buttonOk->setDefault(true);
246   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
247   buttonApply->setAutoDefault(true);
248   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
249   buttonCancel->setAutoDefault(true);
250   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
251   buttonHelp->setAutoDefault(true);
252
253   GroupButtonsLayout->addWidget(buttonOk);
254   GroupButtonsLayout->addSpacing(10);
255   GroupButtonsLayout->addWidget(buttonApply);
256   GroupButtonsLayout->addSpacing(10);
257   GroupButtonsLayout->addStretch();
258   GroupButtonsLayout->addWidget(buttonCancel);
259   GroupButtonsLayout->addWidget(buttonHelp);
260
261   /***************************************************************/
262   SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
263   SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
264   SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
265
266   /* Initialisations */
267   SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268   SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269   SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270   SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
271   SpinBox_FX->SetStep(0.1);
272   SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
273   SpinBox_FY->SetStep(0.1);
274   SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
275   SpinBox_FZ->SetStep(0.1);
276
277   RadioButton1->setChecked(true);
278
279   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280
281   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282
283   // Costruction of the logical filter
284   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
285   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
286
287   QList<SUIT_SelectionFilter*> aListOfFilters;
288   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
290
291   myMeshOrSubMeshOrGroupFilter =
292     new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
293
294   myHelpFileName = "scale_page.html";
295
296   Init();
297
298   /* signals and slots connections */
299   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
301   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
304
305   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306   connect(SelectButton1,        SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307
308   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
310   /* to close dialog if study change */
311   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),      this, SLOT(reject()));
312   connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
313   connect(mySMESHGUI, SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
314
315   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
316   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
317   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
318
319   connect(SpinBox1_1,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320   connect(SpinBox1_2,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321   connect(SpinBox1_3,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322
323   connect(SpinBox_FX,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324   connect(SpinBox_FY,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325   connect(SpinBox_FZ,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326
327   //To Connect preview check box
328   connectPreviewControl();
329
330   ConstructorsClicked(0);
331   SelectionIntoArgument();
332   onActionClicked(MOVE_ELEMS_BUTTON);
333 }
334
335 //=================================================================================
336 // function : ~SMESHGUI_ScaleDlg()
337 // purpose  : Destroys the object and frees any allocated resources
338 //=================================================================================
339 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
340 {
341   if ( myFilterDlg ) {
342     myFilterDlg->setParent( 0 );
343     delete myFilterDlg;
344     myFilterDlg = 0;
345   }
346 }
347
348 //=================================================================================
349 // function : Init()
350 // purpose  :
351 //=================================================================================
352 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
353 {
354   myBusy = false;
355   myObjects.clear();
356   myObjectsNames.clear();
357   myMeshes.clear();
358
359   myEditCurrentArgument = 0;
360   LineEditElements->clear();
361   myElementsId = "";
362   myNbOkElements = 0;
363
364   buttonOk->setEnabled(false);
365   buttonApply->setEnabled(false);
366
367   myActor = 0;
368
369   if (ResetControls) {
370     SpinBox1_1->SetValue(0.0);
371     SpinBox1_2->SetValue(0.0);
372     SpinBox1_3->SetValue(0.0);
373     SpinBox_FX->SetValue(1.0);
374     SpinBox_FY->SetValue(1.0);
375     SpinBox_FZ->SetValue(1.0);
376     myPreviewCheckBox->setChecked(false);
377     onDisplaySimulation(false);
378
379     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
380     CheckBoxMesh->setChecked(false);
381     onSelectMesh(false);
382   }
383 }
384
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose  : Radio button management
388 //=================================================================================
389 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
390 {
391   disconnect(mySelectionMgr, 0, this, 0);
392
393   switch (constructorId) {
394   case 0:
395     {
396       TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
397       TextLabel3->hide();
398       TextLabel4->hide();
399       SpinBox_FY->hide();
400       SpinBox_FZ->hide();
401       break;
402     }
403   case 1:
404     {
405       TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
406       TextLabel3->show();
407       TextLabel4->show();
408       SpinBox_FY->show();
409       SpinBox_FZ->show();
410       break;
411     }
412   }
413
414   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
415     SMESH::SetPointRepresentation(false);
416     if (!CheckBoxMesh->isChecked())
417       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
418         aViewWindow->SetSelectionMode( CellSelection );
419   }
420
421   myEditCurrentArgument = (QWidget*)LineEditElements;
422   LineEditElements->setFocus();
423
424   if (CheckBoxMesh->isChecked())
425     onSelectMesh(true);
426
427   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
428
429   QApplication::instance()->processEvents();
430   myEditCurrentArgument->hide();
431   myEditCurrentArgument->show();
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           SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
493           myMeshes[0]->SetParameters( aParameters.join( ":" ).toLatin1().constData() );
494           aMeshEditor->Scale( src, aPoint, aScaleFact, false);
495         }
496         break;
497
498       case COPY_ELEMS_BUTTON:
499         if ( makeGroups ) {
500           SMESH::ListOfGroups_var groups;
501           if(CheckBoxMesh->isChecked())
502             for ( int i = 0; i < myObjects.count(); i++ ) {
503               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
504               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
505               groups = aMeshEditor->ScaleMakeGroups(myObjects[i], aPoint, aScaleFact);
506             }
507           else {
508             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
509             SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
510             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
511             groups = aMeshEditor->ScaleMakeGroups( src, aPoint, aScaleFact);
512           }
513         }
514         else {
515           if(CheckBoxMesh->isChecked()) {
516             for ( int i = 0; i < myObjects.count(); i++ ) {
517               SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
518               myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
519               aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, true);
520             }
521           }
522           else {
523             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
524             SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
525             myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
526             aMeshEditor->Scale( src, aPoint, aScaleFact, true);
527           }
528         }
529         break;
530
531       case MAKE_MESH_BUTTON: {
532         SMESH::SMESH_Mesh_var mesh;
533         if (CheckBoxMesh->isChecked()) {
534           for ( int i = 0; i < myObjects.count(); i++ ) {
535             QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
536             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
537             myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
538             mesh = aMeshEditor->ScaleMakeMesh(myObjects[i], aPoint, aScaleFact, makeGroups,
539                                               aName.toLatin1().data());
540             if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
541               anEntryList.append( aSObject->GetID().c_str() );
542           }
543         }
544         else {
545           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
546           myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
547           SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
548           mesh = aMeshEditor->ScaleMakeMesh( src, aPoint, aScaleFact, makeGroups,
549                                              LineEditNewMesh->text().toLatin1().data());
550           if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
551             anEntryList.append( aSObject->GetID().c_str() );
552         }
553         break;
554       }
555       }
556     } catch (...) {
557     }
558
559     for ( int i = 0; i < myObjects.count(); i++ ) {
560       SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
561       if ( actor ) SMESH::Update( actor->getIO(), true );
562     }
563
564     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
565          actionButton == MAKE_MESH_BUTTON ) {
566       mySMESHGUI->updateObjBrowser(true); // new groups may appear
567       if( LightApp_Application* anApp =
568           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
569         anApp->browseObjects( anEntryList, isApplyAndClose() );
570     }
571     Init(false);
572     ConstructorsClicked(GetConstructorId());
573     SelectionIntoArgument();
574
575     SMESHGUI::Modified();
576   }
577
578   return true;
579 }
580
581 //=================================================================================
582 // function : ClickOnOk()
583 // purpose  :
584 //=================================================================================
585 void SMESHGUI_ScaleDlg::ClickOnOk()
586 {
587   setIsApplyAndClose( true );
588   if( ClickOnApply() )
589     reject();
590 }
591
592 //=================================================================================
593 // function : reject()
594 // purpose  :
595 //=================================================================================
596 void SMESHGUI_ScaleDlg::reject()
597 {
598   disconnect(mySelectionMgr, 0, this, 0);
599   mySelectionMgr->clearFilters();
600   //mySelectionMgr->clearSelected();
601   if (SMESH::GetCurrentVtkView()) {
602     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
603     SMESH::SetPointRepresentation(false);
604   }
605   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
606     aViewWindow->SetSelectionMode( ActorSelection );
607   mySMESHGUI->ResetState();
608   QDialog::reject();
609 }
610
611 //=================================================================================
612 // function : onOpenView()
613 // purpose  :
614 //=================================================================================
615 void SMESHGUI_ScaleDlg::onOpenView()
616 {
617   if ( mySelector ) {
618     SMESH::SetPointRepresentation(false);
619   }
620   else {
621     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
622     ActivateThisDialog();
623   }
624 }
625
626 //=================================================================================
627 // function : onCloseView()
628 // purpose  :
629 //=================================================================================
630 void SMESHGUI_ScaleDlg::onCloseView()
631 {
632   DeactivateActiveDialog();
633   mySelector = 0;
634 }
635
636 //=================================================================================
637 // function : ClickOnHelp()
638 // purpose  :
639 //=================================================================================
640 void SMESHGUI_ScaleDlg::ClickOnHelp()
641 {
642   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
643   if (app)
644     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
645   else {
646     QString platform;
647 #ifdef WIN32
648     platform = "winapplication";
649 #else
650     platform = "application";
651 #endif
652     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
653                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
654                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
655                                                                  platform)).
656                              arg(myHelpFileName));
657   }
658 }
659
660 //=======================================================================
661 // function : onTextChange()
662 // purpose  :
663 //=======================================================================
664 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
665 {
666   QLineEdit* send = (QLineEdit*)sender();
667
668   if (myBusy) return;
669   BusyLocker lock( myBusy );
670
671   if (send == LineEditElements)
672     myNbOkElements = 0;
673
674   buttonOk->setEnabled(false);
675   buttonApply->setEnabled(false);
676
677   // hilight entered elements
678   SMDS_Mesh* aMesh = 0;
679   if (myActor)
680     aMesh = myActor->GetObject()->GetMesh();
681
682   if (aMesh) {
683     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
684
685     TColStd_MapOfInteger newIndices;
686
687     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
688
689     if (send == LineEditElements) {
690       for (int i = 0; i < aListId.count(); i++) {
691         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
692         if (e)
693           newIndices.Add(e->GetID());
694         myNbOkElements++;
695       }
696     }
697
698     mySelector->AddOrRemoveIndex( anIO, newIndices, false );
699     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700       aViewWindow->highlight( anIO, true, true );
701
702     myElementsId = theNewText;
703   }
704
705   if (myNbOkElements) {
706     buttonOk->setEnabled(true);
707     buttonApply->setEnabled(true);
708   }
709 }
710
711 //=================================================================================
712 // function : SelectionIntoArgument()
713 // purpose  : Called when selection as changed or other case
714 //=================================================================================
715 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
716 {
717   if (myBusy) return;
718   if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
719
720   BusyLocker lock( myBusy );
721   // clear
722   myActor = 0;
723   QString aString = "";
724   onDisplaySimulation(false);
725
726   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
727     LineEditElements->setText(aString);
728     myNbOkElements = 0;
729     buttonOk->setEnabled(false);
730     buttonApply->setEnabled(false);
731   }
732
733   if (!GroupButtons->isEnabled()) // inactive
734     return;
735
736   // get selected mesh
737   SALOME_ListIO aList;
738   mySelectionMgr->selectedObjects(aList);
739
740   int nbSel = aList.Extent();
741   if (nbSel < 1)
742     return;
743
744   int aNbUnits = 0;
745
746   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
747     myElementsId = "";
748     myObjects.clear();
749     myObjectsNames.clear();
750     myMeshes.clear();
751
752     for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
753       Handle(SALOME_InteractiveObject) IO = it.Value();
754       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
755       if ( aMesh->_is_nil() )
756         return;
757   
758       myActor = SMESH::FindActorByObject( aMesh );
759       if ( !myActor )
760         myActor = SMESH::FindActorByEntry( IO->getEntry() );
761       if ( !myActor && !CheckBoxMesh->isChecked() )
762         return;
763
764       if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
765         if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
766           _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
767           _PTR(GenericAttribute) anAttr;
768           if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
769             _PTR(AttributeName) aNameAttr( anAttr );
770             myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
771             myObjectsNames << aNameAttr->Value().c_str();
772             myMeshes << aMesh;
773           }
774         }
775       }
776     }
777       
778     // MakeGroups is available if there are groups and "Copy"
779     int aNbGroups = 0;
780     for ( int i = 0; i < myMeshes.count(); i++ )
781       aNbGroups += myMeshes[i]->NbGroups();
782
783     if ( aNbGroups == 0 ) {
784       MakeGroupsCheck->setChecked(false);
785       MakeGroupsCheck->setEnabled(false);
786     }
787     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
788       MakeGroupsCheck->setEnabled(true);
789     }
790
791     if (CheckBoxMesh->isChecked()) {
792       SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
793       if (myMeshes.isEmpty())
794         return;
795         // get IDs from mesh
796         /*
797         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
798         if (!aSMDSMesh)
799           return;
800
801         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
802           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
803           if (e) {
804             myElementsId += QString(" %1").arg(i);
805             aNbUnits++;
806           }
807         }
808       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
809         // get submesh
810         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
811
812         // get IDs from submesh
813         SMESH::long_array_var anElementsIds = new SMESH::long_array;
814         anElementsIds = aSubMesh->GetElementsId();
815         for (int i = 0; i < anElementsIds->length(); i++) {
816           myElementsId += QString(" %1").arg(anElementsIds[i]);
817         }
818         aNbUnits = anElementsIds->length();
819       } else { // GROUP
820         // get smesh group
821         SMESH::SMESH_GroupBase_var aGroup =
822           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
823         if (aGroup->_is_nil())
824           return;
825
826         // get IDs from smesh group
827         SMESH::long_array_var anElementsIds = new SMESH::long_array;
828         anElementsIds = aGroup->GetListOfID();
829         for (int i = 0; i < anElementsIds->length(); i++) {
830           myElementsId += QString(" %1").arg(anElementsIds[i]);
831         }
832         aNbUnits = anElementsIds->length();
833       }
834         */
835     } else {
836       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
837       myElementsId = aString;
838       if (aNbUnits < 1)
839         return;
840     }
841
842     myNbOkElements = true;
843   } else {
844     Handle(SALOME_InteractiveObject) IO = aList.First();
845     if ((SMESH::GetMeshByIO(IO))->_is_nil())
846       return;
847
848     SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
849     if (!anActor)
850       anActor = SMESH::FindActorByEntry(IO->getEntry());
851     if (!anActor && !CheckBoxMesh->isChecked())
852       return;
853
854     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
855     if (aNbUnits != 1)
856       return;
857
858     SMDS_Mesh* aMesh =  anActor->GetObject()->GetMesh();
859     if (!aMesh)
860       return;
861
862     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
863     if (!n)
864       return;
865
866     double x = n->X();
867     double y = n->Y();
868     double z = n->Z();
869
870     if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
871       SpinBox1_1->SetValue(x);
872       SpinBox1_2->SetValue(y);
873       SpinBox1_3->SetValue(z);
874     }
875     else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
876       SpinBox_FX->SetValue(x);
877       SpinBox_FY->SetValue(y);
878       SpinBox_FZ->SetValue(z);
879     }
880   }
881
882   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
883     LineEditElements->setText(aString);
884     LineEditElements->repaint();
885     LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
886     LineEditElements->setEnabled(true);
887     setNewMeshName();
888   }
889
890   // OK
891   if (myNbOkElements) {
892     buttonOk->setEnabled(true);
893     buttonApply->setEnabled(true);
894   }
895   
896   onDisplaySimulation(true);
897 }
898
899 //=================================================================================
900 // function : SetEditCurrentArgument()
901 // purpose  :
902 //=================================================================================
903 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
904 {
905   QPushButton* send = (QPushButton*)sender();
906
907   disconnect(mySelectionMgr, 0, this, 0);
908   mySelectionMgr->clearSelected();
909   mySelectionMgr->clearFilters();
910
911   if (send == SelectElementsButton) {
912     myEditCurrentArgument = (QWidget*)LineEditElements;
913     SMESH::SetPointRepresentation(false);
914     if (CheckBoxMesh->isChecked()) {
915       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
916         aViewWindow->SetSelectionMode( ActorSelection );
917       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
918     }
919     else {
920       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921         aViewWindow->SetSelectionMode( CellSelection );
922     }
923   }
924   else if (send == SelectButton1) {
925     myEditCurrentArgument = (QWidget*)SpinBox1_1;
926     SMESH::SetPointRepresentation(true);
927     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928       aViewWindow->SetSelectionMode( NodeSelection );
929   }
930
931   myEditCurrentArgument->setFocus();
932   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
933   SelectionIntoArgument();
934 }
935
936 //=================================================================================
937 // function : DeactivateActiveDialog()
938 // purpose  :
939 //=================================================================================
940 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
941 {
942   if (ConstructorsBox->isEnabled()) {
943     ConstructorsBox->setEnabled(false);
944     GroupArguments->setEnabled(false);
945     GroupButtons->setEnabled(false);
946     mySMESHGUI->ResetState();
947     mySMESHGUI->SetActiveDialogBox(0);
948   }
949 }
950
951 //=================================================================================
952 // function : ActivateThisDialog()
953 // purpose  :
954 //=================================================================================
955 void SMESHGUI_ScaleDlg::ActivateThisDialog()
956 {
957   /* Emit a signal to deactivate the active dialog */
958   mySMESHGUI->EmitSignalDeactivateDialog();
959   ConstructorsBox->setEnabled(true);
960   GroupArguments->setEnabled(true);
961   GroupButtons->setEnabled(true);
962
963   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
964
965   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
966     aViewWindow->SetSelectionMode( CellSelection );
967
968   SelectionIntoArgument();
969 }
970
971 //=================================================================================
972 // function : enterEvent()
973 // purpose  :
974 //=================================================================================
975 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
976 {
977   if (!ConstructorsBox->isEnabled()) {
978     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
979     if ( aViewWindow && !mySelector) {
980       mySelector = aViewWindow->GetSelector();
981     }
982     ActivateThisDialog();
983   }
984 }
985
986 //=======================================================================
987 //function : onSelectMesh
988 //purpose  :
989 //=======================================================================
990 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
991 {
992   if (toSelectMesh)
993     TextLabelElements->setText(tr("SMESH_NAME"));
994   else
995     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
996   myFilterBtn->setEnabled(!toSelectMesh);
997
998   if (myEditCurrentArgument != LineEditElements) {
999     LineEditElements->clear();
1000     return;
1001   }
1002
1003   mySelectionMgr->clearFilters();
1004   SMESH::SetPointRepresentation(false);
1005
1006   if (toSelectMesh) {
1007     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1008       aViewWindow->SetSelectionMode( ActorSelection );
1009     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1010     LineEditElements->setReadOnly(true);
1011     LineEditElements->setValidator(0);
1012   } else {
1013     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1014       aViewWindow->SetSelectionMode( CellSelection );
1015     LineEditElements->setReadOnly(false);
1016     LineEditElements->setValidator(myIdValidator);
1017     onTextChange(LineEditElements->text());
1018     hidePreview();
1019   }
1020
1021   SelectionIntoArgument();
1022 }
1023
1024 //=======================================================================
1025 //function : onActionClicked
1026 //purpose  : slot called when an action type changed
1027 //=======================================================================
1028
1029 void SMESHGUI_ScaleDlg::onActionClicked(int button)
1030 {
1031   int aNbGroups = 0;
1032   for ( int i = 0; i < myMeshes.count(); i++ )
1033     aNbGroups += myMeshes[i]->NbGroups();
1034
1035   switch ( button ) {
1036   case MOVE_ELEMS_BUTTON:
1037     MakeGroupsCheck->setEnabled(false);
1038     LineEditNewMesh->setEnabled(false);
1039     break;
1040   case COPY_ELEMS_BUTTON:
1041     LineEditNewMesh->setEnabled(false);
1042     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1043     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1044     break;
1045   case MAKE_MESH_BUTTON:
1046     LineEditNewMesh->setEnabled(true);
1047     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1048     MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1049     break;
1050   }
1051   setNewMeshName();
1052   toDisplaySimulation();
1053 }
1054
1055 //=======================================================================
1056 //function : setNewMeshName
1057 //purpose  : update contents of LineEditNewMesh
1058 //=======================================================================
1059
1060 void SMESHGUI_ScaleDlg::setNewMeshName()
1061 {
1062   LineEditNewMesh->setText("");
1063   if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1064     QString name;
1065     if ( CheckBoxMesh->isChecked() ) {
1066       name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1067     }
1068     else {
1069       _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1070       name = meshSO->GetName().c_str();
1071     }
1072     if ( !name.isEmpty() )
1073       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1074   }
1075 }
1076
1077 //=================================================================================
1078 // function : GetConstructorId()
1079 // purpose  :
1080 //=================================================================================
1081 int SMESHGUI_ScaleDlg::GetConstructorId()
1082 {
1083   return GroupConstructors->checkedId();
1084 }
1085
1086 //=================================================================================
1087 // function : keyPressEvent()
1088 // purpose  :
1089 //=================================================================================
1090 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1091 {
1092   QDialog::keyPressEvent( e );
1093   if ( e->isAccepted() )
1094     return;
1095
1096   if ( e->key() == Qt::Key_F1 ) {
1097     e->accept();
1098     ClickOnHelp();
1099   }
1100 }
1101
1102 //=================================================================================
1103 // function : setFilters()
1104 // purpose  : SLOT. Called when "Filter" button pressed.
1105 //=================================================================================
1106 void SMESHGUI_ScaleDlg::setFilters()
1107 {
1108   if(myMeshes.isEmpty()) {
1109     SUIT_MessageBox::critical(this,
1110                               tr("SMESH_ERROR"),
1111                               tr("NO_MESH_SELECTED"));
1112    return;
1113   }
1114   if ( !myFilterDlg )
1115     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1116
1117   QList<int> types;
1118   if ( myMeshes[0]->NbEdges()     ) types << SMESH::EDGE;
1119   if ( myMeshes[0]->NbFaces()     ) types << SMESH::FACE;
1120   if ( myMeshes[0]->NbVolumes()   ) types << SMESH::VOLUME;
1121   if ( myMeshes[0]->NbBalls()     ) types << SMESH::BALL;
1122   if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1123   if ( types.count() > 1 )          types << SMESH::ALL;
1124
1125   myFilterDlg->Init( types );
1126   myFilterDlg->SetSelection();
1127   myFilterDlg->SetMesh( myMeshes[0] );
1128   myFilterDlg->SetSourceWg( LineEditElements );
1129
1130   myFilterDlg->show();
1131 }
1132
1133 //=================================================================================
1134 // function : isValid
1135 // purpose  :
1136 //=================================================================================
1137 bool SMESHGUI_ScaleDlg::isValid()
1138 {
1139   bool ok = true;
1140   QString msg;
1141
1142   ok = SpinBox1_1->isValid( msg, true ) && ok;
1143   ok = SpinBox1_2->isValid( msg, true ) && ok;
1144   ok = SpinBox1_3->isValid( msg, true ) && ok;
1145   ok = SpinBox_FX->isValid( msg, true ) && ok;
1146   if (GetConstructorId() == 1) {
1147     ok = SpinBox_FY->isValid( msg, true ) && ok;
1148     ok = SpinBox_FZ->isValid( msg, true ) && ok;
1149   }
1150
1151   if( !ok ) {
1152     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1153     if ( !msg.isEmpty() )
1154       str += "\n" + msg;
1155     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1156     return false;
1157   }
1158   return true;
1159 }
1160
1161 //=================================================================================
1162 // function : onDisplaySimulation
1163 // purpose  : Show/Hide preview
1164 //=================================================================================
1165 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1166   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {    
1167     if ( myNbOkElements && isValid() ) {
1168       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1169
1170       SMESH::long_array_var anElementsId = new SMESH::long_array;
1171       
1172       anElementsId->length(aListElementsId.count());
1173       for (int i = 0; i < aListElementsId.count(); i++)
1174         anElementsId[i] = aListElementsId[i].toInt();
1175       
1176       SMESH::PointStruct aPoint;
1177       SMESH::double_array_var aScaleFact = new SMESH::double_array;
1178       getScale(aPoint, aScaleFact);
1179       
1180       try {
1181         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1182                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1183         SUIT_OverrideCursor aWaitCursor;
1184         QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1185
1186         if(CheckBoxMesh->isChecked())
1187           for ( int i = 0; i < myObjects.count(); i++ ) {
1188             SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1189             aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, copy);
1190             aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1191           }
1192         else {
1193           SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1194           SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1195           aMeshEditor->Scale( src, aPoint, aScaleFact, copy);
1196           aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1197         }
1198         setSimulationPreview(aMeshPreviewStruct);
1199       } catch (...) {
1200         hidePreview();
1201       }
1202     } else {
1203       hidePreview();
1204     } 
1205   } else {
1206     hidePreview();
1207   }
1208 }
1209
1210 //=================================================================================
1211 // function : getScale
1212 // purpose  : get scale parameters
1213 //=================================================================================
1214 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint ,  SMESH::double_array_var& theScaleFact) {
1215   thePoint.x = SpinBox1_1->GetValue();
1216   thePoint.y = SpinBox1_2->GetValue();
1217   thePoint.z = SpinBox1_3->GetValue();
1218   
1219   theScaleFact->length(3);
1220   theScaleFact[0] = SpinBox_FX->GetValue();
1221   if (GetConstructorId() == 0) {
1222     theScaleFact[1] = SpinBox_FX->GetValue();
1223     theScaleFact[2] = SpinBox_FX->GetValue();
1224   }
1225   else {
1226     theScaleFact[1] = SpinBox_FY->GetValue();
1227     theScaleFact[2] = SpinBox_FZ->GetValue();
1228   } 
1229 }