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_CircleDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_CircleDlg.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 : BasicGUI_CircleDlg()
47 // purpose : Constructs a BasicGUI_CircleDlg 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_CircleDlg::BasicGUI_CircleDlg( 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_CIRCLE_PV" ) ) );
57 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PNTS" ) ) );
58 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_C2P" ) ) );
59 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_CIRCLE_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setIcon( image2 );
67 mainFrame()->RadioButton3->setIcon( image3 );
69 GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
70 GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) + " (Origin by default)" );
73 GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " (Z axis by default)" );
74 GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
75 GroupPntVecR->PushButton1->setIcon( image1 );
76 GroupPntVecR->PushButton2->setIcon( image1 );
78 GroupPntVecR->LineEdit1->setReadOnly( true );
79 GroupPntVecR->LineEdit2->setReadOnly( true );
81 Group3Pnts = new DlgRef_3Sel( 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->PushButton1->setIcon( image1 );
88 Group3Pnts->PushButton2->setIcon( image1 );
89 Group3Pnts->PushButton3->setIcon( image1 );
91 Group3Pnts->LineEdit1->setReadOnly( true );
92 Group3Pnts->LineEdit2->setReadOnly( true );
93 Group3Pnts->LineEdit3->setReadOnly( true );
95 GroupCenter2Pnts = new DlgRef_3Sel( centralWidget() );
96 GroupCenter2Pnts->GroupBox1->setTitle( tr( "GEOM_CENTER_2POINTS" ) );
97 GroupCenter2Pnts->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
98 GroupCenter2Pnts->TextLabel2->setText( tr( "GEOM_POINT1" ) );
99 GroupCenter2Pnts->TextLabel3->setText( tr( "GEOM_POINT2" ) );
100 GroupCenter2Pnts->PushButton1->setIcon( image1 );
101 GroupCenter2Pnts->PushButton2->setIcon( image1 );
102 GroupCenter2Pnts->PushButton3->setIcon( image1 );
104 GroupCenter2Pnts->LineEdit1->setReadOnly( true );
105 GroupCenter2Pnts->LineEdit2->setReadOnly( true );
106 GroupCenter2Pnts->LineEdit3->setReadOnly( true );
108 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
109 layout->setMargin( 0 ); layout->setSpacing( 6 );
110 layout->addWidget( GroupPntVecR );
111 layout->addWidget( Group3Pnts );
112 layout->addWidget( GroupCenter2Pnts );
113 /***************************************************************/
115 setHelpFileName( "create_circle_page.html" );
121 //=================================================================================
122 // function : ~BasicGUI_CircleDlg()
123 // purpose : Destroys the object and frees any allocated resources
124 //=================================================================================
125 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
130 //=================================================================================
133 //=================================================================================
134 void BasicGUI_CircleDlg::Init()
137 myEditCurrentArgument = GroupPntVecR->LineEdit1;
139 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
141 // myGeomGUI->SetState( 0 );
143 /* Get setting of step value from file configuration */
144 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
145 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
147 /* min, max, step and decimals for spin boxes & initial values */
148 initSpinBox( GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
149 GroupPntVecR->SpinBox_DX->setValue( 100 );
151 /* signals and slots connections */
152 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
153 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
155 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
156 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
158 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
160 connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
161 connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
162 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
163 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
164 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
166 connect( GroupCenter2Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
167 connect( GroupCenter2Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
168 connect( GroupCenter2Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
170 connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
171 connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
173 connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
174 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
176 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
177 this, SLOT( SelectionIntoArgument() ) );
179 initName( tr( "GEOM_CIRCLE" ) );
181 ConstructorsClicked( 0 );
184 //=================================================================================
185 // function : SetDoubleSpinBoxStep()
186 // purpose : Double spin box management
187 //=================================================================================
188 void BasicGUI_CircleDlg::SetDoubleSpinBoxStep( double step )
190 GroupPntVecR->SpinBox_DX->setSingleStep(step);
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
199 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
201 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
203 switch ( constructorId ) {
207 GroupCenter2Pnts->hide();
208 GroupPntVecR->show();
210 myEditCurrentArgument = GroupPntVecR->LineEdit1;
211 GroupPntVecR->LineEdit1->setText( "" );
212 GroupPntVecR->LineEdit2->setText( "" );
217 GroupPntVecR->hide();
218 GroupCenter2Pnts->hide();
221 myEditCurrentArgument = Group3Pnts->LineEdit1;
222 Group3Pnts->LineEdit1->setText( "" );
223 Group3Pnts->LineEdit2->setText( "" );
224 Group3Pnts->LineEdit3->setText( "" );
229 GroupPntVecR->hide();
231 GroupCenter2Pnts->show();
233 myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
234 GroupCenter2Pnts->LineEdit1->setText( "" );
235 GroupCenter2Pnts->LineEdit2->setText( "" );
236 GroupCenter2Pnts->LineEdit3->setText( "" );
241 qApp->processEvents();
243 resize( minimumSize() );
245 myEditCurrentArgument->setFocus();
246 globalSelection(); // close local contexts, if any
247 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
249 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
250 this, SLOT( SelectionIntoArgument() ) );
255 //=================================================================================
256 // function : ClickOnOk()
258 //=================================================================================
259 void BasicGUI_CircleDlg::ClickOnOk()
261 if ( ClickOnApply() )
265 //=================================================================================
266 // function : ClickOnApply()
268 //=================================================================================
269 bool BasicGUI_CircleDlg::ClickOnApply()
275 ConstructorsClicked( getConstructorId() );
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose : Called when selection as changed or other case
282 //=================================================================================
283 void BasicGUI_CircleDlg::SelectionIntoArgument()
285 myEditCurrentArgument->setText( "" );
287 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
289 aSelMgr->selectedObjects( aList );
291 if ( aList.Extent() != 1 ) {
292 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
293 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
294 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
295 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
296 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
297 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = GEOM::GEOM_Object::_nil();
298 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = GEOM::GEOM_Object::_nil();
299 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = GEOM::GEOM_Object::_nil();
304 Handle(SALOME_InteractiveObject) anIO = aList.First();
306 Standard_Boolean aRes = Standard_False;
307 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
308 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
309 QString aName = GEOMBase::GetName( aSelectedObject );
311 // If selected Vertex or Edge on the some Shape Get selection Subshape
313 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
314 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
315 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
316 aNeedType = TopAbs_EDGE;
318 TColStd_IndexedMapOfInteger aMap;
319 aSelMgr->GetIndexes(anIO, aMap);
320 if ( aMap.Extent() == 1 ) { // Local Selection
321 int anIndex = aMap(1);
322 if ( aNeedType == TopAbs_EDGE )
323 aName += QString( ":edge_%1" ).arg( anIndex );
325 aName += QString( ":vertex_%1" ).arg( anIndex );
327 //Find SubShape Object in Father
328 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
330 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
331 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
332 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
335 aSelectedObject = aFindedObject; // get Object from study
338 else { // Global Selection
339 if ( aShape.ShapeType() != aNeedType ) {
340 aSelectedObject = GEOM::GEOM_Object::_nil();
346 myEditCurrentArgument->setText( aName );
348 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
349 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
350 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
351 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
352 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
353 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = aSelectedObject;
354 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = aSelectedObject;
355 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = aSelectedObject;
362 //=================================================================================
363 // function : SetEditCurrentArgument()
365 //=================================================================================
366 void BasicGUI_CircleDlg::SetEditCurrentArgument()
368 QPushButton* send = (QPushButton*)sender();
370 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
371 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
372 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
373 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
374 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
375 else if ( send == GroupCenter2Pnts->PushButton1 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
376 else if ( send == GroupCenter2Pnts->PushButton2 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
377 else if ( send == GroupCenter2Pnts->PushButton3 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
380 myEditCurrentArgument->setFocus();
382 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
383 globalSelection(); // close local contexts, if any
384 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
387 globalSelection(); // close local contexts, if any
388 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
391 SelectionIntoArgument();
394 //=================================================================================
395 // function : LineEditReturnPressed()
397 //=================================================================================
398 void BasicGUI_CircleDlg::LineEditReturnPressed()
400 QLineEdit* send = (QLineEdit*)sender();
401 if ( send == GroupPntVecR->LineEdit1 ||
402 send == GroupPntVecR->LineEdit2 ||
403 send == Group3Pnts->LineEdit1 ||
404 send == Group3Pnts->LineEdit2 ||
405 send == Group3Pnts->LineEdit3 ||
406 send == GroupCenter2Pnts->LineEdit1 ||
407 send == GroupCenter2Pnts->LineEdit2 ||
408 send == GroupCenter2Pnts->LineEdit3 ) {
409 myEditCurrentArgument = send;
410 GEOMBase_Skeleton::LineEditReturnPressed();
415 //=================================================================================
416 // function : ActivateThisDialog()
418 //=================================================================================
419 void BasicGUI_CircleDlg::ActivateThisDialog()
421 GEOMBase_Skeleton::ActivateThisDialog();
423 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
424 this, SLOT( SelectionIntoArgument() ) );
426 ConstructorsClicked( getConstructorId() );
430 //=================================================================================
431 // function : enterEvent()
433 //=================================================================================
434 void BasicGUI_CircleDlg::enterEvent( QEvent* )
436 if ( !mainFrame()->GroupConstructors->isEnabled() )
437 ActivateThisDialog();
440 //=================================================================================
441 // function : DeactivateActiveDialog()
442 // purpose : public slot to deactivate if active
443 //=================================================================================
444 void BasicGUI_CircleDlg::DeactivateActiveDialog()
446 // myGeomGUI->SetState( -1 );
447 GEOMBase_Skeleton::DeactivateActiveDialog();
450 //=================================================================================
451 // function : ValueChangedInSpinBox()
453 //=================================================================================
454 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
459 //=================================================================================
460 // function : getRadius()
462 //=================================================================================
463 double BasicGUI_CircleDlg::getRadius() const
466 switch ( getConstructorId() ) {
468 r = GroupPntVecR->SpinBox_DX->value(); break;
473 //=================================================================================
474 // function : createOperation
476 //=================================================================================
477 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
479 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
482 //=================================================================================
483 // function : isEqual
484 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
485 //=================================================================================
486 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
488 return thePnt1->_is_equivalent( thePnt2 );
491 //=================================================================================
492 // function : isValid
494 //=================================================================================
495 bool BasicGUI_CircleDlg::isValid( QString& msg )
497 const int id = getConstructorId();
499 //return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
500 //nil point means origin of global CS
501 //nil vector means Z axis
502 return getRadius() > 0;
504 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
505 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
507 return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() &&
508 !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 );
512 //=================================================================================
513 // function : execute
515 //=================================================================================
516 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
520 GEOM::GEOM_Object_var anObj;
522 switch ( getConstructorId() ) {
524 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
528 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
532 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleCenter2Pnt( myPoint4, myPoint5, myPoint6 );
537 if ( !anObj->_is_nil() )
538 objects.push_back( anObj._retn() );
540 MESSAGE( "Execute Object is NULL!" );
546 //=================================================================================
547 // function : addSubshapeToStudy
548 // purpose : virtual method to add new SubObjects if local selection
549 //=================================================================================
550 void BasicGUI_CircleDlg::addSubshapesToStudy()
552 QMap<QString, GEOM::GEOM_Object_var> objMap;
554 switch ( getConstructorId() ) {
556 if (!CORBA::is_nil(myPoint))
557 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
558 if (!CORBA::is_nil(myDir))
559 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
562 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
563 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
564 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
567 objMap[GroupCenter2Pnts->LineEdit1->text()] = myPoint4;
568 objMap[GroupCenter2Pnts->LineEdit2->text()] = myPoint5;
569 objMap[GroupCenter2Pnts->LineEdit3->text()] = myPoint6;
572 addSubshapesToFather( objMap );