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_PlaneDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_PlaneDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TColStd_MapOfInteger.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : BasicGUI_PlaneDlg()
50 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl )
57 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
59 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PLANE_PV" ) ) );
60 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PLANE_3PNTS" ) ) );
61 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PLANE_FACE" ) ) );
62 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
64 setWindowTitle( tr( "GEOM_PLANE_TITLE" ) );
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PLANE" ) );
68 mainFrame()->RadioButton1->setIcon( image0 );
69 mainFrame()->RadioButton2->setIcon( image1 );
70 mainFrame()->RadioButton3->setIcon( image2 );
72 GroupPntDir = new DlgRef_2Sel1Spin( centralWidget() );
73 GroupPntDir->GroupBox1->setTitle( tr( "GEOM_PLANE_PV" ) );
74 GroupPntDir->TextLabel1->setText( tr( "GEOM_POINT" ) );
75 GroupPntDir->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
76 GroupPntDir->TextLabel3->setText( tr( "GEOM_PLANE_SIZE" ) );
77 GroupPntDir->PushButton1->setIcon( image3 );
78 GroupPntDir->PushButton2->setIcon( image3 );
79 GroupPntDir->LineEdit1->setReadOnly( true );
80 GroupPntDir->LineEdit2->setReadOnly( true );
82 Group3Pnts = new DlgRef_3Sel1Spin( centralWidget() );
83 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
84 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
85 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
86 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
87 Group3Pnts->TextLabel4->setText( tr( "GEOM_PLANE_SIZE" ) );
88 Group3Pnts->PushButton1->setIcon( image3 );
89 Group3Pnts->PushButton2->setIcon( image3 );
90 Group3Pnts->PushButton3->setIcon( image3 );
92 Group3Pnts->LineEdit1->setReadOnly( true );
93 Group3Pnts->LineEdit2->setReadOnly( true );
94 Group3Pnts->LineEdit3->setReadOnly( true );
96 GroupFace = new DlgRef_1Sel1Spin( centralWidget() );
97 GroupFace->GroupBox1->setTitle( tr( "GEOM_FACE_OR_LCS" ) );
98 GroupFace->TextLabel1->setText( tr( "GEOM_SELECTION" ) );
99 GroupFace->TextLabel2->setText( tr( "GEOM_PLANE_SIZE" ) );
100 GroupFace->PushButton1->setIcon( image3 );
102 GroupFace->LineEdit1->setReadOnly( true );
104 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
105 layout->setMargin( 0 ); layout->setSpacing( 6 );
106 layout->addWidget( GroupPntDir );
107 layout->addWidget( Group3Pnts );
108 layout->addWidget( GroupFace );
109 /***************************************************************/
111 setHelpFileName( "create_plane_page.html" );
117 //=================================================================================
118 // function : ~BasicGUI_PlaneDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
126 //=================================================================================
129 //=================================================================================
130 void BasicGUI_PlaneDlg::Init()
133 myEditCurrentArgument = GroupPntDir->LineEdit1;
135 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
137 // myGeomGUI->SetState( 0 );
139 /* Get setting of step value from file configuration */
140 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
141 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
143 double aTrimSize = 2000.0;
145 /* min, max, step and decimals for spin boxes */
146 initSpinBox( GroupPntDir->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
147 GroupPntDir->SpinBox_DX->setValue( aTrimSize );
148 initSpinBox( Group3Pnts->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
149 Group3Pnts->SpinBox_DX->setValue( aTrimSize );
150 initSpinBox( GroupFace->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
151 GroupFace->SpinBox_DX->setValue( aTrimSize );
153 /* signals and slots connections */
154 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
155 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
157 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
158 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
160 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
162 connect( GroupPntDir->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
163 connect( GroupPntDir->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
164 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
165 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
166 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
167 connect( GroupFace->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
169 connect( GroupPntDir->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
170 connect( GroupPntDir->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
171 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
172 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
173 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
174 connect( GroupFace->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
176 connect( GroupPntDir->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
177 connect( Group3Pnts->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
178 connect( GroupFace->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
180 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
182 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
184 initName( tr( "GEOM_PLANE" ) );
186 ConstructorsClicked( 0 );
189 //=================================================================================
190 // function : SetDoubleSpinBoxStep()
191 // purpose : Double spin box management
192 //=================================================================================
193 void BasicGUI_PlaneDlg::SetDoubleSpinBoxStep( double step )
195 GroupPntDir->SpinBox_DX->setSingleStep(step);
196 Group3Pnts->SpinBox_DX->setSingleStep(step);
197 GroupFace->SpinBox_DX->setSingleStep(step);
201 //=================================================================================
202 // function : ConstructorsClicked()
203 // purpose : Radio button management
204 //=================================================================================
205 void BasicGUI_PlaneDlg::ConstructorsClicked( int constructorId )
207 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
208 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
210 switch ( constructorId ) {
211 case 0: /* plane from a point and a direction (vector, edge...) */
217 myEditCurrentArgument = GroupPntDir->LineEdit1;
218 GroupPntDir->LineEdit1->setText( "" );
219 GroupPntDir->LineEdit2->setText( "" );
221 /* for the first argument */
222 globalSelection(); // close local contexts, if any
223 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
226 case 1: /* plane from 3 points */
232 myEditCurrentArgument = Group3Pnts->LineEdit1;
233 Group3Pnts->LineEdit1->setText( "" );
234 Group3Pnts->LineEdit2->setText( "" );
235 Group3Pnts->LineEdit3->setText( "" );
237 /* for the first argument */
238 globalSelection(); // close local contexts, if any
239 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
242 case 2: /* plane from a planar face selection */
248 myEditCurrentArgument = GroupFace->LineEdit1;
249 GroupFace->LineEdit1->setText( "" );
251 /* for the first argument */
252 //globalSelection( GEOM_PLANE );
253 TColStd_MapOfInteger aMap;
254 aMap.Add( GEOM_PLANE );
255 aMap.Add( GEOM_MARKER );
256 globalSelection( aMap );
261 qApp->processEvents();
263 resize( minimumSize() );
265 myEditCurrentArgument->setFocus();
266 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
267 this, SLOT( SelectionIntoArgument() ) );
271 //=================================================================================
272 // function : ClickOnOk()
274 //=================================================================================
275 void BasicGUI_PlaneDlg::ClickOnOk()
277 if ( ClickOnApply() )
282 //=================================================================================
283 // function : ClickOnApply()
285 //=================================================================================
286 bool BasicGUI_PlaneDlg::ClickOnApply()
292 ConstructorsClicked( getConstructorId() );
296 //=================================================================================
297 // function : SelectionIntoArgument()
298 // purpose : Called when selection has changed
299 //=================================================================================
300 void BasicGUI_PlaneDlg::SelectionIntoArgument()
302 myEditCurrentArgument->setText("");
304 if ( IObjectCount() != 1 ) {
305 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
306 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
307 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
308 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
309 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
310 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = GEOM::GEOM_Object::_nil();
315 Standard_Boolean aRes = Standard_False;
316 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
317 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
318 QString aName = GEOMBase::GetName( aSelectedObject );
321 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
322 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
323 if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
324 aNeedType = TopAbs_EDGE;
325 else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
326 aNeedType = TopAbs_FACE;
328 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
329 TColStd_IndexedMapOfInteger aMap;
330 aSelMgr->GetIndexes( firstIObject(), aMap );
331 if ( aMap.Extent() == 1 ) { // Local Selection
332 int anIndex = aMap( 1 );
333 if ( aNeedType == TopAbs_EDGE )
334 aName += QString( ":edge_%1" ).arg( anIndex );
335 else if (aNeedType == TopAbs_FACE)
336 aName += QString( ":face_%1" ).arg( anIndex );
338 aName += QString( ":vertex_%1" ).arg( anIndex );
340 //Find SubShape Object in Father
341 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
343 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
344 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
345 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
348 aSelectedObject = aFindedObject; // get Object from study
351 else { // Global Selection
352 if ( aShape.ShapeType() != aNeedType ) {
353 aSelectedObject = GEOM::GEOM_Object::_nil();
359 myEditCurrentArgument->setText( aName );
361 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = aSelectedObject;
362 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = aSelectedObject;
363 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
364 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
365 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
366 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = aSelectedObject;
373 //=================================================================================
374 // function : SetEditCurrentArgument()
376 //=================================================================================
377 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
379 QPushButton* send = (QPushButton*)sender();
380 globalSelection( GEOM_POINT );
382 if ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
383 else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
384 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
385 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
386 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
387 else if ( send == GroupFace->PushButton1 ) myEditCurrentArgument = GroupFace->LineEdit1;
389 myEditCurrentArgument->setFocus();
391 if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) {
392 globalSelection(); // close local contexts, if any
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
395 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
396 TColStd_MapOfInteger aMap;
397 aMap.Add( GEOM_PLANE );
398 aMap.Add( GEOM_MARKER );
399 globalSelection( aMap );
402 globalSelection(); // close local contexts, if any
403 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
406 SelectionIntoArgument();
410 //=================================================================================
411 // function : LineEditReturnPressed()
413 //=================================================================================
414 void BasicGUI_PlaneDlg::LineEditReturnPressed()
416 QLineEdit* send = (QLineEdit*)sender();
417 if ( send == GroupPntDir->LineEdit1 ||
418 send == GroupPntDir->LineEdit2 ||
419 send == Group3Pnts->LineEdit1 ||
420 send == Group3Pnts->LineEdit2 ||
421 send == Group3Pnts->LineEdit3 ||
422 send == GroupFace->LineEdit1 ) {
423 myEditCurrentArgument = send;
424 GEOMBase_Skeleton::LineEditReturnPressed();
429 //=================================================================================
430 // function : ActivateThisDialog()
432 //=================================================================================
433 void BasicGUI_PlaneDlg::ActivateThisDialog()
435 GEOMBase_Skeleton::ActivateThisDialog();
436 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
437 this, SLOT( SelectionIntoArgument() ) );
439 ConstructorsClicked( getConstructorId() );
442 //=================================================================================
443 // function : DeactivateActiveDialog()
444 // purpose : public slot to deactivate if active
445 //=================================================================================
446 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
448 GEOMBase_Skeleton::DeactivateActiveDialog();
451 //=================================================================================
452 // function : enterEvent()
454 //=================================================================================
455 void BasicGUI_PlaneDlg::enterEvent( QEvent* )
457 if ( !mainFrame()->GroupConstructors->isEnabled() )
458 ActivateThisDialog();
462 //=================================================================================
463 // function : ValueChangedInSpinBox()
465 //=================================================================================
466 void BasicGUI_PlaneDlg::ValueChangedInSpinBox( double newValue )
471 //=================================================================================
472 // function : getSize()
474 //=================================================================================
475 double BasicGUI_PlaneDlg::getSize() const
477 switch ( getConstructorId() ) {
478 case 0 : return GroupPntDir->SpinBox_DX->value();
479 case 1 : return Group3Pnts->SpinBox_DX->value();
480 case 2 : return GroupFace->SpinBox_DX->value();
485 //=================================================================================
486 // function : createOperation
488 //=================================================================================
489 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
491 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
494 //=================================================================================
495 // function : isEqual
496 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
497 //=================================================================================
498 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
500 return thePnt1->_is_equivalent( thePnt2 );
503 //=================================================================================
504 // function : isValid
506 //=================================================================================
507 bool BasicGUI_PlaneDlg::isValid( QString& msg )
509 const int id = getConstructorId();
510 if ( getSize() <= 0 ) {
511 msg = QString( "Please, enter size greater than 0." );
515 return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
517 return !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
518 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
520 return !CORBA::is_nil( myFace );
524 //=================================================================================
525 // function : execute
527 //=================================================================================
528 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
532 GEOM::GEOM_Object_var anObj;
534 switch ( getConstructorId() ) {
536 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
540 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
544 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
549 if ( !anObj->_is_nil() )
550 objects.push_back( anObj._retn() );
554 //=================================================================================
555 // function : addSubshapeToStudy
556 // purpose : virtual method to add new SubObjects if local selection
557 //=================================================================================
558 void BasicGUI_PlaneDlg::addSubshapesToStudy()
560 QMap<QString, GEOM::GEOM_Object_var> objMap;
562 switch ( getConstructorId() ) {
564 objMap[GroupPntDir->LineEdit1->text()] = myPoint;
565 objMap[GroupPntDir->LineEdit2->text()] = myDir;
568 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
569 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
570 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
573 objMap[GroupFace->LineEdit1->text()] = myFace;
576 addSubshapesToFather( objMap );