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( "cone.htm" );
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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
185 switch(constructorId)
189 // globalSelection( GEOM_POINT );
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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
201 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
208 GroupDimensions->show();
217 //=================================================================================
218 // function : ClickOnOk()
220 //=================================================================================
221 void PrimitiveGUI_ConeDlg::ClickOnOk()
223 if ( ClickOnApply() )
228 //=================================================================================
229 // function : ClickOnApply()
231 //=================================================================================
232 bool PrimitiveGUI_ConeDlg::ClickOnApply()
238 ConstructorsClicked( getConstructorId() );
243 //=======================================================================
244 // function : ClickOnCancel()
246 //=======================================================================
247 void PrimitiveGUI_ConeDlg::ClickOnCancel()
249 GEOMBase_Skeleton::ClickOnCancel();
253 //=================================================================================
254 // function : SelectionIntoArgument()
255 // purpose : Called when selection as changed or other case
256 //=================================================================================
257 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
259 if ( getConstructorId() != 0 )
262 if(IObjectCount() != 1)
264 if(myEditCurrentArgument == GroupPoints->LineEdit1)
265 myPoint = GEOM::GEOM_Object::_nil();
266 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
267 myDir = GEOM::GEOM_Object::_nil();
272 Standard_Boolean testResult = Standard_False;
273 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
275 if(!testResult || CORBA::is_nil( aSelectedObject ))
279 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
280 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
282 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
283 TColStd_IndexedMapOfInteger aMap;
284 aSelMgr->GetIndexes( firstIObject(), aMap );
285 if ( aMap.Extent() == 1 )
287 GEOM::GEOM_IShapesOperations_var aShapesOp =
288 getGeomEngine()->GetIShapesOperations( getStudyId() );
289 int anIndex = aMap( 1 );
290 TopTools_IndexedMapOfShape aShapes;
291 TopExp::MapShapes( aShape, aShapes );
292 aShape = aShapes.FindKey( anIndex );
293 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
294 aSelMgr->clearSelected();
297 if (myEditCurrentArgument == GroupPoints->LineEdit1)
298 myPoint = aSelectedObject;
299 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
300 myDir = aSelectedObject;
306 //=================================================================================
307 // function : SetEditCurrentArgument()
309 //=================================================================================
310 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
312 QPushButton* send = (QPushButton*)sender();
314 if(send == GroupPoints->PushButton1) {
315 myEditCurrentArgument = GroupPoints->LineEdit1;
316 // globalSelection( GEOM_POINT );
317 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
319 else if(send == GroupPoints->PushButton2) {
320 myEditCurrentArgument = GroupPoints->LineEdit2;
321 // globalSelection( GEOM_LINE );
322 GEOM::GEOM_Object_var anObj;
323 localSelection( anObj, TopAbs_EDGE );
326 myEditCurrentArgument->setFocus();
327 SelectionIntoArgument();
331 //=================================================================================
332 // function : LineEditReturnPressed()
334 //=================================================================================
335 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
337 QLineEdit* send = (QLineEdit*)sender();
338 if(send == GroupPoints->LineEdit1 ||
339 send == GroupPoints->LineEdit2)
341 myEditCurrentArgument = send;
342 GEOMBase_Skeleton::LineEditReturnPressed();
347 //=================================================================================
348 // function : ActivateThisDialog()
350 //=================================================================================
351 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
353 GEOMBase_Skeleton::ActivateThisDialog();
354 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
355 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
357 ConstructorsClicked( getConstructorId() );
361 //=================================================================================
362 // function : DeactivateActiveDialog()
363 // purpose : public slot to deactivate if active
364 //=================================================================================
365 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
367 GEOMBase_Skeleton::DeactivateActiveDialog();
371 //=================================================================================
372 // function : enterEvent()
374 //=================================================================================
375 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
377 if ( !GroupConstructors->isEnabled() )
378 ActivateThisDialog();
382 //=================================================================================
383 // function : ValueChangedInSpinBox()
385 //=================================================================================
386 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
392 //=================================================================================
393 // function : createOperation
395 //=================================================================================
396 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
398 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
401 //=================================================================================
402 // function : isValid
404 //=================================================================================
405 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
407 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
410 //=================================================================================
411 // function : execute
413 //=================================================================================
414 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
418 GEOM::GEOM_Object_var anObj;
420 switch ( getConstructorId() )
424 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
425 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
436 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
444 if ( !anObj->_is_nil() )
445 objects.push_back( anObj._retn() );
450 //=================================================================================
451 // function : closeEvent
453 //=================================================================================
454 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
456 // myGeomGUI->SetState( -1 );
457 GEOMBase_Skeleton::closeEvent( e );
461 //=================================================================================
462 // function : getRadius1()
464 //=================================================================================
465 double PrimitiveGUI_ConeDlg::getRadius1() const
467 int aConstructorId = getConstructorId();
468 if (aConstructorId == 0)
469 return GroupPoints->SpinBox_DX->GetValue();
470 else if (aConstructorId == 1)
471 return GroupDimensions->SpinBox_DX->GetValue();
476 //=================================================================================
477 // function : getRadius2()
479 //=================================================================================
480 double PrimitiveGUI_ConeDlg::getRadius2() const
482 int aConstructorId = getConstructorId();
483 if (aConstructorId == 0)
484 return GroupPoints->SpinBox_DY->GetValue();
485 else if (aConstructorId == 1)
486 return GroupDimensions->SpinBox_DY->GetValue();
491 //=================================================================================
492 // function : getRadius2()
494 //=================================================================================
495 double PrimitiveGUI_ConeDlg::getHeight() const
497 int aConstructorId = getConstructorId();
498 if (aConstructorId == 0)
499 return GroupPoints->SpinBox_DZ->GetValue();
500 else if (aConstructorId == 1)
501 return GroupDimensions->SpinBox_DZ->GetValue();