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_CylinderDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_CylinderDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : PrimitiveGUI_CylinderDlg()
49 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl )
56 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
58 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_PV" ) ) );
59 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_DXYZ" ) ) );
60 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_CYLINDER_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CYLINDER" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_2Sel2Spin( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
76 GroupPoints->TextLabel4->setText( tr( "GEOM_HEIGHT" ) );
77 GroupPoints->PushButton1->setIcon( image2 );
78 GroupPoints->PushButton2->setIcon( image2 );
80 GroupDimensions = new DlgRef_2Spin( centralWidget() );
81 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
82 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) );
83 GroupDimensions->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
85 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
86 layout->setMargin( 0 ); layout->setSpacing( 6 );
87 layout->addWidget( GroupPoints );
88 layout->addWidget( GroupDimensions );
89 /***************************************************************/
91 setHelpFileName( "create_cylinder_page.html" );
97 //=================================================================================
98 // function : ~PrimitiveGUI_CylinderDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_CylinderDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
115 GroupPoints->LineEdit1->setReadOnly( true );
116 GroupPoints->LineEdit2->setReadOnly( true );
118 myPoint = myDir = GEOM::GEOM_Object::_nil();
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
124 /* min, max, step and decimals for spin boxes & initial values */
125 /* First constructor : radius */
126 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
127 /* First constructor : algebric height */
128 initSpinBox( GroupPoints->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
129 /* Second constructor : radius */
130 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
131 /* Second constructor : algebric height */
132 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
134 GroupPoints->SpinBox_DX->setValue( 100.0 );
135 GroupPoints->SpinBox_DY->setValue( 300.0 );
136 GroupDimensions->SpinBox_DX->setValue( 100.0 );
137 GroupDimensions->SpinBox_DY->setValue( 300.0 );
139 /* signals and slots connections */
140 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
143 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
145 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
148 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
151 connect( GroupPoints->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
152 connect( GroupPoints->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
153 connect( GroupDimensions->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
154 connect( GroupDimensions->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
156 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
158 connect( myGeomGUI->getApp()->selectionMgr(),
159 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
161 initName( tr( "GEOM_CYLINDER" ) );
163 setConstructorId( 1 ); // simplest constructor
164 ConstructorsClicked( 1 );
168 //=================================================================================
169 // function : SetDoubleSpinBoxStep()
170 // purpose : Double spin box management
171 //=================================================================================
172 void PrimitiveGUI_CylinderDlg::SetDoubleSpinBoxStep( double step )
174 GroupPoints->SpinBox_DX->setSingleStep(step);
175 GroupPoints->SpinBox_DY->setSingleStep(step);
176 GroupDimensions->SpinBox_DX->setSingleStep(step);
177 GroupDimensions->SpinBox_DY->setSingleStep(step);
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void PrimitiveGUI_CylinderDlg::ConstructorsClicked( int constructorId )
187 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
189 switch( constructorId ) {
192 globalSelection( GEOM_POINT ); // to break previous local selection
193 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
195 GroupDimensions->hide();
198 myEditCurrentArgument = GroupPoints->LineEdit1;
199 GroupPoints->LineEdit1->setText( "" );
200 GroupPoints->LineEdit2->setText( "" );
201 myPoint = myDir = GEOM::GEOM_Object::_nil();
203 connect( myGeomGUI->getApp()->selectionMgr(),
204 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209 globalSelection(); // close local contexts, if any
212 GroupDimensions->show();
217 qApp->processEvents();
219 resize( minimumSize() );
225 //=================================================================================
226 // function : ClickOnOk()
228 //=================================================================================
229 void PrimitiveGUI_CylinderDlg::ClickOnOk()
231 if ( ClickOnApply() )
236 //=================================================================================
237 // function : ClickOnApply()
239 //=================================================================================
240 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
246 ConstructorsClicked( getConstructorId() );
251 //=================================================================================
252 // function : SelectionIntoArgument()
253 // purpose : Called when selection as changed or other case
254 //=================================================================================
255 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
257 if ( getConstructorId() != 0 )
260 myEditCurrentArgument->setText( "" );
262 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
263 SALOME_ListIO aSelList;
264 aSelMgr->selectedObjects(aSelList);
266 if (aSelList.Extent() != 1) {
267 if (myEditCurrentArgument == GroupPoints->LineEdit1)
268 myPoint = GEOM::GEOM_Object::_nil();
269 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
270 myDir = GEOM::GEOM_Object::_nil();
275 Standard_Boolean testResult = Standard_False;
276 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
278 if (!testResult || CORBA::is_nil(aSelectedObject))
281 QString aName = GEOMBase::GetName(aSelectedObject);
283 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 TColStd_IndexedMapOfInteger aMap;
289 aSelMgr->GetIndexes(aSelList.First(), aMap);
290 if ( aMap.Extent() == 1 ) { // Local Selection
291 int anIndex = aMap( 1 );
292 if ( aNeedType == TopAbs_EDGE )
293 aName.append( ":edge_" + QString::number( anIndex ) );
295 aName.append( ":vertex_" + QString::number( anIndex ) );
297 //Find SubShape Object in Father
298 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
300 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
301 GEOM::GEOM_IShapesOperations_var aShapesOp =
302 getGeomEngine()->GetIShapesOperations( getStudyId() );
303 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
306 aSelectedObject = aFindedObject; // get Object from study
309 else { // Global Selection
310 if ( aShape.ShapeType() != aNeedType ) {
311 aSelectedObject = GEOM::GEOM_Object::_nil();
317 myEditCurrentArgument->setText(aName);
319 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
320 myPoint = aSelectedObject;
321 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
322 myDir = aSelectedObject;
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
336 if ( send == GroupPoints->PushButton1 ) {
337 myEditCurrentArgument = GroupPoints->LineEdit1;
338 globalSelection( GEOM_POINT ); // to break previous local selection
339 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
341 else if ( send == GroupPoints->PushButton2 ) {
342 myEditCurrentArgument = GroupPoints->LineEdit2;
343 globalSelection( GEOM_LINE ); // to break previous local selection
344 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
347 myEditCurrentArgument->setFocus();
348 SelectionIntoArgument();
352 //=================================================================================
353 // function : LineEditReturnPressed()
355 //=================================================================================
356 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
358 QLineEdit* send = (QLineEdit*)sender();
359 if ( send == GroupPoints->LineEdit1 ||
360 send == GroupPoints->LineEdit2 ) {
361 myEditCurrentArgument = send;
362 GEOMBase_Skeleton::LineEditReturnPressed();
367 //=================================================================================
368 // function : ActivateThisDialog()
370 //=================================================================================
371 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
373 GEOMBase_Skeleton::ActivateThisDialog();
374 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
375 this, SLOT( SelectionIntoArgument() ) );
377 ConstructorsClicked( getConstructorId() );
381 //=================================================================================
382 // function : enterEvent()
384 //=================================================================================
385 void PrimitiveGUI_CylinderDlg::enterEvent( QEvent* )
387 if ( !mainFrame()->GroupConstructors->isEnabled() )
388 ActivateThisDialog();
392 //=================================================================================
393 // function : DeactivateActiveDialog()
394 // purpose : public slot to deactivate if active
395 //=================================================================================
396 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
398 GEOMBase_Skeleton::DeactivateActiveDialog();
402 //=================================================================================
403 // function : ValueChangedInSpinBox
405 //=================================================================================
406 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
412 //=================================================================================
413 // function : createOperation
415 //=================================================================================
416 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
418 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
422 //=================================================================================
423 // function : isValid
425 //=================================================================================
426 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
428 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
431 //=================================================================================
432 // function : execute
434 //=================================================================================
435 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
439 GEOM::GEOM_Object_var anObj;
441 switch ( getConstructorId() ) {
443 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) {
444 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH( myPoint, myDir, getRadius(), getHeight() );
449 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH( getRadius(), getHeight() );
455 if ( !anObj->_is_nil() )
456 objects.push_back( anObj._retn() );
462 //=================================================================================
463 // function : getRadius()
465 //=================================================================================
466 double PrimitiveGUI_CylinderDlg::getRadius() const
468 int aConstructorId = getConstructorId();
469 if ( aConstructorId == 0 )
470 return GroupPoints->SpinBox_DX->value();
471 else if ( aConstructorId == 1 )
472 return GroupDimensions->SpinBox_DX->value();
477 //=================================================================================
478 // function : getHeight()
480 //=================================================================================
481 double PrimitiveGUI_CylinderDlg::getHeight() const
483 int aConstructorId = getConstructorId();
484 if ( aConstructorId == 0 )
485 return GroupPoints->SpinBox_DY->value();
486 else if ( aConstructorId == 1 )
487 return GroupDimensions->SpinBox_DY->value();
491 //=================================================================================
492 // function : addSubshapeToStudy
493 // purpose : virtual method to add new SubObjects if local selection
494 //=================================================================================
495 void PrimitiveGUI_CylinderDlg::addSubshapesToStudy()
497 QMap<QString, GEOM::GEOM_Object_var> objMap;
499 switch ( getConstructorId() ) {
501 objMap[GroupPoints->LineEdit1->text()] = myPoint;
502 objMap[GroupPoints->LineEdit2->text()] = myDir;
507 addSubshapesToFather( objMap );