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