1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_VectorDlg.cxx
24 // 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 );
76 GroupPoints->PushButton1->setDown( true );
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
80 GroupPoints->LineEdit1->setEnabled( true );
81 GroupPoints->LineEdit2->setEnabled( false );
83 GroupDimensions = new DlgRef_3Spin1Check( centralWidget() );
84 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
85 GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) );
86 GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) );
87 GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) );
88 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE_VECTOR" ) );
90 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
91 layout->setMargin( 0 ); layout->setSpacing( 6 );
92 layout->addWidget( GroupPoints );
93 layout->addWidget( GroupDimensions );
94 /***************************************************************/
96 setHelpFileName( "create_vector_page.html" );
103 //=================================================================================
104 // function : ~BasicGUI_VectorDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
112 //=================================================================================
115 //=================================================================================
116 void BasicGUI_VectorDlg::Init()
119 myEditCurrentArgument = GroupPoints->LineEdit1;
121 myPoint1 = GEOM::GEOM_Object::_nil();
122 myPoint2 = GEOM::GEOM_Object::_nil();
124 /* Get setting of step value from file configuration */
125 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
126 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
128 /* min, max, step and decimals for spin boxes */
129 initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
130 initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
131 initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
133 double dx( 0. ), dy( 0. ), dz( 200. );
134 GroupDimensions->SpinBox_DX->setValue( dx );
135 GroupDimensions->SpinBox_DY->setValue( dy );
136 GroupDimensions->SpinBox_DZ->setValue( dz );
138 GroupDimensions->CheckButton1->setChecked( false );
140 /* signals and slots connections */
141 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
142 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
144 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
145 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
147 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
149 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
150 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
153 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
156 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
157 connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
159 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
161 connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) );
163 connect( myGeomGUI->getApp()->selectionMgr(),
164 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
166 initName( tr("GEOM_VECTOR") );
168 setConstructorId( 1 ); // simplest constructor
169 ConstructorsClicked( 1 );
172 //=================================================================================
173 // function : SetDoubleSpinBoxStep()
174 // purpose : Double spin box management
175 //=================================================================================
176 void BasicGUI_VectorDlg::SetDoubleSpinBoxStep( double step )
178 GroupDimensions->SpinBox_DX->setSingleStep(step);
179 GroupDimensions->SpinBox_DY->setSingleStep(step);
180 GroupDimensions->SpinBox_DZ->setSingleStep(step);
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
190 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
191 myPoint1 = GEOM::GEOM_Object::_nil();
192 myPoint2 = GEOM::GEOM_Object::_nil();
194 switch ( constructorId ) {
197 GroupDimensions->hide();
200 myEditCurrentArgument = GroupPoints->LineEdit1;
201 GroupPoints->LineEdit1->setText( "" );
202 GroupPoints->LineEdit2->setText( "" );
203 GroupPoints->PushButton1->setDown( true );
204 GroupPoints->PushButton2->setDown( false );
205 GroupPoints->LineEdit1->setEnabled( true );
206 GroupPoints->LineEdit2->setEnabled( false );
208 globalSelection(); // close local contexts, if any
209 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
210 connect( myGeomGUI->getApp()->selectionMgr(),
211 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217 GroupDimensions->show();
218 globalSelection(); // close local contexts, if any
220 double dx( 0. ), dy( 0. ), dz( 0. );
221 GroupDimensions->SpinBox_DX->setValue( dx );
222 GroupDimensions->SpinBox_DY->setValue( dy );
223 GroupDimensions->SpinBox_DZ->setValue( dz );
225 GroupDimensions->CheckButton1->setChecked( false );
230 qApp->processEvents();
232 resize( minimumSizeHint() );
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void BasicGUI_VectorDlg::ClickOnOk()
244 if ( ClickOnApply() )
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 bool BasicGUI_VectorDlg::ClickOnApply()
254 buttonApply()->setFocus();
260 if ( getConstructorId() != 1 )
261 ConstructorsClicked( getConstructorId() );
266 //=================================================================================
267 // function : SelectionIntoArgument()
268 // purpose : Called when selection as changed or other case
269 //=================================================================================
270 void BasicGUI_VectorDlg::SelectionIntoArgument()
272 myEditCurrentArgument->setText( "" );
274 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
275 SALOME_ListIO aSelList;
276 aSelMgr->selectedObjects(aSelList);
278 if (aSelList.Extent() != 1) {
279 if (myEditCurrentArgument == GroupPoints->LineEdit1)
280 myPoint1 = GEOM::GEOM_Object::_nil();
281 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
282 myPoint2 = GEOM::GEOM_Object::_nil();
287 Standard_Boolean aRes = Standard_False;
288 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
289 if (!CORBA::is_nil(aSelectedObject) && aRes) {
290 QString aName = GEOMBase::GetName(aSelectedObject);
293 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
294 TColStd_IndexedMapOfInteger aMap;
295 aSelMgr->GetIndexes(aSelList.First(), aMap);
296 if (aMap.Extent() == 1) { // Local Selection
297 int anIndex = aMap(1);
298 aName += QString(":vertex_%1").arg(anIndex);
300 //Find SubShape Object in Father
301 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
303 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
304 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
305 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
308 aSelectedObject = aFindedObject; // get Object from study
311 else { // Global Selection
312 if (aShape.ShapeType() != TopAbs_VERTEX) {
313 aSelectedObject = GEOM::GEOM_Object::_nil();
319 myEditCurrentArgument->setText(aName);
321 if (!aSelectedObject->_is_nil()) { // clear selection if something selected
323 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
326 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
327 myPoint1 = aSelectedObject;
328 if (!myPoint1->_is_nil() && myPoint2->_is_nil())
329 GroupPoints->PushButton2->click();
331 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
332 myPoint2 = aSelectedObject;
333 if (!myPoint2->_is_nil() && myPoint1->_is_nil())
334 GroupPoints->PushButton1->click();
341 //=================================================================================
342 // function : SetEditCurrentArgument()
344 //=================================================================================
345 void BasicGUI_VectorDlg::SetEditCurrentArgument()
347 QPushButton* send = (QPushButton*)sender();
348 if ( send == GroupPoints->PushButton1 ) {
349 myEditCurrentArgument = GroupPoints->LineEdit1;
350 GroupPoints->PushButton2->setDown(false);
351 GroupPoints->LineEdit1->setEnabled(true);
352 GroupPoints->LineEdit2->setEnabled(false);
354 else if ( send == GroupPoints->PushButton2 ) {
355 myEditCurrentArgument = GroupPoints->LineEdit2;
356 GroupPoints->PushButton1->setDown(false);
357 GroupPoints->LineEdit1->setEnabled(false);
358 GroupPoints->LineEdit2->setEnabled(true);
360 myEditCurrentArgument->setFocus();
361 // SelectionIntoArgument();
362 globalSelection(); // close local selection to clear it
363 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
369 //=================================================================================
370 // function : LineEditReturnPressed()
372 //=================================================================================
373 void BasicGUI_VectorDlg::LineEditReturnPressed()
375 QLineEdit* send = (QLineEdit*)sender();
376 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
377 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
379 GEOMBase_Skeleton::LineEditReturnPressed();
383 //=================================================================================
384 // function : ActivateThisDialog()
386 //=================================================================================
387 void BasicGUI_VectorDlg::ActivateThisDialog()
389 GEOMBase_Skeleton::ActivateThisDialog();
390 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
391 this, SLOT( SelectionIntoArgument() ) );
393 ConstructorsClicked( getConstructorId() );
396 //=================================================================================
397 // function : DeactivateActiveDialog()
398 // purpose : public slot to deactivate if active
399 //=================================================================================
400 void BasicGUI_VectorDlg::DeactivateActiveDialog()
402 GEOMBase_Skeleton::DeactivateActiveDialog();
405 //=================================================================================
406 // function : enterEvent()
408 //=================================================================================
409 void BasicGUI_VectorDlg::enterEvent( QEvent* )
411 if ( !mainFrame()->GroupConstructors->isEnabled() )
412 ActivateThisDialog();
415 //=================================================================================
416 // function : ValueChangedInSpinBox()
418 //=================================================================================
419 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
424 //=================================================================================
425 // function : ReverseVector()
426 // purpose : 'state' not used here
427 //=================================================================================
428 void BasicGUI_VectorDlg::ReverseVector( int state )
430 double dx = -GroupDimensions->SpinBox_DX->value();
431 double dy = -GroupDimensions->SpinBox_DY->value();
432 double dz = -GroupDimensions->SpinBox_DZ->value();
434 GroupDimensions->SpinBox_DX->setValue( dx );
435 GroupDimensions->SpinBox_DY->setValue( dy );
436 GroupDimensions->SpinBox_DZ->setValue( dz );
441 //=================================================================================
442 // function : createOperation
444 //=================================================================================
445 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
447 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
450 //=================================================================================
451 // function : isValid
453 //=================================================================================
454 bool BasicGUI_VectorDlg::isValid( QString& msg )
456 if(getConstructorId() == 0)
457 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
458 else if(getConstructorId() == 1)
461 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
462 ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
463 ok = GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
477 GEOM::GEOM_Object_var anObj;
479 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
481 switch ( getConstructorId() ) {
484 anObj = anOper->MakeVectorTwoPnt( myPoint1, myPoint2 );
490 double dx = GroupDimensions->SpinBox_DX->value();
491 double dy = GroupDimensions->SpinBox_DY->value();
492 double dz = GroupDimensions->SpinBox_DZ->value();
494 QStringList aParameters;
495 aParameters << GroupDimensions->SpinBox_DX->text();
496 aParameters << GroupDimensions->SpinBox_DY->text();
497 aParameters << GroupDimensions->SpinBox_DZ->text();
498 anObj = anOper->MakeVectorDXDYDZ( dx, dy, dz );
500 if ( !anObj->_is_nil() && !IsPreview() )
501 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
508 if ( !anObj->_is_nil() )
509 objects.push_back( anObj._retn() );
514 //=================================================================================
515 // function : addSubshapeToStudy
516 // purpose : virtual method to add new SubObjects if local selection
517 //=================================================================================
518 void BasicGUI_VectorDlg::addSubshapesToStudy()
520 QMap<QString, GEOM::GEOM_Object_var> objMap;
522 switch ( getConstructorId() ) {
524 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
525 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
530 addSubshapesToFather( objMap );