1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI_ArcDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BasicGUI_ArcDlg.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 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : BasicGUI_ArcDlg()
49 // purpose : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 BasicGUI_ArcDlg::BasicGUI_ArcDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl )
56 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
58 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC" ) ) );
60 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_CENTER" ) ) );
61 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_OF_ELLIPSE" ) ) );
64 setWindowTitle( tr( "GEOM_ARC_TITLE" ) );
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
68 mainFrame()->RadioButton1->setIcon( image0 );
69 mainFrame()->RadioButton2->setIcon( image1 );
70 mainFrame()->RadioButton3->setIcon( image3 );
72 Group3Pnts = new DlgRef_3Sel( centralWidget() );
74 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
75 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
76 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
77 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 3 ) );
79 Group3Pnts->LineEdit1->setReadOnly( true );
80 Group3Pnts->LineEdit2->setReadOnly( true );
81 Group3Pnts->LineEdit3->setReadOnly( true );
83 Group3Pnts->LineEdit1->setEnabled(true);
84 Group3Pnts->LineEdit2->setEnabled(false);
85 Group3Pnts->LineEdit3->setEnabled(false);
87 Group3Pnts->PushButton1->setIcon(image2);
88 Group3Pnts->PushButton2->setIcon(image2);
89 Group3Pnts->PushButton3->setIcon(image2);
92 Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
94 Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
95 Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
96 Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
97 Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
99 Group3Pnts2->LineEdit1->setReadOnly( true );
100 Group3Pnts2->LineEdit2->setReadOnly( true );
101 Group3Pnts2->LineEdit3->setReadOnly( true );
103 Group3Pnts2->LineEdit1->setEnabled(true);
104 Group3Pnts2->LineEdit2->setEnabled(false);
105 Group3Pnts2->LineEdit3->setEnabled(false);
107 Group3Pnts2->PushButton1->setIcon( image2 );
108 Group3Pnts2->PushButton2->setIcon( image2 );
109 Group3Pnts2->PushButton3->setIcon( image2 );
111 Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
113 Group3Pnts3 = new DlgRef_3Sel( centralWidget() );
115 Group3Pnts3->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
116 Group3Pnts3->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
117 Group3Pnts3->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
118 Group3Pnts3->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
120 Group3Pnts3->LineEdit1->setReadOnly( true );
121 Group3Pnts3->LineEdit2->setReadOnly( true );
122 Group3Pnts3->LineEdit3->setReadOnly( true );
124 Group3Pnts3->LineEdit1->setEnabled(true);
125 Group3Pnts3->LineEdit2->setEnabled(false);
126 Group3Pnts3->LineEdit3->setEnabled(false);
128 Group3Pnts3->PushButton1->setIcon(image2);
129 Group3Pnts3->PushButton2->setIcon(image2);
130 Group3Pnts3->PushButton3->setIcon(image2);
132 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
133 layout->setMargin( 0 ); layout->setSpacing( 6 );
134 layout->addWidget( Group3Pnts );
135 layout->addWidget( Group3Pnts2 );
136 layout->addWidget( Group3Pnts3 );
138 setHelpFileName( "create_arc_page.html" );
144 //=================================================================================
145 // function : ~BasicGUI_ArcDlg()
146 // purpose : Destroys the object and frees any allocated resources
147 //=================================================================================
148 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
153 //=================================================================================
156 //=================================================================================
157 void BasicGUI_ArcDlg::Init()
160 myEditCurrentArgument = Group3Pnts->LineEdit1;
165 Group3Pnts2->CheckButton1->setChecked( false );
166 Group3Pnts->PushButton1->setDown(true);
168 /* signals and slots connections */
169 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
170 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
172 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
174 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
175 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
177 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
178 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
179 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
181 connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
182 connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
183 connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
185 connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
187 connect( Group3Pnts3->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
188 connect( Group3Pnts3->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
189 connect( Group3Pnts3->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
191 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
192 this, SLOT( SelectionIntoArgument() ) );
194 initName( tr( "GEOM_ARC" ) );
197 ConstructorsClicked( 0 );
201 //=================================================================================
202 // function : ClickOnOk()
204 //=================================================================================
205 void BasicGUI_ArcDlg::ClickOnOk()
207 if ( ClickOnApply() )
211 //=================================================================================
212 // function : ClickOnApply()
214 //=================================================================================
215 bool BasicGUI_ArcDlg::ClickOnApply()
221 ConstructorsClicked( getConstructorId() );
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection as changed or other case
230 //=================================================================================
231 void BasicGUI_ArcDlg::SelectionIntoArgument()
233 myEditCurrentArgument->setText( "" );
235 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
236 SALOME_ListIO aSelList;
237 aSelMgr->selectedObjects(aSelList);
239 if (aSelList.Extent() != 1) {
240 switch (getConstructorId()) {
242 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1.nullify();
243 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2.nullify();
244 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3.nullify();
247 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1.nullify();
248 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2.nullify();
249 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3.nullify();
252 if ( myEditCurrentArgument == Group3Pnts3->LineEdit1 ) myPoint1.nullify();
253 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 ) myPoint2.nullify();
254 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 ) myPoint3.nullify();
262 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
264 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
265 QString aName = GEOMBase::GetName( aSelectedObject.get() );
266 myEditCurrentArgument->setText(aName);
267 switch ( getConstructorId() ) {
269 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
270 myPoint1 = aSelectedObject;
271 if ( myPoint1 && !myPoint2 )
272 Group3Pnts->PushButton2->click();
274 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
275 myPoint2 = aSelectedObject;
276 if ( myPoint2 && !myPoint3 )
277 Group3Pnts->PushButton3->click();
279 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
280 myPoint3 = aSelectedObject;
281 if ( myPoint3 && !myPoint1 )
282 Group3Pnts->PushButton1->click();
286 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) {
287 myPoint1 = aSelectedObject;
288 if ( myPoint1 && !myPoint2 )
289 Group3Pnts2->PushButton2->click();
291 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) {
292 myPoint2 = aSelectedObject;
293 if ( myPoint2 && !myPoint3 )
294 Group3Pnts2->PushButton3->click();
296 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) {
297 myPoint3 = aSelectedObject;
298 if ( myPoint3 && !myPoint1 )
299 Group3Pnts2->PushButton1->click();
303 if ( myEditCurrentArgument == Group3Pnts3->LineEdit1 ) {
304 myPoint1 = aSelectedObject;
305 if ( myPoint1 && !myPoint2 )
306 Group3Pnts3->PushButton2->click();
308 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 ) {
309 myPoint2 = aSelectedObject;
310 if ( myPoint2 && !myPoint3 )
311 Group3Pnts3->PushButton3->click();
313 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 ) {
314 myPoint3 = aSelectedObject;
315 if ( myPoint3 && !myPoint1 )
316 Group3Pnts3->PushButton1->click();
322 displayPreview(true);
326 //=================================================================================
327 // function : SetEditCurrentArgument()
329 //=================================================================================
330 void BasicGUI_ArcDlg::SetEditCurrentArgument()
332 globalSelection(); // close local selection to clear it
333 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
335 QPushButton* send = (QPushButton*)sender();
336 switch ( getConstructorId() ) {
338 if ( send == Group3Pnts->PushButton1 ) {
339 myEditCurrentArgument = Group3Pnts->LineEdit1;
340 Group3Pnts->PushButton2->setDown(false);
341 Group3Pnts->PushButton3->setDown(false);
342 Group3Pnts->LineEdit1->setEnabled(true);
343 Group3Pnts->LineEdit2->setEnabled(false);
344 Group3Pnts->LineEdit3->setEnabled(false);
346 else if ( send == Group3Pnts->PushButton2 ) {
347 myEditCurrentArgument = Group3Pnts->LineEdit2;
348 Group3Pnts->PushButton1->setDown(false);
349 Group3Pnts->PushButton3->setDown(false);
350 Group3Pnts->LineEdit1->setEnabled(false);
351 Group3Pnts->LineEdit2->setEnabled(true);
352 Group3Pnts->LineEdit3->setEnabled(false);
354 else if ( send == Group3Pnts->PushButton3 ) {
355 myEditCurrentArgument = Group3Pnts->LineEdit3;
356 Group3Pnts->PushButton1->setDown(false);
357 Group3Pnts->PushButton2->setDown(false);
358 Group3Pnts->LineEdit1->setEnabled(false);
359 Group3Pnts->LineEdit2->setEnabled(false);
360 Group3Pnts->LineEdit3->setEnabled(true);
364 if ( send == Group3Pnts2->PushButton1 ) {
365 myEditCurrentArgument = Group3Pnts2->LineEdit1;
366 Group3Pnts2->PushButton2->setDown(false);
367 Group3Pnts2->PushButton3->setDown(false);
368 Group3Pnts2->LineEdit1->setEnabled(true);
369 Group3Pnts2->LineEdit2->setEnabled(false);
370 Group3Pnts2->LineEdit3->setEnabled(false);
372 else if ( send == Group3Pnts2->PushButton2 ) {
373 myEditCurrentArgument = Group3Pnts2->LineEdit2;
374 Group3Pnts2->PushButton1->setDown(false);
375 Group3Pnts2->PushButton3->setDown(false);
376 Group3Pnts2->LineEdit1->setEnabled(false);
377 Group3Pnts2->LineEdit2->setEnabled(true);
378 Group3Pnts2->LineEdit3->setEnabled(false);
380 else if ( send == Group3Pnts2->PushButton3 ) {
381 myEditCurrentArgument = Group3Pnts2->LineEdit3;
382 Group3Pnts2->PushButton1->setDown(false);
383 Group3Pnts2->PushButton2->setDown(false);
384 Group3Pnts2->LineEdit1->setEnabled(false);
385 Group3Pnts2->LineEdit2->setEnabled(false);
386 Group3Pnts2->LineEdit3->setEnabled(true);
390 if ( send == Group3Pnts3->PushButton1 ) {
391 myEditCurrentArgument = Group3Pnts3->LineEdit1;
392 Group3Pnts3->PushButton2->setDown(false);
393 Group3Pnts3->PushButton3->setDown(false);
394 Group3Pnts3->LineEdit1->setEnabled(true);
395 Group3Pnts3->LineEdit2->setEnabled(false);
396 Group3Pnts3->LineEdit3->setEnabled(false);
398 else if ( send == Group3Pnts3->PushButton2 ) {
399 myEditCurrentArgument = Group3Pnts3->LineEdit2;
400 Group3Pnts3->PushButton1->setDown(false);
401 Group3Pnts3->PushButton3->setDown(false);
402 Group3Pnts3->LineEdit1->setEnabled(false);
403 Group3Pnts3->LineEdit2->setEnabled(true);
404 Group3Pnts3->LineEdit3->setEnabled(false);
406 else if ( send == Group3Pnts3->PushButton3 ) {
407 myEditCurrentArgument = Group3Pnts3->LineEdit3;
408 Group3Pnts3->PushButton1->setDown(false);
409 Group3Pnts3->PushButton2->setDown(false);
410 Group3Pnts3->LineEdit1->setEnabled(false);
411 Group3Pnts3->LineEdit2->setEnabled(false);
412 Group3Pnts3->LineEdit3->setEnabled(true);
416 myEditCurrentArgument->setFocus();
417 // SelectionIntoArgument();
419 displayPreview(true);
423 //=================================================================================
424 // function : ActivateThisDialog()
426 //=================================================================================
427 void BasicGUI_ArcDlg::ActivateThisDialog()
429 GEOMBase_Skeleton::ActivateThisDialog();
431 connect( myGeomGUI->getApp()->selectionMgr(),
432 SIGNAL( currentSelectionChanged() ),
434 SLOT(SelectionIntoArgument() ) );
436 ConstructorsClicked( getConstructorId() );
439 //=================================================================================
440 // function : enterEvent()
442 //=================================================================================
443 void BasicGUI_ArcDlg::enterEvent( QEvent* )
445 if ( !mainFrame()->GroupConstructors->isEnabled() )
446 ActivateThisDialog();
449 //=================================================================================
450 // function : createOperation
452 //=================================================================================
453 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
455 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
458 //=================================================================================
459 // function : isValid
461 //=================================================================================
462 bool BasicGUI_ArcDlg::isValid( QString& msg )
464 bool ok = myPoint1 && myPoint2 && myPoint3 &&
465 myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
476 GEOM::GEOM_Object_var anObj;
478 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
480 switch ( getConstructorId() ) {
483 if ( myPoint1 && myPoint2 && myPoint3 ) {
484 anObj = anOper->MakeArc( myPoint1.get(), myPoint2.get(), myPoint3.get() );
491 bool Sense = Group3Pnts2->CheckButton1->isChecked();
492 if ( myPoint1 && myPoint2 && myPoint3 ) {
493 anObj = anOper->MakeArcCenter( myPoint1.get(), myPoint2.get(), myPoint3.get(), Sense );
500 if ( myPoint1 && myPoint2 && myPoint3 ) {
501 anObj = anOper->MakeArcOfEllipse( myPoint1.get(), myPoint2.get(), myPoint3.get() );
507 if ( !anObj->_is_nil() ) {
508 objects.push_back( anObj._retn() );
513 //=================================================================================
514 // function : ConstructorsClicked()
515 // purpose : Radio button management
516 //=================================================================================
517 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
519 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
525 switch ( constructorId ) {
531 Group3Pnts->PushButton1->setDown(true);
532 Group3Pnts->PushButton2->setDown(false);
533 Group3Pnts->PushButton3->setDown(false);
534 Group3Pnts->LineEdit1->setText( "" );
535 Group3Pnts->LineEdit2->setText( "" );
536 Group3Pnts->LineEdit3->setText( "" );
537 Group3Pnts->LineEdit1->setEnabled(true);
538 Group3Pnts->LineEdit2->setEnabled(false);
539 Group3Pnts->LineEdit3->setEnabled(false);
541 myEditCurrentArgument = Group3Pnts->LineEdit1;
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);
559 myEditCurrentArgument = Group3Pnts2->LineEdit1;
567 Group3Pnts3->PushButton1->setDown(true);
568 Group3Pnts3->PushButton2->setDown(false);
569 Group3Pnts3->PushButton3->setDown(false);
570 Group3Pnts3->LineEdit1->setText( "" );
571 Group3Pnts3->LineEdit2->setText( "" );
572 Group3Pnts3->LineEdit3->setText( "" );
573 Group3Pnts3->LineEdit1->setEnabled(true);
574 Group3Pnts3->LineEdit2->setEnabled(false);
575 Group3Pnts3->LineEdit3->setEnabled(false);
577 myEditCurrentArgument = Group3Pnts3->LineEdit1;
582 globalSelection(); // close local contexts, if any
583 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
585 qApp->processEvents();
587 resize( minimumSizeHint() );
589 myEditCurrentArgument->setFocus();
590 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
591 this, SLOT( SelectionIntoArgument() ) );
593 SelectionIntoArgument();
595 displayPreview(true);
598 //=================================================================================
599 // function : ReverseSense()
600 // purpose : Orientation of the arc
601 //=================================================================================
602 void BasicGUI_ArcDlg::ReverseSense()
604 displayPreview(true);
607 //=================================================================================
608 // function : addSubshapeToStudy
609 // purpose : virtual method to add new SubObjects if local selection
610 //=================================================================================
611 void BasicGUI_ArcDlg::addSubshapesToStudy()
613 switch ( getConstructorId() ) {
617 GEOMBase::PublishSubObject( myPoint1.get() );
618 GEOMBase::PublishSubObject( myPoint2.get() );
619 GEOMBase::PublishSubObject( myPoint3.get() );