Salome HOME
441abea0a72eb3c804abfbd11fc0d3c133826f97
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TransformationGUI_MultiRotationDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_MultiRotationDlg.h"
30
31 #include "GEOMImpl_Types.hxx"
32
33 #include "QAD_Config.h"
34 #include "QAD_Desktop.h"
35
36 #include <qcheckbox.h>
37
38 #include "utilities.h"
39
40 using namespace std;
41
42 //=================================================================================
43 // class    : TransformationGUI_MultiRotationDlg()
44 // purpose  : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg(QWidget* parent,  const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 {
52   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
53   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
54   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55
56   setCaption(tr("GEOM_MULTIROTATION_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
60   RadioButton1->setPixmap(image0);
61   RadioButton2->setPixmap(image1);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
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->setPixmap(image2);
70   GroupPoints->PushButton2->setPixmap(image2);
71   GroupPoints->LineEdit1->setReadOnly(true);
72   GroupPoints->LineEdit2->setReadOnly(true);
73
74   GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
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->setPixmap(image2);
84   GroupDimensions->PushButton2->setPixmap(image2);
85   GroupDimensions->LineEdit1->setReadOnly(true);
86   GroupDimensions->LineEdit2->setReadOnly(true);
87
88   Layout1->addWidget(GroupPoints, 2, 0);
89   Layout1->addWidget(GroupDimensions, 2, 0);
90   /***************************************************************/
91
92   Init();
93 }
94
95
96 //=================================================================================
97 // function : ~TransformationGUI_MultiRotationDlg()
98 // purpose  : Destroys the object and frees any allocated resources
99 //=================================================================================
100 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
101 {
102   // no need to delete child widgets, Qt does it all for us
103 }
104
105
106 //=================================================================================
107 // function : Init()
108 // purpose  :
109 //=================================================================================
110 void TransformationGUI_MultiRotationDlg::Init()
111 {
112   /* Get setting of step value from file configuration */
113   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
114   double step = St.toDouble();
115
116   double SpecificStep1 = 5;
117   double SpecificStep2 = 1;
118   /* min, max, step and decimals for spin boxes & initial values */
119   GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
120   GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
121
122   GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
123   GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
124   GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
125   GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
126   GroupDimensions->SpinBox_DX1->SetValue(myAng);
127   GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
128   GroupDimensions->SpinBox_DX2->SetValue(myStep);
129   GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
130
131   /* signals and slots connections */
132   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
135
136   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140
141   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145
146   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151
152   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
153   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
154   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
155   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
156   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
157
158   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
159   
160   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
161
162   initName( tr( "GEOM_MULTIROTATION" ) );
163   ConstructorsClicked( 0 );
164 }
165
166
167 //=================================================================================
168 // function : ConstructorsClicked()
169 // purpose  : Radio button management
170 //=================================================================================
171 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
172 {
173   disconnect(mySelection, 0, this, 0);
174   
175   myAng = 45.0;
176   myStep = 50.0;
177   myNbTimes1 = myNbTimes2 = 2;
178   
179   globalSelection( GEOM_ALLSHAPES );
180
181   switch (constructorId)
182     {
183     case 0: /* Rotate simple */
184       {
185         GroupDimensions->hide();
186         resize(0, 0);
187         GroupPoints->show();
188
189         myEditCurrentArgument = GroupPoints->LineEdit1;
190         GroupPoints->LineEdit1->setText("");
191         GroupPoints->LineEdit2->setText("");
192
193         GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
194
195         break;
196       }
197     case 1: /* Rotate double */
198       {
199         GroupPoints->hide();
200         resize(0, 0);
201         GroupDimensions->show();
202
203         myEditCurrentArgument = GroupDimensions->LineEdit1;
204         GroupDimensions->LineEdit1->setText("");
205         GroupDimensions->LineEdit2->setText("");
206
207         GroupDimensions->SpinBox_DX1->SetValue(myAng);
208         GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
209         GroupDimensions->SpinBox_DX2->SetValue(myStep);
210         GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
211
212         break;
213       }      
214     }
215
216   myEditCurrentArgument->setFocus();
217   myBase = myVector = GEOM::GEOM_Object::_nil();
218   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
219 }
220
221
222 //=================================================================================
223 // function : ClickOnOk()
224 // purpose  :
225 //=================================================================================
226 void TransformationGUI_MultiRotationDlg::ClickOnOk()
227 {
228   if ( ClickOnApply() )
229     ClickOnCancel();
230 }
231
232
233 //=================================================================================
234 // function : ClickOnApply()
235 // purpose  :
236 //=================================================================================
237 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
238 {
239   if ( !onAccept() )
240     return false;
241   
242   initName();
243   ConstructorsClicked( getConstructorId() );
244   return true;
245 }
246
247
248 //=======================================================================
249 // function : ClickOnCancel()
250 // purpose  :
251 //=======================================================================
252 void TransformationGUI_MultiRotationDlg::ClickOnCancel()
253 {
254   GEOMBase_Skeleton::ClickOnCancel();
255 }
256
257
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose  : Called when selection as changed or other case
261 //=================================================================================
262 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
263 {
264   myEditCurrentArgument->setText("");
265   
266   if(mySelection->IObjectCount() != 1) {
267     if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
268       myBase = GEOM::GEOM_Object::_nil();
269     else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
270       myVector = GEOM::GEOM_Object::_nil();
271     return;
272   }
273   
274   // nbSel == 1
275   Standard_Boolean testResult = Standard_False;;
276   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
277
278   if ( !testResult || CORBA::is_nil( aSelectedObject ) || !GEOMBase::IsShape( aSelectedObject ) )
279     return;
280
281
282   if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
283     myBase = aSelectedObject;
284   else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
285     myVector = aSelectedObject;
286     
287   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
288
289   displayPreview();
290 }
291
292
293 //=================================================================================
294 // function : SetEditCurrentArgument()
295 // purpose  :
296 //=================================================================================
297 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
298 {
299   QPushButton* send = (QPushButton*)sender();
300   
301   if(send == GroupPoints->PushButton1) {
302     myEditCurrentArgument = GroupPoints->LineEdit1;
303     globalSelection( GEOM_ALLSHAPES );
304   }
305   else if(send == GroupPoints->PushButton2) {
306     myEditCurrentArgument = GroupPoints->LineEdit2;
307     globalSelection( GEOM_LINE  );
308   }
309   else if(send == GroupDimensions->PushButton1) {
310     myEditCurrentArgument = GroupDimensions->LineEdit1;
311     globalSelection( GEOM_ALLSHAPES );
312   }
313   else if(send == GroupDimensions->PushButton2) {
314     myEditCurrentArgument = GroupDimensions->LineEdit2;
315     globalSelection( GEOM_LINE  );
316   }
317
318   myEditCurrentArgument->setFocus();
319   SelectionIntoArgument();
320 }
321
322
323 //=================================================================================
324 // function : LineEditReturnPressed()
325 // purpose  :
326 //=================================================================================
327 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
328 {
329   QLineEdit* send = (QLineEdit*)sender();
330   if(send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 || 
331      send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2)
332     {
333       myEditCurrentArgument = send; 
334       GEOMBase_Skeleton::LineEditReturnPressed();
335     }
336 }
337
338
339 //=================================================================================
340 // function : ActivateThisDialog()
341 // purpose  :
342 //=================================================================================
343 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
344 {
345   GEOMBase_Skeleton::ActivateThisDialog();
346   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
347   
348   ConstructorsClicked( getConstructorId() );
349 }
350
351
352 //=================================================================================
353 // function : DeactivateActiveDialog()
354 // purpose  : public slot to deactivate if active
355 //=================================================================================
356 void TransformationGUI_MultiRotationDlg::DeactivateActiveDialog()
357 {
358   GEOMBase_Skeleton::DeactivateActiveDialog();
359 }
360
361
362 //=================================================================================
363 // function : enterEvent()
364 // purpose  :
365 //=================================================================================
366 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
367 {
368   if(!GroupConstructors->isEnabled())
369     ActivateThisDialog();
370 }
371
372
373 //=================================================================================
374 // function : ValueChangedInSpinBox()
375 // purpose  :
376 //=================================================================================
377 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
378 {
379   QObject* send = (QObject*)sender();
380
381   if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
382     myNbTimes1 = (int)newValue;
383   else if(send == GroupDimensions->SpinBox_DX1)
384     myAng = newValue;
385   else if(send == GroupDimensions->SpinBox_DX2)
386     myStep = newValue;
387   else if(send == GroupDimensions->SpinBox_DY2)
388     myNbTimes2 = (int)newValue;
389   
390   displayPreview();
391 }
392
393
394 //=================================================================================
395 // function : ReverseAngle()
396 // purpose  : 'state' not used here
397 //=================================================================================
398 void TransformationGUI_MultiRotationDlg::ReverseAngle()
399 {
400   myAng = -myAng;
401
402   int aConstructorId = getConstructorId();
403
404   if(aConstructorId == 0)
405     GroupPoints->SpinBox_DX->SetValue(myAng);
406   else if(aConstructorId == 1)
407     GroupDimensions->SpinBox_DX1->SetValue(myAng);
408
409   displayPreview();
410 }
411
412
413 //=================================================================================
414 // function : createOperation
415 // purpose  :
416 //=================================================================================
417 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiRotationDlg::createOperation()
418 {
419   return getGeomEngine()->GetITransformOperations( getStudyId() );
420 }
421
422
423 //=================================================================================
424 // function : isValid
425 // purpose  :
426 //=================================================================================
427 bool TransformationGUI_MultiRotationDlg::isValid( QString& msg )
428 {
429   return !(myBase->_is_nil() || myVector->_is_nil());
430 }
431
432 //=================================================================================
433 // function : execute
434 // purpose  :
435 //=================================================================================
436 bool TransformationGUI_MultiRotationDlg::execute( ObjectList& objects )
437 {
438   bool res = false;
439   
440   GEOM::GEOM_Object_var anObj;
441
442   switch ( getConstructorId() ) 
443     {
444     case 0 :
445       {
446         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
447           anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate1D( myBase, myVector, myNbTimes1 );
448           res = true;
449         }
450         break;
451       }
452     case 1 :
453       {
454         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
455           {
456             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
457             res = true;
458           }
459         break;
460       }
461     }
462   
463   if ( !anObj->_is_nil() )
464     objects.push_back( anObj._retn() );
465   
466   return res;
467 }
468
469
470 //=================================================================================
471 // function : closeEvent
472 // purpose  :
473 //=================================================================================
474 void  TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
475 {
476   myGeomGUI->SetState( -1 );
477   GEOMBase_Skeleton::closeEvent( e );
478 }