Salome HOME
7ebe162546e9028d75133df4802c4a4dd85cc1bc
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MultiTranslationDlg.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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       if ( myBase ) GroupDimensions->LineEdit1->setText( GEOMBase::GetName( myBase.get() ) );
248       if ( myVectorU ) GroupDimensions->LineEdit2->setText( GEOMBase::GetName( myVectorU.get() ) );
249
250       GroupPoints->SpinBox_DX->setValue(myStepU);
251       GroupPoints->SpinBox_DY->setValue(myNbTimesU);
252
253       if ( !myBase )
254         GroupPoints->PushButton1->click();
255       else if ( !myVectorU )
256         GroupPoints->PushButton2->click();
257       break;
258     }
259   case 1: // Translate double
260     {
261       GroupPoints->hide();
262       GroupDimensions->show();
263
264       //GroupDimensions->LineEdit1->setText("");
265       //GroupDimensions->LineEdit2->setText("");
266       //GroupDimensions->LineEdit3->setText("");
267       //myBase.nullify();
268       //myVectorU.nullify();
269       //myVectorV.nullify();
270
271       if ( myBase ) GroupDimensions->LineEdit1->setText( GEOMBase::GetName( myBase.get() ) );
272       if ( myVectorU ) GroupDimensions->LineEdit2->setText( GEOMBase::GetName( myVectorU.get() ) );
273       if ( myVectorV ) GroupDimensions->LineEdit3->setText( GEOMBase::GetName( myVectorV.get() ) );
274
275       GroupDimensions->SpinBox_DX1->setValue(myStepU);
276       GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
277       GroupDimensions->SpinBox_DX2->setValue(myStepV);
278       GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
279
280       if ( !myBase )
281         GroupDimensions->PushButton1->click();
282       else if ( !myVectorU )
283         GroupDimensions->PushButton2->click();
284       else if ( !myVectorV )
285         GroupDimensions->PushButton3->click();
286       break;
287     }
288   }
289
290   qApp->processEvents();
291   updateGeometry();
292   resize(minimumSizeHint());
293
294   if (myInitial) {
295     myInitial = false;
296     SelectionIntoArgument();
297   }
298   else {
299     processPreview();
300   }
301 }
302
303 //=================================================================================
304 // function : ClickOnOk()
305 // purpose  :
306 //=================================================================================
307 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
308 {
309   setIsApplyAndClose( true );
310   if (ClickOnApply())
311     ClickOnCancel();
312 }
313
314 //=================================================================================
315 // function : ClickOnApply()
316 // purpose  :
317 //=================================================================================
318 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
319 {
320   if (!onAccept())
321     return false;
322
323   initName();
324   // activate selection and connect selection manager
325   ConstructorsClicked(getConstructorId());
326   return true;
327 }
328
329 //=================================================================================
330 // function : SelectionIntoArgument()
331 // purpose  : Called when selection is changed or on dialog initialization or activation
332 //=================================================================================
333 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
334 {
335   erasePreview();
336
337   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
338                                  myEditCurrentArgument == GroupDimensions->LineEdit2 ||
339                                  myEditCurrentArgument == GroupDimensions->LineEdit3 ) ?
340     TopAbs_EDGE : TopAbs_SHAPE;
341   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
342   TopoDS_Shape aShape;
343   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
344     QString aName = GEOMBase::GetName( aSelectedObject.get() );
345     myEditCurrentArgument->setText( aName );
346
347     if ( myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1 ) {
348       myBase = aSelectedObject;
349
350       // recompute myStepU (Mantis issue 0021718)
351       GEOM::GEOM_IMeasureOperations_var anOper = getGeomEngine()->GetIMeasureOperations();
352       double Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;
353       anOper->GetBoundingBox(myBase.get(), true, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
354       if (anOper->IsDone()) {
355         myStepU = floor(1.5 * (Xmax - Xmin));
356         myStepV = floor(1.5 * (Ymax - Ymin));
357         GroupPoints->SpinBox_DX->setValue(myStepU);
358         GroupDimensions->SpinBox_DX1->setValue(myStepU);
359         GroupDimensions->SpinBox_DX2->setValue(myStepV);
360       }
361
362       if ( myEditCurrentArgument == GroupPoints->LineEdit1 && !myVectorU )
363         GroupPoints->PushButton2->click();
364       if ( myEditCurrentArgument == GroupDimensions->LineEdit1 ) {
365         if ( !myVectorU )
366           GroupDimensions->PushButton2->click();
367         else if ( !myVectorV )
368           GroupDimensions->PushButton3->click();
369       }
370     }
371     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
372       myVectorU = aSelectedObject;
373       if ( !myBase )
374         GroupPoints->PushButton1->click();
375     }
376     else if ( myEditCurrentArgument == GroupDimensions->LineEdit2 ) {
377       myVectorU = aSelectedObject;
378       if ( !myVectorV )
379         GroupDimensions->PushButton3->click();
380       else if ( !myBase )
381         GroupDimensions->PushButton1->click();
382     }
383     else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 ) {
384       myVectorV = aSelectedObject;
385       if ( !myBase )
386         GroupDimensions->PushButton1->click();
387       else if ( !myVectorU )
388         GroupDimensions->PushButton2->click();
389     }
390
391     // clear selection
392     // disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
393     // myGeomGUI->getApp()->selectionMgr()->clearSelected();
394     // connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
395     //         this, SLOT(SelectionIntoArgument()));
396   }
397   else {
398     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
399          myEditCurrentArgument == GroupDimensions->LineEdit1 )
400       myBase.nullify();
401     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
402               myEditCurrentArgument == GroupDimensions->LineEdit2 )
403       myVectorU.nullify();
404     else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
405       myVectorV.nullify();
406     myEditCurrentArgument->setText("");
407   }
408
409   processPreview();
410 }
411
412 //=================================================================================
413 // function : SetEditCurrentArgument()
414 // purpose  :
415 //=================================================================================
416 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
417 {
418   QPushButton* send = (QPushButton*)sender();
419
420   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
421   globalSelection(GEOM_ALLSHAPES);
422
423   if (send == GroupPoints->PushButton1) {
424     myEditCurrentArgument = GroupPoints->LineEdit1;
425
426     GroupPoints->PushButton2->setDown(false);
427     GroupPoints->LineEdit2->setEnabled(false);
428   }
429   else if (send == GroupPoints->PushButton2) {
430     myEditCurrentArgument = GroupPoints->LineEdit2;
431
432     localSelection(TopAbs_EDGE);
433
434     GroupPoints->PushButton1->setDown(false);
435     GroupPoints->LineEdit1->setEnabled(false);
436   }
437   else if (send == GroupDimensions->PushButton1) {
438     myEditCurrentArgument = GroupDimensions->LineEdit1;
439
440     GroupDimensions->PushButton2->setDown(false);
441     GroupDimensions->PushButton3->setDown(false);
442     GroupDimensions->LineEdit2->setEnabled(false);
443     GroupDimensions->LineEdit3->setEnabled(false);
444   }
445   else if (send == GroupDimensions->PushButton2) {
446     myEditCurrentArgument = GroupDimensions->LineEdit2;
447
448     localSelection(TopAbs_EDGE);
449
450     GroupDimensions->PushButton1->setDown(false);
451     GroupDimensions->PushButton3->setDown(false);
452     GroupDimensions->LineEdit1->setEnabled(false);
453     GroupDimensions->LineEdit3->setEnabled(false);
454   }
455   else if (send == GroupDimensions->PushButton3) {
456     myEditCurrentArgument = GroupDimensions->LineEdit3;
457
458     localSelection(TopAbs_EDGE);
459
460     GroupDimensions->PushButton1->setDown(false);
461     GroupDimensions->PushButton2->setDown(false);
462     GroupDimensions->LineEdit1->setEnabled(false);
463     GroupDimensions->LineEdit2->setEnabled(false);
464   }
465   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
466           this, SLOT(SelectionIntoArgument()));
467
468   // enable line edit
469   myEditCurrentArgument->setEnabled(true);
470   myEditCurrentArgument->setFocus();
471   // after setFocus(), because it will be setDown(false) when loses focus
472   send->setDown(true);
473
474   // seems we need it only to avoid preview disappearing, caused by selection mode change
475   processPreview();
476 }
477
478 //=================================================================================
479 // function : ActivateThisDialog()
480 // purpose  :
481 //=================================================================================
482 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
483 {
484   GEOMBase_Skeleton::ActivateThisDialog();
485   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
486            this, SLOT( SelectionIntoArgument() ) );
487
488   ConstructorsClicked( getConstructorId() );
489 }
490
491 //=================================================================================
492 // function : enterEvent()
493 // purpose  :
494 //=================================================================================
495 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
496 {
497   if (!mainFrame()->GroupConstructors->isEnabled())
498     ActivateThisDialog();
499 }
500
501 //=================================================================================
502 // function : TextValueChangedInSpinBox
503 // purpose  :
504 //=================================================================================
505 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& )
506 {
507   QObject* send = (QObject*)sender();
508   bool isDigit = true;
509
510   switch (getConstructorId()) {
511   case 0:
512     GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
513     if(!isDigit){
514       GroupPoints->CheckButton1->setChecked(false);
515     }
516     GroupPoints->CheckButton1->setEnabled(isDigit);
517     break;
518   case 1:
519     if (send == GroupDimensions->SpinBox_DX1) {
520       GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
521       if(!isDigit)
522         GroupDimensions->CheckButton1->setChecked(false);
523       GroupDimensions->CheckButton1->setEnabled(isDigit);
524     }
525     else if(send == GroupDimensions->SpinBox_DX2){
526       GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
527       if(!isDigit)
528         GroupDimensions->CheckButton2->setChecked(false);
529       GroupDimensions->CheckButton2->setEnabled(isDigit);
530     }
531     break;
532   }
533 }
534
535 //=================================================================================
536 // function : ValueChangedInSpinBox()
537 // purpose  :
538 //=================================================================================
539 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
540 {
541   QObject* send = (QObject*)sender();
542   switch (getConstructorId()) {
543   case 0:
544     if (send == GroupPoints->SpinBox_DX)
545       myStepU = newValue;
546     break;
547   case 1:
548     if (send == GroupDimensions->SpinBox_DX1)
549       myStepU = newValue;
550     else if (send == GroupDimensions->SpinBox_DX2)
551       myStepV = newValue;
552     break;
553   }
554
555   processPreview();
556 }
557
558 //=================================================================================
559 // function : ValueChangedInSpinBox()
560 // purpose  :
561 //=================================================================================
562 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
563 {
564   QObject* send = (QObject*)sender();
565   switch (getConstructorId()) {
566   case 0:
567     if (send == GroupPoints->SpinBox_DY)
568       myNbTimesU = newValue;
569     break;
570   case 1:
571     if (send == GroupDimensions->SpinBox_DY1)
572       myNbTimesU = newValue;
573     else if (send == GroupDimensions->SpinBox_DY2)
574       myNbTimesV = newValue;
575     break;
576   }
577
578   processPreview();
579 }
580
581 //=================================================================================
582 // function : ReverseStepU()
583 // purpose  : 'state' not used here
584 //=================================================================================
585 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
586 {
587   myStepU = -myStepU;
588
589   int aConstructorId = getConstructorId();
590
591   if (aConstructorId == 0)
592     GroupPoints->SpinBox_DX->setValue(myStepU);
593   else if (aConstructorId == 1)
594     GroupDimensions->SpinBox_DX1->setValue(myStepU);
595
596   processPreview();
597 }
598
599 //=================================================================================
600 // function : ReverseStepV
601 // purpose  : 'state' not used here
602 //=================================================================================
603 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
604 {
605   myStepV = -myStepV;
606
607   GroupDimensions->SpinBox_DX2->setValue(myStepV);
608
609   processPreview();
610 }
611
612 //=================================================================================
613 // function : createOperation
614 // purpose  :
615 //=================================================================================
616 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
617 {
618   return getGeomEngine()->GetITransformOperations();
619 }
620
621 //=================================================================================
622 // function : isValid
623 // purpose  :
624 //=================================================================================
625 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
626 {
627   bool ok = false;
628   switch (getConstructorId()) {
629   case 0:
630     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) &&
631          GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) &&
632          myBase;
633          //myBase && myVectorU; // Mantis issue 0021718
634     break;
635   case 1:
636     ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) &&
637          GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) &&
638          GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) &&
639          GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) &&
640          myBase;
641          //myBase && myVectorU && myVectorV; // Mantis issue 0021718
642     break;
643   default:
644     break;
645   }
646   return ok;
647 }
648
649 //=================================================================================
650 // function : execute
651 // purpose  :
652 //=================================================================================
653 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
654 {
655   bool res = false;
656
657   GEOM::GEOM_Object_var anObj;
658   QStringList aParameters;
659
660   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
661
662   switch (getConstructorId()) {
663   case 0:
664     createPathPreview(myVectorU.get());
665     anObj = anOper->MultiTranslate1D(myBase.get(), myVectorU.get(), myStepU, myNbTimesU);
666     if (!IsPreview()) {
667       aParameters << GroupPoints->SpinBox_DX->text();
668       aParameters << GroupPoints->SpinBox_DY->text();
669     }
670     res = true;
671     break;
672   case 1:
673     createPathPreview(myVectorU.get());
674     createPathPreview(myVectorV.get());
675     anObj = anOper->MultiTranslate2D(myBase.get(),
676                                      myVectorU.get(), myStepU, myNbTimesU,
677                                      myVectorV.get(), myStepV, myNbTimesV);
678     if (!IsPreview()) {
679       aParameters << GroupDimensions->SpinBox_DX1->text();
680       aParameters << GroupDimensions->SpinBox_DY1->text();
681       aParameters << GroupDimensions->SpinBox_DX2->text();
682       aParameters << GroupDimensions->SpinBox_DY2->text();
683     }
684     res = true;
685     break;
686   }
687
688   if (!anObj->_is_nil()) {
689     if (!IsPreview())
690       anObj->SetParameters(aParameters.join(":").toUtf8().constData());
691     objects.push_back(anObj._retn());
692   }
693
694   return res;
695 }
696
697 //=================================================================================
698 // function : addSubshapeToStudy
699 // purpose  : virtual method to add new SubObjects if local selection
700 //=================================================================================
701 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
702 {
703   switch (getConstructorId()) {
704   case 0:
705     GEOMBase::PublishSubObject( myVectorU.get() );
706     break;
707   case 1:
708     GEOMBase::PublishSubObject( myVectorU.get() );
709     GEOMBase::PublishSubObject( myVectorV.get() );
710     break;
711   default:
712     break;
713   }
714 }
715
716 //=================================================================================
717 // function : getSourceObjects
718 // purpose  : virtual method to get source objects
719 //=================================================================================
720 QList<GEOM::GeomObjPtr> TransformationGUI_MultiTranslationDlg::getSourceObjects()
721 {
722   QList<GEOM::GeomObjPtr> res;
723   res << myBase << myVectorU << myVectorV;
724   return res;
725 }
726
727 //=================================================================================
728 // function : restoreSubShapes
729 // purpose  :
730 //=================================================================================
731 void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::SObject_ptr theSObject)
732 {
733   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
734     // we pass here the first operation argument (object) through the list of arguments
735     // because the rotation operation place its arguments in the data structure in another order,
736     // and we need to point the first argument directly
737     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
738     anArgs->length(1);
739     anArgs[0] = myBase.copy();
740     getGeomEngine()->RestoreSubShapesSO(theSObject, anArgs,
741                                         /*theFindMethod=*/GEOM::FSM_MultiTransformed,
742                                         /*theInheritFirstArg=*/true,
743                                         mainFrame()->CheckBoxAddPrefix->isChecked());
744   }
745 }
746
747 //=================================================================================
748 // function : createPathPreview
749 // purpose  :
750 //=================================================================================
751 void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_ptr thePath )
752 {
753   if ( IsPreview() ) {
754     if (thePath->_is_nil()) return;
755     TopoDS_Shape aShape;
756     GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
757     TopoDS_Edge anEdge = TopoDS::Edge( aShape );
758     ShapeAnalysis_Edge aShapeAnal;
759     TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
760     TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
761     if ( BRep_Tool::Pnt(aFirst).IsEqual( BRep_Tool::Pnt(aLast), Precision::Confusion() ) ) return;
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 }