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
24 // File : PrimitiveGUI_ConeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_ConeDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
51 //=================================================================================
52 // class : PrimitiveGUI_ConeDlg()
53 // purpose : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_PV")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
65 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 setCaption(tr("GEOM_CONE_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_CONE"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->setPixmap(image1);
73 RadioButton3->close(TRUE);
75 GroupPoints = new DlgRef_2Sel3Spin(this, "GroupPoints");
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
80 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
81 GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
82 GroupPoints->PushButton1->setPixmap(image2);
83 GroupPoints->PushButton2->setPixmap(image2);
85 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
86 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
87 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
88 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
89 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
91 Layout1->addWidget(GroupPoints, 2, 0);
92 Layout1->addWidget(GroupDimensions, 2, 0);
93 /***************************************************************/
95 setHelpFileName( "create_cone_page.html" );
101 //=================================================================================
102 // function : ~PrimitiveGUI_ConeDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
107 // no need to delete child widgets, Qt does it all for us
111 //=================================================================================
114 //=================================================================================
115 void PrimitiveGUI_ConeDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
119 GroupPoints->LineEdit1->setReadOnly( true );
120 GroupPoints->LineEdit2->setReadOnly( true );
122 myPoint = myDir = GEOM::GEOM_Object::_nil();
124 /* Get setting of step value from file configuration */
125 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
126 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
128 /* min, max, step and decimals for spin boxes & initial values */
129 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
130 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
131 GroupPoints->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
132 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
133 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, DBL_DIGITS_DISPLAY);
134 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
136 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
137 GroupPoints->SpinBox_DX->SetValue(aRadius1);
138 GroupPoints->SpinBox_DY->SetValue(aRadius2);
139 GroupPoints->SpinBox_DZ->SetValue(aHeight);
140 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
141 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
142 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
144 /* signals and slots connections */
145 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
146 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
147 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
158 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
159 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
160 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
169 connect(myGeomGUI->getApp()->selectionMgr(),
170 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
172 initName( tr( "GEOM_CONE" ) );
173 ConstructorsClicked(0);
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose : Radio button management
180 //=================================================================================
181 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
183 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
185 switch(constructorId)
189 // globalSelection( GEOM_POINT );
190 globalSelection(); // to break prvious local selection
191 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
192 GroupDimensions->hide();
196 myEditCurrentArgument = GroupPoints->LineEdit1;
197 GroupPoints->LineEdit1->setText(tr(""));
198 GroupPoints->LineEdit2->setText(tr(""));
199 myPoint = myDir = GEOM::GEOM_Object::_nil();
201 connect(myGeomGUI->getApp()->selectionMgr(),
202 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
208 globalSelection(); // close local contexts, if any
210 GroupDimensions->show();
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void PrimitiveGUI_ConeDlg::ClickOnOk()
225 if ( ClickOnApply() )
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool PrimitiveGUI_ConeDlg::ClickOnApply()
240 ConstructorsClicked( getConstructorId() );
245 //=======================================================================
246 // function : ClickOnCancel()
248 //=======================================================================
249 void PrimitiveGUI_ConeDlg::ClickOnCancel()
251 GEOMBase_Skeleton::ClickOnCancel();
255 //=================================================================================
256 // function : SelectionIntoArgument()
257 // purpose : Called when selection as changed or other case
258 //=================================================================================
259 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
261 if (getConstructorId() != 0)
264 if (IObjectCount() != 1)
266 if (myEditCurrentArgument == GroupPoints->LineEdit1)
267 myPoint = GEOM::GEOM_Object::_nil();
268 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
269 myDir = GEOM::GEOM_Object::_nil();
274 Standard_Boolean testResult = Standard_False;
275 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
277 if(!testResult || CORBA::is_nil( aSelectedObject ))
281 QString aName = GEOMBase::GetName( aSelectedObject );
283 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
285 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
286 if (myEditCurrentArgument == GroupPoints->LineEdit2)
287 aNeedType = TopAbs_EDGE;
289 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
290 TColStd_IndexedMapOfInteger aMap;
291 aSelMgr->GetIndexes( firstIObject(), aMap );
292 if (aMap.Extent() == 1)
294 int anIndex = aMap(1);
295 if (aNeedType == TopAbs_EDGE)
296 aName.append(":edge_" + QString::number(anIndex));
298 aName.append(":vertex_" + QString::number(anIndex));
300 //Find SubShape Object in Father
301 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
303 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
304 GEOM::GEOM_IShapesOperations_var aShapesOp =
305 getGeomEngine()->GetIShapesOperations(getStudyId());
306 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
309 aSelectedObject = aFindedObject; // get Object from study
313 if (aShape.ShapeType() != aNeedType) {
314 aSelectedObject = GEOM::GEOM_Object::_nil();
320 myEditCurrentArgument->setText(aName);
322 if (myEditCurrentArgument == GroupPoints->LineEdit1)
323 myPoint = aSelectedObject;
324 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
325 myDir = aSelectedObject;
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
338 if(send == GroupPoints->PushButton1) {
339 myEditCurrentArgument = GroupPoints->LineEdit1;
340 globalSelection( GEOM_POINT ); // to break prvious local selection
341 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
343 else if(send == GroupPoints->PushButton2) {
344 myEditCurrentArgument = GroupPoints->LineEdit2;
345 globalSelection( GEOM_LINE );// to break prvious local selection
346 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
349 myEditCurrentArgument->setFocus();
350 SelectionIntoArgument();
354 //=================================================================================
355 // function : LineEditReturnPressed()
357 //=================================================================================
358 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
360 QLineEdit* send = (QLineEdit*)sender();
361 if(send == GroupPoints->LineEdit1 ||
362 send == GroupPoints->LineEdit2)
364 myEditCurrentArgument = send;
365 GEOMBase_Skeleton::LineEditReturnPressed();
369 //=================================================================================
370 // function : ActivateThisDialog()
372 //=================================================================================
373 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
375 GEOMBase_Skeleton::ActivateThisDialog();
376 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
377 this, SLOT(SelectionIntoArgument()));
379 ConstructorsClicked(getConstructorId());
382 //=================================================================================
383 // function : DeactivateActiveDialog()
384 // purpose : public slot to deactivate if active
385 //=================================================================================
386 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
388 GEOMBase_Skeleton::DeactivateActiveDialog();
392 //=================================================================================
393 // function : enterEvent()
395 //=================================================================================
396 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
398 if ( !GroupConstructors->isEnabled() )
399 ActivateThisDialog();
403 //=================================================================================
404 // function : ValueChangedInSpinBox()
406 //=================================================================================
407 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
413 //=================================================================================
414 // function : createOperation
416 //=================================================================================
417 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
419 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
422 //=================================================================================
423 // function : isValid
425 //=================================================================================
426 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
428 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
431 //=================================================================================
432 // function : execute
434 //=================================================================================
435 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
439 GEOM::GEOM_Object_var anObj;
441 switch ( getConstructorId() )
445 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
446 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
457 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
465 if ( !anObj->_is_nil() )
466 objects.push_back( anObj._retn() );
471 //=================================================================================
472 // function : closeEvent
474 //=================================================================================
475 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
477 // myGeomGUI->SetState( -1 );
478 GEOMBase_Skeleton::closeEvent( e );
482 //=================================================================================
483 // function : getRadius1()
485 //=================================================================================
486 double PrimitiveGUI_ConeDlg::getRadius1() const
488 int aConstructorId = getConstructorId();
489 if (aConstructorId == 0)
490 return GroupPoints->SpinBox_DX->GetValue();
491 else if (aConstructorId == 1)
492 return GroupDimensions->SpinBox_DX->GetValue();
497 //=================================================================================
498 // function : getRadius2()
500 //=================================================================================
501 double PrimitiveGUI_ConeDlg::getRadius2() const
503 int aConstructorId = getConstructorId();
504 if (aConstructorId == 0)
505 return GroupPoints->SpinBox_DY->GetValue();
506 else if (aConstructorId == 1)
507 return GroupDimensions->SpinBox_DY->GetValue();
512 //=================================================================================
513 // function : getRadius2()
515 //=================================================================================
516 double PrimitiveGUI_ConeDlg::getHeight() const
518 int aConstructorId = getConstructorId();
519 if (aConstructorId == 0)
520 return GroupPoints->SpinBox_DZ->GetValue();
521 else if (aConstructorId == 1)
522 return GroupDimensions->SpinBox_DZ->GetValue();
526 //=================================================================================
527 // function : addSubshapeToStudy
528 // purpose : virtual method to add new SubObjects if local selection
529 //=================================================================================
530 void PrimitiveGUI_ConeDlg::addSubshapesToStudy()
532 QMap<QString, GEOM::GEOM_Object_var> objMap;
534 switch (getConstructorId())
537 objMap[GroupPoints->LineEdit1->text()] = myPoint;
538 objMap[GroupPoints->LineEdit2->text()] = myDir;
543 addSubshapesToFather( objMap );