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_RotationDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_RotationDlg.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_RotationDlg()
41 // purpose : Constructs a TransformationGUI_RotationDlg 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_RotationDlg::TransformationGUI_RotationDlg
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_ROTATION" ) ) );
52 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ROTATION_THREE_POINTS" ) ) );
55 setWindowTitle( tr( "GEOM_ROTATION_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ROTATION" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setIcon( image2 );
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_4Sel1Spin2Check( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_AXIS" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_ANGLE" ) );
69 GroupPoints->TextLabel4->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
70 GroupPoints->TextLabel5->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
74 GroupPoints->LineEdit4->setReadOnly( true );
75 GroupPoints->LineEdit5->setReadOnly( true );
76 GroupPoints->PushButton1->setIcon( image1 );
77 GroupPoints->PushButton2->setIcon( image1 );
78 GroupPoints->PushButton4->setIcon( image1 );
79 GroupPoints->PushButton5->setIcon( image1 );
80 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
81 GroupPoints->CheckButton2->setText( tr( "GEOM_REVERSE" ) );
83 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
84 layout->setMargin( 0 ); layout->setSpacing( 6 );
85 layout->addWidget( GroupPoints );
87 /***************************************************************/
89 double SpecificStep = 5;
90 /* min, max, step and decimals for spin boxes & initial values */
91 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3 );
92 GroupPoints->SpinBox_DX->setValue( anAngle );
94 // Activate Create a Copy mode
95 GroupPoints->CheckButton1->setChecked( true );
96 CreateCopyModeChanged( true );
98 /* signals and slots connections */
99 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
100 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
102 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
104 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
105 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
106 connect( GroupPoints->PushButton4, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
107 connect( GroupPoints->PushButton5, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
109 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
110 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
112 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
113 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
114 connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( onReverse() ) );
116 connect( myGeomGUI->getApp()->selectionMgr(),
117 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
119 setHelpFileName( "rotation.htm" );
125 //=================================================================================
126 // function : ~TransformationGUI_RotationDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
131 // no need to delete child widgets, Qt does it all for us
135 //=================================================================================
138 //=================================================================================
139 void TransformationGUI_RotationDlg::Init()
142 myEditCurrentArgument = GroupPoints->LineEdit1;
143 GroupPoints->LineEdit2->clear();
145 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
147 initName( tr( "GEOM_ROTATION" ) );
148 ConstructorsClicked( 0 );
151 //=================================================================================
152 // function : ConstructorsClicked()
153 // purpose : Radio button management
154 //=================================================================================
155 void TransformationGUI_RotationDlg::ConstructorsClicked( int constructorId )
157 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
159 myEditCurrentArgument = GroupPoints->LineEdit1;
162 switch ( constructorId ) {
163 case 0: /* rotation an object angle and axis */
164 GroupPoints->ShowRows( 2, 3, false );
165 GroupPoints->TextLabel2->setText( tr( "GEOM_AXIS" ) );
166 GroupPoints->LineEdit2->clear();
167 GroupPoints->ShowRows( 4, 4, true );
168 myAxis = GEOM::GEOM_Object::_nil();
170 case 1: /* rotation an object by 3 points */
171 GroupPoints->ShowRows( 4, 4, false );
172 GroupPoints->ShowRows( 2, 3, true );
173 GroupPoints->TextLabel2->setText( tr( "GEOM_CENTRAL_POINT" ) );
174 GroupPoints->TextLabel4->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
175 GroupPoints->TextLabel5->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
176 GroupPoints->LineEdit2->clear();
177 GroupPoints->LineEdit4->clear();
178 GroupPoints->LineEdit5->clear();
179 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
183 qApp->processEvents();
185 resize( minimumSize() );
187 myEditCurrentArgument->setFocus();
188 connect( myGeomGUI->getApp()->selectionMgr(),
189 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
192 //=================================================================================
193 // function : ClickOnOk()
195 //=================================================================================
196 void TransformationGUI_RotationDlg::ClickOnOk()
198 if ( ClickOnApply() )
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool TransformationGUI_RotationDlg::ClickOnApply()
209 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
213 ConstructorsClicked( getConstructorId() );
218 //=================================================================================
219 // function : SelectionIntoArgument()
220 // purpose : Called when selection as changed or other case
221 //=================================================================================
222 void TransformationGUI_RotationDlg::SelectionIntoArgument()
224 myEditCurrentArgument->setText( "" );
227 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
228 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
230 myObjects.length( 0 );
233 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
234 if ( !myObjects.length() )
238 if ( IObjectCount() != 1 ) {
239 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 )
240 myAxis = GEOM::GEOM_Object::_nil();
241 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
242 myCentPoint = GEOM::GEOM_Object::_nil();
243 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
244 myPoint1 = GEOM::GEOM_Object::_nil();
245 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 )
246 myPoint2 = GEOM::GEOM_Object::_nil();
250 Standard_Boolean testResult = Standard_False;
251 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
252 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
255 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 )
256 myAxis = aSelectedObject;
257 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
258 myCentPoint = aSelectedObject;
259 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
260 myPoint1 = aSelectedObject;
261 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 )
262 myPoint2 = aSelectedObject;
264 aName = GEOMBase::GetName( aSelectedObject );
266 myEditCurrentArgument->setText( aName );
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
278 QPushButton* send = (QPushButton*)sender();
280 if ( send == GroupPoints->PushButton1 ) {
281 myEditCurrentArgument = GroupPoints->LineEdit1;
284 else if ( send == GroupPoints->PushButton2 ) {
285 myEditCurrentArgument = GroupPoints->LineEdit2;
286 getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
287 globalSelection( GEOM_POINT );
289 else if ( send == GroupPoints->PushButton4 ) {
290 myEditCurrentArgument = GroupPoints->LineEdit4;
291 globalSelection( GEOM_POINT );
293 else if ( send == GroupPoints->PushButton5 ) {
294 myEditCurrentArgument = GroupPoints->LineEdit5;
295 globalSelection( GEOM_POINT );
298 myEditCurrentArgument->setFocus();
299 SelectionIntoArgument();
303 //=================================================================================
304 // function : LineEditReturnPressed()
306 //=================================================================================
307 void TransformationGUI_RotationDlg::LineEditReturnPressed()
309 QLineEdit* send = (QLineEdit*)sender();
310 if ( send == GroupPoints->LineEdit1 ||
311 send == GroupPoints->LineEdit2 ) {
312 myEditCurrentArgument = send;
313 GEOMBase_Skeleton::LineEditReturnPressed();
318 //=================================================================================
319 // function : ActivateThisDialog()
321 //=================================================================================
322 void TransformationGUI_RotationDlg::ActivateThisDialog()
324 GEOMBase_Skeleton::ActivateThisDialog();
325 connect( myGeomGUI->getApp()->selectionMgr(),
326 SIGNAL( currentSelectionChanged() ) , this, SLOT( SelectionIntoArgument() ) );
328 ConstructorsClicked( getConstructorId() );
332 //=================================================================================
333 // function : enterEvent()
335 //=================================================================================
336 void TransformationGUI_RotationDlg::enterEvent( QEvent* )
338 if ( !mainFrame()->GroupConstructors->isEnabled() )
339 ActivateThisDialog();
343 //=================================================================================
344 // function : ValueChangedInSpinBox()
346 //=================================================================================
347 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
359 return getGeomEngine()->GetITransformOperations( getStudyId() );
363 //=================================================================================
364 // function : isValid
366 //=================================================================================
367 bool TransformationGUI_RotationDlg::isValid( QString& /*msg*/ )
369 switch ( getConstructorId() ) {
371 return !( myObjects.length() == 0 || myAxis->_is_nil() );
374 return !( myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
382 //=================================================================================
383 // function : execute
385 //=================================================================================
386 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
389 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
391 GEOM::GEOM_Object_var anObj;
393 switch ( getConstructorId() ) {
396 if ( toCreateCopy ) {
397 for ( int i = 0; i < myObjects.length(); i++ ) {
398 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
399 if ( !anObj->_is_nil() )
400 objects.push_back( anObj._retn() );
404 for ( int i = 0; i < myObjects.length(); i++ ) {
405 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
415 if ( toCreateCopy ) {
416 for ( int i = 0; i < myObjects.length(); i++ ) {
417 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
418 if ( !anObj->_is_nil() )
419 objects.push_back( anObj._retn() );
423 for ( int i = 0; i < myObjects.length(); i++ ) {
424 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
425 if ( !anObj->_is_nil() )
426 objects.push_back( anObj._retn() );
438 //=================================================================================
439 // function : closeEvent
441 //=================================================================================
442 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
444 GEOMBase_Skeleton::closeEvent( e );
448 //=================================================================================
449 // function : GetAngle()
451 //=================================================================================
452 double TransformationGUI_RotationDlg::GetAngle() const
454 return GroupPoints->SpinBox_DX->value();
458 //=================================================================================
459 // function : CreateCopyModeChanged()
461 //=================================================================================
462 void TransformationGUI_RotationDlg::CreateCopyModeChanged( bool isCreateCopy )
464 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
468 //=================================================================================
469 // function : onReverse()
471 //=================================================================================
472 void TransformationGUI_RotationDlg::onReverse()
474 double anOldValue = GroupPoints->SpinBox_DX->value();
475 GroupPoints->SpinBox_DX->setValue( -anOldValue );