Salome HOME
Update copyright notes (for 2010)
[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   // activate selection and connect selection manager
276   ConstructorsClicked(getConstructorId());
277   return true;
278 }
279
280 //=================================================================================
281 // function : SelectionIntoArgument()
282 // purpose  : Called when selection is changed or on dialog initialization or activation
283 //=================================================================================
284 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
285 {
286   erasePreview();
287   myEditCurrentArgument->setText("");
288
289   if (myEditCurrentArgument == GroupPoints->LineEdit1)
290     myObjects.length(0);
291   else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
292     myPoint1 = GEOM::GEOM_Object::_nil();
293   else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
294     myVector = GEOM::GEOM_Object::_nil();
295   else if (myEditCurrentArgument == GroupPoints->LineEdit3)
296     myPoint2 = GEOM::GEOM_Object::_nil();
297
298   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
299   SALOME_ListIO aSelList;
300   aSelMgr->selectedObjects(aSelList);
301
302   QString aName;
303
304   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
305     int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
306     if (aNbSel < 1)
307       return;
308
309     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
310     if (!myObjects.length())
311       return;
312     else {
313       myEditCurrentArgument->setText(aName);
314
315       // here we do not switch to the next field, because multiple objects can be selected
316       /*
317       if (getConstructorId() == 1) {
318         if (myPoint1->_is_nil())
319           GroupPoints->PushButton2->click();
320       }
321       else if (getConstructorId() == 2) {
322         if (myVector->_is_nil())
323           GroupPoints->PushButton2->click();
324       }
325       */
326     }
327   }
328   else {
329     if (aSelList.Extent() != 1)
330       return;
331
332     // nbSel == 1
333     Standard_Boolean testResult = Standard_False;
334     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
335
336     if (!testResult || CORBA::is_nil(aSelectedObject))
337       return;
338
339     aName = GEOMBase::GetName(aSelectedObject);
340
341     // Get Selected object if selected subshape
342     TopoDS_Shape aShape;
343     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
344     {
345       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
346       if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
347         aNeedType = TopAbs_EDGE;
348
349       TColStd_IndexedMapOfInteger aMap;
350       aSelMgr->GetIndexes(aSelList.First(), aMap);
351       if (aMap.Extent() == 1)
352       {
353         int anIndex = aMap(1);
354         if (aNeedType == TopAbs_EDGE)
355           aName += QString(":edge_%1").arg(anIndex);
356         else
357           aName += QString(":vertex_%1").arg(anIndex);
358
359         //Find SubShape Object in Father
360         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
361
362         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
363           GEOM::GEOM_IShapesOperations_var aShapesOp =
364             getGeomEngine()->GetIShapesOperations(getStudyId());
365           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
366         }
367         else {
368           aSelectedObject = aFindedObject;
369         }
370       }
371       else // Global Selection
372       {
373         if (aShape.ShapeType() != aNeedType) {
374           aSelectedObject = GEOM::GEOM_Object::_nil();
375           aName = "";
376         }
377       }
378     }
379
380     myEditCurrentArgument->setText(aName);
381
382     if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
383       myPoint1 = aSelectedObject;
384       if (!myPoint1->_is_nil() && myPoint2->_is_nil())
385         GroupPoints->PushButton3->click();
386     }
387     else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2) {
388       myVector = aSelectedObject;
389       if (!myVector->_is_nil() && !myObjects.length())
390         GroupPoints->PushButton1->click();
391     }
392     else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
393       myPoint2 = aSelectedObject;
394       if (!myPoint2->_is_nil() && !myObjects.length())
395         GroupPoints->PushButton1->click();
396     }
397   }
398
399   // clear selection
400   /*  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
401   myGeomGUI->getApp()->selectionMgr()->clearSelected();
402   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
403   this, SLOT(SelectionIntoArgument()));*/
404   // here commented, because multiple objects can be selected IPAL 21437
405
406   displayPreview();
407 }
408
409 //=================================================================================
410 // function : SetEditCurrentArgument()
411 // purpose  :
412 //=================================================================================
413 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
414 {
415   QPushButton* send = (QPushButton*)sender();
416
417   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
418   globalSelection();
419
420   if (send == GroupPoints->PushButton1) {
421     myEditCurrentArgument = GroupPoints->LineEdit1;
422
423     GroupPoints->PushButton2->setDown(false);
424     GroupPoints->PushButton3->setDown(false);
425     GroupPoints->LineEdit2->setEnabled(false);
426     GroupPoints->LineEdit3->setEnabled(false);
427   }
428   else if (send == GroupPoints->PushButton2) {
429     myEditCurrentArgument = GroupPoints->LineEdit2;
430
431     GroupPoints->PushButton1->setDown(false);
432     GroupPoints->PushButton3->setDown(false);
433     GroupPoints->LineEdit1->setEnabled(false);
434     GroupPoints->LineEdit3->setEnabled(false);
435
436     if (getConstructorId() == 1)
437       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
438     else
439       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
440   }
441   else if (send == GroupPoints->PushButton3) {
442     myEditCurrentArgument = GroupPoints->LineEdit3;
443
444     GroupPoints->PushButton1->setDown(false);
445     GroupPoints->PushButton2->setDown(false);
446     GroupPoints->LineEdit1->setEnabled(false);
447     GroupPoints->LineEdit2->setEnabled(false);
448
449     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
450   }
451   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
452           this, SLOT(SelectionIntoArgument()));
453
454   // enable line edit
455   myEditCurrentArgument->setEnabled(true);
456   myEditCurrentArgument->setFocus();
457   // after setFocus(), because it will be setDown(false) when loses focus
458   send->setDown(true);
459
460   // seems we need it only to avoid preview disappearing, caused by selection mode change
461   displayPreview();
462 }
463
464 //=================================================================================
465 // function : LineEditReturnPressed()
466 // purpose  :
467 //=================================================================================
468 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
469 {
470   QLineEdit* send = (QLineEdit*)sender();
471   if (send == GroupPoints->LineEdit1) {
472     myEditCurrentArgument = send;
473     GEOMBase_Skeleton::LineEditReturnPressed();
474   }
475 }
476
477 //=================================================================================
478 // function : ActivateThisDialog()
479 // purpose  :
480 //=================================================================================
481 void TransformationGUI_TranslationDlg::ActivateThisDialog()
482 {
483   GEOMBase_Skeleton::ActivateThisDialog();
484   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
485            this, SLOT( SelectionIntoArgument() ) );
486
487   ConstructorsClicked( getConstructorId() );
488 }
489
490 //=================================================================================
491 // function : enterEvent()
492 // purpose  :
493 //=================================================================================
494 void TransformationGUI_TranslationDlg::enterEvent (QEvent*)
495 {
496   if (!mainFrame()->GroupConstructors->isEnabled())
497     ActivateThisDialog();
498 }
499
500 //=================================================================================
501 // function : ValueChangedInSpinBox()
502 // purpose  :
503 //=================================================================================
504 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
505 {
506   displayPreview();
507 }
508
509 //=================================================================================
510 // function : createOperation
511 // purpose  :
512 //=================================================================================
513 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
514 {
515   return getGeomEngine()->GetITransformOperations(getStudyId());
516 }
517
518 //=================================================================================
519 // function : isValid
520 // purpose  :
521 //=================================================================================
522 bool TransformationGUI_TranslationDlg::isValid (QString& msg)
523 {
524   int aConstructorId = getConstructorId();
525
526   switch (aConstructorId) {
527   case 0: 
528     {
529       bool ok = true;
530       ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
531       ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
532       ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
533       return myObjects.length() > 0 && ok;
534     }
535   case 1:
536     return myObjects.length() > 0 && !(myPoint1->_is_nil() || myPoint2->_is_nil());
537   case 2:
538     {
539       bool ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() );
540       return myObjects.length() > 0 && !(myVector->_is_nil()) && ok;
541     }
542   default:
543     break;
544   }
545   return false;
546 }
547
548 //=================================================================================
549 // function : execute
550 // purpose  :
551 //=================================================================================
552 bool TransformationGUI_TranslationDlg::execute (ObjectList& objects)
553 {
554   bool res = false;
555   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
556
557   GEOM::GEOM_Object_var anObj;
558
559   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
560
561   switch (getConstructorId()) {
562   case 0:
563     {
564       double dx = GroupPoints->SpinBox1->value();
565       double dy = GroupPoints->SpinBox2->value();
566       double dz = GroupPoints->SpinBox3->value();
567
568       QStringList aParameters;
569       aParameters<<GroupPoints->SpinBox1->text();
570       aParameters<<GroupPoints->SpinBox2->text();
571       aParameters<<GroupPoints->SpinBox3->text();
572
573       if (toCreateCopy) {
574         for (int i = 0; i < myObjects.length(); i++) {
575           myCurrObject = myObjects[i];
576           anObj = anOper->TranslateDXDYDZCopy(myObjects[i], dx, dy, dz);
577           if (!anObj->_is_nil()) {
578             if(!IsPreview())
579               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
580             objects.push_back(anObj._retn());
581           }
582         }
583       }
584       else {
585         for (int i = 0; i < myObjects.length(); i++) {
586           myCurrObject = myObjects[i];
587           anObj = anOper->TranslateDXDYDZ(myObjects[i], dx, dy, dz);
588           if (!anObj->_is_nil()) {
589             if(!IsPreview()) {
590               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
591               updateAttributes(anObj, aParameters);
592             }
593             objects.push_back(anObj._retn());
594           }
595         }
596       }
597       res = true;
598       break;
599     }
600   case 1:
601     {
602       if (toCreateCopy) {
603         for (int i = 0; i < myObjects.length(); i++) {
604           myCurrObject = myObjects[i];
605           anObj = anOper->TranslateTwoPointsCopy(myObjects[i], myPoint1, myPoint2);
606           if (!anObj->_is_nil())
607             objects.push_back(anObj._retn());
608         }
609       }
610       else {
611         for (int i = 0; i < myObjects.length(); i++) {
612           myCurrObject = myObjects[i];
613           anObj = anOper->TranslateTwoPoints(myObjects[i], myPoint1, myPoint2);
614           if (!anObj->_is_nil())
615             objects.push_back(anObj._retn());
616         }
617       }
618       res = true;
619       break;
620     }
621   case 2:
622     {
623       QStringList aParameters;
624       aParameters<<GroupPoints->SpinBox3->text();
625       bool byDistance = GroupPoints->CheckBox1->isChecked();
626       if (byDistance) {
627         double aDistance = GroupPoints->SpinBox3->value();
628         for (int i = 0; i < myObjects.length(); i++) {
629           myCurrObject = myObjects[i];
630           anObj = anOper->TranslateVectorDistance(myObjects[i], myVector, aDistance, toCreateCopy);
631           if (!anObj->_is_nil()) {
632             if(!IsPreview()) {
633               anObj->SetParameters(aParameters.join(":").toLatin1().constData());
634               if (!toCreateCopy)
635                 updateAttributes(anObj, aParameters);
636             }
637             objects.push_back(anObj._retn());
638           }
639         }
640       }
641       else {
642         if (toCreateCopy) {
643           for (int i = 0; i < myObjects.length(); i++) {
644             myCurrObject = myObjects[i];
645             anObj = anOper->TranslateVectorCopy(myObjects[i], myVector);
646             if (!anObj->_is_nil())
647               objects.push_back(anObj._retn());
648           }
649         }
650         else {
651           for (int i = 0; i < myObjects.length(); i++) {
652             myCurrObject = myObjects[i];
653             anObj = anOper->TranslateVector(myObjects[i], myVector);
654             if (!anObj->_is_nil())
655               objects.push_back(anObj._retn());
656           }
657         }
658       }
659       res = true;
660       break;
661     }
662   }
663   return res;
664 }
665
666 //=================================================================================
667 // function : restoreSubShapes
668 // purpose  :
669 //=================================================================================
670 void TransformationGUI_TranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
671                                                          SALOMEDS::SObject_ptr theSObject)
672 {
673   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
674     // we pass here the first operation argument (object) through the list of arguments
675     // because the rotation operation place its arguments in the data structure in another order,
676     // and we need to point the first argument directly
677     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
678     anArgs->length(1);
679     anArgs[0] = myCurrObject;
680     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
681                                         /*theFindMethod=*/GEOM::FSM_Transformed,
682                                         /*theInheritFirstArg=*/true,
683                                         mainFrame()->CheckBoxAddPrefix->isChecked());
684   }
685 }
686
687 //=================================================================================
688 // function :  CreateCopyModeChanged()
689 // purpose  :
690 //=================================================================================
691 void TransformationGUI_TranslationDlg::CreateCopyModeChanged (bool isCreateCopy)
692 {
693   mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
694 }
695
696 //=================================================================================
697 // function :  ActivateDistanceChanged()
698 // purpose  :
699 //=================================================================================
700 void TransformationGUI_TranslationDlg::ActivateDistanceChanged (bool theEnable)
701 {
702   GroupPoints->SpinBox3->setEnabled(theEnable);
703   displayPreview();
704 }
705
706 //=================================================================================
707 // function : addSubshapeToStudy
708 // purpose  : virtual method to add new SubObjects if local selection
709 //=================================================================================
710 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
711 {
712   bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
713   if (toCreateCopy) {
714     QMap<QString, GEOM::GEOM_Object_var> objMap;
715
716     switch (getConstructorId()) {
717     case 0:
718       return;
719     case 1:
720       objMap[GroupPoints->LineEdit2->text()] = myPoint1;
721       objMap[GroupPoints->LineEdit3->text()] = myPoint2;
722       break;
723     case 2:
724       objMap[GroupPoints->LineEdit2->text()] = myVector;
725       break;
726     }
727     addSubshapesToFather(objMap);
728   }
729 }