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_MultiRotationDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "TransformationGUI_MultiRotationDlg.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_MultiRotationDlg()
48 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg
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_MULTIROTATION_SIMPLE" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTIROTATION_DOUBLE" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_MULTIROTATION_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MULTIROTATION" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_2Sel1Spin( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_MULTIROTATION_SIMPLE" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_NB_TIMES" ) );
76 GroupPoints->PushButton1->setIcon( image2 );
77 GroupPoints->PushButton2->setIcon( image2 );
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
81 GroupDimensions = new DlgRef_2Sel4Spin1Check( centralWidget() );
82 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_MULTIROTATION_DOUBLE" ) );
83 GroupDimensions->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
84 GroupDimensions->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
85 GroupDimensions->TextLabel3->setText( tr( "GEOM_ANGLE" ) );
86 GroupDimensions->TextLabel4->setText( tr( "GEOM_NB_TIMES" ) );
87 GroupDimensions->TextLabel5->setText( tr( "GEOM_STEP" ) );
88 GroupDimensions->TextLabel6->setText( tr( "GEOM_NB_TIMES" ) );
89 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
90 GroupDimensions->PushButton1->setIcon( image2 );
91 GroupDimensions->PushButton2->setIcon( image2 );
92 GroupDimensions->LineEdit1->setReadOnly( true );
93 GroupDimensions->LineEdit2->setReadOnly( true );
95 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
96 layout->setMargin( 0 ); layout->setSpacing( 6 );
97 layout->addWidget( GroupPoints );
98 layout->addWidget( GroupDimensions );
99 /***************************************************************/
101 setHelpFileName( "multi_rotation_operation_page.html" );
107 //=================================================================================
108 // function : ~TransformationGUI_MultiRotationDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
113 // no need to delete child widgets, Qt does it all for us
117 //=================================================================================
120 //=================================================================================
121 void TransformationGUI_MultiRotationDlg::Init()
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 double SpecificStep1 = 5;
128 double SpecificStep2 = 1;
129 /* min, max, step and decimals for spin boxes & initial values */
130 initSpinBox( GroupPoints->SpinBox_DX, 1.0, MAX_NUMBER, SpecificStep2, 10 );
131 GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
133 initSpinBox( GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, SpecificStep1, 10 ); // VSR: TODO: DBL_DIGITS_DISPLAY
134 initSpinBox( GroupDimensions->SpinBox_DY1, 1.0, MAX_NUMBER, SpecificStep2, 10 );
135 initSpinBox( GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 10 ); // VSR: TODO: DBL_DIGITS_DISPLAY
136 initSpinBox( GroupDimensions->SpinBox_DY2, 1.0, MAX_NUMBER, SpecificStep2, 10 );
137 GroupDimensions->SpinBox_DX1->setValue( myAng );
138 GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
139 GroupDimensions->SpinBox_DX2->setValue( myStep );
140 GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
142 /* signals and slots connections */
143 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
144 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
146 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
148 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
149 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
150 connect( GroupDimensions->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151 connect( GroupDimensions->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
153 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
154 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155 connect( GroupDimensions->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156 connect( GroupDimensions->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
159 connect( GroupDimensions->SpinBox_DX1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
160 connect( GroupDimensions->SpinBox_DY1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
161 connect( GroupDimensions->SpinBox_DX2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
162 connect( GroupDimensions->SpinBox_DY2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
165 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
166 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX1, SLOT( SetStep( double ) ) );
167 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY1, SLOT( SetStep( double ) ) );
168 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX2, SLOT( SetStep( double ) ) );
169 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY2, SLOT( SetStep( double ) ) );
172 connect( GroupDimensions->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseAngle() ) );
174 connect( myGeomGUI->getApp()->selectionMgr(),
175 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
177 initName( tr( "GEOM_MULTIROTATION" ) );
179 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose : Radio button management
186 //=================================================================================
187 void TransformationGUI_MultiRotationDlg::ConstructorsClicked( int constructorId )
189 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
193 myNbTimes1 = myNbTimes2 = 2;
195 globalSelection( GEOM_ALLSHAPES );
197 switch ( constructorId ) {
198 case 0: /* Rotate simple */
200 GroupDimensions->hide();
203 myEditCurrentArgument = GroupPoints->LineEdit1;
204 GroupPoints->LineEdit1->setText( "" );
205 GroupPoints->LineEdit2->setText( "" );
207 GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
211 case 1: /* Rotate double */
214 GroupDimensions->show();
216 myEditCurrentArgument = GroupDimensions->LineEdit1;
217 GroupDimensions->LineEdit1->setText( "" );
218 GroupDimensions->LineEdit2->setText( "" );
220 GroupDimensions->SpinBox_DX1->setValue( myAng );
221 GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
222 GroupDimensions->SpinBox_DX2->setValue( myStep );
223 GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
229 qApp->processEvents();
231 resize( minimumSize() );
233 myEditCurrentArgument->setFocus();
234 myBase = myVector = GEOM::GEOM_Object::_nil();
235 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
236 this, SLOT( SelectionIntoArgument() ) );
240 //=================================================================================
241 // function : ClickOnOk()
243 //=================================================================================
244 void TransformationGUI_MultiRotationDlg::ClickOnOk()
246 if ( ClickOnApply() )
251 //=================================================================================
252 // function : ClickOnApply()
254 //=================================================================================
255 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
261 ConstructorsClicked( getConstructorId() );
266 //=================================================================================
267 // function : SelectionIntoArgument()
268 // purpose : Called when selection as changed or other case
269 //=================================================================================
270 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
272 myEditCurrentArgument->setText( "" );
274 if ( IObjectCount() != 1 ) {
275 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
276 myEditCurrentArgument == GroupDimensions->LineEdit1 )
277 myBase = GEOM::GEOM_Object::_nil();
278 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
279 myEditCurrentArgument == GroupDimensions->LineEdit2 )
280 myVector = GEOM::GEOM_Object::_nil();
285 Standard_Boolean testResult = Standard_False;;
286 GEOM::GEOM_Object_var aSelectedObject =
287 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
289 if ( !testResult || CORBA::is_nil( aSelectedObject) || !GEOMBase::IsShape( aSelectedObject ) )
292 QString aName = GEOMBase::GetName( aSelectedObject );
294 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
295 myEditCurrentArgument == GroupDimensions->LineEdit1 )
296 myBase = aSelectedObject;
297 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
298 myEditCurrentArgument == GroupDimensions->LineEdit2 ) {
299 if ( testResult && !aSelectedObject->_is_nil() ) {
302 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
303 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
304 TColStd_IndexedMapOfInteger aMap;
305 aSelMgr->GetIndexes( firstIObject(), aMap );
306 if ( aMap.Extent() == 1 ) {
307 int anIndex = aMap( 1 );
308 aName += QString( ":edge_%1" ).arg( anIndex );
310 //Find SubShape Object in Father
311 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
313 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
314 GEOM::GEOM_IShapesOperations_var aShapesOp =
315 getGeomEngine()->GetIShapesOperations( getStudyId() );
316 myVector = aShapesOp->GetSubShape(aSelectedObject, anIndex);
319 myVector = aFindedObject; // get existing object
323 if ( aShape.ShapeType() != TopAbs_EDGE ) {
324 aSelectedObject = GEOM::GEOM_Object::_nil();
327 myVector = aSelectedObject;
332 myEditCurrentArgument->setText( aName );
338 //=================================================================================
339 // function : SetEditCurrentArgument()
341 //=================================================================================
342 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
344 QPushButton* send = (QPushButton*)sender();
345 globalSelection( GEOM_ALLSHAPES );
347 if ( send == GroupPoints->PushButton1 ) {
348 myEditCurrentArgument = GroupPoints->LineEdit1;
350 else if ( send == GroupPoints->PushButton2 ) {
351 myEditCurrentArgument = GroupPoints->LineEdit2;
352 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
354 else if ( send == GroupDimensions->PushButton1 ) {
355 myEditCurrentArgument = GroupDimensions->LineEdit1;
357 else if ( send == GroupDimensions->PushButton2 ) {
358 myEditCurrentArgument = GroupDimensions->LineEdit2;
359 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
362 myEditCurrentArgument->setFocus();
363 SelectionIntoArgument();
367 //=================================================================================
368 // function : LineEditReturnPressed()
370 //=================================================================================
371 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
373 QLineEdit* send = (QLineEdit*)sender();
374 if ( send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
375 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ) {
376 myEditCurrentArgument = send;
377 GEOMBase_Skeleton::LineEditReturnPressed();
382 //=================================================================================
383 // function : ActivateThisDialog()
385 //=================================================================================
386 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
388 GEOMBase_Skeleton::ActivateThisDialog();
389 connect( myGeomGUI->getApp()->selectionMgr(),
390 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
392 ConstructorsClicked( getConstructorId() );
396 //=================================================================================
397 // function : enterEvent()
399 //=================================================================================
400 void TransformationGUI_MultiRotationDlg::enterEvent( QEvent* )
402 if ( !mainFrame()->GroupConstructors->isEnabled() )
403 ActivateThisDialog();
407 //=================================================================================
408 // function : ValueChangedInSpinBox()
410 //=================================================================================
411 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox( double newValue )
413 QObject* send = (QObject*)sender();
415 if ( send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1 )
416 myNbTimes1 = (int)newValue;
417 else if ( send == GroupDimensions->SpinBox_DX1 )
419 else if ( send == GroupDimensions->SpinBox_DX2 )
421 else if ( send == GroupDimensions->SpinBox_DY2 )
422 myNbTimes2 = (int)newValue;
428 //=================================================================================
429 // function : ReverseAngle()
430 // purpose : 'state' not used here
431 //=================================================================================
432 void TransformationGUI_MultiRotationDlg::ReverseAngle()
436 int aConstructorId = getConstructorId();
438 if ( aConstructorId == 0 )
439 GroupPoints->SpinBox_DX->setValue( myAng );
440 else if ( aConstructorId == 1 )
441 GroupDimensions->SpinBox_DX1->setValue( myAng );
447 //=================================================================================
448 // function : createOperation
450 //=================================================================================
451 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
453 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
457 //=================================================================================
458 // function : isValid
460 //=================================================================================
461 bool TransformationGUI_MultiRotationDlg::isValid( QString& /*msg*/ )
463 return !( myBase->_is_nil() || myVector->_is_nil() );
466 //=================================================================================
467 // function : execute
469 //=================================================================================
470 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
474 GEOM::GEOM_Object_var anObj;
476 switch ( getConstructorId() ) {
478 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
479 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
480 MultiRotate1D( myBase, myVector, myNbTimes1 );
485 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
486 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
487 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
493 if ( !anObj->_is_nil() )
494 objects.push_back( anObj._retn() );
499 //=================================================================================
500 // function : addSubshapeToStudy
501 // purpose : virtual method to add new SubObjects if local selection
502 //=================================================================================
503 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
505 QMap<QString, GEOM::GEOM_Object_var> objMap;
507 switch ( getConstructorId() ) {
509 objMap[GroupPoints->LineEdit2->text()] = myVector;
512 objMap[GroupDimensions->LineEdit2->text()] = myVector;
515 addSubshapesToFather( objMap );