Salome HOME
Changes for 0020673 - Implementation of "Auto-correct edges orientation".
[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 <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, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
143   initSpinBox(GroupPoints3->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
144   initSpinBox(GroupPoints3->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6); // 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, 6); // 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 = 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(minimumSizeHint());
280
281   SelectionIntoArgument();
282   displayPreview();
283 }
284
285 //=================================================================================
286 // function : ClickOnOk()
287 // purpose  :
288 //=================================================================================
289 void GenerationGUI_PrismDlg::ClickOnOk()
290 {
291   if (ClickOnApply())
292     ClickOnCancel();
293 }
294
295 //=================================================================================
296 // function : ClickOnApply()
297 // purpose  :
298 //=================================================================================
299 bool GenerationGUI_PrismDlg::ClickOnApply()
300 {
301   if (!onAccept())
302     return false;
303
304   initName();
305   // activate selection and connect selection manager
306   ConstructorsClicked(getConstructorId());
307   return true;
308 }
309
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose  : Called when selection is changed or on dialog initialization or activation
313 //=================================================================================
314 void GenerationGUI_PrismDlg::SelectionIntoArgument()
315 {
316   erasePreview();
317   myEditCurrentArgument->setText("");
318
319   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
320   SALOME_ListIO aSelList;
321   aSelMgr->selectedObjects(aSelList);
322
323   QString aBaseName = ""; /* name of base object selection */
324   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aBaseName, true);
325
326   if (nbSel > 1)
327     aBaseName = QString( "%1_objects").arg( nbSel );
328
329   // Base Object(s) selected
330   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
331       myEditCurrentArgument == GroupPoints2->LineEdit1 ||
332       getConstructorId() == 2 ) {
333     myOkBase = false;
334     if ( nbSel > 0 ) {
335       GEOMBase::ConvertListOfIOInListOfGO(aSelList, myBaseObjects, true);
336       myEditCurrentArgument->setText( aBaseName );
337       myOkBase = true;
338     }
339     displayPreview();
340     return;
341   }
342
343   if (getConstructorId() == 0)
344   {
345     if (aSelList.Extent() < 1) {
346       if (myEditCurrentArgument == GroupPoints->LineEdit2)
347         myOkVec = false;
348       return;
349     }
350
351     Standard_Boolean testResult = Standard_False;
352     GEOM::GEOM_Object_var aSelectedObject =
353       GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
354     if (!testResult || 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 == GEOM::GEOM_Object::_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     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->LineEdit2 && myOk) {
451       myOkPnt1 = true;
452       myPoint1 = aSelectedObject;
453       if (!myOkPnt2)
454         GroupPoints2->PushButton3->click();
455     }
456     else if (myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk) {
457       myOkPnt2 = true;
458       myPoint2 = aSelectedObject;
459       if (!myOkBase)
460         GroupPoints2->PushButton1->click();
461     }
462   }
463
464   displayPreview();
465 }
466
467 //=================================================================================
468 // function : SetEditCurrentArgument()
469 // purpose  :
470 //=================================================================================
471 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
472 {
473   QPushButton* send = (QPushButton*)sender();
474
475   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
476   globalSelection(GEOM_ALLSHAPES);
477   if (send == GroupPoints->PushButton1) {
478     myEditCurrentArgument = GroupPoints->LineEdit1;
479     GroupPoints->PushButton2->setDown(false);
480     GroupPoints->LineEdit2->setEnabled(false);
481   }
482   else if (send == GroupPoints->PushButton2) {
483     myEditCurrentArgument = GroupPoints->LineEdit2;
484     GroupPoints->PushButton1->setDown(false);
485     GroupPoints->LineEdit1->setEnabled(false);
486     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
487   }
488   else if (send == GroupPoints2->PushButton1) {
489     myEditCurrentArgument = GroupPoints2->LineEdit1;
490     GroupPoints2->PushButton2->setDown(false);
491     GroupPoints2->PushButton3->setDown(false);
492     GroupPoints2->LineEdit2->setEnabled(false);
493     GroupPoints2->LineEdit3->setEnabled(false);
494   }
495   else if (send == GroupPoints2->PushButton2) {
496     myEditCurrentArgument = GroupPoints2->LineEdit2;
497     GroupPoints2->PushButton1->setDown(false);
498     GroupPoints2->PushButton3->setDown(false);
499     GroupPoints2->LineEdit1->setEnabled(false);
500     GroupPoints2->LineEdit3->setEnabled(false);
501     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
502   }
503   else if (send == GroupPoints2->PushButton3) {
504     myEditCurrentArgument = GroupPoints2->LineEdit3;
505     GroupPoints2->PushButton1->setDown(false);
506     GroupPoints2->PushButton2->setDown(false);
507     GroupPoints2->LineEdit1->setEnabled(false);
508     GroupPoints2->LineEdit2->setEnabled(false);
509     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
510   }
511   else   if (send == GroupPoints3->PushButton1) {
512     myEditCurrentArgument = GroupPoints3->LineEdit1;
513   }
514   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
515           this, SLOT(SelectionIntoArgument()));
516
517   // enable line edit
518   myEditCurrentArgument->setEnabled(true);
519   myEditCurrentArgument->setFocus();
520   // after setFocus(), because it will be setDown(false) when loses focus
521   send->setDown(true);
522
523   // seems we need it only to avoid preview disappearing, caused by selection mode change
524   displayPreview();
525 }
526
527 //=================================================================================
528 // function : LineEditReturnPressed()
529 // purpose  :
530 //=================================================================================
531 void GenerationGUI_PrismDlg::LineEditReturnPressed()
532 {
533   QLineEdit* send = (QLineEdit*)sender();
534   if (send == GroupPoints->LineEdit1 ||
535       send == GroupPoints->LineEdit2 ||
536       send == GroupPoints2->LineEdit1 ||
537       send == GroupPoints2->LineEdit2 ||
538       send == GroupPoints2->LineEdit3 ||
539       send == GroupPoints3->LineEdit1) {
540     myEditCurrentArgument = send;
541     GEOMBase_Skeleton::LineEditReturnPressed();
542   }
543 }
544
545 //=================================================================================
546 // function : ActivateThisDialog()
547 // purpose  :
548 //=================================================================================
549 void GenerationGUI_PrismDlg::ActivateThisDialog()
550 {
551   GEOMBase_Skeleton::ActivateThisDialog();
552
553   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
554            this, SLOT( SelectionIntoArgument() ) );
555
556   ConstructorsClicked( getConstructorId() );
557 }
558
559 //=================================================================================
560 // function : enterEvent()
561 // purpose  : when mouse enter onto the QWidget
562 //=================================================================================
563 void GenerationGUI_PrismDlg::enterEvent (QEvent*)
564 {
565   if (!mainFrame()->GroupConstructors->isEnabled())
566     ActivateThisDialog();
567 }
568
569 //=================================================================================
570 // function : ValueChangedInSpinBox()
571 // purpose  :
572 //=================================================================================
573 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
574 {
575   displayPreview();
576 }
577
578 //=================================================================================
579 // function : getHeight()
580 // purpose  :
581 //=================================================================================
582 double GenerationGUI_PrismDlg::getHeight() const
583 {
584   return GroupPoints->SpinBox_DX->value();
585 }
586
587 //=================================================================================
588 // function : createOperation
589 // purpose  :
590 //=================================================================================
591 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
592 {
593   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
594 }
595
596 //=================================================================================
597 // function : isValid
598 // purpose  :
599 //=================================================================================
600 bool GenerationGUI_PrismDlg::isValid (QString& msg)
601 {
602   bool ok = true;
603   if( getConstructorId() == 0 )
604     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
605   else if( getConstructorId() == 2 )
606   {
607     ok = GroupPoints3->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
608     ok = GroupPoints3->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
609     ok = GroupPoints3->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
610   }
611
612   if (getConstructorId() == 0)
613     return (myOkBase && myOkVec) && ok;     // by vector and height
614   else if (getConstructorId() == 1)
615     return (myOkBase && myOkPnt1 && myOkPnt2);   // by two points
616   else if (getConstructorId() == 2)
617     return myOkBase && ok;
618
619   return false;
620 }
621
622 //=================================================================================
623 // function : execute
624 // purpose  :
625 //=================================================================================
626 bool GenerationGUI_PrismDlg::execute (ObjectList& objects)
627 {
628   QStringList aParameters;
629   GEOM::GEOM_Object_var anObj, aBaseObj;
630
631   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
632
633   for (int i=0; i < myBaseObjects.length(); i++) {
634     aBaseObj = myBaseObjects[i];
635     
636     switch (getConstructorId()) {
637     case 0:
638       if (!myBothway)
639         anObj = anOper->MakePrismVecH(aBaseObj, myVec, getHeight());
640       else
641         anObj = anOper->MakePrismVecH2Ways(aBaseObj, myVec, getHeight());
642       
643       if (!anObj->_is_nil() && !IsPreview()) {
644         aParameters << GroupPoints->SpinBox_DX->text();
645         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
646       }
647       break;
648     case 1:
649       if (!myBothway2)
650         anObj = anOper->MakePrismTwoPnt(aBaseObj, myPoint1, myPoint2);
651       else
652         anObj = anOper->MakePrismTwoPnt2Ways(aBaseObj, myPoint1, myPoint2);
653       break;
654     case 2:
655       double dx = GroupPoints3->SpinBox_DX->value();
656       double dy = GroupPoints3->SpinBox_DY->value();
657       double dz = GroupPoints3->SpinBox_DZ->value();
658       
659       if (!myBothway3)
660         anObj = anOper->MakePrismDXDYDZ(aBaseObj, dx, dy, dz);
661       else
662         anObj = anOper->MakePrismDXDYDZ2Ways(aBaseObj, dx, dy, dz);
663       
664       if (!anObj->_is_nil() && !IsPreview()) {
665         aParameters << GroupPoints3->SpinBox_DX->text();
666         aParameters << GroupPoints3->SpinBox_DY->text();
667         aParameters << GroupPoints3->SpinBox_DZ->text();
668         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
669       }
670       break;
671     }
672     
673     if (!anObj->_is_nil())
674       objects.push_back(anObj._retn());
675   }
676   
677   return true;
678 }
679
680 //=================================================================================
681 // function : onReverse()
682 // purpose  :
683 //=================================================================================
684 void GenerationGUI_PrismDlg::onReverse()
685 {
686   double anOldValue = GroupPoints->SpinBox_DX->value();
687   GroupPoints->SpinBox_DX->setValue(-anOldValue);
688 }
689
690 //=================================================================================
691 // function : onBothway()
692 // purpose  :
693 //=================================================================================
694 void GenerationGUI_PrismDlg::onBothway()
695 {
696   bool anOldValue;
697   switch (getConstructorId()) {
698   case 0:
699     anOldValue = myBothway;
700     myBothway = !anOldValue;
701     GroupPoints->CheckButton2->setEnabled(!myBothway);
702     displayPreview();
703     break;
704   case 1:
705     anOldValue = myBothway2;
706     myBothway2 = !anOldValue;
707     displayPreview();
708     break;
709   case 2:
710     anOldValue = myBothway3;
711     myBothway3 = !anOldValue;
712     displayPreview();
713     break;
714   }
715 }
716
717 //=================================================================================
718 // function : addSubshapeToStudy
719 // purpose  : virtual method to add new SubObjects if local selection
720 //=================================================================================
721 void GenerationGUI_PrismDlg::addSubshapesToStudy()
722 {
723   QMap<QString, GEOM::GEOM_Object_var> objMap;
724
725   switch (getConstructorId()) {
726   case 0:
727     objMap[GroupPoints->LineEdit2->text()] = myVec;
728     break;
729   case 1:
730     objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
731     objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
732     break;
733   }
734   addSubshapesToFather(objMap);
735 }
736
737 //=================================================================================
738 // function : extractPrefix
739 // purpose  : redefined from GEOMBase_Helper class
740 //=================================================================================
741 bool GenerationGUI_PrismDlg::extractPrefix() const
742 {
743   return myBaseObjects.length() > 1;
744 }