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_RevolDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_RevolDlg.h"
32 #include <BRepAdaptor_Curve.hxx>
34 #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 <qcheckbox.h>
42 #include <qgroupbox.h>
44 #include <qlineedit.h>
45 #include <qpushbutton.h>
46 #include <qradiobutton.h>
50 #include <qwhatsthis.h>
52 #include <qvalidator.h>
55 //=================================================================================
56 // class : GeometryGUI_RevolDlg()
57 // purpose : Constructs a GeometryGUI_RevolDlg which is a child of 'parent', with the
58 // name 'name' and widget flags set to 'f'.
59 // The dialog will by default be modeless, unless you set 'modal' to
60 // TRUE to construct a modal dialog.
61 //=================================================================================
62 GeometryGUI_RevolDlg::GeometryGUI_RevolDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
63 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_REVOL")));
66 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
69 setName( "GeometryGUI_RevolDlg" );
71 setCaption( tr( "GEOM_REVOLUTION_TITLE" ) );
72 setSizeGripEnabled( TRUE );
73 GeometryGUI_RevolDlgLayout = new QGridLayout( this );
74 GeometryGUI_RevolDlgLayout->setSpacing( 6 );
75 GeometryGUI_RevolDlgLayout->setMargin( 11 );
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_REVOLUTION" ) );
79 GroupConstructors->setExclusive( TRUE );
80 GroupConstructors->setColumnLayout(0, Qt::Vertical );
81 GroupConstructors->layout()->setSpacing( 0 );
82 GroupConstructors->layout()->setMargin( 0 );
83 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85 GroupConstructorsLayout->setSpacing( 6 );
86 GroupConstructorsLayout->setMargin( 11 );
87 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
88 Constructor1->setText( tr( "" ) );
89 Constructor1->setPixmap( image0 );
90 Constructor1->setChecked( TRUE );
91 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
92 Constructor1->setMinimumSize( QSize( 50, 0 ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupConstructorsLayout->addItem( spacer, 0, 1 );
96 GeometryGUI_RevolDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupButtons = new QGroupBox( this, "GroupButtons" );
100 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
101 GroupButtons->setTitle( tr( "" ) );
102 GroupButtons->setColumnLayout(0, Qt::Vertical );
103 GroupButtons->layout()->setSpacing( 0 );
104 GroupButtons->layout()->setMargin( 0 );
105 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106 GroupButtonsLayout->setAlignment( Qt::AlignTop );
107 GroupButtonsLayout->setSpacing( 6 );
108 GroupButtonsLayout->setMargin( 11 );
109 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
110 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
111 buttonCancel->setAutoDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
113 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
114 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
115 buttonApply->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
119 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
121 buttonOk->setAutoDefault( TRUE );
122 buttonOk->setDefault( TRUE );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124 GeometryGUI_RevolDlgLayout->addWidget( GroupButtons, 2, 0 );
126 /***************************************************************/
127 GroupC1 = new QGroupBox( this, "GroupC1" );
128 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
129 GroupC1->setFrameShape( QGroupBox::Box );
130 GroupC1->setFrameShadow( QGroupBox::Sunken );
131 GroupC1->setColumnLayout(0, Qt::Vertical );
132 GroupC1->layout()->setSpacing( 0 );
133 GroupC1->layout()->setMargin( 0 );
134 GroupC1Layout = new QGridLayout( GroupC1->layout() );
135 GroupC1Layout->setAlignment( Qt::AlignTop );
136 GroupC1Layout->setSpacing( 6 );
137 GroupC1Layout->setMargin( 11 );
139 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
140 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
141 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
142 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
143 TextLabelC1A1->setFrameShadow( QLabel::Plain );
144 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
145 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
146 SelectButtonC1A1->setText( tr( "" ) );
147 SelectButtonC1A1->setPixmap( image1 );
148 SelectButtonC1A1->setToggleButton( FALSE );
149 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
150 SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
151 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
152 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
153 GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 3 );
155 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
156 TextLabelC1A2->setText( tr( "GEOM_AXIS" ) );
157 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
158 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
159 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
160 SelectButtonC1A2->setText( tr( "" ) );
161 SelectButtonC1A2->setPixmap( image1 );
162 SelectButtonC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
163 SelectButtonC1A2->sizePolicy().hasHeightForWidth() ) );
164 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
165 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
166 GroupC1Layout->addMultiCellWidget( LineEditC1A2, 1, 1, 2, 3 );
168 CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
169 CheckBoxReverse->setText( tr( "GEOM_REVERSE" ) );
170 GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 1 );
171 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
172 TextLabelC1A3->setText( tr( "GEOM_ANGLE" ) );
173 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
174 GroupC1Layout->addWidget( TextLabelC1A3, 2, 2 );
175 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
176 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 3 );
178 GeometryGUI_RevolDlgLayout->addWidget( GroupC1, 1, 0 );
179 /***************************************************************/
181 Init(Sel) ; /* Initialisations */
185 //=================================================================================
186 // function : ~GeometryGUI_RevolDlg()
187 // purpose : Destroys the object and frees any allocated resources
188 //=================================================================================
189 GeometryGUI_RevolDlg::~GeometryGUI_RevolDlg()
191 // no need to delete child widgets, Qt does it all for us
195 //=================================================================================
198 //=================================================================================
199 void GeometryGUI_RevolDlg::Init( SALOME_Selection* Sel )
202 /* Get setting of step value from file configuration */
204 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
205 step = St.toDouble() ;
207 /* min, max, step and decimals for spin boxes */
208 SpinBox_C1A3->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
209 SpinBox_C1A3->SetValue( 45.0 ) ; /* = myAngle */
213 myConstructorId = 0 ;
214 Constructor1->setChecked( TRUE );
215 myEditCurrentArgument = LineEditC1A1 ;
217 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
222 mySimulationTopoDs.Nullify() ;
224 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
226 // TODO : previous selection into argument
228 /* Filter definitions */
229 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
230 myGeom = GEOM::GEOM_Gen::_narrow(comp);
231 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
233 /* signals and slots connections */
234 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
235 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
236 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
237 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
238 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
239 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
241 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
242 connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseAngle(int) ) ) ;
244 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
245 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
247 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
248 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
249 /* to close dialog if study change */
250 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
252 /* Move widget on the botton right corner of main widget */
254 myGeomGUI->DefineDlgPosition( this, x, y ) ;
256 this->show() ; /* displays Dialog */
261 //=================================================================================
262 // function : ReverseAngle()
263 // purpose : 'state' not used here
264 //=================================================================================
265 void GeometryGUI_RevolDlg::ReverseAngle(int state)
268 SpinBox_C1A3->SetValue( myAngle ) ;
270 if(myOkBase && myOkAxis) {
271 MakeRevolutionSimulationAndDisplay(myBase) ;
273 myGeomGUI->EraseSimulationShape() ;
274 mySimulationTopoDs.Nullify() ;
280 //=================================================================================
281 // function : ConstructorsClicked()
282 // purpose : Radio button management
283 //=================================================================================
284 void GeometryGUI_RevolDlg::ConstructorsClicked(int constructorId)
286 /* only a constructor now */
290 //=================================================================================
291 // function : ClickOnOk()
293 //=================================================================================
294 void GeometryGUI_RevolDlg::ClickOnOk()
296 this->ClickOnApply() ;
297 this->ClickOnCancel() ;
302 //=================================================================================
303 // function : ClickOnApply()
305 //=================================================================================
306 void GeometryGUI_RevolDlg::ClickOnApply()
308 myGeomGUI->EraseSimulationShape() ;
309 mySimulationTopoDs.Nullify() ;
310 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
312 switch(myConstructorId)
316 if(myOkBase && myOkAxis) {
317 myGeomGUI->MakeRevolutionAndDisplay( myGeomShape, myLoc, myDir, myAngle*PI180 ) ;
326 //=================================================================================
327 // function : ClickOnCancel()
329 //=================================================================================
330 void GeometryGUI_RevolDlg::ClickOnCancel()
332 mySelection->ClearFilters() ;
333 myGeomGUI->EraseSimulationShape() ;
334 mySimulationTopoDs.Nullify() ;
335 disconnect( mySelection, 0, this, 0 );
336 myGeomGUI->ResetState() ;
342 //=================================================================================
343 // function : SelectionIntoArgument()
344 // purpose : Called when selection as changed or other case
345 //=================================================================================
346 void GeometryGUI_RevolDlg::SelectionIntoArgument()
348 myGeomGUI->EraseSimulationShape() ;
349 mySimulationTopoDs.Nullify() ;
351 QString aString = ""; /* name of selection */
353 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
355 if ( myEditCurrentArgument == LineEditC1A1 ) {
356 LineEditC1A1->setText("") ;
359 else if ( myEditCurrentArgument == LineEditC1A2 ) {
360 LineEditC1A2->setText("") ;
368 Standard_Boolean testResult ;
369 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
371 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
374 if ( myEditCurrentArgument == LineEditC1A1 ) {
375 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
379 /* test if appropriate shape for revol */
380 TopAbs_ShapeEnum aType = S.ShapeType() ;
381 if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType != TopAbs_COMPOUND )
384 LineEditC1A1->setText(aString) ;
388 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, myLoc, myDir) */) {
389 BRepAdaptor_Curve curv(TopoDS::Edge(S));
390 myDir = curv.Line().Direction();
391 myLoc = curv.Line().Location();
392 LineEditC1A2->setText(aString) ;
396 if( myOkBase && myOkAxis ) {
397 MakeRevolutionSimulationAndDisplay( myBase) ;
403 //=================================================================================
404 // function : SetEditCurrentArgument()
406 //=================================================================================
407 void GeometryGUI_RevolDlg::SetEditCurrentArgument()
409 QPushButton* send = (QPushButton*)sender();
410 switch (myConstructorId)
412 case 0: /* default constructor */
414 if(send == SelectButtonC1A1) {
415 LineEditC1A1->setFocus() ;
416 myEditCurrentArgument = LineEditC1A1;
417 mySelection->ClearFilters() ;
419 else if(send == SelectButtonC1A2) {
420 LineEditC1A2->setFocus() ;
421 myEditCurrentArgument = LineEditC1A2;
422 mySelection->AddFilter(myEdgeFilter) ;
424 SelectionIntoArgument() ;
431 //=================================================================================
432 // function : LineEditReturnPressed()
434 //=================================================================================
435 void GeometryGUI_RevolDlg::LineEditReturnPressed()
437 QLineEdit* send = (QLineEdit*)sender();
438 if( send == LineEditC1A1 )
439 myEditCurrentArgument = LineEditC1A1 ;
440 else if ( send == LineEditC1A2 )
441 myEditCurrentArgument = LineEditC1A2 ;
445 /* User name of object input management */
446 /* If successfull the selection is changed and signal emitted... */
447 /* so SelectionIntoArgument() is automatically called. */
448 const QString objectUserName = myEditCurrentArgument->text() ;
449 QWidget* thisWidget = (QWidget*)this ;
450 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
451 myEditCurrentArgument->setText( objectUserName ) ;
457 //=================================================================================
458 // function : ValueChangedInSpinBox()
460 //=================================================================================
461 void GeometryGUI_RevolDlg::ValueChangedInSpinBox( double newValue )
464 if ( myOkBase && myOkAxis ) {
465 MakeRevolutionSimulationAndDisplay(myBase) ;
468 myGeomGUI->EraseSimulationShape() ;
469 mySimulationTopoDs.Nullify() ;
475 //=================================================================================
476 // function : DeactivateActiveDialog()
478 //=================================================================================
479 void GeometryGUI_RevolDlg::DeactivateActiveDialog()
481 if ( GroupConstructors->isEnabled() ) {
482 GroupConstructors->setEnabled(false) ;
483 GroupC1->setEnabled(false) ;
484 GroupButtons->setEnabled(false) ;
485 disconnect( mySelection, 0, this, 0 );
486 myGeomGUI->EraseSimulationShape() ;
487 mySelection->ClearFilters() ;
493 //=================================================================================
494 // function : ActivateThisDialog()
496 //=================================================================================
497 void GeometryGUI_RevolDlg::ActivateThisDialog()
499 /* Emit a signal to deactivate the active dialog */
500 myGeomGUI->EmitSignalDeactivateDialog() ;
501 GroupConstructors->setEnabled(true) ;
502 GroupC1->setEnabled(true) ;
503 GroupButtons->setEnabled(true) ;
504 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
505 if( !mySimulationTopoDs.IsNull() )
506 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
512 //=================================================================================
513 // function : enterEvent()
515 //=================================================================================
516 void GeometryGUI_RevolDlg::enterEvent(QEvent* e)
518 if ( GroupConstructors->isEnabled() )
520 ActivateThisDialog() ;
525 //=================================================================================
526 // function : closeEvent()
528 //=================================================================================
529 void GeometryGUI_RevolDlg::closeEvent( QCloseEvent* e )
531 this->ClickOnCancel() ; /* same than click on cancel button */
535 //=================================================================================
536 // function : MakeRevolutionSimulationAndDisplay()
538 //=================================================================================
539 void GeometryGUI_RevolDlg::MakeRevolutionSimulationAndDisplay( const TopoDS_Shape& S)
541 myGeomGUI->EraseSimulationShape() ;
542 mySimulationTopoDs.Nullify() ;
547 TopAbs_ShapeEnum aType = S.ShapeType() ;
548 if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType !=TopAbs_COMPOUND )
552 gp_Ax1 AX( this->myLoc, this->myDir);
553 mySimulationTopoDs = BRepPrimAPI_MakeRevol(S, AX, this->myAngle*PI180 );
554 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
556 catch(Standard_Failure) {
557 MESSAGE( "Exception catched in MakeRevolutionSimulationAndDisplay" ) ;