1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : PrimitiveGUI_CylinderDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "PrimitiveGUI_CylinderDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : PrimitiveGUI_CylinderDlg()
50 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
60 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CYLINDER_PV")));
61 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CYLINDER_DXYZ")));
62 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_CYLINDER_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
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"));
78 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
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"));
85 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
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_cylinder_page.html");
98 //=================================================================================
99 // function : ~PrimitiveGUI_CylinderDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
104 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_CylinderDlg::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.00001, COORD_MAX, step, "length_precision" );
119 initSpinBox(GroupPoints->SpinBox_DY, 0.00001, COORD_MAX, step, "length_precision" );
120 initSpinBox(GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
121 initSpinBox(GroupDimensions->SpinBox_DY, 0.00001, COORD_MAX, step, "length_precision" );
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 double aRadius(100.0), aHeight(300.0);
133 GroupPoints->SpinBox_DX->setValue(aRadius);
134 GroupPoints->SpinBox_DY->setValue(aHeight);
135 GroupDimensions->SpinBox_DX->setValue(aRadius);
136 GroupDimensions->SpinBox_DY->setValue(aHeight);
138 // signals and slots connections
139 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
144 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
157 initName(tr("GEOM_CYLINDER"));
159 setConstructorId(1); // simplest constructor
160 ConstructorsClicked(1);
163 //=================================================================================
164 // function : SetDoubleSpinBoxStep()
165 // purpose : Double spin box management
166 //=================================================================================
167 void PrimitiveGUI_CylinderDlg::SetDoubleSpinBoxStep (double step)
169 GroupPoints->SpinBox_DX->setSingleStep(step);
170 GroupPoints->SpinBox_DY->setSingleStep(step);
171 GroupDimensions->SpinBox_DX->setSingleStep(step);
172 GroupDimensions->SpinBox_DY->setSingleStep(step);
175 //=================================================================================
176 // function : ConstructorsClicked()
177 // purpose : Radio button management
178 //=================================================================================
179 void PrimitiveGUI_CylinderDlg::ConstructorsClicked (int constructorId)
181 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
183 switch (constructorId) {
186 GroupDimensions->hide();
189 GroupPoints->PushButton1->click();
195 GroupDimensions->show();
196 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
197 globalSelection(); // close local contexts, if any
202 qApp->processEvents();
204 resize(minimumSizeHint());
205 SelectionIntoArgument();
210 //=================================================================================
211 // function : ClickOnOk()
213 //=================================================================================
214 void PrimitiveGUI_CylinderDlg::ClickOnOk()
220 //=================================================================================
221 // function : ClickOnApply()
223 //=================================================================================
224 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
230 // activate selection and connect selection manager
231 ConstructorsClicked(getConstructorId());
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose : Called when selection is changed or on dialog initialization or activation
238 //=================================================================================
239 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
241 if (getConstructorId() != 0)
245 myEditCurrentArgument->setText("");
247 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
248 SALOME_ListIO aSelList;
249 aSelMgr->selectedObjects(aSelList);
251 if (aSelList.Extent() != 1) {
252 if (myEditCurrentArgument == GroupPoints->LineEdit1)
253 myPoint = GEOM::GEOM_Object::_nil();
254 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
255 myDir = GEOM::GEOM_Object::_nil();
260 Standard_Boolean testResult = Standard_False;
261 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
263 if (!testResult || CORBA::is_nil(aSelectedObject))
266 QString aName = GEOMBase::GetName(aSelectedObject);
268 // Get Selected object if selected subshape
270 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
272 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
273 if (myEditCurrentArgument == GroupPoints->LineEdit2)
274 aNeedType = TopAbs_EDGE;
276 TColStd_IndexedMapOfInteger aMap;
277 aSelMgr->GetIndexes(aSelList.First(), aMap);
278 if (aMap.Extent() == 1) { // Local Selection
279 int anIndex = aMap(1);
280 if (aNeedType == TopAbs_EDGE)
281 aName.append(":edge_" + QString::number(anIndex));
283 aName.append(":vertex_" + QString::number(anIndex));
285 //Find SubShape Object in Father
286 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
288 if (aFindedObject->_is_nil()) { // Object not found in study
289 GEOM::GEOM_IShapesOperations_var aShapesOp =
290 getGeomEngine()->GetIShapesOperations(getStudyId());
291 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
294 aSelectedObject = aFindedObject; // get Object from study
297 else { // Global Selection
298 if (aShape.ShapeType() != aNeedType) {
299 aSelectedObject = GEOM::GEOM_Object::_nil();
305 myEditCurrentArgument->setText(aName);
308 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
309 myGeomGUI->getApp()->selectionMgr()->clearSelected();
310 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
311 this, SLOT(SelectionIntoArgument()));
313 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
314 myPoint = aSelectedObject;
315 if (!myPoint->_is_nil() && myDir->_is_nil())
316 GroupPoints->PushButton2->click();
318 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
319 myDir = aSelectedObject;
320 if (!myDir->_is_nil() && myPoint->_is_nil())
321 GroupPoints->PushButton1->click();
327 //=================================================================================
328 // function : SetEditCurrentArgument()
330 //=================================================================================
331 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
333 QPushButton* send = (QPushButton*)sender();
335 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
336 if (send == GroupPoints->PushButton1) {
337 myEditCurrentArgument = GroupPoints->LineEdit1;
339 GroupPoints->PushButton2->setDown(false);
340 GroupPoints->LineEdit2->setEnabled(false);
342 globalSelection(GEOM_POINT); // to break previous local selection
343 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
345 else if (send == GroupPoints->PushButton2) {
346 myEditCurrentArgument = GroupPoints->LineEdit2;
348 GroupPoints->PushButton1->setDown(false);
349 GroupPoints->LineEdit1->setEnabled(false);
351 globalSelection(GEOM_LINE); // to break previous local selection
352 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
354 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
355 this, SLOT(SelectionIntoArgument()));
358 myEditCurrentArgument->setEnabled(true);
359 myEditCurrentArgument->setFocus();
360 // after setFocus(), because it will be setDown(false) when loses focus
363 // seems we need it only to avoid preview disappearing, caused by selection mode change
367 //=================================================================================
368 // function : LineEditReturnPressed()
370 //=================================================================================
371 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
373 QLineEdit* send = (QLineEdit*)sender();
374 if (send == GroupPoints->LineEdit1 ||
375 send == GroupPoints->LineEdit2) {
376 myEditCurrentArgument = send;
377 GEOMBase_Skeleton::LineEditReturnPressed();
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
387 GEOMBase_Skeleton::ActivateThisDialog();
389 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
390 this, SLOT( SelectionIntoArgument() ) );
392 ConstructorsClicked( getConstructorId() );
395 //=================================================================================
396 // function : enterEvent()
398 //=================================================================================
399 void PrimitiveGUI_CylinderDlg::enterEvent (QEvent*)
401 if (!mainFrame()->GroupConstructors->isEnabled())
402 ActivateThisDialog();
405 //=================================================================================
406 // function : ValueChangedInSpinBox()
408 //=================================================================================
409 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox()
414 //=================================================================================
415 // function : createOperation
417 //=================================================================================
418 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
420 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
423 //=================================================================================
424 // function : isValid
426 //=================================================================================
427 bool PrimitiveGUI_CylinderDlg::isValid (QString& msg)
430 if( getConstructorId() == 0 )
432 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
433 ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
435 else if( getConstructorId() == 1 )
437 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
438 ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
440 ok = fabs( getHeight() ) > Precision::Confusion() && ok;
441 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) && ok : ok;
444 //=================================================================================
445 // function : execute
447 //=================================================================================
448 bool PrimitiveGUI_CylinderDlg::execute (ObjectList& objects)
452 GEOM::GEOM_Object_var anObj;
454 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
456 switch (getConstructorId()) {
458 if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) {
459 anObj = anOper->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
460 if (!anObj->_is_nil() && !IsPreview())
462 QStringList aParameters;
463 aParameters << GroupPoints->SpinBox_DX->text();
464 aParameters << GroupPoints->SpinBox_DY->text();
465 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
471 anObj = anOper->MakeCylinderRH(getRadius(), getHeight());
472 if (!anObj->_is_nil() && !IsPreview())
474 QStringList aParameters;
475 aParameters << GroupDimensions->SpinBox_DX->text();
476 aParameters << GroupDimensions->SpinBox_DY->text();
477 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
483 if (!anObj->_is_nil())
484 objects.push_back(anObj._retn());
489 //=================================================================================
490 // function : getRadius()
492 //=================================================================================
493 double PrimitiveGUI_CylinderDlg::getRadius() const
495 int aConstructorId = getConstructorId();
496 if (aConstructorId == 0)
497 return GroupPoints->SpinBox_DX->value();
498 else if (aConstructorId == 1)
499 return GroupDimensions->SpinBox_DX->value();
503 //=================================================================================
504 // function : getHeight()
506 //=================================================================================
507 double PrimitiveGUI_CylinderDlg::getHeight() const
509 int aConstructorId = getConstructorId();
510 if (aConstructorId == 0)
511 return GroupPoints->SpinBox_DY->value();
512 else if (aConstructorId == 1)
513 return GroupDimensions->SpinBox_DY->value();
517 //=================================================================================
518 // function : addSubshapeToStudy
519 // purpose : virtual method to add new SubObjects if local selection
520 //=================================================================================
521 void PrimitiveGUI_CylinderDlg::addSubshapesToStudy()
523 QMap<QString, GEOM::GEOM_Object_var> objMap;
525 switch (getConstructorId()) {
527 objMap[GroupPoints->LineEdit1->text()] = myPoint;
528 objMap[GroupPoints->LineEdit2->text()] = myDir;
533 addSubshapesToFather(objMap);