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"
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_MultiRotationDlg()
41 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg
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_MULTIROTATION_SIMPLE" ) ) );
52 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_MULTIROTATION_DOUBLE" ) ) );
53 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_MULTIROTATION_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MULTIROTATION" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setIcon( image1 );
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
64 GroupPoints = new DlgRef_2Sel1Spin( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_MULTIROTATION_SIMPLE" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_NB_TIMES" ) );
69 GroupPoints->PushButton1->setIcon( image2 );
70 GroupPoints->PushButton2->setIcon( image2 );
71 GroupPoints->LineEdit1->setReadOnly( true );
72 GroupPoints->LineEdit2->setReadOnly( true );
74 GroupDimensions = new DlgRef_2Sel4Spin1Check( centralWidget() );
75 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_MULTIROTATION_DOUBLE" ) );
76 GroupDimensions->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
77 GroupDimensions->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
78 GroupDimensions->TextLabel3->setText( tr( "GEOM_ANGLE" ) );
79 GroupDimensions->TextLabel4->setText( tr( "GEOM_NB_TIMES" ) );
80 GroupDimensions->TextLabel5->setText( tr( "GEOM_STEP" ) );
81 GroupDimensions->TextLabel6->setText( tr( "GEOM_NB_TIMES" ) );
82 GroupDimensions->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
83 GroupDimensions->PushButton1->setIcon( image2 );
84 GroupDimensions->PushButton2->setIcon( image2 );
85 GroupDimensions->LineEdit1->setReadOnly( true );
86 GroupDimensions->LineEdit2->setReadOnly( true );
88 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
89 layout->setMargin( 0 ); layout->setSpacing( 6 );
90 layout->addWidget( GroupPoints );
91 layout->addWidget( GroupDimensions );
92 /***************************************************************/
94 setHelpFileName( "multi_rotation.htm" );
100 //=================================================================================
101 // function : ~TransformationGUI_MultiRotationDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
106 // no need to delete child widgets, Qt does it all for us
110 //=================================================================================
113 //=================================================================================
114 void TransformationGUI_MultiRotationDlg::Init()
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 double SpecificStep1 = 5;
121 double SpecificStep2 = 1;
122 /* min, max, step and decimals for spin boxes & initial values */
123 initSpinBox( GroupPoints->SpinBox_DX, 1.0, MAX_NUMBER, SpecificStep2, 3 );
124 GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
126 initSpinBox( GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, SpecificStep1, 3 );
127 initSpinBox( GroupDimensions->SpinBox_DY1, 1.0, MAX_NUMBER, SpecificStep2, 3 );
128 initSpinBox( GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 3 );
129 initSpinBox( GroupDimensions->SpinBox_DY2, 1.0, MAX_NUMBER, SpecificStep2, 3 );
130 GroupDimensions->SpinBox_DX1->setValue( myAng );
131 GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
132 GroupDimensions->SpinBox_DX2->setValue( myStep );
133 GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
135 /* signals and slots connections */
136 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
137 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
139 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
141 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
142 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( GroupDimensions->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( GroupDimensions->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
147 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
148 connect( GroupDimensions->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149 connect( GroupDimensions->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
151 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
152 connect( GroupDimensions->SpinBox_DX1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
153 connect( GroupDimensions->SpinBox_DY1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
154 connect( GroupDimensions->SpinBox_DX2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
155 connect( GroupDimensions->SpinBox_DY2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
158 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
159 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX1, SLOT( SetStep( double ) ) );
160 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY1, SLOT( SetStep( double ) ) );
161 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX2, SLOT( SetStep( double ) ) );
162 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY2, SLOT( SetStep( double ) ) );
165 connect( GroupDimensions->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseAngle() ) );
167 connect( myGeomGUI->getApp()->selectionMgr(),
168 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
170 initName( tr( "GEOM_MULTIROTATION" ) );
172 ConstructorsClicked( 0 );
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void TransformationGUI_MultiRotationDlg::ConstructorsClicked( int constructorId )
182 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
186 myNbTimes1 = myNbTimes2 = 2;
188 globalSelection( GEOM_ALLSHAPES );
190 switch ( constructorId ) {
191 case 0: /* Rotate simple */
193 GroupDimensions->hide();
196 myEditCurrentArgument = GroupPoints->LineEdit1;
197 GroupPoints->LineEdit1->setText( "" );
198 GroupPoints->LineEdit2->setText( "" );
200 GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
204 case 1: /* Rotate double */
207 GroupDimensions->show();
209 myEditCurrentArgument = GroupDimensions->LineEdit1;
210 GroupDimensions->LineEdit1->setText( "" );
211 GroupDimensions->LineEdit2->setText( "" );
213 GroupDimensions->SpinBox_DX1->setValue( myAng );
214 GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
215 GroupDimensions->SpinBox_DX2->setValue( myStep );
216 GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
222 qApp->processEvents();
224 resize( minimumSize() );
226 myEditCurrentArgument->setFocus();
227 myBase = myVector = GEOM::GEOM_Object::_nil();
228 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
229 this, SLOT( SelectionIntoArgument() ) );
233 //=================================================================================
234 // function : ClickOnOk()
236 //=================================================================================
237 void TransformationGUI_MultiRotationDlg::ClickOnOk()
239 if ( ClickOnApply() )
244 //=================================================================================
245 // function : ClickOnApply()
247 //=================================================================================
248 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
254 ConstructorsClicked( getConstructorId() );
259 //=================================================================================
260 // function : SelectionIntoArgument()
261 // purpose : Called when selection as changed or other case
262 //=================================================================================
263 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
265 myEditCurrentArgument->setText( "" );
267 if ( IObjectCount() != 1 ) {
268 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
269 myEditCurrentArgument == GroupDimensions->LineEdit1 )
270 myBase = GEOM::GEOM_Object::_nil();
271 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
272 myEditCurrentArgument == GroupDimensions->LineEdit2 )
273 myVector = GEOM::GEOM_Object::_nil();
278 Standard_Boolean testResult = Standard_False;;
279 GEOM::GEOM_Object_var aSelectedObject =
280 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
282 if ( !testResult || CORBA::is_nil( aSelectedObject) || !GEOMBase::IsShape( aSelectedObject ) )
285 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
286 myEditCurrentArgument == GroupDimensions->LineEdit1 )
287 myBase = aSelectedObject;
288 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
289 myEditCurrentArgument == GroupDimensions->LineEdit2 )
290 myVector = aSelectedObject;
292 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
298 //=================================================================================
299 // function : SetEditCurrentArgument()
301 //=================================================================================
302 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
304 QPushButton* send = (QPushButton*)sender();
306 if ( send == GroupPoints->PushButton1 ) {
307 myEditCurrentArgument = GroupPoints->LineEdit1;
308 globalSelection( GEOM_ALLSHAPES );
310 else if ( send == GroupPoints->PushButton2 ) {
311 myEditCurrentArgument = GroupPoints->LineEdit2;
312 globalSelection( GEOM_LINE );
314 else if ( send == GroupDimensions->PushButton1 ) {
315 myEditCurrentArgument = GroupDimensions->LineEdit1;
316 globalSelection( GEOM_ALLSHAPES );
318 else if ( send == GroupDimensions->PushButton2 ) {
319 myEditCurrentArgument = GroupDimensions->LineEdit2;
320 globalSelection( GEOM_LINE );
323 myEditCurrentArgument->setFocus();
324 SelectionIntoArgument();
328 //=================================================================================
329 // function : LineEditReturnPressed()
331 //=================================================================================
332 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
334 QLineEdit* send = (QLineEdit*)sender();
335 if ( send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
336 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ) {
337 myEditCurrentArgument = send;
338 GEOMBase_Skeleton::LineEditReturnPressed();
343 //=================================================================================
344 // function : ActivateThisDialog()
346 //=================================================================================
347 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
349 GEOMBase_Skeleton::ActivateThisDialog();
350 connect( myGeomGUI->getApp()->selectionMgr(),
351 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
353 ConstructorsClicked( getConstructorId() );
357 //=================================================================================
358 // function : enterEvent()
360 //=================================================================================
361 void TransformationGUI_MultiRotationDlg::enterEvent( QEvent* )
363 if ( !mainFrame()->GroupConstructors->isEnabled() )
364 ActivateThisDialog();
368 //=================================================================================
369 // function : ValueChangedInSpinBox()
371 //=================================================================================
372 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox( double newValue )
374 QObject* send = (QObject*)sender();
376 if ( send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1 )
377 myNbTimes1 = (int)newValue;
378 else if ( send == GroupDimensions->SpinBox_DX1 )
380 else if ( send == GroupDimensions->SpinBox_DX2 )
382 else if ( send == GroupDimensions->SpinBox_DY2 )
383 myNbTimes2 = (int)newValue;
389 //=================================================================================
390 // function : ReverseAngle()
391 // purpose : 'state' not used here
392 //=================================================================================
393 void TransformationGUI_MultiRotationDlg::ReverseAngle()
397 int aConstructorId = getConstructorId();
399 if ( aConstructorId == 0 )
400 GroupPoints->SpinBox_DX->setValue( myAng );
401 else if ( aConstructorId == 1 )
402 GroupDimensions->SpinBox_DX1->setValue( myAng );
408 //=================================================================================
409 // function : createOperation
411 //=================================================================================
412 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
414 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
418 //=================================================================================
419 // function : isValid
421 //=================================================================================
422 bool TransformationGUI_MultiRotationDlg::isValid( QString& /*msg*/ )
424 return !( myBase->_is_nil() || myVector->_is_nil() );
427 //=================================================================================
428 // function : execute
430 //=================================================================================
431 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
435 GEOM::GEOM_Object_var anObj;
437 switch ( getConstructorId() ) {
439 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
440 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
441 MultiRotate1D( myBase, myVector, myNbTimes1 );
446 if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
447 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
448 MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
454 if ( !anObj->_is_nil() )
455 objects.push_back( anObj._retn() );
461 //=================================================================================
462 // function : closeEvent
464 //=================================================================================
465 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
467 // myGeomGUI->SetState( -1 );
468 GEOMBase_Skeleton::closeEvent( e );