]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_RotationDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TransformationGUI_RotationDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "TransformationGUI_RotationDlg.h"
31
32 #include <gp_Lin.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35
36 //=================================================================================
37 // class    : TransformationGUI_RotationDlg()
38 // purpose  : Constructs a TransformationGUI_RotationDlg which is a child of 'parent', with the 
39 //            name 'name' and widget flags set to 'f'.
40 //            The dialog will by default be modeless, unless you set 'modal' to
41 //            TRUE to construct a modal dialog.
42 //=================================================================================
43 TransformationGUI_RotationDlg::TransformationGUI_RotationDlg(QWidget* parent,  const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
44   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 {
46   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
47   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48
49   setCaption(tr("GEOM_ROTATION_TITLE"));
50
51   /***************************************************************/
52   GroupConstructors->setTitle(tr("GEOM_ROTATION"));
53   RadioButton1->setPixmap(image0);
54   RadioButton2->close(TRUE);
55   RadioButton3->close(TRUE);
56
57   GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
58   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
59   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
60   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
61   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
62   GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
63   GroupPoints->PushButton1->setPixmap(image1);
64   GroupPoints->PushButton2->setPixmap(image1);
65
66   Layout1->addWidget(GroupPoints, 1, 0);
67   /***************************************************************/
68
69   /* Initialisations */
70   myTransformationGUI = theTransformationGUI;
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~TransformationGUI_RotationDlg()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 TransformationGUI_RotationDlg::~TransformationGUI_RotationDlg()
80 {
81   // no need to delete child widgets, Qt does it all for us
82 }
83
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void TransformationGUI_RotationDlg::Init()
90 {
91   /* init variables */
92   myEditCurrentArgument = GroupPoints->LineEdit1;
93
94   myAngle = 0.0;
95   myOkBase = myOkAxis = false;
96
97   myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
98
99   double SpecificStep = 5;
100   /* min, max, step and decimals for spin boxes & initial values */
101   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
102   GroupPoints->SpinBox_DX->SetValue(myAngle);
103
104   /* signals and slots connections */
105   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107
108   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110
111   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113
114   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
115   connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
116   
117   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
118
119   /* displays Dialog */
120   GroupPoints->show();
121   this->show();
122
123   return;
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  :
130 //=================================================================================
131 void TransformationGUI_RotationDlg::ClickOnOk()
132 {
133   this->ClickOnApply();
134   ClickOnCancel();
135   return;
136 }
137
138
139 //=================================================================================
140 // function : ClickOnApply()
141 // purpose  :
142 //=================================================================================
143 void TransformationGUI_RotationDlg::ClickOnApply()
144 {
145   buttonApply->setFocus();
146   QAD_Application::getDesktop()->putInfo(tr(""));
147   if (mySimulationTopoDs.IsNull())
148     return;
149   myGeomBase->EraseSimulationShape();
150   mySimulationTopoDs.Nullify();
151
152   if(myOkBase && myOkAxis)  
153     myTransformationGUI->MakeRotationAndDisplay(myGeomShape, myLoc, myDir, myAngle*PI180); 
154   return;
155 }
156
157
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose  : Called when selection as changed or other case
161 //=================================================================================
162 void TransformationGUI_RotationDlg::SelectionIntoArgument()
163 {
164   myGeomBase->EraseSimulationShape();
165   mySimulationTopoDs.Nullify();
166   myEditCurrentArgument->setText("");
167   QString aString = ""; /* name of selection */
168   
169   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
170   if(nbSel != 1) {
171     if(myEditCurrentArgument == GroupPoints->LineEdit1)
172       myOkBase = false;
173     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
174       myOkAxis = false;
175     return;
176   }
177   
178   // nbSel == 1
179   TopoDS_Shape S; 
180   Standard_Boolean testResult;
181   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
182   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
183     return;
184     
185   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
186     myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
187     if(!testResult)
188       return;
189     myEditCurrentArgument->setText(aString);
190     myOkBase = true;
191     myBase = S;
192   }
193   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
194     BRepAdaptor_Curve curv(TopoDS::Edge(S));
195     myDir = curv.Line().Direction();
196     myLoc = curv.Line().Location();
197     myEditCurrentArgument->setText(aString);
198     myOkAxis = true;
199   }
200
201   if(myOkBase && myOkAxis)
202     this->MakeRotationSimulationAndDisplay();
203   return; 
204 }
205
206
207 //=================================================================================
208 // function : SetEditCurrentArgument()
209 // purpose  :
210 //=================================================================================
211 void TransformationGUI_RotationDlg::SetEditCurrentArgument()
212 {
213   QPushButton* send = (QPushButton*)sender();
214   mySelection->ClearFilters();
215
216   if(send == GroupPoints->PushButton1) {
217     GroupPoints->LineEdit1->setFocus();
218     myEditCurrentArgument = GroupPoints->LineEdit1;
219   }
220   else if(send == GroupPoints->PushButton2) {
221     GroupPoints->LineEdit2->setFocus();
222     myEditCurrentArgument = GroupPoints->LineEdit2;
223     mySelection->AddFilter(myEdgeFilter);
224   }
225   this->SelectionIntoArgument();
226
227   return;
228 }
229
230
231 //=================================================================================
232 // function : LineEditReturnPressed()
233 // purpose  :
234 //=================================================================================
235 void TransformationGUI_RotationDlg::LineEditReturnPressed()
236 {  
237   QLineEdit* send = (QLineEdit*)sender();
238   if(send == GroupPoints->LineEdit1)
239     myEditCurrentArgument = GroupPoints->LineEdit1;
240   else if (send == GroupPoints->LineEdit2)
241     myEditCurrentArgument = GroupPoints->LineEdit2;
242   else
243     return;
244
245   GEOMBase_Skeleton::LineEditReturnPressed();
246   return;
247 }
248
249
250 //=================================================================================
251 // function : ActivateThisDialog()
252 // purpose  :
253 //=================================================================================
254 void TransformationGUI_RotationDlg::ActivateThisDialog()
255 {
256   GEOMBase_Skeleton::ActivateThisDialog();
257   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
258   GroupPoints->LineEdit1->setFocus();
259   myEditCurrentArgument = GroupPoints->LineEdit1;
260   if(!mySimulationTopoDs.IsNull())
261     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
262   return;
263 }
264
265
266 //=================================================================================
267 // function : enterEvent()
268 // purpose  :
269 //=================================================================================
270 void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
271 {
272   if (GroupConstructors->isEnabled())
273     return;
274   this->ActivateThisDialog();
275   return;
276 }
277
278
279 //=================================================================================
280 // function : ValueChangedInSpinBox()
281 // purpose  :
282 //=================================================================================
283 void TransformationGUI_RotationDlg::ValueChangedInSpinBox(double newValue)
284 {
285   myAngle = newValue;
286   if(myOkBase && myOkAxis)
287     MakeRotationSimulationAndDisplay();
288   return;
289 }
290
291
292 //=================================================================================
293 // function : MakeRotationSimulationAndDisplay()
294 // purpose  :
295 //=================================================================================
296 void TransformationGUI_RotationDlg::MakeRotationSimulationAndDisplay() 
297 {
298   myGeomBase->EraseSimulationShape();
299   mySimulationTopoDs.Nullify();
300
301   try {
302     gp_Ax1 AX(myLoc, myDir);
303     gp_Trsf theTransformation;
304     theTransformation.SetRotation(AX, myAngle*PI180);
305     BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
306     this->mySimulationTopoDs = myBRepTransformation.Shape();
307     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
308   }
309   catch(Standard_Failure) {
310     MESSAGE("Exception catched in MakeRotationSimulationAndDisplay");
311     return;
312   }
313   return;
314 }
315
316
317 //=================================================================================
318 // function : ReverseAngle()
319 // purpose  : 'state' not used here
320 //=================================================================================
321 void TransformationGUI_RotationDlg::ReverseAngle(int state)
322 {
323   myAngle = -myAngle;
324   GroupPoints->SpinBox_DX->SetValue(myAngle);
325   if(myOkBase && myOkAxis)
326     MakeRotationSimulationAndDisplay();
327   return;
328 }