Salome HOME
Porting to Qt4.
[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 //
23 //
24 //  File   : TransformationGUI_MultiRotationDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_MultiRotationDlg.h"
30 #include "DlgRef_2Sel4Spin1Check.h"
31 #include "DlgRef_2Sel1Spin.h"
32 #include "DlgRef_SpinBox.h"
33
34 #include "GeometryGUI.h"
35 #include "GEOMBase.h"
36
37 #include "SUIT_ResourceMgr.h"
38 #include "SUIT_Session.h"
39 #include "SalomeApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
41
42 #include "GEOMImpl_Types.hxx"
43
44 using namespace std;
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,  const char* name, bool modal, Qt::WindowFlags fl)
55   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
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   GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
66   RadioButton1->setIcon(image0);
67   RadioButton2->setIcon(image1);
68   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69   RadioButton3->close();
70
71   GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
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(this, "GroupDimensions");
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   gridLayout1->addWidget(GroupPoints, 2, 0);
96   gridLayout1->addWidget(GroupDimensions, 2, 0);
97   /***************************************************************/
98
99   setHelpFileName("multi_rotation.htm");
100
101   Init();
102 }
103
104
105 //=================================================================================
106 // function : ~TransformationGUI_MultiRotationDlg()
107 // purpose  : Destroys the object and frees any allocated resources
108 //=================================================================================
109 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
110 {
111   // no need to delete child widgets, Qt does it all for us
112 }
113
114
115 //=================================================================================
116 // function : Init()
117 // purpose  :
118 //=================================================================================
119 void TransformationGUI_MultiRotationDlg::Init()
120 {
121   /* Get setting of step value from file configuration */
122   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
124
125   double SpecificStep1 = 5;
126   double SpecificStep2 = 1;
127   /* min, max, step and decimals for spin boxes & initial values */
128   GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
129   GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
130
131   GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, 3);
132   GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
133   GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
134   GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, MAX_NUMBER, SpecificStep2, 3);
135   GroupDimensions->SpinBox_DX1->SetValue(myAng);
136   GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
137   GroupDimensions->SpinBox_DX2->SetValue(myStep);
138   GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
139
140   /* signals and slots connections */
141   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144
145   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149
150   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154
155   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
159   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160
161   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
162   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
163   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
164   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
165   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
166
167   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
168   
169   connect(myGeomGUI->getApp()->selectionMgr(), 
170           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
171
172   initName( tr( "GEOM_MULTIROTATION" ).toLatin1().constData() );
173   ConstructorsClicked( 0 );
174 }
175
176
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose  : Radio button management
180 //=================================================================================
181 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
182 {
183   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
184
185   myAng = 45.0;
186   myStep = 50.0;
187   myNbTimes1 = myNbTimes2 = 2;
188
189   globalSelection( GEOM_ALLSHAPES );
190
191   switch (constructorId)
192     {
193     case 0: /* Rotate simple */
194       {
195         GroupDimensions->hide();
196         resize(0, 0);
197         GroupPoints->show();
198
199         myEditCurrentArgument = GroupPoints->LineEdit1;
200         GroupPoints->LineEdit1->setText("");
201         GroupPoints->LineEdit2->setText("");
202
203         GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
204
205         break;
206       }
207     case 1: /* Rotate double */
208       {
209         GroupPoints->hide();
210         resize(0, 0);
211         GroupDimensions->show();
212
213         myEditCurrentArgument = GroupDimensions->LineEdit1;
214         GroupDimensions->LineEdit1->setText("");
215         GroupDimensions->LineEdit2->setText("");
216
217         GroupDimensions->SpinBox_DX1->SetValue(myAng);
218         GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
219         GroupDimensions->SpinBox_DX2->SetValue(myStep);
220         GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
221
222         break;
223       }      
224     }
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     {
338       myEditCurrentArgument = send; 
339       GEOMBase_Skeleton::LineEditReturnPressed();
340     }
341 }
342
343
344 //=================================================================================
345 // function : ActivateThisDialog()
346 // purpose  :
347 //=================================================================================
348 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
349 {
350   GEOMBase_Skeleton::ActivateThisDialog();
351   connect(myGeomGUI->getApp()->selectionMgr(), 
352           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
353   
354   ConstructorsClicked( getConstructorId() );
355 }
356
357
358 //=================================================================================
359 // function : enterEvent()
360 // purpose  :
361 //=================================================================================
362 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
363 {
364   if(!GroupConstructors->isEnabled())
365     ActivateThisDialog();
366 }
367
368
369 //=================================================================================
370 // function : ValueChangedInSpinBox()
371 // purpose  :
372 //=================================================================================
373 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
374 {
375   QObject* send = (QObject*)sender();
376
377   if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
378     myNbTimes1 = (int)newValue;
379   else if(send == GroupDimensions->SpinBox_DX1)
380     myAng = newValue;
381   else if(send == GroupDimensions->SpinBox_DX2)
382     myStep = newValue;
383   else if(send == GroupDimensions->SpinBox_DY2)
384     myNbTimes2 = (int)newValue;
385   
386   displayPreview();
387 }
388
389
390 //=================================================================================
391 // function : ReverseAngle()
392 // purpose  : 'state' not used here
393 //=================================================================================
394 void TransformationGUI_MultiRotationDlg::ReverseAngle()
395 {
396   myAng = -myAng;
397
398   int aConstructorId = getConstructorId();
399
400   if(aConstructorId == 0)
401     GroupPoints->SpinBox_DX->SetValue(myAng);
402   else if(aConstructorId == 1)
403     GroupDimensions->SpinBox_DX1->SetValue(myAng);
404
405   displayPreview();
406 }
407
408
409 //=================================================================================
410 // function : createOperation
411 // purpose  :
412 //=================================================================================
413 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
414 {
415   return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
416 }
417
418
419 //=================================================================================
420 // function : isValid
421 // purpose  :
422 //=================================================================================
423 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
424 {
425   return !(myBase->_is_nil() || myVector->_is_nil());
426 }
427
428 //=================================================================================
429 // function : execute
430 // purpose  :
431 //=================================================================================
432 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
433 {
434   bool res = false;
435   
436   GEOM::GEOM_Object_var anObj;
437
438   switch ( getConstructorId() ) 
439     {
440     case 0 :
441       {
442         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
443           anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
444             MultiRotate1D( myBase, myVector, myNbTimes1 );
445           res = true;
446         }
447         break;
448       }
449     case 1 :
450       {
451         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
452           {
453             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
454               MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
455             res = true;
456           }
457         break;
458       }
459     }
460   
461   if ( !anObj->_is_nil() )
462     objects.push_back( anObj._retn() );
463   
464   return res;
465 }
466
467
468 //=================================================================================
469 // function : closeEvent
470 // purpose  :
471 //=================================================================================
472 void  TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
473 {
474   // myGeomGUI->SetState( -1 );
475   GEOMBase_Skeleton::closeEvent( e );
476 }