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