]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx
Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[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 <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS.hxx>
40 #include <TopExp.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43
44 #include <GEOMImpl_Types.hxx>
45
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 )
56 {
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" ) ) );
61
62   setWindowTitle( tr( "GEOM_MULTIROTATION_TITLE" ) );
63
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();
70
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 );
80
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 );
94
95   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
96   layout->setMargin( 0 ); layout->setSpacing( 6 );
97   layout->addWidget( GroupPoints );
98   layout->addWidget( GroupDimensions );
99   /***************************************************************/
100
101   setHelpFileName( "multi_rotation_operation_page.html" );
102
103   Init();
104 }
105
106
107 //=================================================================================
108 // function : ~TransformationGUI_MultiRotationDlg()
109 // purpose  : Destroys the object and frees any allocated resources
110 //=================================================================================
111 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
112 {
113   // no need to delete child widgets, Qt does it all for us
114 }
115
116
117 //=================================================================================
118 // function : Init()
119 // purpose  :
120 //=================================================================================
121 void TransformationGUI_MultiRotationDlg::Init()
122 {
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 );
126
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 );
132
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 );
141
142   /* signals and slots connections */
143   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
144   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
145
146   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
147
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() ) );
152
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() ) );
157
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 ) ) );
163
164   // VSR: TODO ->>
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 ) ) );
170   // <<-
171
172   connect( GroupDimensions->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseAngle() ) );
173   
174   connect( myGeomGUI->getApp()->selectionMgr(),
175            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
176
177   initName( tr( "GEOM_MULTIROTATION" ) );
178
179   ConstructorsClicked( 0 );
180 }
181
182
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose  : Radio button management
186 //=================================================================================
187 void TransformationGUI_MultiRotationDlg::ConstructorsClicked( int constructorId )
188 {
189   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
190
191   myAng = 45.0;
192   myStep = 50.0;
193   myNbTimes1 = myNbTimes2 = 2;
194
195   globalSelection( GEOM_ALLSHAPES );
196
197   switch ( constructorId ) {
198   case 0: /* Rotate simple */
199     {
200       GroupDimensions->hide();
201       GroupPoints->show();
202
203       myEditCurrentArgument = GroupPoints->LineEdit1;
204       GroupPoints->LineEdit1->setText( "" );
205       GroupPoints->LineEdit2->setText( "" );
206       
207       GroupPoints->SpinBox_DX->setValue( myNbTimes1 );
208       
209       break;
210     }
211   case 1: /* Rotate double */
212     {
213       GroupPoints->hide();
214       GroupDimensions->show();
215       
216       myEditCurrentArgument = GroupDimensions->LineEdit1;
217       GroupDimensions->LineEdit1->setText( "" );
218       GroupDimensions->LineEdit2->setText( "" );
219       
220       GroupDimensions->SpinBox_DX1->setValue( myAng );
221       GroupDimensions->SpinBox_DY1->setValue( myNbTimes1 );
222       GroupDimensions->SpinBox_DX2->setValue( myStep );
223       GroupDimensions->SpinBox_DY2->setValue( myNbTimes2 );
224       
225       break;
226     }      
227   }
228
229   qApp->processEvents();
230   updateGeometry();
231   resize( minimumSize() );
232
233   myEditCurrentArgument->setFocus();
234   myBase = myVector = GEOM::GEOM_Object::_nil();
235   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
236            this, SLOT( SelectionIntoArgument() ) );
237 }
238
239
240 //=================================================================================
241 // function : ClickOnOk()
242 // purpose  :
243 //=================================================================================
244 void TransformationGUI_MultiRotationDlg::ClickOnOk()
245 {
246   if ( ClickOnApply() )
247     ClickOnCancel();
248 }
249
250
251 //=================================================================================
252 // function : ClickOnApply()
253 // purpose  :
254 //=================================================================================
255 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
256 {
257   if ( !onAccept() )
258     return false;
259   
260   initName();
261   ConstructorsClicked( getConstructorId() );
262   return true;
263 }
264
265
266 //=================================================================================
267 // function : SelectionIntoArgument()
268 // purpose  : Called when selection as changed or other case
269 //=================================================================================
270 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
271 {
272   myEditCurrentArgument->setText( "" );
273
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();
281     return;
282   }
283
284   // nbSel == 1
285   Standard_Boolean testResult = Standard_False;;
286   GEOM::GEOM_Object_var aSelectedObject =
287     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
288
289   if ( !testResult || CORBA::is_nil( aSelectedObject) || !GEOMBase::IsShape( aSelectedObject ) )
290     return;
291
292   QString aName = GEOMBase::GetName( aSelectedObject );
293
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() ) {
300       TopoDS_Shape aShape;
301           
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 );
309           
310           //Find SubShape Object in Father
311           GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
312                   
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);
317           }
318           else {
319             myVector = aFindedObject; // get existing object
320           }
321         }
322         else {
323           if ( aShape.ShapeType() != TopAbs_EDGE ) {
324             aSelectedObject = GEOM::GEOM_Object::_nil();
325             aName = "";
326           }
327           myVector = aSelectedObject;
328         }
329       }
330     }
331   }
332   myEditCurrentArgument->setText( aName );
333
334   displayPreview();
335 }
336
337
338 //=================================================================================
339 // function : SetEditCurrentArgument()
340 // purpose  :
341 //=================================================================================
342 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
343 {
344   QPushButton* send = (QPushButton*)sender();
345   globalSelection( GEOM_ALLSHAPES );
346   
347   if ( send == GroupPoints->PushButton1 ) {
348     myEditCurrentArgument = GroupPoints->LineEdit1;
349   }
350   else if ( send == GroupPoints->PushButton2 ) {
351     myEditCurrentArgument = GroupPoints->LineEdit2;
352     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
353   }
354   else if ( send == GroupDimensions->PushButton1 ) {
355     myEditCurrentArgument = GroupDimensions->LineEdit1;
356   }
357   else if ( send == GroupDimensions->PushButton2 ) {
358     myEditCurrentArgument = GroupDimensions->LineEdit2;
359     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
360   }
361
362   myEditCurrentArgument->setFocus();
363   SelectionIntoArgument();
364 }
365
366
367 //=================================================================================
368 // function : LineEditReturnPressed()
369 // purpose  :
370 //=================================================================================
371 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
372 {
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();
378   }
379 }
380
381
382 //=================================================================================
383 // function : ActivateThisDialog()
384 // purpose  :
385 //=================================================================================
386 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
387 {
388   GEOMBase_Skeleton::ActivateThisDialog();
389   connect( myGeomGUI->getApp()->selectionMgr(), 
390            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
391   
392   ConstructorsClicked( getConstructorId() );
393 }
394
395
396 //=================================================================================
397 // function : enterEvent()
398 // purpose  :
399 //=================================================================================
400 void TransformationGUI_MultiRotationDlg::enterEvent( QEvent* )
401 {
402   if ( !mainFrame()->GroupConstructors->isEnabled() )
403     ActivateThisDialog();
404 }
405
406
407 //=================================================================================
408 // function : ValueChangedInSpinBox()
409 // purpose  :
410 //=================================================================================
411 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox( double newValue )
412 {
413   QObject* send = (QObject*)sender();
414
415   if ( send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1 )
416     myNbTimes1 = (int)newValue;
417   else if ( send == GroupDimensions->SpinBox_DX1 )
418     myAng = newValue;
419   else if ( send == GroupDimensions->SpinBox_DX2 )
420     myStep = newValue;
421   else if ( send == GroupDimensions->SpinBox_DY2 )
422     myNbTimes2 = (int)newValue;
423   
424   displayPreview();
425 }
426
427
428 //=================================================================================
429 // function : ReverseAngle()
430 // purpose  : 'state' not used here
431 //=================================================================================
432 void TransformationGUI_MultiRotationDlg::ReverseAngle()
433 {
434   myAng = -myAng;
435
436   int aConstructorId = getConstructorId();
437
438   if ( aConstructorId == 0 )
439     GroupPoints->SpinBox_DX->setValue( myAng );
440   else if ( aConstructorId == 1 )
441     GroupDimensions->SpinBox_DX1->setValue( myAng );
442
443   displayPreview();
444 }
445
446
447 //=================================================================================
448 // function : createOperation
449 // purpose  :
450 //=================================================================================
451 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
452 {
453   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
454 }
455
456
457 //=================================================================================
458 // function : isValid
459 // purpose  :
460 //=================================================================================
461 bool TransformationGUI_MultiRotationDlg::isValid( QString& /*msg*/ )
462 {
463   return !( myBase->_is_nil() || myVector->_is_nil() );
464 }
465
466 //=================================================================================
467 // function : execute
468 // purpose  :
469 //=================================================================================
470 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
471 {
472   bool res = false;
473   
474   GEOM::GEOM_Object_var anObj;
475
476   switch ( getConstructorId() ) {
477   case 0 :
478     if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
479       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
480         MultiRotate1D( myBase, myVector, myNbTimes1 );
481       res = true;
482     }
483     break;
484   case 1 :
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 );
488       res = true;
489     }
490     break;
491   }
492   
493   if ( !anObj->_is_nil() )
494     objects.push_back( anObj._retn() );
495   
496   return res;
497 }
498
499 //=================================================================================
500 // function : addSubshapeToStudy
501 // purpose  : virtual method to add new SubObjects if local selection
502 //=================================================================================
503 void TransformationGUI_MultiRotationDlg::addSubshapesToStudy()
504 {
505   QMap<QString, GEOM::GEOM_Object_var> objMap;
506   
507   switch ( getConstructorId() ) {
508   case 0:
509     objMap[GroupPoints->LineEdit2->text()] = myVector;
510     break;
511   case 1:
512     objMap[GroupDimensions->LineEdit2->text()] = myVector;
513     break;
514   }
515   addSubshapesToFather( objMap );
516 }