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 : BasicGUI_VectorDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_VectorDlg.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 : BasicGUI_VectorDlg()
47 // purpose : Constructs a BasicGUI_VectorDlg 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 BasicGUI_VectorDlg::BasicGUI_VectorDlg( 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_VECTOR_2P" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_VECTOR_DXYZ" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_VECTOR_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_VECTOR"));
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() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_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 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
80 GroupDimensions = new DlgRef_3Spin1Check( centralWidget() );
81 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
82 GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
83 GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
84 GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
85 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE_VECTOR" ) );
87 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
88 layout->setMargin( 0 ); layout->setSpacing( 6 );
89 layout->addWidget( GroupPoints );
90 layout->addWidget( GroupDimensions );
91 /***************************************************************/
93 setHelpFileName( "create_vector_page.html" );
100 //=================================================================================
101 // function : ~BasicGUI_VectorDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
109 //=================================================================================
112 //=================================================================================
113 void BasicGUI_VectorDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
118 myPoint1 = GEOM::GEOM_Object::_nil();
119 myPoint2 = GEOM::GEOM_Object::_nil();
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
125 /* min, max, step and decimals for spin boxes */
126 initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
127 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
128 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
130 double dx( 0. ), dy( 0. ), dz( 200. );
131 GroupDimensions->SpinBox_DX->setValue( dx );
132 GroupDimensions->SpinBox_DY->setValue( dy );
133 GroupDimensions->SpinBox_DZ->setValue( dz );
135 GroupDimensions->CheckButton1->setChecked( false );
137 /* signals and slots connections */
138 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
139 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
141 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
142 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
144 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
146 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
147 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
149 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
150 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
152 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
153 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
154 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
156 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
158 connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) );
160 connect( myGeomGUI->getApp()->selectionMgr(),
161 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
163 initName( tr("GEOM_VECTOR") );
165 setConstructorId( 1 ); // simplest constructor
166 ConstructorsClicked( 1 );
169 //=================================================================================
170 // function : SetDoubleSpinBoxStep()
171 // purpose : Double spin box management
172 //=================================================================================
173 void BasicGUI_VectorDlg::SetDoubleSpinBoxStep( double step )
175 GroupDimensions->SpinBox_DX->setSingleStep(step);
176 GroupDimensions->SpinBox_DY->setSingleStep(step);
177 GroupDimensions->SpinBox_DZ->setSingleStep(step);
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
187 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
188 myPoint1 = GEOM::GEOM_Object::_nil();
189 myPoint2 = GEOM::GEOM_Object::_nil();
191 switch ( constructorId ) {
194 GroupDimensions->hide();
197 myEditCurrentArgument = GroupPoints->LineEdit1;
198 GroupPoints->LineEdit1->setText( "" );
199 GroupPoints->LineEdit2->setText( "" );
201 globalSelection(); // close local contexts, if any
202 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
203 connect( myGeomGUI->getApp()->selectionMgr(),
204 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
210 GroupDimensions->show();
211 globalSelection(); // close local contexts, if any
213 double dx( 0. ), dy( 0. ), dz( 0. );
214 GroupDimensions->SpinBox_DX->setValue( dx );
215 GroupDimensions->SpinBox_DY->setValue( dy );
216 GroupDimensions->SpinBox_DZ->setValue( dz );
218 GroupDimensions->CheckButton1->setChecked( false );
223 qApp->processEvents();
225 resize( minimumSize() );
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void BasicGUI_VectorDlg::ClickOnOk()
237 if ( ClickOnApply() )
241 //=================================================================================
242 // function : ClickOnApply()
244 //=================================================================================
245 bool BasicGUI_VectorDlg::ClickOnApply()
247 buttonApply()->setFocus();
253 if ( getConstructorId() != 1 )
254 ConstructorsClicked( getConstructorId() );
259 //=================================================================================
260 // function : SelectionIntoArgument()
261 // purpose : Called when selection as changed or other case
262 //=================================================================================
263 void BasicGUI_VectorDlg::SelectionIntoArgument()
265 myEditCurrentArgument->setText( "" );
267 if ( IObjectCount() != 1 ) {
268 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
269 myPoint1 = GEOM::GEOM_Object::_nil();
270 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
271 myPoint2 = GEOM::GEOM_Object::_nil();
276 Standard_Boolean aRes = Standard_False;
277 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
278 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
279 QString aName = GEOMBase::GetName(aSelectedObject);
282 if ( GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
283 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
284 TColStd_IndexedMapOfInteger aMap;
285 aSelMgr->GetIndexes( firstIObject(), aMap );
286 if ( aMap.Extent() == 1 ) { // Local Selection
287 int anIndex = aMap( 1 );
288 aName += QString( ":vertex_%1" ).arg( anIndex );
290 //Find SubShape Object in Father
291 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
293 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
294 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
295 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
298 aSelectedObject = aFindedObject; // get Object from study
301 else { // Global Selection
302 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
303 aSelectedObject = GEOM::GEOM_Object::_nil();
309 myEditCurrentArgument->setText(aName);
311 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
312 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
319 //=================================================================================
320 // function : SetEditCurrentArgument()
322 //=================================================================================
323 void BasicGUI_VectorDlg::SetEditCurrentArgument()
325 QPushButton* send = (QPushButton*)sender();
326 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
327 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
328 myEditCurrentArgument->setFocus();
329 SelectionIntoArgument();
333 //=================================================================================
334 // function : LineEditReturnPressed()
336 //=================================================================================
337 void BasicGUI_VectorDlg::LineEditReturnPressed()
339 QLineEdit* send = (QLineEdit*)sender();
340 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
341 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
343 GEOMBase_Skeleton::LineEditReturnPressed();
347 //=================================================================================
348 // function : ActivateThisDialog()
350 //=================================================================================
351 void BasicGUI_VectorDlg::ActivateThisDialog()
353 GEOMBase_Skeleton::ActivateThisDialog();
354 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
355 this, SLOT( SelectionIntoArgument() ) );
357 ConstructorsClicked( getConstructorId() );
360 //=================================================================================
361 // function : DeactivateActiveDialog()
362 // purpose : public slot to deactivate if active
363 //=================================================================================
364 void BasicGUI_VectorDlg::DeactivateActiveDialog()
366 GEOMBase_Skeleton::DeactivateActiveDialog();
369 //=================================================================================
370 // function : enterEvent()
372 //=================================================================================
373 void BasicGUI_VectorDlg::enterEvent( QEvent* )
375 if ( !mainFrame()->GroupConstructors->isEnabled() )
376 ActivateThisDialog();
379 //=================================================================================
380 // function : ValueChangedInSpinBox()
382 //=================================================================================
383 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
388 //=================================================================================
389 // function : ReverseVector()
390 // purpose : 'state' not used here
391 //=================================================================================
392 void BasicGUI_VectorDlg::ReverseVector( int state )
394 double dx = -GroupDimensions->SpinBox_DX->value();
395 double dy = -GroupDimensions->SpinBox_DY->value();
396 double dz = -GroupDimensions->SpinBox_DZ->value();
398 GroupDimensions->SpinBox_DX->setValue( dx );
399 GroupDimensions->SpinBox_DY->setValue( dy );
400 GroupDimensions->SpinBox_DZ->setValue( dz );
405 //=================================================================================
406 // function : createOperation
408 //=================================================================================
409 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
411 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
414 //=================================================================================
415 // function : isValid
417 //=================================================================================
418 bool BasicGUI_VectorDlg::isValid( QString& msg )
420 return getConstructorId() == 0 ? !myPoint1->_is_nil() && !myPoint2->_is_nil() : true;
423 //=================================================================================
424 // function : execute
426 //=================================================================================
427 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
431 GEOM::GEOM_Object_var anObj;
433 switch ( getConstructorId() ) {
436 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
442 double dx = GroupDimensions->SpinBox_DX->value();
443 double dy = GroupDimensions->SpinBox_DY->value();
444 double dz = GroupDimensions->SpinBox_DZ->value();
445 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx, dy, dz );
451 if ( !anObj->_is_nil() )
452 objects.push_back( anObj._retn() );
457 //=================================================================================
458 // function : addSubshapeToStudy
459 // purpose : virtual method to add new SubObjects if local selection
460 //=================================================================================
461 void BasicGUI_VectorDlg::addSubshapesToStudy()
463 QMap<QString, GEOM::GEOM_Object_var> objMap;
465 switch ( getConstructorId() ) {
467 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
468 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
473 addSubshapesToFather( objMap );