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