Salome HOME
Fix memory leaks
[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, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
122   initSpinBox(GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
123   initSpinBox(GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
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
404   displayPreview();
405 }
406
407 //=================================================================================
408 // function : SetEditCurrentArgument()
409 // purpose  :
410 //=================================================================================
411 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
412 {
413   QPushButton* send = (QPushButton*)sender();
414
415   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
416   globalSelection();
417
418   if (send == GroupPoints->PushButton1) {
419     myEditCurrentArgument = GroupPoints->LineEdit1;
420
421     GroupPoints->PushButton2->setDown(false);
422     GroupPoints->PushButton3->setDown(false);
423     GroupPoints->LineEdit2->setEnabled(false);
424     GroupPoints->LineEdit3->setEnabled(false);
425   }
426   else if (send == GroupPoints->PushButton2) {
427     myEditCurrentArgument = GroupPoints->LineEdit2;
428
429     GroupPoints->PushButton1->setDown(false);
430     GroupPoints->PushButton3->setDown(false);
431     GroupPoints->LineEdit1->setEnabled(false);
432     GroupPoints->LineEdit3->setEnabled(false);
433
434     if (getConstructorId() == 1)
435       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
436     else
437       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
438   }
439   else if (send == GroupPoints->PushButton3) {
440     myEditCurrentArgument = GroupPoints->LineEdit3;
441
442     GroupPoints->PushButton1->setDown(false);
443     GroupPoints->PushButton2->setDown(false);
444     GroupPoints->LineEdit1->setEnabled(false);
445     GroupPoints->LineEdit2->setEnabled(false);
446
447     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
448   }
449   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
450           this, SLOT(SelectionIntoArgument()));
451
452   // enable line edit
453   myEditCurrentArgument->setEnabled(true);
454   myEditCurrentArgument->setFocus();
455   // after setFocus(), because it will be setDown(false) when loses focus
456   send->setDown(true);
457
458   // seems we need it only to avoid preview disappearing, caused by selection mode change
459   displayPreview();
460 }
461
462 //=================================================================================
463 // function : LineEditReturnPressed()
464 // purpose  :
465 //=================================================================================
466 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
467 {
468   QLineEdit* send = (QLineEdit*)sender();
469   if (send == GroupPoints->LineEdit1) {
470     myEditCurrentArgument = send;
471     GEOMBase_Skeleton::LineEditReturnPressed();
472   }
473 }
474
475 //=================================================================================
476 // function : ActivateThisDialog()
477 // purpose  :
478 //=================================================================================
479 void TransformationGUI_TranslationDlg::ActivateThisDialog()
480 {
481   GEOMBase_Skeleton::ActivateThisDialog();
482   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
483            this, SLOT( SelectionIntoArgument() ) );
484
485   ConstructorsClicked( getConstructorId() );
486 }
487
488 //=================================================================================
489 // function : enterEvent()
490 // purpose  :
491 //=================================================================================
492 void TransformationGUI_TranslationDlg::enterEvent (QEvent*)
493 {
494   if (!mainFrame()->GroupConstructors->isEnabled())
495     ActivateThisDialog();
496 }
497
498 //=================================================================================
499 // function : ValueChangedInSpinBox()
500 // purpose  :
501 //=================================================================================
502 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
503 {
504   displayPreview();
505 }
506
507 //=================================================================================
508 // function : createOperation
509 // purpose  :
510 //=================================================================================
511 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
512 {
513   return getGeomEngine()->GetITransformOperations(getStudyId());
514 }
515
516 //=================================================================================
517 // function : isValid
518 // purpose  :
519 //=================================================================================
520 bool TransformationGUI_TranslationDlg::isValid (QString& msg)
521 {
522   int aConstructorId = getConstructorId();
523
524   switch (aConstructorId) {
525   case 0: 
526     {
527       bool ok = true;
528       ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
529       ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
530       ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
531       return myObjects.length() > 0 && ok;
532     }
533   case 1:
534     return myObjects.length() > 0 && !(myPoint1->_is_nil() || myPoint2->_is_nil());
535   case 2:
536     {
537       bool ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() );
538       return myObjects.length() > 0 && !(myVector->_is_nil()) && ok;
539     }
540   default:
541     break;
542   }
543   return false;
544 }
545
546 //=================================================================================
547 // function : execute
548 // purpose  :
549 //=================================================================================
550 bool TransformationGUI_TranslationDlg::execute (ObjectList& objects)
551 {
552   bool res = false;
553   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
554
555   GEOM::GEOM_Object_var anObj;
556
557   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
558
559   switch (getConstructorId()) {
560   case 0:
561     {
562       double dx = GroupPoints->SpinBox1->value();
563       double dy = GroupPoints->SpinBox2->value();
564       double dz = GroupPoints->SpinBox3->value();
565
566       QStringList aParameters;
567       aParameters<<GroupPoints->SpinBox1->text();
568       aParameters<<GroupPoints->SpinBox2->text();
569       aParameters<<GroupPoints->SpinBox3->text();
570
571       if (toCreateCopy) {
572         for (int i = 0; i < myObjects.length(); i++) {
573           myCurrObject = myObjects[i];
574           anObj = anOper->TranslateDXDYDZCopy(myObjects[i], dx, dy, dz);
575           if (!anObj->_is_nil()) {
576             if(!IsPreview())
577               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
578             objects.push_back(anObj._retn());
579           }
580         }
581       }
582       else {
583         for (int i = 0; i < myObjects.length(); i++) {
584           myCurrObject = myObjects[i];
585           anObj = anOper->TranslateDXDYDZ(myObjects[i], dx, dy, dz);
586           if (!anObj->_is_nil()) {
587             if(!IsPreview()) {
588               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
589               updateAttributes(anObj, aParameters);
590             }
591             objects.push_back(anObj._retn());
592           }
593         }
594       }
595       res = true;
596       break;
597     }
598   case 1:
599     {
600       if (toCreateCopy) {
601         for (int i = 0; i < myObjects.length(); i++) {
602           myCurrObject = myObjects[i];
603           anObj = anOper->TranslateTwoPointsCopy(myObjects[i], myPoint1, myPoint2);
604           if (!anObj->_is_nil())
605             objects.push_back(anObj._retn());
606         }
607       }
608       else {
609         for (int i = 0; i < myObjects.length(); i++) {
610           myCurrObject = myObjects[i];
611           anObj = anOper->TranslateTwoPoints(myObjects[i], myPoint1, myPoint2);
612           if (!anObj->_is_nil())
613             objects.push_back(anObj._retn());
614         }
615       }
616       res = true;
617       break;
618     }
619   case 2:
620     {
621       QStringList aParameters;
622       aParameters<<GroupPoints->SpinBox3->text();
623       bool byDistance = GroupPoints->CheckBox1->isChecked();
624       if (byDistance) {
625         double aDistance = GroupPoints->SpinBox3->value();
626         for (int i = 0; i < myObjects.length(); i++) {
627           myCurrObject = myObjects[i];
628           anObj = anOper->TranslateVectorDistance(myObjects[i], myVector, aDistance, toCreateCopy);
629           if (!anObj->_is_nil()) {
630             if(!IsPreview()) {
631               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
632               if (!toCreateCopy)
633                 updateAttributes(anObj, aParameters);
634             }
635             objects.push_back(anObj._retn());
636           }
637         }
638       }
639       else {
640         if (toCreateCopy) {
641           for (int i = 0; i < myObjects.length(); i++) {
642             myCurrObject = myObjects[i];
643             anObj = anOper->TranslateVectorCopy(myObjects[i], myVector);
644             if (!anObj->_is_nil())
645               objects.push_back(anObj._retn());
646           }
647         }
648         else {
649           for (int i = 0; i < myObjects.length(); i++) {
650             myCurrObject = myObjects[i];
651             anObj = anOper->TranslateVector(myObjects[i], myVector);
652             if (!anObj->_is_nil())
653               objects.push_back(anObj._retn());
654           }
655         }
656       }
657       res = true;
658       break;
659     }
660   }
661   return res;
662 }
663
664 //=================================================================================
665 // function : restoreSubShapes
666 // purpose  :
667 //=================================================================================
668 void TransformationGUI_TranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
669                                                          SALOMEDS::SObject_ptr theSObject)
670 {
671   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
672     // we pass here the first operation argument (object) through the list of arguments
673     // because the rotation operation place its arguments in the data structure in another order,
674     // and we need to point the first argument directly
675     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
676     anArgs->length(1);
677     anArgs[0] = myCurrObject;
678     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
679                                         /*theFindMethod=*/GEOM::FSM_Transformed,
680                                         /*theInheritFirstArg=*/true);
681   }
682 }
683
684 //=================================================================================
685 // function :  CreateCopyModeChanged()
686 // purpose  :
687 //=================================================================================
688 void TransformationGUI_TranslationDlg::CreateCopyModeChanged (bool isCreateCopy)
689 {
690   mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
691 }
692
693 //=================================================================================
694 // function :  ActivateDistanceChanged()
695 // purpose  :
696 //=================================================================================
697 void TransformationGUI_TranslationDlg::ActivateDistanceChanged (bool theEnable)
698 {
699   GroupPoints->SpinBox3->setEnabled(theEnable);
700   displayPreview();
701 }
702
703 //=================================================================================
704 // function : addSubshapeToStudy
705 // purpose  : virtual method to add new SubObjects if local selection
706 //=================================================================================
707 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
708 {
709   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
710   if (toCreateCopy) {
711     QMap<QString, GEOM::GEOM_Object_var> objMap;
712
713     switch (getConstructorId()) {
714     case 0:
715       return;
716     case 1:
717       objMap[GroupPoints->LineEdit2->text()] = myPoint1;
718       objMap[GroupPoints->LineEdit3->text()] = myPoint2;
719       break;
720     case 2:
721       objMap[GroupPoints->LineEdit2->text()] = myVector;
722       break;
723     }
724     addSubshapesToFather(objMap);
725   }
726 }