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_TranslationDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_TranslationDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Config.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
49 #include <qvalidator.h>
55 //=================================================================================
56 // class : GeometryGUI_TranslationDlg()
57 // purpose : Constructs a GeometryGUI_TranslationDlg 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_TranslationDlg::GeometryGUI_TranslationDlg( 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_TRANSLATION")));
66 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
69 setName( "GeometryGUI_TranslationDlg" );
71 setCaption( tr( "GEOM_TRANSLATION_TITLE" ) );
72 setSizeGripEnabled( TRUE );
73 GeometryGUI_TranslationDlgLayout = new QGridLayout( this );
74 GeometryGUI_TranslationDlgLayout->setSpacing( 6 );
75 GeometryGUI_TranslationDlgLayout->setMargin( 11 );
77 /***************************************************************/
78 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
79 GroupConstructors->setTitle( tr( "GEOM_TRANSLATION" ) );
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_TranslationDlgLayout->addWidget( GroupConstructors, 0, 0 );
99 GroupC1 = new QGroupBox( this, "GroupC1" );
100 GroupC1->setTitle( tr( "GEOM_TRANSLATION" ) ) ;
101 GroupC1->setMinimumSize( QSize( 0, 0 ) );
102 GroupC1->setFrameShape( QGroupBox::Box );
103 GroupC1->setFrameShadow( QGroupBox::Sunken );
104 GroupC1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)5, GroupC1->sizePolicy().hasHeightForWidth() ) );
105 GroupC1->setColumnLayout(0, Qt::Vertical );
106 GroupC1->layout()->setSpacing( 0 );
107 GroupC1->layout()->setMargin( 0 );
108 GroupC1Layout = new QGridLayout( GroupC1->layout() );
109 GroupC1Layout->setAlignment( Qt::AlignTop );
110 GroupC1Layout->setSpacing( 6 );
111 GroupC1Layout->setMargin( 11 );
113 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
114 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
115 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
116 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
117 TextLabelC1A1->setFrameShadow( QLabel::Plain );
118 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
120 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
121 SelectButtonC1A1->setText( tr( "" ) );
122 SelectButtonC1A1->setPixmap( image1 );
123 SelectButtonC1A1->setToggleButton( FALSE );
124 SelectButtonC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, SelectButtonC1A1->sizePolicy().hasHeightForWidth() ) );
125 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
127 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
128 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
130 Layout1 = new QHBoxLayout;
131 Layout1->setSpacing( 6 );
132 Layout1->setMargin( 0 );
134 TextLabel_DX = new QLabel( GroupC1, "TextLabel_DX" );
135 TextLabel_DX->setText( tr( "GEOM_DX" ) );
136 Layout1->addWidget( TextLabel_DX );
138 SpinBox_DX = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DX" );
139 SpinBox_DX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DX->sizePolicy().hasHeightForWidth() ) );
140 Layout1->addWidget( SpinBox_DX );
142 TextLabel_DY = new QLabel( GroupC1, "TextLabel_DY" );
143 TextLabel_DY->setText( tr( "GEOM_DY" ) );
144 Layout1->addWidget( TextLabel_DY );
146 SpinBox_DY = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DY" );
147 SpinBox_DY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DY->sizePolicy().hasHeightForWidth() ) );
148 Layout1->addWidget( SpinBox_DY );
150 TextLabel_DZ = new QLabel( GroupC1, "TextLabel_DZ" );
151 TextLabel_DZ->setText( tr( "GEOM_DZ" ) );
152 Layout1->addWidget( TextLabel_DZ );
154 SpinBox_DZ = new GeometryGUI_SpinBox( GroupC1, "SpinBox_DZ" );
155 SpinBox_DZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_DZ->sizePolicy().hasHeightForWidth() ) );
156 Layout1->addWidget( SpinBox_DZ );
158 GroupC1Layout->addMultiCellLayout( Layout1, 1, 1, 0, 2 );
160 GeometryGUI_TranslationDlgLayout->addWidget( GroupC1, 1, 0 );
163 /***************************************************************/
164 GroupButtons = new QGroupBox( this, "GroupButtons" );
165 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
166 GroupButtons->setTitle( tr( "" ) );
167 GroupButtons->setColumnLayout(0, Qt::Vertical );
168 GroupButtons->layout()->setSpacing( 0 );
169 GroupButtons->layout()->setMargin( 0 );
170 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
171 GroupButtonsLayout->setAlignment( Qt::AlignTop );
172 GroupButtonsLayout->setSpacing( 6 );
173 GroupButtonsLayout->setMargin( 11 );
174 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
175 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
176 buttonCancel->setAutoDefault( TRUE );
177 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
178 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
179 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
180 buttonApply->setAutoDefault( TRUE );
181 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
182 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
183 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
184 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
185 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
186 buttonOk->setAutoDefault( TRUE );
187 buttonOk->setDefault( TRUE );
188 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
189 GeometryGUI_TranslationDlgLayout->addWidget( GroupButtons, 2, 0 );
190 /***************************************************************/
192 Init(Sel) ; /* Initialisations */
197 //=================================================================================
198 // function : ~GeometryGUI_TranslationDlg()
199 // purpose : Destroys the object and frees any allocated resources
200 //=================================================================================
201 GeometryGUI_TranslationDlg::~GeometryGUI_TranslationDlg()
203 // no need to delete child widgets, Qt does it all for us
207 //=================================================================================
210 //=================================================================================
211 void GeometryGUI_TranslationDlg::Init( SALOME_Selection* Sel )
214 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
215 step = St.toDouble() ;
217 /* min, max, step and decimals for spin boxes */
218 SpinBox_DX->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
219 SpinBox_DX->SetValue( 100.0 ) ;
220 SpinBox_DY->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
221 SpinBox_DY->SetValue( 100.0 ) ;
222 SpinBox_DZ->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
223 SpinBox_DZ->SetValue( 100.0 ) ;
226 myConstructorId = 0 ;
227 Constructor1->setChecked( TRUE );
228 myEditCurrentArgument = LineEditC1A1 ;
230 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
233 this->myVec.SetCoord( 100.0, 100.0, 100.0 ) ;
234 mySimulationTopoDs.Nullify() ;
236 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
238 // TODO : previous selection into argument ?
240 /* Filter definitions */
241 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
242 myGeom = GEOM::GEOM_Gen::_narrow(comp);
243 // myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
245 /* signals and slots connections */
246 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
247 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
248 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
249 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
250 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
252 connect( SpinBox_DX, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
253 connect( SpinBox_DY, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
254 connect( SpinBox_DZ, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
256 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
258 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
259 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
260 /* to close dialog if study change */
261 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
263 /* Move widget on the botton right corner of main widget */
265 myGeomGUI->DefineDlgPosition( this, x, y ) ;
267 this->show() ; /* displays Dialog */
273 //=================================================================================
274 // function : ConstructorsClicked()
275 // purpose : Radio button management
276 //=================================================================================
277 void GeometryGUI_TranslationDlg::ConstructorsClicked(int constructorId)
279 // myGeomGUI->EraseSimulationShape() ;
280 switch (constructorId)
294 //=================================================================================
295 // function : ClickOnOk()
297 //=================================================================================
298 void GeometryGUI_TranslationDlg::ClickOnOk()
300 this->ClickOnApply() ;
301 this->ClickOnCancel() ;
306 //=================================================================================
307 // function : ClickOnApply()
309 //=================================================================================
310 void GeometryGUI_TranslationDlg::ClickOnApply()
312 myGeomGUI->EraseSimulationShape() ;
313 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
314 mySimulationTopoDs.Nullify() ;
315 switch(myConstructorId)
320 myGeomGUI->MakeTranslationAndDisplay( myGeomShape, myVec ) ;
334 //=================================================================================
335 // function : ClickOnCancel()
337 //=================================================================================
338 void GeometryGUI_TranslationDlg::ClickOnCancel()
340 mySelection->ClearFilters() ;
341 myGeomGUI->EraseSimulationShape() ;
342 mySimulationTopoDs.Nullify() ;
343 disconnect( mySelection, 0, this, 0 );
344 myGeomGUI->ResetState() ;
350 //=================================================================================
351 // function : SelectionIntoArgument()
352 // purpose : Called when selection as changed or other case
353 //=================================================================================
354 void GeometryGUI_TranslationDlg::SelectionIntoArgument()
356 myEditCurrentArgument->setText("") ;
357 myGeomGUI->EraseSimulationShape() ;
358 mySimulationTopoDs.Nullify() ;
360 /* Future name of selection */
361 QString aString = "";
363 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
365 if ( myEditCurrentArgument == LineEditC1A1 ) {
366 LineEditC1A1->setText("") ;
374 Standard_Boolean testResult ;
375 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
377 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
380 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 ) {
381 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
384 LineEditC1A1->setText(aString) ;
390 MakeTranslationSimulationAndDisplay() ;
396 //=================================================================================
397 // function : SetEditCurrentArgument()
399 //=================================================================================
400 void GeometryGUI_TranslationDlg::SetEditCurrentArgument()
402 QPushButton* send = (QPushButton*)sender();
403 switch (myConstructorId)
405 case 0: /* default constructor */
407 if(send == SelectButtonC1A1) {
408 LineEditC1A1->setFocus() ;
409 myEditCurrentArgument = LineEditC1A1 ;
410 SelectionIntoArgument() ;
422 //=================================================================================
423 // function : LineEditReturnPressed()
425 //=================================================================================
426 void GeometryGUI_TranslationDlg::LineEditReturnPressed()
428 QLineEdit* send = (QLineEdit*)sender();
429 if( send == LineEditC1A1 )
430 myEditCurrentArgument = LineEditC1A1 ;
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 ) ;
447 //=================================================================================
448 // function : ValueChangedInSpinBox()
450 //=================================================================================
451 void GeometryGUI_TranslationDlg::ValueChangedInSpinBox( double newValue )
454 QObject* send = (QObject*)sender() ;
455 Standard_Real Dx, Dy, Dz ;
457 if( send == SpinBox_DX ) {
459 Dy = SpinBox_DY->GetValue() ;
460 Dz = SpinBox_DZ->GetValue() ;
461 } else if( send == SpinBox_DY ) {
462 Dx = SpinBox_DX->GetValue() ;
464 Dz = SpinBox_DZ->GetValue() ;
465 } else if( send == SpinBox_DZ ) {
466 Dx = SpinBox_DX->GetValue() ;
467 Dy = SpinBox_DY->GetValue() ;
471 this->myVec.SetCoord(Dx, Dy, Dz) ;
473 MakeTranslationSimulationAndDisplay() ;
476 myGeomGUI->EraseSimulationShape() ;
477 mySimulationTopoDs.Nullify() ;
484 //=================================================================================
485 // function : DeactivateActiveDialog()
487 //=================================================================================
488 void GeometryGUI_TranslationDlg::DeactivateActiveDialog()
490 if ( GroupConstructors->isEnabled() ) {
491 GroupConstructors->setEnabled(false) ;
492 GroupC1->setEnabled(false) ;
493 GroupButtons->setEnabled(false) ;
494 disconnect( mySelection, 0, this, 0 );
495 myGeomGUI->EraseSimulationShape() ;
496 mySelection->ClearFilters() ;
502 //=================================================================================
503 // function : ActivateThisDialog()
505 //=================================================================================
506 void GeometryGUI_TranslationDlg::ActivateThisDialog()
508 /* Emit a signal to deactivate the active dialog */
509 myGeomGUI->EmitSignalDeactivateDialog() ;
510 GroupConstructors->setEnabled(true) ;
511 GroupC1->setEnabled(true) ;
512 GroupButtons->setEnabled(true) ;
514 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
515 if( !mySimulationTopoDs.IsNull() )
516 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
522 //=================================================================================
523 // function : enterEvent()
525 //=================================================================================
526 void GeometryGUI_TranslationDlg::enterEvent(QEvent* e)
528 if ( GroupConstructors->isEnabled() )
530 ActivateThisDialog() ;
535 //=================================================================================
536 // function : closeEvent()
538 //=================================================================================
539 void GeometryGUI_TranslationDlg::closeEvent( QCloseEvent* e )
541 /* same than click on cancel button */
542 this->ClickOnCancel() ;
547 //=================================================================================
548 // function : MakeTranslationSimulationAndDisplay()
550 //=================================================================================
551 void GeometryGUI_TranslationDlg::MakeTranslationSimulationAndDisplay()
553 myGeomGUI->EraseSimulationShape() ;
554 mySimulationTopoDs.Nullify() ;
556 gp_Trsf theTransformation ;
557 theTransformation.SetTranslation(this->myVec) ;
559 BRepBuilderAPI_Transform myBRepTransformation(this->myBase, theTransformation, Standard_False) ;
560 mySimulationTopoDs = myBRepTransformation.Shape() ;
561 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;