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
22 // File : PrimitiveGUI_ConeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_ConeDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : PrimitiveGUI_ConeDlg()
48 // purpose : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_PV" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_DXYZ" ) ) );
59 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_CONE_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CONE" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setIcon( image1 );
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel3Spin( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
74 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
75 GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
76 GroupPoints->TextLabel5->setText( tr( "GEOM_HEIGHT" ) );
77 GroupPoints->PushButton1->setIcon( image2 );
78 GroupPoints->PushButton2->setIcon( image2 );
80 GroupDimensions = new DlgRef_3Spin( centralWidget() );
81 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
82 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
83 GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
84 GroupDimensions->TextLabel3->setText( tr( "GEOM_HEIGHT" ) );
86 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
87 layout->setMargin( 0 ); layout->setSpacing( 6 );
88 layout->addWidget( GroupPoints );
89 layout->addWidget( GroupDimensions );
90 /***************************************************************/
92 setHelpFileName( "create_cone_page.html" );
98 //=================================================================================
99 // function : ~PrimitiveGUI_ConeDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
104 // no need to delete child widgets, Qt does it all for us
108 //=================================================================================
111 //=================================================================================
112 void PrimitiveGUI_ConeDlg::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 initSpinBox( GroupPoints->SpinBox_DX, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
127 initSpinBox( GroupPoints->SpinBox_DY, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
128 initSpinBox( GroupPoints->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
129 initSpinBox( GroupDimensions->SpinBox_DX, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
130 initSpinBox( GroupDimensions->SpinBox_DY, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
131 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
133 double aRadius1( 100.0 ), aRadius2( 0.0 ), aHeight( 300.0 );
134 GroupPoints->SpinBox_DX->setValue( aRadius1 );
135 GroupPoints->SpinBox_DY->setValue( aRadius2 );
136 GroupPoints->SpinBox_DZ->setValue( aHeight );
137 GroupDimensions->SpinBox_DX->setValue( aRadius1 );
138 GroupDimensions->SpinBox_DY->setValue( aRadius2 );
139 GroupDimensions->SpinBox_DZ->setValue( aHeight );
141 /* signals and slots connections */
142 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
143 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
145 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
147 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
148 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
150 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
151 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
153 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
154 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
155 connect( GroupPoints->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
156 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
157 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
158 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 ) ) );
169 connect( myGeomGUI->getApp()->selectionMgr(),
170 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
172 initName( tr( "GEOM_CONE" ) );
174 ConstructorsClicked( 0 );
178 //=================================================================================
179 // function : ConstructorsClicked()
180 // purpose : Radio button management
181 //=================================================================================
182 void PrimitiveGUI_ConeDlg::ConstructorsClicked( int constructorId )
184 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
186 switch( constructorId ) {
189 //globalSelection( GEOM_POINT );
190 globalSelection(); // to break prvious local selection
191 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
193 GroupDimensions->hide();
196 myEditCurrentArgument = GroupPoints->LineEdit1;
197 GroupPoints->LineEdit1->setText( "" );
198 GroupPoints->LineEdit2->setText( "" );
199 myPoint = myDir = GEOM::GEOM_Object::_nil();
201 connect( myGeomGUI->getApp()->selectionMgr(),
202 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
207 globalSelection(); // close local contexts, if any
210 GroupDimensions->show();
216 qApp->processEvents();
218 resize( minimumSize() );
224 //=================================================================================
225 // function : ClickOnOk()
227 //=================================================================================
228 void PrimitiveGUI_ConeDlg::ClickOnOk()
230 if ( ClickOnApply() )
235 //=================================================================================
236 // function : ClickOnApply()
238 //=================================================================================
239 bool PrimitiveGUI_ConeDlg::ClickOnApply()
245 ConstructorsClicked( getConstructorId() );
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose : Called when selection as changed or other case
253 //=================================================================================
254 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
256 if ( getConstructorId() != 0 )
259 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 ) )
275 QString aName = GEOMBase::GetName( aSelectedObject );
277 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 ) {
286 int anIndex = aMap(1);
287 if ( aNeedType == TopAbs_EDGE )
288 aName.append( ":edge_" + QString::number( anIndex ) );
290 aName.append( ":vertex_" + QString::number( anIndex ) );
292 //Find SubShape Object in Father
293 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
295 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
296 GEOM::GEOM_IShapesOperations_var aShapesOp =
297 getGeomEngine()->GetIShapesOperations( getStudyId() );
298 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
301 aSelectedObject = aFindedObject; // get Object from study
305 if ( aShape.ShapeType() != aNeedType ) {
306 aSelectedObject = GEOM::GEOM_Object::_nil();
312 myEditCurrentArgument->setText( aName );
314 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
315 myPoint = aSelectedObject;
316 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
317 myDir = aSelectedObject;
323 //=================================================================================
324 // function : SetEditCurrentArgument()
326 //=================================================================================
327 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
329 QPushButton* send = (QPushButton*)sender();
331 if ( send == GroupPoints->PushButton1 ) {
332 myEditCurrentArgument = GroupPoints->LineEdit1;
333 globalSelection( GEOM_POINT ); // to break prvious local selection
334 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
336 else if ( send == GroupPoints->PushButton2 ) {
337 myEditCurrentArgument = GroupPoints->LineEdit2;
338 globalSelection( GEOM_LINE );// to break prvious local selection
339 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
342 myEditCurrentArgument->setFocus();
343 SelectionIntoArgument();
347 //=================================================================================
348 // function : LineEditReturnPressed()
350 //=================================================================================
351 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
353 QLineEdit* send = (QLineEdit*)sender();
354 if ( send == GroupPoints->LineEdit1 ||
355 send == GroupPoints->LineEdit2 ) {
356 myEditCurrentArgument = send;
357 GEOMBase_Skeleton::LineEditReturnPressed();
362 //=================================================================================
363 // function : ActivateThisDialog()
365 //=================================================================================
366 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
368 GEOMBase_Skeleton::ActivateThisDialog();
369 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
370 this, SLOT( SelectionIntoArgument() ) );
372 ConstructorsClicked( getConstructorId() );
376 //=================================================================================
377 // function : DeactivateActiveDialog()
378 // purpose : public slot to deactivate if active
379 //=================================================================================
380 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
382 GEOMBase_Skeleton::DeactivateActiveDialog();
386 //=================================================================================
387 // function : enterEvent()
389 //=================================================================================
390 void PrimitiveGUI_ConeDlg::enterEvent( QEvent* )
392 if ( !mainFrame()->GroupConstructors->isEnabled() )
393 ActivateThisDialog();
397 //=================================================================================
398 // function : ValueChangedInSpinBox()
400 //=================================================================================
401 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
407 //=================================================================================
408 // function : createOperation
410 //=================================================================================
411 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
413 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
416 //=================================================================================
417 // function : isValid
419 //=================================================================================
420 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
422 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
425 //=================================================================================
426 // function : execute
428 //=================================================================================
429 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
433 GEOM::GEOM_Object_var anObj;
435 switch ( getConstructorId() ) {
437 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) {
438 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
447 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
454 if ( !anObj->_is_nil() )
455 objects.push_back( anObj._retn() );
461 //=================================================================================
462 // function : getRadius1()
464 //=================================================================================
465 double PrimitiveGUI_ConeDlg::getRadius1() const
467 int aConstructorId = getConstructorId();
468 if ( aConstructorId == 0 )
469 return GroupPoints->SpinBox_DX->value();
470 else if ( aConstructorId == 1 )
471 return GroupDimensions->SpinBox_DX->value();
476 //=================================================================================
477 // function : getRadius2()
479 //=================================================================================
480 double PrimitiveGUI_ConeDlg::getRadius2() const
482 int aConstructorId = getConstructorId();
483 if ( aConstructorId == 0 )
484 return GroupPoints->SpinBox_DY->value();
485 else if ( aConstructorId == 1 )
486 return GroupDimensions->SpinBox_DY->value();
491 //=================================================================================
492 // function : getRadius2()
494 //=================================================================================
495 double PrimitiveGUI_ConeDlg::getHeight() const
497 int aConstructorId = getConstructorId();
498 if ( aConstructorId == 0 )
499 return GroupPoints->SpinBox_DZ->value();
500 else if ( aConstructorId == 1 )
501 return GroupDimensions->SpinBox_DZ->value();
505 //=================================================================================
506 // function : addSubshapeToStudy
507 // purpose : virtual method to add new SubObjects if local selection
508 //=================================================================================
509 void PrimitiveGUI_ConeDlg::addSubshapesToStudy()
511 QMap<QString, GEOM::GEOM_Object_var> objMap;
513 switch ( getConstructorId() ) {
515 objMap[GroupPoints->LineEdit1->text()] = myPoint;
516 objMap[GroupPoints->LineEdit2->text()] = myDir;
521 addSubshapesToFather( objMap );