2 // File : GeometryGUI_SphereDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_SphereDlg.h"
11 #include "GeometryGUI_SpinBox.h"
13 #include "GeometryGUI.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_Config.h"
18 #include "utilities.h"
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>
36 //=================================================================================
37 // class : GeometryGUI_SphereDlg()
38 // purpose : Constructs a GeometryGUI_SphereDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 GeometryGUI_SphereDlg::GeometryGUI_SphereDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
44 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SPHERE_P")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
48 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SPHERE_DXYZ")));
51 setName( "GeometryGUI_SphereDlg" );
53 setCaption( tr( "GEOM_SPHERE_TITLE" ) );
54 setSizeGripEnabled( TRUE );
55 GeometryGUI_SphereDlgLayout = new QGridLayout( this );
56 GeometryGUI_SphereDlgLayout->setSpacing( 6 );
57 GeometryGUI_SphereDlgLayout->setMargin( 11 );
59 /***************************************************************/
60 GroupButtons = new QGroupBox( this, "GroupButtons" );
61 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
62 GroupButtons->setTitle( tr( "" ) );
63 GroupButtons->setColumnLayout(0, Qt::Vertical );
64 GroupButtons->layout()->setSpacing( 0 );
65 GroupButtons->layout()->setMargin( 0 );
66 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
67 GroupButtonsLayout->setAlignment( Qt::AlignTop );
68 GroupButtonsLayout->setSpacing( 6 );
69 GroupButtonsLayout->setMargin( 11 );
70 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
71 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
72 buttonCancel->setAutoDefault( TRUE );
73 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
74 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
75 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
76 buttonApply->setAutoDefault( TRUE );
77 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
78 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
80 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
81 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
82 buttonOk->setAutoDefault( TRUE );
83 buttonOk->setDefault( TRUE );
84 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
85 GeometryGUI_SphereDlgLayout->addWidget( GroupButtons, 2, 0 );
87 /***************************************************************/
88 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
89 GroupConstructors->setTitle( tr( "GEOM_SPHERE" ) );
90 GroupConstructors->setExclusive( TRUE );
91 GroupConstructors->setColumnLayout(0, Qt::Vertical );
92 GroupConstructors->layout()->setSpacing( 0 );
93 GroupConstructors->layout()->setMargin( 0 );
94 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
95 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
96 GroupConstructorsLayout->setSpacing( 6 );
97 GroupConstructorsLayout->setMargin( 11 );
98 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupConstructorsLayout->addItem( spacer_2, 0, 3 );
100 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
101 Constructor1->setText( tr( "" ) );
102 Constructor1->setPixmap( image0 );
103 Constructor1->setChecked( TRUE );
104 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
105 Constructor1->setMinimumSize( QSize( 50, 0 ) );
106 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
107 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
108 GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
109 Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
110 Constructor2->setText( tr( "" ) );
111 GroupConstructors->insert( Constructor2, 1 );
112 Constructor2->setMinimumSize( QSize( 50, 0 ) );
113 Constructor2->setPixmap( image2 );
114 GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
115 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructors, 0, 0 );
116 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
117 GroupConstructor1->setTitle( tr( "GEOM_SPHERE_CR" ) );
118 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
119 GroupConstructor1->layout()->setSpacing( 0 );
120 GroupConstructor1->layout()->setMargin( 0 );
121 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
122 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
123 GroupConstructor1Layout->setSpacing( 6 );
124 GroupConstructor1Layout->setMargin( 11 );
125 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
126 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
127 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
128 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
129 SelectButtonC1A1->setText( tr( "" ) );
130 SelectButtonC1A1->setPixmap( image1 );
131 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
132 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
133 TextLabelC1A1->setText( tr( "GEOM_CENTER" ) );
134 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
135 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
136 TextLabelC1A1->setFrameShadow( QLabel::Plain );
137 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
138 TextLabelC1A2 = new QLabel( GroupConstructor1, "TextLabelC1A2" );
139 TextLabelC1A2->setText( tr( "GEOM_RADIUS" ) );
140 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
141 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
142 TextLabelC1A2->setFrameShadow( QLabel::Plain );
143 GroupConstructor1Layout->addWidget( TextLabelC1A2, 1, 0 );
145 SpinBox_C1A2 = new GeometryGUI_SpinBox( GroupConstructor1, "GeomSpinBox_C1A2" ) ;
146 GroupConstructor1Layout->addWidget( SpinBox_C1A2, 1, 2 );
148 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructor1, 1, 0 );
150 /***************************************************************/
151 GroupConstructor2 = new QGroupBox( this, "GroupConstructor2" );
152 GroupConstructor2->setTitle( tr( "GEOM_SPHERE_RO" ) );
153 GroupConstructor2->setColumnLayout(0, Qt::Vertical );
154 GroupConstructor2->layout()->setSpacing( 0 );
155 GroupConstructor2->layout()->setMargin( 0 );
156 GroupConstructor2Layout = new QGridLayout( GroupConstructor2->layout() );
157 GroupConstructor2Layout->setAlignment( Qt::AlignTop );
158 GroupConstructor2Layout->setSpacing( 6 );
159 GroupConstructor2Layout->setMargin( 11 );
161 SpinBox_C2A1 = new GeometryGUI_SpinBox( GroupConstructor2, "GeomSpinBox_C2A1" ) ;
162 GroupConstructor2Layout->addWidget( SpinBox_C2A1, 0, 1 );
164 TextLabelC2A1 = new QLabel( GroupConstructor2, "TextLabelC2A1" );
165 TextLabelC2A1->setText( tr( "GEOM_RADIUS" ) );
166 TextLabelC2A1->setMinimumSize( QSize( 50, 0 ) );
167 TextLabelC2A1->setFrameShape( QLabel::NoFrame );
168 TextLabelC2A1->setFrameShadow( QLabel::Plain );
169 GroupConstructor2Layout->addWidget( TextLabelC2A1, 0, 0 );
170 QSpacerItem* spacer_5 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
171 GroupConstructor2Layout->addItem( spacer_5, 1, 1 );
172 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructor2, 1, 0 );
174 Init(Sel) ; /* Initialisations */
178 //=================================================================================
179 // function : ~GeometryGUI_SphereDlg()
180 // purpose : Destroys the object and frees any allocated resources
181 //=================================================================================
182 GeometryGUI_SphereDlg::~GeometryGUI_SphereDlg()
184 /* no need to delete child widgets, Qt does it all for us */
188 //=================================================================================
191 //=================================================================================
192 void GeometryGUI_SphereDlg::Init( SALOME_Selection* Sel )
195 /* Get setting of step value from file configuration */
197 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
198 step = St.toDouble() ;
200 /* min, max, step and decimals for spin boxes */
201 SpinBox_C1A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
202 SpinBox_C1A2->SetValue( 100.0 ) ;
203 SpinBox_C2A1->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
204 SpinBox_C2A1->SetValue( 100.0 ) ;
206 GroupConstructor1->show();
207 GroupConstructor2->hide();
208 myConstructorId = 0 ;
209 Constructor1->setChecked( TRUE );
210 myEditCurrentArgument = LineEditC1A1 ;
212 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
213 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
219 mySimulationTopoDs.Nullify() ;
220 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
222 /* Filters definition */
223 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
224 myGeom = GEOM::GEOM_Gen::_narrow(comp);
225 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
226 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
228 /* signals and slots connections */
229 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
230 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
231 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
232 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
233 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
235 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
237 connect( SpinBox_C1A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
238 connect( SpinBox_C2A1, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
240 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
241 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
242 /* to close dialog if study change */
243 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
245 /* Move widget on the botton right corner of main widget */
247 myGeomGUI->DefineDlgPosition( this, x, y ) ;
249 this->show() ; /* displays Dialog */
256 //=================================================================================
257 // function : ConstructorsClicked()
258 // purpose : Radio button management
259 //=================================================================================
260 void GeometryGUI_SphereDlg::ConstructorsClicked(int constructorId)
262 myGeomGUI->EraseSimulationShape() ;
264 switch (constructorId)
268 GroupConstructor1->show();
269 GroupConstructor2->hide();
270 myConstructorId = constructorId ;
271 myEditCurrentArgument = SpinBox_C1A2 ;
272 LineEditC1A1->setText(tr("")) ;
273 SpinBox_C1A2->SetValue( 100.0 ) ;
277 /* filter for next selections */
278 mySelection->ClearFilters() ;
279 mySelection->AddFilter( myVertexFilter );
280 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
285 GroupConstructor1->hide();
286 GroupConstructor2->show();
287 myConstructorId = constructorId ;
288 myEditCurrentArgument = SpinBox_C2A1 ;;
289 SpinBox_C2A1->SetValue( 100.0 ) ;
292 myPoint1.SetCoord( 0.0, 0.0, 0.0 ); /* at origin */
294 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
295 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
296 /* no filters here */
297 mySelection->ClearFilters() ;
304 //=================================================================================
305 // function : ClickOnApply()
307 //=================================================================================
308 void GeometryGUI_SphereDlg::ClickOnApply()
310 myGeomGUI->EraseSimulationShape() ;
311 mySimulationTopoDs.Nullify() ;
312 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
313 switch(myConstructorId)
317 if( myOkPoint1 && myOkRadius ) {
318 myGeomGUI->MakeSphereAndDisplay( myPoint1, myRadius ) ;
325 myGeomGUI->MakeSphereAndDisplay( myPoint1, myRadius ) ;
333 //=================================================================================
334 // function : ClickOnOk()
336 //=================================================================================
337 void GeometryGUI_SphereDlg::ClickOnOk()
339 this->ClickOnApply() ;
340 this->ClickOnCancel() ;
345 //=================================================================================
346 // function : ClickOnCancel()
348 //=================================================================================
349 void GeometryGUI_SphereDlg::ClickOnCancel()
351 mySelection->ClearFilters() ;
352 myGeomGUI->EraseSimulationShape() ;
353 mySimulationTopoDs.Nullify() ;
354 disconnect( mySelection, 0, this, 0 );
355 myGeomGUI->ResetState() ;
361 //=================================================================================
362 // function : SelectionIntoArgument()
363 // purpose : Called when selection as changed or other case
364 //=================================================================================
365 void GeometryGUI_SphereDlg::SelectionIntoArgument()
367 myGeomGUI->EraseSimulationShape() ;
368 mySimulationTopoDs.Nullify() ;
370 /* Future name of selection */
371 QString aString = "";
373 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
375 if ( myEditCurrentArgument == LineEditC1A1 ) {
376 LineEditC1A1->setText("") ;
384 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
387 /* Constructor 1 treatment */
388 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
389 LineEditC1A1->setText(aString) ;
393 if( ( myOkPoint1 || myConstructorId == 1 ) && myOkRadius ) {
394 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
395 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
401 //=================================================================================
402 // function : LineEditReturnPressed()
404 //=================================================================================
405 void GeometryGUI_SphereDlg::LineEditReturnPressed()
407 QLineEdit* send = (QLineEdit*)sender();
408 if( send == LineEditC1A1 )
409 myEditCurrentArgument = LineEditC1A1 ;
413 /* User name of object input management */
414 /* If successfull the selection is changed and signal emitted... */
415 /* so SelectionIntoArgument() is automatically called. */
416 QLineEdit* LE = (QLineEdit*)myEditCurrentArgument ;
417 const QString objectUserName = LE->text() ;
418 QWidget* thisWidget = (QWidget*)this ;
419 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
420 LE->setText( objectUserName ) ;
426 //=================================================================================
427 // function : ValueChangedInSpinBox()
429 //=================================================================================
430 void GeometryGUI_SphereDlg::ValueChangedInSpinBox( double newValue )
432 myRadius = newValue ;
435 if ( ( myOkPoint1 || myConstructorId == 1 ) && myOkRadius ) {
436 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
437 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
440 myGeomGUI->EraseSimulationShape() ;
441 mySimulationTopoDs.Nullify() ;
449 //=================================================================================
450 // function : SetEditCurrentArgument()
452 //=================================================================================
453 void GeometryGUI_SphereDlg::SetEditCurrentArgument()
455 QPushButton* send = (QPushButton*)sender();
456 switch (myConstructorId)
458 case 0: /* default constructor */
460 if(send == SelectButtonC1A1) {
461 LineEditC1A1->setFocus() ;
462 myEditCurrentArgument = LineEditC1A1;
463 mySelection->AddFilter(myVertexFilter) ;
464 SelectionIntoArgument() ;
470 /* no selection button here */
478 //=================================================================================
479 // function : DeactivateActiveDialog()
481 //=================================================================================
482 void GeometryGUI_SphereDlg::DeactivateActiveDialog()
484 if ( GroupConstructors->isEnabled() ) {
486 GroupConstructors->setEnabled(false) ;
487 GroupConstructor1->setEnabled(false) ;
488 GroupConstructor2->setEnabled(false) ;
489 GroupButtons->setEnabled(false) ;
490 disconnect( mySelection, 0, this, 0 );
491 myGeomGUI->EraseSimulationShape() ;
492 mySelection->ClearFilters() ;
497 //=================================================================================
498 // function : ActivateThisDialog()
500 //=================================================================================
501 void GeometryGUI_SphereDlg::ActivateThisDialog()
503 /* Emit a signal to deactivate other active dialog */
504 myGeomGUI->EmitSignalDeactivateDialog() ;
505 GroupConstructors->setEnabled(true) ;
506 GroupConstructor1->setEnabled(true) ;
507 GroupConstructor2->setEnabled(true) ;
508 GroupButtons->setEnabled(true) ;
510 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
511 if( !mySimulationTopoDs.IsNull() )
512 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
518 //=================================================================================
519 // function : enterEvent()
521 //=================================================================================
522 void GeometryGUI_SphereDlg::enterEvent(QEvent* e)
524 if ( GroupConstructors->isEnabled() )
526 ActivateThisDialog() ;
530 //=================================================================================
531 // function : closeEvent()
533 //=================================================================================
534 void GeometryGUI_SphereDlg::closeEvent( QCloseEvent* e )
536 this->ClickOnCancel() ; /* same than click on cancel button */