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"
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 <TopoDS_Shape.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : PrimitiveGUI_BoxDlg()
47 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_2P" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_DXYZ" ) ));
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_BOX_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BOX" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image1 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_2Sel( centralWidget() );
70 GroupPoints->GroupBox1->setTitle( tr( "GEOM_DIAGONAL_POINTS" ) );
71 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
72 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
73 GroupPoints->PushButton1->setIcon( image2 );
74 GroupPoints->PushButton2->setIcon( image2 );
76 GroupDimensions = new DlgRef_3Spin( centralWidget() );
77 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
78 GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
79 GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
80 GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( GroupPoints );
85 layout->addWidget( GroupDimensions );
86 /***************************************************************/
88 setHelpFileName( "create_box_page.html" );
94 //=================================================================================
95 // function : ~DialogBox_Box()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
100 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_BoxDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly( true );
113 GroupPoints->LineEdit2->setReadOnly( true );
115 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
117 /* Get setting of step value from file configuration */
118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
119 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
121 /* min, max, step and decimals for spin boxes */
122 initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
123 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
124 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
126 double initValue = 200.0;
127 GroupDimensions->SpinBox_DX->setValue( initValue );
128 GroupDimensions->SpinBox_DY->setValue( initValue );
129 GroupDimensions->SpinBox_DZ->setValue( initValue );
131 /* signals and slots connections */
132 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
133 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
135 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
137 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
140 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
141 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
143 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
144 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
145 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
148 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
149 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
150 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DZ, SLOT( SetStep( double ) ) );
153 connect( myGeomGUI->getApp()->selectionMgr(),
154 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
156 initName( tr( "GEOM_BOX" ) );
158 ConstructorsClicked( 0 );
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void PrimitiveGUI_BoxDlg::ConstructorsClicked( int constructorId )
168 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
170 switch ( constructorId ) {
173 //globalSelection( GEOM_POINT );
174 globalSelection(); // close local contexts, if any
175 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
177 GroupDimensions->hide();
180 myEditCurrentArgument = GroupPoints->LineEdit1;
181 GroupPoints->LineEdit1->setText( "" );
182 GroupPoints->LineEdit2->setText( "" );
183 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
185 connect( myGeomGUI->getApp()->selectionMgr(),
186 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
192 GroupDimensions->show();
193 globalSelection(); // close local contexts, if any
198 qApp->processEvents();
200 resize( minimumSize() );
206 //=================================================================================
207 // function : ClickOnOk()
209 //=================================================================================
210 void PrimitiveGUI_BoxDlg::ClickOnOk()
212 if ( ClickOnApply() )
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 bool PrimitiveGUI_BoxDlg::ClickOnApply()
227 ConstructorsClicked( getConstructorId() );
232 //=================================================================================
233 // function : SelectionIntoArgument()
234 // purpose : Called when selection as changed
235 //=================================================================================
236 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
238 if ( getConstructorId() != 0 )
241 myEditCurrentArgument->setText( "" );
243 if ( IObjectCount() != 1 ) {
244 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
245 myPoint1 = GEOM::GEOM_Object::_nil();
246 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
247 myPoint2 = GEOM::GEOM_Object::_nil();
252 Standard_Boolean testResult = Standard_False;
253 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
255 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
259 QString aName = GEOMBase::GetName( aSelectedObject );
260 if (GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
261 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
262 TColStd_IndexedMapOfInteger aMap;
263 aSelMgr->GetIndexes( firstIObject(), aMap );
264 if ( aMap.Extent() == 1) { // Local Selection
265 int anIndex = aMap( 1 );
266 aName.append( ":vertex_" + QString::number( anIndex ) );
268 //Find SubShape Object in Father
269 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
271 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
272 GEOM::GEOM_IShapesOperations_var aShapesOp =
273 getGeomEngine()->GetIShapesOperations( getStudyId() );
274 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
277 aSelectedObject = aFindedObject; // get Object from study
280 else { // Global Selection
281 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
282 aSelectedObject = GEOM::GEOM_Object::_nil();
288 myEditCurrentArgument->setText( aName );
290 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
291 myPoint1 = aSelectedObject;
292 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
293 myPoint2 = aSelectedObject;
299 //=================================================================================
300 // function : SetEditCurrentArgument()
302 //=================================================================================
303 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
305 QPushButton* send = (QPushButton*)sender();
307 if ( send == GroupPoints->PushButton1 )
308 myEditCurrentArgument = GroupPoints->LineEdit1;
309 else if ( send == GroupPoints->PushButton2 )
310 myEditCurrentArgument = GroupPoints->LineEdit2;
312 // globalSelection( GEOM_POINT );
313 globalSelection(); // close local contexts, if any
314 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
316 myEditCurrentArgument->setFocus();
317 SelectionIntoArgument();
321 //=================================================================================
322 // function : LineEditReturnPressed()
324 //=================================================================================
325 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
327 QLineEdit* send = (QLineEdit*)sender();
328 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
329 myEditCurrentArgument = send;
330 GEOMBase_Skeleton::LineEditReturnPressed();
335 //=================================================================================
336 // function : ActivateThisDialog()
338 //=================================================================================
339 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
341 GEOMBase_Skeleton::ActivateThisDialog();
342 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
343 this, SLOT( SelectionIntoArgument() ) );
345 ConstructorsClicked( getConstructorId() );
349 //=================================================================================
350 // function : enterEvent [REDEFINED]
352 //=================================================================================
353 void PrimitiveGUI_BoxDlg::enterEvent( QEvent* )
355 if ( !mainFrame()->GroupConstructors->isEnabled() )
356 ActivateThisDialog();
360 //=================================================================================
361 // function : ValueChangedInSpinBox()
363 //=================================================================================
364 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
376 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
380 //=================================================================================
381 // function : isValid
383 //=================================================================================
384 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
386 return getConstructorId() == 0 ? !( myPoint1->_is_nil() || myPoint2->_is_nil() ) : true;
390 //=================================================================================
391 // function : execute
393 //=================================================================================
394 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
398 GEOM::GEOM_Object_var anObj;
400 switch ( getConstructorId() ) {
403 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
404 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
412 double x = GroupDimensions->SpinBox_DX->value();
413 double y = GroupDimensions->SpinBox_DY->value();
414 double z = GroupDimensions->SpinBox_DZ->value();
416 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
422 if ( !anObj->_is_nil() )
423 objects.push_back( anObj._retn() );
428 //=================================================================================
429 // function : addSubshapeToStudy
430 // purpose : virtual method to add new SubObjects if local selection
431 //=================================================================================
432 void PrimitiveGUI_BoxDlg::addSubshapesToStudy()
434 QMap<QString, GEOM::GEOM_Object_var> objMap;
435 if ( getConstructorId() == 0 ) {
436 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
437 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
438 addSubshapesToFather( objMap );