2 // File : GeometryGUI_CircleDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_CircleDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Config.h"
16 #include "utilities.h"
18 #include <BRepAdaptor_Curve.hxx>
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qwhatsthis.h>
31 #include <qvalidator.h>
34 //=================================================================================
35 // class : GeometryGUI_CircleDlg()
36 // purpose : Constructs a GeometryGUI_CircleDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 GeometryGUI_CircleDlg::GeometryGUI_CircleDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_CIRCLE_PV")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
48 setName( "GeometryGUI_CircleDlg" );
50 setCaption( tr( "GEOM_CIRCLE_TITLE" ) );
51 setSizeGripEnabled( TRUE );
52 GeometryGUI_CircleDlgLayout = new QGridLayout( this );
53 GeometryGUI_CircleDlgLayout->setSpacing( 6 );
54 GeometryGUI_CircleDlgLayout->setMargin( 11 );
56 /***************************************************************/
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
59 GroupConstructors->setExclusive( TRUE );
60 GroupConstructors->setColumnLayout(0, Qt::Vertical );
61 GroupConstructors->layout()->setSpacing( 0 );
62 GroupConstructors->layout()->setMargin( 0 );
63 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
64 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
65 GroupConstructorsLayout->setSpacing( 6 );
66 GroupConstructorsLayout->setMargin( 11 );
67 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
68 Constructor1->setText( tr( "" ) );
69 Constructor1->setPixmap( image0 );
70 Constructor1->setChecked( TRUE );
71 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
72 Constructor1->setMinimumSize( QSize( 50, 0 ) );
73 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
74 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
75 GroupConstructorsLayout->addItem( spacer, 0, 1 );
76 GeometryGUI_CircleDlgLayout->addWidget( GroupConstructors, 0, 0 );
78 /***************************************************************/
79 GroupC1 = new QGroupBox( this, "GroupC1" );
80 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
81 GroupC1->setFrameShape( QGroupBox::Box );
82 GroupC1->setFrameShadow( QGroupBox::Sunken );
83 GroupC1->setColumnLayout(0, Qt::Vertical );
84 GroupC1->layout()->setSpacing( 0 );
85 GroupC1->layout()->setMargin( 0 );
86 GroupC1Layout = new QGridLayout( GroupC1->layout() );
87 GroupC1Layout->setAlignment( Qt::AlignTop );
88 GroupC1Layout->setSpacing( 6 );
89 GroupC1Layout->setMargin( 11 );
91 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
92 TextLabelC1A1->setText( tr( "GEOM_CENTER_POINT" ) );
93 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
94 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
95 TextLabelC1A1->setFrameShadow( QLabel::Plain );
96 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
97 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
98 SelectButtonC1A1->setText( tr( "" ) );
99 SelectButtonC1A1->setPixmap( image1 );
100 SelectButtonC1A1->setToggleButton( FALSE );
101 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
102 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
103 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
104 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
105 TextLabelC1A2->setText( tr( "GEOM_VECTOR" ) );
106 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
107 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
108 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
109 SelectButtonC1A2->setText( tr( "" ) );
110 SelectButtonC1A2->setPixmap( image1 );
111 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
112 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
113 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
114 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
115 TextLabelC1A3->setText( tr( "GEOM_RADIUS" ) );
116 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
117 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
118 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
119 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 2 );
120 GeometryGUI_CircleDlgLayout->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 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
134 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
135 buttonOk->setAutoDefault( TRUE );
136 buttonOk->setDefault( TRUE );
137 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
138 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
139 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
140 buttonApply->setAutoDefault( TRUE );
141 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
142 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
143 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
144 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
145 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
146 buttonCancel->setAutoDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
148 GeometryGUI_CircleDlgLayout->addWidget( GroupButtons, 2, 0 );
149 /***************************************************************/
151 Init(Sel) ; /* Initialisations */
155 //=================================================================================
156 // function : ~GeometryGUI_CircleDlg()
157 // purpose : Destroys the object and frees any allocated resources
158 //=================================================================================
159 GeometryGUI_CircleDlg::~GeometryGUI_CircleDlg()
161 // no need to delete child widgets, Qt does it all for us
165 //=================================================================================
168 //=================================================================================
169 void GeometryGUI_CircleDlg::Init( SALOME_Selection* Sel )
172 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
173 step = St.toDouble() ;
175 /* min, max, step and decimals for spin boxes */
176 SpinBox_C1A3->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
177 SpinBox_C1A3->SetValue( 100.0 ) ; /* = myRadius */
180 myConstructorId = 0 ;
181 Constructor1->setChecked( TRUE );
182 myEditCurrentArgument = LineEditC1A1 ;
184 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
186 myOkPoint1 = myOkDir = false ;
187 mySimulationTopoDs.Nullify() ;
188 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
190 // TODO : previous selection into argument ?
192 /* Filter definitions */
193 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
194 myGeom = GEOM::GEOM_Gen::_narrow(comp);
195 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
196 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
198 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
200 /* signals and slots connections */
201 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
202 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
203 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
204 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
205 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
206 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
208 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
209 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
211 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
212 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
213 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
214 /* to close dialog if study change */
215 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
217 /* Move widget on the botton right corner of main widget */
219 myGeomGUI->DefineDlgPosition( this, x, y ) ;
221 this->show() ; /* displays Dialog */
227 //=================================================================================
228 // function : ConstructorsClicked()
229 // purpose : Radio button management
230 //=================================================================================
231 void GeometryGUI_CircleDlg::ConstructorsClicked(int constructorId)
233 /* only a constructor now */
237 //=================================================================================
238 // function : ClickOnOk()
240 //=================================================================================
241 void GeometryGUI_CircleDlg::ClickOnOk()
243 this->ClickOnApply() ;
244 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 void GeometryGUI_CircleDlg::ClickOnApply()
255 myGeomGUI->EraseSimulationShape() ;
256 mySimulationTopoDs.Nullify() ;
257 switch(myConstructorId)
261 if(myOkPoint1 && myOkDir) {
262 myGeomGUI->MakeCircleAndDisplay( myPoint1, myDir, myRadius) ;
271 //=================================================================================
272 // function : ClickOnCancel()
274 //=================================================================================
275 void GeometryGUI_CircleDlg::ClickOnCancel()
277 mySelection->ClearFilters() ;
278 myGeomGUI->EraseSimulationShape() ;
279 mySimulationTopoDs.Nullify() ;
280 disconnect( mySelection, 0, this, 0 );
281 myGeomGUI->ResetState() ;
286 //=================================================================================
287 // function : SelectionIntoArgument()
288 // purpose : Called when selection as changed or other case
289 //=================================================================================
290 void GeometryGUI_CircleDlg::SelectionIntoArgument()
293 myGeomGUI->EraseSimulationShape() ;
294 mySimulationTopoDs.Nullify() ;
296 /* Future name of selection */
297 QString aString = "";
299 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
301 if ( myEditCurrentArgument == LineEditC1A1 ) {
302 LineEditC1A1->setText("") ;
305 else if ( myEditCurrentArgument == LineEditC1A2 ) {
306 LineEditC1A2->setText("") ;
314 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
317 /* gp_Pnt : not used */
318 if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
319 LineEditC1A1->setText(aString) ;
322 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, notUsed, myDir) */) {
323 BRepAdaptor_Curve curv(TopoDS::Edge(S));
324 myDir = curv.Line().Direction();
325 LineEditC1A2->setText(aString) ;
329 if( myOkPoint1 && myOkDir ) {
330 MakeCircleSimulationAndDisplay() ;
335 //=================================================================================
336 // function : SetEditCurrentArgument()
338 //=================================================================================
339 void GeometryGUI_CircleDlg::SetEditCurrentArgument()
341 mySelection->ClearFilters() ;
342 QPushButton* send = (QPushButton*)sender();
343 switch (myConstructorId)
345 case 0: /* default constructor */
347 if(send == SelectButtonC1A1) {
348 LineEditC1A1->setFocus() ;
349 myEditCurrentArgument = LineEditC1A1;
350 mySelection->AddFilter(myVertexFilter) ;
352 else if(send == SelectButtonC1A2) {
353 LineEditC1A2->setFocus() ;
354 myEditCurrentArgument = LineEditC1A2;
355 mySelection->AddFilter(myEdgeFilter) ;
357 SelectionIntoArgument() ;
364 //=================================================================================
365 // function : LineEditReturnPressed()
367 //=================================================================================
368 void GeometryGUI_CircleDlg::LineEditReturnPressed()
370 QLineEdit* send = (QLineEdit*)sender();
371 if( send == LineEditC1A1 )
372 myEditCurrentArgument = LineEditC1A1 ;
373 else if ( send == LineEditC1A2 )
374 myEditCurrentArgument = LineEditC1A2 ;
378 /* User name of object input management */
379 /* If successfull the selection is changed and signal emitted... */
380 /* so SelectionIntoArgument() is automatically called. */
381 const QString objectUserName = myEditCurrentArgument->text() ;
382 QWidget* thisWidget = (QWidget*)this ;
383 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
384 myEditCurrentArgument->setText( objectUserName ) ;
390 //=================================================================================
391 // function : ValueChangedInSpinBox()
393 //=================================================================================
394 void GeometryGUI_CircleDlg::ValueChangedInSpinBox( double newValue )
396 myRadius = newValue ;
398 if (myOkPoint1 && myOkDir) {
399 MakeCircleSimulationAndDisplay() ;
402 myGeomGUI->EraseSimulationShape() ;
403 mySimulationTopoDs.Nullify() ;
408 //=================================================================================
409 // function : DeactivateActiveDialog()
411 //=================================================================================
412 void GeometryGUI_CircleDlg::DeactivateActiveDialog()
414 if ( GroupConstructors->isEnabled() ) {
415 GroupConstructors->setEnabled(false) ;
416 GroupC1->setEnabled(false) ;
417 GroupButtons->setEnabled(false) ;
418 disconnect( mySelection, 0, this, 0 );
419 myGeomGUI->EraseSimulationShape() ;
420 mySelection->ClearFilters() ;
425 //=================================================================================
426 // function : ActivateThisDialog()
428 //=================================================================================
429 void GeometryGUI_CircleDlg::ActivateThisDialog()
431 /* Emit a signal to deactivate the active dialog */
432 myGeomGUI->EmitSignalDeactivateDialog() ;
433 GroupConstructors->setEnabled(true) ;
434 GroupC1->setEnabled(true) ;
435 GroupButtons->setEnabled(true) ;
436 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
437 if( !mySimulationTopoDs.IsNull() )
438 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
443 //=================================================================================
444 // function : enterEvent()
446 //=================================================================================
447 void GeometryGUI_CircleDlg::enterEvent(QEvent* e)
449 if ( GroupConstructors->isEnabled() )
451 ActivateThisDialog() ;
455 //=================================================================================
456 // function : closeEvent()
458 //=================================================================================
459 void GeometryGUI_CircleDlg::closeEvent( QCloseEvent* e )
461 this->ClickOnCancel() ; /* same than click on cancel button */
465 //=================================================================================
466 // function : MakeCircleSimulationAndDisplay()
468 //=================================================================================
469 void GeometryGUI_CircleDlg::MakeCircleSimulationAndDisplay()
471 myGeomGUI->EraseSimulationShape() ;
474 gp_Ax2 axis( this->myPoint1, this->myDir ) ;
475 gp_Circ circ( axis, this->myRadius);
476 BRepBuilderAPI_MakeEdge MakeEdge( circ );
477 mySimulationTopoDs = MakeEdge.Shape();
478 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
480 catch(Standard_Failure) {
481 MESSAGE( "Exception catched in MakeCircleSimulationAndDisplay" ) ;