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