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_DiskDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_DiskDlg.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_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
45 //=================================================================================
46 // class : PrimitiveGUI_DiskDlg()
47 // purpose : Constructs a PrimitiveGUI_DiskDlg 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_DiskDlg::PrimitiveGUI_DiskDlg( 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_DISK_PNT_VEC_R" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_THREE_POINTS" ) ) );
59 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_R" ) ) );
61 setWindowTitle( tr( "GEOM_DISK_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_DISK" ) );
65 mainFrame()->RadioButton1->setIcon( image3 );
66 mainFrame()->RadioButton2->setIcon( image0 );
67 mainFrame()->RadioButton3->setIcon( image2 );
69 GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
70 GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
71 GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
72 GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
73 GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
74 GroupPntVecR->PushButton1->setIcon( image1 );
75 GroupPntVecR->PushButton2->setIcon( image1 );
76 GroupPntVecR->LineEdit1->setReadOnly( true );
77 GroupPntVecR->LineEdit2->setReadOnly( true );
79 Group3Pnts = new DlgRef_3Sel( centralWidget() );
80 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
81 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
82 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
83 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
84 Group3Pnts->PushButton1->setIcon( image1 );
85 Group3Pnts->PushButton2->setIcon( image1 );
86 Group3Pnts->PushButton3->setIcon( image1 );
87 Group3Pnts->LineEdit1->setReadOnly( true );
88 Group3Pnts->LineEdit2->setReadOnly( true );
89 Group3Pnts->LineEdit3->setReadOnly( true );
91 GroupDimensions = new DlgRef_1Spin( centralWidget() );
92 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
93 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) );
95 GroupOrientation = new DlgRef_3Radio( centralWidget() );
96 GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
97 GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
98 GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
99 GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
101 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
102 layout->setMargin( 0 ); layout->setSpacing( 6 );
103 layout->addWidget( GroupPntVecR );
104 layout->addWidget( Group3Pnts );
105 layout->addWidget( GroupDimensions );
106 layout->addWidget( GroupOrientation );
107 /***************************************************************/
109 setHelpFileName( "create_disk_page.html" );
115 //=================================================================================
116 // function : ~PrimitiveGUI_DiskDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
124 //=================================================================================
127 //=================================================================================
128 void PrimitiveGUI_DiskDlg::Init()
131 myEditCurrentArgument = GroupPntVecR->LineEdit1;
132 myOrientationType = 1;
134 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
136 /* Get setting of step value from file configuration */
137 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
138 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
140 /* min, max, step and decimals for spin boxes & initial values */
141 initSpinBox( GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
142 GroupPntVecR->SpinBox_DX->setValue( 100 );
143 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
144 GroupDimensions->SpinBox_DX->setValue( 100 );
146 /* signals and slots connections */
147 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
148 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
150 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
151 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
153 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
155 connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
156 connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
157 connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
160 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
161 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
162 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
163 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
164 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
165 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
167 connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
168 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
170 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
171 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
172 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
175 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
176 this, SLOT( SelectionIntoArgument() ) );
178 initName( tr( "GEOM_DISK" ) );
180 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : SetDoubleSpinBoxStep()
185 // purpose : Double spin box management
186 //=================================================================================
187 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep( double step )
189 GroupPntVecR->SpinBox_DX->setSingleStep(step);
192 //=================================================================================
193 // function : RadioBittonClicked()
194 // purpose : Radio button management
195 //=================================================================================
196 void PrimitiveGUI_DiskDlg::RadioButtonClicked()
198 if ( GroupOrientation->RadioButton1->isChecked() )
199 myOrientationType = 1;
200 else if ( GroupOrientation->RadioButton2->isChecked() )
201 myOrientationType = 2;
202 else if ( GroupOrientation->RadioButton3->isChecked() )
203 myOrientationType = 3;
207 //=================================================================================
208 // function : ConstructorsClicked()
209 // purpose : Radio button management
210 //=================================================================================
211 void PrimitiveGUI_DiskDlg::ConstructorsClicked( int constructorId )
213 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
215 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
217 switch ( constructorId ) {
220 GroupPntVecR->hide();
222 GroupDimensions->show();
223 GroupOrientation->show();
224 GroupOrientation->RadioButton1->setChecked( true );
225 myOrientationType = 1;
231 GroupPntVecR->show();
232 GroupDimensions->hide();
233 GroupOrientation->hide();
234 myEditCurrentArgument = GroupPntVecR->LineEdit1;
235 GroupPntVecR->LineEdit1->setText( "" );
236 GroupPntVecR->LineEdit2->setText( "" );
241 GroupPntVecR->hide();
243 GroupDimensions->hide();
244 GroupOrientation->hide();
245 myEditCurrentArgument = Group3Pnts->LineEdit1;
246 Group3Pnts->LineEdit1->setText( "" );
247 Group3Pnts->LineEdit2->setText( "" );
248 Group3Pnts->LineEdit3->setText( "" );
253 qApp->processEvents();
255 resize( minimumSize() );
257 myEditCurrentArgument->setFocus();
258 globalSelection(); // close local contexts, if any
259 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
261 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
262 this, SLOT( SelectionIntoArgument() ) );
266 //=================================================================================
267 // function : ClickOnOk()
269 //=================================================================================
270 void PrimitiveGUI_DiskDlg::ClickOnOk()
272 if ( ClickOnApply() )
276 //=================================================================================
277 // function : ClickOnApply()
279 //=================================================================================
280 bool PrimitiveGUI_DiskDlg::ClickOnApply()
286 ConstructorsClicked( getConstructorId() );
290 //=================================================================================
291 // function : SelectionIntoArgument()
292 // purpose : Called when selection as changed or other case
293 //=================================================================================
294 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
296 if (getConstructorId() == 0) {
301 myEditCurrentArgument->setText( "" );
303 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
305 aSelMgr->selectedObjects( aList );
307 if ( aList.Extent() != 1 ) {
308 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
309 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
310 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
311 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
312 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
317 Handle(SALOME_InteractiveObject) anIO = aList.First();
319 Standard_Boolean aRes = Standard_False;
320 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
321 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
322 QString aName = GEOMBase::GetName( aSelectedObject );
324 // If selected Vertex or Edge on the some Shape Get selection Subshape
326 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
327 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
328 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
329 aNeedType = TopAbs_EDGE;
331 TColStd_IndexedMapOfInteger aMap;
332 aSelMgr->GetIndexes(anIO, aMap);
333 if ( aMap.Extent() == 1 ) { // Local Selection
334 int anIndex = aMap(1);
335 if ( aNeedType == TopAbs_EDGE )
336 aName += QString( ":edge_%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 == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
362 else if ( myEditCurrentArgument == GroupPntVecR->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;
372 //=================================================================================
373 // function : SetEditCurrentArgument()
375 //=================================================================================
376 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
378 QPushButton* send = (QPushButton*)sender();
380 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
381 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
382 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
383 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
384 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
386 myEditCurrentArgument->setFocus();
388 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
389 globalSelection(); // close local contexts, if any
390 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
393 globalSelection(); // close local contexts, if any
394 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
397 SelectionIntoArgument();
400 //=================================================================================
401 // function : LineEditReturnPressed()
403 //=================================================================================
404 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
406 QLineEdit* send = (QLineEdit*)sender();
407 if ( send == GroupPntVecR->LineEdit1 ||
408 send == GroupPntVecR->LineEdit2 ||
409 send == Group3Pnts->LineEdit1 ||
410 send == Group3Pnts->LineEdit2 ||
411 send == Group3Pnts->LineEdit3 ) {
412 myEditCurrentArgument = send;
413 GEOMBase_Skeleton::LineEditReturnPressed();
418 //=================================================================================
419 // function : ActivateThisDialog()
421 //=================================================================================
422 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
424 GEOMBase_Skeleton::ActivateThisDialog();
426 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
427 this, SLOT( SelectionIntoArgument() ) );
429 ConstructorsClicked( getConstructorId() );
433 //=================================================================================
434 // function : enterEvent()
436 //=================================================================================
437 void PrimitiveGUI_DiskDlg::enterEvent( QEvent* )
439 if ( !mainFrame()->GroupConstructors->isEnabled() )
440 ActivateThisDialog();
443 //=================================================================================
444 // function : DeactivateActiveDialog()
445 // purpose : public slot to deactivate if active
446 //=================================================================================
447 void PrimitiveGUI_DiskDlg::DeactivateActiveDialog()
449 // myGeomGUI->SetState( -1 );
450 GEOMBase_Skeleton::DeactivateActiveDialog();
453 //=================================================================================
454 // function : ValueChangedInSpinBox()
456 //=================================================================================
457 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
462 //=================================================================================
463 // function : getRadius()
465 //=================================================================================
466 double PrimitiveGUI_DiskDlg::getRadius() const
469 switch ( getConstructorId() ) {
471 r = GroupDimensions->SpinBox_DX->value(); break;
473 r = GroupPntVecR->SpinBox_DX->value(); break;
478 //=================================================================================
479 // function : createOperation
481 //=================================================================================
482 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
484 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
487 //=================================================================================
488 // function : isEqual
489 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
490 //=================================================================================
491 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
493 return thePnt1->_is_equivalent( thePnt2 );
496 //=================================================================================
497 // function : isValid
499 //=================================================================================
500 bool PrimitiveGUI_DiskDlg::isValid( QString& msg )
502 const int id = getConstructorId();
506 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
508 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
509 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
513 //=================================================================================
514 // function : execute
516 //=================================================================================
517 bool PrimitiveGUI_DiskDlg::execute( ObjectList& objects )
521 GEOM::GEOM_Object_var anObj;
523 switch ( getConstructorId() ) {
525 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskR( getRadius(), myOrientationType );
529 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskPntVecR( myPoint, myDir, getRadius() );
533 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskThreePnt( myPoint1, myPoint2, myPoint3 );
538 if ( !anObj->_is_nil() )
539 objects.push_back( anObj._retn() );
541 MESSAGE( "Execute Object is NULL!" );
547 //=================================================================================
548 // function : addSubshapeToStudy
549 // purpose : virtual method to add new SubObjects if local selection
550 //=================================================================================
551 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
553 QMap<QString, GEOM::GEOM_Object_var> objMap;
555 switch ( getConstructorId() ) {
557 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
558 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
561 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
562 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
563 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
566 addSubshapesToFather( objMap );