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_RotationDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_RotationDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
38 #include <BRepAdaptor_Curve.hxx>
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>
56 //=================================================================================
57 // class : GeometryGUI_RotationDlg()
58 // purpose : Constructs a GeometryGUI_RotationDlg 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_RotationDlg::GeometryGUI_RotationDlg( 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_ROTATION")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
70 setName( "GeometryGUI_RotationDlg" );
72 setCaption( tr( "GEOM_ROTATION_TITLE" ) );
73 setSizeGripEnabled( TRUE );
74 GeometryGUI_RotationDlgLayout = new QGridLayout( this );
75 GeometryGUI_RotationDlgLayout->setSpacing( 6 );
76 GeometryGUI_RotationDlgLayout->setMargin( 11 );
78 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
79 GroupConstructors->setTitle( tr( "GEOM_ROTATION" ) );
80 GroupConstructors->setExclusive( TRUE );
81 GroupConstructors->setColumnLayout(0, Qt::Vertical );
82 GroupConstructors->layout()->setSpacing( 0 );
83 GroupConstructors->layout()->setMargin( 0 );
84 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
85 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
86 GroupConstructorsLayout->setSpacing( 6 );
87 GroupConstructorsLayout->setMargin( 11 );
88 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
89 Constructor1->setText( tr( "" ) );
90 Constructor1->setPixmap( image0 );
91 Constructor1->setChecked( TRUE );
92 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
93 Constructor1->setMinimumSize( QSize( 50, 0 ) );
94 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
95 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
96 GroupConstructorsLayout->addItem( spacer, 0, 1 );
97 GeometryGUI_RotationDlgLayout->addWidget( GroupConstructors, 0, 0 );
99 /***************************************************************/
100 GroupButtons = new QGroupBox( this, "GroupButtons" );
101 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
102 GroupButtons->setTitle( tr( "" ) );
103 GroupButtons->setColumnLayout(0, Qt::Vertical );
104 GroupButtons->layout()->setSpacing( 0 );
105 GroupButtons->layout()->setMargin( 0 );
106 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
107 GroupButtonsLayout->setAlignment( Qt::AlignTop );
108 GroupButtonsLayout->setSpacing( 6 );
109 GroupButtonsLayout->setMargin( 11 );
110 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
111 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
112 buttonCancel->setAutoDefault( TRUE );
113 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
114 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
115 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
116 buttonApply->setAutoDefault( TRUE );
117 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
118 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
119 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
120 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
121 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
122 buttonOk->setAutoDefault( TRUE );
123 buttonOk->setDefault( TRUE );
124 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
125 GeometryGUI_RotationDlgLayout->addWidget( GroupButtons, 2, 0 );
127 /***************************************************************/
128 GroupC1 = new QGroupBox( this, "GroupC1" );
129 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
130 GroupC1->setFrameShape( QGroupBox::Box );
131 GroupC1->setFrameShadow( QGroupBox::Sunken );
132 GroupC1->setColumnLayout(0, Qt::Vertical );
133 GroupC1->layout()->setSpacing( 0 );
134 GroupC1->layout()->setMargin( 0 );
135 GroupC1Layout = new QGridLayout( GroupC1->layout() );
136 GroupC1Layout->setAlignment( Qt::AlignTop );
137 GroupC1Layout->setSpacing( 6 );
138 GroupC1Layout->setMargin( 11 );
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 );
146 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
147 GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 3 );
148 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
149 GroupC1Layout->addMultiCellWidget( LineEditC1A2, 1, 1, 2, 3 );
150 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
151 SelectButtonC1A1->setText( tr( "" ) );
152 SelectButtonC1A1->setPixmap( image1 );
153 SelectButtonC1A1->setToggleButton( FALSE );
154 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0,
155 SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
156 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
158 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
159 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
160 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
161 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
162 TextLabelC1A1->setFrameShadow( QLabel::Plain );
163 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
164 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
165 TextLabelC1A2->setText( tr( "GEOM_AXIS" ) );
166 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
167 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
169 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
170 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 3 );
172 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
173 TextLabelC1A3->setText( tr( "GEOM_ANGLE" ) );
174 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
175 GroupC1Layout->addWidget( TextLabelC1A3, 2, 2 );
176 CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
177 CheckBoxReverse->setText( tr( "GEOM_REVERSE" ) );
178 GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 1 );
179 GeometryGUI_RotationDlgLayout->addWidget( GroupC1, 1, 0 );
181 Init(Sel) ; /* Initialisations */
184 //=================================================================================
185 // function : ~GeometryGUI_RotationDlg()
186 // purpose : Destroys the object and frees any allocated resources
187 //=================================================================================
188 GeometryGUI_RotationDlg::~GeometryGUI_RotationDlg()
190 // no need to delete child widgets, Qt does it all for us
193 //=================================================================================
196 //=================================================================================
197 void GeometryGUI_RotationDlg::Init( SALOME_Selection* Sel )
200 /* Get setting of step value from file configuration */
202 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
203 step = St.toDouble() ;
205 /* min, max, step and decimals for spin boxes */
206 SpinBox_C1A3->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
207 SpinBox_C1A3->SetValue( 45.0 ) ; /* = myAngle */
211 myConstructorId = 0 ;
212 Constructor1->setChecked( TRUE );
213 myEditCurrentArgument = LineEditC1A1 ;
215 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
216 myOkBase = myOkAxis = false ;
217 mySimulationTopoDs.Nullify() ;
219 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
221 // TODO : set previous selection into argument ?
223 /* Filter definitions */
224 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
225 myGeom = GEOM::GEOM_Gen::_narrow(comp);
226 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
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() ) ) ;
234 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
236 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
237 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
239 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
240 connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseAngle(int) ) ) ;
242 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
243 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
244 /* to close dialog if study change */
245 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
247 /* Move widget on the botton right corner of main widget */
249 myGeomGUI->DefineDlgPosition( this, x, y ) ;
251 this->show() ; /* displays Dialog */
256 //=================================================================================
257 // function : ReverseAngle()
258 // purpose : 'state' not used here
259 //=================================================================================
260 void GeometryGUI_RotationDlg::ReverseAngle(int state)
263 SpinBox_C1A3->SetValue( myAngle ) ;
264 if( myOkBase && myOkAxis ) {
265 MakeRotationSimulationAndDisplay( myBase ) ;
268 myGeomGUI->EraseSimulationShape() ;
269 mySimulationTopoDs.Nullify() ;
275 //=================================================================================
276 // function : ConstructorsClicked()
277 // purpose : Radio button management
278 //=================================================================================
279 void GeometryGUI_RotationDlg::ConstructorsClicked(int constructorId)
281 /* only a constructor now */
285 //=================================================================================
286 // function : ClickOnOk()
288 //=================================================================================
289 void GeometryGUI_RotationDlg::ClickOnOk()
291 this->ClickOnApply() ;
292 this->ClickOnCancel() ;
296 //=================================================================================
297 // function : ClickOnApply()
299 //=================================================================================
300 void GeometryGUI_RotationDlg::ClickOnApply()
302 myGeomGUI->EraseSimulationShape() ;
303 mySimulationTopoDs.Nullify() ;
304 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
306 switch(myConstructorId)
310 if(myOkBase && myOkAxis) {
311 myGeomGUI->MakeRotationAndDisplay( myGeomShape, myLoc, myDir, myAngle*PI180) ;
320 //=================================================================================
321 // function : ClickOnCancel()
323 //=================================================================================
324 void GeometryGUI_RotationDlg::ClickOnCancel()
326 mySelection->ClearFilters() ;
327 myGeomGUI->EraseSimulationShape() ;
328 mySimulationTopoDs.Nullify() ;
329 disconnect( mySelection, 0, this, 0 );
330 myGeomGUI->ResetState() ;
336 //=================================================================================
337 // function : SelectionIntoArgument()
338 // purpose : Called when selection as changed or other case
339 //=================================================================================
340 void GeometryGUI_RotationDlg::SelectionIntoArgument()
342 myGeomGUI->EraseSimulationShape() ;
343 mySimulationTopoDs.Nullify() ;
345 QString aString = ""; /* name of future selection */
347 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
349 if ( myEditCurrentArgument == LineEditC1A1 ) {
350 LineEditC1A1->setText("") ;
353 else if ( myEditCurrentArgument == LineEditC1A2 ) {
354 LineEditC1A2->setText("") ;
362 Standard_Boolean testResult ;
363 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
365 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
368 if ( myEditCurrentArgument == LineEditC1A1 ) {
369 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
372 LineEditC1A1->setText(aString) ;
376 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, myLoc, myDir) */) {
377 BRepAdaptor_Curve curv(TopoDS::Edge(S));
378 myDir = curv.Line().Direction();
379 myLoc = curv.Line().Location();
380 LineEditC1A2->setText(aString) ;
384 if( myOkBase && myOkAxis ) {
385 MakeRotationSimulationAndDisplay( myBase) ;
391 //=================================================================================
392 // function : SetEditCurrentArgument()
394 //=================================================================================
395 void GeometryGUI_RotationDlg::SetEditCurrentArgument()
397 QPushButton* send = (QPushButton*)sender();
398 switch (myConstructorId)
400 case 0: /* default constructor */
402 if(send == SelectButtonC1A1) {
403 LineEditC1A1->setFocus() ;
404 myEditCurrentArgument = LineEditC1A1;
405 mySelection->ClearFilters() ;
407 else if(send == SelectButtonC1A2) {
408 LineEditC1A2->setFocus() ;
409 myEditCurrentArgument = LineEditC1A2;
410 mySelection->AddFilter(myEdgeFilter) ;
412 SelectionIntoArgument() ;
420 //=================================================================================
421 // function : LineEditReturnPressed()
423 //=================================================================================
424 void GeometryGUI_RotationDlg::LineEditReturnPressed()
426 QLineEdit* send = (QLineEdit*)sender();
427 if( send == LineEditC1A1 )
428 myEditCurrentArgument = LineEditC1A1 ;
429 else if ( send == LineEditC1A2 )
430 myEditCurrentArgument = LineEditC1A2 ;
434 /* User name of object input management */
435 /* If successfull the selection is changed and signal emitted... */
436 /* so SelectionIntoArgument() is automatically called. */
437 const QString objectUserName = myEditCurrentArgument->text() ;
438 QWidget* thisWidget = (QWidget*)this ;
439 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
440 myEditCurrentArgument->setText( objectUserName ) ;
446 //=================================================================================
447 // function : ValueChangedInSpinBox()
449 //=================================================================================
450 void GeometryGUI_RotationDlg::ValueChangedInSpinBox( double newValue )
453 if (myOkBase && myOkAxis) {
454 MakeRotationSimulationAndDisplay(myBase) ;
457 myGeomGUI->EraseSimulationShape() ;
458 mySimulationTopoDs.Nullify() ;
464 //=================================================================================
465 // function : DeactivateActiveDialog()
467 //=================================================================================
468 void GeometryGUI_RotationDlg::DeactivateActiveDialog()
470 if ( GroupConstructors->isEnabled() ) {
471 GroupConstructors->setEnabled(false) ;
472 GroupC1->setEnabled(false) ;
473 GroupButtons->setEnabled(false) ;
474 disconnect( mySelection, 0, this, 0 );
475 myGeomGUI->EraseSimulationShape() ;
476 mySelection->ClearFilters() ;
482 //=================================================================================
483 // function : ActivateThisDialog()
485 //=================================================================================
486 void GeometryGUI_RotationDlg::ActivateThisDialog()
488 /* Emit a signal to deactivate the active dialog */
489 myGeomGUI->EmitSignalDeactivateDialog() ;
490 GroupConstructors->setEnabled(true) ;
491 GroupC1->setEnabled(true) ;
492 GroupButtons->setEnabled(true) ;
493 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
494 if( !mySimulationTopoDs.IsNull() )
495 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
501 //=================================================================================
502 // function : enterEvent()
504 //=================================================================================
505 void GeometryGUI_RotationDlg::enterEvent(QEvent* e)
507 if ( GroupConstructors->isEnabled() )
509 ActivateThisDialog() ;
514 //=================================================================================
515 // function : closeEvent()
517 //=================================================================================
518 void GeometryGUI_RotationDlg::closeEvent( QCloseEvent* e )
520 this->ClickOnCancel() ; /* same than click on cancel button */
524 //=================================================================================
525 // function : MakeRotationSimulationAndDisplay()
527 //=================================================================================
528 void GeometryGUI_RotationDlg::MakeRotationSimulationAndDisplay( const TopoDS_Shape& S)
530 myGeomGUI->EraseSimulationShape() ;
536 gp_Ax1 AX( this->myLoc, this->myDir ) ;
537 gp_Trsf theTransformation ;
538 theTransformation.SetRotation(AX, this->myAngle*PI180 ) ;
539 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False) ;
540 this->mySimulationTopoDs = myBRepTransformation.Shape() ;
541 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
543 catch(Standard_Failure) {
544 MESSAGE( "Exception catched in MakeRotationSimulationAndDisplay" ) ;