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"
28 #include <GEOM_DlgRef.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 <GEOMImpl_Types.hxx>
40 //=================================================================================
41 // class : PrimitiveGUI_CylinderDlg()
42 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
48 bool modal, Qt::WindowFlags fl )
49 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
51 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_PV" ) ) );
52 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_DXYZ" ) ) );
53 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_CYLINDER_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CYLINDER" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setIcon( image1 );
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_2Sel2Spin( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
69 GroupPoints->TextLabel4->setText( tr( "GEOM_HEIGHT" ) );
70 GroupPoints->PushButton1->setIcon( image2 );
71 GroupPoints->PushButton2->setIcon( image2 );
73 GroupDimensions = new DlgRef_2Spin( centralWidget() );
74 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
75 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) );
76 GroupDimensions->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
78 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79 layout->setMargin( 0 ); layout->setSpacing( 6 );
80 layout->addWidget( GroupPoints );
81 layout->addWidget( GroupDimensions );
82 /***************************************************************/
84 setHelpFileName( "cylinder.htm" );
90 //=================================================================================
91 // function : ~PrimitiveGUI_CylinderDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void PrimitiveGUI_CylinderDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly( true );
109 GroupPoints->LineEdit2->setReadOnly( true );
111 myPoint = myDir = GEOM::GEOM_Object::_nil();
113 /* Get setting of step value from file configuration */
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
117 /* min, max, step and decimals for spin boxes & initial values */
118 /* First constructor : radius */
119 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 );
120 /* First constructor : algebric height */
121 initSpinBox( GroupPoints->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
122 /* Second constructor : radius */
123 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 );
124 /* Second constructor : algebric height */
125 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
127 GroupPoints->SpinBox_DX->setValue( 100.0 );
128 GroupPoints->SpinBox_DY->setValue( 300.0 );
129 GroupDimensions->SpinBox_DX->setValue( 100.0 );
130 GroupDimensions->SpinBox_DY->setValue( 300.0 );
132 /* signals and slots connections */
133 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
134 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
136 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
138 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
139 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
142 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144 connect( GroupPoints->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
145 connect( GroupPoints->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
146 connect( GroupDimensions->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
147 connect( GroupDimensions->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
150 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
151 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DY, SLOT( SetStep( double ) ) );
152 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
153 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
156 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
157 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
159 initName( tr( "GEOM_CYLINDER" ) );
160 ConstructorsClicked( 0 );
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void PrimitiveGUI_CylinderDlg::ConstructorsClicked( int constructorId )
170 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
172 switch( constructorId ) {
175 globalSelection( GEOM_POINT );
177 GroupDimensions->hide();
180 myEditCurrentArgument = GroupPoints->LineEdit1;
181 GroupPoints->LineEdit1->setText( "" );
182 GroupPoints->LineEdit2->setText( "" );
183 myPoint = myDir = GEOM::GEOM_Object::_nil();
185 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
186 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
192 GroupDimensions->show();
197 qApp->processEvents();
199 resize( minimumSize() );
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void PrimitiveGUI_CylinderDlg::ClickOnOk()
211 if ( ClickOnApply() )
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
226 ConstructorsClicked( getConstructorId() );
231 //=================================================================================
232 // function : SelectionIntoArgument()
233 // purpose : Called when selection as changed or other case
234 //=================================================================================
235 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
237 if ( getConstructorId() != 0 )
240 myEditCurrentArgument->setText( "" );
242 if ( IObjectCount() != 1 ) {
243 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
244 myPoint = GEOM::GEOM_Object::_nil();
245 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
246 myDir = GEOM::GEOM_Object::_nil();
251 Standard_Boolean testResult = Standard_False;
252 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
254 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
257 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
258 myPoint = aSelectedObject;
259 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
260 myDir = aSelectedObject;
262 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
268 //=================================================================================
269 // function : SetEditCurrentArgument()
271 //=================================================================================
272 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
274 QPushButton* send = (QPushButton*)sender();
276 if ( send == GroupPoints->PushButton1 ) {
277 myEditCurrentArgument = GroupPoints->LineEdit1;
278 globalSelection( GEOM_POINT );
280 else if ( send == GroupPoints->PushButton2 ) {
281 myEditCurrentArgument = GroupPoints->LineEdit2;
282 globalSelection( GEOM_LINE );
285 myEditCurrentArgument->setFocus();
286 SelectionIntoArgument();
290 //=================================================================================
291 // function : LineEditReturnPressed()
293 //=================================================================================
294 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
296 QLineEdit* send = (QLineEdit*)sender();
297 if ( send == GroupPoints->LineEdit1 ||
298 send == GroupPoints->LineEdit2 ) {
299 myEditCurrentArgument = send;
300 GEOMBase_Skeleton::LineEditReturnPressed();
305 //=================================================================================
306 // function : ActivateThisDialog()
308 //=================================================================================
309 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
311 GEOMBase_Skeleton::ActivateThisDialog();
312 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
313 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
315 ConstructorsClicked( getConstructorId() );
319 //=================================================================================
320 // function : enterEvent()
322 //=================================================================================
323 void PrimitiveGUI_CylinderDlg::enterEvent( QEvent* )
325 if ( !mainFrame()->GroupConstructors->isEnabled() )
326 ActivateThisDialog();
330 //=================================================================================
331 // function : DeactivateActiveDialog()
332 // purpose : public slot to deactivate if active
333 //=================================================================================
334 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
336 GEOMBase_Skeleton::DeactivateActiveDialog();
340 //=================================================================================
341 // function : ValueChangedInSpinBox
343 //=================================================================================
344 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
350 //=================================================================================
351 // function : createOperation
353 //=================================================================================
354 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
356 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
360 //=================================================================================
361 // function : isValid
363 //=================================================================================
364 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
366 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
369 //=================================================================================
370 // function : execute
372 //=================================================================================
373 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
377 GEOM::GEOM_Object_var anObj;
379 switch ( getConstructorId() ) {
381 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) {
382 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH( myPoint, myDir, getRadius(), getHeight() );
387 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH( getRadius(), getHeight() );
393 if ( !anObj->_is_nil() )
394 objects.push_back( anObj._retn() );
399 //=================================================================================
400 // function : closeEvent
402 //=================================================================================
403 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
405 GEOMBase_Skeleton::closeEvent( e );
409 //=================================================================================
410 // function : getRadius()
412 //=================================================================================
413 double PrimitiveGUI_CylinderDlg::getRadius() const
415 int aConstructorId = getConstructorId();
416 if ( aConstructorId == 0 )
417 return GroupPoints->SpinBox_DX->value();
418 else if ( aConstructorId == 1 )
419 return GroupDimensions->SpinBox_DX->value();
424 //=================================================================================
425 // function : getHeight()
427 //=================================================================================
428 double PrimitiveGUI_CylinderDlg::getHeight() const
430 int aConstructorId = getConstructorId();
431 if ( aConstructorId == 0 )
432 return GroupPoints->SpinBox_DY->value();
433 else if ( aConstructorId == 1 )
434 return GroupDimensions->SpinBox_DY->value();