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_ConeDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "PrimitiveGUI_ConeDlg.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_ConeDlg()
52 // purpose : Constructs a PrimitiveGUI_ConeDlg 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_ConeDlg::PrimitiveGUI_ConeDlg(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_CONE_PV")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
64 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_CONE_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_CONE"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->setPixmap(image1);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_2Sel3Spin(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_I").arg("1"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
80 GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
81 GroupPoints->PushButton1->setPixmap(image2);
82 GroupPoints->PushButton2->setPixmap(image2);
84 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
85 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
86 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
87 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
88 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
90 Layout1->addWidget(GroupPoints, 2, 0);
91 Layout1->addWidget(GroupDimensions, 2, 0);
92 /***************************************************************/
94 setHelpFileName( "create_cone_page.html" );
100 //=================================================================================
101 // function : ~PrimitiveGUI_ConeDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
106 // no need to delete child widgets, Qt does it all for us
110 //=================================================================================
113 //=================================================================================
114 void PrimitiveGUI_ConeDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
118 GroupPoints->LineEdit1->setReadOnly( true );
119 GroupPoints->LineEdit2->setReadOnly( true );
121 myPoint = myDir = GEOM::GEOM_Object::_nil();
123 /* Get setting of step value from file configuration */
124 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
125 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
127 /* min, max, step and decimals for spin boxes & initial values */
128 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
129 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
130 GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
131 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
132 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
133 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
135 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
136 GroupPoints->SpinBox_DX->SetValue(aRadius1);
137 GroupPoints->SpinBox_DY->SetValue(aRadius2);
138 GroupPoints->SpinBox_DZ->SetValue(aHeight);
139 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
140 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
141 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
143 /* signals and slots connections */
144 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
145 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
148 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
158 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
159 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
168 connect(myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
171 initName( tr( "GEOM_CONE" ) );
172 ConstructorsClicked(0);
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
182 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
184 switch(constructorId)
188 // globalSelection( GEOM_POINT );
189 globalSelection(); // to break prvious local selection
190 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
191 GroupDimensions->hide();
195 myEditCurrentArgument = GroupPoints->LineEdit1;
196 GroupPoints->LineEdit1->setText(tr(""));
197 GroupPoints->LineEdit2->setText(tr(""));
198 myPoint = myDir = GEOM::GEOM_Object::_nil();
200 connect(myGeomGUI->getApp()->selectionMgr(),
201 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
207 globalSelection(); // close local contexts, if any
209 GroupDimensions->show();
218 //=================================================================================
219 // function : ClickOnOk()
221 //=================================================================================
222 void PrimitiveGUI_ConeDlg::ClickOnOk()
224 if ( ClickOnApply() )
229 //=================================================================================
230 // function : ClickOnApply()
232 //=================================================================================
233 bool PrimitiveGUI_ConeDlg::ClickOnApply()
239 ConstructorsClicked( getConstructorId() );
244 //=======================================================================
245 // function : ClickOnCancel()
247 //=======================================================================
248 void PrimitiveGUI_ConeDlg::ClickOnCancel()
250 GEOMBase_Skeleton::ClickOnCancel();
254 //=================================================================================
255 // function : SelectionIntoArgument()
256 // purpose : Called when selection as changed or other case
257 //=================================================================================
258 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
260 if (getConstructorId() != 0)
263 if (IObjectCount() != 1)
265 if (myEditCurrentArgument == GroupPoints->LineEdit1)
266 myPoint = GEOM::GEOM_Object::_nil();
267 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
268 myDir = GEOM::GEOM_Object::_nil();
273 Standard_Boolean testResult = Standard_False;
274 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
276 if(!testResult || CORBA::is_nil( aSelectedObject ))
280 QString aName = GEOMBase::GetName( aSelectedObject );
282 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
284 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
285 if (myEditCurrentArgument == GroupPoints->LineEdit2)
286 aNeedType = TopAbs_EDGE;
288 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
289 TColStd_IndexedMapOfInteger aMap;
290 aSelMgr->GetIndexes( firstIObject(), aMap );
291 if (aMap.Extent() == 1)
293 int anIndex = aMap(1);
294 if (aNeedType == TopAbs_EDGE)
295 aName.append(":edge_" + QString::number(anIndex));
297 aName.append(":vertex_" + QString::number(anIndex));
299 //Find SubShape Object in Father
300 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
302 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
303 GEOM::GEOM_IShapesOperations_var aShapesOp =
304 getGeomEngine()->GetIShapesOperations(getStudyId());
305 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
308 aSelectedObject = aFindedObject; // get Object from study
312 if (aShape.ShapeType() != aNeedType) {
313 aSelectedObject = GEOM::GEOM_Object::_nil();
319 myEditCurrentArgument->setText(aName);
321 if (myEditCurrentArgument == GroupPoints->LineEdit1)
322 myPoint = aSelectedObject;
323 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
324 myDir = aSelectedObject;
329 //=================================================================================
330 // function : SetEditCurrentArgument()
332 //=================================================================================
333 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
335 QPushButton* send = (QPushButton*)sender();
337 if(send == GroupPoints->PushButton1) {
338 myEditCurrentArgument = GroupPoints->LineEdit1;
339 globalSelection( GEOM_POINT ); // to break prvious local selection
340 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
342 else if(send == GroupPoints->PushButton2) {
343 myEditCurrentArgument = GroupPoints->LineEdit2;
344 globalSelection( GEOM_LINE );// to break prvious local selection
345 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
348 myEditCurrentArgument->setFocus();
349 SelectionIntoArgument();
353 //=================================================================================
354 // function : LineEditReturnPressed()
356 //=================================================================================
357 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
359 QLineEdit* send = (QLineEdit*)sender();
360 if(send == GroupPoints->LineEdit1 ||
361 send == GroupPoints->LineEdit2)
363 myEditCurrentArgument = send;
364 GEOMBase_Skeleton::LineEditReturnPressed();
368 //=================================================================================
369 // function : ActivateThisDialog()
371 //=================================================================================
372 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
374 GEOMBase_Skeleton::ActivateThisDialog();
375 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
376 this, SLOT(SelectionIntoArgument()));
378 ConstructorsClicked(getConstructorId());
381 //=================================================================================
382 // function : DeactivateActiveDialog()
383 // purpose : public slot to deactivate if active
384 //=================================================================================
385 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
387 GEOMBase_Skeleton::DeactivateActiveDialog();
391 //=================================================================================
392 // function : enterEvent()
394 //=================================================================================
395 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
397 if ( !GroupConstructors->isEnabled() )
398 ActivateThisDialog();
402 //=================================================================================
403 // function : ValueChangedInSpinBox()
405 //=================================================================================
406 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
412 //=================================================================================
413 // function : createOperation
415 //=================================================================================
416 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
418 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
421 //=================================================================================
422 // function : isValid
424 //=================================================================================
425 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
427 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
430 //=================================================================================
431 // function : execute
433 //=================================================================================
434 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
438 GEOM::GEOM_Object_var anObj;
440 switch ( getConstructorId() )
444 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
445 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
456 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
464 if ( !anObj->_is_nil() )
465 objects.push_back( anObj._retn() );
470 //=================================================================================
471 // function : closeEvent
473 //=================================================================================
474 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
476 // myGeomGUI->SetState( -1 );
477 GEOMBase_Skeleton::closeEvent( e );
481 //=================================================================================
482 // function : getRadius1()
484 //=================================================================================
485 double PrimitiveGUI_ConeDlg::getRadius1() const
487 int aConstructorId = getConstructorId();
488 if (aConstructorId == 0)
489 return GroupPoints->SpinBox_DX->GetValue();
490 else if (aConstructorId == 1)
491 return GroupDimensions->SpinBox_DX->GetValue();
496 //=================================================================================
497 // function : getRadius2()
499 //=================================================================================
500 double PrimitiveGUI_ConeDlg::getRadius2() const
502 int aConstructorId = getConstructorId();
503 if (aConstructorId == 0)
504 return GroupPoints->SpinBox_DY->GetValue();
505 else if (aConstructorId == 1)
506 return GroupDimensions->SpinBox_DY->GetValue();
511 //=================================================================================
512 // function : getRadius2()
514 //=================================================================================
515 double PrimitiveGUI_ConeDlg::getHeight() const
517 int aConstructorId = getConstructorId();
518 if (aConstructorId == 0)
519 return GroupPoints->SpinBox_DZ->GetValue();
520 else if (aConstructorId == 1)
521 return GroupDimensions->SpinBox_DZ->GetValue();
525 //=================================================================================
526 // function : addSubshapeToStudy
527 // purpose : virtual method to add new SubObjects if local selection
528 //=================================================================================
529 void PrimitiveGUI_ConeDlg::addSubshapesToStudy()
531 QMap<QString, GEOM::GEOM_Object_var> objMap;
533 switch (getConstructorId())
536 objMap[GroupPoints->LineEdit1->text()] = myPoint;
537 objMap[GroupPoints->LineEdit2->text()] = myDir;
542 addSubshapesToFather( objMap );