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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : TransformationGUI_MultiTranslationDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "TransformationGUI_MultiTranslationDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : TransformationGUI_MultiTranslationDlg()
41 // purpose : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
47 ( GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
51 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTITRANSLATION_SIMPLE" ) ) );
52 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTITRANSLATION_DOUBLE" ) ) );
53 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_MULTITRANSLATION_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MULTITRANSLATION" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setIcon( image1 );
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_2Sel2Spin1Check( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_MULTITRANSLATION_SIMPLE" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR_U" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_STEP_U" ) );
69 GroupPoints->TextLabel4->setText( tr( "GEOM_NB_TIMES_U" ) );
70 GroupPoints->CheckButton1->setText( tr( "GEOM_REVERSE_U" ) );
71 GroupPoints->PushButton1->setIcon( image2 );
72 GroupPoints->PushButton2->setIcon( image2 );
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 GroupDimensions = new DlgRef_3Sel4Spin2Check( centralWidget() );
77 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_MULTITRANSLATION_DOUBLE" ) );
78 GroupDimensions->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
79 GroupDimensions->TextLabel2->setText( tr( "GEOM_VECTOR_U" ) );
80 GroupDimensions->TextLabel3->setText( tr( "GEOM_VECTOR_V" ) );
81 GroupDimensions->TextLabel4->setText( tr( "GEOM_STEP_U" ) );
82 GroupDimensions->TextLabel5->setText( tr( "GEOM_NB_TIMES_U" ) );
83 GroupDimensions->TextLabel6->setText( tr( "GEOM_STEP_V" ) );
84 GroupDimensions->TextLabel7->setText( tr( "GEOM_NB_TIMES_V" ) );
85 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE_U" ) );
86 GroupDimensions->CheckButton2->setText( tr( "GEOM_REVERSE_V" ) );
87 GroupDimensions->PushButton1->setIcon( image2 );
88 GroupDimensions->PushButton2->setIcon( image2 );
89 GroupDimensions->PushButton3->setIcon( image2 );
90 GroupDimensions->LineEdit1->setReadOnly( true );
91 GroupDimensions->LineEdit2->setReadOnly( true );
92 GroupDimensions->LineEdit3->setReadOnly( true );
94 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
95 layout->setMargin( 0 ); layout->setSpacing( 6 );
96 layout->addWidget( GroupPoints );
97 layout->addWidget( GroupDimensions );
98 /***************************************************************/
100 setHelpFileName( "multi_translation.htm" );
106 //=================================================================================
107 // function : ~TransformationGUI_MultiTranslationDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
112 // no need to delete child widgets, Qt does it all for us
116 //=================================================================================
119 //=================================================================================
120 void TransformationGUI_MultiTranslationDlg::Init()
122 /* Get setting of step value from file configuration */
123 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
124 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
126 double SpecificStep = 1;
127 /* min, max, step and decimals for spin boxes & initial values */
128 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
129 initSpinBox( GroupPoints->SpinBox_DY, 1.0, MAX_NUMBER, SpecificStep, 3 );
130 GroupPoints->SpinBox_DX->setValue( myStepU );
131 GroupPoints->SpinBox_DY->setValue( myNbTimesU );
133 initSpinBox( GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, 3 );
134 initSpinBox( GroupDimensions->SpinBox_DY1, 1.0, MAX_NUMBER, SpecificStep, 3 );
135 initSpinBox( GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 3 );
136 initSpinBox( GroupDimensions->SpinBox_DY2, 1.0, MAX_NUMBER, SpecificStep, 3 );
137 GroupDimensions->SpinBox_DX1->setValue( myStepU );
138 GroupDimensions->SpinBox_DY1->setValue( myNbTimesU );
139 GroupDimensions->SpinBox_DX2->setValue( myStepV );
140 GroupDimensions->SpinBox_DY2->setValue( myNbTimesV );
142 /* signals and slots connections */
143 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
144 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
146 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
148 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
149 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
150 connect( GroupDimensions->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151 connect( GroupDimensions->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152 connect( GroupDimensions->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156 connect( GroupDimensions->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
157 connect( GroupDimensions->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( GroupDimensions->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
160 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
161 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
162 connect( GroupDimensions->SpinBox_DX1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
163 connect( GroupDimensions->SpinBox_DY1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
164 connect( GroupDimensions->SpinBox_DX2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
165 connect( GroupDimensions->SpinBox_DY2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
169 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DY, SLOT( SetStep( double ) ) );
170 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX1, SLOT( SetStep( double ) ) );
171 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY1, SLOT( SetStep( double ) ) );
172 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX2, SLOT( SetStep( double ) ) );
173 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY2, SLOT( SetStep( double ) ) );
176 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseStepU() ) );
177 connect( GroupDimensions->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseStepU() ) );
178 connect( GroupDimensions->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( ReverseStepV() ) );
180 connect( myGeomGUI->getApp()->selectionMgr(),
181 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
184 initName( tr( "GEOM_MULTITRANSLATION" ) );
186 ConstructorsClicked( 0 );
190 //=================================================================================
191 // function : ConstructorsClicked()
192 // purpose : Radio button management
193 //=================================================================================
194 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked( int constructorId )
196 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
198 myStepU = myStepV = 50.0;
199 myNbTimesU = myNbTimesV = 2;
201 globalSelection( GEOM_ALLSHAPES );
203 switch ( constructorId ) {
204 case 0: /* Translate simple */
206 GroupDimensions->hide();
209 myEditCurrentArgument = GroupPoints->LineEdit1;
210 GroupPoints->LineEdit1->setText( "" );
211 GroupPoints->LineEdit2->setText( "" );
213 GroupPoints->SpinBox_DX->setValue( myStepU );
214 GroupPoints->SpinBox_DY->setValue( myNbTimesU );
218 case 1: /* Translate double */
221 GroupDimensions->show();
223 myEditCurrentArgument = GroupDimensions->LineEdit1;
224 GroupDimensions->LineEdit1->setText( "" );
225 GroupDimensions->LineEdit2->setText( "" );
226 GroupDimensions->LineEdit3->setText( "" );
228 GroupDimensions->SpinBox_DX1->setValue( myStepU );
229 GroupDimensions->SpinBox_DY1->setValue( myNbTimesU );
230 GroupDimensions->SpinBox_DX2->setValue( myStepV );
231 GroupDimensions->SpinBox_DY2->setValue( myNbTimesV );
233 myVectorV = GEOM::GEOM_Object::_nil();
238 qApp->processEvents();
240 resize( minimumSize() );
242 myEditCurrentArgument->setFocus();
243 myBase = myVectorU = GEOM::GEOM_Object::_nil();
244 connect( myGeomGUI->getApp()->selectionMgr(),
245 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
249 //=================================================================================
250 // function : ClickOnOk()
252 //=================================================================================
253 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
255 if ( ClickOnApply() )
260 //=================================================================================
261 // function : ClickOnApply()
263 //=================================================================================
264 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
270 ConstructorsClicked( getConstructorId() );
275 //=================================================================================
276 // function : SelectionIntoArgument()
277 // purpose : Called when selection as changed or other case
278 //=================================================================================
279 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
281 myEditCurrentArgument->setText( "" );
283 if ( IObjectCount() != 1 ) {
284 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
285 myEditCurrentArgument == GroupDimensions->LineEdit1 )
286 myBase = GEOM::GEOM_Object::_nil();
287 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
288 myEditCurrentArgument == GroupDimensions->LineEdit2 )
289 myVectorU = GEOM::GEOM_Object::_nil();
290 else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
291 myVectorV = GEOM::GEOM_Object::_nil();
296 Standard_Boolean testResult = Standard_False;;
297 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
299 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
302 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
303 myEditCurrentArgument == GroupDimensions->LineEdit1 )
304 myBase = aSelectedObject;
305 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
306 myEditCurrentArgument == GroupDimensions->LineEdit2 )
307 myVectorU = aSelectedObject;
308 else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
309 myVectorV = aSelectedObject;
311 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
317 //=================================================================================
318 // function : SetEditCurrentArgument()
320 //=================================================================================
321 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
323 QPushButton* send = (QPushButton*)sender();
326 if ( send == GroupPoints->PushButton1 ) {
327 myEditCurrentArgument = GroupPoints->LineEdit1;
328 globalSelection( GEOM_ALLSHAPES );
330 else if ( send == GroupPoints->PushButton2 ) {
331 myEditCurrentArgument = GroupPoints->LineEdit2;
332 globalSelection( GEOM_LINE );
334 else if ( send == GroupDimensions->PushButton1 ) {
335 myEditCurrentArgument = GroupDimensions->LineEdit1;
336 globalSelection( GEOM_ALLSHAPES );
338 else if ( send == GroupDimensions->PushButton2 ) {
339 myEditCurrentArgument = GroupDimensions->LineEdit2;
340 globalSelection( GEOM_LINE );
342 else if ( send == GroupDimensions->PushButton3 ) {
343 myEditCurrentArgument = GroupDimensions->LineEdit3;
344 globalSelection( GEOM_LINE );
347 myEditCurrentArgument->setFocus();
348 SelectionIntoArgument();
352 //=================================================================================
353 // function : LineEditReturnPressed()
355 //=================================================================================
356 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
358 QLineEdit* send = (QLineEdit*)sender();
359 if ( send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
360 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
361 send == GroupDimensions->LineEdit3 ) {
362 myEditCurrentArgument = send;
363 GEOMBase_Skeleton::LineEditReturnPressed();
368 //=================================================================================
369 // function : ActivateThisDialog()
371 //=================================================================================
372 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
374 GEOMBase_Skeleton::ActivateThisDialog();
375 connect( myGeomGUI->getApp()->selectionMgr(),
376 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
378 ConstructorsClicked( getConstructorId() );
382 //=================================================================================
383 // function : enterEvent()
385 //=================================================================================
386 void TransformationGUI_MultiTranslationDlg::enterEvent( QEvent* )
388 if ( !mainFrame()->GroupConstructors->isEnabled() )
389 ActivateThisDialog();
393 //=================================================================================
394 // function : ValueChangedInSpinBox()
396 //=================================================================================
397 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox( double newValue )
399 QObject* send = (QObject*)sender();
401 switch ( getConstructorId() ) {
403 if ( send == GroupPoints->SpinBox_DX )
405 else if ( send == GroupPoints->SpinBox_DY )
406 myNbTimesU = (int)newValue;
409 if ( send == GroupDimensions->SpinBox_DX1 )
411 else if ( send == GroupDimensions->SpinBox_DY1)
412 myNbTimesU = (int)newValue;
413 else if ( send == GroupDimensions->SpinBox_DX2 )
415 else if ( send == GroupDimensions->SpinBox_DY2 )
416 myNbTimesV = (int)newValue;
424 //=================================================================================
425 // function : ReverseStepU()
426 // purpose : 'state' not used here
427 //=================================================================================
428 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
432 int aConstructorId = getConstructorId();
434 if ( aConstructorId == 0 )
435 GroupPoints->SpinBox_DX->setValue( myStepU );
436 else if ( aConstructorId == 1 )
437 GroupDimensions->SpinBox_DX1->setValue( myStepU );
443 //=================================================================================
444 // function : ReverseStepV
445 // purpose : 'state' not used here
446 //=================================================================================
447 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
451 GroupDimensions->SpinBox_DX2->setValue( myStepV );
457 //=================================================================================
458 // function : createOperation
460 //=================================================================================
461 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
463 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
467 //=================================================================================
468 // function : isValid
470 //=================================================================================
471 bool TransformationGUI_MultiTranslationDlg::isValid( QString& /*msg*/ )
473 int aConstructorId = getConstructorId();
475 if ( aConstructorId == 0 )
476 return !( myBase->_is_nil() || myVectorU->_is_nil() );
477 else if ( aConstructorId == 1 )
478 return !( myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil() );
482 //=================================================================================
483 // function : execute
485 //=================================================================================
486 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
490 GEOM::GEOM_Object_var anObj;
492 switch ( getConstructorId() ) {
494 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
495 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
500 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) &&
501 !CORBA::is_nil( myVectorV ) ) {
502 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
503 myVectorV, myStepV, myNbTimesV );
509 if ( !anObj->_is_nil() )
510 objects.push_back( anObj._retn() );
516 //=================================================================================
517 // function : closeEvent
519 //=================================================================================
520 void TransformationGUI_MultiTranslationDlg::closeEvent( QCloseEvent* e )
522 // myGeomGUI->SetState( -1 );
523 GEOMBase_Skeleton::closeEvent( e );