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),
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")));
61 setWindowTitle(tr("GEOM_DISK_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISK"));
65 mainFrame()->RadioButton1->setIcon(image3);
66 mainFrame()->RadioButton2->setIcon(image0);
67 mainFrame()->RadioButton3->setIcon(image2);
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);
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);
91 GroupDimensions = new DlgRef_1Spin(centralWidget());
92 GroupDimensions->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
93 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
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"));
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 /***************************************************************/
109 setHelpFileName("create_disk_page.html");
114 //=================================================================================
115 // function : ~PrimitiveGUI_DiskDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
122 //=================================================================================
125 //=================================================================================
126 void PrimitiveGUI_DiskDlg::Init()
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);
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" );
137 myEditCurrentArgument = GroupPntVecR->LineEdit1;
138 myOrientationType = 1;
139 GroupOrientation->RadioButton1->setChecked(true);
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();
148 GroupPntVecR->SpinBox_DX->setValue(100);
149 GroupDimensions->SpinBox_DX->setValue(100);
151 // signals and slots connections
152 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
155 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
157 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
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()));
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()));
171 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
172 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
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()));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
179 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
181 initName(tr("GEOM_DISK"));
183 ConstructorsClicked(0);
186 //=================================================================================
187 // function : SetDoubleSpinBoxStep()
188 // purpose : Double spin box management
189 //=================================================================================
190 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step)
192 GroupDimensions->SpinBox_DX->setSingleStep(step);
193 GroupPntVecR->SpinBox_DX->setSingleStep(step);
196 //=================================================================================
197 // function : RadioBittonClicked()
198 // purpose : Radio button management
199 //=================================================================================
200 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
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;
211 //=================================================================================
212 // function : ConstructorsClicked()
213 // purpose : Radio button management
214 //=================================================================================
215 void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
217 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
219 switch (constructorId) {
222 GroupPntVecR->hide();
224 GroupDimensions->show();
225 GroupOrientation->show();
227 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
228 globalSelection(); // close local contexts, if any
233 GroupDimensions->hide();
234 GroupOrientation->hide();
235 GroupPntVecR->show();
238 GroupPntVecR->PushButton1->click();
243 GroupDimensions->hide();
244 GroupOrientation->hide();
245 GroupPntVecR->hide();
248 Group3Pnts->PushButton1->click();
253 qApp->processEvents();
255 resize(minimumSizeHint());
259 if (constructorId == 1 || constructorId == 2) {
260 // on dialog initialization we init the first field with a selected object (if any)
261 SelectionIntoArgument();
272 //=================================================================================
273 // function : ClickOnOk()
275 //=================================================================================
276 void PrimitiveGUI_DiskDlg::ClickOnOk()
282 //=================================================================================
283 // function : ClickOnApply()
285 //=================================================================================
286 bool PrimitiveGUI_DiskDlg::ClickOnApply()
292 // activate selection and connect selection manager
293 ConstructorsClicked(getConstructorId());
297 //=================================================================================
298 // function : SelectionIntoArgument()
299 // purpose : Called when selection is changed or on dialog initialization or activation
300 //=================================================================================
301 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
303 if (getConstructorId() == 0)
307 myEditCurrentArgument->setText("");
309 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
310 SALOME_ListIO aSelList;
311 aSelMgr->selectedObjects(aSelList);
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();
323 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
324 Standard_Boolean testResult = Standard_False;
325 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult);
327 if (!testResult || CORBA::is_nil(aSelectedObject))
330 QString aName = GEOMBase::GetName(aSelectedObject);
332 // If selected Vertex or Edge on the some Shape Get selection Subshape
334 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
336 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
337 if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
338 aNeedType = TopAbs_EDGE;
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);
347 aName += QString(":vertex_%1").arg(anIndex);
349 //Find SubShape Object in Father
350 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
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);
357 aSelectedObject = aFindedObject; // get Object from study
360 else { // Global Selection
361 if (aShape.ShapeType() != aNeedType) {
362 aSelectedObject = GEOM::GEOM_Object::_nil();
368 myEditCurrentArgument->setText(aName);
371 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
372 myGeomGUI->getApp()->selectionMgr()->clearSelected();
373 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
374 this, SLOT(SelectionIntoArgument()));
376 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
377 myPoint = aSelectedObject;
378 if (!myPoint->_is_nil() && myDir->_is_nil())
379 GroupPntVecR->PushButton2->click();
381 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
382 myDir = aSelectedObject;
383 if (!myDir->_is_nil() && myPoint->_is_nil())
384 GroupPntVecR->PushButton1->click();
386 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
387 myPoint1 = aSelectedObject;
388 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
389 Group3Pnts->PushButton2->click();
391 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
392 myPoint2 = aSelectedObject;
393 if (!myPoint2->_is_nil() && myPoint3->_is_nil())
394 Group3Pnts->PushButton3->click();
396 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
397 myPoint3 = aSelectedObject;
398 if (!myPoint3->_is_nil() && myPoint1->_is_nil())
399 Group3Pnts->PushButton1->click();
405 //=================================================================================
406 // function : SetEditCurrentArgument()
408 //=================================================================================
409 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
411 QPushButton* send = (QPushButton*)sender();
413 if (send == GroupPntVecR->PushButton1) {
414 myEditCurrentArgument = GroupPntVecR->LineEdit1;
416 GroupPntVecR->PushButton2->setDown(false);
417 GroupPntVecR->LineEdit2->setEnabled(false);
419 else if (send == GroupPntVecR->PushButton2) {
420 myEditCurrentArgument = GroupPntVecR->LineEdit2;
422 GroupPntVecR->PushButton1->setDown(false);
423 GroupPntVecR->LineEdit1->setEnabled(false);
425 else if (send == Group3Pnts->PushButton1) {
426 myEditCurrentArgument = Group3Pnts->LineEdit1;
428 Group3Pnts->PushButton2->setDown(false);
429 Group3Pnts->PushButton3->setDown(false);
430 Group3Pnts->LineEdit2->setEnabled(false);
431 Group3Pnts->LineEdit3->setEnabled(false);
433 else if (send == Group3Pnts->PushButton2) {
434 myEditCurrentArgument = Group3Pnts->LineEdit2;
436 Group3Pnts->PushButton1->setDown(false);
437 Group3Pnts->PushButton3->setDown(false);
438 Group3Pnts->LineEdit1->setEnabled(false);
439 Group3Pnts->LineEdit3->setEnabled(false);
441 else if (send == Group3Pnts->PushButton3) {
442 myEditCurrentArgument = Group3Pnts->LineEdit3;
444 Group3Pnts->PushButton1->setDown(false);
445 Group3Pnts->PushButton2->setDown(false);
446 Group3Pnts->LineEdit1->setEnabled(false);
447 Group3Pnts->LineEdit2->setEnabled(false);
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);
456 globalSelection(); // close local contexts, if any
457 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
459 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
460 this, SLOT(SelectionIntoArgument()));
463 myEditCurrentArgument->setEnabled(true);
464 myEditCurrentArgument->setFocus();
465 // after setFocus(), because it will be setDown(false) when loses focus
468 // seems we need it only to avoid preview disappearing, caused by selection mode change
472 //=================================================================================
473 // function : LineEditReturnPressed()
475 //=================================================================================
476 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
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();
489 //=================================================================================
490 // function : ActivateThisDialog()
492 //=================================================================================
493 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
495 GEOMBase_Skeleton::ActivateThisDialog();
496 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
497 this, SLOT( SelectionIntoArgument() ) );
499 ConstructorsClicked( getConstructorId() );
502 //=================================================================================
503 // function : enterEvent()
505 //=================================================================================
506 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
508 if (!mainFrame()->GroupConstructors->isEnabled())
509 ActivateThisDialog();
512 //=================================================================================
513 // function : ValueChangedInSpinBox()
515 //=================================================================================
516 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
521 //=================================================================================
522 // function : createOperation
524 //=================================================================================
525 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
527 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
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)
536 return thePnt1->_is_equivalent(thePnt2);
539 //=================================================================================
540 // function : isValid
542 //=================================================================================
543 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
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;
551 const int id = getConstructorId();
555 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0 && ok;
557 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
558 !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
562 //=================================================================================
563 // function : execute
565 //=================================================================================
566 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
569 QStringList aParameters;
571 GEOM::GEOM_Object_var anObj;
573 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
575 switch (getConstructorId()) {
577 anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
578 if (!anObj->_is_nil() && !IsPreview())
580 aParameters << GroupDimensions->SpinBox_DX->text();
581 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
586 anObj = anOper->MakeDiskPntVecR(myPoint, myDir, getRadius());
587 if (!anObj->_is_nil() && !IsPreview())
589 aParameters << GroupPntVecR->SpinBox_DX->text();
590 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
595 anObj = anOper->MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
600 if (!anObj->_is_nil())
601 objects.push_back(anObj._retn());
606 //=================================================================================
607 // function : getRadius()
609 //=================================================================================
610 double PrimitiveGUI_DiskDlg::getRadius() const
613 switch (getConstructorId()) {
615 r = GroupDimensions->SpinBox_DX->value(); break;
617 r = GroupPntVecR->SpinBox_DX->value(); break;
622 //=================================================================================
623 // function : addSubshapeToStudy
624 // purpose : virtual method to add new SubObjects if local selection
625 //=================================================================================
626 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
628 QMap<QString, GEOM::GEOM_Object_var> objMap;
630 switch (getConstructorId()) {
632 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
633 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
636 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
637 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
638 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
641 addSubshapesToFather(objMap);