2 // File : GeometryGUI_RevolDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_RevolDlg.h"
12 #include <BRepAdaptor_Curve.hxx>
14 #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 <qcheckbox.h>
22 #include <qgroupbox.h>
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
30 #include <qwhatsthis.h>
32 #include <qvalidator.h>
35 //=================================================================================
36 // class : GeometryGUI_RevolDlg()
37 // purpose : Constructs a GeometryGUI_RevolDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 GeometryGUI_RevolDlg::GeometryGUI_RevolDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
43 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_REVOL")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
49 setName( "GeometryGUI_RevolDlg" );
51 setCaption( tr( "GEOM_REVOLUTION_TITLE" ) );
52 setSizeGripEnabled( TRUE );
53 GeometryGUI_RevolDlgLayout = new QGridLayout( this );
54 GeometryGUI_RevolDlgLayout->setSpacing( 6 );
55 GeometryGUI_RevolDlgLayout->setMargin( 11 );
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_REVOLUTION" ) );
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_RevolDlgLayout->addWidget( GroupConstructors, 0, 0 );
78 /***************************************************************/
79 GroupButtons = new QGroupBox( this, "GroupButtons" );
80 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
81 GroupButtons->setTitle( tr( "" ) );
82 GroupButtons->setColumnLayout(0, Qt::Vertical );
83 GroupButtons->layout()->setSpacing( 0 );
84 GroupButtons->layout()->setMargin( 0 );
85 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
86 GroupButtonsLayout->setAlignment( Qt::AlignTop );
87 GroupButtonsLayout->setSpacing( 6 );
88 GroupButtonsLayout->setMargin( 11 );
89 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
90 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
91 buttonCancel->setAutoDefault( TRUE );
92 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
93 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
94 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
95 buttonApply->setAutoDefault( TRUE );
96 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
97 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
98 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
99 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
100 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
101 buttonOk->setAutoDefault( TRUE );
102 buttonOk->setDefault( TRUE );
103 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
104 GeometryGUI_RevolDlgLayout->addWidget( GroupButtons, 2, 0 );
106 /***************************************************************/
107 GroupC1 = new QGroupBox( this, "GroupC1" );
108 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
109 GroupC1->setFrameShape( QGroupBox::Box );
110 GroupC1->setFrameShadow( QGroupBox::Sunken );
111 GroupC1->setColumnLayout(0, Qt::Vertical );
112 GroupC1->layout()->setSpacing( 0 );
113 GroupC1->layout()->setMargin( 0 );
114 GroupC1Layout = new QGridLayout( GroupC1->layout() );
115 GroupC1Layout->setAlignment( Qt::AlignTop );
116 GroupC1Layout->setSpacing( 6 );
117 GroupC1Layout->setMargin( 11 );
119 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
120 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
121 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
122 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
123 TextLabelC1A1->setFrameShadow( QLabel::Plain );
124 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
125 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
126 SelectButtonC1A1->setText( tr( "" ) );
127 SelectButtonC1A1->setPixmap( image1 );
128 SelectButtonC1A1->setToggleButton( FALSE );
129 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
130 SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
131 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
132 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
133 GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 3 );
135 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
136 TextLabelC1A2->setText( tr( "GEOM_AXIS" ) );
137 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
138 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
139 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
140 SelectButtonC1A2->setText( tr( "" ) );
141 SelectButtonC1A2->setPixmap( image1 );
142 SelectButtonC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
143 SelectButtonC1A2->sizePolicy().hasHeightForWidth() ) );
144 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
145 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
146 GroupC1Layout->addMultiCellWidget( LineEditC1A2, 1, 1, 2, 3 );
148 CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
149 CheckBoxReverse->setText( tr( "GEOM_REVERSE" ) );
150 GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 1 );
151 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
152 TextLabelC1A3->setText( tr( "GEOM_ANGLE" ) );
153 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
154 GroupC1Layout->addWidget( TextLabelC1A3, 2, 2 );
155 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
156 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 3 );
158 GeometryGUI_RevolDlgLayout->addWidget( GroupC1, 1, 0 );
159 /***************************************************************/
161 Init(Sel) ; /* Initialisations */
165 //=================================================================================
166 // function : ~GeometryGUI_RevolDlg()
167 // purpose : Destroys the object and frees any allocated resources
168 //=================================================================================
169 GeometryGUI_RevolDlg::~GeometryGUI_RevolDlg()
171 // no need to delete child widgets, Qt does it all for us
175 //=================================================================================
178 //=================================================================================
179 void GeometryGUI_RevolDlg::Init( SALOME_Selection* Sel )
182 /* Get setting of step value from file configuration */
184 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
185 step = St.toDouble() ;
187 /* min, max, step and decimals for spin boxes */
188 SpinBox_C1A3->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
189 SpinBox_C1A3->SetValue( 45.0 ) ; /* = myAngle */
193 myConstructorId = 0 ;
194 Constructor1->setChecked( TRUE );
195 myEditCurrentArgument = LineEditC1A1 ;
197 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
202 mySimulationTopoDs.Nullify() ;
204 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
206 // TODO : previous selection into argument
208 /* Filter definitions */
209 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
210 myGeom = GEOM::GEOM_Gen::_narrow(comp);
211 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
216 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
217 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
218 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
219 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
221 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
222 connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseAngle(int) ) ) ;
224 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
225 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
227 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
228 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
229 /* to close dialog if study change */
230 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
232 /* Move widget on the botton right corner of main widget */
234 myGeomGUI->DefineDlgPosition( this, x, y ) ;
236 this->show() ; /* displays Dialog */
241 //=================================================================================
242 // function : ReverseAngle()
243 // purpose : 'state' not used here
244 //=================================================================================
245 void GeometryGUI_RevolDlg::ReverseAngle(int state)
248 SpinBox_C1A3->SetValue( myAngle ) ;
250 if(myOkBase && myOkAxis) {
251 MakeRevolutionSimulationAndDisplay(myBase) ;
253 myGeomGUI->EraseSimulationShape() ;
254 mySimulationTopoDs.Nullify() ;
260 //=================================================================================
261 // function : ConstructorsClicked()
262 // purpose : Radio button management
263 //=================================================================================
264 void GeometryGUI_RevolDlg::ConstructorsClicked(int constructorId)
266 /* only a constructor now */
270 //=================================================================================
271 // function : ClickOnOk()
273 //=================================================================================
274 void GeometryGUI_RevolDlg::ClickOnOk()
276 this->ClickOnApply() ;
277 this->ClickOnCancel() ;
282 //=================================================================================
283 // function : ClickOnApply()
285 //=================================================================================
286 void GeometryGUI_RevolDlg::ClickOnApply()
288 myGeomGUI->EraseSimulationShape() ;
289 mySimulationTopoDs.Nullify() ;
290 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
292 switch(myConstructorId)
296 if(myOkBase && myOkAxis) {
297 myGeomGUI->MakeRevolutionAndDisplay( myGeomShape, myLoc, myDir, myAngle*PI180 ) ;
306 //=================================================================================
307 // function : ClickOnCancel()
309 //=================================================================================
310 void GeometryGUI_RevolDlg::ClickOnCancel()
312 mySelection->ClearFilters() ;
313 myGeomGUI->EraseSimulationShape() ;
314 mySimulationTopoDs.Nullify() ;
315 disconnect( mySelection, 0, this, 0 );
316 myGeomGUI->ResetState() ;
322 //=================================================================================
323 // function : SelectionIntoArgument()
324 // purpose : Called when selection as changed or other case
325 //=================================================================================
326 void GeometryGUI_RevolDlg::SelectionIntoArgument()
328 myGeomGUI->EraseSimulationShape() ;
329 mySimulationTopoDs.Nullify() ;
331 QString aString = ""; /* name of selection */
333 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
335 if ( myEditCurrentArgument == LineEditC1A1 ) {
336 LineEditC1A1->setText("") ;
339 else if ( myEditCurrentArgument == LineEditC1A2 ) {
340 LineEditC1A2->setText("") ;
348 Standard_Boolean testResult ;
349 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
351 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
354 if ( myEditCurrentArgument == LineEditC1A1 ) {
355 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
359 /* test if appropriate shape for revol */
360 TopAbs_ShapeEnum aType = S.ShapeType() ;
361 if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType != TopAbs_COMPOUND )
364 LineEditC1A1->setText(aString) ;
368 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, myLoc, myDir) */) {
369 BRepAdaptor_Curve curv(TopoDS::Edge(S));
370 myDir = curv.Line().Direction();
371 myLoc = curv.Line().Location();
372 LineEditC1A2->setText(aString) ;
376 if( myOkBase && myOkAxis ) {
377 MakeRevolutionSimulationAndDisplay( myBase) ;
383 //=================================================================================
384 // function : SetEditCurrentArgument()
386 //=================================================================================
387 void GeometryGUI_RevolDlg::SetEditCurrentArgument()
389 QPushButton* send = (QPushButton*)sender();
390 switch (myConstructorId)
392 case 0: /* default constructor */
394 if(send == SelectButtonC1A1) {
395 LineEditC1A1->setFocus() ;
396 myEditCurrentArgument = LineEditC1A1;
397 mySelection->ClearFilters() ;
399 else if(send == SelectButtonC1A2) {
400 LineEditC1A2->setFocus() ;
401 myEditCurrentArgument = LineEditC1A2;
402 mySelection->AddFilter(myEdgeFilter) ;
404 SelectionIntoArgument() ;
411 //=================================================================================
412 // function : LineEditReturnPressed()
414 //=================================================================================
415 void GeometryGUI_RevolDlg::LineEditReturnPressed()
417 QLineEdit* send = (QLineEdit*)sender();
418 if( send == LineEditC1A1 )
419 myEditCurrentArgument = LineEditC1A1 ;
420 else if ( send == LineEditC1A2 )
421 myEditCurrentArgument = LineEditC1A2 ;
425 /* User name of object input management */
426 /* If successfull the selection is changed and signal emitted... */
427 /* so SelectionIntoArgument() is automatically called. */
428 const QString objectUserName = myEditCurrentArgument->text() ;
429 QWidget* thisWidget = (QWidget*)this ;
430 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
431 myEditCurrentArgument->setText( objectUserName ) ;
437 //=================================================================================
438 // function : ValueChangedInSpinBox()
440 //=================================================================================
441 void GeometryGUI_RevolDlg::ValueChangedInSpinBox( double newValue )
444 if ( myOkBase && myOkAxis ) {
445 MakeRevolutionSimulationAndDisplay(myBase) ;
448 myGeomGUI->EraseSimulationShape() ;
449 mySimulationTopoDs.Nullify() ;
455 //=================================================================================
456 // function : DeactivateActiveDialog()
458 //=================================================================================
459 void GeometryGUI_RevolDlg::DeactivateActiveDialog()
461 if ( GroupConstructors->isEnabled() ) {
462 GroupConstructors->setEnabled(false) ;
463 GroupC1->setEnabled(false) ;
464 GroupButtons->setEnabled(false) ;
465 disconnect( mySelection, 0, this, 0 );
466 myGeomGUI->EraseSimulationShape() ;
467 mySelection->ClearFilters() ;
473 //=================================================================================
474 // function : ActivateThisDialog()
476 //=================================================================================
477 void GeometryGUI_RevolDlg::ActivateThisDialog()
479 /* Emit a signal to deactivate the active dialog */
480 myGeomGUI->EmitSignalDeactivateDialog() ;
481 GroupConstructors->setEnabled(true) ;
482 GroupC1->setEnabled(true) ;
483 GroupButtons->setEnabled(true) ;
484 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
485 if( !mySimulationTopoDs.IsNull() )
486 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
492 //=================================================================================
493 // function : enterEvent()
495 //=================================================================================
496 void GeometryGUI_RevolDlg::enterEvent(QEvent* e)
498 if ( GroupConstructors->isEnabled() )
500 ActivateThisDialog() ;
505 //=================================================================================
506 // function : closeEvent()
508 //=================================================================================
509 void GeometryGUI_RevolDlg::closeEvent( QCloseEvent* e )
511 this->ClickOnCancel() ; /* same than click on cancel button */
515 //=================================================================================
516 // function : MakeRevolutionSimulationAndDisplay()
518 //=================================================================================
519 void GeometryGUI_RevolDlg::MakeRevolutionSimulationAndDisplay( const TopoDS_Shape& S)
521 myGeomGUI->EraseSimulationShape() ;
522 mySimulationTopoDs.Nullify() ;
527 TopAbs_ShapeEnum aType = S.ShapeType() ;
528 if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType !=TopAbs_COMPOUND )
532 gp_Ax1 AX( this->myLoc, this->myDir);
533 mySimulationTopoDs = BRepPrimAPI_MakeRevol(S, AX, this->myAngle*PI180 );
534 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
536 catch(Standard_Failure) {
537 MESSAGE( "Exception catched in MakeRevolutionSimulationAndDisplay" ) ;