]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx
Salome HOME
*** empty log message ***
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MultiRotationDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : TransformationGUI_MultiRotationDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
24 //
25
26 #include "TransformationGUI_MultiRotationDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
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 )
49 {
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" ) ) );
54
55   setWindowTitle( tr( "GEOM_MULTIROTATION_TITLE" ) );
56
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();
63
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 );
73
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 );
87
88   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
89   layout->setMargin( 0 ); layout->setSpacing( 6 );
90   layout->addWidget( GroupPoints );
91   layout->addWidget( GroupDimensions );
92   /***************************************************************/
93
94   setHelpFileName( "multi_rotation.htm" );
95
96   Init();
97 }
98
99
100 //=================================================================================
101 // function : ~TransformationGUI_MultiRotationDlg()
102 // purpose  : Destroys the object and frees any allocated resources
103 //=================================================================================
104 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
105 {
106   // no need to delete child widgets, Qt does it all for us
107 }
108
109
110 //=================================================================================
111 // function : Init()
112 // purpose  :
113 //=================================================================================
114 void TransformationGUI_MultiRotationDlg::Init()
115 {
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 );
119
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 );
125
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 );
134
135   /* signals and slots connections */
136   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
137   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
138
139   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
140
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() ) );
145
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() ) );
150
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 ) ) );
156
157   // VSR: TODO ->>
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 ) ) );
163   // <<-
164
165   connect( GroupDimensions->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseAngle() ) );
166   
167   connect( myGeomGUI->getApp()->selectionMgr(), 
168            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
169
170   initName( tr( "GEOM_MULTIROTATION" ) );
171
172   ConstructorsClicked( 0 );
173 }
174
175
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose  : Radio button management
179 //=================================================================================
180 void TransformationGUI_MultiRotationDlg::ConstructorsClicked( int constructorId )
181 {
182   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
183
184   myAng = 45.0;
185   myStep = 50.0;
186   myNbTimes1 = myNbTimes2 = 2;
187
188   globalSelection( GEOM_ALLSHAPES );
189
190   switch ( constructorId ) {
191   case 0: /* Rotate simple */
192     {
193       GroupDimensions->hide();
194       GroupPoints->show();
195
196       myEditCurrentArgument = GroupPoints->LineEdit1;
197       GroupPoints->LineEdit1->setText( "" );
198       GroupPoints->LineEdit2->setText( "" );
199       
200       GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
201       
202       break;
203     }
204   case 1: /* Rotate double */
205     {
206       GroupPoints->hide();
207       GroupDimensions->show();
208       
209       myEditCurrentArgument = GroupDimensions->LineEdit1;
210       GroupDimensions->LineEdit1->setText( "" );
211       GroupDimensions->LineEdit2->setText( "" );
212       
213       GroupDimensions->SpinBox_DX1->setValue( myAng );
214       GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
215       GroupDimensions->SpinBox_DX2->setValue( myStep );
216       GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
217       
218       break;
219     }      
220   }
221
222   qApp->processEvents();
223   updateGeometry();
224   resize( minimumSize() );
225
226   myEditCurrentArgument->setFocus();
227   myBase = myVector = GEOM::GEOM_Object::_nil();
228   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
229            this, SLOT( SelectionIntoArgument() ) );
230 }
231
232
233 //=================================================================================
234 // function : ClickOnOk()
235 // purpose  :
236 //=================================================================================
237 void TransformationGUI_MultiRotationDlg::ClickOnOk()
238 {
239   if ( ClickOnApply() )
240     ClickOnCancel();
241 }
242
243
244 //=================================================================================
245 // function : ClickOnApply()
246 // purpose  :
247 //=================================================================================
248 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
249 {
250   if ( !onAccept() )
251     return false;
252   
253   initName();
254   ConstructorsClicked( getConstructorId() );
255   return true;
256 }
257
258
259 //=================================================================================
260 // function : SelectionIntoArgument()
261 // purpose  : Called when selection as changed or other case
262 //=================================================================================
263 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
264 {
265   myEditCurrentArgument->setText( "" );
266
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();
274     return;
275   }
276
277   // nbSel == 1
278   Standard_Boolean testResult = Standard_False;;
279   GEOM::GEOM_Object_var aSelectedObject =
280     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
281
282   if ( !testResult || CORBA::is_nil( aSelectedObject) || !GEOMBase::IsShape( aSelectedObject ) )
283     return;
284
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;
291
292   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
293
294   displayPreview();
295 }
296
297
298 //=================================================================================
299 // function : SetEditCurrentArgument()
300 // purpose  :
301 //=================================================================================
302 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
303 {
304   QPushButton* send = (QPushButton*)sender();
305   
306   if ( send == GroupPoints->PushButton1 ) {
307     myEditCurrentArgument = GroupPoints->LineEdit1;
308     globalSelection( GEOM_ALLSHAPES );
309   }
310   else if ( send == GroupPoints->PushButton2 ) {
311     myEditCurrentArgument = GroupPoints->LineEdit2;
312     globalSelection( GEOM_LINE  );
313   }
314   else if ( send == GroupDimensions->PushButton1 ) {
315     myEditCurrentArgument = GroupDimensions->LineEdit1;
316     globalSelection( GEOM_ALLSHAPES );
317   }
318   else if ( send == GroupDimensions->PushButton2 ) {
319     myEditCurrentArgument = GroupDimensions->LineEdit2;
320     globalSelection( GEOM_LINE  );
321   }
322
323   myEditCurrentArgument->setFocus();
324   SelectionIntoArgument();
325 }
326
327
328 //=================================================================================
329 // function : LineEditReturnPressed()
330 // purpose  :
331 //=================================================================================
332 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
333 {
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();
339   }
340 }
341
342
343 //=================================================================================
344 // function : ActivateThisDialog()
345 // purpose  :
346 //=================================================================================
347 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
348 {
349   GEOMBase_Skeleton::ActivateThisDialog();
350   connect( myGeomGUI->getApp()->selectionMgr(), 
351            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
352   
353   ConstructorsClicked( getConstructorId() );
354 }
355
356
357 //=================================================================================
358 // function : enterEvent()
359 // purpose  :
360 //=================================================================================
361 void TransformationGUI_MultiRotationDlg::enterEvent( QEvent* )
362 {
363   if ( !mainFrame()->GroupConstructors->isEnabled() )
364     ActivateThisDialog();
365 }
366
367
368 //=================================================================================
369 // function : ValueChangedInSpinBox()
370 // purpose  :
371 //=================================================================================
372 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox( double newValue )
373 {
374   QObject* send = (QObject*)sender();
375
376   if ( send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1 )
377     myNbTimes1 = (int)newValue;
378   else if ( send == GroupDimensions->SpinBox_DX1 )
379     myAng = newValue;
380   else if ( send == GroupDimensions->SpinBox_DX2 )
381     myStep = newValue;
382   else if ( send == GroupDimensions->SpinBox_DY2 )
383     myNbTimes2 = (int)newValue;
384   
385   displayPreview();
386 }
387
388
389 //=================================================================================
390 // function : ReverseAngle()
391 // purpose  : 'state' not used here
392 //=================================================================================
393 void TransformationGUI_MultiRotationDlg::ReverseAngle()
394 {
395   myAng = -myAng;
396
397   int aConstructorId = getConstructorId();
398
399   if ( aConstructorId == 0 )
400     GroupPoints->SpinBox_DX->setValue( myAng );
401   else if ( aConstructorId == 1 )
402     GroupDimensions->SpinBox_DX1->setValue( myAng );
403
404   displayPreview();
405 }
406
407
408 //=================================================================================
409 // function : createOperation
410 // purpose  :
411 //=================================================================================
412 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
413 {
414   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
415 }
416
417
418 //=================================================================================
419 // function : isValid
420 // purpose  :
421 //=================================================================================
422 bool TransformationGUI_MultiRotationDlg::isValid( QString& /*msg*/ )
423 {
424   return !( myBase->_is_nil() || myVector->_is_nil() );
425 }
426
427 //=================================================================================
428 // function : execute
429 // purpose  :
430 //=================================================================================
431 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
432 {
433   bool res = false;
434   
435   GEOM::GEOM_Object_var anObj;
436
437   switch ( getConstructorId() ) {
438   case 0 :
439     if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
440       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
441         MultiRotate1D( myBase, myVector, myNbTimes1 );
442       res = true;
443     }
444     break;
445   case 1 :
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 );
449       res = true;
450     }
451     break;
452   }
453   
454   if ( !anObj->_is_nil() )
455     objects.push_back( anObj._retn() );
456   
457   return res;
458 }
459
460
461 //=================================================================================
462 // function : closeEvent
463 // purpose  :
464 //=================================================================================
465 void TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
466 {
467   // myGeomGUI->SetState( -1 );
468   GEOMBase_Skeleton::closeEvent( e );
469 }