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 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO );
314 if ( CORBA::is_nil(aSelectedObject) )
317 QString aName = GEOMBase::GetName(aSelectedObject);
319 // If selected Vertex or Edge on the some Shape Get selection Subshape
321 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
323 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
324 if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
325 aNeedType = TopAbs_EDGE;
327 TColStd_IndexedMapOfInteger aMap;
328 aSelMgr->GetIndexes(anIO, aMap);
329 if (aMap.Extent() == 1) { // Local Selection
330 int anIndex = aMap(1);
331 if (aNeedType == TopAbs_EDGE)
332 aName += QString(":edge_%1").arg(anIndex);
334 aName += QString(":vertex_%1").arg(anIndex);
336 //Find SubShape Object in Father
337 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
339 if (aFindedObject->_is_nil()) { // Object not found in study
340 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
341 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
344 aSelectedObject = aFindedObject; // get Object from study
347 else { // Global Selection
348 if (aShape.ShapeType() != aNeedType) {
349 aSelectedObject = GEOM::GEOM_Object::_nil();
355 myEditCurrentArgument->setText(aName);
358 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
359 myGeomGUI->getApp()->selectionMgr()->clearSelected();
360 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
361 this, SLOT(SelectionIntoArgument()));
363 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
364 myPoint = aSelectedObject;
365 if (!myPoint->_is_nil() && myDir->_is_nil())
366 GroupPntVecR->PushButton2->click();
368 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
369 myDir = aSelectedObject;
370 if (!myDir->_is_nil() && myPoint->_is_nil())
371 GroupPntVecR->PushButton1->click();
373 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
374 myPoint1 = aSelectedObject;
375 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
376 Group3Pnts->PushButton2->click();
378 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
379 myPoint2 = aSelectedObject;
380 if (!myPoint2->_is_nil() && myPoint3->_is_nil())
381 Group3Pnts->PushButton3->click();
383 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
384 myPoint3 = aSelectedObject;
385 if (!myPoint3->_is_nil() && myPoint1->_is_nil())
386 Group3Pnts->PushButton1->click();
392 //=================================================================================
393 // function : SetEditCurrentArgument()
395 //=================================================================================
396 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
398 QPushButton* send = (QPushButton*)sender();
400 if (send == GroupPntVecR->PushButton1) {
401 myEditCurrentArgument = GroupPntVecR->LineEdit1;
403 GroupPntVecR->PushButton2->setDown(false);
404 GroupPntVecR->LineEdit2->setEnabled(false);
406 else if (send == GroupPntVecR->PushButton2) {
407 myEditCurrentArgument = GroupPntVecR->LineEdit2;
409 GroupPntVecR->PushButton1->setDown(false);
410 GroupPntVecR->LineEdit1->setEnabled(false);
412 else if (send == Group3Pnts->PushButton1) {
413 myEditCurrentArgument = Group3Pnts->LineEdit1;
415 Group3Pnts->PushButton2->setDown(false);
416 Group3Pnts->PushButton3->setDown(false);
417 Group3Pnts->LineEdit2->setEnabled(false);
418 Group3Pnts->LineEdit3->setEnabled(false);
420 else if (send == Group3Pnts->PushButton2) {
421 myEditCurrentArgument = Group3Pnts->LineEdit2;
423 Group3Pnts->PushButton1->setDown(false);
424 Group3Pnts->PushButton3->setDown(false);
425 Group3Pnts->LineEdit1->setEnabled(false);
426 Group3Pnts->LineEdit3->setEnabled(false);
428 else if (send == Group3Pnts->PushButton3) {
429 myEditCurrentArgument = Group3Pnts->LineEdit3;
431 Group3Pnts->PushButton1->setDown(false);
432 Group3Pnts->PushButton2->setDown(false);
433 Group3Pnts->LineEdit1->setEnabled(false);
434 Group3Pnts->LineEdit2->setEnabled(false);
437 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
438 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
439 globalSelection(); // close local contexts, if any
440 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
443 globalSelection(); // close local contexts, if any
444 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
446 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
447 this, SLOT(SelectionIntoArgument()));
450 myEditCurrentArgument->setEnabled(true);
451 myEditCurrentArgument->setFocus();
452 // after setFocus(), because it will be setDown(false) when loses focus
455 // seems we need it only to avoid preview disappearing, caused by selection mode change
459 //=================================================================================
460 // function : LineEditReturnPressed()
462 //=================================================================================
463 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
465 QLineEdit* send = (QLineEdit*)sender();
466 if (send == GroupPntVecR->LineEdit1 ||
467 send == GroupPntVecR->LineEdit2 ||
468 send == Group3Pnts->LineEdit1 ||
469 send == Group3Pnts->LineEdit2 ||
470 send == Group3Pnts->LineEdit3) {
471 myEditCurrentArgument = send;
472 GEOMBase_Skeleton::LineEditReturnPressed();
476 //=================================================================================
477 // function : ActivateThisDialog()
479 //=================================================================================
480 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
482 GEOMBase_Skeleton::ActivateThisDialog();
483 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
484 this, SLOT( SelectionIntoArgument() ) );
486 ConstructorsClicked( getConstructorId() );
489 //=================================================================================
490 // function : enterEvent()
492 //=================================================================================
493 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
495 if (!mainFrame()->GroupConstructors->isEnabled())
496 ActivateThisDialog();
499 //=================================================================================
500 // function : ValueChangedInSpinBox()
502 //=================================================================================
503 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
508 //=================================================================================
509 // function : createOperation
511 //=================================================================================
512 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
514 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
517 //=================================================================================
518 // function : isEqual
519 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
520 //=================================================================================
521 static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
523 return thePnt1->_is_equivalent(thePnt2);
526 //=================================================================================
527 // function : isValid
529 //=================================================================================
530 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
533 if( getConstructorId() == 0 )
534 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
535 else if( getConstructorId() == 1 )
536 ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
538 const int id = getConstructorId();
542 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0 && ok;
544 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
545 !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
549 //=================================================================================
550 // function : execute
552 //=================================================================================
553 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
556 QStringList aParameters;
558 GEOM::GEOM_Object_var anObj;
560 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
562 switch (getConstructorId()) {
564 anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
565 if (!anObj->_is_nil() && !IsPreview())
567 aParameters << GroupDimensions->SpinBox_DX->text();
568 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
573 anObj = anOper->MakeDiskPntVecR(myPoint, myDir, getRadius());
574 if (!anObj->_is_nil() && !IsPreview())
576 aParameters << GroupPntVecR->SpinBox_DX->text();
577 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
582 anObj = anOper->MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
587 if (!anObj->_is_nil())
588 objects.push_back(anObj._retn());
593 //=================================================================================
594 // function : getRadius()
596 //=================================================================================
597 double PrimitiveGUI_DiskDlg::getRadius() const
600 switch (getConstructorId()) {
602 r = GroupDimensions->SpinBox_DX->value(); break;
604 r = GroupPntVecR->SpinBox_DX->value(); break;
609 //=================================================================================
610 // function : addSubshapeToStudy
611 // purpose : virtual method to add new SubObjects if local selection
612 //=================================================================================
613 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
615 QMap<QString, GEOM::GEOM_Object_var> objMap;
617 switch (getConstructorId()) {
619 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
620 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
623 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
624 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
625 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
628 addSubshapesToFather(objMap);