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"
28 #include <GEOM_DlgRef.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 <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : PrimitiveGUI_ConeDlg()
41 // purpose : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_PV" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_DXYZ" ) ) );
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_CONE_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CONE" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setIcon( image1 );
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_2Sel3Spin( centralWidget() );
64 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
65 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) );
66 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
67 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
68 GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
69 GroupPoints->TextLabel5->setText( tr( "GEOM_HEIGHT" ) );
70 GroupPoints->PushButton1->setIcon( image2 );
71 GroupPoints->PushButton2->setIcon( image2 );
73 GroupDimensions = new DlgRef_3Spin( centralWidget() );
74 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
75 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
76 GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
77 GroupDimensions->TextLabel3->setText( tr( "GEOM_HEIGHT" ) );
79 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80 layout->setMargin( 0 ); layout->setSpacing( 6 );
81 layout->addWidget( GroupPoints );
82 layout->addWidget( GroupDimensions );
83 /***************************************************************/
85 setHelpFileName( "cone.htm" );
91 //=================================================================================
92 // function : ~PrimitiveGUI_ConeDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
97 // no need to delete child widgets, Qt does it all for us
101 //=================================================================================
104 //=================================================================================
105 void PrimitiveGUI_ConeDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
110 GroupPoints->LineEdit2->setReadOnly( true );
112 myPoint = myDir = GEOM::GEOM_Object::_nil();
114 /* Get setting of step value from file configuration */
115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
118 /* min, max, step and decimals for spin boxes & initial values */
119 initSpinBox( GroupPoints->SpinBox_DX, 0.000, COORD_MAX, step, 3 );
120 initSpinBox( GroupPoints->SpinBox_DY, 0.000, COORD_MAX, step, 3 );
121 initSpinBox( GroupPoints->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
122 initSpinBox( GroupDimensions->SpinBox_DX, 0.000, COORD_MAX, step, 3 );
123 initSpinBox( GroupDimensions->SpinBox_DY, 0.000, COORD_MAX, step, 3 );
124 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
126 double aRadius1( 100.0 ), aRadius2( 0.0 ), aHeight( 300.0 );
127 GroupPoints->SpinBox_DX->setValue( aRadius1 );
128 GroupPoints->SpinBox_DY->setValue( aRadius2 );
129 GroupPoints->SpinBox_DZ->setValue( aHeight );
130 GroupDimensions->SpinBox_DX->setValue( aRadius1 );
131 GroupDimensions->SpinBox_DY->setValue( aRadius2 );
132 GroupDimensions->SpinBox_DZ->setValue( aHeight );
134 /* signals and slots connections */
135 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
138 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
140 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
146 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
147 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
148 connect( GroupPoints->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
149 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
150 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
151 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
154 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
155 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DY, SLOT( SetStep( double ) ) );
156 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DZ, SLOT( SetStep( double ) ) );
157 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
158 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
159 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DZ, SLOT( SetStep( double ) ) );
162 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
163 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
165 initName( tr( "GEOM_CONE" ) );
167 ConstructorsClicked( 0 );
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose : Radio button management
174 //=================================================================================
175 void PrimitiveGUI_ConeDlg::ConstructorsClicked( int constructorId )
177 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
179 switch( constructorId ) {
182 globalSelection( GEOM_POINT );
183 GroupDimensions->hide();
186 myEditCurrentArgument = GroupPoints->LineEdit1;
187 GroupPoints->LineEdit1->setText( "" );
188 GroupPoints->LineEdit2->setText( "" );
189 myPoint = myDir = GEOM::GEOM_Object::_nil();
191 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
192 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
198 GroupDimensions->show();
204 qApp->processEvents();
206 resize( minimumSize() );
212 //=================================================================================
213 // function : ClickOnOk()
215 //=================================================================================
216 void PrimitiveGUI_ConeDlg::ClickOnOk()
218 if ( ClickOnApply() )
223 //=================================================================================
224 // function : ClickOnApply()
226 //=================================================================================
227 bool PrimitiveGUI_ConeDlg::ClickOnApply()
233 ConstructorsClicked( getConstructorId() );
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
244 if ( getConstructorId() != 0 )
247 if ( IObjectCount() != 1 ) {
248 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
249 myPoint = GEOM::GEOM_Object::_nil();
250 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
251 myDir = GEOM::GEOM_Object::_nil();
256 Standard_Boolean testResult = Standard_False;
257 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
259 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
262 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
263 myPoint = aSelectedObject;
264 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
265 myDir = aSelectedObject;
268 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
279 QPushButton* send = (QPushButton*)sender();
281 if ( send == GroupPoints->PushButton1 ) {
282 myEditCurrentArgument = GroupPoints->LineEdit1;
283 globalSelection( GEOM_POINT );
285 else if ( send == GroupPoints->PushButton2 ) {
286 myEditCurrentArgument = GroupPoints->LineEdit2;
287 globalSelection( GEOM_LINE );
290 myEditCurrentArgument->setFocus();
291 SelectionIntoArgument();
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if ( send == GroupPoints->LineEdit1 ||
303 send == GroupPoints->LineEdit2 ) {
304 myEditCurrentArgument = send;
305 GEOMBase_Skeleton::LineEditReturnPressed();
310 //=================================================================================
311 // function : ActivateThisDialog()
313 //=================================================================================
314 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
316 GEOMBase_Skeleton::ActivateThisDialog();
317 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
318 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
320 ConstructorsClicked( getConstructorId() );
324 //=================================================================================
325 // function : DeactivateActiveDialog()
326 // purpose : public slot to deactivate if active
327 //=================================================================================
328 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
330 GEOMBase_Skeleton::DeactivateActiveDialog();
334 //=================================================================================
335 // function : enterEvent()
337 //=================================================================================
338 void PrimitiveGUI_ConeDlg::enterEvent( QEvent* )
340 if ( !mainFrame()->GroupConstructors->isEnabled() )
341 ActivateThisDialog();
345 //=================================================================================
346 // function : ValueChangedInSpinBox()
348 //=================================================================================
349 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
355 //=================================================================================
356 // function : createOperation
358 //=================================================================================
359 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
361 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
364 //=================================================================================
365 // function : isValid
367 //=================================================================================
368 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
370 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
373 //=================================================================================
374 // function : execute
376 //=================================================================================
377 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
381 GEOM::GEOM_Object_var anObj;
383 switch ( getConstructorId() ) {
385 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) {
386 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
395 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
402 if ( !anObj->_is_nil() )
403 objects.push_back( anObj._retn() );
408 //=================================================================================
409 // function : closeEvent
411 //=================================================================================
412 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
414 // myGeomGUI->SetState( -1 );
415 GEOMBase_Skeleton::closeEvent( e );
419 //=================================================================================
420 // function : getRadius1()
422 //=================================================================================
423 double PrimitiveGUI_ConeDlg::getRadius1() const
425 int aConstructorId = getConstructorId();
426 if ( aConstructorId == 0 )
427 return GroupPoints->SpinBox_DX->value();
428 else if ( aConstructorId == 1 )
429 return GroupDimensions->SpinBox_DX->value();
434 //=================================================================================
435 // function : getRadius2()
437 //=================================================================================
438 double PrimitiveGUI_ConeDlg::getRadius2() const
440 int aConstructorId = getConstructorId();
441 if ( aConstructorId == 0 )
442 return GroupPoints->SpinBox_DY->value();
443 else if ( aConstructorId == 1 )
444 return GroupDimensions->SpinBox_DY->value();
449 //=================================================================================
450 // function : getRadius2()
452 //=================================================================================
453 double PrimitiveGUI_ConeDlg::getHeight() const
455 int aConstructorId = getConstructorId();
456 if ( aConstructorId == 0 )
457 return GroupPoints->SpinBox_DZ->value();
458 else if ( aConstructorId == 1 )
459 return GroupDimensions->SpinBox_DZ->value();