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