Salome HOME
Update mail address
[modules/geom.git] / src / TransformationGUI / TransformationGUI_RotationDlg.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_RotationDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_RotationDlg.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_RotationDlg()
47 // purpose  : Constructs a TransformationGUI_RotationDlg 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_RotationDlg::TransformationGUI_RotationDlg
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   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
58   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59
60   setCaption(tr("GEOM_ROTATION_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_ROTATION"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->close(TRUE);
66   RadioButton3->close(TRUE);
67
68   GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
69   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
71   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
72   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
73   GroupPoints->LineEdit1->setReadOnly(true);
74   GroupPoints->LineEdit2->setReadOnly(true);
75   GroupPoints->PushButton1->setPixmap(image1);
76   GroupPoints->PushButton2->setPixmap(image1);
77   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
78   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
79
80   Layout1->addWidget(GroupPoints, 2, 0);
81   /***************************************************************/
82   double anAngle = 0;
83   double SpecificStep = 5;
84   /* min, max, step and decimals for spin boxes & initial values */
85   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
86   GroupPoints->SpinBox_DX->SetValue(anAngle);
87
88   // Activate Create a Copy mode
89   GroupPoints->CheckButton1->setChecked(true);
90   CreateCopyModeChanged(true);
91   
92   /* signals and slots connections */
93   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
94   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
95   
96   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
97   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
98   
99   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
100   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
101
102   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
103   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
104   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
105   
106   connect(myGeomGUI->getApp()->selectionMgr(),
107           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
108
109   setHelpFileName("rotation.htm");
110
111   Init();
112 }
113
114
115 //=================================================================================
116 // function : ~TransformationGUI_RotationDlg()
117 // purpose  : Destroys the object and frees any allocated resources
118 //=================================================================================
119 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
120 {
121   // no need to delete child widgets, Qt does it all for us
122 }
123
124
125 //=================================================================================
126 // function : Init()
127 // purpose  :
128 //=================================================================================
129 void TransformationGUI_RotationDlg::Init()
130 {
131   /* init variables */
132   myEditCurrentArgument = GroupPoints->LineEdit1;
133   GroupPoints->LineEdit2->clear();
134   
135   myAxis = GEOM::GEOM_Object::_nil();
136   
137   initName( tr( "GEOM_ROTATION" ) );
138 }
139
140
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose  :
144 //=================================================================================
145 void TransformationGUI_RotationDlg::ClickOnOk()
146 {
147   if ( ClickOnApply() )
148     ClickOnCancel();
149 }
150
151
152 //=================================================================================
153 // function : ClickOnApply()
154 // purpose  :
155 //=================================================================================
156 bool TransformationGUI_RotationDlg::ClickOnApply()
157 {
158   if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
159     return false;
160   
161   Init();
162   return true;
163 }
164
165
166 //=================================================================================
167 // function : SelectionIntoArgument()
168 // purpose  : Called when selection as changed or other case
169 //=================================================================================
170 void TransformationGUI_RotationDlg::SelectionIntoArgument()
171 {
172   myEditCurrentArgument->setText("");
173   QString aName;
174   
175   if(myEditCurrentArgument == GroupPoints->LineEdit1)
176     {
177       int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
178       if(aNbSel < 1)
179         {
180           myObjects.length(0);
181           return;
182         }
183       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
184       if (!myObjects.length())
185         return;
186     }
187   else if(myEditCurrentArgument == GroupPoints->LineEdit2)
188     {
189       if(IObjectCount() != 1)
190         {
191           myAxis = GEOM::GEOM_Object::_nil();
192           return;
193         }
194       Standard_Boolean testResult = Standard_False;
195       myAxis = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
196       if(!testResult || CORBA::is_nil( myAxis ))
197         return;
198       aName = GEOMBase::GetName( myAxis );
199     }
200   myEditCurrentArgument->setText( aName );
201   
202   displayPreview();
203 }
204
205
206 //=================================================================================
207 // function : SetEditCurrentArgument()
208 // purpose  :
209 //=================================================================================
210 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
211 {
212   QPushButton* send = (QPushButton*)sender();
213   
214   if(send == GroupPoints->PushButton1) {
215     myEditCurrentArgument = GroupPoints->LineEdit1;
216     globalSelection();
217   }
218   else if(send == GroupPoints->PushButton2) {
219     myEditCurrentArgument = GroupPoints->LineEdit2;
220     globalSelection( GEOM_LINE );
221   }
222   
223   myEditCurrentArgument->setFocus();
224   SelectionIntoArgument();
225 }
226
227
228 //=================================================================================
229 // function : LineEditReturnPressed()
230 // purpose  :
231 //=================================================================================
232 void TransformationGUI_RotationDlg::LineEditReturnPressed()
233 {  
234   QLineEdit* send = (QLineEdit*)sender();
235   if(send == GroupPoints->LineEdit1 ||
236      send == GroupPoints->LineEdit2)
237     {
238       myEditCurrentArgument = send;
239       GEOMBase_Skeleton::LineEditReturnPressed();
240     }
241 }
242
243
244 //=================================================================================
245 // function : ActivateThisDialog()
246 // purpose  :
247 //=================================================================================
248 void TransformationGUI_RotationDlg::ActivateThisDialog()
249 {
250   GEOMBase_Skeleton::ActivateThisDialog();
251   connect(myGeomGUI->getApp()->selectionMgr(), 
252           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
253   globalSelection();
254   GroupPoints->LineEdit1->setFocus();
255   myEditCurrentArgument = GroupPoints->LineEdit1;
256   GroupPoints->LineEdit2->clear();
257   myAxis = GEOM::GEOM_Object::_nil();
258 }
259
260
261 //=================================================================================
262 // function : enterEvent()
263 // purpose  :
264 //=================================================================================
265 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
266 {
267   if (!GroupConstructors->isEnabled())
268     ActivateThisDialog();
269 }
270
271
272 //=================================================================================
273 // function : ValueChangedInSpinBox()
274 // purpose  :
275 //=================================================================================
276 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
277 {
278   displayPreview();
279 }
280
281
282 //=================================================================================
283 // function : createOperation
284 // purpose  :
285 //=================================================================================
286 GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
287 {
288   return getGeomEngine()->GetITransformOperations( getStudyId() );
289 }
290
291
292 //=================================================================================
293 // function : isValid
294 // purpose  :
295 //=================================================================================
296 bool TransformationGUI_RotationDlg::isValid( QString& msg )
297 {
298   return !(myObjects.length() == 0 || myAxis->_is_nil());
299 }
300
301
302 //=================================================================================
303 // function : execute
304 // purpose  :
305 //=================================================================================
306 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
307 {
308   bool res = false;
309   
310   GEOM::GEOM_Object_var anObj;
311   
312   if (GroupPoints->CheckButton1->isChecked() || IsPreview())
313     for (int i = 0; i < myObjects.length(); i++)
314       {
315         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
316         if ( !anObj->_is_nil() )
317           objects.push_back( anObj._retn() );
318       }
319   else
320     for (int i = 0; i < myObjects.length(); i++)
321       {
322         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
323         if ( !anObj->_is_nil() )
324           objects.push_back( anObj._retn() );
325       }
326   res = true;
327   
328   return res;
329 }
330
331
332 //=================================================================================
333 // function : closeEvent
334 // purpose  :
335 //=================================================================================
336 void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
337 {
338   GEOMBase_Skeleton::closeEvent( e );
339 }
340
341
342 //=================================================================================
343 // function : GetAngle()
344 // purpose  :
345 //=================================================================================
346 double TransformationGUI_RotationDlg::GetAngle() const
347 {
348   return GroupPoints->SpinBox_DX->GetValue();
349 }
350
351
352 //=================================================================================
353 // function :  CreateCopyModeChanged()
354 // purpose  :
355 //=================================================================================
356 void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
357 {
358   this->GroupBoxName->setEnabled(isCreateCopy);
359 }
360
361
362 //=================================================================================
363 // function :  onReverse()
364 // purpose  :
365 //=================================================================================
366 void TransformationGUI_RotationDlg::onReverse()
367 {
368   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
369   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
370 }