]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx
Salome HOME
CCAR: improve speed of getAIS by calling CreatePrs that uses entry2aisobjects map
[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   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
342
343   if ( !GEOMBase::IsShape(aSelectedObject) )
344     return;
345
346   QString aName = GEOMBase::GetName(aSelectedObject);
347
348   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
349       myEditCurrentArgument == GroupDimensions->LineEdit1)
350     myBase = aSelectedObject;
351   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
352            myEditCurrentArgument == GroupDimensions->LineEdit2 ||
353            myEditCurrentArgument == GroupDimensions->LineEdit3) {
354     TopoDS_Shape aShape;
355
356     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
357       TColStd_IndexedMapOfInteger aMap;
358       aSelMgr->GetIndexes(aSelList.First(), aMap);
359       if (aMap.Extent() == 1) {
360         int anIndex = aMap(1);
361         aName += QString(":edge_%1").arg(anIndex);
362
363         //Find SubShape Object in Father
364         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
365
366         if (aFindedObject->_is_nil()) { // Object not found in study
367           GEOM::GEOM_IShapesOperations_var aShapesOp =
368             getGeomEngine()->GetIShapesOperations(getStudyId());
369           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
370             myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
371           else
372             myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
373         }
374         else {
375           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
376             myVectorV = aFindedObject;
377           else
378             myVectorU = aFindedObject;
379         }
380       }
381       else {
382         if (aShape.ShapeType() != TopAbs_EDGE) {
383           aSelectedObject = GEOM::GEOM_Object::_nil();
384           aName = "";
385         }
386         if (myEditCurrentArgument == GroupDimensions->LineEdit3)
387           myVectorV = aSelectedObject;
388         else
389           myVectorU = aSelectedObject;
390       }
391     }
392   }
393   myEditCurrentArgument->setText(aName);
394
395   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
396     if (!myBase->_is_nil() && myVectorU->_is_nil())
397       GroupPoints->PushButton2->click();
398   }
399   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
400     if (!myVectorU->_is_nil() && myBase->_is_nil())
401       GroupPoints->PushButton1->click();
402   }
403   else if (myEditCurrentArgument == GroupDimensions->LineEdit1) {
404     if (!myBase->_is_nil() && myVectorU->_is_nil())
405       GroupDimensions->PushButton2->click();
406   }
407   else if (myEditCurrentArgument == GroupDimensions->LineEdit2) {
408     if (!myVectorU->_is_nil() && myVectorV->_is_nil())
409       GroupDimensions->PushButton3->click();
410   }
411   else if (myEditCurrentArgument == GroupDimensions->LineEdit3) {
412     if (!myVectorV->_is_nil() && myBase->_is_nil())
413       GroupDimensions->PushButton1->click();
414   }
415
416   // clear selection
417   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
418   myGeomGUI->getApp()->selectionMgr()->clearSelected();
419   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
420           this, SLOT(SelectionIntoArgument()));
421
422   displayPreview();
423 }
424
425 //=================================================================================
426 // function : SetEditCurrentArgument()
427 // purpose  :
428 //=================================================================================
429 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
430 {
431   QPushButton* send = (QPushButton*)sender();
432
433   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
434   globalSelection(GEOM_ALLSHAPES);
435
436   if (send == GroupPoints->PushButton1) {
437     myEditCurrentArgument = GroupPoints->LineEdit1;
438
439     GroupPoints->PushButton2->setDown(false);
440     GroupPoints->LineEdit2->setEnabled(false);
441   }
442   else if (send == GroupPoints->PushButton2) {
443     myEditCurrentArgument = GroupPoints->LineEdit2;
444
445     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
446
447     GroupPoints->PushButton1->setDown(false);
448     GroupPoints->LineEdit1->setEnabled(false);
449   }
450   else if (send == GroupDimensions->PushButton1) {
451     myEditCurrentArgument = GroupDimensions->LineEdit1;
452
453     GroupDimensions->PushButton2->setDown(false);
454     GroupDimensions->PushButton3->setDown(false);
455     GroupDimensions->LineEdit2->setEnabled(false);
456     GroupDimensions->LineEdit3->setEnabled(false);
457   }
458   else if (send == GroupDimensions->PushButton2) {
459     myEditCurrentArgument = GroupDimensions->LineEdit2;
460
461     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
462
463     GroupDimensions->PushButton1->setDown(false);
464     GroupDimensions->PushButton3->setDown(false);
465     GroupDimensions->LineEdit1->setEnabled(false);
466     GroupDimensions->LineEdit3->setEnabled(false);
467   }
468   else if (send == GroupDimensions->PushButton3) {
469     myEditCurrentArgument = GroupDimensions->LineEdit3;
470
471     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
472
473     GroupDimensions->PushButton1->setDown(false);
474     GroupDimensions->PushButton2->setDown(false);
475     GroupDimensions->LineEdit1->setEnabled(false);
476     GroupDimensions->LineEdit2->setEnabled(false);
477   }
478   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
479           this, SLOT(SelectionIntoArgument()));
480
481   // enable line edit
482   myEditCurrentArgument->setEnabled(true);
483   myEditCurrentArgument->setFocus();
484   // after setFocus(), because it will be setDown(false) when loses focus
485   send->setDown(true);
486
487   // seems we need it only to avoid preview disappearing, caused by selection mode change
488   displayPreview();
489 }
490
491 //=================================================================================
492 // function : LineEditReturnPressed()
493 // purpose  :
494 //=================================================================================
495 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
496 {
497   QLineEdit* send = (QLineEdit*)sender();
498   if (send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
499       send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
500       send == GroupDimensions->LineEdit3) {
501     myEditCurrentArgument = send;
502     GEOMBase_Skeleton::LineEditReturnPressed();
503   }
504 }
505
506 //=================================================================================
507 // function : ActivateThisDialog()
508 // purpose  :
509 //=================================================================================
510 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
511 {
512   GEOMBase_Skeleton::ActivateThisDialog();
513   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
514            this, SLOT( SelectionIntoArgument() ) );
515
516   ConstructorsClicked( getConstructorId() );
517 }
518
519 //=================================================================================
520 // function : enterEvent()
521 // purpose  :
522 //=================================================================================
523 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
524 {
525   if (!mainFrame()->GroupConstructors->isEnabled())
526     ActivateThisDialog();
527 }
528
529 //=================================================================================
530 // function : TextValueChangedInSpinBox
531 // purpose  :
532 //=================================================================================
533 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& s)
534 {
535   QObject* send = (QObject*)sender();
536   bool isDigit = true;
537
538   switch (getConstructorId()) {
539   case 0:
540     GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
541     if(!isDigit){
542       GroupPoints->CheckButton1->setChecked(false);
543     }
544     GroupPoints->CheckButton1->setEnabled(isDigit);
545     break;
546   case 1:
547     if (send == GroupDimensions->SpinBox_DX1) {
548       GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
549       if(!isDigit)
550         GroupDimensions->CheckButton1->setChecked(false);
551       GroupDimensions->CheckButton1->setEnabled(isDigit);
552     }
553     else if(send == GroupDimensions->SpinBox_DX2){
554       GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
555       if(!isDigit)
556         GroupDimensions->CheckButton2->setChecked(false);
557       GroupDimensions->CheckButton2->setEnabled(isDigit);
558     }
559     break;
560   }
561 }
562
563 //=================================================================================
564 // function : ValueChangedInSpinBox()
565 // purpose  :
566 //=================================================================================
567 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
568 {
569   QObject* send = (QObject*)sender();
570   switch (getConstructorId()) {
571   case 0:
572     if (send == GroupPoints->SpinBox_DX)
573       myStepU = newValue;
574     break;
575   case 1:
576     if (send == GroupDimensions->SpinBox_DX1)
577       myStepU = newValue;
578     else if (send == GroupDimensions->SpinBox_DX2)
579       myStepV = newValue;
580     break;
581   }
582
583   displayPreview();
584 }
585
586 //=================================================================================
587 // function : ValueChangedInSpinBox()
588 // purpose  :
589 //=================================================================================
590 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
591 {
592   QObject* send = (QObject*)sender();
593   switch (getConstructorId()) {
594   case 0:
595     if (send == GroupPoints->SpinBox_DY)
596       myNbTimesU = newValue;
597     break;
598   case 1:
599     if (send == GroupDimensions->SpinBox_DY1)
600       myNbTimesU = newValue;
601     else if (send == GroupDimensions->SpinBox_DY2)
602       myNbTimesV = newValue;
603     break;
604   }
605
606   displayPreview();
607 }
608
609 //=================================================================================
610 // function : ReverseStepU()
611 // purpose  : 'state' not used here
612 //=================================================================================
613 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
614 {
615   myStepU = -myStepU;
616
617   int aConstructorId = getConstructorId();
618
619   if (aConstructorId == 0)
620     GroupPoints->SpinBox_DX->setValue(myStepU);
621   else if (aConstructorId == 1)
622     GroupDimensions->SpinBox_DX1->setValue(myStepU);
623
624   displayPreview();
625 }
626
627 //=================================================================================
628 // function : ReverseStepV
629 // purpose  : 'state' not used here
630 //=================================================================================
631 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
632 {
633   myStepV = -myStepV;
634
635   GroupDimensions->SpinBox_DX2->setValue(myStepV);
636
637   displayPreview();
638 }
639
640 //=================================================================================
641 // function : createOperation
642 // purpose  :
643 //=================================================================================
644 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
645 {
646   return getGeomEngine()->GetITransformOperations(getStudyId());
647 }
648
649 //=================================================================================
650 // function : isValid
651 // purpose  :
652 //=================================================================================
653 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
654 {
655   int aConstructorId = getConstructorId();
656
657   if (aConstructorId == 0) {
658     bool ok = true;
659     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
660     ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
661     return !(myBase->_is_nil() || myVectorU->_is_nil()) && ok;
662   }
663   else if (aConstructorId == 1) {
664     bool ok = true;
665     ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) && ok;
666     ok = GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) && ok;
667     ok = GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) && ok;
668     ok = GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) && ok;
669     return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil()) && ok;
670   }
671   return 0;
672 }
673
674 //=================================================================================
675 // function : execute
676 // purpose  :
677 //=================================================================================
678 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
679 {
680   bool res = false;
681
682   GEOM::GEOM_Object_var anObj;
683
684   QStringList aParameters;
685
686   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
687
688   switch (getConstructorId()) {
689   case 0:
690     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU)) {
691       createPathPreview ( myVectorU );
692       anObj = anOper->MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
693       if(!IsPreview()) {
694         aParameters<<GroupPoints->SpinBox_DX->text();
695         aParameters<<GroupPoints->SpinBox_DY->text();
696       }
697       res = true;
698     }
699     break;
700   case 1:
701     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU) &&
702         !CORBA::is_nil(myVectorV)) {
703       createPathPreview ( myVectorU );
704       createPathPreview ( myVectorV );
705       anObj = anOper->MultiTranslate2D(myBase,
706                                        myVectorU, myStepU, myNbTimesU,
707                                        myVectorV, myStepV, myNbTimesV);
708       if(!IsPreview()) {
709         aParameters<<GroupDimensions->SpinBox_DX1->text();
710         aParameters<<GroupDimensions->SpinBox_DY1->text();
711         aParameters<<GroupDimensions->SpinBox_DX2->text();
712         aParameters<<GroupDimensions->SpinBox_DY2->text();
713       }
714       res = true;
715     }
716     break;
717   }
718
719   if (!anObj->_is_nil()) {
720     if(!IsPreview())
721       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
722     objects.push_back(anObj._retn());
723   }
724
725   return res;
726 }
727
728 //=================================================================================
729 // function : addSubshapeToStudy
730 // purpose  : virtual method to add new SubObjects if local selection
731 //=================================================================================
732 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
733 {
734   QMap<QString, GEOM::GEOM_Object_var> objMap;
735
736   switch (getConstructorId()) {
737   case 0:
738     objMap[GroupPoints->LineEdit2->text()] = myVectorU;
739     break;
740   case 1:
741     objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
742     objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
743     break;
744   }
745   addSubshapesToFather(objMap);
746 }
747
748 //=================================================================================
749 // function : restoreSubShapes
750 // purpose  :
751 //=================================================================================
752 void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
753                                                               SALOMEDS::SObject_ptr theSObject)
754 {
755   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
756     // we pass here the first operation argument (object) through the list of arguments
757     // because the rotation operation place its arguments in the data structure in another order,
758     // and we need to point the first argument directly
759     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
760     anArgs->length(1);
761     anArgs[0] = myBase;
762     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
763                                         /*theFindMethod=*/GEOM::FSM_MultiTransformed,
764                                         /*theInheritFirstArg=*/true,
765                                         mainFrame()->CheckBoxAddPrefix->isChecked());
766   }
767 }
768
769 //=================================================================================
770 // function : createPathPreview
771 // purpose  :
772 //=================================================================================
773 void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_var thePath )
774 {
775   if ( IsPreview() ) {
776     TopoDS_Shape aShape;
777     GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
778     TopoDS_Edge anEdge = TopoDS::Edge( aShape );
779     ShapeAnalysis_Edge aShapeAnal;
780     TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
781     TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
782     TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
783     const char* aName = "tmpVector";
784     Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
785
786     // add Prs to preview
787     SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
788     SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
789     if (aPrs)
790       aPrs->AddObject(anIO);
791     GEOMBase_Helper::displayPreview( aPrs, false, true );
792   }
793 }