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