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