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_TranslationDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_TranslationDlg.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_TranslationDlg()
48 // purpose : Constructs a TransformationGUI_TranslationDlg 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_TranslationDlg::TransformationGUI_TranslationDlg
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_TRANSLATION_DXYZ" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TRANSLATION_POINTS" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TRANSLATION_VECTOR" ) ) );
61 QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
63 setWindowTitle( tr( "GEOM_TRANSLATION_TITLE" ) );
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TRANSLATION" ) );
67 mainFrame()->RadioButton1->setIcon( image0 );
68 mainFrame()->RadioButton2->setIcon( image1 );
69 mainFrame()->RadioButton3->setIcon( image2 );
70 mainFrame()->RadioButton1->setChecked( true );
72 GroupPoints = new DlgRef_3Sel3Spin2Check( centralWidget() );
73 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
74 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
76 GroupPoints->TextLabel4->setText( tr( "GEOM_DX" ) );
77 GroupPoints->TextLabel5->setText( tr( "GEOM_DY" ) );
78 GroupPoints->TextLabel6->setText( tr( "GEOM_DZ" ) );
79 GroupPoints->PushButton1->setIcon( image3 );
80 GroupPoints->PushButton2->setIcon( image3 );
81 GroupPoints->PushButton3->setIcon( image3 );
82 GroupPoints->CheckBox1->setText( tr( "Activate Distance" ) );
83 GroupPoints->CheckBox2->setText( tr( "GEOM_CREATE_COPY" ) );
85 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
86 layout->setMargin( 0 ); layout->setSpacing( 6 );
87 layout->addWidget( GroupPoints );
88 /***************************************************************/
90 setHelpFileName( "translation_operation_page.html" );
96 //=================================================================================
97 // function : ~TransformationGUI_TranslationDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
102 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void TransformationGUI_TranslationDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
114 GroupPoints->LineEdit1->setReadOnly( true );
115 GroupPoints->LineEdit2->setReadOnly( true );
116 GroupPoints->LineEdit3->setReadOnly( true );
118 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
120 // Activate Create a Copy mode
121 GroupPoints->CheckBox2->setChecked( true );
122 CreateCopyModeChanged( true );
124 mainFrame()->GroupBoxPublish->show();
126 /* Get setting of step value from file configuration */
127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
130 /* min, max, step and decimals for spin boxes & initial values */
131 initSpinBox( GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
132 initSpinBox( GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
133 initSpinBox( GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
135 GroupPoints->SpinBox1->setValue( 0.0 );
136 GroupPoints->SpinBox2->setValue( 0.0 );
137 GroupPoints->SpinBox3->setValue( 0.0 );
139 /* signals and slots connections */
140 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
143 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
145 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
147 connect( GroupPoints->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
149 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); //@ Delete ?
151 connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
152 connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
153 connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
155 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
157 connect( GroupPoints->CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( ActivateDistanceChanged( bool ) ) );
158 connect( GroupPoints->CheckBox2, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
160 connect( myGeomGUI->getApp()->selectionMgr(),
161 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
163 initName( tr( "GEOM_TRANSLATION" ) );
165 ConstructorsClicked( 0 );
169 //=================================================================================
170 // function : SetDoubleSpinBoxStep()
171 // purpose : Double spin box management
172 //=================================================================================
173 void TransformationGUI_TranslationDlg::SetDoubleSpinBoxStep( double step )
175 GroupPoints->SpinBox1->setSingleStep(step);
176 GroupPoints->SpinBox2->setSingleStep(step);
177 GroupPoints->SpinBox3->setSingleStep(step);
180 //=================================================================================
181 // function : ConstructorsClicked()
182 // purpose : Radio button management
183 //=================================================================================
184 void TransformationGUI_TranslationDlg::ConstructorsClicked( int constructorId )
187 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
189 myEditCurrentArgument = GroupPoints->LineEdit1;
192 switch ( constructorId ) {
193 case 0: /* translation an object by dx, dy, dz */
195 GroupPoints->ShowRows( 1, 2, false );
196 GroupPoints->ShowRows( 3, 5, true );
197 GroupPoints->TextLabel6->setText( tr( "GEOM_DZ" ) );
198 GroupPoints->CheckBox1->hide();
199 GroupPoints->SpinBox3->setEnabled( true );
202 case 1: /* translation an object by 2 points */
204 GroupPoints->ShowRows( 3, 5, false );
205 GroupPoints->ShowRows( 0, 2, true );
206 GroupPoints->CheckBox1->hide();
207 GroupPoints->TextLabel6->setText( tr( "GEOM_DZ" ) );
208 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
209 GroupPoints->LineEdit2->clear();
210 GroupPoints->LineEdit3->clear();
211 GroupPoints->SpinBox3->setEnabled( true );
212 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
215 case 2: /* translation an object by vector */
217 GroupPoints->ShowRows( 0, 1, true );
218 GroupPoints->ShowRows( 2, 4, false );
219 GroupPoints->ShowRows( 5, 5, true );
220 GroupPoints->CheckBox1->show();
221 GroupPoints->TextLabel6->setText( tr( "GEOM_DISTANCE" ) );
222 GroupPoints->SpinBox3->setValue( 0.0 );
223 GroupPoints->SpinBox3->setEnabled( false );
224 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
225 GroupPoints->LineEdit2->clear();
226 myVector = GEOM::GEOM_Object::_nil();
227 ActivateDistanceChanged( GroupPoints->CheckBox1->isChecked() );
232 qApp->processEvents();
234 resize( minimumSize() );
236 myEditCurrentArgument->setFocus();
237 connect( myGeomGUI->getApp()->selectionMgr(),
238 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void TransformationGUI_TranslationDlg::ClickOnOk()
248 if ( ClickOnApply() )
253 //=================================================================================
254 // function : ClickOnApply()
256 //=================================================================================
257 bool TransformationGUI_TranslationDlg::ClickOnApply()
259 if ( !onAccept(GroupPoints->CheckBox2->isChecked()) )
268 //=================================================================================
269 // function : SelectionIntoArgument()
270 // purpose : Called when selection as changed or other case
271 //=================================================================================
272 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
274 myEditCurrentArgument->setText( "" );
277 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
278 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
281 myObjects.length( 0 );
284 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
285 if ( !myObjects.length() )
289 if ( IObjectCount() != 1 ) {
290 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
291 myPoint1 = GEOM::GEOM_Object::_nil();
292 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
293 myVector = GEOM::GEOM_Object::_nil();
294 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
295 myPoint2 = GEOM::GEOM_Object::_nil();
299 Standard_Boolean testResult = Standard_False;;
300 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
302 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
306 aName = GEOMBase::GetName( aSelectedObject );
307 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
309 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
310 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
311 aNeedType = TopAbs_EDGE;
313 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
314 TColStd_IndexedMapOfInteger aMap;
315 aSelMgr->GetIndexes( firstIObject(), aMap );
316 if ( aMap.Extent() == 1 )
318 int anIndex = aMap( 1 );
319 if ( aNeedType == TopAbs_EDGE )
320 aName += QString( ":edge_%1" ).arg( anIndex );
322 aName += QString( ":vertex_%1" ).arg( anIndex );
324 //Find SubShape Object in Father
325 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
327 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
328 GEOM::GEOM_IShapesOperations_var aShapesOp =
329 getGeomEngine()->GetIShapesOperations( getStudyId() );
330 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
333 aSelectedObject = aFindedObject;
335 else // Global Selection
337 if ( aShape.ShapeType() != aNeedType ) {
338 aSelectedObject = GEOM::GEOM_Object::_nil();
344 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
345 myPoint1 = aSelectedObject;
346 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
347 myVector = aSelectedObject;
348 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
349 myPoint2 = aSelectedObject;
352 myEditCurrentArgument->setText( aName );
358 //=================================================================================
359 // function : LineEditReturnPressed()
361 //=================================================================================
362 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
364 QLineEdit* send = (QLineEdit*)sender();
365 if ( send == GroupPoints->LineEdit1 ) {
366 myEditCurrentArgument = send;
367 GEOMBase_Skeleton::LineEditReturnPressed();
372 //=================================================================================
373 // function : SetEditCurrentArgument()
375 //=================================================================================
376 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
378 QPushButton* send = (QPushButton*)sender();
381 if ( send == GroupPoints->PushButton1 ) {
382 myEditCurrentArgument = GroupPoints->LineEdit1;
384 else if ( send == GroupPoints->PushButton2 ) {
385 myEditCurrentArgument = GroupPoints->LineEdit2;
386 if ( getConstructorId() == 1 )
387 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
389 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
391 else if ( send == GroupPoints->PushButton3 ) {
392 myEditCurrentArgument = GroupPoints->LineEdit3;
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
396 myEditCurrentArgument->setFocus();
397 SelectionIntoArgument();
401 //=================================================================================
402 // function : ActivateThisDialog()
404 //=================================================================================
405 void TransformationGUI_TranslationDlg::ActivateThisDialog()
407 GEOMBase_Skeleton::ActivateThisDialog();
409 connect( myGeomGUI->getApp()->selectionMgr(),
410 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
412 ConstructorsClicked( getConstructorId() );
416 //=================================================================================
417 // function : enterEvent()
419 //=================================================================================
420 void TransformationGUI_TranslationDlg::enterEvent( QEvent* )
422 if ( !mainFrame()->GroupConstructors->isEnabled() )
423 ActivateThisDialog();
427 //=================================================================================
428 // function : ValueChangedInSpinBox()
430 //=================================================================================
431 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
437 //=================================================================================
438 // function : createOperation
440 //=================================================================================
441 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
443 return getGeomEngine()->GetITransformOperations( getStudyId() );
447 //=================================================================================
448 // function : isValid
450 //=================================================================================
451 bool TransformationGUI_TranslationDlg::isValid( QString& /*msg*/ )
453 int aConstructorId = getConstructorId();
455 switch ( aConstructorId ) {
458 Handle(SALOME_InteractiveObject) IO = firstIObject();
459 Standard_Boolean testResult;
460 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
461 if ( !testResult || anObject->_is_nil() )
464 return !( myObjects.length() == 0 );
467 return !( myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
469 return !( myObjects.length() == 0 || myVector->_is_nil() );
476 //=================================================================================
477 // function : execute
479 //=================================================================================
480 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
483 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
485 GEOM::GEOM_Object_var anObj;
487 switch ( getConstructorId() ) {
490 double dx = GroupPoints->SpinBox1->value();
491 double dy = GroupPoints->SpinBox2->value();
492 double dz = GroupPoints->SpinBox3->value();
494 if ( toCreateCopy ) {
495 for ( int i = 0; i < myObjects.length(); i++ ) {
496 myCurrObject = myObjects[i];
497 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
498 if ( !anObj->_is_nil() )
499 objects.push_back( anObj._retn() );
503 for ( int i = 0; i < myObjects.length(); i++ ) {
504 myCurrObject = myObjects[i];
505 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
506 if ( !anObj->_is_nil() )
507 objects.push_back( anObj._retn() );
515 if ( toCreateCopy ) {
516 for ( int i = 0; i < myObjects.length(); i++ ) {
517 myCurrObject = myObjects[i];
518 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
519 if ( !anObj->_is_nil() )
520 objects.push_back( anObj._retn() );
524 for ( int i = 0; i < myObjects.length(); i++ ) {
525 myCurrObject = myObjects[i];
526 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
527 if ( !anObj->_is_nil() )
528 objects.push_back( anObj._retn() );
536 bool byDistance = GroupPoints->CheckBox1->isChecked();
538 double aDistance = GroupPoints->SpinBox3->value();
539 for ( int i = 0; i < myObjects.length(); i++ ) {
540 myCurrObject = myObjects[i];
541 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
542 TranslateVectorDistance( myObjects[i], myVector, aDistance, toCreateCopy );
543 if ( !anObj->_is_nil() )
544 objects.push_back( anObj._retn() );
548 if ( toCreateCopy ) {
549 for ( int i = 0; i < myObjects.length(); i++ ) {
550 myCurrObject = myObjects[i];
551 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
552 TranslateVectorCopy( myObjects[i], myVector );
553 if ( !anObj->_is_nil() )
554 objects.push_back( anObj._retn() );
559 for (int i = 0; i < myObjects.length(); i++) {
560 myCurrObject = myObjects[i];
561 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
562 TranslateVector( myObjects[i], myVector );
563 if ( !anObj->_is_nil() )
564 objects.push_back( anObj._retn() );
575 //=================================================================================
576 // function : restoreSubShapes
578 //=================================================================================
579 void TransformationGUI_TranslationDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
580 SALOMEDS::SObject_ptr theSObject )
582 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
583 // we pass here the first operation argument (object) through the list of arguments
584 // because the rotation operation place its arguments in the data structure in another order,
585 // and we need to point the first argument directly
586 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
588 anArgs[0] = myCurrObject;
589 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, anArgs,
590 /*theFindMethod=*/GEOM::FSM_Transformed,
591 /*theInheritFirstArg=*/true );
595 //=================================================================================
596 // function : CreateCopyModeChanged()
598 //=================================================================================
599 void TransformationGUI_TranslationDlg::CreateCopyModeChanged( bool isCreateCopy )
601 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
604 //=================================================================================
605 // function : ActivateDistanceChanged()
607 //=================================================================================
608 void TransformationGUI_TranslationDlg::ActivateDistanceChanged( bool theEnable )
610 GroupPoints->SpinBox3->setEnabled( theEnable );
614 //=================================================================================
615 // function : addSubshapeToStudy
616 // purpose : virtual method to add new SubObjects if local selection
617 //=================================================================================
618 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
620 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
621 if ( toCreateCopy ) {
622 QMap<QString, GEOM::GEOM_Object_var> objMap;
624 switch ( getConstructorId() ) {
628 objMap[GroupPoints->LineEdit2->text()] = myPoint1;
629 objMap[GroupPoints->LineEdit3->text()] = myPoint2;
632 objMap[GroupPoints->LineEdit2->text()] = myVector;
635 addSubshapesToFather( objMap );