2 // File : GeometryGUI_RotationDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_RotationDlg.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 <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>
36 //=================================================================================
37 // class : GeometryGUI_RotationDlg()
38 // purpose : Constructs a GeometryGUI_RotationDlg 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_RotationDlg::GeometryGUI_RotationDlg( 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( "GEOM",tr("ICON_DLG_ROTATION")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
50 setName( "GeometryGUI_RotationDlg" );
52 setCaption( tr( "GEOM_ROTATION_TITLE" ) );
53 setSizeGripEnabled( TRUE );
54 GeometryGUI_RotationDlgLayout = new QGridLayout( this );
55 GeometryGUI_RotationDlgLayout->setSpacing( 6 );
56 GeometryGUI_RotationDlgLayout->setMargin( 11 );
58 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
59 GroupConstructors->setTitle( tr( "GEOM_ROTATION" ) );
60 GroupConstructors->setExclusive( TRUE );
61 GroupConstructors->setColumnLayout(0, Qt::Vertical );
62 GroupConstructors->layout()->setSpacing( 0 );
63 GroupConstructors->layout()->setMargin( 0 );
64 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
65 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
66 GroupConstructorsLayout->setSpacing( 6 );
67 GroupConstructorsLayout->setMargin( 11 );
68 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
69 Constructor1->setText( tr( "" ) );
70 Constructor1->setPixmap( image0 );
71 Constructor1->setChecked( TRUE );
72 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
73 Constructor1->setMinimumSize( QSize( 50, 0 ) );
74 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
75 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
76 GroupConstructorsLayout->addItem( spacer, 0, 1 );
77 GeometryGUI_RotationDlgLayout->addWidget( GroupConstructors, 0, 0 );
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_RotationDlgLayout->addWidget( GroupButtons, 2, 0 );
107 /***************************************************************/
108 GroupC1 = new QGroupBox( this, "GroupC1" );
109 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
110 GroupC1->setFrameShape( QGroupBox::Box );
111 GroupC1->setFrameShadow( QGroupBox::Sunken );
112 GroupC1->setColumnLayout(0, Qt::Vertical );
113 GroupC1->layout()->setSpacing( 0 );
114 GroupC1->layout()->setMargin( 0 );
115 GroupC1Layout = new QGridLayout( GroupC1->layout() );
116 GroupC1Layout->setAlignment( Qt::AlignTop );
117 GroupC1Layout->setSpacing( 6 );
118 GroupC1Layout->setMargin( 11 );
119 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
120 SelectButtonC1A2->setText( tr( "" ) );
121 SelectButtonC1A2->setPixmap( image1 );
122 SelectButtonC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
123 SelectButtonC1A2->sizePolicy().hasHeightForWidth() ) );
124 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
126 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
127 GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 3 );
128 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
129 GroupC1Layout->addMultiCellWidget( LineEditC1A2, 1, 1, 2, 3 );
130 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
131 SelectButtonC1A1->setText( tr( "" ) );
132 SelectButtonC1A1->setPixmap( image1 );
133 SelectButtonC1A1->setToggleButton( FALSE );
134 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
135 SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
136 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
138 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
139 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
140 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
141 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
142 TextLabelC1A1->setFrameShadow( QLabel::Plain );
143 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
144 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
145 TextLabelC1A2->setText( tr( "GEOM_AXIS" ) );
146 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
147 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
149 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
150 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 3 );
152 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
153 TextLabelC1A3->setText( tr( "GEOM_ANGLE" ) );
154 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
155 GroupC1Layout->addWidget( TextLabelC1A3, 2, 2 );
156 CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
157 CheckBoxReverse->setText( tr( "GEOM_REVERSE" ) );
158 GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 1 );
159 GeometryGUI_RotationDlgLayout->addWidget( GroupC1, 1, 0 );
161 Init(Sel) ; /* Initialisations */
164 //=================================================================================
165 // function : ~GeometryGUI_RotationDlg()
166 // purpose : Destroys the object and frees any allocated resources
167 //=================================================================================
168 GeometryGUI_RotationDlg::~GeometryGUI_RotationDlg()
170 // no need to delete child widgets, Qt does it all for us
173 //=================================================================================
176 //=================================================================================
177 void GeometryGUI_RotationDlg::Init( SALOME_Selection* Sel )
180 /* Get setting of step value from file configuration */
182 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
183 step = St.toDouble() ;
185 /* min, max, step and decimals for spin boxes */
186 SpinBox_C1A3->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
187 SpinBox_C1A3->SetValue( 45.0 ) ; /* = myAngle */
191 myConstructorId = 0 ;
192 Constructor1->setChecked( TRUE );
193 myEditCurrentArgument = LineEditC1A1 ;
195 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
196 myOkBase = myOkAxis = false ;
197 mySimulationTopoDs.Nullify() ;
199 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
201 // TODO : set previous selection into argument ?
203 /* Filter definitions */
204 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
205 myGeom = GEOM::GEOM_Gen::_narrow(comp);
206 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
208 /* signals and slots connections */
209 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
210 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
211 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
212 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
213 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
214 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
216 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
217 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
219 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
220 connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseAngle(int) ) ) ;
222 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
223 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
224 /* to close dialog if study change */
225 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
227 /* Move widget on the botton right corner of main widget */
229 myGeomGUI->DefineDlgPosition( this, x, y ) ;
231 this->show() ; /* displays Dialog */
236 //=================================================================================
237 // function : ReverseAngle()
238 // purpose : 'state' not used here
239 //=================================================================================
240 void GeometryGUI_RotationDlg::ReverseAngle(int state)
243 SpinBox_C1A3->SetValue( myAngle ) ;
244 if( myOkBase && myOkAxis ) {
245 MakeRotationSimulationAndDisplay( myBase ) ;
248 myGeomGUI->EraseSimulationShape() ;
249 mySimulationTopoDs.Nullify() ;
255 //=================================================================================
256 // function : ConstructorsClicked()
257 // purpose : Radio button management
258 //=================================================================================
259 void GeometryGUI_RotationDlg::ConstructorsClicked(int constructorId)
261 /* only a constructor now */
265 //=================================================================================
266 // function : ClickOnOk()
268 //=================================================================================
269 void GeometryGUI_RotationDlg::ClickOnOk()
271 this->ClickOnApply() ;
272 this->ClickOnCancel() ;
276 //=================================================================================
277 // function : ClickOnApply()
279 //=================================================================================
280 void GeometryGUI_RotationDlg::ClickOnApply()
282 myGeomGUI->EraseSimulationShape() ;
283 mySimulationTopoDs.Nullify() ;
284 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
286 switch(myConstructorId)
290 if(myOkBase && myOkAxis) {
291 myGeomGUI->MakeRotationAndDisplay( myGeomShape, myLoc, myDir, myAngle*PI180) ;
300 //=================================================================================
301 // function : ClickOnCancel()
303 //=================================================================================
304 void GeometryGUI_RotationDlg::ClickOnCancel()
306 mySelection->ClearFilters() ;
307 myGeomGUI->EraseSimulationShape() ;
308 mySimulationTopoDs.Nullify() ;
309 disconnect( mySelection, 0, this, 0 );
310 myGeomGUI->ResetState() ;
316 //=================================================================================
317 // function : SelectionIntoArgument()
318 // purpose : Called when selection as changed or other case
319 //=================================================================================
320 void GeometryGUI_RotationDlg::SelectionIntoArgument()
322 myGeomGUI->EraseSimulationShape() ;
323 mySimulationTopoDs.Nullify() ;
325 QString aString = ""; /* name of future selection */
327 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
329 if ( myEditCurrentArgument == LineEditC1A1 ) {
330 LineEditC1A1->setText("") ;
333 else if ( myEditCurrentArgument == LineEditC1A2 ) {
334 LineEditC1A2->setText("") ;
342 Standard_Boolean testResult ;
343 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
345 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
348 if ( myEditCurrentArgument == LineEditC1A1 ) {
349 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
352 LineEditC1A1->setText(aString) ;
356 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, myLoc, myDir) */) {
357 BRepAdaptor_Curve curv(TopoDS::Edge(S));
358 myDir = curv.Line().Direction();
359 myLoc = curv.Line().Location();
360 LineEditC1A2->setText(aString) ;
364 if( myOkBase && myOkAxis ) {
365 MakeRotationSimulationAndDisplay( myBase) ;
371 //=================================================================================
372 // function : SetEditCurrentArgument()
374 //=================================================================================
375 void GeometryGUI_RotationDlg::SetEditCurrentArgument()
377 QPushButton* send = (QPushButton*)sender();
378 switch (myConstructorId)
380 case 0: /* default constructor */
382 if(send == SelectButtonC1A1) {
383 LineEditC1A1->setFocus() ;
384 myEditCurrentArgument = LineEditC1A1;
385 mySelection->ClearFilters() ;
387 else if(send == SelectButtonC1A2) {
388 LineEditC1A2->setFocus() ;
389 myEditCurrentArgument = LineEditC1A2;
390 mySelection->AddFilter(myEdgeFilter) ;
392 SelectionIntoArgument() ;
400 //=================================================================================
401 // function : LineEditReturnPressed()
403 //=================================================================================
404 void GeometryGUI_RotationDlg::LineEditReturnPressed()
406 QLineEdit* send = (QLineEdit*)sender();
407 if( send == LineEditC1A1 )
408 myEditCurrentArgument = LineEditC1A1 ;
409 else if ( send == LineEditC1A2 )
410 myEditCurrentArgument = LineEditC1A2 ;
414 /* User name of object input management */
415 /* If successfull the selection is changed and signal emitted... */
416 /* so SelectionIntoArgument() is automatically called. */
417 const QString objectUserName = myEditCurrentArgument->text() ;
418 QWidget* thisWidget = (QWidget*)this ;
419 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
420 myEditCurrentArgument->setText( objectUserName ) ;
426 //=================================================================================
427 // function : ValueChangedInSpinBox()
429 //=================================================================================
430 void GeometryGUI_RotationDlg::ValueChangedInSpinBox( double newValue )
433 if (myOkBase && myOkAxis) {
434 MakeRotationSimulationAndDisplay(myBase) ;
437 myGeomGUI->EraseSimulationShape() ;
438 mySimulationTopoDs.Nullify() ;
444 //=================================================================================
445 // function : DeactivateActiveDialog()
447 //=================================================================================
448 void GeometryGUI_RotationDlg::DeactivateActiveDialog()
450 if ( GroupConstructors->isEnabled() ) {
451 GroupConstructors->setEnabled(false) ;
452 GroupC1->setEnabled(false) ;
453 GroupButtons->setEnabled(false) ;
454 disconnect( mySelection, 0, this, 0 );
455 myGeomGUI->EraseSimulationShape() ;
456 mySelection->ClearFilters() ;
462 //=================================================================================
463 // function : ActivateThisDialog()
465 //=================================================================================
466 void GeometryGUI_RotationDlg::ActivateThisDialog()
468 /* Emit a signal to deactivate the active dialog */
469 myGeomGUI->EmitSignalDeactivateDialog() ;
470 GroupConstructors->setEnabled(true) ;
471 GroupC1->setEnabled(true) ;
472 GroupButtons->setEnabled(true) ;
473 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
474 if( !mySimulationTopoDs.IsNull() )
475 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
481 //=================================================================================
482 // function : enterEvent()
484 //=================================================================================
485 void GeometryGUI_RotationDlg::enterEvent(QEvent* e)
487 if ( GroupConstructors->isEnabled() )
489 ActivateThisDialog() ;
494 //=================================================================================
495 // function : closeEvent()
497 //=================================================================================
498 void GeometryGUI_RotationDlg::closeEvent( QCloseEvent* e )
500 this->ClickOnCancel() ; /* same than click on cancel button */
504 //=================================================================================
505 // function : MakeRotationSimulationAndDisplay()
507 //=================================================================================
508 void GeometryGUI_RotationDlg::MakeRotationSimulationAndDisplay( const TopoDS_Shape& S)
510 myGeomGUI->EraseSimulationShape() ;
516 gp_Ax1 AX( this->myLoc, this->myDir ) ;
517 gp_Trsf theTransformation ;
518 theTransformation.SetRotation(AX, this->myAngle*PI180 ) ;
519 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False) ;
520 this->mySimulationTopoDs = myBRepTransformation.Shape() ;
521 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
523 catch(Standard_Failure) {
524 MESSAGE( "Exception catched in MakeRotationSimulationAndDisplay" ) ;