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