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_TorusDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_TorusDlg.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_TorusDlg()
41 // purpose : Constructs a PrimitiveGUI_TorusDlg 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_TorusDlg::PrimitiveGUI_TorusDlg( 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_TORUS_PV" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_TORUS_DXYZ" ) ) );
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_TORUS_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TORUS" ) );
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_2Sel2Spin( 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->PushButton1->setIcon( image2 );
70 GroupPoints->PushButton2->setIcon( image2 );
72 GroupDimensions = new DlgRef_2Spin( centralWidget() );
73 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
74 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
75 GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
77 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
78 layout->setMargin( 0 ); layout->setSpacing( 6 );
79 layout->addWidget( GroupPoints );
80 layout->addWidget( GroupDimensions );
81 /***************************************************************/
83 setHelpFileName( "turus.htm" );
89 //=================================================================================
90 // function : ~PrimitiveGUI_TorusDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
95 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void PrimitiveGUI_TorusDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly( true );
108 GroupPoints->LineEdit2->setReadOnly( true );
110 myPoint = myDir = GEOM::GEOM_Object::_nil();
112 /* Get setting of step value from file configuration */
113 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
114 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
116 /* min, max, step and decimals for spin boxes & initial values */
117 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 );
118 initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3 );
119 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 );
120 initSpinBox( GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, step, 3 );
122 GroupPoints->SpinBox_DX->setValue( 300.0 );
123 GroupPoints->SpinBox_DY->setValue( 100.0 );
124 GroupDimensions->SpinBox_DX->setValue( 300.0 );
125 GroupDimensions->SpinBox_DY->setValue( 100.0 );
127 /* signals and slots connections */
128 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
129 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
131 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
133 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
137 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
139 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
140 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
141 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
142 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
145 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
146 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DY, SLOT( SetStep( double ) ) );
147 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
148 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
150 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
151 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
153 initName( tr( "GEOM_TORUS" ) );
155 ConstructorsClicked( 0 );
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose : Radio button management
162 //=================================================================================
163 void PrimitiveGUI_TorusDlg::ConstructorsClicked( int constructorId )
165 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
167 switch( constructorId ) {
170 globalSelection( GEOM_LINE );
172 GroupDimensions->hide();
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 GroupPoints->LineEdit1->setText( "" );
177 GroupPoints->LineEdit2->setText( "" );
178 myPoint = myDir = GEOM::GEOM_Object::_nil();
180 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
181 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
187 GroupDimensions->show();
193 qApp->processEvents();
195 resize( minimumSize() );
201 //=================================================================================
202 // function : ClickOnOk()
204 //=================================================================================
205 void PrimitiveGUI_TorusDlg::ClickOnOk()
207 if ( ClickOnApply() )
212 //=================================================================================
213 // function : ClickOnApply()
215 //=================================================================================
216 bool PrimitiveGUI_TorusDlg::ClickOnApply()
222 ConstructorsClicked( getConstructorId() );
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection as changed or other case
230 //=================================================================================
231 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
233 if ( getConstructorId() != 0 )
236 myEditCurrentArgument->setText( "" );
238 if ( IObjectCount() != 1 ) {
239 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
240 myPoint = GEOM::GEOM_Object::_nil();
241 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
242 myDir = GEOM::GEOM_Object::_nil();
247 Standard_Boolean testResult = Standard_False;
248 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
250 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
253 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
254 myPoint = aSelectedObject;
255 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
256 myDir = aSelectedObject;
258 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
269 QPushButton* send = (QPushButton*)sender();
271 if ( send == GroupPoints->PushButton1 ) {
272 myEditCurrentArgument = GroupPoints->LineEdit1;
273 globalSelection( GEOM_POINT );
275 else if ( send == GroupPoints->PushButton2 ) {
276 myEditCurrentArgument = GroupPoints->LineEdit2;
277 globalSelection( GEOM_LINE );
280 myEditCurrentArgument->setFocus();
281 SelectionIntoArgument();
285 //=================================================================================
286 // function : LineEditReturnPressed()
288 //=================================================================================
289 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
291 QLineEdit* send = (QLineEdit*)sender();
292 if ( send == GroupPoints->LineEdit1 ||
293 send == GroupPoints->LineEdit2 ) {
294 myEditCurrentArgument = send;
295 GEOMBase_Skeleton::LineEditReturnPressed();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
308 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
310 ConstructorsClicked( getConstructorId() );
314 //=================================================================================
315 // function : enterEvent()
317 //=================================================================================
318 void PrimitiveGUI_TorusDlg::enterEvent( QEvent* )
320 if ( !mainFrame()->GroupConstructors->isEnabled() )
321 ActivateThisDialog();
325 //=================================================================================
326 // function : DeactivateActiveDialog()
327 // purpose : public slot to deactivate if active
328 //=================================================================================
329 void PrimitiveGUI_TorusDlg::DeactivateActiveDialog()
331 GEOMBase_Skeleton::DeactivateActiveDialog();
335 //=================================================================================
336 // function : ValueChangedInSpinBox
338 //=================================================================================
339 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
345 //=================================================================================
346 // function : createOperation
348 //=================================================================================
349 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
351 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
355 //=================================================================================
356 // function : isValid
358 //=================================================================================
359 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
361 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
365 //=================================================================================
366 // function : execute
368 //=================================================================================
369 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
373 GEOM::GEOM_Object_var anObj;
375 switch ( getConstructorId() ) {
377 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
378 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR( myPoint, myDir, getRadius1(), getRadius2() );
383 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR( getRadius1(), getRadius2() );
388 if ( !anObj->_is_nil() )
389 objects.push_back( anObj._retn() );
395 //=================================================================================
396 // function : closeEvent
398 //=================================================================================
399 void PrimitiveGUI_TorusDlg::closeEvent( QCloseEvent* e )
401 GEOMBase_Skeleton::closeEvent( e );
405 //=================================================================================
406 // function : getRadius1()
408 //=================================================================================
409 double PrimitiveGUI_TorusDlg::getRadius1() const
411 int aConstructorId = getConstructorId();
412 if ( aConstructorId == 0 )
413 return GroupPoints->SpinBox_DX->value();
414 else if ( aConstructorId == 1 )
415 return GroupDimensions->SpinBox_DX->value();
420 //=================================================================================
421 // function : getRadius2()
423 //=================================================================================
424 double PrimitiveGUI_TorusDlg::getRadius2() const
426 int aConstructorId = getConstructorId();
427 if ( aConstructorId == 0 )
428 return GroupPoints->SpinBox_DY->value();
429 else if ( aConstructorId == 1 )
430 return GroupDimensions->SpinBox_DY->value();