Salome HOME
Fix for PAL12857.
[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
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
53   (GeometryGUI* theGeometryGUI, QWidget* parent,  const char* name, bool modal, WFlags fl)
54   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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   setCaption(tr("GEOM_MULTIROTATION_TITLE"));
63
64   /***************************************************************/
65   GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
66   RadioButton1->setPixmap(image0);
67   RadioButton2->setPixmap(image1);
68   RadioButton3->close(TRUE);
69
70   GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
75   GroupPoints->PushButton1->setPixmap(image2);
76   GroupPoints->PushButton2->setPixmap(image2);
77   GroupPoints->LineEdit1->setReadOnly(true);
78   GroupPoints->LineEdit2->setReadOnly(true);
79
80   GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
81   GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
82   GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
83   GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
84   GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
85   GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
86   GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
87   GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
88   GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
89   GroupDimensions->PushButton1->setPixmap(image2);
90   GroupDimensions->PushButton2->setPixmap(image2);
91   GroupDimensions->LineEdit1->setReadOnly(true);
92   GroupDimensions->LineEdit2->setReadOnly(true);
93
94   Layout1->addWidget(GroupPoints, 2, 0);
95   Layout1->addWidget(GroupDimensions, 2, 0);
96   /***************************************************************/
97
98   setHelpFileName("multi_rotation.htm");
99
100   Init();
101 }
102
103
104 //=================================================================================
105 // function : ~TransformationGUI_MultiRotationDlg()
106 // purpose  : Destroys the object and frees any allocated resources
107 //=================================================================================
108 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
109 {
110   // no need to delete child widgets, Qt does it all for us
111 }
112
113
114 //=================================================================================
115 // function : Init()
116 // purpose  :
117 //=================================================================================
118 void TransformationGUI_MultiRotationDlg::Init()
119 {
120   /* Get setting of step value from file configuration */
121   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
123
124   double SpecificStep1 = 5;
125   double SpecificStep2 = 1;
126   /* min, max, step and decimals for spin boxes & initial values */
127   GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep2, 3);
128   GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
129
130   GroupDimensions->SpinBox_DX1->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep1, 3);
131   GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep2, 3);
132   GroupDimensions->SpinBox_DX2->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
133   GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, COORD_MAX, SpecificStep2, 3);
134   GroupDimensions->SpinBox_DX1->SetValue(myAng);
135   GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
136   GroupDimensions->SpinBox_DX2->SetValue(myStep);
137   GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
138
139   /* signals and slots connections */
140   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143
144   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148
149   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151   connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152   connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153
154   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
159
160   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
161   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
162   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
163   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
164   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
165
166   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseAngle()));
167   
168   connect(myGeomGUI->getApp()->selectionMgr(), 
169           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
170
171   initName( tr( "GEOM_MULTIROTATION" ) );
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     {
192     case 0: /* Rotate simple */
193       {
194         GroupDimensions->hide();
195         resize(0, 0);
196         GroupPoints->show();
197
198         myEditCurrentArgument = GroupPoints->LineEdit1;
199         GroupPoints->LineEdit1->setText("");
200         GroupPoints->LineEdit2->setText("");
201
202         GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
203
204         break;
205       }
206     case 1: /* Rotate double */
207       {
208         GroupPoints->hide();
209         resize(0, 0);
210         GroupDimensions->show();
211
212         myEditCurrentArgument = GroupDimensions->LineEdit1;
213         GroupDimensions->LineEdit1->setText("");
214         GroupDimensions->LineEdit2->setText("");
215
216         GroupDimensions->SpinBox_DX1->SetValue(myAng);
217         GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
218         GroupDimensions->SpinBox_DX2->SetValue(myStep);
219         GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
220
221         break;
222       }      
223     }
224
225   myEditCurrentArgument->setFocus();
226   myBase = myVector = GEOM::GEOM_Object::_nil();
227   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
228           this, SLOT(SelectionIntoArgument()));
229 }
230
231
232 //=================================================================================
233 // function : ClickOnOk()
234 // purpose  :
235 //=================================================================================
236 void TransformationGUI_MultiRotationDlg::ClickOnOk()
237 {
238   if ( ClickOnApply() )
239     ClickOnCancel();
240 }
241
242
243 //=================================================================================
244 // function : ClickOnApply()
245 // purpose  :
246 //=================================================================================
247 bool TransformationGUI_MultiRotationDlg::ClickOnApply()
248 {
249   if ( !onAccept() )
250     return false;
251   
252   initName();
253   ConstructorsClicked( getConstructorId() );
254   return true;
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 (IObjectCount() != 1) {
267     if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
268         myEditCurrentArgument == GroupDimensions->LineEdit1)
269       myBase = GEOM::GEOM_Object::_nil();
270     else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
271              myEditCurrentArgument == GroupDimensions->LineEdit2)
272       myVector = GEOM::GEOM_Object::_nil();
273     return;
274   }
275
276   // nbSel == 1
277   Standard_Boolean testResult = Standard_False;;
278   GEOM::GEOM_Object_var aSelectedObject =
279     GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
280
281   if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
282     return;
283
284   if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
285       myEditCurrentArgument == GroupDimensions->LineEdit1)
286     myBase = aSelectedObject;
287   else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
288            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(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* e)
362 {
363   if(!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     {
439     case 0 :
440       {
441         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) ) {
442           anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
443             MultiRotate1D( myBase, myVector, myNbTimes1 );
444           res = true;
445         }
446         break;
447       }
448     case 1 :
449       {
450         if ( !CORBA::is_nil( myBase ) && !CORBA::is_nil( myVector ) )
451           {
452             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
453               MultiRotate2D( myBase, myVector, myAng, myNbTimes1, myStep, myNbTimes2 );
454             res = true;
455           }
456         break;
457       }
458     }
459   
460   if ( !anObj->_is_nil() )
461     objects.push_back( anObj._retn() );
462   
463   return res;
464 }
465
466
467 //=================================================================================
468 // function : closeEvent
469 // purpose  :
470 //=================================================================================
471 void  TransformationGUI_MultiRotationDlg::closeEvent( QCloseEvent* e )
472 {
473   // myGeomGUI->SetState( -1 );
474   GEOMBase_Skeleton::closeEvent( e );
475 }