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_SphereDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_SphereDlg.h"
31 #include "GeometryGUI_SpinBox.h"
33 #include "GeometryGUI.h"
35 #include "QAD_Application.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_Config.h"
38 #include "utilities.h"
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
51 #include <qvalidator.h>
56 //=================================================================================
57 // class : GeometryGUI_SphereDlg()
58 // purpose : Constructs a GeometryGUI_SphereDlg which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // TRUE to construct a modal dialog.
62 //=================================================================================
63 GeometryGUI_SphereDlg::GeometryGUI_SphereDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SPHERE_P")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
68 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
71 setName( "GeometryGUI_SphereDlg" );
73 setCaption( tr( "GEOM_SPHERE_TITLE" ) );
74 setSizeGripEnabled( TRUE );
75 GeometryGUI_SphereDlgLayout = new QGridLayout( this );
76 GeometryGUI_SphereDlgLayout->setSpacing( 6 );
77 GeometryGUI_SphereDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 GroupButtons = new QGroupBox( this, "GroupButtons" );
81 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
82 GroupButtons->setTitle( tr( "" ) );
83 GroupButtons->setColumnLayout(0, Qt::Vertical );
84 GroupButtons->layout()->setSpacing( 0 );
85 GroupButtons->layout()->setMargin( 0 );
86 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
87 GroupButtonsLayout->setAlignment( Qt::AlignTop );
88 GroupButtonsLayout->setSpacing( 6 );
89 GroupButtonsLayout->setMargin( 11 );
90 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
91 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
92 buttonCancel->setAutoDefault( TRUE );
93 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
94 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
95 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
96 buttonApply->setAutoDefault( TRUE );
97 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
98 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
100 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
101 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
102 buttonOk->setAutoDefault( TRUE );
103 buttonOk->setDefault( TRUE );
104 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
105 GeometryGUI_SphereDlgLayout->addWidget( GroupButtons, 2, 0 );
107 /***************************************************************/
108 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
109 GroupConstructors->setTitle( tr( "GEOM_SPHERE" ) );
110 GroupConstructors->setExclusive( TRUE );
111 GroupConstructors->setColumnLayout(0, Qt::Vertical );
112 GroupConstructors->layout()->setSpacing( 0 );
113 GroupConstructors->layout()->setMargin( 0 );
114 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
115 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
116 GroupConstructorsLayout->setSpacing( 6 );
117 GroupConstructorsLayout->setMargin( 11 );
118 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
119 GroupConstructorsLayout->addItem( spacer_2, 0, 3 );
120 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
121 Constructor1->setText( tr( "" ) );
122 Constructor1->setPixmap( image0 );
123 Constructor1->setChecked( TRUE );
124 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
125 Constructor1->setMinimumSize( QSize( 50, 0 ) );
126 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
127 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
128 GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
129 Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
130 Constructor2->setText( tr( "" ) );
131 GroupConstructors->insert( Constructor2, 1 );
132 Constructor2->setMinimumSize( QSize( 50, 0 ) );
133 Constructor2->setPixmap( image2 );
134 GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
135 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructors, 0, 0 );
136 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
137 GroupConstructor1->setTitle( tr( "GEOM_SPHERE_CR" ) );
138 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
139 GroupConstructor1->layout()->setSpacing( 0 );
140 GroupConstructor1->layout()->setMargin( 0 );
141 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
142 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
143 GroupConstructor1Layout->setSpacing( 6 );
144 GroupConstructor1Layout->setMargin( 11 );
145 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
146 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
147 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
148 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
149 SelectButtonC1A1->setText( tr( "" ) );
150 SelectButtonC1A1->setPixmap( image1 );
151 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
152 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
153 TextLabelC1A1->setText( tr( "GEOM_CENTER" ) );
154 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
155 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
156 TextLabelC1A1->setFrameShadow( QLabel::Plain );
157 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
158 TextLabelC1A2 = new QLabel( GroupConstructor1, "TextLabelC1A2" );
159 TextLabelC1A2->setText( tr( "GEOM_RADIUS" ) );
160 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
161 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
162 TextLabelC1A2->setFrameShadow( QLabel::Plain );
163 GroupConstructor1Layout->addWidget( TextLabelC1A2, 1, 0 );
165 SpinBox_C1A2 = new GeometryGUI_SpinBox( GroupConstructor1, "GeomSpinBox_C1A2" ) ;
166 GroupConstructor1Layout->addWidget( SpinBox_C1A2, 1, 2 );
168 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructor1, 1, 0 );
170 /***************************************************************/
171 GroupConstructor2 = new QGroupBox( this, "GroupConstructor2" );
172 GroupConstructor2->setTitle( tr( "GEOM_SPHERE_RO" ) );
173 GroupConstructor2->setColumnLayout(0, Qt::Vertical );
174 GroupConstructor2->layout()->setSpacing( 0 );
175 GroupConstructor2->layout()->setMargin( 0 );
176 GroupConstructor2Layout = new QGridLayout( GroupConstructor2->layout() );
177 GroupConstructor2Layout->setAlignment( Qt::AlignTop );
178 GroupConstructor2Layout->setSpacing( 6 );
179 GroupConstructor2Layout->setMargin( 11 );
181 SpinBox_C2A1 = new GeometryGUI_SpinBox( GroupConstructor2, "GeomSpinBox_C2A1" ) ;
182 GroupConstructor2Layout->addWidget( SpinBox_C2A1, 0, 1 );
184 TextLabelC2A1 = new QLabel( GroupConstructor2, "TextLabelC2A1" );
185 TextLabelC2A1->setText( tr( "GEOM_RADIUS" ) );
186 TextLabelC2A1->setMinimumSize( QSize( 50, 0 ) );
187 TextLabelC2A1->setFrameShape( QLabel::NoFrame );
188 TextLabelC2A1->setFrameShadow( QLabel::Plain );
189 GroupConstructor2Layout->addWidget( TextLabelC2A1, 0, 0 );
190 QSpacerItem* spacer_5 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
191 GroupConstructor2Layout->addItem( spacer_5, 1, 1 );
192 GeometryGUI_SphereDlgLayout->addWidget( GroupConstructor2, 1, 0 );
194 Init(Sel) ; /* Initialisations */
198 //=================================================================================
199 // function : ~GeometryGUI_SphereDlg()
200 // purpose : Destroys the object and frees any allocated resources
201 //=================================================================================
202 GeometryGUI_SphereDlg::~GeometryGUI_SphereDlg()
204 /* no need to delete child widgets, Qt does it all for us */
208 //=================================================================================
211 //=================================================================================
212 void GeometryGUI_SphereDlg::Init( SALOME_Selection* Sel )
215 /* Get setting of step value from file configuration */
217 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
218 step = St.toDouble() ;
220 /* min, max, step and decimals for spin boxes */
221 SpinBox_C1A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
222 SpinBox_C1A2->SetValue( 100.0 ) ;
223 SpinBox_C2A1->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
224 SpinBox_C2A1->SetValue( 100.0 ) ;
226 GroupConstructor1->show();
227 GroupConstructor2->hide();
228 myConstructorId = 0 ;
229 Constructor1->setChecked( TRUE );
230 myEditCurrentArgument = LineEditC1A1 ;
232 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
233 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
239 mySimulationTopoDs.Nullify() ;
240 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
242 /* Filters definition */
243 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
244 myGeom = GEOM::GEOM_Gen::_narrow(comp);
245 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
246 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
248 /* signals and slots connections */
249 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
250 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
251 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
252 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
253 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
255 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
257 connect( SpinBox_C1A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
258 connect( SpinBox_C2A1, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
260 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
261 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
262 /* to close dialog if study change */
263 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
265 /* Move widget on the botton right corner of main widget */
267 myGeomGUI->DefineDlgPosition( this, x, y ) ;
269 this->show() ; /* displays Dialog */
276 //=================================================================================
277 // function : ConstructorsClicked()
278 // purpose : Radio button management
279 //=================================================================================
280 void GeometryGUI_SphereDlg::ConstructorsClicked(int constructorId)
282 myGeomGUI->EraseSimulationShape() ;
284 switch (constructorId)
288 GroupConstructor1->show();
289 GroupConstructor2->hide();
290 myConstructorId = constructorId ;
291 myEditCurrentArgument = SpinBox_C1A2 ;
292 LineEditC1A1->setText(tr("")) ;
293 SpinBox_C1A2->SetValue( 100.0 ) ;
297 /* filter for next selections */
298 mySelection->ClearFilters() ;
299 mySelection->AddFilter( myVertexFilter );
300 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
305 GroupConstructor1->hide();
306 GroupConstructor2->show();
307 myConstructorId = constructorId ;
308 myEditCurrentArgument = SpinBox_C2A1 ;;
309 SpinBox_C2A1->SetValue( 100.0 ) ;
312 myPoint1.SetCoord( 0.0, 0.0, 0.0 ); /* at origin */
314 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
315 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
316 /* no filters here */
317 mySelection->ClearFilters() ;
324 //=================================================================================
325 // function : ClickOnApply()
327 //=================================================================================
328 void GeometryGUI_SphereDlg::ClickOnApply()
330 myGeomGUI->EraseSimulationShape() ;
331 mySimulationTopoDs.Nullify() ;
332 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
333 switch(myConstructorId)
337 if( myOkPoint1 && myOkRadius ) {
338 myGeomGUI->MakeSphereAndDisplay( myPoint1, myRadius ) ;
345 myGeomGUI->MakeSphereAndDisplay( myPoint1, myRadius ) ;
353 //=================================================================================
354 // function : ClickOnOk()
356 //=================================================================================
357 void GeometryGUI_SphereDlg::ClickOnOk()
359 this->ClickOnApply() ;
360 this->ClickOnCancel() ;
365 //=================================================================================
366 // function : ClickOnCancel()
368 //=================================================================================
369 void GeometryGUI_SphereDlg::ClickOnCancel()
371 mySelection->ClearFilters() ;
372 myGeomGUI->EraseSimulationShape() ;
373 mySimulationTopoDs.Nullify() ;
374 disconnect( mySelection, 0, this, 0 );
375 myGeomGUI->ResetState() ;
381 //=================================================================================
382 // function : SelectionIntoArgument()
383 // purpose : Called when selection as changed or other case
384 //=================================================================================
385 void GeometryGUI_SphereDlg::SelectionIntoArgument()
387 myGeomGUI->EraseSimulationShape() ;
388 mySimulationTopoDs.Nullify() ;
390 /* Future name of selection */
391 QString aString = "";
393 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
395 if ( myEditCurrentArgument == LineEditC1A1 ) {
396 LineEditC1A1->setText("") ;
404 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
407 /* Constructor 1 treatment */
408 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
409 LineEditC1A1->setText(aString) ;
413 if( ( myOkPoint1 || myConstructorId == 1 ) && myOkRadius ) {
414 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
415 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
421 //=================================================================================
422 // function : LineEditReturnPressed()
424 //=================================================================================
425 void GeometryGUI_SphereDlg::LineEditReturnPressed()
427 QLineEdit* send = (QLineEdit*)sender();
428 if( send == LineEditC1A1 )
429 myEditCurrentArgument = LineEditC1A1 ;
433 /* User name of object input management */
434 /* If successfull the selection is changed and signal emitted... */
435 /* so SelectionIntoArgument() is automatically called. */
436 QLineEdit* LE = (QLineEdit*)myEditCurrentArgument ;
437 const QString objectUserName = LE->text() ;
438 QWidget* thisWidget = (QWidget*)this ;
439 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
440 LE->setText( objectUserName ) ;
446 //=================================================================================
447 // function : ValueChangedInSpinBox()
449 //=================================================================================
450 void GeometryGUI_SphereDlg::ValueChangedInSpinBox( double newValue )
452 myRadius = newValue ;
455 if ( ( myOkPoint1 || myConstructorId == 1 ) && myOkRadius ) {
456 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
457 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
460 myGeomGUI->EraseSimulationShape() ;
461 mySimulationTopoDs.Nullify() ;
469 //=================================================================================
470 // function : SetEditCurrentArgument()
472 //=================================================================================
473 void GeometryGUI_SphereDlg::SetEditCurrentArgument()
475 QPushButton* send = (QPushButton*)sender();
476 switch (myConstructorId)
478 case 0: /* default constructor */
480 if(send == SelectButtonC1A1) {
481 LineEditC1A1->setFocus() ;
482 myEditCurrentArgument = LineEditC1A1;
483 mySelection->AddFilter(myVertexFilter) ;
484 SelectionIntoArgument() ;
490 /* no selection button here */
498 //=================================================================================
499 // function : DeactivateActiveDialog()
501 //=================================================================================
502 void GeometryGUI_SphereDlg::DeactivateActiveDialog()
504 if ( GroupConstructors->isEnabled() ) {
506 GroupConstructors->setEnabled(false) ;
507 GroupConstructor1->setEnabled(false) ;
508 GroupConstructor2->setEnabled(false) ;
509 GroupButtons->setEnabled(false) ;
510 disconnect( mySelection, 0, this, 0 );
511 myGeomGUI->EraseSimulationShape() ;
512 mySelection->ClearFilters() ;
517 //=================================================================================
518 // function : ActivateThisDialog()
520 //=================================================================================
521 void GeometryGUI_SphereDlg::ActivateThisDialog()
523 /* Emit a signal to deactivate other active dialog */
524 myGeomGUI->EmitSignalDeactivateDialog() ;
525 GroupConstructors->setEnabled(true) ;
526 GroupConstructor1->setEnabled(true) ;
527 GroupConstructor2->setEnabled(true) ;
528 GroupButtons->setEnabled(true) ;
530 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
531 if( !mySimulationTopoDs.IsNull() )
532 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
538 //=================================================================================
539 // function : enterEvent()
541 //=================================================================================
542 void GeometryGUI_SphereDlg::enterEvent(QEvent* e)
544 if ( GroupConstructors->isEnabled() )
546 ActivateThisDialog() ;
550 //=================================================================================
551 // function : closeEvent()
553 //=================================================================================
554 void GeometryGUI_SphereDlg::closeEvent( QCloseEvent* e )
556 this->ClickOnCancel() ; /* same than click on cancel button */