]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_RevolDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/geom.git] / src / GenerationGUI / GenerationGUI_RevolDlg.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   : GenerationGUI_RevolDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GenerationGUI_RevolDlg.h"
31
32 #include <gp_Lin.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <BRepPrimAPI_MakeRevol.hxx>
35 #include "QAD_Config.h"
36
37 //=================================================================================
38 // class    : GenerationGUI_RevolDlg()
39 // purpose  : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the 
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 {
47   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_REVOLUTION_TITLE"));
51
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
54   RadioButton1->setPixmap(image0);
55   RadioButton2->close(TRUE);
56   RadioButton3->close(TRUE);
57
58   GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
59   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
61   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
62   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
63   GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
64   GroupPoints->PushButton1->setPixmap(image1);
65   GroupPoints->PushButton2->setPixmap(image1);
66
67   Layout1->addWidget(GroupPoints, 1, 0);
68   /***************************************************************/
69
70   /* Initialisations */
71   myGenerationGUI = theGenerationGUI;
72   Init();
73 }
74
75
76 //=================================================================================
77 // function : ~GenerationGUI_RevolDlg()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
81 {
82   // no need to delete child widgets, Qt does it all for us
83 }
84
85
86 //=================================================================================
87 // function : Init()
88 // purpose  :
89 //=================================================================================
90 void GenerationGUI_RevolDlg::Init()
91 {
92   /* init variables */
93   myEditCurrentArgument = GroupPoints->LineEdit1;
94
95   myAngle = 45.0;
96   myOkBase = myOkAxis = false;
97
98   myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
99
100   double SpecificStep = 5;
101   /* min, max, step and decimals for spin boxes & initial values */
102   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
103   GroupPoints->SpinBox_DX->SetValue(myAngle);
104
105   /* signals and slots connections */
106   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108
109   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111
112   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114
115   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
116   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
117
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 GenerationGUI_RevolDlg::ClickOnOk()
135 {
136   this->ClickOnApply();
137   ClickOnCancel();
138   return;
139 }
140
141
142 //=================================================================================
143 // function : ClickOnApply()
144 // purpose  :
145 //=================================================================================
146 void GenerationGUI_RevolDlg::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     myGenerationGUI->MakeRevolutionAndDisplay(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 GenerationGUI_RevolDlg::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     TopAbs_ShapeEnum aType = S.ShapeType();
193     if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType != TopAbs_COMPOUND)
194       return;
195     myEditCurrentArgument->setText(aString);
196     myOkBase = true;
197     myBase = S;
198   }
199   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
200     BRepAdaptor_Curve curv(TopoDS::Edge(S));
201     myDir = curv.Line().Direction();
202     myLoc = curv.Line().Location();
203     myEditCurrentArgument->setText(aString);
204     myOkAxis = true;
205   }
206
207   if(myOkBase && myOkAxis)
208     this->MakeRevolutionSimulationAndDisplay();
209   return; 
210 }
211
212
213 //=================================================================================
214 // function : SetEditCurrentArgument()
215 // purpose  :
216 //=================================================================================
217 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
218 {
219   QPushButton* send = (QPushButton*)sender();
220   mySelection->ClearFilters();
221
222   if(send == GroupPoints->PushButton1) {
223     GroupPoints->LineEdit1->setFocus();
224     myEditCurrentArgument = GroupPoints->LineEdit1;
225   }
226   else if(send == GroupPoints->PushButton2) {
227     GroupPoints->LineEdit2->setFocus();
228     myEditCurrentArgument = GroupPoints->LineEdit2;
229     mySelection->AddFilter(myEdgeFilter);
230   }
231   this->SelectionIntoArgument();
232
233   return;
234 }
235
236
237 //=================================================================================
238 // function : LineEditReturnPressed()
239 // purpose  :
240 //=================================================================================
241 void GenerationGUI_RevolDlg::LineEditReturnPressed()
242 {  
243   QLineEdit* send = (QLineEdit*)sender();
244   if(send == GroupPoints->LineEdit1)
245     myEditCurrentArgument = GroupPoints->LineEdit1;
246   else if (send == GroupPoints->LineEdit2)
247     myEditCurrentArgument = GroupPoints->LineEdit2;
248   else
249     return;
250
251   GEOMBase_Skeleton::LineEditReturnPressed();
252   return;
253 }
254
255
256 //=================================================================================
257 // function : ActivateThisDialog()
258 // purpose  :
259 //=================================================================================
260 void GenerationGUI_RevolDlg::ActivateThisDialog()
261 {
262   GEOMBase_Skeleton::ActivateThisDialog();
263   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
264   GroupPoints->LineEdit1->setFocus();
265   myEditCurrentArgument = GroupPoints->LineEdit1;
266   if(!mySimulationTopoDs.IsNull())
267     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
268   return;
269 }
270
271
272 //=================================================================================
273 // function : enterEvent()
274 // purpose  :
275 //=================================================================================
276 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
277 {
278   if (GroupConstructors->isEnabled())
279     return;
280   this->ActivateThisDialog();
281   return;
282 }
283
284
285 //=================================================================================
286 // function : ValueChangedInSpinBox()
287 // purpose  :
288 //=================================================================================
289 void GenerationGUI_RevolDlg::ValueChangedInSpinBox(double newValue)
290 {  
291   myAngle = newValue;
292   if(myOkBase && myOkAxis)
293     this->MakeRevolutionSimulationAndDisplay();
294   return;
295 }
296
297
298 //=================================================================================
299 // function : ReverseAngle()
300 // purpose  : 'state' not used here
301 //=================================================================================
302 void GenerationGUI_RevolDlg::ReverseAngle(int state)
303 {
304   myAngle = -myAngle;
305   GroupPoints->SpinBox_DX->SetValue(myAngle);
306   if(myOkBase && myOkAxis)
307     this->MakeRevolutionSimulationAndDisplay();
308   return;
309 }
310
311
312 //=================================================================================
313 // function : MakeRevolutionSimulationAndDisplay()
314 // purpose  :
315 //=================================================================================
316 void GenerationGUI_RevolDlg::MakeRevolutionSimulationAndDisplay() 
317 {
318   myGeomBase->EraseSimulationShape();
319   mySimulationTopoDs.Nullify();
320
321   TopAbs_ShapeEnum aType = myBase.ShapeType();
322   if(aType != TopAbs_VERTEX && aType != TopAbs_EDGE && aType != TopAbs_WIRE && aType != TopAbs_FACE && aType != TopAbs_SHELL && aType !=TopAbs_COMPOUND)
323     return;
324
325   try {
326     gp_Ax1 AX(myLoc, myDir);
327     mySimulationTopoDs = BRepPrimAPI_MakeRevol(myBase, AX, myAngle*PI180);
328     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
329   }
330   catch(Standard_Failure) {
331     MESSAGE("Exception catched in MakeRevolutionSimulationAndDisplay");
332     return;
333   }
334   return;
335 }