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