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