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() ) );
160 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
162 connect( myGeomGUI->getApp()->selectionMgr(),
163 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
165 initName( tr( "GEOM_CONE" ) );
167 setConstructorId( 1 ); // simplest constructor
168 ConstructorsClicked( 1 );
172 //=================================================================================
173 // function : SetDoubleSpinBoxStep()
174 // purpose : Double spin box management
175 //=================================================================================
176 void PrimitiveGUI_ConeDlg::SetDoubleSpinBoxStep( double step )
178 GroupPoints->SpinBox_DX->setSingleStep(step);
179 GroupPoints->SpinBox_DY->setSingleStep(step);
180 GroupPoints->SpinBox_DZ->setSingleStep(step);
181 GroupDimensions->SpinBox_DX->setSingleStep(step);
182 GroupDimensions->SpinBox_DY->setSingleStep(step);
183 GroupDimensions->SpinBox_DZ->setSingleStep(step);
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void PrimitiveGUI_ConeDlg::ConstructorsClicked( int constructorId )
192 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
194 switch( constructorId ) {
197 //globalSelection( GEOM_POINT );
198 globalSelection(); // to break prvious local selection
199 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
201 GroupDimensions->hide();
204 myEditCurrentArgument = GroupPoints->LineEdit1;
205 GroupPoints->LineEdit1->setText( "" );
206 GroupPoints->LineEdit2->setText( "" );
207 myPoint = myDir = GEOM::GEOM_Object::_nil();
209 connect( myGeomGUI->getApp()->selectionMgr(),
210 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
215 globalSelection(); // close local contexts, if any
218 GroupDimensions->show();
224 qApp->processEvents();
226 resize( minimumSize() );
232 //=================================================================================
233 // function : ClickOnOk()
235 //=================================================================================
236 void PrimitiveGUI_ConeDlg::ClickOnOk()
238 if ( ClickOnApply() )
243 //=================================================================================
244 // function : ClickOnApply()
246 //=================================================================================
247 bool PrimitiveGUI_ConeDlg::ClickOnApply()
253 ConstructorsClicked( getConstructorId() );
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
264 if ( getConstructorId() != 0 )
267 if ( IObjectCount() != 1 ) {
268 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
269 myPoint = GEOM::GEOM_Object::_nil();
270 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
271 myDir = GEOM::GEOM_Object::_nil();
276 Standard_Boolean testResult = Standard_False;
277 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
279 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
283 QString aName = GEOMBase::GetName( aSelectedObject );
285 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
286 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
287 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
288 aNeedType = TopAbs_EDGE;
290 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
291 TColStd_IndexedMapOfInteger aMap;
292 aSelMgr->GetIndexes( firstIObject(), aMap );
293 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;
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
337 QPushButton* send = (QPushButton*)sender();
339 if ( send == GroupPoints->PushButton1 ) {
340 myEditCurrentArgument = GroupPoints->LineEdit1;
341 globalSelection( GEOM_POINT ); // to break prvious local selection
342 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
344 else if ( send == GroupPoints->PushButton2 ) {
345 myEditCurrentArgument = GroupPoints->LineEdit2;
346 globalSelection( GEOM_LINE );// to break prvious local selection
347 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
350 myEditCurrentArgument->setFocus();
351 SelectionIntoArgument();
355 //=================================================================================
356 // function : LineEditReturnPressed()
358 //=================================================================================
359 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
361 QLineEdit* send = (QLineEdit*)sender();
362 if ( send == GroupPoints->LineEdit1 ||
363 send == GroupPoints->LineEdit2 ) {
364 myEditCurrentArgument = send;
365 GEOMBase_Skeleton::LineEditReturnPressed();
370 //=================================================================================
371 // function : ActivateThisDialog()
373 //=================================================================================
374 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
376 GEOMBase_Skeleton::ActivateThisDialog();
377 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
378 this, SLOT( SelectionIntoArgument() ) );
380 ConstructorsClicked( getConstructorId() );
384 //=================================================================================
385 // function : DeactivateActiveDialog()
386 // purpose : public slot to deactivate if active
387 //=================================================================================
388 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
390 GEOMBase_Skeleton::DeactivateActiveDialog();
394 //=================================================================================
395 // function : enterEvent()
397 //=================================================================================
398 void PrimitiveGUI_ConeDlg::enterEvent( QEvent* )
400 if ( !mainFrame()->GroupConstructors->isEnabled() )
401 ActivateThisDialog();
405 //=================================================================================
406 // function : ValueChangedInSpinBox()
408 //=================================================================================
409 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
415 //=================================================================================
416 // function : createOperation
418 //=================================================================================
419 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
421 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
424 //=================================================================================
425 // function : isValid
427 //=================================================================================
428 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
430 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
433 //=================================================================================
434 // function : execute
436 //=================================================================================
437 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
441 GEOM::GEOM_Object_var anObj;
443 switch ( getConstructorId() ) {
445 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) {
446 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
455 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
462 if ( !anObj->_is_nil() )
463 objects.push_back( anObj._retn() );
469 //=================================================================================
470 // function : getRadius1()
472 //=================================================================================
473 double PrimitiveGUI_ConeDlg::getRadius1() const
475 int aConstructorId = getConstructorId();
476 if ( aConstructorId == 0 )
477 return GroupPoints->SpinBox_DX->value();
478 else if ( aConstructorId == 1 )
479 return GroupDimensions->SpinBox_DX->value();
484 //=================================================================================
485 // function : getRadius2()
487 //=================================================================================
488 double PrimitiveGUI_ConeDlg::getRadius2() const
490 int aConstructorId = getConstructorId();
491 if ( aConstructorId == 0 )
492 return GroupPoints->SpinBox_DY->value();
493 else if ( aConstructorId == 1 )
494 return GroupDimensions->SpinBox_DY->value();
499 //=================================================================================
500 // function : getRadius2()
502 //=================================================================================
503 double PrimitiveGUI_ConeDlg::getHeight() const
505 int aConstructorId = getConstructorId();
506 if ( aConstructorId == 0 )
507 return GroupPoints->SpinBox_DZ->value();
508 else if ( aConstructorId == 1 )
509 return GroupDimensions->SpinBox_DZ->value();
513 //=================================================================================
514 // function : addSubshapeToStudy
515 // purpose : virtual method to add new SubObjects if local selection
516 //=================================================================================
517 void PrimitiveGUI_ConeDlg::addSubshapesToStudy()
519 QMap<QString, GEOM::GEOM_Object_var> objMap;
521 switch ( getConstructorId() ) {
523 objMap[GroupPoints->LineEdit1->text()] = myPoint;
524 objMap[GroupPoints->LineEdit2->text()] = myDir;
529 addSubshapesToFather( objMap );