Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.cxx
1 //  Copyright (C) 2007-2008  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   : GenerationGUI_PrismDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
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 <SalomeApp_Notebook.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, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
144   initSpinBox(GroupPoints3->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
145   initSpinBox(GroupPoints3->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
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, 6); // VSR: TODO: DBL_DIGITS_DISPLAY
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 = myBase = 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   if (myInitial) {
283     myInitial = false;
284     SelectionIntoArgument();
285   }
286   else {
287     displayPreview();
288   }
289 }
290
291 //=================================================================================
292 // function : ClickOnOk()
293 // purpose  :
294 //=================================================================================
295 void GenerationGUI_PrismDlg::ClickOnOk()
296 {
297   if (ClickOnApply())
298     ClickOnCancel();
299 }
300
301 //=================================================================================
302 // function : ClickOnApply()
303 // purpose  :
304 //=================================================================================
305 bool GenerationGUI_PrismDlg::ClickOnApply()
306 {
307   if (!onAccept())
308     return false;
309
310   initName();
311   // activate selection and connect selection manager
312   ConstructorsClicked(getConstructorId());
313   return true;
314 }
315
316 //=================================================================================
317 // function : SelectionIntoArgument()
318 // purpose  : Called when selection is changed or on dialog initialization or activation
319 //=================================================================================
320 void GenerationGUI_PrismDlg::SelectionIntoArgument()
321 {
322   erasePreview();
323   myEditCurrentArgument->setText("");
324
325   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
326   SALOME_ListIO aSelList;
327   aSelMgr->selectedObjects(aSelList);
328
329   if (getConstructorId() == 0)
330   {
331     if (aSelList.Extent() != 1) {
332       if (myEditCurrentArgument == GroupPoints->LineEdit1)
333         myOkBase = false;
334       else if (myEditCurrentArgument == GroupPoints->LineEdit2)
335         myOkVec = false;
336       return;
337     }
338
339     // nbSel == 1
340     Standard_Boolean testResult = Standard_False;
341     GEOM::GEOM_Object_var aSelectedObject =
342       GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
343     if (!testResult || CORBA::is_nil(aSelectedObject))
344       return;
345
346     QString aName = GEOMBase::GetName(aSelectedObject);
347
348     // Get Selected object if selected subshape
349     bool myOk = true;
350     TopoDS_Shape aShape;
351     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
352     {
353       TColStd_IndexedMapOfInteger aMap;
354       aSelMgr->GetIndexes(aSelList.First(), aMap);
355       if (aMap.Extent() == 1) {
356         int anIndex = aMap(1);
357         aName.append(":edge_" + QString::number(anIndex));
358
359         //Find SubShape Object in Father
360         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
361
362         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
363           GEOM::GEOM_IShapesOperations_var aShapesOp =
364             getGeomEngine()->GetIShapesOperations(getStudyId());
365           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
366         }
367         else {
368           aSelectedObject = aFindedObject; // get Object from study
369         }
370       }
371       else { // Global Selection
372         if (aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2) {
373           aSelectedObject = GEOM::GEOM_Object::_nil();
374           aName = "";
375           myOk = false;
376         }
377       }
378     }
379
380     myEditCurrentArgument->setText(aName);
381
382     if (myEditCurrentArgument == GroupPoints->LineEdit1) {
383       myBase = aSelectedObject;
384       myOkBase = true;
385       if (!myOkVec)
386         GroupPoints->PushButton2->click();
387     }
388     else if (myEditCurrentArgument == GroupPoints->LineEdit2 && myOk) {
389       myOkVec = true;
390       myVec = aSelectedObject;
391       if (!myOkBase)
392         GroupPoints->PushButton1->click();
393     }
394   }
395   else if (getConstructorId() == 1) { // getConstructorId()==1 - extrusion using 2 points
396     if (aSelList.Extent() != 1) {
397       if (myEditCurrentArgument == GroupPoints2->LineEdit1)
398         myOkBase = false;
399       else 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     // nbSel == 1
411     Standard_Boolean testResult = Standard_False;
412     GEOM::GEOM_Object_var aSelectedObject =
413       GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
414
415     if (!testResult || CORBA::is_nil(aSelectedObject))
416       return;
417
418     QString aName = GEOMBase::GetName(aSelectedObject);
419     TopoDS_Shape aShape;
420     bool myOk = true;
421     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
422       TColStd_IndexedMapOfInteger aMap;
423       aSelMgr->GetIndexes(aSelList.First(), aMap);
424       if (aMap.Extent() == 1) {
425         int anIndex = aMap(1);
426         aName.append(":vertex_" + QString::number(anIndex));
427
428         //Find SubShape Object in Father
429         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
430
431         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
432           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
433           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
434         }
435         else {
436           aSelectedObject = aFindedObject;
437         }
438       }
439       else {
440         if ((aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2) ||
441              (aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3)) {
442           aSelectedObject = GEOM::GEOM_Object::_nil();
443           aName = "";
444           myOk = false;
445         }
446       }
447     }
448
449     myEditCurrentArgument->setText(aName);
450
451     if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
452       myOkBase = true;
453       myBase = aSelectedObject;
454       if (!myOkPnt1)
455         GroupPoints2->PushButton2->click();
456     }
457     else if (myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk) {
458       myOkPnt1 = true;
459       myPoint1 = aSelectedObject;
460       if (!myOkPnt2)
461         GroupPoints2->PushButton3->click();
462     }
463     else if (myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk) {
464       myOkPnt2 = true;
465       myPoint2 = aSelectedObject;
466       if (!myOkBase)
467         GroupPoints2->PushButton1->click();
468     }
469   }
470   else if (getConstructorId() == 2) { // extrusion using dx dy dz
471     Standard_Boolean testResult = Standard_False;
472     GEOM::GEOM_Object_var aSelectedObject =
473       GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
474
475     if (!testResult || CORBA::is_nil(aSelectedObject))
476       return;
477
478     QString aName = GEOMBase::GetName(aSelectedObject);
479     myBase = aSelectedObject;
480     myOkBase = true;
481     myEditCurrentArgument->setText(aName);
482   }
483
484   // clear selection
485   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
486   myGeomGUI->getApp()->selectionMgr()->clearSelected();
487   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
488           this, SLOT(SelectionIntoArgument()));
489
490   displayPreview();
491 }
492
493 //=================================================================================
494 // function : SetEditCurrentArgument()
495 // purpose  :
496 //=================================================================================
497 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
498 {
499   QPushButton* send = (QPushButton*)sender();
500
501   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
502   globalSelection(GEOM_ALLSHAPES);
503   if (send == GroupPoints->PushButton1) {
504     myEditCurrentArgument = GroupPoints->LineEdit1;
505     GroupPoints->PushButton2->setDown(false);
506     GroupPoints->LineEdit2->setEnabled(false);
507   }
508   else if (send == GroupPoints->PushButton2) {
509     myEditCurrentArgument = GroupPoints->LineEdit2;
510     GroupPoints->PushButton1->setDown(false);
511     GroupPoints->LineEdit1->setEnabled(false);
512     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
513   }
514   else if (send == GroupPoints2->PushButton1) {
515     myEditCurrentArgument = GroupPoints2->LineEdit1;
516     GroupPoints2->PushButton2->setDown(false);
517     GroupPoints2->PushButton3->setDown(false);
518     GroupPoints2->LineEdit2->setEnabled(false);
519     GroupPoints2->LineEdit3->setEnabled(false);
520   }
521   else if (send == GroupPoints2->PushButton2) {
522     myEditCurrentArgument = GroupPoints2->LineEdit2;
523     GroupPoints2->PushButton1->setDown(false);
524     GroupPoints2->PushButton3->setDown(false);
525     GroupPoints2->LineEdit1->setEnabled(false);
526     GroupPoints2->LineEdit3->setEnabled(false);
527     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
528   }
529   else if (send == GroupPoints2->PushButton3) {
530     myEditCurrentArgument = GroupPoints2->LineEdit3;
531     GroupPoints2->PushButton1->setDown(false);
532     GroupPoints2->PushButton2->setDown(false);
533     GroupPoints2->LineEdit1->setEnabled(false);
534     GroupPoints2->LineEdit2->setEnabled(false);
535     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
536   }
537   else   if (send == GroupPoints3->PushButton1) {
538     myEditCurrentArgument = GroupPoints3->LineEdit1;
539   }
540   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
541           this, SLOT(SelectionIntoArgument()));
542
543   // enable line edit
544   myEditCurrentArgument->setEnabled(true);
545   myEditCurrentArgument->setFocus();
546   // after setFocus(), because it will be setDown(false) when loses focus
547   send->setDown(true);
548
549   // seems we need it only to avoid preview disappearing, caused by selection mode change
550   displayPreview();
551 }
552
553 //=================================================================================
554 // function : LineEditReturnPressed()
555 // purpose  :
556 //=================================================================================
557 void GenerationGUI_PrismDlg::LineEditReturnPressed()
558 {
559   QLineEdit* send = (QLineEdit*)sender();
560   if (send == GroupPoints->LineEdit1 ||
561       send == GroupPoints->LineEdit2 ||
562       send == GroupPoints2->LineEdit1 ||
563       send == GroupPoints2->LineEdit2 ||
564       send == GroupPoints2->LineEdit3 ||
565       send == GroupPoints3->LineEdit1) {
566     myEditCurrentArgument = send;
567     GEOMBase_Skeleton::LineEditReturnPressed();
568   }
569 }
570
571 //=================================================================================
572 // function : ActivateThisDialog()
573 // purpose  :
574 //=================================================================================
575 void GenerationGUI_PrismDlg::ActivateThisDialog()
576 {
577   GEOMBase_Skeleton::ActivateThisDialog();
578
579   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
580            this, SLOT( SelectionIntoArgument() ) );
581
582   ConstructorsClicked( getConstructorId() );
583 }
584
585 //=================================================================================
586 // function : enterEvent()
587 // purpose  : when mouse enter onto the QWidget
588 //=================================================================================
589 void GenerationGUI_PrismDlg::enterEvent (QEvent*)
590 {
591   if (!mainFrame()->GroupConstructors->isEnabled())
592     ActivateThisDialog();
593 }
594
595 //=================================================================================
596 // function : ValueChangedInSpinBox()
597 // purpose  :
598 //=================================================================================
599 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
600 {
601   displayPreview();
602 }
603
604 //=================================================================================
605 // function : getHeight()
606 // purpose  :
607 //=================================================================================
608 double GenerationGUI_PrismDlg::getHeight() const
609 {
610   return GroupPoints->SpinBox_DX->value();
611 }
612
613 //=================================================================================
614 // function : createOperation
615 // purpose  :
616 //=================================================================================
617 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
618 {
619   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
620 }
621
622 //=================================================================================
623 // function : isValid
624 // purpose  :
625 //=================================================================================
626 bool GenerationGUI_PrismDlg::isValid (QString& msg)
627 {
628   bool ok = true;
629   if( getConstructorId() == 0 )
630     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
631   else if( getConstructorId() == 2 )
632   {
633     ok = GroupPoints3->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
634     ok = GroupPoints3->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
635     ok = GroupPoints3->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
636   }
637
638   if (getConstructorId() == 0)
639     return (myOkBase && myOkVec) && ok;     // by vector and height
640   else if (getConstructorId() == 1)
641     return (myOkBase && myOkPnt1 && myOkPnt2);   // by two points
642   else if (getConstructorId() == 2)
643     return myOkBase && ok;
644
645   return false;
646 }
647
648 //=================================================================================
649 // function : execute
650 // purpose  :
651 //=================================================================================
652 bool GenerationGUI_PrismDlg::execute (ObjectList& objects)
653 {
654   GEOM::GEOM_Object_var anObj;
655
656   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
657
658   switch (getConstructorId()) {
659   case 0:
660     if (!myBothway) {
661       anObj = anOper->MakePrismVecH(myBase, myVec, getHeight());
662     }
663     else {
664       anObj = anOper->MakePrismVecH2Ways(myBase, myVec, getHeight());
665     }
666
667     if (!anObj->_is_nil() && !IsPreview())
668       myNoteBook->setParameters(anObj, 1, GroupPoints->SpinBox_DX );
669
670     break;
671   case 1:
672     if (!myBothway2) {
673       anObj = anOper->MakePrismTwoPnt(myBase, myPoint1, myPoint2);
674     }
675     else {
676       anObj = anOper->MakePrismTwoPnt2Ways(myBase, myPoint1, myPoint2);
677     }
678     break;
679   case 2:
680     double dx = GroupPoints3->SpinBox_DX->value();
681     double dy = GroupPoints3->SpinBox_DY->value();
682     double dz = GroupPoints3->SpinBox_DZ->value();
683
684     if (!myBothway3) {
685       anObj = anOper->MakePrismDXDYDZ(myBase, dx, dy, dz);
686     }
687     else {
688       anObj = anOper->MakePrismDXDYDZ2Ways(myBase, dx, dy, dz);
689     }
690
691     if (!anObj->_is_nil() && !IsPreview())
692       myNoteBook->setParameters(anObj, 3,
693                                 GroupPoints3->SpinBox_DX,
694                                 GroupPoints3->SpinBox_DY,
695                                 GroupPoints3->SpinBox_DZ);
696
697     break;
698   }
699
700   if (!anObj->_is_nil())
701     objects.push_back(anObj._retn());
702
703   return true;
704 }
705
706 //=================================================================================
707 // function : onReverse()
708 // purpose  :
709 //=================================================================================
710 void GenerationGUI_PrismDlg::onReverse()
711 {
712   double anOldValue = GroupPoints->SpinBox_DX->value();
713   GroupPoints->SpinBox_DX->setValue(-anOldValue);
714 }
715
716 //=================================================================================
717 // function : onBothway()
718 // purpose  :
719 //=================================================================================
720 void GenerationGUI_PrismDlg::onBothway()
721 {
722   bool anOldValue;
723   switch (getConstructorId()) {
724   case 0:
725     anOldValue = myBothway;
726     myBothway = !anOldValue;
727     GroupPoints->CheckButton2->setEnabled(!myBothway);
728     displayPreview();
729     break;
730   case 1:
731     anOldValue = myBothway2;
732     myBothway2 = !anOldValue;
733     displayPreview();
734     break;
735   case 2:
736     anOldValue = myBothway3;
737     myBothway3 = !anOldValue;
738     displayPreview();
739     break;
740   }
741 }
742
743 //=================================================================================
744 // function : addSubshapeToStudy
745 // purpose  : virtual method to add new SubObjects if local selection
746 //=================================================================================
747 void GenerationGUI_PrismDlg::addSubshapesToStudy()
748 {
749   QMap<QString, GEOM::GEOM_Object_var> objMap;
750
751   switch (getConstructorId()) {
752   case 0:
753     objMap[GroupPoints->LineEdit2->text()] = myVec;
754     break;
755   case 1:
756     objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
757     objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
758     break;
759   }
760   addSubshapesToFather(objMap);
761 }