1 // Copyright (C) 2007-2011 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 setIsApplyAndClose( true );
208 if ( ClickOnApply() )
212 //=================================================================================
213 // function : ClickOnApply()
215 //=================================================================================
216 bool BasicGUI_ArcDlg::ClickOnApply()
222 ConstructorsClicked( getConstructorId() );
228 //=================================================================================
229 // function : SelectionIntoArgument()
230 // purpose : Called when selection as changed or other case
231 //=================================================================================
232 void BasicGUI_ArcDlg::SelectionIntoArgument()
234 myEditCurrentArgument->setText( "" );
236 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
237 SALOME_ListIO aSelList;
238 aSelMgr->selectedObjects(aSelList);
240 if (aSelList.Extent() != 1) {
241 switch (getConstructorId()) {
243 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1.nullify();
244 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2.nullify();
245 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3.nullify();
248 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1.nullify();
249 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2.nullify();
250 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3.nullify();
253 if ( myEditCurrentArgument == Group3Pnts3->LineEdit1 ) myPoint1.nullify();
254 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 ) myPoint2.nullify();
255 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 ) myPoint3.nullify();
263 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
265 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
266 QString aName = GEOMBase::GetName( aSelectedObject.get() );
267 myEditCurrentArgument->setText(aName);
268 switch ( getConstructorId() ) {
270 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
271 myPoint1 = aSelectedObject;
272 if ( myPoint1 && !myPoint2 )
273 Group3Pnts->PushButton2->click();
275 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
276 myPoint2 = aSelectedObject;
277 if ( myPoint2 && !myPoint3 )
278 Group3Pnts->PushButton3->click();
280 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
281 myPoint3 = aSelectedObject;
282 if ( myPoint3 && !myPoint1 )
283 Group3Pnts->PushButton1->click();
287 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) {
288 myPoint1 = aSelectedObject;
289 if ( myPoint1 && !myPoint2 )
290 Group3Pnts2->PushButton2->click();
292 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) {
293 myPoint2 = aSelectedObject;
294 if ( myPoint2 && !myPoint3 )
295 Group3Pnts2->PushButton3->click();
297 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) {
298 myPoint3 = aSelectedObject;
299 if ( myPoint3 && !myPoint1 )
300 Group3Pnts2->PushButton1->click();
304 if ( myEditCurrentArgument == Group3Pnts3->LineEdit1 ) {
305 myPoint1 = aSelectedObject;
306 if ( myPoint1 && !myPoint2 )
307 Group3Pnts3->PushButton2->click();
309 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 ) {
310 myPoint2 = aSelectedObject;
311 if ( myPoint2 && !myPoint3 )
312 Group3Pnts3->PushButton3->click();
314 else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 ) {
315 myPoint3 = aSelectedObject;
316 if ( myPoint3 && !myPoint1 )
317 Group3Pnts3->PushButton1->click();
323 displayPreview(true);
327 //=================================================================================
328 // function : SetEditCurrentArgument()
330 //=================================================================================
331 void BasicGUI_ArcDlg::SetEditCurrentArgument()
333 globalSelection(); // close local selection to clear it
334 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
336 QPushButton* send = (QPushButton*)sender();
337 switch ( getConstructorId() ) {
339 if ( send == Group3Pnts->PushButton1 ) {
340 myEditCurrentArgument = Group3Pnts->LineEdit1;
341 Group3Pnts->PushButton2->setDown(false);
342 Group3Pnts->PushButton3->setDown(false);
343 Group3Pnts->LineEdit1->setEnabled(true);
344 Group3Pnts->LineEdit2->setEnabled(false);
345 Group3Pnts->LineEdit3->setEnabled(false);
347 else if ( send == Group3Pnts->PushButton2 ) {
348 myEditCurrentArgument = Group3Pnts->LineEdit2;
349 Group3Pnts->PushButton1->setDown(false);
350 Group3Pnts->PushButton3->setDown(false);
351 Group3Pnts->LineEdit1->setEnabled(false);
352 Group3Pnts->LineEdit2->setEnabled(true);
353 Group3Pnts->LineEdit3->setEnabled(false);
355 else if ( send == Group3Pnts->PushButton3 ) {
356 myEditCurrentArgument = Group3Pnts->LineEdit3;
357 Group3Pnts->PushButton1->setDown(false);
358 Group3Pnts->PushButton2->setDown(false);
359 Group3Pnts->LineEdit1->setEnabled(false);
360 Group3Pnts->LineEdit2->setEnabled(false);
361 Group3Pnts->LineEdit3->setEnabled(true);
365 if ( send == Group3Pnts2->PushButton1 ) {
366 myEditCurrentArgument = Group3Pnts2->LineEdit1;
367 Group3Pnts2->PushButton2->setDown(false);
368 Group3Pnts2->PushButton3->setDown(false);
369 Group3Pnts2->LineEdit1->setEnabled(true);
370 Group3Pnts2->LineEdit2->setEnabled(false);
371 Group3Pnts2->LineEdit3->setEnabled(false);
373 else if ( send == Group3Pnts2->PushButton2 ) {
374 myEditCurrentArgument = Group3Pnts2->LineEdit2;
375 Group3Pnts2->PushButton1->setDown(false);
376 Group3Pnts2->PushButton3->setDown(false);
377 Group3Pnts2->LineEdit1->setEnabled(false);
378 Group3Pnts2->LineEdit2->setEnabled(true);
379 Group3Pnts2->LineEdit3->setEnabled(false);
381 else if ( send == Group3Pnts2->PushButton3 ) {
382 myEditCurrentArgument = Group3Pnts2->LineEdit3;
383 Group3Pnts2->PushButton1->setDown(false);
384 Group3Pnts2->PushButton2->setDown(false);
385 Group3Pnts2->LineEdit1->setEnabled(false);
386 Group3Pnts2->LineEdit2->setEnabled(false);
387 Group3Pnts2->LineEdit3->setEnabled(true);
391 if ( send == Group3Pnts3->PushButton1 ) {
392 myEditCurrentArgument = Group3Pnts3->LineEdit1;
393 Group3Pnts3->PushButton2->setDown(false);
394 Group3Pnts3->PushButton3->setDown(false);
395 Group3Pnts3->LineEdit1->setEnabled(true);
396 Group3Pnts3->LineEdit2->setEnabled(false);
397 Group3Pnts3->LineEdit3->setEnabled(false);
399 else if ( send == Group3Pnts3->PushButton2 ) {
400 myEditCurrentArgument = Group3Pnts3->LineEdit2;
401 Group3Pnts3->PushButton1->setDown(false);
402 Group3Pnts3->PushButton3->setDown(false);
403 Group3Pnts3->LineEdit1->setEnabled(false);
404 Group3Pnts3->LineEdit2->setEnabled(true);
405 Group3Pnts3->LineEdit3->setEnabled(false);
407 else if ( send == Group3Pnts3->PushButton3 ) {
408 myEditCurrentArgument = Group3Pnts3->LineEdit3;
409 Group3Pnts3->PushButton1->setDown(false);
410 Group3Pnts3->PushButton2->setDown(false);
411 Group3Pnts3->LineEdit1->setEnabled(false);
412 Group3Pnts3->LineEdit2->setEnabled(false);
413 Group3Pnts3->LineEdit3->setEnabled(true);
417 myEditCurrentArgument->setFocus();
418 // SelectionIntoArgument();
420 displayPreview(true);
424 //=================================================================================
425 // function : ActivateThisDialog()
427 //=================================================================================
428 void BasicGUI_ArcDlg::ActivateThisDialog()
430 GEOMBase_Skeleton::ActivateThisDialog();
432 connect( myGeomGUI->getApp()->selectionMgr(),
433 SIGNAL( currentSelectionChanged() ),
435 SLOT(SelectionIntoArgument() ) );
437 ConstructorsClicked( getConstructorId() );
440 //=================================================================================
441 // function : enterEvent()
443 //=================================================================================
444 void BasicGUI_ArcDlg::enterEvent( QEvent* )
446 if ( !mainFrame()->GroupConstructors->isEnabled() )
447 ActivateThisDialog();
450 //=================================================================================
451 // function : createOperation
453 //=================================================================================
454 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
456 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
459 //=================================================================================
460 // function : isValid
462 //=================================================================================
463 bool BasicGUI_ArcDlg::isValid( QString& msg )
465 bool ok = myPoint1 && myPoint2 && myPoint3 &&
466 myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
470 //=================================================================================
471 // function : execute
473 //=================================================================================
474 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
477 GEOM::GEOM_Object_var anObj;
479 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
481 switch ( getConstructorId() ) {
484 if ( myPoint1 && myPoint2 && myPoint3 ) {
485 anObj = anOper->MakeArc( myPoint1.get(), myPoint2.get(), myPoint3.get() );
492 bool Sense = Group3Pnts2->CheckButton1->isChecked();
493 if ( myPoint1 && myPoint2 && myPoint3 ) {
494 anObj = anOper->MakeArcCenter( myPoint1.get(), myPoint2.get(), myPoint3.get(), Sense );
501 if ( myPoint1 && myPoint2 && myPoint3 ) {
502 anObj = anOper->MakeArcOfEllipse( myPoint1.get(), myPoint2.get(), myPoint3.get() );
508 if ( !anObj->_is_nil() ) {
509 objects.push_back( anObj._retn() );
514 //=================================================================================
515 // function : ConstructorsClicked()
516 // purpose : Radio button management
517 //=================================================================================
518 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
520 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
526 switch ( constructorId ) {
532 Group3Pnts->PushButton1->setDown(true);
533 Group3Pnts->PushButton2->setDown(false);
534 Group3Pnts->PushButton3->setDown(false);
535 Group3Pnts->LineEdit1->setText( "" );
536 Group3Pnts->LineEdit2->setText( "" );
537 Group3Pnts->LineEdit3->setText( "" );
538 Group3Pnts->LineEdit1->setEnabled(true);
539 Group3Pnts->LineEdit2->setEnabled(false);
540 Group3Pnts->LineEdit3->setEnabled(false);
542 myEditCurrentArgument = Group3Pnts->LineEdit1;
550 Group3Pnts2->PushButton1->setDown(true);
551 Group3Pnts2->PushButton2->setDown(false);
552 Group3Pnts2->PushButton3->setDown(false);
553 Group3Pnts2->LineEdit1->setText( "" );
554 Group3Pnts2->LineEdit2->setText( "" );
555 Group3Pnts2->LineEdit3->setText( "" );
556 Group3Pnts2->LineEdit1->setEnabled(true);
557 Group3Pnts2->LineEdit2->setEnabled(false);
558 Group3Pnts2->LineEdit3->setEnabled(false);
560 myEditCurrentArgument = Group3Pnts2->LineEdit1;
568 Group3Pnts3->PushButton1->setDown(true);
569 Group3Pnts3->PushButton2->setDown(false);
570 Group3Pnts3->PushButton3->setDown(false);
571 Group3Pnts3->LineEdit1->setText( "" );
572 Group3Pnts3->LineEdit2->setText( "" );
573 Group3Pnts3->LineEdit3->setText( "" );
574 Group3Pnts3->LineEdit1->setEnabled(true);
575 Group3Pnts3->LineEdit2->setEnabled(false);
576 Group3Pnts3->LineEdit3->setEnabled(false);
578 myEditCurrentArgument = Group3Pnts3->LineEdit1;
583 globalSelection(); // close local contexts, if any
584 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
586 qApp->processEvents();
588 resize( minimumSizeHint() );
590 myEditCurrentArgument->setFocus();
591 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
592 this, SLOT( SelectionIntoArgument() ) );
594 SelectionIntoArgument();
596 displayPreview(true);
599 //=================================================================================
600 // function : ReverseSense()
601 // purpose : Orientation of the arc
602 //=================================================================================
603 void BasicGUI_ArcDlg::ReverseSense()
605 displayPreview(true);
608 //=================================================================================
609 // function : addSubshapeToStudy
610 // purpose : virtual method to add new SubObjects if local selection
611 //=================================================================================
612 void BasicGUI_ArcDlg::addSubshapesToStudy()
614 switch ( getConstructorId() ) {
618 GEOMBase::PublishSubObject( myPoint1.get() );
619 GEOMBase::PublishSubObject( myPoint2.get() );
620 GEOMBase::PublishSubObject( myPoint3.get() );