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("");
151 GroupPntVecR->SpinBox_DX->setValue(100);
152 GroupDimensions->SpinBox_DX->setValue(100);
154 // signals and slots connections
155 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
156 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
158 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
160 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
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(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
168 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
170 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
171 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
172 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
175 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
177 initName(tr("GEOM_DISK"));
179 ConstructorsClicked(0);
182 //=================================================================================
183 // function : SetDoubleSpinBoxStep()
184 // purpose : Double spin box management
185 //=================================================================================
186 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step)
188 GroupDimensions->SpinBox_DX->setSingleStep(step);
189 GroupPntVecR->SpinBox_DX->setSingleStep(step);
192 //=================================================================================
193 // function : RadioBittonClicked()
194 // purpose : Radio button management
195 //=================================================================================
196 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
198 if (GroupOrientation->RadioButton1->isChecked())
199 myOrientationType = 1;
200 else if (GroupOrientation->RadioButton2->isChecked())
201 myOrientationType = 2;
202 else if (GroupOrientation->RadioButton3->isChecked())
203 myOrientationType = 3;
204 displayPreview(true);
207 //=================================================================================
208 // function : ConstructorsClicked()
209 // purpose : Radio button management
210 //=================================================================================
211 void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
213 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
215 switch (constructorId) {
218 GroupPntVecR->hide();
220 GroupDimensions->show();
221 GroupOrientation->show();
223 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
224 globalSelection(); // close local contexts, if any
229 GroupDimensions->hide();
230 GroupOrientation->hide();
231 GroupPntVecR->show();
234 GroupPntVecR->PushButton1->click();
239 GroupDimensions->hide();
240 GroupOrientation->hide();
241 GroupPntVecR->hide();
244 Group3Pnts->PushButton1->click();
249 qApp->processEvents();
251 resize(minimumSizeHint());
252 SelectionIntoArgument();
254 displayPreview(true);
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void PrimitiveGUI_DiskDlg::ClickOnOk()
267 //=================================================================================
268 // function : ClickOnApply()
270 //=================================================================================
271 bool PrimitiveGUI_DiskDlg::ClickOnApply()
277 // activate selection and connect selection manager
278 ConstructorsClicked(getConstructorId());
282 //=================================================================================
283 // function : SelectionIntoArgument()
284 // purpose : Called when selection is changed or on dialog initialization or activation
285 //=================================================================================
286 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
288 if (getConstructorId() == 0)
292 myEditCurrentArgument->setText("");
294 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
295 SALOME_ListIO aSelList;
296 aSelMgr->selectedObjects(aSelList);
298 if (aSelList.Extent() != 1) {
299 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
300 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
301 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) myPoint1.nullify();
302 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) myPoint2.nullify();
303 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) myPoint3.nullify();
307 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
308 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
310 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
311 QString aName = GEOMBase::GetName( aSelectedObject.get() );
313 myEditCurrentArgument->setText(aName);
316 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
317 myGeomGUI->getApp()->selectionMgr()->clearSelected();
318 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
319 this, SLOT(SelectionIntoArgument()));
321 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
322 myPoint = aSelectedObject;
323 if (myPoint && !myDir)
324 GroupPntVecR->PushButton2->click();
326 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
327 myDir = aSelectedObject;
328 if (myDir && !myPoint)
329 GroupPntVecR->PushButton1->click();
331 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
332 myPoint1 = aSelectedObject;
333 if (myPoint1 && !myPoint2)
334 Group3Pnts->PushButton2->click();
336 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
337 myPoint2 = aSelectedObject;
338 if (myPoint2 && !myPoint3)
339 Group3Pnts->PushButton3->click();
341 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
342 myPoint3 = aSelectedObject;
343 if (myPoint3 && !myPoint1)
344 Group3Pnts->PushButton1->click();
348 displayPreview(true);
351 //=================================================================================
352 // function : SetEditCurrentArgument()
354 //=================================================================================
355 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
357 QPushButton* send = (QPushButton*)sender();
359 if (send == GroupPntVecR->PushButton1) {
360 myEditCurrentArgument = GroupPntVecR->LineEdit1;
362 GroupPntVecR->PushButton2->setDown(false);
363 GroupPntVecR->LineEdit2->setEnabled(false);
365 else if (send == GroupPntVecR->PushButton2) {
366 myEditCurrentArgument = GroupPntVecR->LineEdit2;
368 GroupPntVecR->PushButton1->setDown(false);
369 GroupPntVecR->LineEdit1->setEnabled(false);
371 else if (send == Group3Pnts->PushButton1) {
372 myEditCurrentArgument = Group3Pnts->LineEdit1;
374 Group3Pnts->PushButton2->setDown(false);
375 Group3Pnts->PushButton3->setDown(false);
376 Group3Pnts->LineEdit2->setEnabled(false);
377 Group3Pnts->LineEdit3->setEnabled(false);
379 else if (send == Group3Pnts->PushButton2) {
380 myEditCurrentArgument = Group3Pnts->LineEdit2;
382 Group3Pnts->PushButton1->setDown(false);
383 Group3Pnts->PushButton3->setDown(false);
384 Group3Pnts->LineEdit1->setEnabled(false);
385 Group3Pnts->LineEdit3->setEnabled(false);
387 else if (send == Group3Pnts->PushButton3) {
388 myEditCurrentArgument = Group3Pnts->LineEdit3;
390 Group3Pnts->PushButton1->setDown(false);
391 Group3Pnts->PushButton2->setDown(false);
392 Group3Pnts->LineEdit1->setEnabled(false);
393 Group3Pnts->LineEdit2->setEnabled(false);
396 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
397 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
398 globalSelection(); // close local contexts, if any
399 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
402 globalSelection(); // close local contexts, if any
403 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
405 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
406 this, SLOT(SelectionIntoArgument()));
409 myEditCurrentArgument->setEnabled(true);
410 myEditCurrentArgument->setFocus();
411 // after setFocus(), because it will be setDown(false) when loses focus
414 // seems we need it only to avoid preview disappearing, caused by selection mode change
415 displayPreview(true);
418 //=================================================================================
419 // function : ActivateThisDialog()
421 //=================================================================================
422 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
424 GEOMBase_Skeleton::ActivateThisDialog();
425 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
426 this, SLOT( SelectionIntoArgument() ) );
428 ConstructorsClicked( getConstructorId() );
431 //=================================================================================
432 // function : enterEvent()
434 //=================================================================================
435 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
437 if (!mainFrame()->GroupConstructors->isEnabled())
438 ActivateThisDialog();
441 //=================================================================================
442 // function : ValueChangedInSpinBox()
444 //=================================================================================
445 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
447 displayPreview(true);
450 //=================================================================================
451 // function : createOperation
453 //=================================================================================
454 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
456 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
459 //=================================================================================
460 // function : isEqual
461 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
462 //=================================================================================
463 static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
465 return thePnt1->_is_equivalent(thePnt2);
468 //=================================================================================
469 // function : isValid
471 //=================================================================================
472 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
475 if ( getConstructorId() == 0 )
476 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && getRadius() > 0;
477 else if ( getConstructorId() == 1 )
478 ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint && myDir && getRadius() > 0;
479 else if ( getConstructorId() == 2 )
480 ok = myPoint1 && myPoint2 && myPoint3 && myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
484 //=================================================================================
485 // function : execute
487 //=================================================================================
488 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
491 QStringList aParameters;
493 GEOM::GEOM_Object_var anObj;
495 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
497 switch (getConstructorId()) {
499 anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
500 if (!anObj->_is_nil() && !IsPreview())
502 aParameters << GroupDimensions->SpinBox_DX->text();
503 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
508 anObj = anOper->MakeDiskPntVecR(myPoint.get(), myDir.get(), getRadius());
509 if (!anObj->_is_nil() && !IsPreview())
511 aParameters << GroupPntVecR->SpinBox_DX->text();
512 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
517 anObj = anOper->MakeDiskThreePnt(myPoint1.get(), myPoint2.get(), myPoint3.get());
522 if (!anObj->_is_nil())
523 objects.push_back(anObj._retn());
528 //=================================================================================
529 // function : getRadius()
531 //=================================================================================
532 double PrimitiveGUI_DiskDlg::getRadius() const
535 switch (getConstructorId()) {
537 r = GroupDimensions->SpinBox_DX->value(); break;
539 r = GroupPntVecR->SpinBox_DX->value(); break;
544 //=================================================================================
545 // function : addSubshapeToStudy
546 // purpose : virtual method to add new SubObjects if local selection
547 //=================================================================================
548 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
550 switch (getConstructorId()) {
552 GEOMBase::PublishSubObject( myPoint.get() );
553 GEOMBase::PublishSubObject( myDir.get() );
556 GEOMBase::PublishSubObject( myPoint1.get() );
557 GEOMBase::PublishSubObject( myPoint2.get() );
558 GEOMBase::PublishSubObject( myPoint3.get() );