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 <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_RotationDlg()
48 // purpose : Constructs a TransformationGUI_RotationDlg 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_RotationDlg::TransformationGUI_RotationDlg
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_ROTATION" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ROTATION_THREE_POINTS" ) ) );
62 setWindowTitle( tr( "GEOM_ROTATION_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ROTATION" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image2 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_4Sel1Spin2Check( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_AXIS" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_ANGLE" ) );
76 GroupPoints->TextLabel4->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
77 GroupPoints->TextLabel5->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
79 GroupPoints->LineEdit1->setReadOnly( true );
80 GroupPoints->LineEdit2->setReadOnly( true );
81 GroupPoints->LineEdit4->setReadOnly( true );
82 GroupPoints->LineEdit5->setReadOnly( true );
83 GroupPoints->PushButton1->setIcon( image1 );
84 GroupPoints->PushButton2->setIcon( image1 );
85 GroupPoints->PushButton4->setIcon( image1 );
86 GroupPoints->PushButton5->setIcon( image1 );
87 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
88 GroupPoints->CheckButton2->setText( tr( "GEOM_REVERSE" ) );
90 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
91 layout->setMargin( 0 ); layout->setSpacing( 6 );
92 layout->addWidget( GroupPoints );
94 /***************************************************************/
96 double SpecificStep = 5;
97 /* min, max, step and decimals for spin boxes & initial values */
98 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
99 GroupPoints->SpinBox_DX->setValue( anAngle );
101 // Activate Create a Copy mode
102 GroupPoints->CheckButton1->setChecked( true );
103 CreateCopyModeChanged( true );
105 /* signals and slots connections */
106 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
107 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
109 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
111 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
112 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect( GroupPoints->PushButton4, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114 connect( GroupPoints->PushButton5, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
117 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
119 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
120 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
121 connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( onReverse() ) );
123 connect( myGeomGUI->getApp()->selectionMgr(),
124 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
126 setHelpFileName( "rotation_operation_page.html" );
132 //=================================================================================
133 // function : ~TransformationGUI_RotationDlg()
134 // purpose : Destroys the object and frees any allocated resources
135 //=================================================================================
136 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
138 // no need to delete child widgets, Qt does it all for us
142 //=================================================================================
145 //=================================================================================
146 void TransformationGUI_RotationDlg::Init()
149 myEditCurrentArgument = GroupPoints->LineEdit1;
150 GroupPoints->LineEdit2->clear();
152 myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
154 initName( tr( "GEOM_ROTATION" ) );
155 ConstructorsClicked( 0 );
158 //=================================================================================
159 // function : ConstructorsClicked()
160 // purpose : Radio button management
161 //=================================================================================
162 void TransformationGUI_RotationDlg::ConstructorsClicked( int constructorId )
164 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
166 myEditCurrentArgument = GroupPoints->LineEdit1;
169 switch ( constructorId ) {
170 case 0: /* rotation an object angle and axis */
171 GroupPoints->ShowRows( 2, 3, false );
172 GroupPoints->TextLabel2->setText( tr( "GEOM_AXIS" ) );
173 GroupPoints->LineEdit2->clear();
174 GroupPoints->ShowRows( 4, 4, true );
175 myAxis = GEOM::GEOM_Object::_nil();
177 case 1: /* rotation an object by 3 points */
178 GroupPoints->ShowRows( 4, 4, false );
179 GroupPoints->ShowRows( 2, 3, true );
180 GroupPoints->TextLabel2->setText( tr( "GEOM_CENTRAL_POINT" ) );
181 GroupPoints->TextLabel4->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
182 GroupPoints->TextLabel5->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
183 GroupPoints->LineEdit2->clear();
184 GroupPoints->LineEdit4->clear();
185 GroupPoints->LineEdit5->clear();
186 myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
190 qApp->processEvents();
192 resize( minimumSize() );
194 myEditCurrentArgument->setFocus();
195 connect( myGeomGUI->getApp()->selectionMgr(),
196 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void TransformationGUI_RotationDlg::ClickOnOk()
205 if ( ClickOnApply() )
210 //=================================================================================
211 // function : ClickOnApply()
213 //=================================================================================
214 bool TransformationGUI_RotationDlg::ClickOnApply()
216 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
220 ConstructorsClicked( getConstructorId() );
225 //=================================================================================
226 // function : SelectionIntoArgument()
227 // purpose : Called when selection as changed or other case
228 //=================================================================================
229 void TransformationGUI_RotationDlg::SelectionIntoArgument()
231 myEditCurrentArgument->setText( "" );
234 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
235 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
237 myObjects.length( 0 );
240 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
241 if ( !myObjects.length() )
245 if ( IObjectCount() != 1 ) {
246 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 )
247 myAxis = GEOM::GEOM_Object::_nil();
248 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
249 myCentPoint = GEOM::GEOM_Object::_nil();
250 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
251 myPoint1 = GEOM::GEOM_Object::_nil();
252 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 )
253 myPoint2 = GEOM::GEOM_Object::_nil();
257 Standard_Boolean testResult = Standard_False;
258 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
259 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
262 aName = GEOMBase::GetName( aSelectedObject );
264 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
265 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
266 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 )
267 aNeedType = TopAbs_EDGE;
269 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
270 TColStd_IndexedMapOfInteger aMap;
271 aSelMgr->GetIndexes( firstIObject(), aMap );
272 if ( aMap.Extent() == 1 ) {
273 int anIndex = aMap( 1 );
274 if ( aNeedType == TopAbs_EDGE )
275 aName += QString( ":edge_%1" ).arg( anIndex );
277 aName += QString( ":vertex_%1" ).arg( anIndex );
279 //Find SubShape Object in Father
280 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
282 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
283 GEOM::GEOM_IShapesOperations_var aShapesOp =
284 getGeomEngine()->GetIShapesOperations( getStudyId() );
285 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
288 aSelectedObject = aFindedObject; // get Object from study
292 if ( aShape.ShapeType() != aNeedType ) {
293 aSelectedObject = GEOM::GEOM_Object::_nil();
299 if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 )
300 myAxis = aSelectedObject;
301 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1 )
302 myCentPoint = aSelectedObject;
303 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
304 myPoint1 = aSelectedObject;
305 else if ( myEditCurrentArgument == GroupPoints->LineEdit5 )
306 myPoint2 = aSelectedObject;
308 myEditCurrentArgument->setText( aName );
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
320 QPushButton* send = (QPushButton*)sender();
323 if ( send == GroupPoints->PushButton1 ) {
324 myEditCurrentArgument = GroupPoints->LineEdit1;
326 else if ( send == GroupPoints->PushButton2 ) {
327 myEditCurrentArgument = GroupPoints->LineEdit2;
328 if ( getConstructorId() == 0 )
329 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
331 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
333 else if ( send == GroupPoints->PushButton4 ) {
334 myEditCurrentArgument = GroupPoints->LineEdit4;
335 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
337 else if ( send == GroupPoints->PushButton5 ) {
338 myEditCurrentArgument = GroupPoints->LineEdit5;
339 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
342 myEditCurrentArgument->setFocus();
343 SelectionIntoArgument();
347 //=================================================================================
348 // function : LineEditReturnPressed()
350 //=================================================================================
351 void TransformationGUI_RotationDlg::LineEditReturnPressed()
353 QLineEdit* send = (QLineEdit*)sender();
354 if ( send == GroupPoints->LineEdit1 ||
355 send == GroupPoints->LineEdit2 ) {
356 myEditCurrentArgument = send;
357 GEOMBase_Skeleton::LineEditReturnPressed();
362 //=================================================================================
363 // function : ActivateThisDialog()
365 //=================================================================================
366 void TransformationGUI_RotationDlg::ActivateThisDialog()
368 GEOMBase_Skeleton::ActivateThisDialog();
369 connect( myGeomGUI->getApp()->selectionMgr(),
370 SIGNAL( currentSelectionChanged() ) , this, SLOT( SelectionIntoArgument() ) );
372 ConstructorsClicked( getConstructorId() );
376 //=================================================================================
377 // function : enterEvent()
379 //=================================================================================
380 void TransformationGUI_RotationDlg::enterEvent( QEvent* )
382 if ( !mainFrame()->GroupConstructors->isEnabled() )
383 ActivateThisDialog();
387 //=================================================================================
388 // function : ValueChangedInSpinBox()
390 //=================================================================================
391 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
397 //=================================================================================
398 // function : createOperation
400 //=================================================================================
401 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
403 return getGeomEngine()->GetITransformOperations( getStudyId() );
407 //=================================================================================
408 // function : isValid
410 //=================================================================================
411 bool TransformationGUI_RotationDlg::isValid( QString& /*msg*/ )
413 switch ( getConstructorId() ) {
415 return !( myObjects.length() == 0 || myAxis->_is_nil() );
418 return !( myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
426 //=================================================================================
427 // function : execute
429 //=================================================================================
430 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
433 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
435 GEOM::GEOM_Object_var anObj;
437 switch ( getConstructorId() ) {
440 if ( toCreateCopy ) {
441 for ( int i = 0; i < myObjects.length(); i++ ) {
442 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
443 if ( !anObj->_is_nil() )
444 objects.push_back( anObj._retn() );
448 for ( int i = 0; i < myObjects.length(); i++ ) {
449 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
450 if ( !anObj->_is_nil() )
451 objects.push_back( anObj._retn() );
459 if ( toCreateCopy ) {
460 for ( int i = 0; i < myObjects.length(); i++ ) {
461 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
462 if ( !anObj->_is_nil() )
463 objects.push_back( anObj._retn() );
467 for ( int i = 0; i < myObjects.length(); i++ ) {
468 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
469 if ( !anObj->_is_nil() )
470 objects.push_back( anObj._retn() );
482 //=================================================================================
483 // function : GetAngle()
485 //=================================================================================
486 double TransformationGUI_RotationDlg::GetAngle() const
488 return GroupPoints->SpinBox_DX->value();
492 //=================================================================================
493 // function : CreateCopyModeChanged()
495 //=================================================================================
496 void TransformationGUI_RotationDlg::CreateCopyModeChanged( bool isCreateCopy )
498 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
502 //=================================================================================
503 // function : onReverse()
505 //=================================================================================
506 void TransformationGUI_RotationDlg::onReverse()
508 double anOldValue = GroupPoints->SpinBox_DX->value();
509 GroupPoints->SpinBox_DX->setValue( -anOldValue );
512 //=================================================================================
513 // function : addSubshapeToStudy
514 // purpose : virtual method to add new SubObjects if local selection
515 //=================================================================================
516 void TransformationGUI_RotationDlg::addSubshapesToStudy()
518 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
519 if ( toCreateCopy ) {
520 QMap<QString, GEOM::GEOM_Object_var> objMap;
521 switch ( getConstructorId() ) {
523 objMap[GroupPoints->LineEdit2->text()] = myAxis;
526 objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
527 objMap[GroupPoints->LineEdit4->text()] = myPoint1;
528 objMap[GroupPoints->LineEdit5->text()] = myPoint2;
531 addSubshapesToFather( objMap );