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_3Sel3Spin1Check( 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( "GEOM_CREATE_COPY" ) );
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( GroupPoints );
87 /***************************************************************/
89 setHelpFileName( "translation_operation_page.html" );
95 //=================================================================================
96 // function : ~TransformationGUI_TranslationDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
101 // no need to delete child widgets, Qt does it all for us
105 //=================================================================================
108 //=================================================================================
109 void TransformationGUI_TranslationDlg::Init()
112 myEditCurrentArgument = GroupPoints->LineEdit1;
113 GroupPoints->LineEdit1->setReadOnly( true );
114 GroupPoints->LineEdit2->setReadOnly( true );
115 GroupPoints->LineEdit3->setReadOnly( true );
117 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
119 // Activate Create a Copy mode
120 GroupPoints->CheckBox1->setChecked( true );
121 CreateCopyModeChanged( true );
123 /* Get setting of step value from file configuration */
124 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
125 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
127 /* min, max, step and decimals for spin boxes & initial values */
128 initSpinBox( GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
129 initSpinBox( GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
130 initSpinBox( GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
132 GroupPoints->SpinBox1->setValue( 0.0 );
133 GroupPoints->SpinBox2->setValue( 0.0 );
134 GroupPoints->SpinBox3->setValue( 0.0 );
136 /* signals and slots connections */
137 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
138 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
140 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
142 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( GroupPoints->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); //@ Delete ?
148 connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
149 connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
150 connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
153 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox1, SLOT( SetStep( double ) ) );
154 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox2, SLOT( SetStep( double ) ) );
155 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox3, SLOT( SetStep( double ) ) );
158 connect( GroupPoints->CheckBox1, 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 : ConstructorsClicked()
171 // purpose : Radio button management
172 //=================================================================================
173 void TransformationGUI_TranslationDlg::ConstructorsClicked( int constructorId )
176 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
178 myEditCurrentArgument = GroupPoints->LineEdit1;
181 switch ( constructorId ) {
182 case 0: /* translation an object by dx, dy, dz */
184 GroupPoints->ShowRows( 1, 2, false );
185 GroupPoints->ShowRows( 3, 5, true );
188 case 1: /* translation an object by 2 points */
190 GroupPoints->ShowRows( 3, 5, false );
191 GroupPoints->ShowRows( 0, 2, true );
192 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
193 GroupPoints->LineEdit2->clear();
194 GroupPoints->LineEdit3->clear();
195 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
198 case 2: /* translation an object by vector */
200 GroupPoints->ShowRows( 2, 5, false );
201 GroupPoints->ShowRows( 0, 1, true );
202 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
203 GroupPoints->LineEdit2->clear();
204 myVector = GEOM::GEOM_Object::_nil();
209 qApp->processEvents();
211 resize( minimumSize() );
213 myEditCurrentArgument->setFocus();
214 connect( myGeomGUI->getApp()->selectionMgr(),
215 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void TransformationGUI_TranslationDlg::ClickOnOk()
225 if ( ClickOnApply() )
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool TransformationGUI_TranslationDlg::ClickOnApply()
236 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
245 //=================================================================================
246 // function : SelectionIntoArgument()
247 // purpose : Called when selection as changed or other case
248 //=================================================================================
249 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
251 myEditCurrentArgument->setText( "" );
254 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
255 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
258 myObjects.length( 0 );
261 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
262 if ( !myObjects.length() )
266 if ( IObjectCount() != 1 ) {
267 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
268 myPoint1 = GEOM::GEOM_Object::_nil();
269 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
270 myVector = GEOM::GEOM_Object::_nil();
271 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
272 myPoint2 = GEOM::GEOM_Object::_nil();
276 Standard_Boolean testResult = Standard_False;;
277 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
279 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
283 aName = GEOMBase::GetName( aSelectedObject );
284 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
285 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
286 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
287 aNeedType = TopAbs_EDGE;
289 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
290 TColStd_IndexedMapOfInteger aMap;
291 aSelMgr->GetIndexes( firstIObject(), aMap );
292 if ( aMap.Extent() == 1 ) {
293 int anIndex = aMap( 1 );
294 if ( aNeedType == TopAbs_EDGE )
295 aName += QString( ":edge_%1" ).arg( anIndex );
297 aName += QString( ":vertex_%1" ).arg( anIndex );
299 //Find SubShape Object in Father
300 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
302 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
303 GEOM::GEOM_IShapesOperations_var aShapesOp =
304 getGeomEngine()->GetIShapesOperations( getStudyId() );
305 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
308 aSelectedObject = aFindedObject;
311 else { // Global Selection
312 if ( aShape.ShapeType() != aNeedType ) {
313 aSelectedObject = GEOM::GEOM_Object::_nil();
319 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
320 myPoint1 = aSelectedObject;
321 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
322 myVector = aSelectedObject;
323 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
324 myPoint2 = aSelectedObject;
327 myEditCurrentArgument->setText( aName );
333 //=================================================================================
334 // function : LineEditReturnPressed()
336 //=================================================================================
337 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
339 QLineEdit* send = (QLineEdit*)sender();
340 if ( send == GroupPoints->LineEdit1 ) {
341 myEditCurrentArgument = send;
342 GEOMBase_Skeleton::LineEditReturnPressed();
347 //=================================================================================
348 // function : SetEditCurrentArgument()
350 //=================================================================================
351 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
353 QPushButton* send = (QPushButton*)sender();
356 if ( send == GroupPoints->PushButton1 ) {
357 myEditCurrentArgument = GroupPoints->LineEdit1;
359 else if ( send == GroupPoints->PushButton2 ) {
360 myEditCurrentArgument = GroupPoints->LineEdit2;
361 if ( getConstructorId() == 1 )
362 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
364 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
366 else if ( send == GroupPoints->PushButton3 ) {
367 myEditCurrentArgument = GroupPoints->LineEdit3;
368 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
371 myEditCurrentArgument->setFocus();
372 SelectionIntoArgument();
376 //=================================================================================
377 // function : ActivateThisDialog()
379 //=================================================================================
380 void TransformationGUI_TranslationDlg::ActivateThisDialog()
382 GEOMBase_Skeleton::ActivateThisDialog();
384 connect( myGeomGUI->getApp()->selectionMgr(),
385 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
387 ConstructorsClicked( getConstructorId() );
391 //=================================================================================
392 // function : enterEvent()
394 //=================================================================================
395 void TransformationGUI_TranslationDlg::enterEvent( QEvent* )
397 if ( !mainFrame()->GroupConstructors->isEnabled() )
398 ActivateThisDialog();
402 //=================================================================================
403 // function : ValueChangedInSpinBox()
405 //=================================================================================
406 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
412 //=================================================================================
413 // function : createOperation
415 //=================================================================================
416 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
418 return getGeomEngine()->GetITransformOperations( getStudyId() );
422 //=================================================================================
423 // function : isValid
425 //=================================================================================
426 bool TransformationGUI_TranslationDlg::isValid( QString& /*msg*/ )
428 int aConstructorId = getConstructorId();
430 switch ( aConstructorId ) {
432 return !( myObjects.length() == 0 );
435 return !( myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
438 return !( myObjects.length() == 0 || myVector->_is_nil() );
445 //=================================================================================
446 // function : execute
448 //=================================================================================
449 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
452 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
454 GEOM::GEOM_Object_var anObj;
456 switch ( getConstructorId() ) {
459 double dx = GroupPoints->SpinBox1->value();
460 double dy = GroupPoints->SpinBox2->value();
461 double dz = GroupPoints->SpinBox3->value();
463 if ( toCreateCopy ) {
464 for ( int i = 0; i < myObjects.length(); i++ ) {
465 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
466 if ( !anObj->_is_nil() )
467 objects.push_back( anObj._retn() );
471 for ( int i = 0; i < myObjects.length(); i++ ) {
472 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
473 if ( !anObj->_is_nil() )
474 objects.push_back( anObj._retn() );
482 if ( toCreateCopy ) {
483 for ( int i = 0; i < myObjects.length(); i++ ) {
484 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
485 if ( !anObj->_is_nil() )
486 objects.push_back( anObj._retn() );
490 for ( int i = 0; i < myObjects.length(); i++ ) {
491 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
492 if ( !anObj->_is_nil() )
493 objects.push_back( anObj._retn() );
501 if ( toCreateCopy ) {
502 for ( int i = 0; i < myObjects.length(); i++ ) {
503 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
504 if ( !anObj->_is_nil() )
505 objects.push_back( anObj._retn() );
509 for ( int i = 0; i < myObjects.length(); i++ ) {
510 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
511 if ( !anObj->_is_nil() )
512 objects.push_back( anObj._retn() );
524 //=================================================================================
525 // function : CreateCopyModeChanged()
527 //=================================================================================
528 void TransformationGUI_TranslationDlg::CreateCopyModeChanged( bool isCreateCopy )
530 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
533 //=================================================================================
534 // function : addSubshapeToStudy
535 // purpose : virtual method to add new SubObjects if local selection
536 //=================================================================================
537 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
539 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
540 if ( toCreateCopy ) {
541 QMap<QString, GEOM::GEOM_Object_var> objMap;
543 switch ( getConstructorId() ) {
547 objMap[GroupPoints->LineEdit2->text()] = myPoint1;
548 objMap[GroupPoints->LineEdit3->text()] = myPoint2;
551 objMap[GroupPoints->LineEdit2->text()] = myVector;
554 addSubshapesToFather( objMap );