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() ) );
152 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
154 connect( GroupPoints->CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
156 connect( myGeomGUI->getApp()->selectionMgr(),
157 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
159 initName( tr( "GEOM_TRANSLATION" ) );
161 ConstructorsClicked( 0 );
165 //=================================================================================
166 // function : SetDoubleSpinBoxStep()
167 // purpose : Double spin box management
168 //=================================================================================
169 void TransformationGUI_TranslationDlg::SetDoubleSpinBoxStep( double step )
171 GroupPoints->SpinBox1->setSingleStep(step);
172 GroupPoints->SpinBox2->setSingleStep(step);
173 GroupPoints->SpinBox3->setSingleStep(step);
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void TransformationGUI_TranslationDlg::ConstructorsClicked( int constructorId )
183 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
185 myEditCurrentArgument = GroupPoints->LineEdit1;
188 switch ( constructorId ) {
189 case 0: /* translation an object by dx, dy, dz */
191 GroupPoints->ShowRows( 1, 2, false );
192 GroupPoints->ShowRows( 3, 5, true );
195 case 1: /* translation an object by 2 points */
197 GroupPoints->ShowRows( 3, 5, false );
198 GroupPoints->ShowRows( 0, 2, true );
199 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
200 GroupPoints->LineEdit2->clear();
201 GroupPoints->LineEdit3->clear();
202 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
205 case 2: /* translation an object by vector */
207 GroupPoints->ShowRows( 2, 5, false );
208 GroupPoints->ShowRows( 0, 1, true );
209 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
210 GroupPoints->LineEdit2->clear();
211 myVector = GEOM::GEOM_Object::_nil();
216 qApp->processEvents();
218 resize( minimumSize() );
220 myEditCurrentArgument->setFocus();
221 connect( myGeomGUI->getApp()->selectionMgr(),
222 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
226 //=================================================================================
227 // function : ClickOnOk()
229 //=================================================================================
230 void TransformationGUI_TranslationDlg::ClickOnOk()
232 if ( ClickOnApply() )
237 //=================================================================================
238 // function : ClickOnApply()
240 //=================================================================================
241 bool TransformationGUI_TranslationDlg::ClickOnApply()
243 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
252 //=================================================================================
253 // function : SelectionIntoArgument()
254 // purpose : Called when selection as changed or other case
255 //=================================================================================
256 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
258 myEditCurrentArgument->setText( "" );
261 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
262 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
265 myObjects.length( 0 );
268 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
269 if ( !myObjects.length() )
273 if ( IObjectCount() != 1 ) {
274 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
275 myPoint1 = GEOM::GEOM_Object::_nil();
276 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
277 myVector = GEOM::GEOM_Object::_nil();
278 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
279 myPoint2 = GEOM::GEOM_Object::_nil();
283 Standard_Boolean testResult = Standard_False;;
284 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
286 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
290 aName = GEOMBase::GetName( aSelectedObject );
291 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
292 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
293 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
294 aNeedType = TopAbs_EDGE;
296 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
297 TColStd_IndexedMapOfInteger aMap;
298 aSelMgr->GetIndexes( firstIObject(), aMap );
299 if ( aMap.Extent() == 1 ) {
300 int anIndex = aMap( 1 );
301 if ( aNeedType == TopAbs_EDGE )
302 aName += QString( ":edge_%1" ).arg( anIndex );
304 aName += QString( ":vertex_%1" ).arg( anIndex );
306 //Find SubShape Object in Father
307 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
309 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
310 GEOM::GEOM_IShapesOperations_var aShapesOp =
311 getGeomEngine()->GetIShapesOperations( getStudyId() );
312 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
315 aSelectedObject = aFindedObject;
318 else { // Global Selection
319 if ( aShape.ShapeType() != aNeedType ) {
320 aSelectedObject = GEOM::GEOM_Object::_nil();
326 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
327 myPoint1 = aSelectedObject;
328 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
329 myVector = aSelectedObject;
330 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
331 myPoint2 = aSelectedObject;
334 myEditCurrentArgument->setText( aName );
340 //=================================================================================
341 // function : LineEditReturnPressed()
343 //=================================================================================
344 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
346 QLineEdit* send = (QLineEdit*)sender();
347 if ( send == GroupPoints->LineEdit1 ) {
348 myEditCurrentArgument = send;
349 GEOMBase_Skeleton::LineEditReturnPressed();
354 //=================================================================================
355 // function : SetEditCurrentArgument()
357 //=================================================================================
358 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
360 QPushButton* send = (QPushButton*)sender();
363 if ( send == GroupPoints->PushButton1 ) {
364 myEditCurrentArgument = GroupPoints->LineEdit1;
366 else if ( send == GroupPoints->PushButton2 ) {
367 myEditCurrentArgument = GroupPoints->LineEdit2;
368 if ( getConstructorId() == 1 )
369 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
371 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
373 else if ( send == GroupPoints->PushButton3 ) {
374 myEditCurrentArgument = GroupPoints->LineEdit3;
375 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
378 myEditCurrentArgument->setFocus();
379 SelectionIntoArgument();
383 //=================================================================================
384 // function : ActivateThisDialog()
386 //=================================================================================
387 void TransformationGUI_TranslationDlg::ActivateThisDialog()
389 GEOMBase_Skeleton::ActivateThisDialog();
391 connect( myGeomGUI->getApp()->selectionMgr(),
392 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
394 ConstructorsClicked( getConstructorId() );
398 //=================================================================================
399 // function : enterEvent()
401 //=================================================================================
402 void TransformationGUI_TranslationDlg::enterEvent( QEvent* )
404 if ( !mainFrame()->GroupConstructors->isEnabled() )
405 ActivateThisDialog();
409 //=================================================================================
410 // function : ValueChangedInSpinBox()
412 //=================================================================================
413 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
419 //=================================================================================
420 // function : createOperation
422 //=================================================================================
423 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
425 return getGeomEngine()->GetITransformOperations( getStudyId() );
429 //=================================================================================
430 // function : isValid
432 //=================================================================================
433 bool TransformationGUI_TranslationDlg::isValid( QString& /*msg*/ )
435 int aConstructorId = getConstructorId();
437 switch ( aConstructorId ) {
439 return !( myObjects.length() == 0 );
442 return !( myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
445 return !( myObjects.length() == 0 || myVector->_is_nil() );
452 //=================================================================================
453 // function : execute
455 //=================================================================================
456 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
459 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
461 GEOM::GEOM_Object_var anObj;
463 switch ( getConstructorId() ) {
466 double dx = GroupPoints->SpinBox1->value();
467 double dy = GroupPoints->SpinBox2->value();
468 double dz = GroupPoints->SpinBox3->value();
470 if ( toCreateCopy ) {
471 for ( int i = 0; i < myObjects.length(); i++ ) {
472 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
473 if ( !anObj->_is_nil() )
474 objects.push_back( anObj._retn() );
478 for ( int i = 0; i < myObjects.length(); i++ ) {
479 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
480 if ( !anObj->_is_nil() )
481 objects.push_back( anObj._retn() );
489 if ( toCreateCopy ) {
490 for ( int i = 0; i < myObjects.length(); i++ ) {
491 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
492 if ( !anObj->_is_nil() )
493 objects.push_back( anObj._retn() );
497 for ( int i = 0; i < myObjects.length(); i++ ) {
498 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
499 if ( !anObj->_is_nil() )
500 objects.push_back( anObj._retn() );
508 if ( toCreateCopy ) {
509 for ( int i = 0; i < myObjects.length(); i++ ) {
510 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
511 if ( !anObj->_is_nil() )
512 objects.push_back( anObj._retn() );
516 for ( int i = 0; i < myObjects.length(); i++ ) {
517 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
518 if ( !anObj->_is_nil() )
519 objects.push_back( anObj._retn() );
531 //=================================================================================
532 // function : CreateCopyModeChanged()
534 //=================================================================================
535 void TransformationGUI_TranslationDlg::CreateCopyModeChanged( bool isCreateCopy )
537 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
540 //=================================================================================
541 // function : addSubshapeToStudy
542 // purpose : virtual method to add new SubObjects if local selection
543 //=================================================================================
544 void TransformationGUI_TranslationDlg::addSubshapesToStudy()
546 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
547 if ( toCreateCopy ) {
548 QMap<QString, GEOM::GEOM_Object_var> objMap;
550 switch ( getConstructorId() ) {
554 objMap[GroupPoints->LineEdit2->text()] = myPoint1;
555 objMap[GroupPoints->LineEdit3->text()] = myPoint2;
558 objMap[GroupPoints->LineEdit2->text()] = myVector;
561 addSubshapesToFather( objMap );