1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : PrimitiveGUI_DiskDlg.cxx
22 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 #include "PrimitiveGUI_DiskDlg.h"
27 #include <GeometryGUI.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
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)
54 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
55 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
56 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
57 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_THREE_POINTS")));
58 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
60 setWindowTitle(tr("GEOM_DISK_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISK"));
64 mainFrame()->RadioButton1->setIcon(image3);
65 mainFrame()->RadioButton2->setIcon(image0);
66 mainFrame()->RadioButton3->setIcon(image2);
68 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
69 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
71 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
72 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
73 GroupPntVecR->PushButton1->setIcon(image1);
74 GroupPntVecR->PushButton2->setIcon(image1);
75 GroupPntVecR->LineEdit1->setReadOnly(true);
76 GroupPntVecR->LineEdit2->setReadOnly(true);
78 Group3Pnts = new DlgRef_3Sel(centralWidget());
79 Group3Pnts->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
81 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
82 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
83 Group3Pnts->PushButton1->setIcon(image1);
84 Group3Pnts->PushButton2->setIcon(image1);
85 Group3Pnts->PushButton3->setIcon(image1);
86 Group3Pnts->LineEdit1->setReadOnly(true);
87 Group3Pnts->LineEdit2->setReadOnly(true);
88 Group3Pnts->LineEdit3->setReadOnly(true);
90 GroupDimensions = new DlgRef_1Spin(centralWidget());
91 GroupDimensions->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
92 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
94 GroupOrientation = new DlgRef_3Radio(centralWidget());
95 GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
96 GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
97 GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
98 GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
100 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
101 layout->setMargin(0); layout->setSpacing(6);
102 layout->addWidget(GroupPntVecR);
103 layout->addWidget(Group3Pnts);
104 layout->addWidget(GroupDimensions);
105 layout->addWidget(GroupOrientation);
106 /***************************************************************/
108 setHelpFileName("create_disk_page.html");
113 //=================================================================================
114 // function : ~PrimitiveGUI_DiskDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
121 //=================================================================================
124 //=================================================================================
125 void PrimitiveGUI_DiskDlg::Init()
127 // Get setting of step value from file configuration
128 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
129 double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
131 // min, max, step and decimals for spin boxes & initial values
132 initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
133 initSpinBox(GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
136 myEditCurrentArgument = GroupPntVecR->LineEdit1;
137 myOrientationType = 1;
138 GroupOrientation->RadioButton1->setChecked(true);
140 GroupPntVecR->LineEdit1->setText("");
141 GroupPntVecR->LineEdit2->setText("");
142 Group3Pnts->LineEdit1->setText("");
143 Group3Pnts->LineEdit2->setText("");
144 Group3Pnts->LineEdit3->setText("");
145 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
147 GroupPntVecR->SpinBox_DX->setValue(100);
148 GroupDimensions->SpinBox_DX->setValue(100);
150 // signals and slots connections
151 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
152 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
154 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
156 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
171 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
173 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
174 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
175 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
177 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
178 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
180 initName(tr("GEOM_DISK"));
182 ConstructorsClicked(0);
185 //=================================================================================
186 // function : SetDoubleSpinBoxStep()
187 // purpose : Double spin box management
188 //=================================================================================
189 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step)
191 GroupDimensions->SpinBox_DX->setSingleStep(step);
192 GroupPntVecR->SpinBox_DX->setSingleStep(step);
195 //=================================================================================
196 // function : RadioBittonClicked()
197 // purpose : Radio button management
198 //=================================================================================
199 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
201 if (GroupOrientation->RadioButton1->isChecked())
202 myOrientationType = 1;
203 else if (GroupOrientation->RadioButton2->isChecked())
204 myOrientationType = 2;
205 else if (GroupOrientation->RadioButton3->isChecked())
206 myOrientationType = 3;
210 //=================================================================================
211 // function : ConstructorsClicked()
212 // purpose : Radio button management
213 //=================================================================================
214 void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
216 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
218 switch (constructorId) {
221 GroupPntVecR->hide();
223 GroupDimensions->show();
224 GroupOrientation->show();
226 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
227 globalSelection(); // close local contexts, if any
232 GroupDimensions->hide();
233 GroupOrientation->hide();
234 GroupPntVecR->show();
237 GroupPntVecR->PushButton1->click();
242 GroupDimensions->hide();
243 GroupOrientation->hide();
244 GroupPntVecR->hide();
247 Group3Pnts->PushButton1->click();
252 qApp->processEvents();
254 resize(minimumSizeHint());
255 SelectionIntoArgument();
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void PrimitiveGUI_DiskDlg::ClickOnOk()
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 bool PrimitiveGUI_DiskDlg::ClickOnApply()
280 // activate selection and connect selection manager
281 ConstructorsClicked(getConstructorId());
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose : Called when selection is changed or on dialog initialization or activation
288 //=================================================================================
289 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
291 if (getConstructorId() == 0)
295 myEditCurrentArgument->setText("");
297 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
298 SALOME_ListIO aSelList;
299 aSelMgr->selectedObjects(aSelList);
301 if (aSelList.Extent() != 1) {
302 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint = GEOM::GEOM_Object::_nil();
303 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir = GEOM::GEOM_Object::_nil();
304 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil();
305 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil();
306 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) myPoint3 = GEOM::GEOM_Object::_nil();
311 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
312 Standard_Boolean testResult = Standard_False;
313 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult);
315 if (!testResult || CORBA::is_nil(aSelectedObject))
318 QString aName = GEOMBase::GetName(aSelectedObject);
320 // If selected Vertex or Edge on the some Shape Get selection Subshape
322 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
324 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
325 if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
326 aNeedType = TopAbs_EDGE;
328 TColStd_IndexedMapOfInteger aMap;
329 aSelMgr->GetIndexes(anIO, aMap);
330 if (aMap.Extent() == 1) { // Local Selection
331 int anIndex = aMap(1);
332 if (aNeedType == TopAbs_EDGE)
333 aName += QString(":edge_%1").arg(anIndex);
335 aName += QString(":vertex_%1").arg(anIndex);
337 //Find SubShape Object in Father
338 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
340 if (aFindedObject->_is_nil()) { // Object not found in study
341 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
342 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
345 aSelectedObject = aFindedObject; // get Object from study
348 else { // Global Selection
349 if (aShape.ShapeType() != aNeedType) {
350 aSelectedObject = GEOM::GEOM_Object::_nil();
356 myEditCurrentArgument->setText(aName);
359 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
360 myGeomGUI->getApp()->selectionMgr()->clearSelected();
361 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
362 this, SLOT(SelectionIntoArgument()));
364 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
365 myPoint = aSelectedObject;
366 if (!myPoint->_is_nil() && myDir->_is_nil())
367 GroupPntVecR->PushButton2->click();
369 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
370 myDir = aSelectedObject;
371 if (!myDir->_is_nil() && myPoint->_is_nil())
372 GroupPntVecR->PushButton1->click();
374 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
375 myPoint1 = aSelectedObject;
376 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
377 Group3Pnts->PushButton2->click();
379 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
380 myPoint2 = aSelectedObject;
381 if (!myPoint2->_is_nil() && myPoint3->_is_nil())
382 Group3Pnts->PushButton3->click();
384 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
385 myPoint3 = aSelectedObject;
386 if (!myPoint3->_is_nil() && myPoint1->_is_nil())
387 Group3Pnts->PushButton1->click();
393 //=================================================================================
394 // function : SetEditCurrentArgument()
396 //=================================================================================
397 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
399 QPushButton* send = (QPushButton*)sender();
401 if (send == GroupPntVecR->PushButton1) {
402 myEditCurrentArgument = GroupPntVecR->LineEdit1;
404 GroupPntVecR->PushButton2->setDown(false);
405 GroupPntVecR->LineEdit2->setEnabled(false);
407 else if (send == GroupPntVecR->PushButton2) {
408 myEditCurrentArgument = GroupPntVecR->LineEdit2;
410 GroupPntVecR->PushButton1->setDown(false);
411 GroupPntVecR->LineEdit1->setEnabled(false);
413 else if (send == Group3Pnts->PushButton1) {
414 myEditCurrentArgument = Group3Pnts->LineEdit1;
416 Group3Pnts->PushButton2->setDown(false);
417 Group3Pnts->PushButton3->setDown(false);
418 Group3Pnts->LineEdit2->setEnabled(false);
419 Group3Pnts->LineEdit3->setEnabled(false);
421 else if (send == Group3Pnts->PushButton2) {
422 myEditCurrentArgument = Group3Pnts->LineEdit2;
424 Group3Pnts->PushButton1->setDown(false);
425 Group3Pnts->PushButton3->setDown(false);
426 Group3Pnts->LineEdit1->setEnabled(false);
427 Group3Pnts->LineEdit3->setEnabled(false);
429 else if (send == Group3Pnts->PushButton3) {
430 myEditCurrentArgument = Group3Pnts->LineEdit3;
432 Group3Pnts->PushButton1->setDown(false);
433 Group3Pnts->PushButton2->setDown(false);
434 Group3Pnts->LineEdit1->setEnabled(false);
435 Group3Pnts->LineEdit2->setEnabled(false);
438 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
439 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
440 globalSelection(); // close local contexts, if any
441 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
444 globalSelection(); // close local contexts, if any
445 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
447 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
448 this, SLOT(SelectionIntoArgument()));
451 myEditCurrentArgument->setEnabled(true);
452 myEditCurrentArgument->setFocus();
453 // after setFocus(), because it will be setDown(false) when loses focus
456 // seems we need it only to avoid preview disappearing, caused by selection mode change
460 //=================================================================================
461 // function : LineEditReturnPressed()
463 //=================================================================================
464 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
466 QLineEdit* send = (QLineEdit*)sender();
467 if (send == GroupPntVecR->LineEdit1 ||
468 send == GroupPntVecR->LineEdit2 ||
469 send == Group3Pnts->LineEdit1 ||
470 send == Group3Pnts->LineEdit2 ||
471 send == Group3Pnts->LineEdit3) {
472 myEditCurrentArgument = send;
473 GEOMBase_Skeleton::LineEditReturnPressed();
477 //=================================================================================
478 // function : ActivateThisDialog()
480 //=================================================================================
481 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
483 GEOMBase_Skeleton::ActivateThisDialog();
484 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
485 this, SLOT( SelectionIntoArgument() ) );
487 ConstructorsClicked( getConstructorId() );
490 //=================================================================================
491 // function : enterEvent()
493 //=================================================================================
494 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
496 if (!mainFrame()->GroupConstructors->isEnabled())
497 ActivateThisDialog();
500 //=================================================================================
501 // function : ValueChangedInSpinBox()
503 //=================================================================================
504 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
509 //=================================================================================
510 // function : createOperation
512 //=================================================================================
513 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
515 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
518 //=================================================================================
519 // function : isEqual
520 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
521 //=================================================================================
522 static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
524 return thePnt1->_is_equivalent(thePnt2);
527 //=================================================================================
528 // function : isValid
530 //=================================================================================
531 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
534 if( getConstructorId() == 0 )
535 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
536 else if( getConstructorId() == 1 )
537 ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
539 const int id = getConstructorId();
543 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0 && ok;
545 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
546 !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
550 //=================================================================================
551 // function : execute
553 //=================================================================================
554 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
557 QStringList aParameters;
559 GEOM::GEOM_Object_var anObj;
561 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
563 switch (getConstructorId()) {
565 anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
566 if (!anObj->_is_nil() && !IsPreview())
568 aParameters << GroupDimensions->SpinBox_DX->text();
569 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
574 anObj = anOper->MakeDiskPntVecR(myPoint, myDir, getRadius());
575 if (!anObj->_is_nil() && !IsPreview())
577 aParameters << GroupPntVecR->SpinBox_DX->text();
578 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
583 anObj = anOper->MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
588 if (!anObj->_is_nil())
589 objects.push_back(anObj._retn());
594 //=================================================================================
595 // function : getRadius()
597 //=================================================================================
598 double PrimitiveGUI_DiskDlg::getRadius() const
601 switch (getConstructorId()) {
603 r = GroupDimensions->SpinBox_DX->value(); break;
605 r = GroupPntVecR->SpinBox_DX->value(); break;
610 //=================================================================================
611 // function : addSubshapeToStudy
612 // purpose : virtual method to add new SubObjects if local selection
613 //=================================================================================
614 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
616 QMap<QString, GEOM::GEOM_Object_var> objMap;
618 switch (getConstructorId()) {
620 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
621 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
624 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
625 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
626 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
629 addSubshapesToFather(objMap);