1 // Copyright (C) 2007-2011 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()
263 setIsApplyAndClose( true );
268 //=================================================================================
269 // function : ClickOnApply()
271 //=================================================================================
272 bool PrimitiveGUI_DiskDlg::ClickOnApply()
278 // activate selection and connect selection manager
279 ConstructorsClicked(getConstructorId());
283 //=================================================================================
284 // function : SelectionIntoArgument()
285 // purpose : Called when selection is changed or on dialog initialization or activation
286 //=================================================================================
287 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
289 if (getConstructorId() == 0)
293 myEditCurrentArgument->setText("");
295 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
296 SALOME_ListIO aSelList;
297 aSelMgr->selectedObjects(aSelList);
299 if (aSelList.Extent() != 1) {
300 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
301 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
302 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) myPoint1.nullify();
303 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) myPoint2.nullify();
304 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) myPoint3.nullify();
308 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
309 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
311 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
312 QString aName = GEOMBase::GetName( aSelectedObject.get() );
314 myEditCurrentArgument->setText(aName);
317 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
318 myGeomGUI->getApp()->selectionMgr()->clearSelected();
319 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
320 this, SLOT(SelectionIntoArgument()));
322 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
323 myPoint = aSelectedObject;
324 if (myPoint && !myDir)
325 GroupPntVecR->PushButton2->click();
327 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
328 myDir = aSelectedObject;
329 if (myDir && !myPoint)
330 GroupPntVecR->PushButton1->click();
332 else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
333 myPoint1 = aSelectedObject;
334 if (myPoint1 && !myPoint2)
335 Group3Pnts->PushButton2->click();
337 else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
338 myPoint2 = aSelectedObject;
339 if (myPoint2 && !myPoint3)
340 Group3Pnts->PushButton3->click();
342 else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
343 myPoint3 = aSelectedObject;
344 if (myPoint3 && !myPoint1)
345 Group3Pnts->PushButton1->click();
349 displayPreview(true);
352 //=================================================================================
353 // function : SetEditCurrentArgument()
355 //=================================================================================
356 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
358 QPushButton* send = (QPushButton*)sender();
360 if (send == GroupPntVecR->PushButton1) {
361 myEditCurrentArgument = GroupPntVecR->LineEdit1;
363 GroupPntVecR->PushButton2->setDown(false);
364 GroupPntVecR->LineEdit2->setEnabled(false);
366 else if (send == GroupPntVecR->PushButton2) {
367 myEditCurrentArgument = GroupPntVecR->LineEdit2;
369 GroupPntVecR->PushButton1->setDown(false);
370 GroupPntVecR->LineEdit1->setEnabled(false);
372 else if (send == Group3Pnts->PushButton1) {
373 myEditCurrentArgument = Group3Pnts->LineEdit1;
375 Group3Pnts->PushButton2->setDown(false);
376 Group3Pnts->PushButton3->setDown(false);
377 Group3Pnts->LineEdit2->setEnabled(false);
378 Group3Pnts->LineEdit3->setEnabled(false);
380 else if (send == Group3Pnts->PushButton2) {
381 myEditCurrentArgument = Group3Pnts->LineEdit2;
383 Group3Pnts->PushButton1->setDown(false);
384 Group3Pnts->PushButton3->setDown(false);
385 Group3Pnts->LineEdit1->setEnabled(false);
386 Group3Pnts->LineEdit3->setEnabled(false);
388 else if (send == Group3Pnts->PushButton3) {
389 myEditCurrentArgument = Group3Pnts->LineEdit3;
391 Group3Pnts->PushButton1->setDown(false);
392 Group3Pnts->PushButton2->setDown(false);
393 Group3Pnts->LineEdit1->setEnabled(false);
394 Group3Pnts->LineEdit2->setEnabled(false);
397 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
398 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
399 globalSelection(); // close local contexts, if any
400 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
403 globalSelection(); // close local contexts, if any
404 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
406 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
407 this, SLOT(SelectionIntoArgument()));
410 myEditCurrentArgument->setEnabled(true);
411 myEditCurrentArgument->setFocus();
412 // after setFocus(), because it will be setDown(false) when loses focus
415 // seems we need it only to avoid preview disappearing, caused by selection mode change
416 displayPreview(true);
419 //=================================================================================
420 // function : ActivateThisDialog()
422 //=================================================================================
423 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
425 GEOMBase_Skeleton::ActivateThisDialog();
426 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
427 this, SLOT( SelectionIntoArgument() ) );
429 ConstructorsClicked( getConstructorId() );
432 //=================================================================================
433 // function : enterEvent()
435 //=================================================================================
436 void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
438 if (!mainFrame()->GroupConstructors->isEnabled())
439 ActivateThisDialog();
442 //=================================================================================
443 // function : ValueChangedInSpinBox()
445 //=================================================================================
446 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
448 displayPreview(true);
451 //=================================================================================
452 // function : createOperation
454 //=================================================================================
455 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
457 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
460 // //=================================================================================
461 // // function : isEqual
462 // // purpose : it may also be needed to check for min distance between gp_Pnt-s...
463 // //=================================================================================
464 // static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2)
466 // return thePnt1->_is_equivalent(thePnt2);
469 //=================================================================================
470 // function : isValid
472 //=================================================================================
473 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
476 if ( getConstructorId() == 0 )
477 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && getRadius() > 0;
478 else if ( getConstructorId() == 1 )
479 ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint && myDir && getRadius() > 0;
480 else if ( getConstructorId() == 2 )
481 ok = myPoint1 && myPoint2 && myPoint3 && myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
485 //=================================================================================
486 // function : execute
488 //=================================================================================
489 bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
492 QStringList aParameters;
494 GEOM::GEOM_Object_var anObj;
496 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
498 switch (getConstructorId()) {
500 anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
501 if (!anObj->_is_nil() && !IsPreview())
503 aParameters << GroupDimensions->SpinBox_DX->text();
504 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
509 anObj = anOper->MakeDiskPntVecR(myPoint.get(), myDir.get(), getRadius());
510 if (!anObj->_is_nil() && !IsPreview())
512 aParameters << GroupPntVecR->SpinBox_DX->text();
513 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
518 anObj = anOper->MakeDiskThreePnt(myPoint1.get(), myPoint2.get(), myPoint3.get());
523 if (!anObj->_is_nil())
524 objects.push_back(anObj._retn());
529 //=================================================================================
530 // function : getRadius()
532 //=================================================================================
533 double PrimitiveGUI_DiskDlg::getRadius() const
536 switch (getConstructorId()) {
538 r = GroupDimensions->SpinBox_DX->value(); break;
540 r = GroupPntVecR->SpinBox_DX->value(); break;
545 //=================================================================================
546 // function : addSubshapeToStudy
547 // purpose : virtual method to add new SubObjects if local selection
548 //=================================================================================
549 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
551 switch (getConstructorId()) {
553 GEOMBase::PublishSubObject( myPoint.get() );
554 GEOMBase::PublishSubObject( myDir.get() );
557 GEOMBase::PublishSubObject( myPoint1.get() );
558 GEOMBase::PublishSubObject( myPoint2.get() );
559 GEOMBase::PublishSubObject( myPoint3.get() );