1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PrimitiveGUI_DiskDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_DiskDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 //=================================================================================
46 // class : PrimitiveGUI_DiskDlg()
47 // purpose : Constructs a PrimitiveGUI_DiskDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl)
54 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
59 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
60 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_THREE_POINTS")));
61 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
63 setWindowTitle(tr("GEOM_DISK_TITLE"));
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISK"));
67 mainFrame()->RadioButton1->setIcon(image3);
68 mainFrame()->RadioButton2->setIcon(image0);
69 mainFrame()->RadioButton3->setIcon(image2);
71 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
72 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
74 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
75 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
76 GroupPntVecR->PushButton1->setIcon(image1);
77 GroupPntVecR->PushButton2->setIcon(image1);
78 GroupPntVecR->LineEdit1->setReadOnly(true);
79 GroupPntVecR->LineEdit2->setReadOnly(true);
81 Group3Pnts = new DlgRef_3Sel(centralWidget());
82 Group3Pnts->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
83 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
84 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
85 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
86 Group3Pnts->PushButton1->setIcon(image1);
87 Group3Pnts->PushButton2->setIcon(image1);
88 Group3Pnts->PushButton3->setIcon(image1);
89 Group3Pnts->LineEdit1->setReadOnly(true);
90 Group3Pnts->LineEdit2->setReadOnly(true);
91 Group3Pnts->LineEdit3->setReadOnly(true);
93 GroupDimensions = new DlgRef_1Spin(centralWidget());
94 GroupDimensions->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
95 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
97 GroupOrientation = new DlgRef_3Radio(centralWidget());
98 GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
99 GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
100 GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
101 GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
103 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
104 layout->setMargin(0); layout->setSpacing(6);
105 layout->addWidget(GroupPntVecR);
106 layout->addWidget(Group3Pnts);
107 layout->addWidget(GroupDimensions);
108 layout->addWidget(GroupOrientation);
109 /***************************************************************/
111 setHelpFileName("create_disk_page.html");
116 //=================================================================================
117 // function : ~PrimitiveGUI_DiskDlg()
118 // purpose : Destroys the object and frees any allocated resources
119 //=================================================================================
120 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
124 //=================================================================================
127 //=================================================================================
128 void PrimitiveGUI_DiskDlg::Init()
130 // Get setting of step value from file configuration
131 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
132 double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
134 // min, max, step and decimals for spin boxes & initial values
135 initSpinBox(GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3); // VSR:TODO : DBL_DIGITS_DISPLAY
136 initSpinBox(GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3); // VSR:TODO : DBL_DIGITS_DISPLAY
139 myEditCurrentArgument = GroupPntVecR->LineEdit1;
140 myOrientationType = 1;
141 GroupOrientation->RadioButton1->setChecked(true);
143 GroupPntVecR->LineEdit1->setText("");
144 GroupPntVecR->LineEdit2->setText("");
145 Group3Pnts->LineEdit1->setText("");
146 Group3Pnts->LineEdit2->setText("");
147 Group3Pnts->LineEdit3->setText("");
148 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
150 GroupPntVecR->SpinBox_DX->setValue(100);
151 GroupDimensions->SpinBox_DX->setValue(100);
153 // signals and slots connections
154 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
157 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
159 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
171 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
173 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
174 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
176 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
177 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
178 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
180 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
181 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
183 initName(tr("GEOM_DISK"));
185 ConstructorsClicked(0);
188 //=================================================================================
189 // function : SetDoubleSpinBoxStep()
190 // purpose : Double spin box management
191 //=================================================================================
192 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step)
194 GroupDimensions->SpinBox_DX->setSingleStep(step);
195 GroupPntVecR->SpinBox_DX->setSingleStep(step);
198 //=================================================================================
199 // function : RadioBittonClicked()
200 // purpose : Radio button management
201 //=================================================================================
202 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
204 if (GroupOrientation->RadioButton1->isChecked())
205 myOrientationType = 1;
206 else if (GroupOrientation->RadioButton2->isChecked())
207 myOrientationType = 2;
208 else if (GroupOrientation->RadioButton3->isChecked())
209 myOrientationType = 3;
213 //=================================================================================
214 // function : ConstructorsClicked()
215 // purpose : Radio button management
216 //=================================================================================
217 void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
219 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
221 switch (constructorId) {
224 GroupPntVecR->hide();
226 GroupDimensions->show();
227 GroupOrientation->show();
229 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
230 globalSelection(); // close local contexts, if any
235 GroupDimensions->hide();
236 GroupOrientation->hide();
237 GroupPntVecR->show();
240 GroupPntVecR->PushButton1->click();
245 GroupDimensions->hide();
246 GroupOrientation->hide();
247 GroupPntVecR->hide();
250 Group3Pnts->PushButton1->click();
255 qApp->processEvents();
257 resize(minimumSize());
261 if (constructorId == 1 || constructorId == 2) {
262 // on dialog initialization we init the first field with a selected object (if any)
263 SelectionIntoArgument();
274 //=================================================================================
275 // function : ClickOnOk()
277 //=================================================================================
278 void PrimitiveGUI_DiskDlg::ClickOnOk()
284 //=================================================================================
285 // function : ClickOnApply()
287 //=================================================================================
288 bool PrimitiveGUI_DiskDlg::ClickOnApply()
294 // activate selection and connect selection manager
295 ConstructorsClicked(getConstructorId());
299 //=================================================================================
300 // function : SelectionIntoArgument()
301 // purpose : Called when selection is changed or on dialog initialization or activation
302 //=================================================================================
303 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
305 if (getConstructorId() == 0)
309 myEditCurrentArgument->setText("");
311 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
312 SALOME_ListIO aSelList;
313 aSelMgr->selectedObjects(aSelList);
315 if (aSelList.Extent() != 1) {
316 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint = GEOM::GEOM_Object::_nil();
317 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir = GEOM::GEOM_Object::_nil();
318 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil();
319 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil();
320 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) myPoint3 = GEOM::GEOM_Object::_nil();
325 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
326 Standard_Boolean testResult = Standard_False;
327 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult);
329 if (!testResult || CORBA::is_nil(aSelectedObject))
332 QString aName = GEOMBase::GetName(aSelectedObject);
334 // If selected Vertex or Edge on the some Shape Get selection Subshape
336 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
338 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
339 if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
340 aNeedType = TopAbs_EDGE;
342 TColStd_IndexedMapOfInteger aMap;
343 aSelMgr->GetIndexes(anIO, aMap);
344 if (aMap.Extent() == 1) { // Local Selection
345 int anIndex = aMap(1);
346 if (aNeedType == TopAbs_EDGE)
347 aName += QString(":edge_%1").arg(anIndex);
349 aName += QString(":vertex_%1").arg(anIndex);
351 //Find SubShape Object in Father
352 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
354 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
355 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
356 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
359 aSelectedObject = aFindedObject; // get Object from study
362 else { // Global Selection
363 if (aShape.ShapeType() != aNeedType) {
364 aSelectedObject = GEOM::GEOM_Object::_nil();
370 myEditCurrentArgument->setText(aName);
373 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
374 myGeomGUI->getApp()->selectionMgr()->clearSelected();
375 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
376 this, SLOT(SelectionIntoArgument()));
378 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
379 myPoint = aSelectedObject;
380 if (!myPoint->_is_nil() && myDir->_is_nil())
381 GroupPntVecR->PushButton2->click();
383 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
384 myDir = aSelectedObject;
385 if (!myDir->_is_nil() && myPoint->_is_nil())
386 GroupPntVecR->PushButton1->click();
388 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
389 myPoint1 = aSelectedObject;
390 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
391 Group3Pnts->PushButton2->click();
393 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
394 myPoint2 = aSelectedObject;
395 if (!myPoint2->_is_nil() && myPoint3->_is_nil())
396 Group3Pnts->PushButton3->click();
398 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
399 myPoint3 = aSelectedObject;
400 if (!myPoint3->_is_nil() && myPoint1->_is_nil())
401 Group3Pnts->PushButton1->click();
407 //=================================================================================
408 // function : SetEditCurrentArgument()
410 //=================================================================================
411 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
413 QPushButton* send = (QPushButton*)sender();
415 if (send == GroupPntVecR->PushButton1) {
416 myEditCurrentArgument = GroupPntVecR->LineEdit1;
418 GroupPntVecR->PushButton2->setDown(false);
419 GroupPntVecR->LineEdit2->setEnabled(false);
421 else if (send == GroupPntVecR->PushButton2) {
422 myEditCurrentArgument = GroupPntVecR->LineEdit2;
424 GroupPntVecR->PushButton1->setDown(false);
425 GroupPntVecR->LineEdit1->setEnabled(false);
427 else if (send == Group3Pnts->PushButton1) {
428 myEditCurrentArgument = Group3Pnts->LineEdit1;
430 Group3Pnts->PushButton2->setDown(false);
431 Group3Pnts->PushButton3->setDown(false);
432 Group3Pnts->LineEdit2->setEnabled(false);
433 Group3Pnts->LineEdit3->setEnabled(false);
435 else if (send == Group3Pnts->PushButton2) {
436 myEditCurrentArgument = Group3Pnts->LineEdit2;
438 Group3Pnts->PushButton1->setDown(false);
439 Group3Pnts->PushButton3->setDown(false);
440 Group3Pnts->LineEdit1->setEnabled(false);
441 Group3Pnts->LineEdit3->setEnabled(false);
443 else if (send == Group3Pnts->PushButton3) {
444 myEditCurrentArgument = Group3Pnts->LineEdit3;
446 Group3Pnts->PushButton1->setDown(false);
447 Group3Pnts->PushButton2->setDown(false);
448 Group3Pnts->LineEdit1->setEnabled(false);
449 Group3Pnts->LineEdit2->setEnabled(false);
452 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
453 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
454 globalSelection(); // close local contexts, if any
455 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
458 globalSelection(); // close local contexts, if any
459 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
461 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
462 this, SLOT(SelectionIntoArgument()));
465 myEditCurrentArgument->setEnabled(true);
466 myEditCurrentArgument->setFocus();
467 // after setFocus(), because it will be setDown(false) when loses focus
470 // seems we need it only to avoid preview disappearing, caused by selection mode change
474 //=================================================================================
475 // function : LineEditReturnPressed()
477 //=================================================================================
478 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
480 QLineEdit* send = (QLineEdit*)sender();
481 if (send == GroupPntVecR->LineEdit1 ||
482 send == GroupPntVecR->LineEdit2 ||
483 send == Group3Pnts->LineEdit1 ||
484 send == Group3Pnts->LineEdit2 ||
485 send == Group3Pnts->LineEdit3) {
486 myEditCurrentArgument = send;
487 GEOMBase_Skeleton::LineEditReturnPressed();
491 //=================================================================================
492 // function : ActivateThisDialog()
494 //=================================================================================
495 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
497 GEOMBase_Skeleton::ActivateThisDialog();
499 // reinit, because some selected objects could be removed
503 //=================================================================================
504 // function : enterEvent()
506 //=================================================================================
507 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
509 if (!mainFrame()->GroupConstructors->isEnabled())
510 ActivateThisDialog();
513 //=================================================================================
514 // function : ValueChangedInSpinBox()
516 //=================================================================================
517 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
522 //=================================================================================
523 // function : createOperation
525 //=================================================================================
526 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
528 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
531 //=================================================================================
532 // function : isEqual
533 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
534 //=================================================================================
535 static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
537 return thePnt1->_is_equivalent(thePnt2);
540 //=================================================================================
541 // function : isValid
543 //=================================================================================
544 bool PrimitiveGUI_DiskDlg::isValid (QString&)
546 const int id = getConstructorId();
550 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
552 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
553 !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
557 //=================================================================================
558 // function : execute
560 //=================================================================================
561 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
565 GEOM::GEOM_Object_var anObj;
567 switch (getConstructorId()) {
569 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
570 MakeDiskR(getRadius(), myOrientationType);
574 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
575 MakeDiskPntVecR(myPoint, myDir, getRadius());
579 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
580 MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
585 if (!anObj->_is_nil())
586 objects.push_back(anObj._retn());
591 //=================================================================================
592 // function : getRadius()
594 //=================================================================================
595 double PrimitiveGUI_DiskDlg::getRadius() const
598 switch (getConstructorId()) {
600 r = GroupDimensions->SpinBox_DX->value(); break;
602 r = GroupPntVecR->SpinBox_DX->value(); break;
607 //=================================================================================
608 // function : addSubshapeToStudy
609 // purpose : virtual method to add new SubObjects if local selection
610 //=================================================================================
611 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
613 QMap<QString, GEOM::GEOM_Object_var> objMap;
615 switch (getConstructorId()) {
617 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
618 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
621 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
622 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
623 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
626 addSubshapesToFather(objMap);