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>
46 //=================================================================================
47 // class : PrimitiveGUI_BoxDlg()
48 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_2P" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_DXYZ" ) ));
59 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_BOX_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BOX" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setIcon( image1 );
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_DIAGONAL_POINTS" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
74 GroupPoints->PushButton1->setIcon( image2 );
75 GroupPoints->PushButton2->setIcon( image2 );
77 GroupDimensions = new DlgRef_3Spin( centralWidget() );
78 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
79 GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
80 GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
81 GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
83 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
84 layout->setMargin( 0 ); layout->setSpacing( 6 );
85 layout->addWidget( GroupPoints );
86 layout->addWidget( GroupDimensions );
87 /***************************************************************/
89 setHelpFileName( "create_box_page.html" );
95 //=================================================================================
96 // function : ~DialogBox_Box()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
101 // no need to delete child widgets, Qt does it all for us
105 //=================================================================================
108 //=================================================================================
109 void PrimitiveGUI_BoxDlg::Init()
112 myEditCurrentArgument = GroupPoints->LineEdit1;
113 GroupPoints->LineEdit1->setReadOnly( true );
114 GroupPoints->LineEdit2->setReadOnly( true );
116 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
118 /* Get setting of step value from file configuration */
119 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
120 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
122 /* min, max, step and decimals for spin boxes */
123 initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
124 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
125 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
127 double initValue = 200.0;
128 GroupDimensions->SpinBox_DX->setValue( initValue );
129 GroupDimensions->SpinBox_DY->setValue( initValue );
130 GroupDimensions->SpinBox_DZ->setValue( initValue );
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( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
145 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
146 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
148 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
150 connect( myGeomGUI->getApp()->selectionMgr(),
151 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
153 initName( tr( "GEOM_BOX" ) );
155 setConstructorId( 1 ); // simplest constructor
156 ConstructorsClicked( 1 );
159 //=================================================================================
160 // function : SetDoubleSpinBoxStep()
161 // purpose : Double spin box management
162 //=================================================================================
163 void PrimitiveGUI_BoxDlg::SetDoubleSpinBoxStep( double step )
165 GroupDimensions->SpinBox_DX->setSingleStep(step);
166 GroupDimensions->SpinBox_DY->setSingleStep(step);
167 GroupDimensions->SpinBox_DZ->setSingleStep(step);
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose : Radio button management
174 //=================================================================================
175 void PrimitiveGUI_BoxDlg::ConstructorsClicked( int constructorId )
177 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
179 switch ( constructorId ) {
182 //globalSelection( GEOM_POINT );
183 globalSelection(); // close local contexts, if any
184 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
186 GroupDimensions->hide();
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 GroupPoints->LineEdit1->setText( "" );
191 GroupPoints->LineEdit2->setText( "" );
192 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
194 connect( myGeomGUI->getApp()->selectionMgr(),
195 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
201 GroupDimensions->show();
202 globalSelection(); // close local contexts, if any
207 qApp->processEvents();
209 resize( minimumSize() );
215 //=================================================================================
216 // function : ClickOnOk()
218 //=================================================================================
219 void PrimitiveGUI_BoxDlg::ClickOnOk()
221 if ( ClickOnApply() )
226 //=================================================================================
227 // function : ClickOnApply()
229 //=================================================================================
230 bool PrimitiveGUI_BoxDlg::ClickOnApply()
236 ConstructorsClicked( getConstructorId() );
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection as changed
244 //=================================================================================
245 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
247 if ( getConstructorId() != 0 )
250 myEditCurrentArgument->setText( "" );
252 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
253 SALOME_ListIO aSelList;
254 aSelMgr->selectedObjects(aSelList);
256 if ( aSelList.Extent() != 1 ) {
257 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
258 myPoint1 = GEOM::GEOM_Object::_nil();
259 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
260 myPoint2 = GEOM::GEOM_Object::_nil();
265 Standard_Boolean testResult = Standard_False;
266 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult );
268 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
272 QString aName = GEOMBase::GetName( aSelectedObject );
273 if (GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
274 TColStd_IndexedMapOfInteger aMap;
275 aSelMgr->GetIndexes( aSelList.First(), aMap );
276 if ( aMap.Extent() == 1) { // Local Selection
277 int anIndex = aMap( 1 );
278 aName.append( ":vertex_" + QString::number( anIndex ) );
280 //Find SubShape Object in Father
281 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
283 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
284 GEOM::GEOM_IShapesOperations_var aShapesOp =
285 getGeomEngine()->GetIShapesOperations( getStudyId() );
286 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
289 aSelectedObject = aFindedObject; // get Object from study
292 else { // Global Selection
293 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
294 aSelectedObject = GEOM::GEOM_Object::_nil();
300 myEditCurrentArgument->setText( aName );
302 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
303 myPoint1 = aSelectedObject;
304 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
305 myPoint2 = aSelectedObject;
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
319 if ( send == GroupPoints->PushButton1 )
320 myEditCurrentArgument = GroupPoints->LineEdit1;
321 else if ( send == GroupPoints->PushButton2 )
322 myEditCurrentArgument = GroupPoints->LineEdit2;
324 // globalSelection( GEOM_POINT );
325 globalSelection(); // close local contexts, if any
326 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
328 myEditCurrentArgument->setFocus();
329 SelectionIntoArgument();
333 //=================================================================================
334 // function : LineEditReturnPressed()
336 //=================================================================================
337 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
339 QLineEdit* send = (QLineEdit*)sender();
340 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
341 myEditCurrentArgument = send;
342 GEOMBase_Skeleton::LineEditReturnPressed();
347 //=================================================================================
348 // function : ActivateThisDialog()
350 //=================================================================================
351 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
353 GEOMBase_Skeleton::ActivateThisDialog();
354 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
355 this, SLOT( SelectionIntoArgument() ) );
357 ConstructorsClicked( getConstructorId() );
361 //=================================================================================
362 // function : enterEvent [REDEFINED]
364 //=================================================================================
365 void PrimitiveGUI_BoxDlg::enterEvent( QEvent* )
367 if ( !mainFrame()->GroupConstructors->isEnabled() )
368 ActivateThisDialog();
372 //=================================================================================
373 // function : ValueChangedInSpinBox()
375 //=================================================================================
376 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
382 //=================================================================================
383 // function : createOperation
385 //=================================================================================
386 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
388 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
392 //=================================================================================
393 // function : isValid
395 //=================================================================================
396 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
398 return getConstructorId() == 0 ? !( myPoint1->_is_nil() || myPoint2->_is_nil() ) : true;
402 //=================================================================================
403 // function : execute
405 //=================================================================================
406 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
410 GEOM::GEOM_Object_var anObj;
412 switch ( getConstructorId() ) {
415 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
416 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
424 double x = GroupDimensions->SpinBox_DX->value();
425 double y = GroupDimensions->SpinBox_DY->value();
426 double z = GroupDimensions->SpinBox_DZ->value();
428 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
434 if ( !anObj->_is_nil() )
435 objects.push_back( anObj._retn() );
440 //=================================================================================
441 // function : addSubshapeToStudy
442 // purpose : virtual method to add new SubObjects if local selection
443 //=================================================================================
444 void PrimitiveGUI_BoxDlg::addSubshapesToStudy()
446 QMap<QString, GEOM::GEOM_Object_var> objMap;
447 if ( getConstructorId() == 0 ) {
448 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
449 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
450 addSubshapesToFather( objMap );