Salome HOME
Code refactoring
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.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   : GenerationGUI_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 //
27 #include "GenerationGUI_PrismDlg.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    : GenerationGUI_PrismDlg()
50 // purpose  : Constructs a GenerationGUI_PrismDlg 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 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56                                                 bool modal, Qt::WindowFlags fl)
57   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
58     myInitial(true)
59 {
60   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM")));
62   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_2P")));
64   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_DXDYDZ")));
65
66   setWindowTitle(tr("GEOM_EXTRUSION_TITLE"));
67
68   /***************************************************************/
69   mainFrame()->GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
70   mainFrame()->RadioButton1->setIcon(image0);
71   mainFrame()->RadioButton2->setIcon(image2);
72   mainFrame()->RadioButton3->setIcon(image3);
73
74   mainFrame()->RadioButton1->setChecked(true);
75   myBothway = myBothway2 = myBothway3 = false;
76
77   GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
78   GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
79   GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
80   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
81   GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
82   GroupPoints->PushButton1->setIcon(image1);
83   GroupPoints->PushButton2->setIcon(image1);
84   GroupPoints->LineEdit1->setReadOnly(true);
85   GroupPoints->LineEdit2->setReadOnly(true);
86   GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
87   GroupPoints->CheckButton1->setChecked(myBothway);
88   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
89
90   GroupPoints2 = new DlgRef_3Sel1Check(centralWidget());
91   GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
92   GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
93   GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg(1));
94   GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg(2));
95   GroupPoints2->PushButton1->setIcon(image1);
96   GroupPoints2->PushButton2->setIcon(image1);
97   GroupPoints2->PushButton3->setIcon(image1);
98   GroupPoints2->CheckButton1->setText(tr("GEOM_BOTHWAY"));
99   GroupPoints2->CheckButton1->setChecked(myBothway2);
100
101   GroupPoints3 = new DlgRef_1Sel3Spin1Check(centralWidget());
102   GroupPoints3->GroupBox1->setTitle(tr("GEOM_EXTRUSION_DXDYDZ"));
103   GroupPoints3->TextLabel1->setText(tr("GEOM_BASE"));
104   GroupPoints3->PushButton1->setIcon(image1);
105   GroupPoints3->TextLabel2->setText(tr("GEOM_DX"));
106   GroupPoints3->TextLabel3->setText(tr("GEOM_DY"));
107   GroupPoints3->TextLabel4->setText(tr("GEOM_DZ"));
108   GroupPoints3->CheckButton1->setText(tr("GEOM_BOTHWAY"));
109   GroupPoints3->CheckButton1->setChecked(myBothway3);
110
111   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
112   layout->setMargin(0); layout->setSpacing(6);
113   layout->addWidget(GroupPoints);
114   layout->addWidget(GroupPoints2);
115   layout->addWidget(GroupPoints3);
116   /***************************************************************/
117
118   setHelpFileName("create_extrusion_page.html");
119
120   Init();
121 }
122
123 //=================================================================================
124 // function : ~GenerationGUI_PrismDlg()
125 // purpose  : Destroys the object and frees any allocated resources
126 //=================================================================================
127 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
128 {
129   // no need to delete child widgets, Qt does it all for us
130 }
131
132 //=================================================================================
133 // function : Init()
134 // purpose  :
135 //=================================================================================
136 void GenerationGUI_PrismDlg::Init()
137 {
138   // Get setting of step value from file configuration
139   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
140   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
141
142   // min, max, step and decimals for spin boxes & initial values
143   initSpinBox(GroupPoints3->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
144   initSpinBox(GroupPoints3->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
145   initSpinBox(GroupPoints3->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
146   GroupPoints3->SpinBox_DX->setValue(0.0);
147   GroupPoints3->SpinBox_DY->setValue(0.0);
148   GroupPoints3->SpinBox_DZ->setValue(0.0);
149
150   initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
151   GroupPoints->SpinBox_DX->setValue(100.0);
152
153   // init variables
154   myEditCurrentArgument = GroupPoints->LineEdit1;
155   GroupPoints->LineEdit1->setReadOnly(true);
156   GroupPoints->LineEdit2->setReadOnly(true);
157
158   GroupPoints2->LineEdit1->setReadOnly(true);
159   GroupPoints2->LineEdit2->setReadOnly(true);
160   GroupPoints2->LineEdit3->setReadOnly(true);
161
162   GroupPoints3->LineEdit1->setReadOnly(true);
163
164   GroupPoints->LineEdit1->setText("");
165   GroupPoints->LineEdit2->setText("");
166
167   GroupPoints2->LineEdit1->setText("");
168   GroupPoints2->LineEdit2->setText("");
169   GroupPoints2->LineEdit3->setText("");
170
171   GroupPoints3->LineEdit1->setText("");
172
173   myPoint1 = myPoint2 = myVec = GEOM::GEOM_Object::_nil();
174   myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
175
176   // signals and slots connections
177   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
178   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
179
180   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
181
182   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
183   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
184
185   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
186   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
187
188   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
189   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
190
191   connect(GroupPoints->CheckButton1,  SIGNAL(toggled(bool)), this, SLOT(onBothway()));
192   connect(GroupPoints->CheckButton2,  SIGNAL(toggled(bool)), this, SLOT(onReverse()));
193
194   connect(GroupPoints2->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
195   connect(GroupPoints2->PushButton2,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
196   connect(GroupPoints2->PushButton3,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
197   connect(GroupPoints2->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
198
199   connect(GroupPoints2->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
200   connect(GroupPoints2->LineEdit2,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
201   connect(GroupPoints2->LineEdit3,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
202
203   connect(GroupPoints3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
204   connect(GroupPoints3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
205   connect(GroupPoints3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
206   connect(GroupPoints3->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
207   connect(GroupPoints3->SpinBox_DZ, SIGNAL(valueChanged (double)), this, SLOT(ValueChangedInSpinBox()));
208   connect(GroupPoints3->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
209
210   initName(tr("GEOM_EXTRUSION"));
211
212   ConstructorsClicked(0);
213 }
214
215 //=================================================================================
216 // function : SetDoubleSpinBoxStep()
217 // purpose  : Double spin box management
218 //=================================================================================
219 void GenerationGUI_PrismDlg::SetDoubleSpinBoxStep (double step)
220 {
221   GroupPoints->SpinBox_DX->setSingleStep(step);
222   GroupPoints3->SpinBox_DX->setSingleStep(step);
223   GroupPoints3->SpinBox_DY->setSingleStep(step);
224   GroupPoints3->SpinBox_DZ->setSingleStep(step);
225 }
226
227 //=================================================================================
228 // function : ConstructorsClicked()
229 // purpose  : Radio button management
230 //=================================================================================
231 void GenerationGUI_PrismDlg::ConstructorsClicked (int constructorId)
232 {
233   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
234
235   switch (constructorId) {
236   case 0:
237     {
238       GroupPoints2->hide();
239       GroupPoints3->hide();
240       GroupPoints->show();
241
242       GroupPoints->LineEdit1->setText(GroupPoints2->LineEdit1->text()); // keep base
243       GroupPoints->LineEdit2->setText("");
244       myVec = GEOM::GEOM_Object::_nil();
245       myOkVec = false;
246
247       GroupPoints->PushButton1->click();
248       break;
249     }
250   case 1:
251     {
252       GroupPoints->hide();
253       GroupPoints2->show();
254       GroupPoints3->hide();
255
256       GroupPoints2->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
257       GroupPoints2->LineEdit2->setText("");
258       GroupPoints2->LineEdit3->setText("");
259       myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
260       myOkPnt1 = myOkPnt2 = false;
261
262       GroupPoints2->PushButton1->click();
263       break;
264     }
265   case 2:
266     {
267       GroupPoints->hide();
268       GroupPoints2->hide();
269       GroupPoints3->show();
270
271       GroupPoints3->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
272
273       GroupPoints3->PushButton1->click();
274       break;
275     }
276   }
277
278   qApp->processEvents();
279   updateGeometry();
280   resize(minimumSizeHint());
281
282   SelectionIntoArgument();
283   displayPreview();
284 }
285
286 //=================================================================================
287 // function : ClickOnOk()
288 // purpose  :
289 //=================================================================================
290 void GenerationGUI_PrismDlg::ClickOnOk()
291 {
292   if (ClickOnApply())
293     ClickOnCancel();
294 }
295
296 //=================================================================================
297 // function : ClickOnApply()
298 // purpose  :
299 //=================================================================================
300 bool GenerationGUI_PrismDlg::ClickOnApply()
301 {
302   if (!onAccept())
303     return false;
304
305   initName();
306   // activate selection and connect selection manager
307   ConstructorsClicked(getConstructorId());
308   return true;
309 }
310
311 //=================================================================================
312 // function : SelectionIntoArgument()
313 // purpose  : Called when selection is changed or on dialog initialization or activation
314 //=================================================================================
315 void GenerationGUI_PrismDlg::SelectionIntoArgument()
316 {
317   erasePreview();
318   myEditCurrentArgument->setText("");
319
320   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
321   SALOME_ListIO aSelList;
322   aSelMgr->selectedObjects(aSelList);
323
324   QString aBaseName = ""; /* name of base object selection */
325   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aBaseName, true);
326
327   if (nbSel > 1)
328     aBaseName = QString( "%1_objects").arg( nbSel );
329
330   // Base Object(s) selected
331   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
332       myEditCurrentArgument == GroupPoints2->LineEdit1 ||
333       getConstructorId() == 2 ) {
334     myOkBase = false;
335     if ( nbSel > 0 ) {
336       GEOMBase::ConvertListOfIOInListOfGO(aSelList, myBaseObjects, true);
337       myEditCurrentArgument->setText( aBaseName );
338       myOkBase = true;
339     }
340     displayPreview();
341     return;
342   }
343
344   if (getConstructorId() == 0)
345   {
346     if (aSelList.Extent() < 1) {
347       if (myEditCurrentArgument == GroupPoints->LineEdit2)
348         myOkVec = false;
349       return;
350     }
351
352     GEOM::GEOM_Object_var aSelectedObject =
353       GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
354     if ( CORBA::is_nil(aSelectedObject) )
355       return;
356
357     QString aName = GEOMBase::GetName(aSelectedObject);
358
359     // Get Selected object if selected subshape
360     bool myOk = true;
361     TopoDS_Shape aShape;
362     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
363     {
364       TColStd_IndexedMapOfInteger aMap;
365       aSelMgr->GetIndexes(aSelList.First(), aMap);
366       if (aMap.Extent() == 1) {
367         int anIndex = aMap(1);
368         aName.append(":edge_" + QString::number(anIndex));
369
370         //Find SubShape Object in Father
371         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
372
373         if (aFindedObject->_is_nil()) { // Object not found in study
374           GEOM::GEOM_IShapesOperations_var aShapesOp =
375             getGeomEngine()->GetIShapesOperations(getStudyId());
376           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
377         }
378         else {
379           aSelectedObject = aFindedObject; // get Object from study
380         }
381       }
382       else { // Global Selection
383         if (aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2) {
384           aSelectedObject = GEOM::GEOM_Object::_nil();
385           aName = "";
386           myOk = false;
387         }
388       }
389     }
390
391     if (myEditCurrentArgument == GroupPoints->LineEdit2 && myOk) {
392       myEditCurrentArgument->setText(aName);
393       myOkVec = true;
394       myVec = aSelectedObject;
395     }
396   }
397   else if (getConstructorId() == 1) { // getConstructorId()==1 - extrusion using 2 points
398     if (aSelList.Extent() != 1) {
399       if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
400         myPoint1 = GEOM::GEOM_Object::_nil();
401         myOkPnt1 = false;
402       }
403       else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
404         myPoint2 = GEOM::GEOM_Object::_nil();
405         myOkPnt2 = false;
406       }
407       return;
408     }
409
410     GEOM::GEOM_Object_var aSelectedObject =
411       GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
412
413     if ( CORBA::is_nil(aSelectedObject) )
414       return;
415
416     QString aName = GEOMBase::GetName(aSelectedObject);
417     TopoDS_Shape aShape;
418     bool myOk = true;
419     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
420       TColStd_IndexedMapOfInteger aMap;
421       aSelMgr->GetIndexes(aSelList.First(), aMap);
422       if (aMap.Extent() == 1) {
423         int anIndex = aMap(1);
424         aName.append(":vertex_" + QString::number(anIndex));
425
426         //Find SubShape Object in Father
427         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
428
429         if (aFindedObject->_is_nil()) { // Object not found in study
430           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
431           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
432         }
433         else {
434           aSelectedObject = aFindedObject;
435         }
436       }
437       else {
438         if ((aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2) ||
439              (aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3)) {
440           aSelectedObject = GEOM::GEOM_Object::_nil();
441           aName = "";
442           myOk = false;
443         }
444       }
445     }
446
447     myEditCurrentArgument->setText(aName);
448
449     if (myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk) {
450       myOkPnt1 = true;
451       myPoint1 = aSelectedObject;
452       if (!myOkPnt2)
453         GroupPoints2->PushButton3->click();
454     }
455     else if (myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk) {
456       myOkPnt2 = true;
457       myPoint2 = aSelectedObject;
458       if (!myOkBase)
459         GroupPoints2->PushButton1->click();
460     }
461   }
462
463   displayPreview();
464 }
465
466 //=================================================================================
467 // function : SetEditCurrentArgument()
468 // purpose  :
469 //=================================================================================
470 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
471 {
472   QPushButton* send = (QPushButton*)sender();
473
474   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
475   globalSelection(GEOM_ALLSHAPES);
476   if (send == GroupPoints->PushButton1) {
477     myEditCurrentArgument = GroupPoints->LineEdit1;
478     GroupPoints->PushButton2->setDown(false);
479     GroupPoints->LineEdit2->setEnabled(false);
480   }
481   else if (send == GroupPoints->PushButton2) {
482     myEditCurrentArgument = GroupPoints->LineEdit2;
483     GroupPoints->PushButton1->setDown(false);
484     GroupPoints->LineEdit1->setEnabled(false);
485     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
486   }
487   else if (send == GroupPoints2->PushButton1) {
488     myEditCurrentArgument = GroupPoints2->LineEdit1;
489     GroupPoints2->PushButton2->setDown(false);
490     GroupPoints2->PushButton3->setDown(false);
491     GroupPoints2->LineEdit2->setEnabled(false);
492     GroupPoints2->LineEdit3->setEnabled(false);
493   }
494   else if (send == GroupPoints2->PushButton2) {
495     myEditCurrentArgument = GroupPoints2->LineEdit2;
496     GroupPoints2->PushButton1->setDown(false);
497     GroupPoints2->PushButton3->setDown(false);
498     GroupPoints2->LineEdit1->setEnabled(false);
499     GroupPoints2->LineEdit3->setEnabled(false);
500     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
501   }
502   else if (send == GroupPoints2->PushButton3) {
503     myEditCurrentArgument = GroupPoints2->LineEdit3;
504     GroupPoints2->PushButton1->setDown(false);
505     GroupPoints2->PushButton2->setDown(false);
506     GroupPoints2->LineEdit1->setEnabled(false);
507     GroupPoints2->LineEdit2->setEnabled(false);
508     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
509   }
510   else   if (send == GroupPoints3->PushButton1) {
511     myEditCurrentArgument = GroupPoints3->LineEdit1;
512   }
513   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
514           this, SLOT(SelectionIntoArgument()));
515
516   // enable line edit
517   myEditCurrentArgument->setEnabled(true);
518   myEditCurrentArgument->setFocus();
519   // after setFocus(), because it will be setDown(false) when loses focus
520   send->setDown(true);
521
522   // seems we need it only to avoid preview disappearing, caused by selection mode change
523   displayPreview();
524 }
525
526 //=================================================================================
527 // function : LineEditReturnPressed()
528 // purpose  :
529 //=================================================================================
530 void GenerationGUI_PrismDlg::LineEditReturnPressed()
531 {
532   QLineEdit* send = (QLineEdit*)sender();
533   if (send == GroupPoints->LineEdit1 ||
534       send == GroupPoints->LineEdit2 ||
535       send == GroupPoints2->LineEdit1 ||
536       send == GroupPoints2->LineEdit2 ||
537       send == GroupPoints2->LineEdit3 ||
538       send == GroupPoints3->LineEdit1) {
539     myEditCurrentArgument = send;
540     GEOMBase_Skeleton::LineEditReturnPressed();
541   }
542 }
543
544 //=================================================================================
545 // function : ActivateThisDialog()
546 // purpose  :
547 //=================================================================================
548 void GenerationGUI_PrismDlg::ActivateThisDialog()
549 {
550   GEOMBase_Skeleton::ActivateThisDialog();
551
552   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
553            this, SLOT( SelectionIntoArgument() ) );
554
555   ConstructorsClicked( getConstructorId() );
556 }
557
558 //=================================================================================
559 // function : enterEvent()
560 // purpose  : when mouse enter onto the QWidget
561 //=================================================================================
562 void GenerationGUI_PrismDlg::enterEvent (QEvent*)
563 {
564   if (!mainFrame()->GroupConstructors->isEnabled())
565     ActivateThisDialog();
566 }
567
568 //=================================================================================
569 // function : ValueChangedInSpinBox()
570 // purpose  :
571 //=================================================================================
572 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
573 {
574   displayPreview();
575 }
576
577 //=================================================================================
578 // function : getHeight()
579 // purpose  :
580 //=================================================================================
581 double GenerationGUI_PrismDlg::getHeight() const
582 {
583   return GroupPoints->SpinBox_DX->value();
584 }
585
586 //=================================================================================
587 // function : createOperation
588 // purpose  :
589 //=================================================================================
590 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
591 {
592   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
593 }
594
595 //=================================================================================
596 // function : isValid
597 // purpose  :
598 //=================================================================================
599 bool GenerationGUI_PrismDlg::isValid (QString& msg)
600 {
601   bool ok = true;
602   if( getConstructorId() == 0 )
603     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
604   else if( getConstructorId() == 2 )
605   {
606     ok = GroupPoints3->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
607     ok = GroupPoints3->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
608     ok = GroupPoints3->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
609   }
610
611   if (getConstructorId() == 0)
612     return (myOkBase && myOkVec) && ok;     // by vector and height
613   else if (getConstructorId() == 1)
614     return (myOkBase && myOkPnt1 && myOkPnt2);   // by two points
615   else if (getConstructorId() == 2)
616     return myOkBase && ok;
617
618   return false;
619 }
620
621 //=================================================================================
622 // function : execute
623 // purpose  :
624 //=================================================================================
625 bool GenerationGUI_PrismDlg::execute (ObjectList& objects)
626 {
627   QStringList aParameters;
628   GEOM::GEOM_Object_var anObj, aBaseObj;
629
630   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
631
632   for (int i=0; i < myBaseObjects.length(); i++) {
633     aBaseObj = myBaseObjects[i];
634     
635     switch (getConstructorId()) {
636     case 0:
637       if (!myBothway)
638         anObj = anOper->MakePrismVecH(aBaseObj, myVec, getHeight());
639       else
640         anObj = anOper->MakePrismVecH2Ways(aBaseObj, myVec, getHeight());
641       
642       if (!anObj->_is_nil() && !IsPreview()) {
643         aParameters << GroupPoints->SpinBox_DX->text();
644         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
645       }
646       break;
647     case 1:
648       if (!myBothway2)
649         anObj = anOper->MakePrismTwoPnt(aBaseObj, myPoint1, myPoint2);
650       else
651         anObj = anOper->MakePrismTwoPnt2Ways(aBaseObj, myPoint1, myPoint2);
652       break;
653     case 2:
654       double dx = GroupPoints3->SpinBox_DX->value();
655       double dy = GroupPoints3->SpinBox_DY->value();
656       double dz = GroupPoints3->SpinBox_DZ->value();
657       
658       if (!myBothway3)
659         anObj = anOper->MakePrismDXDYDZ(aBaseObj, dx, dy, dz);
660       else
661         anObj = anOper->MakePrismDXDYDZ2Ways(aBaseObj, dx, dy, dz);
662       
663       if (!anObj->_is_nil() && !IsPreview()) {
664         aParameters << GroupPoints3->SpinBox_DX->text();
665         aParameters << GroupPoints3->SpinBox_DY->text();
666         aParameters << GroupPoints3->SpinBox_DZ->text();
667         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
668       }
669       break;
670     }
671     
672     if (!anObj->_is_nil())
673       objects.push_back(anObj._retn());
674   }
675   
676   return true;
677 }
678
679 //=================================================================================
680 // function : onReverse()
681 // purpose  :
682 //=================================================================================
683 void GenerationGUI_PrismDlg::onReverse()
684 {
685   double anOldValue = GroupPoints->SpinBox_DX->value();
686   GroupPoints->SpinBox_DX->setValue(-anOldValue);
687 }
688
689 //=================================================================================
690 // function : onBothway()
691 // purpose  :
692 //=================================================================================
693 void GenerationGUI_PrismDlg::onBothway()
694 {
695   bool anOldValue;
696   switch (getConstructorId()) {
697   case 0:
698     anOldValue = myBothway;
699     myBothway = !anOldValue;
700     GroupPoints->CheckButton2->setEnabled(!myBothway);
701     displayPreview();
702     break;
703   case 1:
704     anOldValue = myBothway2;
705     myBothway2 = !anOldValue;
706     displayPreview();
707     break;
708   case 2:
709     anOldValue = myBothway3;
710     myBothway3 = !anOldValue;
711     displayPreview();
712     break;
713   }
714 }
715
716 //=================================================================================
717 // function : addSubshapeToStudy
718 // purpose  : virtual method to add new SubObjects if local selection
719 //=================================================================================
720 void GenerationGUI_PrismDlg::addSubshapesToStudy()
721 {
722   QMap<QString, GEOM::GEOM_Object_var> objMap;
723
724   switch (getConstructorId()) {
725   case 0:
726     objMap[GroupPoints->LineEdit2->text()] = myVec;
727     break;
728   case 1:
729     objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
730     objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
731     break;
732   }
733   addSubshapesToFather(objMap);
734 }
735
736 //=================================================================================
737 // function : extractPrefix
738 // purpose  : redefined from GEOMBase_Helper class
739 //=================================================================================
740 bool GenerationGUI_PrismDlg::extractPrefix() const
741 {
742   return myBaseObjects.length() > 1;
743 }