Salome HOME
Issue 0020580: improved validation in integer and double spin boxes, possibility...
[modules/geom.git] / src / TransformationGUI / TransformationGUI_TranslationDlg.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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : TransformationGUI_TranslationDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 //
26 #include "TransformationGUI_TranslationDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 // OCCT Includes
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS.hxx>
41 #include <TopExp.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44
45 #include <GEOMImpl_Types.hxx>
46
47 //=================================================================================
48 // class    : TransformationGUI_TranslationDlg()
49 // purpose  : Constructs a TransformationGUI_TranslationDlg which is a child of 'parent', with the
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_TranslationDlg::TransformationGUI_TranslationDlg
55 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
56   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
57     myInitial(true)
58 {
59   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_DXYZ")));
61   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_POINTS")));
62   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSLATION_VECTOR")));
63   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64
65   setWindowTitle(tr("GEOM_TRANSLATION_TITLE"));
66
67   /***************************************************************/
68   mainFrame()->GroupConstructors->setTitle(tr("GEOM_TRANSLATION"));
69   mainFrame()->RadioButton1->setIcon(image0);
70   mainFrame()->RadioButton2->setIcon(image1);
71   mainFrame()->RadioButton3->setIcon(image2);
72   mainFrame()->RadioButton1->setChecked(true);
73
74   GroupPoints = new DlgRef_3Sel3Spin2Check(centralWidget());
75   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
77   GroupPoints->TextLabel3->setText(tr("GEOM_POINT_I").arg(2));
78   GroupPoints->TextLabel4->setText(tr("GEOM_DX"));
79   GroupPoints->TextLabel5->setText(tr("GEOM_DY"));
80   GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
81   GroupPoints->PushButton1->setIcon(image3);
82   GroupPoints->PushButton2->setIcon(image3);
83   GroupPoints->PushButton3->setIcon(image3);
84   GroupPoints->CheckBox1->setText(tr("Activate Distance"));
85   GroupPoints->CheckBox2->setText(tr("GEOM_CREATE_COPY"));
86
87   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88   layout->setMargin(0); layout->setSpacing(6);
89   layout->addWidget(GroupPoints);
90   /***************************************************************/
91
92   setHelpFileName("translation_operation_page.html");
93
94   // Activate Create a Copy mode
95   GroupPoints->CheckBox2->setChecked(true);
96   CreateCopyModeChanged(true);
97
98   Init();
99 }
100
101 //=================================================================================
102 // function : ~TransformationGUI_TranslationDlg()
103 // purpose  : Destroys the object and frees any allocated resources
104 //=================================================================================
105 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
106 {
107   // no need to delete child widgets, Qt does it all for us
108 }
109
110 //=================================================================================
111 // function : Init()
112 // purpose  :
113 //=================================================================================
114 void TransformationGUI_TranslationDlg::Init()
115 {
116   // Get setting of step value from file configuration
117   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
118   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
119
120   // min, max, step and decimals for spin boxes & initial values
121   initSpinBox(GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, "length_precision" );
122   initSpinBox(GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, "length_precision" );
123   initSpinBox(GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, "length_precision" );
124
125   GroupPoints->SpinBox1->setValue(0.0);
126   GroupPoints->SpinBox2->setValue(0.0);
127   GroupPoints->SpinBox3->setValue(0.0);
128
129   // init variables
130   GroupPoints->LineEdit1->setReadOnly(true);
131   GroupPoints->LineEdit2->setReadOnly(true);
132   GroupPoints->LineEdit3->setReadOnly(true);
133
134   GroupPoints->LineEdit1->setText("");
135   GroupPoints->LineEdit2->setText("");
136   GroupPoints->LineEdit3->setText("");
137
138   myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
139
140   mainFrame()->GroupBoxPublish->show();
141
142   // signals and slots connections
143   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145
146   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
147
148   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151
152   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
153
154   connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155   connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156   connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157
158   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
159
160   connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(ActivateDistanceChanged(bool)));
161   connect(GroupPoints->CheckBox2, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
162
163   initName(tr("GEOM_TRANSLATION"));
164
165   ConstructorsClicked(0);
166 }
167
168 //=================================================================================
169 // function : SetDoubleSpinBoxStep()
170 // purpose  : Double spin box management
171 //=================================================================================
172 void TransformationGUI_TranslationDlg::SetDoubleSpinBoxStep (double step)
173 {
174   GroupPoints->SpinBox1->setSingleStep(step);
175   GroupPoints->SpinBox2->setSingleStep(step);
176   GroupPoints->SpinBox3->setSingleStep(step);
177 }
178
179 //=================================================================================
180 // function : ConstructorsClicked()
181 // purpose  : Radio button management
182 //=================================================================================
183 void TransformationGUI_TranslationDlg::ConstructorsClicked (int constructorId)
184 {
185   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
186
187   switch (constructorId) {
188   case 0: // translation an object by dx, dy, dz
189     {
190       GroupPoints->ShowRows(1, 2, false);
191       GroupPoints->ShowRows(3, 5, true);
192
193       GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
194       GroupPoints->SpinBox3->setEnabled(true);
195
196       GroupPoints->CheckBox1->hide();
197
198       GroupPoints->PushButton1->click();
199     }
200     break;
201   case 1: // translation an object by 2 points
202     {
203       GroupPoints->ShowRows(3, 5, false);
204       GroupPoints->ShowRows(0, 2, true);
205
206       GroupPoints->TextLabel6->setText(tr("GEOM_DZ"));
207       GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(1));
208       GroupPoints->LineEdit2->clear();
209       GroupPoints->LineEdit3->clear();
210       GroupPoints->SpinBox3->setEnabled(true);
211
212       GroupPoints->CheckBox1->hide();
213
214       myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
215
216       GroupPoints->PushButton1->click();
217     }
218     break;
219   case 2: // translation an object by vector
220     {
221       GroupPoints->ShowRows(0, 1, true);
222       GroupPoints->ShowRows(2, 4, false);
223       GroupPoints->ShowRows(5, 5, true);
224
225       GroupPoints->TextLabel6->setText(tr("GEOM_DISTANCE"));
226       GroupPoints->SpinBox3->setValue(0.0);
227       GroupPoints->SpinBox3->setEnabled(false);
228       GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
229       GroupPoints->LineEdit2->clear();
230
231       GroupPoints->CheckBox1->show();
232
233       myVector = GEOM::GEOM_Object::_nil();
234       ActivateDistanceChanged(GroupPoints->CheckBox1->isChecked());
235
236       GroupPoints->PushButton1->click();
237     }
238     break;
239   }
240
241   qApp->processEvents();
242   updateGeometry();
243   resize(minimumSizeHint());
244
245   if (myInitial) {
246     myInitial = false;
247     SelectionIntoArgument();
248   }
249   else {
250     displayPreview();
251   }
252 }
253
254 //=================================================================================
255 // function : ClickOnOk()
256 // purpose  :
257 //=================================================================================
258 void TransformationGUI_TranslationDlg::ClickOnOk()
259 {
260   if (ClickOnApply())
261     ClickOnCancel();
262 }
263
264 //=================================================================================
265 // function : ClickOnApply()
266 // purpose  :
267 //=================================================================================
268 bool TransformationGUI_TranslationDlg::ClickOnApply()
269 {
270   if (!onAccept(GroupPoints->CheckBox2->isChecked()))
271     return false;
272
273   initName();
274   // activate selection and connect selection manager
275   ConstructorsClicked(getConstructorId());
276   return true;
277 }
278
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose  : Called when selection is changed or on dialog initialization or activation
282 //=================================================================================
283 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
284 {
285   erasePreview();
286   myEditCurrentArgument->setText("");
287
288   if (myEditCurrentArgument == GroupPoints->LineEdit1)
289     myObjects.length(0);
290   else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
291     myPoint1 = GEOM::GEOM_Object::_nil();
292   else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
293     myVector = GEOM::GEOM_Object::_nil();
294   else if (myEditCurrentArgument == GroupPoints->LineEdit3)
295     myPoint2 = GEOM::GEOM_Object::_nil();
296
297   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
298   SALOME_ListIO aSelList;
299   aSelMgr->selectedObjects(aSelList);
300
301   QString aName;
302
303   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
304     int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
305     if (aNbSel < 1)
306       return;
307
308     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
309     if (!myObjects.length())
310       return;
311     else {
312       myEditCurrentArgument->setText(aName);
313
314       // here we do not switch to the next field, because multiple objects can be selected
315       /*
316       if (getConstructorId() == 1) {
317         if (myPoint1->_is_nil())
318           GroupPoints->PushButton2->click();
319       }
320       else if (getConstructorId() == 2) {
321         if (myVector->_is_nil())
322           GroupPoints->PushButton2->click();
323       }
324       */
325     }
326   }
327   else {
328     if (aSelList.Extent() != 1)
329       return;
330
331     // nbSel == 1
332     Standard_Boolean testResult = Standard_False;
333     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
334
335     if (!testResult || CORBA::is_nil(aSelectedObject))
336       return;
337
338     aName = GEOMBase::GetName(aSelectedObject);
339
340     // Get Selected object if selected subshape
341     TopoDS_Shape aShape;
342     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
343     {
344       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
345       if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
346         aNeedType = TopAbs_EDGE;
347
348       TColStd_IndexedMapOfInteger aMap;
349       aSelMgr->GetIndexes(aSelList.First(), aMap);
350       if (aMap.Extent() == 1)
351       {
352         int anIndex = aMap(1);
353         if (aNeedType == TopAbs_EDGE)
354           aName += QString(":edge_%1").arg(anIndex);
355         else
356           aName += QString(":vertex_%1").arg(anIndex);
357
358         //Find SubShape Object in Father
359         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
360
361         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
362           GEOM::GEOM_IShapesOperations_var aShapesOp =
363             getGeomEngine()->GetIShapesOperations(getStudyId());
364           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
365         }
366         else {
367           aSelectedObject = aFindedObject;
368         }
369       }
370       else // Global Selection
371       {
372         if (aShape.ShapeType() != aNeedType) {
373           aSelectedObject = GEOM::GEOM_Object::_nil();
374           aName = "";
375         }
376       }
377     }
378
379     myEditCurrentArgument->setText(aName);
380
381     if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
382       myPoint1 = aSelectedObject;
383       if (!myPoint1->_is_nil() && myPoint2->_is_nil())
384         GroupPoints->PushButton3->click();
385     }
386     else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2) {
387       myVector = aSelectedObject;
388       if (!myVector->_is_nil() && !myObjects.length())
389         GroupPoints->PushButton1->click();
390     }
391     else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
392       myPoint2 = aSelectedObject;
393       if (!myPoint2->_is_nil() && !myObjects.length())
394         GroupPoints->PushButton1->click();
395     }
396   }
397
398   // clear selection
399   /*  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
400   myGeomGUI->getApp()->selectionMgr()->clearSelected();
401   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
402   this, SLOT(SelectionIntoArgument()));*/
403   // here commented, because multiple objects can be selected IPAL 21437
404
405   displayPreview();
406 }
407
408 //=================================================================================
409 // function : SetEditCurrentArgument()
410 // purpose  :
411 //=================================================================================
412 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
413 {
414   QPushButton* send = (QPushButton*)sender();
415
416   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
417   globalSelection();
418
419   if (send == GroupPoints->PushButton1) {
420     myEditCurrentArgument = GroupPoints->LineEdit1;
421
422     GroupPoints->PushButton2->setDown(false);
423     GroupPoints->PushButton3->setDown(false);
424     GroupPoints->LineEdit2->setEnabled(false);
425     GroupPoints->LineEdit3->setEnabled(false);
426   }
427   else if (send == GroupPoints->PushButton2) {
428     myEditCurrentArgument = GroupPoints->LineEdit2;
429
430     GroupPoints->PushButton1->setDown(false);
431     GroupPoints->PushButton3->setDown(false);
432     GroupPoints->LineEdit1->setEnabled(false);
433     GroupPoints->LineEdit3->setEnabled(false);
434
435     if (getConstructorId() == 1)
436       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
437     else
438       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
439   }
440   else if (send == GroupPoints->PushButton3) {
441     myEditCurrentArgument = GroupPoints->LineEdit3;
442
443     GroupPoints->PushButton1->setDown(false);
444     GroupPoints->PushButton2->setDown(false);
445     GroupPoints->LineEdit1->setEnabled(false);
446     GroupPoints->LineEdit2->setEnabled(false);
447
448     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
449   }
450   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
451           this, SLOT(SelectionIntoArgument()));
452
453   // enable line edit
454   myEditCurrentArgument->setEnabled(true);
455   myEditCurrentArgument->setFocus();
456   // after setFocus(), because it will be setDown(false) when loses focus
457   send->setDown(true);
458
459   // seems we need it only to avoid preview disappearing, caused by selection mode change
460   displayPreview();
461 }
462
463 //=================================================================================
464 // function : LineEditReturnPressed()
465 // purpose  :
466 //=================================================================================
467 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
468 {
469   QLineEdit* send = (QLineEdit*)sender();
470   if (send == GroupPoints->LineEdit1) {
471     myEditCurrentArgument = send;
472     GEOMBase_Skeleton::LineEditReturnPressed();
473   }
474 }
475
476 //=================================================================================
477 // function : ActivateThisDialog()
478 // purpose  :
479 //=================================================================================
480 void TransformationGUI_TranslationDlg::ActivateThisDialog()
481 {
482   GEOMBase_Skeleton::ActivateThisDialog();
483   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
484            this, SLOT( SelectionIntoArgument() ) );
485
486   ConstructorsClicked( getConstructorId() );
487 }
488
489 //=================================================================================
490 // function : enterEvent()
491 // purpose  :
492 //=================================================================================
493 void TransformationGUI_TranslationDlg::enterEvent (QEvent*)
494 {
495   if (!mainFrame()->GroupConstructors->isEnabled())
496     ActivateThisDialog();
497 }
498
499 //=================================================================================
500 // function : ValueChangedInSpinBox()
501 // purpose  :
502 //=================================================================================
503 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
504 {
505   displayPreview();
506 }
507
508 //=================================================================================
509 // function : createOperation
510 // purpose  :
511 //=================================================================================
512 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
513 {
514   return getGeomEngine()->GetITransformOperations(getStudyId());
515 }
516
517 //=================================================================================
518 // function : isValid
519 // purpose  :
520 //=================================================================================
521 bool TransformationGUI_TranslationDlg::isValid (QString& msg)
522 {
523   int aConstructorId = getConstructorId();
524
525   switch (aConstructorId) {
526   case 0: 
527     {
528       bool ok = true;
529       ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
530       ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
531       ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
532       return myObjects.length() > 0 && ok;
533     }
534   case 1:
535     return myObjects.length() > 0 && !(myPoint1->_is_nil() || myPoint2->_is_nil());
536   case 2:
537     {
538       bool ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() );
539       return myObjects.length() > 0 && !(myVector->_is_nil()) && ok;
540     }
541   default:
542     break;
543   }
544   return false;
545 }
546
547 //=================================================================================
548 // function : execute
549 // purpose  :
550 //=================================================================================
551 bool TransformationGUI_TranslationDlg::execute (ObjectList& objects)
552 {
553   bool res = false;
554   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
555
556   GEOM::GEOM_Object_var anObj;
557
558   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
559
560   switch (getConstructorId()) {
561   case 0:
562     {
563       double dx = GroupPoints->SpinBox1->value();
564       double dy = GroupPoints->SpinBox2->value();
565       double dz = GroupPoints->SpinBox3->value();
566
567       QStringList aParameters;
568       aParameters<<GroupPoints->SpinBox1->text();
569       aParameters<<GroupPoints->SpinBox2->text();
570       aParameters<<GroupPoints->SpinBox3->text();
571
572       if (toCreateCopy) {
573         for (int i = 0; i < myObjects.length(); i++) {
574           myCurrObject = myObjects[i];
575           anObj = anOper->TranslateDXDYDZCopy(myObjects[i], dx, dy, dz);
576           if (!anObj->_is_nil()) {
577             if(!IsPreview())
578               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
579             objects.push_back(anObj._retn());
580           }
581         }
582       }
583       else {
584         for (int i = 0; i < myObjects.length(); i++) {
585           myCurrObject = myObjects[i];
586           anObj = anOper->TranslateDXDYDZ(myObjects[i], dx, dy, dz);
587           if (!anObj->_is_nil()) {
588             if(!IsPreview()) {
589               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
590               updateAttributes(anObj, aParameters);
591             }
592             objects.push_back(anObj._retn());
593           }
594         }
595       }
596       res = true;
597       break;
598     }
599   case 1:
600     {
601       if (toCreateCopy) {
602         for (int i = 0; i < myObjects.length(); i++) {
603           myCurrObject = myObjects[i];
604           anObj = anOper->TranslateTwoPointsCopy(myObjects[i], myPoint1, myPoint2);
605           if (!anObj->_is_nil())
606             objects.push_back(anObj._retn());
607         }
608       }
609       else {
610         for (int i = 0; i < myObjects.length(); i++) {
611           myCurrObject = myObjects[i];
612           anObj = anOper->TranslateTwoPoints(myObjects[i], myPoint1, myPoint2);
613           if (!anObj->_is_nil())
614             objects.push_back(anObj._retn());
615         }
616       }
617       res = true;
618       break;
619     }
620   case 2:
621     {
622       QStringList aParameters;
623       aParameters<<GroupPoints->SpinBox3->text();
624       bool byDistance = GroupPoints->CheckBox1->isChecked();
625       if (byDistance) {
626         double aDistance = GroupPoints->SpinBox3->value();
627         for (int i = 0; i < myObjects.length(); i++) {
628           myCurrObject = myObjects[i];
629           anObj = anOper->TranslateVectorDistance(myObjects[i], myVector, aDistance, toCreateCopy);
630           if (!anObj->_is_nil()) {
631             if(!IsPreview()) {
632               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
633               if (!toCreateCopy)
634                 updateAttributes(anObj, aParameters);
635             }
636             objects.push_back(anObj._retn());
637           }
638         }
639       }
640       else {
641         if (toCreateCopy) {
642           for (int i = 0; i < myObjects.length(); i++) {
643             myCurrObject = myObjects[i];
644             anObj = anOper->TranslateVectorCopy(myObjects[i], myVector);
645             if (!anObj->_is_nil())
646               objects.push_back(anObj._retn());
647           }
648         }
649         else {
650           for (int i = 0; i < myObjects.length(); i++) {
651             myCurrObject = myObjects[i];
652             anObj = anOper->TranslateVector(myObjects[i], myVector);
653             if (!anObj->_is_nil())
654               objects.push_back(anObj._retn());
655           }
656         }
657       }
658       res = true;
659       break;
660     }
661   }
662   return res;
663 }
664
665 //=================================================================================
666 // function : restoreSubShapes
667 // purpose  :
668 //=================================================================================
669 void TransformationGUI_TranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
670                                                          SALOMEDS::SObject_ptr theSObject)
671 {
672   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
673     // we pass here the first operation argument (object) through the list of arguments
674     // because the rotation operation place its arguments in the data structure in another order,
675     // and we need to point the first argument directly
676     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
677     anArgs->length(1);
678     anArgs[0] = myCurrObject;
679     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
680                                         /*theFindMethod=*/GEOM::FSM_Transformed,
681                                         /*theInheritFirstArg=*/true,
682                                         mainFrame()->CheckBoxAddPrefix->isChecked());
683   }
684 }
685
686 //=================================================================================
687 // function :  CreateCopyModeChanged()
688 // purpose  :
689 //=================================================================================
690 void TransformationGUI_TranslationDlg::CreateCopyModeChanged (bool isCreateCopy)
691 {
692   mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
693 }
694
695 //=================================================================================
696 // function :  ActivateDistanceChanged()
697 // purpose  :
698 //=================================================================================
699 void TransformationGUI_TranslationDlg::ActivateDistanceChanged (bool theEnable)
700 {
701   GroupPoints->SpinBox3->setEnabled(theEnable);
702   displayPreview();
703 }
704
705 //=================================================================================
706 // function : addSubshapeToStudy
707 // purpose  : virtual method to add new SubObjects if local selection
708 //=================================================================================
709 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
710 {
711   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
712   if (toCreateCopy) {
713     QMap<QString, GEOM::GEOM_Object_var> objMap;
714
715     switch (getConstructorId()) {
716     case 0:
717       return;
718     case 1:
719       objMap[GroupPoints->LineEdit2->text()] = myPoint1;
720       objMap[GroupPoints->LineEdit3->text()] = myPoint2;
721       break;
722     case 2:
723       objMap[GroupPoints->LineEdit2->text()] = myVector;
724       break;
725     }
726     addSubshapesToFather(objMap);
727   }
728 }