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 <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : TransformationGUI_MultiTranslationDlg()
48 // purpose : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
54 ( GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTITRANSLATION_SIMPLE" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTITRANSLATION_DOUBLE" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_MULTITRANSLATION_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MULTITRANSLATION" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_2Sel2Spin1Check( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_MULTITRANSLATION_SIMPLE" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR_U" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_STEP_U" ) );
76 GroupPoints->TextLabel4->setText( tr( "GEOM_NB_TIMES_U" ) );
77 GroupPoints->CheckButton1->setText( tr( "GEOM_REVERSE_U" ) );
78 GroupPoints->PushButton1->setIcon( image2 );
79 GroupPoints->PushButton2->setIcon( image2 );
80 GroupPoints->LineEdit1->setReadOnly( true );
81 GroupPoints->LineEdit2->setReadOnly( true );
83 GroupDimensions = new DlgRef_3Sel4Spin2Check( centralWidget() );
84 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_MULTITRANSLATION_DOUBLE" ) );
85 GroupDimensions->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
86 GroupDimensions->TextLabel2->setText( tr( "GEOM_VECTOR_U" ) );
87 GroupDimensions->TextLabel3->setText( tr( "GEOM_VECTOR_V" ) );
88 GroupDimensions->TextLabel4->setText( tr( "GEOM_STEP_U" ) );
89 GroupDimensions->TextLabel5->setText( tr( "GEOM_NB_TIMES_U" ) );
90 GroupDimensions->TextLabel6->setText( tr( "GEOM_STEP_V" ) );
91 GroupDimensions->TextLabel7->setText( tr( "GEOM_NB_TIMES_V" ) );
92 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE_U" ) );
93 GroupDimensions->CheckButton2->setText( tr( "GEOM_REVERSE_V" ) );
94 GroupDimensions->PushButton1->setIcon( image2 );
95 GroupDimensions->PushButton2->setIcon( image2 );
96 GroupDimensions->PushButton3->setIcon( image2 );
97 GroupDimensions->LineEdit1->setReadOnly( true );
98 GroupDimensions->LineEdit2->setReadOnly( true );
99 GroupDimensions->LineEdit3->setReadOnly( true );
101 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
102 layout->setMargin( 0 ); layout->setSpacing( 6 );
103 layout->addWidget( GroupPoints );
104 layout->addWidget( GroupDimensions );
105 /***************************************************************/
107 setHelpFileName( "multi_translation_operation_page.html" );
113 //=================================================================================
114 // function : ~TransformationGUI_MultiTranslationDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
119 // no need to delete child widgets, Qt does it all for us
123 //=================================================================================
126 //=================================================================================
127 void TransformationGUI_MultiTranslationDlg::Init()
129 /* Get setting of step value from file configuration */
130 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
131 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
133 double SpecificStep = 1;
134 /* min, max, step and decimals for spin boxes & initial values */
135 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 10 ); // VSR: TODO: DBL_DIGITS_DISPLAY
136 initSpinBox( GroupPoints->SpinBox_DY, 1.0, MAX_NUMBER, SpecificStep, 10 );
137 GroupPoints->SpinBox_DX->setValue( myStepU );
138 GroupPoints->SpinBox_DY->setValue( myNbTimesU );
140 initSpinBox( GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, 10 ); // VSR: TODO: DBL_DIGITS_DISPLAY
141 initSpinBox( GroupDimensions->SpinBox_DY1, 1.0, MAX_NUMBER, SpecificStep, 10 );
142 initSpinBox( GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 10 ); // VSR: TODO: DBL_DIGITS_DISPLAY
143 initSpinBox( GroupDimensions->SpinBox_DY2, 1.0, MAX_NUMBER, SpecificStep, 10 );
144 GroupDimensions->SpinBox_DX1->setValue( myStepU );
145 GroupDimensions->SpinBox_DY1->setValue( myNbTimesU );
146 GroupDimensions->SpinBox_DX2->setValue( myStepV );
147 GroupDimensions->SpinBox_DY2->setValue( myNbTimesV );
149 /* signals and slots connections */
150 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
151 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
153 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
155 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
156 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
157 connect( GroupDimensions->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
158 connect( GroupDimensions->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
159 connect( GroupDimensions->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
161 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
162 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
163 connect( GroupDimensions->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
164 connect( GroupDimensions->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
165 connect( GroupDimensions->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
167 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
169 connect( GroupDimensions->SpinBox_DX1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
170 connect( GroupDimensions->SpinBox_DY1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
171 connect( GroupDimensions->SpinBox_DX2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
172 connect( GroupDimensions->SpinBox_DY2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
174 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( 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() ) );
183 initName( tr( "GEOM_MULTITRANSLATION" ) );
185 ConstructorsClicked( 0 );
189 //=================================================================================
190 // function : SetDoubleSpinBoxStep()
191 // purpose : Double spin box management
192 //=================================================================================
193 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep( double step )
195 GroupPoints->SpinBox_DX->setSingleStep(step);
196 GroupPoints->SpinBox_DY->setSingleStep(step);
197 GroupDimensions->SpinBox_DX1->setSingleStep(step);
198 GroupDimensions->SpinBox_DY1->setSingleStep(step);
199 GroupDimensions->SpinBox_DX2->setSingleStep(step);
200 GroupDimensions->SpinBox_DY2->setSingleStep(step);
203 //=================================================================================
204 // function : ConstructorsClicked()
205 // purpose : Radio button management
206 //=================================================================================
207 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked( int constructorId )
209 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
211 myStepU = myStepV = 50.0;
212 myNbTimesU = myNbTimesV = 2;
214 globalSelection( GEOM_ALLSHAPES );
216 switch ( constructorId ) {
217 case 0: /* Translate simple */
219 GroupDimensions->hide();
222 myEditCurrentArgument = GroupPoints->LineEdit1;
223 GroupPoints->LineEdit1->setText( "" );
224 GroupPoints->LineEdit2->setText( "" );
226 GroupPoints->SpinBox_DX->setValue( myStepU );
227 GroupPoints->SpinBox_DY->setValue( myNbTimesU );
231 case 1: /* Translate double */
234 GroupDimensions->show();
236 myEditCurrentArgument = GroupDimensions->LineEdit1;
237 GroupDimensions->LineEdit1->setText( "" );
238 GroupDimensions->LineEdit2->setText( "" );
239 GroupDimensions->LineEdit3->setText( "" );
241 GroupDimensions->SpinBox_DX1->setValue( myStepU );
242 GroupDimensions->SpinBox_DY1->setValue( myNbTimesU );
243 GroupDimensions->SpinBox_DX2->setValue( myStepV );
244 GroupDimensions->SpinBox_DY2->setValue( myNbTimesV );
246 myVectorV = GEOM::GEOM_Object::_nil();
251 qApp->processEvents();
253 resize( minimumSize() );
255 myEditCurrentArgument->setFocus();
256 myBase = myVectorU = GEOM::GEOM_Object::_nil();
257 connect( myGeomGUI->getApp()->selectionMgr(),
258 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
268 if ( ClickOnApply() )
273 //=================================================================================
274 // function : ClickOnApply()
276 //=================================================================================
277 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
283 ConstructorsClicked( getConstructorId() );
288 //=================================================================================
289 // function : SelectionIntoArgument()
290 // purpose : Called when selection as changed or other case
291 //=================================================================================
292 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
294 myEditCurrentArgument->setText( "" );
296 if ( IObjectCount() != 1 ) {
297 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
298 myEditCurrentArgument == GroupDimensions->LineEdit1 )
299 myBase = GEOM::GEOM_Object::_nil();
300 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
301 myEditCurrentArgument == GroupDimensions->LineEdit2 )
302 myVectorU = GEOM::GEOM_Object::_nil();
303 else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
304 myVectorV = GEOM::GEOM_Object::_nil();
309 Standard_Boolean testResult = Standard_False;;
310 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
312 if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
315 QString aName = GEOMBase::GetName( aSelectedObject );
317 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
318 myEditCurrentArgument == GroupDimensions->LineEdit1 )
319 myBase = aSelectedObject;
320 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
321 myEditCurrentArgument == GroupDimensions->LineEdit2 ||
322 myEditCurrentArgument == GroupDimensions->LineEdit3 ) {
323 if ( testResult && !aSelectedObject->_is_nil() ) {
326 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
327 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
328 TColStd_IndexedMapOfInteger aMap;
329 aSelMgr->GetIndexes( firstIObject(), aMap );
330 if ( aMap.Extent() == 1 ) {
331 int anIndex = aMap( 1 );
332 aName += QString( ":edge_%1" ).arg( anIndex );
334 //Find SubShape Object in Father
335 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
337 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
338 GEOM::GEOM_IShapesOperations_var aShapesOp =
339 getGeomEngine()->GetIShapesOperations( getStudyId() );
340 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
341 myVectorV = aShapesOp->GetSubShape( aSelectedObject, anIndex );
343 myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
346 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
347 myVectorV = aFindedObject;
349 myVectorU = aFindedObject;
353 if ( aShape.ShapeType() != TopAbs_EDGE ) {
354 aSelectedObject = GEOM::GEOM_Object::_nil();
357 if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
358 myVectorV = aSelectedObject;
360 myVectorU = aSelectedObject;
366 myEditCurrentArgument->setText( aName );
372 //=================================================================================
373 // function : SetEditCurrentArgument()
375 //=================================================================================
376 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
378 QPushButton* send = (QPushButton*)sender();
379 globalSelection( GEOM_ALLSHAPES );
381 if ( send == GroupPoints->PushButton1 ) {
382 myEditCurrentArgument = GroupPoints->LineEdit1;
384 else if ( send == GroupPoints->PushButton2 ) {
385 myEditCurrentArgument = GroupPoints->LineEdit2;
386 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
388 else if ( send == GroupDimensions->PushButton1 ) {
389 myEditCurrentArgument = GroupDimensions->LineEdit1;
391 else if ( send == GroupDimensions->PushButton2 ) {
392 myEditCurrentArgument = GroupDimensions->LineEdit2;
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
395 else if ( send == GroupDimensions->PushButton3 ) {
396 myEditCurrentArgument = GroupDimensions->LineEdit3;
397 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
400 myEditCurrentArgument->setFocus();
401 SelectionIntoArgument();
405 //=================================================================================
406 // function : LineEditReturnPressed()
408 //=================================================================================
409 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
411 QLineEdit* send = (QLineEdit*)sender();
412 if ( send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
413 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
414 send == GroupDimensions->LineEdit3 ) {
415 myEditCurrentArgument = send;
416 GEOMBase_Skeleton::LineEditReturnPressed();
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
427 GEOMBase_Skeleton::ActivateThisDialog();
428 connect( myGeomGUI->getApp()->selectionMgr(),
429 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
431 ConstructorsClicked( getConstructorId() );
435 //=================================================================================
436 // function : enterEvent()
438 //=================================================================================
439 void TransformationGUI_MultiTranslationDlg::enterEvent( QEvent* )
441 if ( !mainFrame()->GroupConstructors->isEnabled() )
442 ActivateThisDialog();
446 //=================================================================================
447 // function : ValueChangedInSpinBox()
449 //=================================================================================
450 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox( double newValue )
452 QObject* send = (QObject*)sender();
454 switch ( getConstructorId() ) {
456 if ( send == GroupPoints->SpinBox_DX )
458 else if ( send == GroupPoints->SpinBox_DY )
459 myNbTimesU = (int)newValue;
462 if ( send == GroupDimensions->SpinBox_DX1 )
464 else if ( send == GroupDimensions->SpinBox_DY1)
465 myNbTimesU = (int)newValue;
466 else if ( send == GroupDimensions->SpinBox_DX2 )
468 else if ( send == GroupDimensions->SpinBox_DY2 )
469 myNbTimesV = (int)newValue;
477 //=================================================================================
478 // function : ReverseStepU()
479 // purpose : 'state' not used here
480 //=================================================================================
481 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
485 int aConstructorId = getConstructorId();
487 if ( aConstructorId == 0 )
488 GroupPoints->SpinBox_DX->setValue( myStepU );
489 else if ( aConstructorId == 1 )
490 GroupDimensions->SpinBox_DX1->setValue( myStepU );
496 //=================================================================================
497 // function : ReverseStepV
498 // purpose : 'state' not used here
499 //=================================================================================
500 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
504 GroupDimensions->SpinBox_DX2->setValue( myStepV );
510 //=================================================================================
511 // function : createOperation
513 //=================================================================================
514 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
516 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
520 //=================================================================================
521 // function : isValid
523 //=================================================================================
524 bool TransformationGUI_MultiTranslationDlg::isValid( QString& /*msg*/ )
526 int aConstructorId = getConstructorId();
528 if ( aConstructorId == 0 )
529 return !( myBase->_is_nil() || myVectorU->_is_nil() );
530 else if ( aConstructorId == 1 )
531 return !( myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil() );
535 //=================================================================================
536 // function : execute
538 //=================================================================================
539 bool TransformationGUI_MultiTranslationDlg::execute( ObjectList& objects )
543 GEOM::GEOM_Object_var anObj;
545 switch ( getConstructorId() ) {
547 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) ) {
548 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate1D( myBase, myVectorU, myStepU, myNbTimesU );
553 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVectorU ) &&
554 !CORBA::is_nil( myVectorV ) ) {
555 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiTranslate2D( myBase, myVectorU, myStepU, myNbTimesU,
556 myVectorV, myStepV, myNbTimesV );
562 if ( !anObj->_is_nil() )
563 objects.push_back( anObj._retn() );
569 //=================================================================================
570 // function : addSubshapeToStudy
571 // purpose : virtual method to add new SubObjects if local selection
572 //=================================================================================
573 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
575 QMap<QString, GEOM::GEOM_Object_var> objMap;
577 switch ( getConstructorId() ) {
579 objMap[GroupPoints->LineEdit2->text()] = myVectorU;
582 objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
583 objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
586 addSubshapesToFather( objMap );