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