Salome HOME
Merge from V5_1_main 14/05/2010
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_DiskDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File   : PrimitiveGUI_DiskDlg.cxx
22 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
23 //
24 #include "PrimitiveGUI_DiskDlg.h"
25
26 #include <DlgRef.h>
27 #include <GeometryGUI.h>
28 #include <GEOMBase.h>
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34
35 // OCCT Includes
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS.hxx>
39 #include <TopExp.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42
43 //=================================================================================
44 // class    : PrimitiveGUI_DiskDlg()
45 // purpose  : Constructs a PrimitiveGUI_DiskDlg which is a child of 'parent', with the
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
51                                             bool modal, Qt::WindowFlags fl)
52   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
53     myInitial(true)
54 {
55   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
56   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
57   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
58   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_THREE_POINTS")));
59   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
60
61   setWindowTitle(tr("GEOM_DISK_TITLE"));
62
63   /***************************************************************/
64   mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISK"));
65   mainFrame()->RadioButton1->setIcon(image3);
66   mainFrame()->RadioButton2->setIcon(image0);
67   mainFrame()->RadioButton3->setIcon(image2);
68
69   GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
70   GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71   GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
72   GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
73   GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
74   GroupPntVecR->PushButton1->setIcon(image1);
75   GroupPntVecR->PushButton2->setIcon(image1);
76   GroupPntVecR->LineEdit1->setReadOnly(true);
77   GroupPntVecR->LineEdit2->setReadOnly(true);
78
79   Group3Pnts = new DlgRef_3Sel(centralWidget());
80   Group3Pnts->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
81   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
82   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
83   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
84   Group3Pnts->PushButton1->setIcon(image1);
85   Group3Pnts->PushButton2->setIcon(image1);
86   Group3Pnts->PushButton3->setIcon(image1);
87   Group3Pnts->LineEdit1->setReadOnly(true);
88   Group3Pnts->LineEdit2->setReadOnly(true);
89   Group3Pnts->LineEdit3->setReadOnly(true);
90
91   GroupDimensions = new DlgRef_1Spin(centralWidget());
92   GroupDimensions->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
93   GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
94
95   GroupOrientation = new DlgRef_3Radio(centralWidget());
96   GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
97   GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
98   GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
99   GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
100
101   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
102   layout->setMargin(0); layout->setSpacing(6);
103   layout->addWidget(GroupPntVecR);
104   layout->addWidget(Group3Pnts);
105   layout->addWidget(GroupDimensions);
106   layout->addWidget(GroupOrientation);
107   /***************************************************************/
108
109   setHelpFileName("create_disk_page.html");
110
111   Init();
112 }
113
114 //=================================================================================
115 // function : ~PrimitiveGUI_DiskDlg()
116 // purpose  : Destroys the object and frees any allocated resources
117 //=================================================================================
118 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
119 {
120 }
121
122 //=================================================================================
123 // function : Init()
124 // purpose  :
125 //=================================================================================
126 void PrimitiveGUI_DiskDlg::Init()
127 {
128   // Get setting of step value from file configuration
129   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
130   double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
131
132   // min, max, step and decimals for spin boxes & initial values
133   initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
134   initSpinBox(GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
135
136   // init variables
137   myEditCurrentArgument = GroupPntVecR->LineEdit1;
138   myOrientationType = 1;
139   GroupOrientation->RadioButton1->setChecked(true);
140
141   GroupPntVecR->LineEdit1->setText("");
142   GroupPntVecR->LineEdit2->setText("");
143   Group3Pnts->LineEdit1->setText("");
144   Group3Pnts->LineEdit2->setText("");
145   Group3Pnts->LineEdit3->setText("");
146   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
147
148   GroupPntVecR->SpinBox_DX->setValue(100);
149   GroupDimensions->SpinBox_DX->setValue(100);
150
151   // signals and slots connections
152   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
154
155   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
156
157   connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158   connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159
160   connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161   connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162
163   connect(Group3Pnts->PushButton1,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164   connect(Group3Pnts->PushButton2,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165   connect(Group3Pnts->PushButton3,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166
167   connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168   connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
169   connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170
171   connect(GroupPntVecR->SpinBox_DX,    SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
172   connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
173
174   connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
175   connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
176   connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
177
178   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
179   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),               this, SLOT(ClickOnCancel()));
180
181   initName(tr("GEOM_DISK"));
182
183   ConstructorsClicked(0);
184 }
185
186 //=================================================================================
187 // function : SetDoubleSpinBoxStep()
188 // purpose  : Double spin box management
189 //=================================================================================
190 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step)
191 {
192   GroupDimensions->SpinBox_DX->setSingleStep(step);
193   GroupPntVecR->SpinBox_DX->setSingleStep(step);
194 }
195
196 //=================================================================================
197 // function : RadioBittonClicked()
198 // purpose  : Radio button management
199 //=================================================================================
200 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
201 {
202   if (GroupOrientation->RadioButton1->isChecked())
203     myOrientationType = 1;
204   else if (GroupOrientation->RadioButton2->isChecked())
205     myOrientationType = 2;
206   else if (GroupOrientation->RadioButton3->isChecked())
207     myOrientationType = 3;
208   displayPreview();
209 }
210
211 //=================================================================================
212 // function : ConstructorsClicked()
213 // purpose  : Radio button management
214 //=================================================================================
215 void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
216 {
217   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
218
219   switch (constructorId) {
220   case 0:
221     {
222       GroupPntVecR->hide();
223       Group3Pnts->hide();
224       GroupDimensions->show();
225       GroupOrientation->show();
226
227       disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
228       globalSelection(); // close local contexts, if any
229       break;
230     }
231   case 1:
232     {
233       GroupDimensions->hide();
234       GroupOrientation->hide();
235       GroupPntVecR->show();
236       Group3Pnts->hide();
237
238       GroupPntVecR->PushButton1->click();
239       break;
240     }
241   case 2:
242     {
243       GroupDimensions->hide();
244       GroupOrientation->hide();
245       GroupPntVecR->hide();
246       Group3Pnts->show();
247
248       Group3Pnts->PushButton1->click();
249       break;
250     }
251   }
252
253   qApp->processEvents();
254   updateGeometry();
255   resize(minimumSizeHint());
256
257   if (myInitial) {
258     myInitial = false;
259     if (constructorId == 1 || constructorId == 2) {
260       // on dialog initialization we init the first field with a selected object (if any)
261       SelectionIntoArgument();
262     }
263     else {
264       displayPreview();
265     }
266   }
267   else {
268     displayPreview();
269   }
270 }
271
272 //=================================================================================
273 // function : ClickOnOk()
274 // purpose  :
275 //=================================================================================
276 void PrimitiveGUI_DiskDlg::ClickOnOk()
277 {
278   if (ClickOnApply())
279     ClickOnCancel();
280 }
281
282 //=================================================================================
283 // function : ClickOnApply()
284 // purpose  :
285 //=================================================================================
286 bool PrimitiveGUI_DiskDlg::ClickOnApply()
287 {
288   if (!onAccept())
289     return false;
290
291   initName();
292   // activate selection and connect selection manager
293   ConstructorsClicked(getConstructorId());
294   return true;
295 }
296
297 //=================================================================================
298 // function : SelectionIntoArgument()
299 // purpose  : Called when selection is changed or on dialog initialization or activation
300 //=================================================================================
301 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
302 {
303   if (getConstructorId() == 0)
304     return;
305
306   erasePreview();
307   myEditCurrentArgument->setText("");
308
309   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
310   SALOME_ListIO aSelList;
311   aSelMgr->selectedObjects(aSelList);
312
313   if (aSelList.Extent() != 1) {
314     if      (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint  = GEOM::GEOM_Object::_nil();
315     else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir    = GEOM::GEOM_Object::_nil();
316     else if (myEditCurrentArgument == Group3Pnts->LineEdit1)   myPoint1 = GEOM::GEOM_Object::_nil();
317     else if (myEditCurrentArgument == Group3Pnts->LineEdit2)   myPoint2 = GEOM::GEOM_Object::_nil();
318     else if (myEditCurrentArgument == Group3Pnts->LineEdit3)   myPoint3 = GEOM::GEOM_Object::_nil();
319     return;
320   }
321
322   // nbSel == 1
323   Handle(SALOME_InteractiveObject) anIO = aSelList.First();
324   Standard_Boolean testResult = Standard_False;
325   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult);
326
327   if (!testResult || CORBA::is_nil(aSelectedObject))
328     return;
329
330   QString aName = GEOMBase::GetName(aSelectedObject);
331
332   // If selected Vertex or Edge on the some Shape Get selection Subshape
333   TopoDS_Shape aShape;
334   if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
335   {
336     TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
337     if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
338       aNeedType = TopAbs_EDGE;
339
340     TColStd_IndexedMapOfInteger aMap;
341     aSelMgr->GetIndexes(anIO, aMap);
342     if (aMap.Extent() == 1) { // Local Selection
343       int anIndex = aMap(1);
344       if (aNeedType == TopAbs_EDGE)
345         aName += QString(":edge_%1").arg(anIndex);
346       else
347         aName += QString(":vertex_%1").arg(anIndex);
348
349       //Find SubShape Object in Father
350       GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
351
352       if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
353         GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
354         aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
355       }
356       else {
357         aSelectedObject = aFindedObject; // get Object from study
358       }
359     }
360     else { // Global Selection
361       if (aShape.ShapeType() != aNeedType) {
362         aSelectedObject = GEOM::GEOM_Object::_nil();
363         aName = "";
364       }
365     }
366   }
367
368   myEditCurrentArgument->setText(aName);
369
370   // clear selection
371   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
372   myGeomGUI->getApp()->selectionMgr()->clearSelected();
373   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
374           this, SLOT(SelectionIntoArgument()));
375
376   if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
377     myPoint = aSelectedObject;
378     if (!myPoint->_is_nil() && myDir->_is_nil())
379       GroupPntVecR->PushButton2->click();
380   }
381   else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
382     myDir = aSelectedObject;
383     if (!myDir->_is_nil() && myPoint->_is_nil())
384       GroupPntVecR->PushButton1->click();
385   }
386   else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
387     myPoint1 = aSelectedObject;
388     if (!myPoint1->_is_nil() && myPoint2->_is_nil())
389       Group3Pnts->PushButton2->click();
390   }
391   else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
392     myPoint2 = aSelectedObject;
393     if (!myPoint2->_is_nil() && myPoint3->_is_nil())
394       Group3Pnts->PushButton3->click();
395   }
396   else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
397     myPoint3 = aSelectedObject;
398     if (!myPoint3->_is_nil() && myPoint1->_is_nil())
399       Group3Pnts->PushButton1->click();
400   }
401
402   displayPreview();
403 }
404
405 //=================================================================================
406 // function : SetEditCurrentArgument()
407 // purpose  :
408 //=================================================================================
409 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
410 {
411   QPushButton* send = (QPushButton*)sender();
412
413   if (send == GroupPntVecR->PushButton1) {
414     myEditCurrentArgument = GroupPntVecR->LineEdit1;
415
416     GroupPntVecR->PushButton2->setDown(false);
417     GroupPntVecR->LineEdit2->setEnabled(false);
418   }
419   else if (send == GroupPntVecR->PushButton2) {
420     myEditCurrentArgument = GroupPntVecR->LineEdit2;
421
422     GroupPntVecR->PushButton1->setDown(false);
423     GroupPntVecR->LineEdit1->setEnabled(false);
424   }
425   else if (send == Group3Pnts->PushButton1) {
426     myEditCurrentArgument = Group3Pnts->LineEdit1;
427
428     Group3Pnts->PushButton2->setDown(false);
429     Group3Pnts->PushButton3->setDown(false);
430     Group3Pnts->LineEdit2->setEnabled(false);
431     Group3Pnts->LineEdit3->setEnabled(false);
432   }
433   else if (send == Group3Pnts->PushButton2) {
434     myEditCurrentArgument = Group3Pnts->LineEdit2;
435
436     Group3Pnts->PushButton1->setDown(false);
437     Group3Pnts->PushButton3->setDown(false);
438     Group3Pnts->LineEdit1->setEnabled(false);
439     Group3Pnts->LineEdit3->setEnabled(false);
440   }
441   else if (send == Group3Pnts->PushButton3) {
442     myEditCurrentArgument = Group3Pnts->LineEdit3;
443
444     Group3Pnts->PushButton1->setDown(false);
445     Group3Pnts->PushButton2->setDown(false);
446     Group3Pnts->LineEdit1->setEnabled(false);
447     Group3Pnts->LineEdit2->setEnabled(false);
448   }
449
450   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
451   if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
452     globalSelection(); // close local contexts, if any
453     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
454   }
455   else {
456     globalSelection(); // close local contexts, if any
457     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
458   }
459   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
460           this, SLOT(SelectionIntoArgument()));
461
462   // enable line edit
463   myEditCurrentArgument->setEnabled(true);
464   myEditCurrentArgument->setFocus();
465   // after setFocus(), because it will be setDown(false) when loses focus
466   send->setDown(true);
467
468   // seems we need it only to avoid preview disappearing, caused by selection mode change
469   displayPreview();
470 }
471
472 //=================================================================================
473 // function : LineEditReturnPressed()
474 // purpose  :
475 //=================================================================================
476 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
477 {
478 QLineEdit* send = (QLineEdit*)sender();
479   if (send == GroupPntVecR->LineEdit1 ||
480       send == GroupPntVecR->LineEdit2 ||
481       send == Group3Pnts->LineEdit1 ||
482       send == Group3Pnts->LineEdit2 ||
483       send == Group3Pnts->LineEdit3) {
484     myEditCurrentArgument = send;
485     GEOMBase_Skeleton::LineEditReturnPressed();
486   }
487 }
488
489 //=================================================================================
490 // function : ActivateThisDialog()
491 // purpose  :
492 //=================================================================================
493 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
494 {
495   GEOMBase_Skeleton::ActivateThisDialog();
496   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
497            this, SLOT( SelectionIntoArgument() ) );
498
499   ConstructorsClicked( getConstructorId() );
500 }
501
502 //=================================================================================
503 // function : enterEvent()
504 // purpose  :
505 //=================================================================================
506 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
507 {
508   if (!mainFrame()->GroupConstructors->isEnabled())
509     ActivateThisDialog();
510 }
511
512 //=================================================================================
513 // function : ValueChangedInSpinBox()
514 // purpose  :
515 //=================================================================================
516 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
517 {
518   displayPreview();
519 }
520
521 //=================================================================================
522 // function : createOperation
523 // purpose  :
524 //=================================================================================
525 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
526 {
527   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
528 }
529
530 //=================================================================================
531 // function : isEqual
532 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
533 //=================================================================================
534 static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
535 {
536   return thePnt1->_is_equivalent(thePnt2);
537 }
538
539 //=================================================================================
540 // function : isValid
541 // purpose  :
542 //=================================================================================
543 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
544 {
545   bool ok = true;
546   if( getConstructorId() == 0 )
547     ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
548   else if( getConstructorId() == 1 )
549     ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
550
551   const int id = getConstructorId();
552   if (id == 0)
553     return ok;
554   else if (id == 1)
555     return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0 && ok;
556   else if (id == 2)
557     return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
558       !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
559   return false;
560 }
561
562 //=================================================================================
563 // function : execute
564 // purpose  :
565 //=================================================================================
566 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
567 {
568   bool res = false;
569   QStringList aParameters;
570
571   GEOM::GEOM_Object_var anObj;
572
573   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
574
575   switch (getConstructorId()) {
576   case 0:
577     anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
578     if (!anObj->_is_nil() && !IsPreview())
579     {
580       aParameters << GroupDimensions->SpinBox_DX->text();
581       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
582     }
583     res = true;
584     break;
585   case 1:
586     anObj = anOper->MakeDiskPntVecR(myPoint, myDir, getRadius());
587     if (!anObj->_is_nil() && !IsPreview())
588     {
589       aParameters << GroupPntVecR->SpinBox_DX->text();
590       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
591     }
592     res = true;
593     break;
594   case 2:
595     anObj = anOper->MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
596     res = true;
597     break;
598   }
599
600   if (!anObj->_is_nil())
601     objects.push_back(anObj._retn());
602
603   return res;
604 }
605
606 //=================================================================================
607 // function : getRadius()
608 // purpose  :
609 //=================================================================================
610 double PrimitiveGUI_DiskDlg::getRadius() const
611 {
612   double r = 0.;
613   switch (getConstructorId()) {
614   case 0:
615     r = GroupDimensions->SpinBox_DX->value(); break;
616   case 1:
617     r = GroupPntVecR->SpinBox_DX->value(); break;
618   }
619   return r;
620 }
621
622 //=================================================================================
623 // function : addSubshapeToStudy
624 // purpose  : virtual method to add new SubObjects if local selection
625 //=================================================================================
626 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
627 {
628   QMap<QString, GEOM::GEOM_Object_var> objMap;
629
630   switch (getConstructorId()) {
631   case 1:
632     objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
633     objMap[GroupPntVecR->LineEdit2->text()] = myDir;
634     break;
635   case 2:
636     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
637     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
638     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
639     break;
640   }
641   addSubshapesToFather(objMap);
642 }