Salome HOME
Mantis issue 0021565: [CEA 557] Opposite of the pipe
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.cxx
1 // Copyright (C) 2007-2012  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 #include <Precision.hxx>
46
47 #include <GEOMImpl_Types.hxx>
48
49 //=================================================================================
50 // class    : GenerationGUI_PrismDlg()
51 // purpose  : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
52 //            name 'name' and widget flags set to 'f'.
53 //            The dialog will by default be modeless, unless you set 'modal' to
54 //            TRUE to construct a modal dialog.
55 //=================================================================================
56 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
57                                                 bool modal, Qt::WindowFlags fl)
58   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
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
76   GroupVecH = new DlgRef_2Sel1Spin3Check1Spin(centralWidget());
77   GroupVecH->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
78   GroupVecH->TextLabel1->setText(tr("GEOM_BASE"));
79   GroupVecH->TextLabel2->setText(tr("GEOM_VECTOR"));
80   GroupVecH->TextLabel3->setText(tr("GEOM_HEIGHT"));
81   GroupVecH->TextLabel4->setText(tr("GEOM_SCALE_FACTOR"));
82   GroupVecH->PushButton1->setIcon(image1);
83   GroupVecH->PushButton2->setIcon(image1);
84   GroupVecH->LineEdit1->setReadOnly(true);
85   GroupVecH->LineEdit2->setReadOnly(true);
86   GroupVecH->CheckBox1->setText(tr("GEOM_BOTHWAY"));
87   GroupVecH->CheckBox2->setText(tr("GEOM_REVERSE"));
88   GroupVecH->CheckBox3->setText(tr("GEOM_SCALE_PRISM"));
89
90   Group2Points = new DlgRef_3Sel2Check3Spin(centralWidget());
91   Group2Points->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
92   Group2Points->TextLabel1->setText(tr("GEOM_BASE"));
93   Group2Points->TextLabel2->setText(tr("GEOM_POINT_I").arg(1));
94   Group2Points->TextLabel3->setText(tr("GEOM_POINT_I").arg(2));
95   Group2Points->TextLabel4->setText(tr("GEOM_SCALE_FACTOR"));
96   Group2Points->PushButton1->setIcon(image1);
97   Group2Points->PushButton2->setIcon(image1);
98   Group2Points->PushButton3->setIcon(image1);
99   Group2Points->CheckBox1->setText(tr("GEOM_BOTHWAY"));
100   Group2Points->CheckBox2->setText(tr("GEOM_SCALE_PRISM"));
101
102   GroupDXDYDZ = new DlgRef_1Sel3Spin2Check1Spin(centralWidget());
103   GroupDXDYDZ->GroupBox1->setTitle(tr("GEOM_EXTRUSION_DXDYDZ"));
104   GroupDXDYDZ->TextLabel1->setText(tr("GEOM_BASE"));
105   GroupDXDYDZ->PushButton1->setIcon(image1);
106   GroupDXDYDZ->TextLabel2->setText(tr("GEOM_DX"));
107   GroupDXDYDZ->TextLabel3->setText(tr("GEOM_DY"));
108   GroupDXDYDZ->TextLabel4->setText(tr("GEOM_DZ"));
109   GroupDXDYDZ->TextLabel5->setText(tr("GEOM_SCALE_FACTOR"));
110   GroupDXDYDZ->CheckBox1->setText(tr("GEOM_BOTHWAY"));
111   GroupDXDYDZ->CheckBox2->setText(tr("GEOM_SCALE_PRISM"));
112
113   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
114   layout->setMargin(0); layout->setSpacing(6);
115   layout->addWidget(GroupVecH);
116   layout->addWidget(Group2Points);
117   layout->addWidget(GroupDXDYDZ);
118   /***************************************************************/
119
120   setHelpFileName("create_extrusion_page.html");
121
122   Init();
123 }
124
125 //=================================================================================
126 // function : ~GenerationGUI_PrismDlg()
127 // purpose  : Destroys the object and frees any allocated resources
128 //=================================================================================
129 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
130 {
131   // no need to delete child widgets, Qt does it all for us
132 }
133
134 //=================================================================================
135 // function : Init()
136 // purpose  :
137 //=================================================================================
138 void GenerationGUI_PrismDlg::Init()
139 {
140   // Get setting of step value from file configuration
141   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
143
144   // min, max, step and decimals for spin boxes & initial values
145   double aScaleFactor = 2.0;
146   double aScaleStep = 0.5;
147   double aScaleMin = Precision::Confusion() * 10.0;
148
149   initSpinBox(GroupVecH->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
150   GroupVecH->SpinBox_DX->setValue(100.0);
151
152   initSpinBox(GroupDXDYDZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
153   initSpinBox(GroupDXDYDZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
154   initSpinBox(GroupDXDYDZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
155   GroupDXDYDZ->SpinBox_DX->setValue(0.0);
156   GroupDXDYDZ->SpinBox_DY->setValue(0.0);
157   GroupDXDYDZ->SpinBox_DZ->setValue(0.0);
158
159   initSpinBox(GroupVecH->SpinBox_DY, aScaleMin, COORD_MAX, aScaleStep, "parametric_precision" );
160   initSpinBox(Group2Points->SpinBox1, aScaleMin, COORD_MAX, aScaleStep, "parametric_precision" );
161   initSpinBox(GroupDXDYDZ->SpinBox_SC, aScaleMin, COORD_MAX, aScaleStep, "parametric_precision" );
162
163   GroupVecH->SpinBox_DY->setValue(aScaleFactor);
164   Group2Points->SpinBox1->setValue(aScaleFactor);
165   GroupDXDYDZ->SpinBox_SC->setValue(aScaleFactor);
166
167   // hide not used controls
168   Group2Points->TextLabel5->hide();
169   Group2Points->TextLabel6->hide();
170
171   Group2Points->SpinBox2->hide();
172   Group2Points->SpinBox3->hide();
173
174   // init variables
175   myEditCurrentArgument = GroupVecH->LineEdit1;
176   GroupVecH->LineEdit1->setReadOnly(true);
177   GroupVecH->LineEdit2->setReadOnly(true);
178
179   Group2Points->LineEdit1->setReadOnly(true);
180   Group2Points->LineEdit2->setReadOnly(true);
181   Group2Points->LineEdit3->setReadOnly(true);
182
183   GroupDXDYDZ->LineEdit1->setReadOnly(true);
184
185   GroupVecH->LineEdit1->setText("");
186   GroupVecH->LineEdit2->setText("");
187
188   Group2Points->LineEdit1->setText("");
189   Group2Points->LineEdit2->setText("");
190   Group2Points->LineEdit3->setText("");
191
192   GroupDXDYDZ->LineEdit1->setText("");
193
194   myBaseObjects.clear();
195   myPoint1.nullify();
196   myPoint2.nullify();
197   myVec.nullify();
198
199   showOnlyPreviewControl();
200     
201   // signals and slots connections
202   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
203   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
204
205   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
206
207   connect(GroupVecH->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
208   connect(GroupVecH->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
209
210   connect(GroupVecH->SpinBox_DX, SIGNAL(valueChanged(double)),    this, SLOT(ValueChangedInSpinBox()));
211   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
212
213   connect(GroupVecH->CheckBox1,  SIGNAL(toggled(bool)), this, SLOT(onBothway()));
214   connect(GroupVecH->CheckBox2,  SIGNAL(toggled(bool)), this, SLOT(onReverse()));
215   connect(GroupVecH->CheckBox3,  SIGNAL(toggled(bool)), this, SLOT(onScalePrism()));
216   connect(GroupVecH->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
217
218   connect(Group2Points->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
219   connect(Group2Points->PushButton2, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
220   connect(Group2Points->PushButton3, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
221   connect(Group2Points->CheckBox1,   SIGNAL(toggled(bool)),   this, SLOT(onBothway()));
222   connect(Group2Points->CheckBox2,   SIGNAL(toggled(bool)),   this, SLOT(onScalePrism()));
223   connect(Group2Points->SpinBox1,    SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
224
225   connect(GroupDXDYDZ->PushButton1, SIGNAL(clicked()),            this, SLOT(SetEditCurrentArgument()));
226   connect(GroupDXDYDZ->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
227   connect(GroupDXDYDZ->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
228   connect(GroupDXDYDZ->SpinBox_DZ,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
229   connect(GroupDXDYDZ->SpinBox_SC,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
230   connect(GroupDXDYDZ->CheckBox1,   SIGNAL(toggled(bool)),        this, SLOT(onBothway()));
231   connect(GroupDXDYDZ->CheckBox2,   SIGNAL(toggled(bool)),        this, SLOT(onScalePrism()));
232
233   initName(tr("GEOM_EXTRUSION"));
234
235   ConstructorsClicked(0);
236   onBothway();
237 }
238
239 //=================================================================================
240 // function : SetDoubleSpinBoxStep()
241 // purpose  : Double spin box management
242 //=================================================================================
243 void GenerationGUI_PrismDlg::SetDoubleSpinBoxStep (double step)
244 {
245   GroupVecH->SpinBox_DX->setSingleStep(step);
246   GroupDXDYDZ->SpinBox_DX->setSingleStep(step);
247   GroupDXDYDZ->SpinBox_DY->setSingleStep(step);
248   GroupDXDYDZ->SpinBox_DZ->setSingleStep(step);
249 }
250
251 //=================================================================================
252 // function : ConstructorsClicked()
253 // purpose  : Radio button management
254 //=================================================================================
255 void GenerationGUI_PrismDlg::ConstructorsClicked (int constructorId)
256 {
257   switch (constructorId) {
258   case 0:
259     Group2Points->hide();
260     GroupDXDYDZ->hide();
261     GroupVecH->show();
262
263     GroupVecH->LineEdit2->setText("");
264     myVec.nullify();
265
266     GroupVecH->PushButton1->click();
267     break;
268   case 1:
269     GroupVecH->hide();
270     Group2Points->show();
271     GroupDXDYDZ->hide();
272
273     Group2Points->LineEdit2->setText("");
274     Group2Points->LineEdit3->setText("");
275     myPoint1.nullify();
276     myPoint2.nullify();
277
278     Group2Points->PushButton1->click();
279     break;
280   case 2:
281     GroupVecH->hide();
282     Group2Points->hide();
283     GroupDXDYDZ->show();
284
285     GroupDXDYDZ->PushButton1->click();
286     break;
287   default:
288     break;
289   }
290
291   qApp->processEvents();
292   updateGeometry();
293   resize(minimumSizeHint());
294
295   SelectionIntoArgument();
296   processPreview();
297 }
298
299 //=================================================================================
300 // function : ClickOnOk()
301 // purpose  :
302 //=================================================================================
303 void GenerationGUI_PrismDlg::ClickOnOk()
304 {
305   setIsApplyAndClose( true );
306   if (ClickOnApply())
307     ClickOnCancel();
308 }
309
310 //=================================================================================
311 // function : ClickOnApply()
312 // purpose  :
313 //=================================================================================
314 bool GenerationGUI_PrismDlg::ClickOnApply()
315 {
316   if (!onAccept())
317     return false;
318
319   initName();
320   // activate selection and connect selection manager
321   ConstructorsClicked(getConstructorId());
322   return true;
323 }
324
325 //=================================================================================
326 // function : SelectionIntoArgument()
327 // purpose  : Called when selection is changed or on dialog initialization or activation
328 //=================================================================================
329 void GenerationGUI_PrismDlg::SelectionIntoArgument()
330 {
331   erasePreview();
332   myEditCurrentArgument->setText("");
333
334   if ( myEditCurrentArgument == GroupVecH->LineEdit1  ||
335        myEditCurrentArgument == Group2Points->LineEdit1 ||
336        myEditCurrentArgument == GroupDXDYDZ->LineEdit1 ) {
337     myBaseObjects.clear();
338     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
339     for ( int i = 0; i < objects.count(); i++ ) {
340       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
341       if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
342         continue;
343       myBaseObjects << objects[i];
344     }
345     if ( !myBaseObjects.isEmpty() ) {
346       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
347       GroupVecH->LineEdit1->setText( aName );
348       Group2Points->LineEdit1->setText( aName );
349       GroupDXDYDZ->LineEdit1->setText( aName );
350     }
351     else {
352       GroupVecH->LineEdit1->setText( "" );
353       Group2Points->LineEdit1->setText( "" );
354       GroupDXDYDZ->LineEdit1->setText( "" );
355     }
356   }
357   else if ( myEditCurrentArgument == GroupVecH->LineEdit2 ) {
358     myVec = getSelected( TopAbs_EDGE );
359     if ( myVec ) {
360       QString aName = GEOMBase::GetName( myVec.get() );
361       myEditCurrentArgument->setText( aName );
362       if ( myBaseObjects.isEmpty() )
363         GroupVecH->PushButton1->click();
364     }
365   }
366   if ( myEditCurrentArgument == Group2Points->LineEdit2 ) {
367     myPoint1 = getSelected( TopAbs_VERTEX );
368     if ( myPoint1 ) {
369       QString aName = GEOMBase::GetName( myPoint1.get() );
370       myEditCurrentArgument->setText( aName );
371       if ( !myPoint2 )
372         Group2Points->PushButton3->click();
373       else if ( myBaseObjects.isEmpty() )
374         Group2Points->PushButton1->click();
375     }
376   }
377   if ( myEditCurrentArgument == Group2Points->LineEdit3 ) {
378     myPoint2 = getSelected( TopAbs_VERTEX );
379     if ( myPoint2 ) {
380       QString aName = GEOMBase::GetName( myPoint2.get() );
381       myEditCurrentArgument->setText( aName );
382       if ( myBaseObjects.isEmpty() )
383         Group2Points->PushButton1->click();
384       else if ( !myPoint1 )
385         Group2Points->PushButton2->click();
386     }
387   }
388
389   processPreview();
390 }
391
392 //=================================================================================
393 // function : SetEditCurrentArgument()
394 // purpose  :
395 //=================================================================================
396 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
397 {
398   QPushButton* send = (QPushButton*)sender();
399
400   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
401   globalSelection(GEOM_ALLSHAPES);
402   if (send == GroupVecH->PushButton1) {
403     myEditCurrentArgument = GroupVecH->LineEdit1;
404     GroupVecH->PushButton2->setDown(false);
405     GroupVecH->LineEdit2->setEnabled(false);
406   }
407   else if (send == GroupVecH->PushButton2) {
408     myEditCurrentArgument = GroupVecH->LineEdit2;
409     GroupVecH->PushButton1->setDown(false);
410     GroupVecH->LineEdit1->setEnabled(false);
411     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
412   }
413   else if (send == Group2Points->PushButton1) {
414     myEditCurrentArgument = Group2Points->LineEdit1;
415     Group2Points->PushButton2->setDown(false);
416     Group2Points->PushButton3->setDown(false);
417     Group2Points->LineEdit2->setEnabled(false);
418     Group2Points->LineEdit3->setEnabled(false);
419   }
420   else if (send == Group2Points->PushButton2) {
421     myEditCurrentArgument = Group2Points->LineEdit2;
422     Group2Points->PushButton1->setDown(false);
423     Group2Points->PushButton3->setDown(false);
424     Group2Points->LineEdit1->setEnabled(false);
425     Group2Points->LineEdit3->setEnabled(false);
426     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
427   }
428   else if (send == Group2Points->PushButton3) {
429     myEditCurrentArgument = Group2Points->LineEdit3;
430     Group2Points->PushButton1->setDown(false);
431     Group2Points->PushButton2->setDown(false);
432     Group2Points->LineEdit1->setEnabled(false);
433     Group2Points->LineEdit2->setEnabled(false);
434     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
435   }
436   else   if (send == GroupDXDYDZ->PushButton1) {
437     myEditCurrentArgument = GroupDXDYDZ->LineEdit1;
438   }
439   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
440           this, SLOT(SelectionIntoArgument()));
441
442   // enable line edit
443   myEditCurrentArgument->setEnabled(true);
444   myEditCurrentArgument->setFocus();
445   // after setFocus(), because it will be setDown(false) when loses focus
446   send->setDown(true);
447
448   // seems we need it only to avoid preview disappearing, caused by selection mode change
449   processPreview();
450 }
451
452 //=================================================================================
453 // function : ActivateThisDialog()
454 // purpose  :
455 //=================================================================================
456 void GenerationGUI_PrismDlg::ActivateThisDialog()
457 {
458   GEOMBase_Skeleton::ActivateThisDialog();
459
460   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
461            this, SLOT( SelectionIntoArgument() ) );
462
463   ConstructorsClicked( getConstructorId() );
464 }
465
466 //=================================================================================
467 // function : enterEvent()
468 // purpose  : when mouse enter onto the QWidget
469 //=================================================================================
470 void GenerationGUI_PrismDlg::enterEvent (QEvent*)
471 {
472   if (!mainFrame()->GroupConstructors->isEnabled())
473     ActivateThisDialog();
474 }
475
476 //=================================================================================
477 // function : ValueChangedInSpinBox()
478 // purpose  :
479 //=================================================================================
480 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
481 {
482   processPreview();
483 }
484
485 //=================================================================================
486 // function : createOperation
487 // purpose  :
488 //=================================================================================
489 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
490 {
491   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
492 }
493
494 //=================================================================================
495 // function : isValid
496 // purpose  :
497 //=================================================================================
498 bool GenerationGUI_PrismDlg::isValid (QString& msg)
499 {
500   bool ok = false;
501   switch ( getConstructorId() ) {
502   case 0:
503     ok = GroupVecH->SpinBox_DX->isValid( msg, !IsPreview() ) &&
504          !myBaseObjects.isEmpty() && myVec;
505     break;
506   case 1:
507     ok = !myBaseObjects.isEmpty() && myPoint1 && myPoint2;
508     break;
509   case 2:
510     ok = GroupDXDYDZ->SpinBox_DX->isValid( msg, !IsPreview() ) &&
511          GroupDXDYDZ->SpinBox_DY->isValid( msg, !IsPreview() ) &&
512          GroupDXDYDZ->SpinBox_DZ->isValid( msg, !IsPreview() ) &&
513          !myBaseObjects.isEmpty();
514     break;
515   default:
516     break;
517   }
518
519   return ok;
520 }
521
522 //=================================================================================
523 // function : onReverse()
524 // purpose  :
525 //=================================================================================
526 void GenerationGUI_PrismDlg::onReverse()
527 {
528   double anOldValue = GroupVecH->SpinBox_DX->value();
529   GroupVecH->SpinBox_DX->setValue(-anOldValue);
530 }
531
532 //=================================================================================
533 // function : onBothway()
534 // purpose  :
535 //=================================================================================
536 void GenerationGUI_PrismDlg::onBothway()
537 {
538   GroupVecH->CheckBox2->setEnabled(!GroupVecH->CheckBox1->isChecked()); // is reversed
539   GroupVecH->CheckBox3->setEnabled(!GroupVecH->CheckBox1->isChecked()); // is scaled
540   GroupVecH->TextLabel4->setEnabled(!GroupVecH->CheckBox1->isChecked() &&
541                                     GroupVecH->CheckBox3->isChecked()); // scale factor
542   GroupVecH->SpinBox_DY->setEnabled(!GroupVecH->CheckBox1->isChecked() &&
543                                     GroupVecH->CheckBox3->isChecked()); // scale factor
544
545   Group2Points->CheckBox2->setEnabled(!Group2Points->CheckBox1->isChecked()); // is scaled
546   Group2Points->TextLabel4->setEnabled(!Group2Points->CheckBox1->isChecked() &&
547                                        Group2Points->CheckBox2->isChecked()); // scale factor
548   Group2Points->SpinBox1->setEnabled(!Group2Points->CheckBox1->isChecked() &&
549                                      Group2Points->CheckBox2->isChecked()); // scale factor
550
551   GroupDXDYDZ->CheckBox2->setEnabled(!GroupDXDYDZ->CheckBox1->isChecked()); // is scaled
552   GroupDXDYDZ->TextLabel5->setEnabled(!GroupDXDYDZ->CheckBox1->isChecked() &&
553                                       GroupDXDYDZ->CheckBox2->isChecked()); // scale factor
554   GroupDXDYDZ->SpinBox_SC->setEnabled(!GroupDXDYDZ->CheckBox1->isChecked() &&
555                                       GroupDXDYDZ->CheckBox2->isChecked()); // scale factor
556
557   processPreview();
558 }
559
560 //=================================================================================
561 // function : onScalePrism()
562 // purpose  :
563 //=================================================================================
564 void GenerationGUI_PrismDlg::onScalePrism()
565 {
566   GroupVecH->TextLabel4->setEnabled(GroupVecH->CheckBox3->isChecked());
567   GroupVecH->SpinBox_DY->setEnabled(GroupVecH->CheckBox3->isChecked());
568
569   Group2Points->TextLabel4->setEnabled(Group2Points->CheckBox2->isChecked());
570   Group2Points->SpinBox1->setEnabled(Group2Points->CheckBox2->isChecked());
571
572   GroupDXDYDZ->TextLabel5->setEnabled(GroupDXDYDZ->CheckBox2->isChecked());
573   GroupDXDYDZ->SpinBox_SC->setEnabled(GroupDXDYDZ->CheckBox2->isChecked());
574
575   processPreview();
576 }
577
578 //=================================================================================
579 // function : execute
580 // purpose  :
581 //=================================================================================
582 bool GenerationGUI_PrismDlg::execute (ObjectList& objects)
583 {
584   QStringList aParameters;
585   GEOM::GEOM_Object_var anObj;
586
587   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
588
589   for (int i = 0; i < myBaseObjects.count(); i++) {
590     switch (getConstructorId()) {
591     case 0:
592       if (GroupVecH->CheckBox1->isChecked())
593         anObj = anOper->MakePrismVecH2Ways(myBaseObjects[i].get(), myVec.get(),
594                                            GroupVecH->SpinBox_DX->value());
595       else {
596         if (GroupVecH->CheckBox3->isChecked())
597           anObj = anOper->MakePrismVecHWithScaling(myBaseObjects[i].get(), myVec.get(),
598                                                    GroupVecH->SpinBox_DX->value(),
599                                                    GroupVecH->SpinBox_DY->value());
600         else
601           anObj = anOper->MakePrismVecH(myBaseObjects[i].get(), myVec.get(),
602                                         GroupVecH->SpinBox_DX->value());
603       }
604
605       if (!anObj->_is_nil() && !IsPreview()) {
606         aParameters << GroupVecH->SpinBox_DX->text();
607         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
608       }
609       break;
610     case 1:
611       if (Group2Points->CheckBox1->isChecked())
612         anObj = anOper->MakePrismTwoPnt2Ways(myBaseObjects[i].get(), myPoint1.get(), myPoint2.get());
613       else {
614         if (Group2Points->CheckBox2->isChecked())
615           anObj = anOper->MakePrismTwoPntWithScaling(myBaseObjects[i].get(), myPoint1.get(),
616                                                      myPoint2.get(), Group2Points->SpinBox1->value());
617         else
618           anObj = anOper->MakePrismTwoPnt(myBaseObjects[i].get(), myPoint1.get(), myPoint2.get());
619       }
620       break;
621     case 2:
622       double dx = GroupDXDYDZ->SpinBox_DX->value();
623       double dy = GroupDXDYDZ->SpinBox_DY->value();
624       double dz = GroupDXDYDZ->SpinBox_DZ->value();
625
626       if (GroupDXDYDZ->CheckBox1->isChecked())
627         anObj = anOper->MakePrismDXDYDZ2Ways(myBaseObjects[i].get(), dx, dy, dz);
628       else {
629         if (GroupDXDYDZ->CheckBox2->isChecked())
630           anObj = anOper->MakePrismDXDYDZWithScaling(myBaseObjects[i].get(), dx, dy, dz,
631                                                      GroupDXDYDZ->SpinBox_SC->value());
632         else
633           anObj = anOper->MakePrismDXDYDZ(myBaseObjects[i].get(), dx, dy, dz);
634       }
635
636       if (!anObj->_is_nil() && !IsPreview()) {
637         aParameters << GroupDXDYDZ->SpinBox_DX->text();
638         aParameters << GroupDXDYDZ->SpinBox_DY->text();
639         aParameters << GroupDXDYDZ->SpinBox_DZ->text();
640         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
641       }
642       break;
643     }
644
645     if (!anObj->_is_nil())
646       objects.push_back(anObj._retn());
647   }
648
649   return true;
650 }
651
652 //=================================================================================
653 // function : addSubshapeToStudy
654 // purpose  : virtual method to add new SubObjects if local selection
655 //=================================================================================
656 void GenerationGUI_PrismDlg::addSubshapesToStudy()
657 {
658   switch (getConstructorId()) {
659   case 0:
660     GEOMBase::PublishSubObject( myVec.get() );
661     break;
662   case 1:
663     GEOMBase::PublishSubObject( myPoint1.get() );
664     GEOMBase::PublishSubObject( myPoint2.get() );
665     break;
666   default:
667     break;
668   }
669 }
670
671 //=================================================================================
672 // function : extractPrefix
673 // purpose  : redefined from GEOMBase_Helper class
674 //=================================================================================
675 bool GenerationGUI_PrismDlg::extractPrefix() const
676 {
677   return myBaseObjects.count() > 1;
678 }