1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : PrimitiveGUI_CylinderDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "PrimitiveGUI_CylinderDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
50 //=================================================================================
51 // class : PrimitiveGUI_CylinderDlg()
52 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58 const char* name, bool modal, WFlags fl)
59 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
64 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_CYLINDER_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->setPixmap(image1);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
80 GroupPoints->PushButton1->setPixmap(image2);
81 GroupPoints->PushButton2->setPixmap(image2);
83 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
84 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
85 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
86 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
88 Layout1->addWidget(GroupPoints, 2, 0);
89 Layout1->addWidget(GroupDimensions, 2, 0);
90 /***************************************************************/
92 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
108 //=================================================================================
111 //=================================================================================
112 void PrimitiveGUI_CylinderDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
116 GroupPoints->LineEdit1->setReadOnly( true );
117 GroupPoints->LineEdit2->setReadOnly( true );
119 myPoint = myDir = GEOM::GEOM_Object::_nil();
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
125 /* min, max, step and decimals for spin boxes & initial values */
126 /* First constructor : radius */
127 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
128 /* First constructor : algebric height */
129 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
130 /* Second constructor : radius */
131 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
132 /* Second constructor : algebric height */
133 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
135 GroupPoints->SpinBox_DX->SetValue(100.0);
136 GroupPoints->SpinBox_DY->SetValue(300.0);
137 GroupDimensions->SpinBox_DX->SetValue(100.0);
138 GroupDimensions->SpinBox_DY->SetValue(300.0);
140 /* signals and slots connections */
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
161 connect(myGeomGUI->getApp()->selectionMgr(),
162 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
164 initName( tr( "GEOM_CYLINDER" ) );
165 ConstructorsClicked(0);
169 //=================================================================================
170 // function : ConstructorsClicked()
171 // purpose : Radio button management
172 //=================================================================================
173 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
175 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
177 switch (constructorId)
181 globalSelection( GEOM_POINT ); // to break previous local selection
182 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
184 GroupDimensions->hide();
188 myEditCurrentArgument = GroupPoints->LineEdit1;
189 GroupPoints->LineEdit1->setText(tr(""));
190 GroupPoints->LineEdit2->setText(tr(""));
191 myPoint = myDir = GEOM::GEOM_Object::_nil();
193 connect(myGeomGUI->getApp()->selectionMgr(),
194 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
200 globalSelection(); // close local contexts, if any
202 GroupDimensions->show();
211 //=================================================================================
212 // function : ClickOnOk()
214 //=================================================================================
215 void PrimitiveGUI_CylinderDlg::ClickOnOk()
217 if ( ClickOnApply() )
222 //=================================================================================
223 // function : ClickOnApply()
225 //=================================================================================
226 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
232 ConstructorsClicked( getConstructorId() );
237 //=======================================================================
238 // function : ClickOnCancel()
240 //=======================================================================
241 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
243 GEOMBase_Skeleton::ClickOnCancel();
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
253 if (getConstructorId() != 0)
256 myEditCurrentArgument->setText("");
258 if (IObjectCount() != 1)
260 if (myEditCurrentArgument == GroupPoints->LineEdit1)
261 myPoint = GEOM::GEOM_Object::_nil();
262 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
263 myDir = GEOM::GEOM_Object::_nil();
268 Standard_Boolean testResult = Standard_False;
269 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
271 if (!testResult || CORBA::is_nil(aSelectedObject))
274 QString aName = GEOMBase::GetName(aSelectedObject);
276 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
278 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
279 if (myEditCurrentArgument == GroupPoints->LineEdit2)
280 aNeedType = TopAbs_EDGE;
282 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
283 TColStd_IndexedMapOfInteger aMap;
284 aSelMgr->GetIndexes(firstIObject(), aMap);
285 if (aMap.Extent() == 1) // Local Selection
287 int anIndex = aMap(1);
288 if (aNeedType == TopAbs_EDGE)
289 aName.append(":edge_" + QString::number(anIndex));
291 aName.append(":vertex_" + QString::number(anIndex));
293 //Find SubShape Object in Father
294 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
296 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
297 GEOM::GEOM_IShapesOperations_var aShapesOp =
298 getGeomEngine()->GetIShapesOperations(getStudyId());
299 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
302 aSelectedObject = aFindedObject; // get Object from study
304 else // Global Selection
306 if (aShape.ShapeType() != aNeedType) {
307 aSelectedObject = GEOM::GEOM_Object::_nil();
313 myEditCurrentArgument->setText(aName);
315 if (myEditCurrentArgument == GroupPoints->LineEdit1)
316 myPoint = aSelectedObject;
317 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
318 myDir = aSelectedObject;
322 //=================================================================================
323 // function : SetEditCurrentArgument()
325 //=================================================================================
326 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
328 QPushButton* send = (QPushButton*)sender();
330 if (send == GroupPoints->PushButton1) {
331 myEditCurrentArgument = GroupPoints->LineEdit1;
332 globalSelection( GEOM_POINT ); // to break previous local selection
333 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
335 else if (send == GroupPoints->PushButton2) {
336 myEditCurrentArgument = GroupPoints->LineEdit2;
337 globalSelection( GEOM_LINE ); // to break previous local selection
338 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
341 myEditCurrentArgument->setFocus();
342 SelectionIntoArgument();
346 //=================================================================================
347 // function : LineEditReturnPressed()
349 //=================================================================================
350 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
352 QLineEdit* send = (QLineEdit*)sender();
353 if(send == GroupPoints->LineEdit1 ||
354 send == GroupPoints->LineEdit2)
356 myEditCurrentArgument = send;
357 GEOMBase_Skeleton::LineEditReturnPressed();
361 //=================================================================================
362 // function : ActivateThisDialog()
364 //=================================================================================
365 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
367 GEOMBase_Skeleton::ActivateThisDialog();
368 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
369 this, SLOT(SelectionIntoArgument()));
371 ConstructorsClicked(getConstructorId());
374 //=================================================================================
375 // function : enterEvent()
377 //=================================================================================
378 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
380 if ( !GroupConstructors->isEnabled() )
381 ActivateThisDialog();
385 //=================================================================================
386 // function : DeactivateActiveDialog()
387 // purpose : public slot to deactivate if active
388 //=================================================================================
389 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
391 GEOMBase_Skeleton::DeactivateActiveDialog();
395 //=================================================================================
396 // function : ValueChangedInSpinBox
398 //=================================================================================
399 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
405 //=================================================================================
406 // function : createOperation
408 //=================================================================================
409 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
411 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
415 //=================================================================================
416 // function : isValid
418 //=================================================================================
419 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
421 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
424 //=================================================================================
425 // function : execute
427 //=================================================================================
428 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
432 GEOM::GEOM_Object_var anObj;
434 switch ( getConstructorId() )
438 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
439 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
446 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
453 if ( !anObj->_is_nil() )
454 objects.push_back( anObj._retn() );
459 //=================================================================================
460 // function : closeEvent
462 //=================================================================================
463 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
465 GEOMBase_Skeleton::closeEvent( e );
469 //=================================================================================
470 // function : getRadius()
472 //=================================================================================
473 double PrimitiveGUI_CylinderDlg::getRadius() const
475 int aConstructorId = getConstructorId();
476 if (aConstructorId == 0)
477 return GroupPoints->SpinBox_DX->GetValue();
478 else if (aConstructorId == 1)
479 return GroupDimensions->SpinBox_DX->GetValue();
483 //=================================================================================
484 // function : getHeight()
486 //=================================================================================
487 double PrimitiveGUI_CylinderDlg::getHeight() const
489 int aConstructorId = getConstructorId();
490 if (aConstructorId == 0)
491 return GroupPoints->SpinBox_DY->GetValue();
492 else if (aConstructorId == 1)
493 return GroupDimensions->SpinBox_DY->GetValue();
497 //=================================================================================
498 // function : addSubshapeToStudy
499 // purpose : virtual method to add new SubObjects if local selection
500 //=================================================================================
501 void PrimitiveGUI_CylinderDlg::addSubshapesToStudy()
503 QMap<QString, GEOM::GEOM_Object_var> objMap;
505 switch (getConstructorId())
508 objMap[GroupPoints->LineEdit1->text()] = myPoint;
509 objMap[GroupPoints->LineEdit2->text()] = myDir;
514 addSubshapesToFather( objMap );