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