1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PrimitiveGUI_TorusDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_TorusDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : PrimitiveGUI_TorusDlg()
49 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_TORUS_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_TORUS"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image1);
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
73 GroupPoints = new DlgRef_2Sel2Spin(centralWidget());
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg(1));
78 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg(2));
79 GroupPoints->PushButton1->setIcon(image2);
80 GroupPoints->PushButton2->setIcon(image2);
82 GroupDimensions = new DlgRef_2Spin(centralWidget());
83 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
84 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg(1));
85 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg(2));
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(GroupPoints);
90 layout->addWidget(GroupDimensions);
91 /***************************************************************/
93 setHelpFileName("create_torus_page.html");
98 //=================================================================================
99 // function : ~PrimitiveGUI_TorusDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
104 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_TorusDlg::Init()
113 // Get setting of step value from file configuration
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
117 // min, max, step and decimals for spin boxes & initial values
118 initSpinBox(GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
119 initSpinBox(GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
120 initSpinBox(GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
121 initSpinBox(GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
124 myEditCurrentArgument = GroupPoints->LineEdit1;
125 GroupPoints->LineEdit1->setReadOnly(true);
126 GroupPoints->LineEdit2->setReadOnly(true);
128 GroupPoints->LineEdit1->setText("");
129 GroupPoints->LineEdit2->setText("");
130 myPoint = myDir = GEOM::GEOM_Object::_nil();
132 GroupPoints->SpinBox_DX->setValue(300.0);
133 GroupPoints->SpinBox_DY->setValue(100.0);
134 GroupDimensions->SpinBox_DX->setValue(300.0);
135 GroupDimensions->SpinBox_DY->setValue(100.0);
137 // signals and slots connections
138 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
156 initName(tr("GEOM_TORUS"));
158 setConstructorId(1); // simplest constructor
159 ConstructorsClicked(1);
162 //=================================================================================
163 // function : SetDoubleSpinBoxStep()
164 // purpose : Double spin box management
165 //=================================================================================
166 void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep (double step)
168 GroupPoints->SpinBox_DX->setSingleStep(step);
169 GroupPoints->SpinBox_DY->setSingleStep(step);
170 GroupDimensions->SpinBox_DX->setSingleStep(step);
171 GroupDimensions->SpinBox_DY->setSingleStep(step);
174 //=================================================================================
175 // function : ConstructorsClicked()
176 // purpose : Radio button management
177 //=================================================================================
178 void PrimitiveGUI_TorusDlg::ConstructorsClicked (int constructorId)
180 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
182 switch (constructorId) {
185 GroupDimensions->hide();
188 GroupPoints->PushButton1->click();
194 GroupDimensions->show();
195 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
196 globalSelection(); // close local contexts, if any
201 qApp->processEvents();
203 resize(minimumSize());
207 if (constructorId == 0) {
208 // on dialog initialization we init the first field with a selected object (if any)
209 SelectionIntoArgument();
220 //=================================================================================
221 // function : ClickOnOk()
223 //=================================================================================
224 void PrimitiveGUI_TorusDlg::ClickOnOk()
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool PrimitiveGUI_TorusDlg::ClickOnApply()
240 // activate selection and connect selection manager
241 ConstructorsClicked(getConstructorId());
245 //=================================================================================
246 // function : SelectionIntoArgument()
247 // purpose : Called when selection is changed or on dialog initialization or activation
248 //=================================================================================
249 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
251 if (getConstructorId() != 0)
255 myEditCurrentArgument->setText("");
257 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
258 SALOME_ListIO aSelList;
259 aSelMgr->selectedObjects(aSelList);
261 if (aSelList.Extent() != 1) {
262 if (myEditCurrentArgument == GroupPoints->LineEdit1)
263 myPoint = GEOM::GEOM_Object::_nil();
264 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
265 myDir = GEOM::GEOM_Object::_nil();
270 Standard_Boolean testResult = Standard_False;
271 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
273 if (!testResult || CORBA::is_nil(aSelectedObject))
276 QString aName = GEOMBase::GetName(aSelectedObject);
278 // Get Selected object if selected subshape
280 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
282 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
283 if (myEditCurrentArgument == GroupPoints->LineEdit2)
284 aNeedType = TopAbs_EDGE;
286 TColStd_IndexedMapOfInteger aMap;
287 aSelMgr->GetIndexes(aSelList.First(), aMap);
288 if (aMap.Extent() == 1) { // Local Selection
289 int anIndex = aMap(1);
290 if (aNeedType == TopAbs_EDGE)
291 aName.append(":edge_" + QString::number(anIndex));
293 aName.append(":vertex_" + QString::number(anIndex));
295 //Find SubShape Object in Father
296 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
298 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
299 GEOM::GEOM_IShapesOperations_var aShapesOp =
300 getGeomEngine()->GetIShapesOperations(getStudyId());
301 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
304 aSelectedObject = aFindedObject; // get Object from study
307 else { // Global Selection
308 if (aShape.ShapeType() != aNeedType) {
309 aSelectedObject = GEOM::GEOM_Object::_nil();
315 myEditCurrentArgument->setText(aName);
318 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
319 myGeomGUI->getApp()->selectionMgr()->clearSelected();
320 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
321 this, SLOT(SelectionIntoArgument()));
323 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
324 myPoint = aSelectedObject;
325 if (!myPoint->_is_nil() && myDir->_is_nil())
326 GroupPoints->PushButton2->click();
328 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
329 myDir = aSelectedObject;
330 if (!myDir->_is_nil() && myPoint->_is_nil())
331 GroupPoints->PushButton1->click();
337 //=================================================================================
338 // function : SetEditCurrentArgument()
340 //=================================================================================
341 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
343 QPushButton* send = (QPushButton*)sender();
345 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
346 if (send == GroupPoints->PushButton1) {
347 myEditCurrentArgument = GroupPoints->LineEdit1;
349 GroupPoints->PushButton2->setDown(false);
350 GroupPoints->LineEdit2->setEnabled(false);
352 globalSelection(GEOM_POINT); // to break previous local selection
353 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
355 else if (send == GroupPoints->PushButton2) {
356 myEditCurrentArgument = GroupPoints->LineEdit2;
358 GroupPoints->PushButton1->setDown(false);
359 GroupPoints->LineEdit1->setEnabled(false);
361 globalSelection(GEOM_LINE); // to break previous local selection
362 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
364 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
365 this, SLOT(SelectionIntoArgument()));
368 myEditCurrentArgument->setEnabled(true);
369 myEditCurrentArgument->setFocus();
370 // after setFocus(), because it will be setDown(false) then loses focus
373 // seems we need it only to avoid preview disappearing, caused by selection mode change
377 //=================================================================================
378 // function : LineEditReturnPressed()
380 //=================================================================================
381 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
383 QLineEdit* send = (QLineEdit*)sender();
384 if (send == GroupPoints->LineEdit1 ||
385 send == GroupPoints->LineEdit2) {
386 myEditCurrentArgument = send;
387 GEOMBase_Skeleton::LineEditReturnPressed();
391 //=================================================================================
392 // function : ActivateThisDialog()
394 //=================================================================================
395 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
397 GEOMBase_Skeleton::ActivateThisDialog();
399 // reinit, because some selected objects could be removed
403 //=================================================================================
404 // function : enterEvent()
406 //=================================================================================
407 void PrimitiveGUI_TorusDlg::enterEvent (QEvent*)
409 if (!mainFrame()->GroupConstructors->isEnabled())
410 ActivateThisDialog();
413 //=================================================================================
414 // function : ValueChangedInSpinBox()
416 //=================================================================================
417 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
422 //=================================================================================
423 // function : createOperation
425 //=================================================================================
426 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
428 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
431 //=================================================================================
432 // function : isValid
434 //=================================================================================
435 bool PrimitiveGUI_TorusDlg::isValid (QString&)
437 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
440 //=================================================================================
441 // function : execute
443 //=================================================================================
444 bool PrimitiveGUI_TorusDlg::execute (ObjectList& objects)
448 GEOM::GEOM_Object_var anObj;
450 switch (getConstructorId()) {
452 if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) {
453 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
454 MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
459 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
460 MakeTorusRR(getRadius1(), getRadius2());
465 if (!anObj->_is_nil())
466 objects.push_back(anObj._retn());
471 //=================================================================================
472 // function : getRadius1()
474 //=================================================================================
475 double PrimitiveGUI_TorusDlg::getRadius1() const
477 int aConstructorId = getConstructorId();
478 if (aConstructorId == 0)
479 return GroupPoints->SpinBox_DX->value();
480 else if (aConstructorId == 1)
481 return GroupDimensions->SpinBox_DX->value();
485 //=================================================================================
486 // function : getRadius2()
488 //=================================================================================
489 double PrimitiveGUI_TorusDlg::getRadius2() const
491 int aConstructorId = getConstructorId();
492 if (aConstructorId == 0)
493 return GroupPoints->SpinBox_DY->value();
494 else if (aConstructorId == 1)
495 return GroupDimensions->SpinBox_DY->value();
499 //=================================================================================
500 // function : addSubshapeToStudy
501 // purpose : virtual method to add new SubObjects if local selection
502 //=================================================================================
503 void PrimitiveGUI_TorusDlg::addSubshapesToStudy()
505 QMap<QString, GEOM::GEOM_Object_var> objMap;
507 switch (getConstructorId()) {
509 objMap[GroupPoints->LineEdit1->text()] = myPoint;
510 objMap[GroupPoints->LineEdit2->text()] = myDir;
515 addSubshapesToFather(objMap);