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