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_BoxDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_BoxDlg.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_BoxDlg()
41 // purpose : Constructs a PrimitiveGUI_BoxDlg 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_BoxDlg::PrimitiveGUI_BoxDlg( 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_BOX_2P" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_DXYZ" ) ));
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_BOX_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BOX" ) );
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_2Sel( centralWidget() );
64 GroupPoints->GroupBox1->setTitle( tr( "GEOM_DIAGONAL_POINTS" ) );
65 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
66 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
67 GroupPoints->PushButton1->setIcon( image2 );
68 GroupPoints->PushButton2->setIcon( image2 );
70 GroupDimensions = new DlgRef_3Spin( centralWidget() );
71 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
72 GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
73 GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
74 GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( GroupPoints );
79 layout->addWidget( GroupDimensions );
80 /***************************************************************/
82 setHelpFileName( "box.htm" );
88 //=================================================================================
89 // function : ~DialogBox_Box()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
94 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void PrimitiveGUI_BoxDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
109 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
111 /* Get setting of step value from file configuration */
112 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
115 /* min, max, step and decimals for spin boxes */
116 initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
117 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
118 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
120 double initValue = 200.0;
121 GroupDimensions->SpinBox_DX->setValue( initValue );
122 GroupDimensions->SpinBox_DY->setValue( initValue );
123 GroupDimensions->SpinBox_DZ->setValue( initValue );
125 /* signals and slots connections */
126 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
127 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
129 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
131 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
135 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
137 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
138 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
139 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
142 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
143 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
144 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DZ, SLOT( SetStep( double ) ) );
147 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
148 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
150 initName( tr( "GEOM_BOX" ) );
152 ConstructorsClicked( 0 );
156 //=================================================================================
157 // function : ConstructorsClicked()
158 // purpose : Radio button management
159 //=================================================================================
160 void PrimitiveGUI_BoxDlg::ConstructorsClicked( int constructorId )
162 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ) )->selectionMgr(), 0, this, 0 );
164 switch ( constructorId ) {
167 globalSelection( GEOM_POINT );
169 GroupDimensions->hide();
172 myEditCurrentArgument = GroupPoints->LineEdit1;
173 GroupPoints->LineEdit1->setText( "" );
174 GroupPoints->LineEdit2->setText( "" );
175 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
177 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
178 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
184 GroupDimensions->show();
189 qApp->processEvents();
191 resize( minimumSize() );
197 //=================================================================================
198 // function : ClickOnOk()
200 //=================================================================================
201 void PrimitiveGUI_BoxDlg::ClickOnOk()
203 if ( ClickOnApply() )
208 //=================================================================================
209 // function : ClickOnApply()
211 //=================================================================================
212 bool PrimitiveGUI_BoxDlg::ClickOnApply()
218 ConstructorsClicked( getConstructorId() );
223 //=================================================================================
224 // function : SelectionIntoArgument()
225 // purpose : Called when selection as changed
226 //=================================================================================
227 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
229 if ( getConstructorId() != 0 )
232 myEditCurrentArgument->setText( "" );
234 if ( IObjectCount() != 1 ) {
235 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
236 myPoint1 = GEOM::GEOM_Object::_nil();
237 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
238 myPoint2 = GEOM::GEOM_Object::_nil();
243 Standard_Boolean testResult = Standard_False;
244 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
246 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
249 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
250 myPoint1 = aSelectedObject;
251 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
252 myPoint2 = aSelectedObject;
254 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
260 //=================================================================================
261 // function : SetEditCurrentArgument()
263 //=================================================================================
264 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
266 QPushButton* send = (QPushButton*)sender();
268 if ( send == GroupPoints->PushButton1 )
269 myEditCurrentArgument = GroupPoints->LineEdit1;
270 else if ( send == GroupPoints->PushButton2 )
271 myEditCurrentArgument = GroupPoints->LineEdit2;
273 globalSelection( GEOM_POINT );
275 myEditCurrentArgument->setFocus();
276 SelectionIntoArgument();
280 //=================================================================================
281 // function : LineEditReturnPressed()
283 //=================================================================================
284 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
286 QLineEdit* send = (QLineEdit*)sender();
287 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
288 myEditCurrentArgument = send;
289 GEOMBase_Skeleton::LineEditReturnPressed();
294 //=================================================================================
295 // function : ActivateThisDialog()
297 //=================================================================================
298 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
300 GEOMBase_Skeleton::ActivateThisDialog();
301 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
302 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
304 ConstructorsClicked( getConstructorId() );
308 //=================================================================================
309 // function : enterEvent [REDEFINED]
311 //=================================================================================
312 void PrimitiveGUI_BoxDlg::enterEvent( QEvent* )
314 if ( !mainFrame()->GroupConstructors->isEnabled() )
315 ActivateThisDialog();
319 //=================================================================================
320 // function : ValueChangedInSpinBox()
322 //=================================================================================
323 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
329 //=================================================================================
330 // function : createOperation
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
335 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
339 //=================================================================================
340 // function : isValid
342 //=================================================================================
343 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
345 return getConstructorId() == 0 ? !( myPoint1->_is_nil() || myPoint2->_is_nil() ) : true;
349 //=================================================================================
350 // function : execute
352 //=================================================================================
353 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
357 GEOM::GEOM_Object_var anObj;
359 switch ( getConstructorId() ) {
362 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
363 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
371 double x = GroupDimensions->SpinBox_DX->value();
372 double y = GroupDimensions->SpinBox_DY->value();
373 double z = GroupDimensions->SpinBox_DZ->value();
375 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
381 if ( !anObj->_is_nil() )
382 objects.push_back( anObj._retn() );
387 //=================================================================================
388 // function : closeEvent
390 //=================================================================================
391 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
393 GEOMBase_Skeleton::closeEvent( e );