Salome HOME
c41e0a12f931ab33b8c9eeef3200166016cb4fe6
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MultiTranslationDlg.cxx
1 //  Copyright (C) 2007-2008  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 <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 // OCCT Includes
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS.hxx>
41 #include <TopExp.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44
45 #include <GEOMImpl_Types.hxx>
46
47 //=================================================================================
48 // class    : TransformationGUI_MultiTranslationDlg()
49 // purpose  : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
55 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
56   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
57     myInitial(true)
58 {
59   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
61   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
62   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63
64   setWindowTitle(tr("GEOM_MULTITRANSLATION_TITLE"));
65
66   /***************************************************************/
67   mainFrame()->GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
68   mainFrame()->RadioButton1->setIcon(image0);
69   mainFrame()->RadioButton2->setIcon(image1);
70   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71   mainFrame()->RadioButton3->close();
72
73   GroupPoints = new DlgRef_2Sel2Spin1Check(centralWidget());
74   GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
75   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
76   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
77   GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
78   GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
79   GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
80   GroupPoints->PushButton1->setIcon(image2);
81   GroupPoints->PushButton2->setIcon(image2);
82   GroupPoints->LineEdit1->setReadOnly(true);
83   GroupPoints->LineEdit2->setReadOnly(true);
84
85   GroupDimensions = new DlgRef_3Sel4Spin2Check(centralWidget());
86   GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
87   GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
88   GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
89   GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
90   GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
91   GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
92   GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
93   GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
94   GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
95   GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
96   GroupDimensions->PushButton1->setIcon(image2);
97   GroupDimensions->PushButton2->setIcon(image2);
98   GroupDimensions->PushButton3->setIcon(image2);
99   GroupDimensions->LineEdit1->setReadOnly(true);
100   GroupDimensions->LineEdit2->setReadOnly(true);
101   GroupDimensions->LineEdit3->setReadOnly(true);
102
103   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
104   layout->setMargin(0); layout->setSpacing(6);
105   layout->addWidget(GroupPoints);
106   layout->addWidget(GroupDimensions);
107   /***************************************************************/
108
109   setHelpFileName("multi_translation_operation_page.html");
110
111   Init();
112 }
113
114 //=================================================================================
115 // function : ~TransformationGUI_MultiTranslationDlg()
116 // purpose  : Destroys the object and frees any allocated resources
117 //=================================================================================
118 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
119 {
120   // no need to delete child widgets, Qt does it all for us
121 }
122
123 //=================================================================================
124 // function : Init()
125 // purpose  :
126 //=================================================================================
127 void TransformationGUI_MultiTranslationDlg::Init()
128 {
129   // Get setting of step value from file configuration
130   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
131   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
132
133   int SpecificStep = 1;
134   // min, max, step and decimals for spin boxes & initial values
135   initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
136   initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep);
137   GroupPoints->SpinBox_DX->setValue(myStepU);
138   GroupPoints->SpinBox_DY->setValue(myNbTimesU);
139
140   initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
141   initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep);
142   initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
143   initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep);
144   GroupDimensions->SpinBox_DX1->setValue(myStepU);
145   GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
146   GroupDimensions->SpinBox_DX2->setValue(myStepV);
147   GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
148
149   // init variables
150   myStepU = myStepV = 50.0;
151   myNbTimesU = myNbTimesV = 2;
152
153   GroupPoints->LineEdit1->setText("");
154   GroupPoints->LineEdit2->setText("");
155
156   GroupDimensions->LineEdit1->setText("");
157   GroupDimensions->LineEdit2->setText("");
158   GroupDimensions->LineEdit3->setText("");
159
160   myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
161
162   // signals and slots connections
163   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
164   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
165
166   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
167
168   connect(GroupPoints->PushButton1,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169   connect(GroupPoints->PushButton2,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
170   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
171   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
172   connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
173
174   connect(GroupPoints->LineEdit1,     SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
175   connect(GroupPoints->LineEdit2,     SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
176   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
177   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
178   connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
179
180   connect(GroupPoints->SpinBox_DX,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
181   connect(GroupPoints->SpinBox_DY,      SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
182   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
183   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
184   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
185   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
186
187   connect(GroupPoints->SpinBox_DX,      SIGNAL(textChanged(const QString& )), 
188           this, SLOT(TextValueChangedInSpinBox(const QString& )));
189   connect(GroupDimensions->SpinBox_DX1, SIGNAL(textChanged(const QString& )), 
190           this, SLOT(TextValueChangedInSpinBox(const QString& )));
191   connect(GroupDimensions->SpinBox_DX2, SIGNAL(textChanged(const QString& )), 
192           this, SLOT(TextValueChangedInSpinBox(const QString& )));
193   
194   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
195
196   connect(GroupPoints->CheckButton1,     SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
197   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
198   connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
199
200   initName(tr("GEOM_MULTITRANSLATION"));
201
202   ConstructorsClicked(0);
203 }
204
205 //=================================================================================
206 // function : SetDoubleSpinBoxStep()
207 // purpose  : Double spin box management
208 //=================================================================================
209 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep (double step)
210 {
211   GroupPoints->SpinBox_DX->setSingleStep(step);
212   GroupPoints->SpinBox_DY->setSingleStep((int)step);
213   GroupDimensions->SpinBox_DX1->setSingleStep(step);
214   GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
215   GroupDimensions->SpinBox_DX2->setSingleStep(step);
216   GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
217 }
218
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose  : Radio button management
222 //=================================================================================
223 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked (int constructorId)
224 {
225   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
226
227   switch (constructorId) {
228   case 0: // Translate simple
229     {
230       GroupDimensions->hide();
231       GroupPoints->show();
232
233       GroupPoints->LineEdit1->setText("");
234       GroupPoints->LineEdit2->setText("");
235       myBase = myVectorU = GEOM::GEOM_Object::_nil();
236
237       GroupPoints->SpinBox_DX->setValue(myStepU);
238       GroupPoints->SpinBox_DY->setValue(myNbTimesU);
239
240       GroupPoints->PushButton1->click();
241       break;
242     }
243   case 1: // Translate double
244     {
245       GroupPoints->hide();
246       GroupDimensions->show();
247
248       GroupDimensions->LineEdit1->setText("");
249       GroupDimensions->LineEdit2->setText("");
250       GroupDimensions->LineEdit3->setText("");
251       myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
252
253       GroupDimensions->SpinBox_DX1->setValue(myStepU);
254       GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
255       GroupDimensions->SpinBox_DX2->setValue(myStepV);
256       GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
257
258       GroupDimensions->PushButton1->click();
259       break;
260     }
261   }
262
263   qApp->processEvents();
264   updateGeometry();
265   resize(minimumSizeHint());
266
267   if (myInitial) {
268     myInitial = false;
269     SelectionIntoArgument();
270   }
271   else {
272     displayPreview();
273   }
274 }
275
276 //=================================================================================
277 // function : ClickOnOk()
278 // purpose  :
279 //=================================================================================
280 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
281 {
282   if (ClickOnApply())
283     ClickOnCancel();
284 }
285
286 //=================================================================================
287 // function : ClickOnApply()
288 // purpose  :
289 //=================================================================================
290 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
291 {
292   if (!onAccept())
293     return false;
294
295   initName();
296   // activate selection and connect selection manager
297   ConstructorsClicked(getConstructorId());
298   return true;
299 }
300
301 //=================================================================================
302 // function : SelectionIntoArgument()
303 // purpose  : Called when selection is changed or on dialog initialization or activation
304 //=================================================================================
305 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
306 {
307   erasePreview();
308   myEditCurrentArgument->setText("");
309
310   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
311       myEditCurrentArgument == GroupDimensions->LineEdit1)
312     myBase = GEOM::GEOM_Object::_nil();
313   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
314            myEditCurrentArgument == GroupDimensions->LineEdit2)
315     myVectorU = GEOM::GEOM_Object::_nil();
316   else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
317     myVectorV = GEOM::GEOM_Object::_nil();
318
319   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
320   SALOME_ListIO aSelList;
321   aSelMgr->selectedObjects(aSelList);
322
323   if (aSelList.Extent() != 1)
324     return;
325
326   // nbSel == 1
327   Standard_Boolean testResult = Standard_False;;
328   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
329
330   if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
331     return;
332
333   QString aName = GEOMBase::GetName(aSelectedObject);
334
335   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
336       myEditCurrentArgument == GroupDimensions->LineEdit1)
337     myBase = aSelectedObject;
338   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
339            myEditCurrentArgument == GroupDimensions->LineEdit2 ||
340            myEditCurrentArgument == GroupDimensions->LineEdit3) {
341     TopoDS_Shape aShape;
342
343     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
344       TColStd_IndexedMapOfInteger aMap;
345       aSelMgr->GetIndexes(aSelList.First(), aMap);
346       if (aMap.Extent() == 1) {
347         int anIndex = aMap(1);
348         aName += QString(":edge_%1").arg(anIndex);
349
350         //Find SubShape Object in Father
351         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
352
353         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
354           GEOM::GEOM_IShapesOperations_var aShapesOp =
355             getGeomEngine()->GetIShapesOperations(getStudyId());
356           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
357             myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
358           else
359             myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
360         }
361         else {
362           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
363             myVectorV = aFindedObject;
364           else
365             myVectorU = aFindedObject;
366         }
367       }
368       else {
369         if (aShape.ShapeType() != TopAbs_EDGE) {
370           aSelectedObject = GEOM::GEOM_Object::_nil();
371           aName = "";
372         }
373         if (myEditCurrentArgument == GroupDimensions->LineEdit3)
374           myVectorV = aSelectedObject;
375         else
376           myVectorU = aSelectedObject;
377       }
378     }
379   }
380   myEditCurrentArgument->setText(aName);
381
382   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
383     if (!myBase->_is_nil() && myVectorU->_is_nil())
384       GroupPoints->PushButton2->click();
385   }
386   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
387     if (!myVectorU->_is_nil() && myBase->_is_nil())
388       GroupPoints->PushButton1->click();
389   }
390   else if (myEditCurrentArgument == GroupDimensions->LineEdit1) {
391     if (!myBase->_is_nil() && myVectorU->_is_nil())
392       GroupDimensions->PushButton2->click();
393   }
394   else if (myEditCurrentArgument == GroupDimensions->LineEdit2) {
395     if (!myVectorU->_is_nil() && myVectorV->_is_nil())
396       GroupDimensions->PushButton3->click();
397   }
398   else if (myEditCurrentArgument == GroupDimensions->LineEdit3) {
399     if (!myVectorV->_is_nil() && myBase->_is_nil())
400       GroupDimensions->PushButton1->click();
401   }
402
403   // clear selection
404   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
405   myGeomGUI->getApp()->selectionMgr()->clearSelected();
406   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
407           this, SLOT(SelectionIntoArgument()));
408
409   displayPreview();
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(GEOM::GEOM_Object::_nil(), 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(GEOM::GEOM_Object::_nil(), 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(GEOM::GEOM_Object::_nil(), 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   displayPreview();
476 }
477
478 //=================================================================================
479 // function : LineEditReturnPressed()
480 // purpose  :
481 //=================================================================================
482 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
483 {
484   QLineEdit* send = (QLineEdit*)sender();
485   if (send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
486       send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
487       send == GroupDimensions->LineEdit3) {
488     myEditCurrentArgument = send;
489     GEOMBase_Skeleton::LineEditReturnPressed();
490   }
491 }
492
493 //=================================================================================
494 // function : ActivateThisDialog()
495 // purpose  :
496 //=================================================================================
497 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
498 {
499   GEOMBase_Skeleton::ActivateThisDialog();
500   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
501            this, SLOT( SelectionIntoArgument() ) );
502
503   ConstructorsClicked( getConstructorId() );
504 }
505
506 //=================================================================================
507 // function : enterEvent()
508 // purpose  :
509 //=================================================================================
510 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
511 {
512   if (!mainFrame()->GroupConstructors->isEnabled())
513     ActivateThisDialog();
514 }
515
516 //=================================================================================
517 // function : TextValueChangedInSpinBox
518 // purpose  :
519 //=================================================================================
520 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& s)
521 {
522   QObject* send = (QObject*)sender();
523   bool isDigit = true;
524   
525   switch (getConstructorId()) {
526   case 0: 
527     GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
528     if(!isDigit){
529       GroupPoints->CheckButton1->setChecked(false);
530     }
531     GroupPoints->CheckButton1->setEnabled(isDigit);
532     break;
533   case 1: 
534     if (send == GroupDimensions->SpinBox_DX1) {
535       GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
536       if(!isDigit) 
537         GroupDimensions->CheckButton1->setChecked(false);
538       GroupDimensions->CheckButton1->setEnabled(isDigit);
539     }
540     else if(send == GroupDimensions->SpinBox_DX2){
541       GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
542       if(!isDigit) 
543         GroupDimensions->CheckButton2->setChecked(false);
544       GroupDimensions->CheckButton2->setEnabled(isDigit);
545     }
546     break;
547   }
548 }
549
550 //=================================================================================
551 // function : ValueChangedInSpinBox()
552 // purpose  :
553 //=================================================================================
554 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
555 {
556   QObject* send = (QObject*)sender();
557   switch (getConstructorId()) {
558   case 0:
559     if (send == GroupPoints->SpinBox_DX)
560       myStepU = newValue;
561     break;
562   case 1:
563     if (send == GroupDimensions->SpinBox_DX1)
564       myStepU = newValue;
565     else if (send == GroupDimensions->SpinBox_DX2)
566       myStepV = newValue;
567     break;
568   }
569
570   displayPreview();
571 }
572
573 //=================================================================================
574 // function : ValueChangedInSpinBox()
575 // purpose  :
576 //=================================================================================
577 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
578 {
579   QObject* send = (QObject*)sender();
580   switch (getConstructorId()) {
581   case 0:
582     if (send == GroupPoints->SpinBox_DY)
583       myNbTimesU = newValue;
584     break;
585   case 1:
586     if (send == GroupDimensions->SpinBox_DY1)
587       myNbTimesU = newValue;
588     else if (send == GroupDimensions->SpinBox_DY2)
589       myNbTimesV = newValue;
590     break;
591   }
592
593   displayPreview();
594 }
595
596 //=================================================================================
597 // function : ReverseStepU()
598 // purpose  : 'state' not used here
599 //=================================================================================
600 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
601 {
602   myStepU = -myStepU;
603
604   int aConstructorId = getConstructorId();
605
606   if (aConstructorId == 0)
607     GroupPoints->SpinBox_DX->setValue(myStepU);
608   else if (aConstructorId == 1)
609     GroupDimensions->SpinBox_DX1->setValue(myStepU);
610
611   displayPreview();
612 }
613
614 //=================================================================================
615 // function : ReverseStepV
616 // purpose  : 'state' not used here
617 //=================================================================================
618 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
619 {
620   myStepV = -myStepV;
621
622   GroupDimensions->SpinBox_DX2->setValue(myStepV);
623
624   displayPreview();
625 }
626
627 //=================================================================================
628 // function : createOperation
629 // purpose  :
630 //=================================================================================
631 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
632 {
633   return getGeomEngine()->GetITransformOperations(getStudyId());
634 }
635
636 //=================================================================================
637 // function : isValid
638 // purpose  :
639 //=================================================================================
640 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
641 {
642   int aConstructorId = getConstructorId();
643   
644   if (aConstructorId == 0) {
645     bool ok = true;
646     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
647     ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
648     return !(myBase->_is_nil() || myVectorU->_is_nil()) && ok;
649   }
650   else if (aConstructorId == 1) {
651     bool ok = true;
652     ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) && ok;
653     ok = GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) && ok;
654     ok = GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) && ok;
655     ok = GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) && ok;
656     return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil()) && ok;
657   }
658   return 0;
659 }
660
661 //=================================================================================
662 // function : execute
663 // purpose  :
664 //=================================================================================
665 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
666 {
667   bool res = false;
668
669   GEOM::GEOM_Object_var anObj;
670
671   QStringList aParameters;
672
673   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
674
675   switch (getConstructorId()) {
676   case 0:
677     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU)) {
678       anObj = anOper->MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
679       if(!IsPreview()) {
680         aParameters<<GroupPoints->SpinBox_DX->text();
681         aParameters<<GroupPoints->SpinBox_DY->text();
682       }
683       res = true;
684     }
685     break;
686   case 1:
687     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU) &&
688         !CORBA::is_nil(myVectorV)) {
689       anObj = anOper->MultiTranslate2D(myBase,
690                                        myVectorU, myStepU, myNbTimesU,
691                                        myVectorV, myStepV, myNbTimesV);
692       if(!IsPreview()) {
693         aParameters<<GroupDimensions->SpinBox_DX1->text();
694         aParameters<<GroupDimensions->SpinBox_DY1->text();
695         aParameters<<GroupDimensions->SpinBox_DX2->text();
696         aParameters<<GroupDimensions->SpinBox_DY2->text();
697       }
698       res = true;
699     }
700     break;
701   }
702
703   if (!anObj->_is_nil()) {
704     if(!IsPreview())
705       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
706     objects.push_back(anObj._retn());
707   }
708
709   return res;
710 }
711
712 //=================================================================================
713 // function : addSubshapeToStudy
714 // purpose  : virtual method to add new SubObjects if local selection
715 //=================================================================================
716 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
717 {
718   QMap<QString, GEOM::GEOM_Object_var> objMap;
719
720   switch (getConstructorId()) {
721   case 0:
722     objMap[GroupPoints->LineEdit2->text()] = myVectorU;
723     break;
724   case 1:
725     objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
726     objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
727     break;
728   }
729   addSubshapesToFather(objMap);
730 }