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"
28 #include <GEOM_DlgRef.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_TranslationDlg()
41 // purpose : Constructs a TransformationGUI_TranslationDlg 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_TranslationDlg::TransformationGUI_TranslationDlg
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_TRANSLATION_DXYZ" ) ) );
52 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TRANSLATION_POINTS" ) ) );
53 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TRANSLATION_VECTOR" ) ) );
54 QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_TRANSLATION_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TRANSLATION" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setIcon( image1 );
62 mainFrame()->RadioButton3->setIcon( image2 );
63 mainFrame()->RadioButton1->setChecked( true );
65 GroupPoints = new DlgRef_3Sel3Spin1Check( centralWidget() );
66 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
67 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
69 GroupPoints->TextLabel4->setText( tr( "GEOM_DX" ) );
70 GroupPoints->TextLabel5->setText( tr( "GEOM_DY" ) );
71 GroupPoints->TextLabel6->setText( tr( "GEOM_DZ" ) );
72 GroupPoints->PushButton1->setIcon( image3 );
73 GroupPoints->PushButton2->setIcon( image3 );
74 GroupPoints->PushButton3->setIcon( image3 );
75 GroupPoints->CheckBox1->setText( tr( "GEOM_CREATE_COPY" ) );
77 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
78 layout->setMargin( 0 ); layout->setSpacing( 6 );
79 layout->addWidget( GroupPoints );
80 /***************************************************************/
82 setHelpFileName( "translation.htm" );
88 //=================================================================================
89 // function : ~TransformationGUI_TranslationDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 TransformationGUI_TranslationDlg::~TransformationGUI_TranslationDlg()
94 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void TransformationGUI_TranslationDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
108 GroupPoints->LineEdit3->setReadOnly( true );
110 myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
112 // Activate Create a Copy mode
113 GroupPoints->CheckBox1->setChecked( true );
114 CreateCopyModeChanged( true );
116 /* Get setting of step value from file configuration */
117 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
118 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
120 /* min, max, step and decimals for spin boxes & initial values */
121 initSpinBox( GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, 3 );
122 initSpinBox( GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, 3 );
123 initSpinBox( GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, 3 );
125 GroupPoints->SpinBox1->setValue( 0.0 );
126 GroupPoints->SpinBox2->setValue( 0.0 );
127 GroupPoints->SpinBox3->setValue( 0.0 );
129 /* signals and slots connections */
130 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
131 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
133 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
135 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
137 connect( GroupPoints->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
139 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); //@ Delete ?
141 connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
142 connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
143 connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
146 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox1, SLOT( SetStep( double ) ) );
147 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox2, SLOT( SetStep( double ) ) );
148 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox3, SLOT( SetStep( double ) ) );
151 connect( GroupPoints->CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
153 connect( myGeomGUI->getApp()->selectionMgr(),
154 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
156 initName( tr( "GEOM_TRANSLATION" ) );
158 ConstructorsClicked( 0 );
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void TransformationGUI_TranslationDlg::ConstructorsClicked( int constructorId )
168 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
170 myEditCurrentArgument = GroupPoints->LineEdit1;
173 switch ( constructorId ) {
174 case 0: /* translation an object by dx, dy, dz */
176 GroupPoints->ShowRows( 1, 2, false );
177 GroupPoints->ShowRows( 3, 5, true );
180 case 1: /* translation an object by 2 points */
182 GroupPoints->ShowRows( 3, 5, false );
183 GroupPoints->ShowRows( 0, 2, true );
184 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
185 GroupPoints->LineEdit2->clear();
186 GroupPoints->LineEdit3->clear();
187 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
190 case 2: /* translation an object by vector */
192 GroupPoints->ShowRows( 2, 5, false );
193 GroupPoints->ShowRows( 0, 1, true );
194 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
195 GroupPoints->LineEdit2->clear();
196 myVector = GEOM::GEOM_Object::_nil();
201 qApp->processEvents();
203 resize( minimumSize() );
205 myEditCurrentArgument->setFocus();
206 connect( myGeomGUI->getApp()->selectionMgr(),
207 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
211 //=================================================================================
212 // function : ClickOnOk()
214 //=================================================================================
215 void TransformationGUI_TranslationDlg::ClickOnOk()
217 if ( ClickOnApply() )
222 //=================================================================================
223 // function : ClickOnApply()
225 //=================================================================================
226 bool TransformationGUI_TranslationDlg::ClickOnApply()
228 if ( !onAccept(GroupPoints->CheckBox1->isChecked()) )
232 ConstructorsClicked( getConstructorId() );
237 //=================================================================================
238 // function : SelectionIntoArgument()
239 // purpose : Called when selection as changed or other case
240 //=================================================================================
241 void TransformationGUI_TranslationDlg::SelectionIntoArgument()
243 myEditCurrentArgument->setText( "" );
246 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
247 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
250 myObjects.length( 0 );
253 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
254 if ( !myObjects.length() )
258 if ( IObjectCount() != 1 ) {
259 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
260 myPoint1 = GEOM::GEOM_Object::_nil();
261 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
262 myVector = GEOM::GEOM_Object::_nil();
263 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
264 myPoint2 = GEOM::GEOM_Object::_nil();
268 Standard_Boolean testResult = Standard_False;;
269 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
271 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
274 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
275 myPoint1 = aSelectedObject;
276 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 )
277 myVector = aSelectedObject;
278 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
279 myPoint2 = aSelectedObject;
281 aName = GEOMBase::GetName( aSelectedObject );
284 myEditCurrentArgument->setText( aName );
290 //=================================================================================
291 // function : LineEditReturnPressed()
293 //=================================================================================
294 void TransformationGUI_TranslationDlg::LineEditReturnPressed()
296 QLineEdit* send = (QLineEdit*)sender();
297 if ( send == GroupPoints->LineEdit1 ) {
298 myEditCurrentArgument = send;
299 GEOMBase_Skeleton::LineEditReturnPressed();
304 //=================================================================================
305 // function : SetEditCurrentArgument()
307 //=================================================================================
308 void TransformationGUI_TranslationDlg::SetEditCurrentArgument()
310 QPushButton* send = (QPushButton*)sender();
312 if ( send == GroupPoints->PushButton1 ) {
313 myEditCurrentArgument = GroupPoints->LineEdit1;
316 else if ( send == GroupPoints->PushButton2 ) {
317 myEditCurrentArgument = GroupPoints->LineEdit2;
318 getConstructorId() == 1 ? globalSelection( GEOM_POINT ) :
319 globalSelection( GEOM_LINE );
321 else if ( send == GroupPoints->PushButton3 ) {
322 myEditCurrentArgument = GroupPoints->LineEdit3;
323 globalSelection( GEOM_POINT );
326 myEditCurrentArgument->setFocus();
327 SelectionIntoArgument();
331 //=================================================================================
332 // function : ActivateThisDialog()
334 //=================================================================================
335 void TransformationGUI_TranslationDlg::ActivateThisDialog()
337 GEOMBase_Skeleton::ActivateThisDialog();
338 connect( myGeomGUI->getApp()->selectionMgr(),
339 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
341 ConstructorsClicked( getConstructorId() );
345 //=================================================================================
346 // function : enterEvent()
348 //=================================================================================
349 void TransformationGUI_TranslationDlg::enterEvent( QEvent* )
351 if ( !mainFrame()->GroupConstructors->isEnabled() )
352 ActivateThisDialog();
356 //=================================================================================
357 // function : ValueChangedInSpinBox()
359 //=================================================================================
360 void TransformationGUI_TranslationDlg::ValueChangedInSpinBox()
366 //=================================================================================
367 // function : createOperation
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr TransformationGUI_TranslationDlg::createOperation()
372 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
376 //=================================================================================
377 // function : isValid
379 //=================================================================================
380 bool TransformationGUI_TranslationDlg::isValid( QString& /*msg*/ )
382 int aConstructorId = getConstructorId();
384 switch ( aConstructorId ) {
386 return !( myObjects.length() == 0 );
389 return !( myObjects.length() == 0 || myPoint1->_is_nil() || myPoint2->_is_nil() );
392 return !( myObjects.length() == 0 || myVector->_is_nil() );
399 //=================================================================================
400 // function : execute
402 //=================================================================================
403 bool TransformationGUI_TranslationDlg::execute( ObjectList& objects )
406 bool toCreateCopy = IsPreview() || GroupPoints->CheckBox1->isChecked();
408 GEOM::GEOM_Object_var anObj;
410 switch ( getConstructorId() ) {
413 double dx = GroupPoints->SpinBox1->value();
414 double dy = GroupPoints->SpinBox2->value();
415 double dz = GroupPoints->SpinBox3->value();
417 if ( toCreateCopy ) {
418 for ( int i = 0; i < myObjects.length(); i++ ) {
419 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZCopy( myObjects[i], dx, dy, dz );
420 if ( !anObj->_is_nil() )
421 objects.push_back( anObj._retn() );
425 for ( int i = 0; i < myObjects.length(); i++ ) {
426 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateDXDYDZ( myObjects[i], dx, dy, dz );
427 if ( !anObj->_is_nil() )
428 objects.push_back( anObj._retn() );
436 if ( toCreateCopy ) {
437 for ( int i = 0; i < myObjects.length(); i++ ) {
438 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPointsCopy( myObjects[i], myPoint1, myPoint2 );
439 if ( !anObj->_is_nil() )
440 objects.push_back( anObj._retn() );
444 for ( int i = 0; i < myObjects.length(); i++ ) {
445 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateTwoPoints( myObjects[i], myPoint1, myPoint2 );
446 if ( !anObj->_is_nil() )
447 objects.push_back( anObj._retn() );
455 if ( toCreateCopy ) {
456 for ( int i = 0; i < myObjects.length(); i++ ) {
457 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVectorCopy( myObjects[i], myVector );
458 if ( !anObj->_is_nil() )
459 objects.push_back( anObj._retn() );
463 for ( int i = 0; i < myObjects.length(); i++ ) {
464 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->TranslateVector( myObjects[i], myVector );
465 if ( !anObj->_is_nil() )
466 objects.push_back( anObj._retn() );
478 //=================================================================================
479 // function : closeEvent
481 //=================================================================================
482 void TransformationGUI_TranslationDlg::closeEvent( QCloseEvent* e )
484 // myGeomGUI->SetState( -1 );
485 GEOMBase_Skeleton::closeEvent( e );
489 //=================================================================================
490 // function : CreateCopyModeChanged()
492 //=================================================================================
493 void TransformationGUI_TranslationDlg::CreateCopyModeChanged( bool isCreateCopy )
495 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );