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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_ArcDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_ArcDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Tools.h"
36 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
51 //=================================================================================
52 // class : GeometryGUI_ArcDlg()
53 // purpose : Constructs a GeometryGUI_ArcDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 GeometryGUI_ArcDlg::GeometryGUI_ArcDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
59 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
61 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_ARC")));
62 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
65 setName( "GeometryGUI_ArcDlg" );
67 setCaption( tr( "GEOM_ARC_TITLE" ) );
68 setSizeGripEnabled( TRUE );
69 GeometryGUI_ArcDlgLayout = new QGridLayout( this );
70 GeometryGUI_ArcDlgLayout->setSpacing( 6 );
71 GeometryGUI_ArcDlgLayout->setMargin( 11 );
73 /***************************************************************/
74 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
75 GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
76 GroupConstructors->setExclusive( TRUE );
77 GroupConstructors->setColumnLayout(0, Qt::Vertical );
78 GroupConstructors->layout()->setSpacing( 0 );
79 GroupConstructors->layout()->setMargin( 0 );
80 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
81 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
82 GroupConstructorsLayout->setSpacing( 6 );
83 GroupConstructorsLayout->setMargin( 11 );
84 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
85 Constructor1->setText( tr( "" ) );
86 Constructor1->setPixmap( image0 );
87 Constructor1->setChecked( TRUE );
88 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
89 Constructor1->setMinimumSize( QSize( 50, 0 ) );
90 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
91 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
92 GroupConstructorsLayout->addItem( spacer, 0, 1 );
93 GeometryGUI_ArcDlgLayout->addWidget( GroupConstructors, 0, 0 );
95 /***************************************************************/
96 GroupC1 = new QGroupBox( this, "GroupC1" );
97 GroupC1->setTitle( tr( "GEOM_POINTS" ) );
98 GroupC1->setFrameShape( QGroupBox::Box );
99 GroupC1->setFrameShadow( QGroupBox::Sunken );
100 GroupC1->setColumnLayout(0, Qt::Vertical );
101 GroupC1->layout()->setSpacing( 0 );
102 GroupC1->layout()->setMargin( 0 );
103 GroupC1Layout = new QGridLayout( GroupC1->layout() );
104 GroupC1Layout->setAlignment( Qt::AlignTop );
105 GroupC1Layout->setSpacing( 6 );
106 GroupC1Layout->setMargin( 11 );
107 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
108 TextLabelC1A1->setText( tr( "GEOM_POINT_I" ).arg( "1" ) );
109 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
110 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
111 TextLabelC1A1->setFrameShadow( QLabel::Plain );
112 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
113 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
114 SelectButtonC1A1->setText( tr( "" ) );
115 SelectButtonC1A1->setPixmap( image1 );
116 SelectButtonC1A1->setToggleButton( FALSE );
117 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
118 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
119 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
120 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
121 TextLabelC1A2->setText( tr( "GEOM_POINT_I" ).arg( "2" ) );
122 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
123 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
124 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
125 SelectButtonC1A2->setText( tr( "" ) );
126 SelectButtonC1A2->setPixmap( image1 );
127 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
128 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
129 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
130 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
131 TextLabelC1A3->setText( tr( "GEOM_POINT_I" ).arg( "3" ) );
132 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
133 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
134 SelectButtonC1A3 = new QPushButton( GroupC1, "SelectButtonC1A3" );
135 SelectButtonC1A3->setText( tr( "" ) );
136 SelectButtonC1A3->setPixmap( image1 );
137 GroupC1Layout->addWidget( SelectButtonC1A3, 2, 1 );
138 LineEditC1A3 = new QLineEdit( GroupC1, "LineEditC1A3" );
139 GroupC1Layout->addWidget( LineEditC1A3, 2, 2 );
140 GeometryGUI_ArcDlgLayout->addWidget( GroupC1, 1, 0 );
141 /***************************************************************/
143 GroupButtons = new QGroupBox( this, "GroupButtons" );
144 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
145 GroupButtons->setTitle( tr( "" ) );
146 GroupButtons->setColumnLayout(0, Qt::Vertical );
147 GroupButtons->layout()->setSpacing( 0 );
148 GroupButtons->layout()->setMargin( 0 );
149 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
150 GroupButtonsLayout->setAlignment( Qt::AlignTop );
151 GroupButtonsLayout->setSpacing( 6 );
152 GroupButtonsLayout->setMargin( 11 );
153 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
154 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
155 buttonCancel->setAutoDefault( TRUE );
156 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
157 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
158 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
159 buttonApply->setAutoDefault( TRUE );
160 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
161 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
162 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
163 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
164 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
165 buttonOk->setAutoDefault( TRUE );
166 buttonOk->setDefault( TRUE );
167 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
168 GeometryGUI_ArcDlgLayout->addWidget( GroupButtons, 2, 0 );
169 /***************************************************************/
171 Init(Sel) ; /* Initialisations */
173 /* Move widget on the botton right corner of main widget */
174 QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
180 //=================================================================================
181 // function : ~GeometryGUI_ArcDlg()
182 // purpose : Destroys the object and frees any allocated resources
183 //=================================================================================
184 GeometryGUI_ArcDlg::~GeometryGUI_ArcDlg()
186 // no need to delete child widgets, Qt does it all for us
191 //=================================================================================
194 //=================================================================================
195 void GeometryGUI_ArcDlg::Init( SALOME_Selection* Sel )
199 myConstructorId = 0 ;
200 Constructor1->setChecked( TRUE );
201 myEditCurrentArgument = LineEditC1A1 ;
203 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
204 myOkPoint1 = myOkPoint2 = myOkPoint3 = false ;
205 mySimulationTopoDs.Nullify() ;
206 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
208 // TODO : previous selection into argument ?
210 /* Filter definitions */
211 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
212 myGeom = GEOM::GEOM_Gen::_narrow(comp);
213 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
214 mySelection->AddFilter(myVertexFilter) ;
216 /* signals and slots connections */
217 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
218 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
219 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
220 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
221 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
222 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
223 connect( SelectButtonC1A3, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
225 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
226 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
227 /* to close dialog if study change */
228 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void GeometryGUI_ArcDlg::ConstructorsClicked(int constructorId)
238 /* only a constructor now */
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void GeometryGUI_ArcDlg::ClickOnOk()
248 this->ClickOnApply() ;
249 this->ClickOnCancel() ;
254 //=================================================================================
255 // function : ClickOnApply()
257 //=================================================================================
258 void GeometryGUI_ArcDlg::ClickOnApply()
260 myGeomGUI->EraseSimulationShape() ;
261 mySimulationTopoDs.Nullify() ;
262 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
263 switch(myConstructorId)
267 if(myOkPoint1 && myOkPoint2 && myOkPoint3 ) {
268 myGeomGUI->MakeArcAndDisplay( myPoint1, myPoint2, myPoint3 ) ;
278 //=================================================================================
279 // function : ClickOnCancel()
281 //=================================================================================
282 void GeometryGUI_ArcDlg::ClickOnCancel()
284 mySelection->ClearFilters() ;
285 myGeomGUI->EraseSimulationShape() ;
286 mySimulationTopoDs.Nullify() ;
287 disconnect( mySelection, 0, this, 0 );
288 myGeomGUI->ResetState() ;
294 //=================================================================================
295 // function : SelectionIntoArgument()
296 // purpose : Called when selection as changed or other case
297 //=================================================================================
298 void GeometryGUI_ArcDlg::SelectionIntoArgument()
300 myEditCurrentArgument->setText("") ;
301 myGeomGUI->EraseSimulationShape() ;
302 mySimulationTopoDs.Nullify() ;
304 QString aString = ""; /* name of future selection */
306 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
308 if ( myEditCurrentArgument == LineEditC1A1 ) {
309 myEditCurrentArgument->setText("") ;
312 else if ( myEditCurrentArgument == LineEditC1A2 ) {
313 myEditCurrentArgument->setText("") ;
316 else if ( myEditCurrentArgument == LineEditC1A3 ) {
317 myEditCurrentArgument->setText("") ;
325 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
328 if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint( S, this->myPoint1 ) ) {
329 myEditCurrentArgument->setText(aString) ;
332 else if ( myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint( S, this->myPoint2 ) ) {
333 myEditCurrentArgument->setText(aString) ;
336 else if ( myEditCurrentArgument == LineEditC1A3 && myGeomGUI->VertexToPoint( S, this->myPoint3 ) ) {
337 myEditCurrentArgument->setText(aString) ;
342 if( myOkPoint1 && myOkPoint2 && myOkPoint3 ) {
343 this->MakeArcSimulationAndDisplay() ;
350 //=================================================================================
351 // function : SetEditCurrentArgument()
353 //=================================================================================
354 void GeometryGUI_ArcDlg::SetEditCurrentArgument()
356 QPushButton* send = (QPushButton*)sender();
357 switch (myConstructorId)
359 case 0: /* default constructor */
361 mySelection->AddFilter(myVertexFilter) ;
362 if(send == SelectButtonC1A1) {
363 LineEditC1A1->setFocus() ;
364 myEditCurrentArgument = LineEditC1A1;
366 else if(send == SelectButtonC1A2) {
367 LineEditC1A2->setFocus() ;
368 myEditCurrentArgument = LineEditC1A2;
370 else if(send == SelectButtonC1A3) {
371 LineEditC1A3->setFocus() ;
372 myEditCurrentArgument = LineEditC1A3;
374 SelectionIntoArgument() ;
381 //=================================================================================
382 // function : LineEditReturnPressed()
384 //=================================================================================
385 void GeometryGUI_ArcDlg::LineEditReturnPressed()
387 QLineEdit* send = (QLineEdit*)sender();
388 if( send == LineEditC1A1 )
389 myEditCurrentArgument = LineEditC1A1 ;
390 else if ( send == LineEditC1A2 )
391 myEditCurrentArgument = LineEditC1A2 ;
392 else if ( send == LineEditC1A3 )
393 myEditCurrentArgument = LineEditC1A3 ;
397 /* User name of object input management */
398 /* If successfull the selection is changed and signal emitted... */
399 /* so SelectionIntoArgument() is automatically called. */
400 const QString objectUserName = myEditCurrentArgument->text() ;
401 QWidget* thisWidget = (QWidget*)this ;
402 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
403 myEditCurrentArgument->setText( objectUserName ) ;
409 //=================================================================================
410 // function : DeactivateActiveDialog()
412 //=================================================================================
413 void GeometryGUI_ArcDlg::DeactivateActiveDialog()
415 if ( GroupConstructors->isEnabled() ) {
416 GroupConstructors->setEnabled(false) ;
417 GroupC1->setEnabled(false) ;
418 GroupButtons->setEnabled(false) ;
419 disconnect( mySelection, 0, this, 0 );
420 myGeomGUI->EraseSimulationShape() ;
421 mySelection->ClearFilters() ;
427 //=================================================================================
428 // function : ActivateThisDialog()
430 //=================================================================================
431 void GeometryGUI_ArcDlg::ActivateThisDialog()
433 /* Emit a signal to deactivate the active dialog */
434 myGeomGUI->EmitSignalDeactivateDialog() ;
435 GroupConstructors->setEnabled(true) ;
436 GroupC1->setEnabled(true) ;
437 GroupButtons->setEnabled(true) ;
438 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
439 if( !mySimulationTopoDs.IsNull() )
440 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
445 //=================================================================================
446 // function : enterEvent()
448 //=================================================================================
449 void GeometryGUI_ArcDlg::enterEvent(QEvent* e)
451 if ( GroupConstructors->isEnabled() )
453 ActivateThisDialog() ;
459 //=================================================================================
460 // function : closeEvent()
462 //=================================================================================
463 void GeometryGUI_ArcDlg::closeEvent( QCloseEvent* e )
465 /* same than click on cancel button */
466 this->ClickOnCancel() ;
471 //=================================================================================
472 // function : MakeArcSimulationAndDisplay()
474 //=================================================================================
475 void GeometryGUI_ArcDlg::MakeArcSimulationAndDisplay()
477 myGeomGUI->EraseSimulationShape() ;
478 mySimulationTopoDs.Nullify() ;
480 if ( myPoint2.IsEqual( myPoint1, Precision::Confusion() ) ) {
481 myEditCurrentArgument->setText("") ;
484 if ( myPoint2.IsEqual( myPoint3, Precision::Confusion() ) ) {
485 myEditCurrentArgument->setText("") ;
489 gp_Vec v1( this->myPoint2, this->myPoint1 ) ;
490 gp_Vec v2( this->myPoint2, this->myPoint3 ) ;
491 if( v1.IsParallel(v2, Precision::Angular() ) ) {
492 myEditCurrentArgument->setText("") ;
496 GC_MakeArcOfCircle Arc( this->myPoint1, this->myPoint2, this->myPoint3 );
497 if ( Arc.IsDone() ) {
498 Handle(Geom_TrimmedCurve) curve = Arc.Value() ;
499 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(curve).Shape() ;
500 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
503 catch(Standard_Failure) {
504 MESSAGE( "Exception catched in MakeArcSimulationAndDisplay" ) ;