2 // File : GeometryGUI_TranslationDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_TranslationDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Config.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 #include <qbuttongroup.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
29 #include <qvalidator.h>
35 //=================================================================================
36 // class : GeometryGUI_TranslationDlg()
37 // purpose : Constructs a GeometryGUI_TranslationDlg 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_TranslationDlg::GeometryGUI_TranslationDlg( 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_TRANSLATION")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
49 setName( "GeometryGUI_TranslationDlg" );
51 setCaption( tr( "GEOM_TRANSLATION_TITLE" ) );
52 setSizeGripEnabled( TRUE );
53 GeometryGUI_TranslationDlgLayout = new QGridLayout( this );
54 GeometryGUI_TranslationDlgLayout->setSpacing( 6 );
55 GeometryGUI_TranslationDlgLayout->setMargin( 11 );
57 /***************************************************************/
58 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
59 GroupConstructors->setTitle( tr( "GEOM_TRANSLATION" ) );
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_TranslationDlgLayout->addWidget( GroupConstructors, 0, 0 );
79 GroupC1 = new QGroupBox( this, "GroupC1" );
80 GroupC1->setTitle( tr( "GEOM_TRANSLATION" ) ) ;
81 GroupC1->setMinimumSize( QSize( 0, 0 ) );
82 GroupC1->setFrameShape( QGroupBox::Box );
83 GroupC1->setFrameShadow( QGroupBox::Sunken );
84 GroupC1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)5, GroupC1->sizePolicy().hasHeightForWidth() ) );
85 GroupC1->setColumnLayout(0, Qt::Vertical );
86 GroupC1->layout()->setSpacing( 0 );
87 GroupC1->layout()->setMargin( 0 );
88 GroupC1Layout = new QGridLayout( GroupC1->layout() );
89 GroupC1Layout->setAlignment( Qt::AlignTop );
90 GroupC1Layout->setSpacing( 6 );
91 GroupC1Layout->setMargin( 11 );
93 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
94 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
95 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
96 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
97 TextLabelC1A1->setFrameShadow( QLabel::Plain );
98 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
100 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
101 SelectButtonC1A1->setText( tr( "" ) );
102 SelectButtonC1A1->setPixmap( image1 );
103 SelectButtonC1A1->setToggleButton( FALSE );
104 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
105 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
107 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
108 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
110 Layout1 = new QHBoxLayout;
111 Layout1->setSpacing( 6 );
112 Layout1->setMargin( 0 );
114 TextLabel_DX = new QLabel( GroupC1, "TextLabel_DX" );
115 TextLabel_DX->setText( tr( "GEOM_DX" ) );
116 Layout1->addWidget( TextLabel_DX );
118 SpinBox_DX = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DX" );
119 SpinBox_DX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DX->sizePolicy().hasHeightForWidth() ) );
120 Layout1->addWidget( SpinBox_DX );
122 TextLabel_DY = new QLabel( GroupC1, "TextLabel_DY" );
123 TextLabel_DY->setText( tr( "GEOM_DY" ) );
124 Layout1->addWidget( TextLabel_DY );
126 SpinBox_DY = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DY" );
127 SpinBox_DY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DY->sizePolicy().hasHeightForWidth() ) );
128 Layout1->addWidget( SpinBox_DY );
130 TextLabel_DZ = new QLabel( GroupC1, "TextLabel_DZ" );
131 TextLabel_DZ->setText( tr( "GEOM_DZ" ) );
132 Layout1->addWidget( TextLabel_DZ );
134 SpinBox_DZ = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DZ" );
135 SpinBox_DZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DZ->sizePolicy().hasHeightForWidth() ) );
136 Layout1->addWidget( SpinBox_DZ );
138 GroupC1Layout->addMultiCellLayout( Layout1, 1, 1, 0, 2 );
140 GeometryGUI_TranslationDlgLayout->addWidget( GroupC1, 1, 0 );
143 /***************************************************************/
144 GroupButtons = new QGroupBox( this, "GroupButtons" );
145 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
146 GroupButtons->setTitle( tr( "" ) );
147 GroupButtons->setColumnLayout(0, Qt::Vertical );
148 GroupButtons->layout()->setSpacing( 0 );
149 GroupButtons->layout()->setMargin( 0 );
150 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
151 GroupButtonsLayout->setAlignment( Qt::AlignTop );
152 GroupButtonsLayout->setSpacing( 6 );
153 GroupButtonsLayout->setMargin( 11 );
154 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
155 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
156 buttonCancel->setAutoDefault( TRUE );
157 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
158 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
159 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
160 buttonApply->setAutoDefault( TRUE );
161 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
162 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
163 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
164 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
165 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
166 buttonOk->setAutoDefault( TRUE );
167 buttonOk->setDefault( TRUE );
168 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
169 GeometryGUI_TranslationDlgLayout->addWidget( GroupButtons, 2, 0 );
170 /***************************************************************/
172 Init(Sel) ; /* Initialisations */
177 //=================================================================================
178 // function : ~GeometryGUI_TranslationDlg()
179 // purpose : Destroys the object and frees any allocated resources
180 //=================================================================================
181 GeometryGUI_TranslationDlg::~GeometryGUI_TranslationDlg()
183 // no need to delete child widgets, Qt does it all for us
187 //=================================================================================
190 //=================================================================================
191 void GeometryGUI_TranslationDlg::Init( SALOME_Selection* Sel )
194 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
195 step = St.toDouble() ;
197 /* min, max, step and decimals for spin boxes */
198 SpinBox_DX->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
199 SpinBox_DX->SetValue( 100.0 ) ;
200 SpinBox_DY->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
201 SpinBox_DY->SetValue( 100.0 ) ;
202 SpinBox_DZ->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
203 SpinBox_DZ->SetValue( 100.0 ) ;
206 myConstructorId = 0 ;
207 Constructor1->setChecked( TRUE );
208 myEditCurrentArgument = LineEditC1A1 ;
210 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
213 this->myVec.SetCoord( 100.0, 100.0, 100.0 ) ;
214 mySimulationTopoDs.Nullify() ;
216 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
218 // TODO : previous selection into argument ?
220 /* Filter definitions */
221 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
222 myGeom = GEOM::GEOM_Gen::_narrow(comp);
223 // myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
225 /* signals and slots connections */
226 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
227 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
228 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
229 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
230 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
232 connect( SpinBox_DX, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
233 connect( SpinBox_DY, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
234 connect( SpinBox_DZ, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
236 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
238 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
239 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
240 /* to close dialog if study change */
241 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
243 /* Move widget on the botton right corner of main widget */
245 myGeomGUI->DefineDlgPosition( this, x, y ) ;
247 this->show() ; /* displays Dialog */
253 //=================================================================================
254 // function : ConstructorsClicked()
255 // purpose : Radio button management
256 //=================================================================================
257 void GeometryGUI_TranslationDlg::ConstructorsClicked(int constructorId)
259 // myGeomGUI->EraseSimulationShape() ;
260 switch (constructorId)
274 //=================================================================================
275 // function : ClickOnOk()
277 //=================================================================================
278 void GeometryGUI_TranslationDlg::ClickOnOk()
280 this->ClickOnApply() ;
281 this->ClickOnCancel() ;
286 //=================================================================================
287 // function : ClickOnApply()
289 //=================================================================================
290 void GeometryGUI_TranslationDlg::ClickOnApply()
292 myGeomGUI->EraseSimulationShape() ;
293 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
294 mySimulationTopoDs.Nullify() ;
295 switch(myConstructorId)
300 myGeomGUI->MakeTranslationAndDisplay( myGeomShape, myVec ) ;
314 //=================================================================================
315 // function : ClickOnCancel()
317 //=================================================================================
318 void GeometryGUI_TranslationDlg::ClickOnCancel()
320 mySelection->ClearFilters() ;
321 myGeomGUI->EraseSimulationShape() ;
322 mySimulationTopoDs.Nullify() ;
323 disconnect( mySelection, 0, this, 0 );
324 myGeomGUI->ResetState() ;
330 //=================================================================================
331 // function : SelectionIntoArgument()
332 // purpose : Called when selection as changed or other case
333 //=================================================================================
334 void GeometryGUI_TranslationDlg::SelectionIntoArgument()
336 myEditCurrentArgument->setText("") ;
337 myGeomGUI->EraseSimulationShape() ;
338 mySimulationTopoDs.Nullify() ;
340 /* Future name of selection */
341 QString aString = "";
343 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
345 if ( myEditCurrentArgument == LineEditC1A1 ) {
346 LineEditC1A1->setText("") ;
354 Standard_Boolean testResult ;
355 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
357 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
360 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 ) {
361 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
364 LineEditC1A1->setText(aString) ;
370 MakeTranslationSimulationAndDisplay() ;
376 //=================================================================================
377 // function : SetEditCurrentArgument()
379 //=================================================================================
380 void GeometryGUI_TranslationDlg::SetEditCurrentArgument()
382 QPushButton* send = (QPushButton*)sender();
383 switch (myConstructorId)
385 case 0: /* default constructor */
387 if(send == SelectButtonC1A1) {
388 LineEditC1A1->setFocus() ;
389 myEditCurrentArgument = LineEditC1A1 ;
390 SelectionIntoArgument() ;
402 //=================================================================================
403 // function : LineEditReturnPressed()
405 //=================================================================================
406 void GeometryGUI_TranslationDlg::LineEditReturnPressed()
408 QLineEdit* send = (QLineEdit*)sender();
409 if( send == LineEditC1A1 )
410 myEditCurrentArgument = LineEditC1A1 ;
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 ) ;
427 //=================================================================================
428 // function : ValueChangedInSpinBox()
430 //=================================================================================
431 void GeometryGUI_TranslationDlg::ValueChangedInSpinBox( double newValue )
434 QObject* send = (QObject*)sender() ;
435 Standard_Real Dx, Dy, Dz ;
437 if( send == SpinBox_DX ) {
439 Dy = SpinBox_DY->GetValue() ;
440 Dz = SpinBox_DZ->GetValue() ;
441 } else if( send == SpinBox_DY ) {
442 Dx = SpinBox_DX->GetValue() ;
444 Dz = SpinBox_DZ->GetValue() ;
445 } else if( send == SpinBox_DZ ) {
446 Dx = SpinBox_DX->GetValue() ;
447 Dy = SpinBox_DY->GetValue() ;
451 this->myVec.SetCoord(Dx, Dy, Dz) ;
453 MakeTranslationSimulationAndDisplay() ;
456 myGeomGUI->EraseSimulationShape() ;
457 mySimulationTopoDs.Nullify() ;
464 //=================================================================================
465 // function : DeactivateActiveDialog()
467 //=================================================================================
468 void GeometryGUI_TranslationDlg::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_TranslationDlg::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) ;
494 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
495 if( !mySimulationTopoDs.IsNull() )
496 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
502 //=================================================================================
503 // function : enterEvent()
505 //=================================================================================
506 void GeometryGUI_TranslationDlg::enterEvent(QEvent* e)
508 if ( GroupConstructors->isEnabled() )
510 ActivateThisDialog() ;
515 //=================================================================================
516 // function : closeEvent()
518 //=================================================================================
519 void GeometryGUI_TranslationDlg::closeEvent( QCloseEvent* e )
521 /* same than click on cancel button */
522 this->ClickOnCancel() ;
527 //=================================================================================
528 // function : MakeTranslationSimulationAndDisplay()
530 //=================================================================================
531 void GeometryGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
533 myGeomGUI->EraseSimulationShape() ;
534 mySimulationTopoDs.Nullify() ;
536 gp_Trsf theTransformation ;
537 theTransformation.SetTranslation(this->myVec) ;
539 BRepBuilderAPI_Transform myBRepTransformation(this->myBase, theTransformation, Standard_False) ;
540 mySimulationTopoDs = myBRepTransformation.Shape() ;
541 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;