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_ArcDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_ArcDlg.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 <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : BasicGUI_ArcDlg()
48 // purpose : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 BasicGUI_ArcDlg::BasicGUI_ArcDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_CENTER" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_ARC_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 Group3Pnts = new DlgRef_3Sel( centralWidget() );
73 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
74 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
75 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
76 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 3 ) );
78 Group3Pnts->LineEdit1->setReadOnly( true );
79 Group3Pnts->LineEdit2->setReadOnly( true );
80 Group3Pnts->LineEdit3->setReadOnly( true );
82 Group3Pnts->LineEdit1->setEnabled(true);
83 Group3Pnts->LineEdit2->setEnabled(false);
84 Group3Pnts->LineEdit3->setEnabled(false);
86 Group3Pnts->PushButton1->setIcon(image2);
87 Group3Pnts->PushButton2->setIcon(image2);
88 Group3Pnts->PushButton3->setIcon(image2);
91 Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
93 Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
94 Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
95 Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
96 Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
98 Group3Pnts2->LineEdit1->setReadOnly( true );
99 Group3Pnts2->LineEdit2->setReadOnly( true );
100 Group3Pnts2->LineEdit3->setReadOnly( true );
102 Group3Pnts2->LineEdit1->setEnabled(true);
103 Group3Pnts2->LineEdit2->setEnabled(false);
104 Group3Pnts2->LineEdit3->setEnabled(false);
106 Group3Pnts2->PushButton1->setIcon( image2 );
107 Group3Pnts2->PushButton2->setIcon( image2 );
108 Group3Pnts2->PushButton3->setIcon( image2 );
110 Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
112 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
113 layout->setMargin( 0 ); layout->setSpacing( 6 );
114 layout->addWidget( Group3Pnts );
115 layout->addWidget( Group3Pnts2 );
117 setHelpFileName( "create_arc_page.html" );
123 //=================================================================================
124 // function : ~BasicGUI_ArcDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
132 //=================================================================================
135 //=================================================================================
136 void BasicGUI_ArcDlg::Init()
139 myEditCurrentArgument = Group3Pnts->LineEdit1;
141 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
142 Group3Pnts2->CheckButton1->setChecked( false );
143 Group3Pnts->PushButton1->setDown(true);
145 /* signals and slots connections */
146 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
147 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
149 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
151 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
152 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
154 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
155 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
156 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
158 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
160 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
162 connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
163 connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
164 connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
166 connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
167 connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
168 connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
170 connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
172 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
173 this, SLOT( SelectionIntoArgument() ) );
175 initName( tr( "GEOM_ARC" ) );
178 ConstructorsClicked( 0 );
182 //=================================================================================
183 // function : ClickOnOk()
185 //=================================================================================
186 void BasicGUI_ArcDlg::ClickOnOk()
188 if ( ClickOnApply() )
192 //=================================================================================
193 // function : ClickOnApply()
195 //=================================================================================
196 bool BasicGUI_ArcDlg::ClickOnApply()
202 ConstructorsClicked( getConstructorId() );
208 //=================================================================================
209 // function : SelectionIntoArgument()
210 // purpose : Called when selection as changed or other case
211 //=================================================================================
212 void BasicGUI_ArcDlg::SelectionIntoArgument()
214 if ( getConstructorId() != 0 && getConstructorId() != 1 )
217 myEditCurrentArgument->setText( "" );
218 if ( IObjectCount() != 1 ) {
219 switch ( getConstructorId() ) {
221 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
222 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
223 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
227 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
228 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
229 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
235 Standard_Boolean aRes = Standard_False;
236 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
237 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
238 QString aName = GEOMBase::GetName(aSelectedObject);
240 // Get Selected object if selected subshape
242 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
244 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
245 TColStd_IndexedMapOfInteger aMap;
246 aSelMgr->GetIndexes(firstIObject(), aMap);
247 if (aMap.Extent() == 1) // Local Selection
249 int anIndex = aMap(1);
250 aName += QString(":vertex_%1").arg(anIndex);
252 //Find SubShape Object in Father
253 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
255 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
256 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
257 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
260 aSelectedObject = aFindedObject; // get Object from study
262 else // Global Selection
264 if (aShape.ShapeType() != TopAbs_VERTEX) {
265 aSelectedObject = GEOM::GEOM_Object::_nil();
271 myEditCurrentArgument->setText(aName);
273 if (!aSelectedObject->_is_nil()) { // clear selection if something selected
275 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
278 switch ( getConstructorId() ) {
280 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
281 myPoint1 = aSelectedObject;
282 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
283 Group3Pnts->PushButton2->click();
285 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
286 myPoint2 = aSelectedObject;
287 if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
288 Group3Pnts->PushButton3->click();
290 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
291 myPoint3 = aSelectedObject;
292 if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
293 Group3Pnts->PushButton1->click();
297 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) {
298 myPoint1 = aSelectedObject;
299 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
300 Group3Pnts2->PushButton2->click();
302 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) {
303 myPoint2 = aSelectedObject;
304 if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
305 Group3Pnts2->PushButton3->click();
307 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) {
308 myPoint3 = aSelectedObject;
309 if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
310 Group3Pnts2->PushButton1->click();
320 //=================================================================================
321 // function : SetEditCurrentArgument()
323 //=================================================================================
324 void BasicGUI_ArcDlg::SetEditCurrentArgument()
326 globalSelection(); // close local selection to clear it
327 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
329 QPushButton* send = (QPushButton*)sender();
330 switch ( getConstructorId() ) {
332 if ( send == Group3Pnts->PushButton1 ) {
333 myEditCurrentArgument = Group3Pnts->LineEdit1;
334 Group3Pnts->PushButton2->setDown(false);
335 Group3Pnts->PushButton3->setDown(false);
336 Group3Pnts->LineEdit1->setEnabled(true);
337 Group3Pnts->LineEdit2->setEnabled(false);
338 Group3Pnts->LineEdit3->setEnabled(false);
340 else if ( send == Group3Pnts->PushButton2 ) {
341 myEditCurrentArgument = Group3Pnts->LineEdit2;
342 Group3Pnts->PushButton1->setDown(false);
343 Group3Pnts->PushButton3->setDown(false);
344 Group3Pnts->LineEdit1->setEnabled(false);
345 Group3Pnts->LineEdit2->setEnabled(true);
346 Group3Pnts->LineEdit3->setEnabled(false);
348 else if ( send == Group3Pnts->PushButton3 ) {
349 myEditCurrentArgument = Group3Pnts->LineEdit3;
350 Group3Pnts->PushButton1->setDown(false);
351 Group3Pnts->PushButton2->setDown(false);
352 Group3Pnts->LineEdit1->setEnabled(false);
353 Group3Pnts->LineEdit2->setEnabled(false);
354 Group3Pnts->LineEdit3->setEnabled(true);
358 if ( send == Group3Pnts2->PushButton1 ) {
359 myEditCurrentArgument = Group3Pnts2->LineEdit1;
360 Group3Pnts2->PushButton2->setDown(false);
361 Group3Pnts2->PushButton3->setDown(false);
362 Group3Pnts2->LineEdit1->setEnabled(true);
363 Group3Pnts2->LineEdit2->setEnabled(false);
364 Group3Pnts2->LineEdit3->setEnabled(false);
366 else if ( send == Group3Pnts2->PushButton2 ) {
367 myEditCurrentArgument = Group3Pnts2->LineEdit2;
368 Group3Pnts2->PushButton1->setDown(false);
369 Group3Pnts2->PushButton3->setDown(false);
370 Group3Pnts2->LineEdit1->setEnabled(false);
371 Group3Pnts2->LineEdit2->setEnabled(true);
372 Group3Pnts2->LineEdit3->setEnabled(false);
374 else if ( send == Group3Pnts2->PushButton3 ) {
375 myEditCurrentArgument = Group3Pnts2->LineEdit3;
376 Group3Pnts2->PushButton1->setDown(false);
377 Group3Pnts2->PushButton2->setDown(false);
378 Group3Pnts2->LineEdit1->setEnabled(false);
379 Group3Pnts2->LineEdit2->setEnabled(false);
380 Group3Pnts2->LineEdit3->setEnabled(true);
384 myEditCurrentArgument->setFocus();
385 // SelectionIntoArgument();
391 //=================================================================================
392 // function : LineEditReturnPressed()
394 //=================================================================================
395 void BasicGUI_ArcDlg::LineEditReturnPressed()
397 QLineEdit* send = (QLineEdit*)sender();
398 if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
399 send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ) {
400 myEditCurrentArgument = send;
401 GEOMBase_Skeleton::LineEditReturnPressed();
406 //=================================================================================
407 // function : ActivateThisDialog()
409 //=================================================================================
410 void BasicGUI_ArcDlg::ActivateThisDialog()
412 GEOMBase_Skeleton::ActivateThisDialog();
414 connect( myGeomGUI->getApp()->selectionMgr(),
415 SIGNAL( currentSelectionChanged() ),
417 SLOT(SelectionIntoArgument() ) );
419 ConstructorsClicked( getConstructorId() );
422 //=================================================================================
423 // function : enterEvent()
425 //=================================================================================
426 void BasicGUI_ArcDlg::enterEvent( QEvent* )
428 if ( !mainFrame()->GroupConstructors->isEnabled() )
429 ActivateThisDialog();
432 //=================================================================================
433 // function : createOperation
435 //=================================================================================
436 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
438 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
441 //=================================================================================
442 // function : isEqual
443 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
444 //=================================================================================
445 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
447 return thePnt1->_is_equivalent( thePnt2 );
450 //=================================================================================
451 // function : isValid
453 //=================================================================================
454 bool BasicGUI_ArcDlg::isValid( QString& msg )
456 switch (getConstructorId()) {
459 if (Group3Pnts->LineEdit1->text().trimmed().isEmpty() ||
460 Group3Pnts->LineEdit2->text().trimmed().isEmpty() ||
461 Group3Pnts->LineEdit3->text().trimmed().isEmpty())
467 if (Group3Pnts2->LineEdit1->text().trimmed().isEmpty() ||
468 Group3Pnts2->LineEdit2->text().trimmed().isEmpty() ||
469 Group3Pnts2->LineEdit3->text().trimmed().isEmpty())
474 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
475 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
478 //=================================================================================
479 // function : execute
481 //=================================================================================
482 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
485 GEOM::GEOM_Object_var anObj;
487 switch ( getConstructorId() ) {
490 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
491 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
498 bool Sense = Group3Pnts2->CheckButton1->isChecked();
499 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
500 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
506 if ( !anObj->_is_nil() ) {
507 objects.push_back( anObj._retn() );
512 //=================================================================================
513 // function : ConstructorsClicked()
514 // purpose : Radio button management
515 //=================================================================================
516 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
518 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
520 switch ( constructorId ) {
523 globalSelection(); // close local contexts, if any
524 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
528 Group3Pnts->PushButton1->setDown(true);
529 Group3Pnts->PushButton2->setDown(false);
530 Group3Pnts->PushButton3->setDown(false);
531 Group3Pnts->LineEdit1->setText( "" );
532 Group3Pnts->LineEdit2->setText( "" );
533 Group3Pnts->LineEdit3->setText( "" );
534 Group3Pnts->LineEdit1->setEnabled(true);
535 Group3Pnts->LineEdit2->setEnabled(false);
536 Group3Pnts->LineEdit3->setEnabled(false);
537 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
539 myEditCurrentArgument = Group3Pnts->LineEdit1;
544 globalSelection(); // close local contexts, if any
545 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
549 Group3Pnts2->PushButton1->setDown(true);
550 Group3Pnts2->PushButton2->setDown(false);
551 Group3Pnts2->PushButton3->setDown(false);
552 Group3Pnts2->LineEdit1->setText( "" );
553 Group3Pnts2->LineEdit2->setText( "" );
554 Group3Pnts2->LineEdit3->setText( "" );
555 Group3Pnts2->LineEdit1->setEnabled(true);
556 Group3Pnts2->LineEdit2->setEnabled(false);
557 Group3Pnts2->LineEdit3->setEnabled(false);
558 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
560 myEditCurrentArgument = Group3Pnts2->LineEdit1;
565 qApp->processEvents();
567 resize( minimumSize() );
569 myEditCurrentArgument->setFocus();
570 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
571 this, SLOT( SelectionIntoArgument() ) );
573 if ( CORBA::is_nil( myPoint1 ) )
574 SelectionIntoArgument();
579 //=================================================================================
580 // function : ReverseSense()
581 // purpose : Orientation of the arc
582 //=================================================================================
583 void BasicGUI_ArcDlg::ReverseSense()
588 //=================================================================================
589 // function : addSubshapeToStudy
590 // purpose : virtual method to add new SubObjects if local selection
591 //=================================================================================
592 void BasicGUI_ArcDlg::addSubshapesToStudy()
594 QMap<QString, GEOM::GEOM_Object_var> objMap;
596 switch ( getConstructorId() ) {
598 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
599 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
600 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
603 objMap[Group3Pnts2->LineEdit1->text()] = myPoint1;
604 objMap[Group3Pnts2->LineEdit2->text()] = myPoint2;
605 objMap[Group3Pnts2->LineEdit3->text()] = myPoint3;
608 addSubshapesToFather( objMap );