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->PushButton1->setIcon(image2);
83 Group3Pnts->PushButton2->setIcon(image2);
84 Group3Pnts->PushButton3->setIcon(image2);
87 Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
89 Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
90 Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
91 Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
92 Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
94 Group3Pnts2->LineEdit1->setReadOnly( true );
95 Group3Pnts2->LineEdit2->setReadOnly( true );
96 Group3Pnts2->LineEdit3->setReadOnly( true );
98 Group3Pnts2->PushButton1->setIcon( image2 );
99 Group3Pnts2->PushButton2->setIcon( image2 );
100 Group3Pnts2->PushButton3->setIcon( image2 );
102 Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
104 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
105 layout->setMargin( 0 ); layout->setSpacing( 6 );
106 layout->addWidget( Group3Pnts );
107 layout->addWidget( Group3Pnts2 );
109 setHelpFileName( "create_arc_page.html" );
115 //=================================================================================
116 // function : ~BasicGUI_ArcDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
124 //=================================================================================
127 //=================================================================================
128 void BasicGUI_ArcDlg::Init()
131 myEditCurrentArgument = Group3Pnts->LineEdit1;
133 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
134 Group3Pnts2->CheckButton1->setChecked( false );
136 /* signals and slots connections */
137 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
138 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
140 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
142 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
143 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
145 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
147 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
149 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
150 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
151 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
153 connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
155 connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
157 connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159 connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
161 connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
163 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
164 this, SLOT( SelectionIntoArgument() ) );
166 initName( tr( "GEOM_ARC" ) );
169 ConstructorsClicked( 0 );
173 //=================================================================================
174 // function : ClickOnOk()
176 //=================================================================================
177 void BasicGUI_ArcDlg::ClickOnOk()
179 if ( ClickOnApply() )
183 //=================================================================================
184 // function : ClickOnApply()
186 //=================================================================================
187 bool BasicGUI_ArcDlg::ClickOnApply()
198 //=================================================================================
199 // function : SelectionIntoArgument()
200 // purpose : Called when selection as changed or other case
201 //=================================================================================
202 void BasicGUI_ArcDlg::SelectionIntoArgument()
204 if ( getConstructorId() != 0 && getConstructorId() != 1 )
207 myEditCurrentArgument->setText( "" );
208 if ( IObjectCount() != 1 ) {
209 switch ( getConstructorId() ) {
211 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
212 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
213 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
217 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
218 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
219 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
225 Standard_Boolean aRes = Standard_False;
226 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
227 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
228 QString aName = GEOMBase::GetName(aSelectedObject);
230 // Get Selected object if selected subshape
232 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
234 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
235 TColStd_IndexedMapOfInteger aMap;
236 aSelMgr->GetIndexes(firstIObject(), aMap);
237 if (aMap.Extent() == 1) // Local Selection
239 int anIndex = aMap(1);
240 aName += QString(":vertex_%1").arg(anIndex);
242 //Find SubShape Object in Father
243 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
245 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
246 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
247 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
250 aSelectedObject = aFindedObject; // get Object from study
252 else // Global Selection
254 if (aShape.ShapeType() != TopAbs_VERTEX) {
255 aSelectedObject = GEOM::GEOM_Object::_nil();
261 myEditCurrentArgument->setText(aName);
263 switch ( getConstructorId() ) {
265 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
266 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
267 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
270 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = aSelectedObject;
271 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = aSelectedObject;
272 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = aSelectedObject;
281 //=================================================================================
282 // function : SetEditCurrentArgument()
284 //=================================================================================
285 void BasicGUI_ArcDlg::SetEditCurrentArgument()
287 QPushButton* send = (QPushButton*)sender();
288 switch ( getConstructorId() ) {
290 if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
291 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
292 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
295 if ( send == Group3Pnts2->PushButton1 ) myEditCurrentArgument = Group3Pnts2->LineEdit1;
296 else if ( send == Group3Pnts2->PushButton2 ) myEditCurrentArgument = Group3Pnts2->LineEdit2;
297 else if ( send == Group3Pnts2->PushButton3 ) myEditCurrentArgument = Group3Pnts2->LineEdit3;
300 myEditCurrentArgument->setFocus();
301 SelectionIntoArgument();
305 //=================================================================================
306 // function : LineEditReturnPressed()
308 //=================================================================================
309 void BasicGUI_ArcDlg::LineEditReturnPressed()
311 QLineEdit* send = (QLineEdit*)sender();
312 if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
313 send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ) {
314 myEditCurrentArgument = send;
315 GEOMBase_Skeleton::LineEditReturnPressed();
320 //=================================================================================
321 // function : ActivateThisDialog()
323 //=================================================================================
324 void BasicGUI_ArcDlg::ActivateThisDialog()
326 GEOMBase_Skeleton::ActivateThisDialog();
328 connect( myGeomGUI->getApp()->selectionMgr(),
329 SIGNAL( currentSelectionChanged() ),
331 SLOT(SelectionIntoArgument() ) );
333 ConstructorsClicked( getConstructorId() );
336 //=================================================================================
337 // function : enterEvent()
339 //=================================================================================
340 void BasicGUI_ArcDlg::enterEvent( QEvent* )
342 if ( !mainFrame()->GroupConstructors->isEnabled() )
343 ActivateThisDialog();
346 //=================================================================================
347 // function : createOperation
349 //=================================================================================
350 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
352 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
355 //=================================================================================
356 // function : isEqual
357 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
358 //=================================================================================
359 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
361 return thePnt1->_is_equivalent( thePnt2 );
364 //=================================================================================
365 // function : isValid
367 //=================================================================================
368 bool BasicGUI_ArcDlg::isValid( QString& msg )
370 switch (getConstructorId()) {
373 if (Group3Pnts->LineEdit1->text().trimmed().isEmpty() ||
374 Group3Pnts->LineEdit2->text().trimmed().isEmpty() ||
375 Group3Pnts->LineEdit3->text().trimmed().isEmpty())
381 if (Group3Pnts2->LineEdit1->text().trimmed().isEmpty() ||
382 Group3Pnts2->LineEdit2->text().trimmed().isEmpty() ||
383 Group3Pnts2->LineEdit3->text().trimmed().isEmpty())
388 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
389 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
392 //=================================================================================
393 // function : execute
395 //=================================================================================
396 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
399 GEOM::GEOM_Object_var anObj;
401 switch ( getConstructorId() ) {
404 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
405 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
412 bool Sense = Group3Pnts2->CheckButton1->isChecked();
413 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
414 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
420 if ( !anObj->_is_nil() ) {
421 objects.push_back( anObj._retn() );
426 //=================================================================================
427 // function : ConstructorsClicked()
428 // purpose : Radio button management
429 //=================================================================================
430 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
432 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
434 switch ( constructorId ) {
437 globalSelection(); // close local contexts, if any
438 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
443 Group3Pnts->LineEdit1->setText( Group3Pnts2->LineEdit1->text() );
444 Group3Pnts->LineEdit2->setText( Group3Pnts2->LineEdit2->text() );
445 Group3Pnts->LineEdit3->setText( Group3Pnts2->LineEdit3->text() );
447 myEditCurrentArgument = Group3Pnts->LineEdit1;
452 globalSelection(); // close local contexts, if any
453 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
458 Group3Pnts2->LineEdit1->setText( Group3Pnts->LineEdit1->text() );
459 Group3Pnts2->LineEdit2->setText( Group3Pnts->LineEdit2->text() );
460 Group3Pnts2->LineEdit3->setText( Group3Pnts->LineEdit3->text() );
462 myEditCurrentArgument = Group3Pnts2->LineEdit1;
467 qApp->processEvents();
469 resize( minimumSize() );
471 myEditCurrentArgument->setFocus();
472 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
473 this, SLOT( SelectionIntoArgument() ) );
475 if ( CORBA::is_nil( myPoint1 ) )
476 SelectionIntoArgument();
481 //=================================================================================
482 // function : ReverseSense()
483 // purpose : Orientation of the arc
484 //=================================================================================
485 void BasicGUI_ArcDlg::ReverseSense()
490 //=================================================================================
491 // function : addSubshapeToStudy
492 // purpose : virtual method to add new SubObjects if local selection
493 //=================================================================================
494 void BasicGUI_ArcDlg::addSubshapesToStudy()
496 QMap<QString, GEOM::GEOM_Object_var> objMap;
498 switch ( getConstructorId() ) {
500 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
501 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
502 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
505 objMap[Group3Pnts2->LineEdit1->text()] = myPoint1;
506 objMap[Group3Pnts2->LineEdit2->text()] = myPoint2;
507 objMap[Group3Pnts2->LineEdit3->text()] = myPoint3;
510 addSubshapesToFather( objMap );