]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx
Salome HOME
Merge from V5_1_main 10/12/2010
[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   // min, max, step and decimals for spin boxes & initial values
145   initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
146   initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep);
147   GroupPoints->SpinBox_DX->setValue(myStepU);
148   GroupPoints->SpinBox_DY->setValue(myNbTimesU);
149
150   initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" );
151   initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep);
152   initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
153   initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep);
154   GroupDimensions->SpinBox_DX1->setValue(myStepU);
155   GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
156   GroupDimensions->SpinBox_DX2->setValue(myStepV);
157   GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
158
159   // init variables
160   myStepU = myStepV = 50.0;
161   myNbTimesU = myNbTimesV = 2;
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 = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
171
172   mainFrame()->GroupBoxPublish->show();
173
174   // signals and slots connections
175   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
176   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
177
178   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
179
180   connect(GroupPoints->PushButton1,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
181   connect(GroupPoints->PushButton2,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
182   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
183   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
184   connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
185
186   connect(GroupPoints->LineEdit1,     SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
187   connect(GroupPoints->LineEdit2,     SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
188   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
189   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
190   connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
191
192   connect(GroupPoints->SpinBox_DX,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
193   connect(GroupPoints->SpinBox_DY,      SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
194   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
195   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
196   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
197   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
198
199   connect(GroupPoints->SpinBox_DX,      SIGNAL(textChanged(const QString& )),
200           this, SLOT(TextValueChangedInSpinBox(const QString& )));
201   connect(GroupDimensions->SpinBox_DX1, SIGNAL(textChanged(const QString& )),
202           this, SLOT(TextValueChangedInSpinBox(const QString& )));
203   connect(GroupDimensions->SpinBox_DX2, SIGNAL(textChanged(const QString& )),
204           this, SLOT(TextValueChangedInSpinBox(const QString& )));
205
206   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
207
208   connect(GroupPoints->CheckButton1,     SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
209   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
210   connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
211
212   initName(tr("GEOM_MULTITRANSLATION"));
213
214   ConstructorsClicked(0);
215 }
216
217 //=================================================================================
218 // function : SetDoubleSpinBoxStep()
219 // purpose  : Double spin box management
220 //=================================================================================
221 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep (double step)
222 {
223   GroupPoints->SpinBox_DX->setSingleStep(step);
224   GroupDimensions->SpinBox_DX1->setSingleStep(step);
225   GroupDimensions->SpinBox_DX2->setSingleStep(step);
226
227   // san : Commented so as not to override specific step settings
228   //GroupPoints->SpinBox_DY->setSingleStep((int)step);
229   //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
230   //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
231 }
232
233 //=================================================================================
234 // function : ConstructorsClicked()
235 // purpose  : Radio button management
236 //=================================================================================
237 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked (int constructorId)
238 {
239   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
240
241   switch (constructorId) {
242   case 0: // Translate simple
243     {
244       GroupDimensions->hide();
245       GroupPoints->show();
246
247       GroupPoints->LineEdit1->setText("");
248       GroupPoints->LineEdit2->setText("");
249       myBase = myVectorU = GEOM::GEOM_Object::_nil();
250
251       GroupPoints->SpinBox_DX->setValue(myStepU);
252       GroupPoints->SpinBox_DY->setValue(myNbTimesU);
253
254       GroupPoints->PushButton1->click();
255       break;
256     }
257   case 1: // Translate double
258     {
259       GroupPoints->hide();
260       GroupDimensions->show();
261
262       GroupDimensions->LineEdit1->setText("");
263       GroupDimensions->LineEdit2->setText("");
264       GroupDimensions->LineEdit3->setText("");
265       myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
266
267       GroupDimensions->SpinBox_DX1->setValue(myStepU);
268       GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
269       GroupDimensions->SpinBox_DX2->setValue(myStepV);
270       GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
271
272       GroupDimensions->PushButton1->click();
273       break;
274     }
275   }
276
277   qApp->processEvents();
278   updateGeometry();
279   resize(minimumSizeHint());
280
281   if (myInitial) {
282     myInitial = false;
283     SelectionIntoArgument();
284   }
285   else {
286     displayPreview();
287   }
288 }
289
290 //=================================================================================
291 // function : ClickOnOk()
292 // purpose  :
293 //=================================================================================
294 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
295 {
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   myEditCurrentArgument->setText("");
323
324   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
325       myEditCurrentArgument == GroupDimensions->LineEdit1)
326     myBase = GEOM::GEOM_Object::_nil();
327   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
328            myEditCurrentArgument == GroupDimensions->LineEdit2)
329     myVectorU = GEOM::GEOM_Object::_nil();
330   else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
331     myVectorV = GEOM::GEOM_Object::_nil();
332
333   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
334   SALOME_ListIO aSelList;
335   aSelMgr->selectedObjects(aSelList);
336
337   if (aSelList.Extent() != 1)
338     return;
339
340   // nbSel == 1
341   Standard_Boolean testResult = Standard_False;;
342   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
343
344   if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
345     return;
346
347   QString aName = GEOMBase::GetName(aSelectedObject);
348
349   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
350       myEditCurrentArgument == GroupDimensions->LineEdit1)
351     myBase = aSelectedObject;
352   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
353            myEditCurrentArgument == GroupDimensions->LineEdit2 ||
354            myEditCurrentArgument == GroupDimensions->LineEdit3) {
355     TopoDS_Shape aShape;
356
357     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
358       TColStd_IndexedMapOfInteger aMap;
359       aSelMgr->GetIndexes(aSelList.First(), aMap);
360       if (aMap.Extent() == 1) {
361         int anIndex = aMap(1);
362         aName += QString(":edge_%1").arg(anIndex);
363
364         //Find SubShape Object in Father
365         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
366
367         if (aFindedObject->_is_nil()) { // Object not found in study
368           GEOM::GEOM_IShapesOperations_var aShapesOp =
369             getGeomEngine()->GetIShapesOperations(getStudyId());
370           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
371             myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
372           else
373             myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
374         }
375         else {
376           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
377             myVectorV = aFindedObject;
378           else
379             myVectorU = aFindedObject;
380         }
381       }
382       else {
383         if (aShape.ShapeType() != TopAbs_EDGE) {
384           aSelectedObject = GEOM::GEOM_Object::_nil();
385           aName = "";
386         }
387         if (myEditCurrentArgument == GroupDimensions->LineEdit3)
388           myVectorV = aSelectedObject;
389         else
390           myVectorU = aSelectedObject;
391       }
392     }
393   }
394   myEditCurrentArgument->setText(aName);
395
396   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
397     if (!myBase->_is_nil() && myVectorU->_is_nil())
398       GroupPoints->PushButton2->click();
399   }
400   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
401     if (!myVectorU->_is_nil() && myBase->_is_nil())
402       GroupPoints->PushButton1->click();
403   }
404   else if (myEditCurrentArgument == GroupDimensions->LineEdit1) {
405     if (!myBase->_is_nil() && myVectorU->_is_nil())
406       GroupDimensions->PushButton2->click();
407   }
408   else if (myEditCurrentArgument == GroupDimensions->LineEdit2) {
409     if (!myVectorU->_is_nil() && myVectorV->_is_nil())
410       GroupDimensions->PushButton3->click();
411   }
412   else if (myEditCurrentArgument == GroupDimensions->LineEdit3) {
413     if (!myVectorV->_is_nil() && myBase->_is_nil())
414       GroupDimensions->PushButton1->click();
415   }
416
417   // clear selection
418   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
419   myGeomGUI->getApp()->selectionMgr()->clearSelected();
420   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
421           this, SLOT(SelectionIntoArgument()));
422
423   displayPreview();
424 }
425
426 //=================================================================================
427 // function : SetEditCurrentArgument()
428 // purpose  :
429 //=================================================================================
430 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
431 {
432   QPushButton* send = (QPushButton*)sender();
433
434   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
435   globalSelection(GEOM_ALLSHAPES);
436
437   if (send == GroupPoints->PushButton1) {
438     myEditCurrentArgument = GroupPoints->LineEdit1;
439
440     GroupPoints->PushButton2->setDown(false);
441     GroupPoints->LineEdit2->setEnabled(false);
442   }
443   else if (send == GroupPoints->PushButton2) {
444     myEditCurrentArgument = GroupPoints->LineEdit2;
445
446     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
447
448     GroupPoints->PushButton1->setDown(false);
449     GroupPoints->LineEdit1->setEnabled(false);
450   }
451   else if (send == GroupDimensions->PushButton1) {
452     myEditCurrentArgument = GroupDimensions->LineEdit1;
453
454     GroupDimensions->PushButton2->setDown(false);
455     GroupDimensions->PushButton3->setDown(false);
456     GroupDimensions->LineEdit2->setEnabled(false);
457     GroupDimensions->LineEdit3->setEnabled(false);
458   }
459   else if (send == GroupDimensions->PushButton2) {
460     myEditCurrentArgument = GroupDimensions->LineEdit2;
461
462     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
463
464     GroupDimensions->PushButton1->setDown(false);
465     GroupDimensions->PushButton3->setDown(false);
466     GroupDimensions->LineEdit1->setEnabled(false);
467     GroupDimensions->LineEdit3->setEnabled(false);
468   }
469   else if (send == GroupDimensions->PushButton3) {
470     myEditCurrentArgument = GroupDimensions->LineEdit3;
471
472     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
473
474     GroupDimensions->PushButton1->setDown(false);
475     GroupDimensions->PushButton2->setDown(false);
476     GroupDimensions->LineEdit1->setEnabled(false);
477     GroupDimensions->LineEdit2->setEnabled(false);
478   }
479   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
480           this, SLOT(SelectionIntoArgument()));
481
482   // enable line edit
483   myEditCurrentArgument->setEnabled(true);
484   myEditCurrentArgument->setFocus();
485   // after setFocus(), because it will be setDown(false) when loses focus
486   send->setDown(true);
487
488   // seems we need it only to avoid preview disappearing, caused by selection mode change
489   displayPreview();
490 }
491
492 //=================================================================================
493 // function : LineEditReturnPressed()
494 // purpose  :
495 //=================================================================================
496 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
497 {
498   QLineEdit* send = (QLineEdit*)sender();
499   if (send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
500       send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
501       send == GroupDimensions->LineEdit3) {
502     myEditCurrentArgument = send;
503     GEOMBase_Skeleton::LineEditReturnPressed();
504   }
505 }
506
507 //=================================================================================
508 // function : ActivateThisDialog()
509 // purpose  :
510 //=================================================================================
511 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
512 {
513   GEOMBase_Skeleton::ActivateThisDialog();
514   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
515            this, SLOT( SelectionIntoArgument() ) );
516
517   ConstructorsClicked( getConstructorId() );
518 }
519
520 //=================================================================================
521 // function : enterEvent()
522 // purpose  :
523 //=================================================================================
524 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
525 {
526   if (!mainFrame()->GroupConstructors->isEnabled())
527     ActivateThisDialog();
528 }
529
530 //=================================================================================
531 // function : TextValueChangedInSpinBox
532 // purpose  :
533 //=================================================================================
534 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& s)
535 {
536   QObject* send = (QObject*)sender();
537   bool isDigit = true;
538
539   switch (getConstructorId()) {
540   case 0:
541     GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
542     if(!isDigit){
543       GroupPoints->CheckButton1->setChecked(false);
544     }
545     GroupPoints->CheckButton1->setEnabled(isDigit);
546     break;
547   case 1:
548     if (send == GroupDimensions->SpinBox_DX1) {
549       GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
550       if(!isDigit)
551         GroupDimensions->CheckButton1->setChecked(false);
552       GroupDimensions->CheckButton1->setEnabled(isDigit);
553     }
554     else if(send == GroupDimensions->SpinBox_DX2){
555       GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
556       if(!isDigit)
557         GroupDimensions->CheckButton2->setChecked(false);
558       GroupDimensions->CheckButton2->setEnabled(isDigit);
559     }
560     break;
561   }
562 }
563
564 //=================================================================================
565 // function : ValueChangedInSpinBox()
566 // purpose  :
567 //=================================================================================
568 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
569 {
570   QObject* send = (QObject*)sender();
571   switch (getConstructorId()) {
572   case 0:
573     if (send == GroupPoints->SpinBox_DX)
574       myStepU = newValue;
575     break;
576   case 1:
577     if (send == GroupDimensions->SpinBox_DX1)
578       myStepU = newValue;
579     else if (send == GroupDimensions->SpinBox_DX2)
580       myStepV = newValue;
581     break;
582   }
583
584   displayPreview();
585 }
586
587 //=================================================================================
588 // function : ValueChangedInSpinBox()
589 // purpose  :
590 //=================================================================================
591 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
592 {
593   QObject* send = (QObject*)sender();
594   switch (getConstructorId()) {
595   case 0:
596     if (send == GroupPoints->SpinBox_DY)
597       myNbTimesU = newValue;
598     break;
599   case 1:
600     if (send == GroupDimensions->SpinBox_DY1)
601       myNbTimesU = newValue;
602     else if (send == GroupDimensions->SpinBox_DY2)
603       myNbTimesV = newValue;
604     break;
605   }
606
607   displayPreview();
608 }
609
610 //=================================================================================
611 // function : ReverseStepU()
612 // purpose  : 'state' not used here
613 //=================================================================================
614 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
615 {
616   myStepU = -myStepU;
617
618   int aConstructorId = getConstructorId();
619
620   if (aConstructorId == 0)
621     GroupPoints->SpinBox_DX->setValue(myStepU);
622   else if (aConstructorId == 1)
623     GroupDimensions->SpinBox_DX1->setValue(myStepU);
624
625   displayPreview();
626 }
627
628 //=================================================================================
629 // function : ReverseStepV
630 // purpose  : 'state' not used here
631 //=================================================================================
632 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
633 {
634   myStepV = -myStepV;
635
636   GroupDimensions->SpinBox_DX2->setValue(myStepV);
637
638   displayPreview();
639 }
640
641 //=================================================================================
642 // function : createOperation
643 // purpose  :
644 //=================================================================================
645 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
646 {
647   return getGeomEngine()->GetITransformOperations(getStudyId());
648 }
649
650 //=================================================================================
651 // function : isValid
652 // purpose  :
653 //=================================================================================
654 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
655 {
656   int aConstructorId = getConstructorId();
657
658   if (aConstructorId == 0) {
659     bool ok = true;
660     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
661     ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
662     return !(myBase->_is_nil() || myVectorU->_is_nil()) && ok;
663   }
664   else if (aConstructorId == 1) {
665     bool ok = true;
666     ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) && ok;
667     ok = GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) && ok;
668     ok = GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) && ok;
669     ok = GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) && ok;
670     return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil()) && ok;
671   }
672   return 0;
673 }
674
675 //=================================================================================
676 // function : execute
677 // purpose  :
678 //=================================================================================
679 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
680 {
681   bool res = false;
682
683   GEOM::GEOM_Object_var anObj;
684
685   QStringList aParameters;
686
687   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
688
689   switch (getConstructorId()) {
690   case 0:
691     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU)) {
692       createPathPreview ( myVectorU );
693       anObj = anOper->MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
694       if(!IsPreview()) {
695         aParameters<<GroupPoints->SpinBox_DX->text();
696         aParameters<<GroupPoints->SpinBox_DY->text();
697       }
698       res = true;
699     }
700     break;
701   case 1:
702     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU) &&
703         !CORBA::is_nil(myVectorV)) {
704       createPathPreview ( myVectorU );
705       createPathPreview ( myVectorV );
706       anObj = anOper->MultiTranslate2D(myBase,
707                                        myVectorU, myStepU, myNbTimesU,
708                                        myVectorV, myStepV, myNbTimesV);
709       if(!IsPreview()) {
710         aParameters<<GroupDimensions->SpinBox_DX1->text();
711         aParameters<<GroupDimensions->SpinBox_DY1->text();
712         aParameters<<GroupDimensions->SpinBox_DX2->text();
713         aParameters<<GroupDimensions->SpinBox_DY2->text();
714       }
715       res = true;
716     }
717     break;
718   }
719
720   if (!anObj->_is_nil()) {
721     if(!IsPreview())
722       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
723     objects.push_back(anObj._retn());
724   }
725
726   return res;
727 }
728
729 //=================================================================================
730 // function : addSubshapeToStudy
731 // purpose  : virtual method to add new SubObjects if local selection
732 //=================================================================================
733 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
734 {
735   QMap<QString, GEOM::GEOM_Object_var> objMap;
736
737   switch (getConstructorId()) {
738   case 0:
739     objMap[GroupPoints->LineEdit2->text()] = myVectorU;
740     break;
741   case 1:
742     objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
743     objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
744     break;
745   }
746   addSubshapesToFather(objMap);
747 }
748
749 //=================================================================================
750 // function : restoreSubShapes
751 // purpose  :
752 //=================================================================================
753 void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
754                                                               SALOMEDS::SObject_ptr theSObject)
755 {
756   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
757     // we pass here the first operation argument (object) through the list of arguments
758     // because the rotation operation place its arguments in the data structure in another order,
759     // and we need to point the first argument directly
760     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
761     anArgs->length(1);
762     anArgs[0] = myBase;
763     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
764                                         /*theFindMethod=*/GEOM::FSM_GetInPlace,
765                                         /*theInheritFirstArg=*/false,
766                                         mainFrame()->CheckBoxAddPrefix->isChecked());
767   }
768 }
769
770 //=================================================================================
771 // function : createPathPreview
772 // purpose  :
773 //=================================================================================
774 void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_var thePath )
775 {
776   if ( IsPreview() ) {
777     TopoDS_Shape aShape;
778     GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
779     TopoDS_Edge anEdge = TopoDS::Edge( aShape );
780     ShapeAnalysis_Edge aShapeAnal;
781     TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
782     TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
783     TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
784     const char* aName = "tmpVector";
785     Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
786
787     // add Prs to preview
788     SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
789     SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
790     if (aPrs)
791       aPrs->AddObject(anIO);
792     GEOMBase_Helper::displayPreview( aPrs, false, true );
793   }
794 }