2 // File : GeometryGUI_ArcDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_ArcDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Tools.h"
16 #include "utilities.h"
18 #include <qbuttongroup.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
31 //=================================================================================
32 // class : GeometryGUI_ArcDlg()
33 // purpose : Constructs a GeometryGUI_ArcDlg which is a child of 'parent', with the
34 // name 'name' and widget flags set to 'f'.
35 // The dialog will by default be modeless, unless you set 'modal' to
36 // TRUE to construct a modal dialog.
37 //=================================================================================
38 GeometryGUI_ArcDlg::GeometryGUI_ArcDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
39 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_ARC")));
42 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
45 setName( "GeometryGUI_ArcDlg" );
47 setCaption( tr( "GEOM_ARC_TITLE" ) );
48 setSizeGripEnabled( TRUE );
49 GeometryGUI_ArcDlgLayout = new QGridLayout( this );
50 GeometryGUI_ArcDlgLayout->setSpacing( 6 );
51 GeometryGUI_ArcDlgLayout->setMargin( 11 );
53 /***************************************************************/
54 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
55 GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
56 GroupConstructors->setExclusive( TRUE );
57 GroupConstructors->setColumnLayout(0, Qt::Vertical );
58 GroupConstructors->layout()->setSpacing( 0 );
59 GroupConstructors->layout()->setMargin( 0 );
60 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
61 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
62 GroupConstructorsLayout->setSpacing( 6 );
63 GroupConstructorsLayout->setMargin( 11 );
64 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
65 Constructor1->setText( tr( "" ) );
66 Constructor1->setPixmap( image0 );
67 Constructor1->setChecked( TRUE );
68 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
69 Constructor1->setMinimumSize( QSize( 50, 0 ) );
70 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
71 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72 GroupConstructorsLayout->addItem( spacer, 0, 1 );
73 GeometryGUI_ArcDlgLayout->addWidget( GroupConstructors, 0, 0 );
75 /***************************************************************/
76 GroupC1 = new QGroupBox( this, "GroupC1" );
77 GroupC1->setTitle( tr( "GEOM_POINTS" ) );
78 GroupC1->setFrameShape( QGroupBox::Box );
79 GroupC1->setFrameShadow( QGroupBox::Sunken );
80 GroupC1->setColumnLayout(0, Qt::Vertical );
81 GroupC1->layout()->setSpacing( 0 );
82 GroupC1->layout()->setMargin( 0 );
83 GroupC1Layout = new QGridLayout( GroupC1->layout() );
84 GroupC1Layout->setAlignment( Qt::AlignTop );
85 GroupC1Layout->setSpacing( 6 );
86 GroupC1Layout->setMargin( 11 );
87 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
88 TextLabelC1A1->setText( tr( "GEOM_POINT_I" ).arg( "1" ) );
89 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
90 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
91 TextLabelC1A1->setFrameShadow( QLabel::Plain );
92 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
93 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
94 SelectButtonC1A1->setText( tr( "" ) );
95 SelectButtonC1A1->setPixmap( image1 );
96 SelectButtonC1A1->setToggleButton( FALSE );
97 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
98 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
99 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
100 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
101 TextLabelC1A2->setText( tr( "GEOM_POINT_I" ).arg( "2" ) );
102 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
103 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
104 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
105 SelectButtonC1A2->setText( tr( "" ) );
106 SelectButtonC1A2->setPixmap( image1 );
107 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
108 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
109 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
110 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
111 TextLabelC1A3->setText( tr( "GEOM_POINT_I" ).arg( "3" ) );
112 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
113 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
114 SelectButtonC1A3 = new QPushButton( GroupC1, "SelectButtonC1A3" );
115 SelectButtonC1A3->setText( tr( "" ) );
116 SelectButtonC1A3->setPixmap( image1 );
117 GroupC1Layout->addWidget( SelectButtonC1A3, 2, 1 );
118 LineEditC1A3 = new QLineEdit( GroupC1, "LineEditC1A3" );
119 GroupC1Layout->addWidget( LineEditC1A3, 2, 2 );
120 GeometryGUI_ArcDlgLayout->addWidget( GroupC1, 1, 0 );
121 /***************************************************************/
123 GroupButtons = new QGroupBox( this, "GroupButtons" );
124 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
125 GroupButtons->setTitle( tr( "" ) );
126 GroupButtons->setColumnLayout(0, Qt::Vertical );
127 GroupButtons->layout()->setSpacing( 0 );
128 GroupButtons->layout()->setMargin( 0 );
129 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
130 GroupButtonsLayout->setAlignment( Qt::AlignTop );
131 GroupButtonsLayout->setSpacing( 6 );
132 GroupButtonsLayout->setMargin( 11 );
133 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
134 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
135 buttonCancel->setAutoDefault( TRUE );
136 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
137 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
138 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
139 buttonApply->setAutoDefault( TRUE );
140 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
141 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
142 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
143 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
144 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
145 buttonOk->setAutoDefault( TRUE );
146 buttonOk->setDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
148 GeometryGUI_ArcDlgLayout->addWidget( GroupButtons, 2, 0 );
149 /***************************************************************/
151 Init(Sel) ; /* Initialisations */
153 /* Move widget on the botton right corner of main widget */
154 QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
160 //=================================================================================
161 // function : ~GeometryGUI_ArcDlg()
162 // purpose : Destroys the object and frees any allocated resources
163 //=================================================================================
164 GeometryGUI_ArcDlg::~GeometryGUI_ArcDlg()
166 // no need to delete child widgets, Qt does it all for us
171 //=================================================================================
174 //=================================================================================
175 void GeometryGUI_ArcDlg::Init( SALOME_Selection* Sel )
179 myConstructorId = 0 ;
180 Constructor1->setChecked( TRUE );
181 myEditCurrentArgument = LineEditC1A1 ;
183 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
184 myOkPoint1 = myOkPoint2 = myOkPoint3 = false ;
185 mySimulationTopoDs.Nullify() ;
186 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
188 // TODO : previous selection into argument ?
190 /* Filter definitions */
191 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
192 myGeom = GEOM::GEOM_Gen::_narrow(comp);
193 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
194 mySelection->AddFilter(myVertexFilter) ;
196 /* signals and slots connections */
197 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
198 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
199 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
200 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
201 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
202 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
203 connect( SelectButtonC1A3, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
205 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
206 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
207 /* to close dialog if study change */
208 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose : Radio button management
215 //=================================================================================
216 void GeometryGUI_ArcDlg::ConstructorsClicked(int constructorId)
218 /* only a constructor now */
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void GeometryGUI_ArcDlg::ClickOnOk()
228 this->ClickOnApply() ;
229 this->ClickOnCancel() ;
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 void GeometryGUI_ArcDlg::ClickOnApply()
240 myGeomGUI->EraseSimulationShape() ;
241 mySimulationTopoDs.Nullify() ;
242 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
243 switch(myConstructorId)
247 if(myOkPoint1 && myOkPoint2 && myOkPoint3 ) {
248 myGeomGUI->MakeArcAndDisplay( myPoint1, myPoint2, myPoint3 ) ;
258 //=================================================================================
259 // function : ClickOnCancel()
261 //=================================================================================
262 void GeometryGUI_ArcDlg::ClickOnCancel()
264 mySelection->ClearFilters() ;
265 myGeomGUI->EraseSimulationShape() ;
266 mySimulationTopoDs.Nullify() ;
267 disconnect( mySelection, 0, this, 0 );
268 myGeomGUI->ResetState() ;
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose : Called when selection as changed or other case
277 //=================================================================================
278 void GeometryGUI_ArcDlg::SelectionIntoArgument()
280 myEditCurrentArgument->setText("") ;
281 myGeomGUI->EraseSimulationShape() ;
282 mySimulationTopoDs.Nullify() ;
284 QString aString = ""; /* name of future selection */
286 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
288 if ( myEditCurrentArgument == LineEditC1A1 ) {
289 myEditCurrentArgument->setText("") ;
292 else if ( myEditCurrentArgument == LineEditC1A2 ) {
293 myEditCurrentArgument->setText("") ;
296 else if ( myEditCurrentArgument == LineEditC1A3 ) {
297 myEditCurrentArgument->setText("") ;
305 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
308 if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint( S, this->myPoint1 ) ) {
309 myEditCurrentArgument->setText(aString) ;
312 else if ( myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint( S, this->myPoint2 ) ) {
313 myEditCurrentArgument->setText(aString) ;
316 else if ( myEditCurrentArgument == LineEditC1A3 && myGeomGUI->VertexToPoint( S, this->myPoint3 ) ) {
317 myEditCurrentArgument->setText(aString) ;
322 if( myOkPoint1 && myOkPoint2 && myOkPoint3 ) {
323 this->MakeArcSimulationAndDisplay() ;
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void GeometryGUI_ArcDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
337 switch (myConstructorId)
339 case 0: /* default constructor */
341 mySelection->AddFilter(myVertexFilter) ;
342 if(send == SelectButtonC1A1) {
343 LineEditC1A1->setFocus() ;
344 myEditCurrentArgument = LineEditC1A1;
346 else if(send == SelectButtonC1A2) {
347 LineEditC1A2->setFocus() ;
348 myEditCurrentArgument = LineEditC1A2;
350 else if(send == SelectButtonC1A3) {
351 LineEditC1A3->setFocus() ;
352 myEditCurrentArgument = LineEditC1A3;
354 SelectionIntoArgument() ;
361 //=================================================================================
362 // function : LineEditReturnPressed()
364 //=================================================================================
365 void GeometryGUI_ArcDlg::LineEditReturnPressed()
367 QLineEdit* send = (QLineEdit*)sender();
368 if( send == LineEditC1A1 )
369 myEditCurrentArgument = LineEditC1A1 ;
370 else if ( send == LineEditC1A2 )
371 myEditCurrentArgument = LineEditC1A2 ;
372 else if ( send == LineEditC1A3 )
373 myEditCurrentArgument = LineEditC1A3 ;
377 /* User name of object input management */
378 /* If successfull the selection is changed and signal emitted... */
379 /* so SelectionIntoArgument() is automatically called. */
380 const QString objectUserName = myEditCurrentArgument->text() ;
381 QWidget* thisWidget = (QWidget*)this ;
382 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
383 myEditCurrentArgument->setText( objectUserName ) ;
389 //=================================================================================
390 // function : DeactivateActiveDialog()
392 //=================================================================================
393 void GeometryGUI_ArcDlg::DeactivateActiveDialog()
395 if ( GroupConstructors->isEnabled() ) {
396 GroupConstructors->setEnabled(false) ;
397 GroupC1->setEnabled(false) ;
398 GroupButtons->setEnabled(false) ;
399 disconnect( mySelection, 0, this, 0 );
400 myGeomGUI->EraseSimulationShape() ;
401 mySelection->ClearFilters() ;
407 //=================================================================================
408 // function : ActivateThisDialog()
410 //=================================================================================
411 void GeometryGUI_ArcDlg::ActivateThisDialog()
413 /* Emit a signal to deactivate the active dialog */
414 myGeomGUI->EmitSignalDeactivateDialog() ;
415 GroupConstructors->setEnabled(true) ;
416 GroupC1->setEnabled(true) ;
417 GroupButtons->setEnabled(true) ;
418 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
419 if( !mySimulationTopoDs.IsNull() )
420 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
425 //=================================================================================
426 // function : enterEvent()
428 //=================================================================================
429 void GeometryGUI_ArcDlg::enterEvent(QEvent* e)
431 if ( GroupConstructors->isEnabled() )
433 ActivateThisDialog() ;
439 //=================================================================================
440 // function : closeEvent()
442 //=================================================================================
443 void GeometryGUI_ArcDlg::closeEvent( QCloseEvent* e )
445 /* same than click on cancel button */
446 this->ClickOnCancel() ;
451 //=================================================================================
452 // function : MakeArcSimulationAndDisplay()
454 //=================================================================================
455 void GeometryGUI_ArcDlg::MakeArcSimulationAndDisplay()
457 myGeomGUI->EraseSimulationShape() ;
458 mySimulationTopoDs.Nullify() ;
460 if ( myPoint2.IsEqual( myPoint1, Precision::Confusion() ) ) {
461 myEditCurrentArgument->setText("") ;
464 if ( myPoint2.IsEqual( myPoint3, Precision::Confusion() ) ) {
465 myEditCurrentArgument->setText("") ;
469 gp_Vec v1( this->myPoint2, this->myPoint1 ) ;
470 gp_Vec v2( this->myPoint2, this->myPoint3 ) ;
471 if( v1.IsParallel(v2, Precision::Angular() ) ) {
472 myEditCurrentArgument->setText("") ;
476 GC_MakeArcOfCircle Arc( this->myPoint1, this->myPoint2, this->myPoint3 );
477 if ( Arc.IsDone() ) {
478 Handle(Geom_TrimmedCurve) curve = Arc.Value() ;
479 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(curve).Shape() ;
480 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
483 catch(Standard_Failure) {
484 MESSAGE( "Exception catched in MakeArcSimulationAndDisplay" ) ;