]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_EllipseDlg.cxx
Salome HOME
DCQ : New Archi
[modules/geom.git] / src / BasicGUI / BasicGUI_EllipseDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE 
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : BasicGUI_EllipseDlg.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : GEOM
26 //  $Header$
27
28 using namespace std;
29 #include "BasicGUI_EllipseDlg.h"
30
31 #include <gp_Lin.hxx>
32 #include <gp_Elips.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include "QAD_Config.h"
36
37 //=================================================================================
38 // class    : BasicGUI_EllipseDlg()
39 // purpose  : Constructs a BasicGUI_EllipseDlg 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 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, 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_ELLIPSE_PV")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_ELLIPSE_TITLE"));
51   
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
54   RadioButton1->setPixmap(image0);
55   RadioButton2->close(TRUE);
56   RadioButton3->close(TRUE);
57
58   GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
59   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60   GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
61   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
62   GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MINOR"));
63   GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MAJOR"));
64   GroupPoints->PushButton1->setPixmap(image1);
65   GroupPoints->PushButton2->setPixmap(image1);
66
67   Layout1->addWidget(GroupPoints, 1, 0);
68   /***************************************************************/
69
70   /* Initialisations */
71   myBasicGUI = theBasicGUI;
72   Init();
73 }
74
75
76 //=================================================================================
77 // function : ~BasicGUI_EllipseDlg()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
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 BasicGUI_EllipseDlg::Init()
91 {
92   /* init variables */
93   myEditCurrentArgument = GroupPoints->LineEdit1;
94
95   myMajorRadius = 200.0;
96   myMinorRadius = 100.0;
97   myOkPoint = myOkDir = false;
98
99   myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
100   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
101   mySelection->AddFilter(myVertexFilter);
102
103   /* Get setting of step value from file configuration */
104   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
105   step = St.toDouble();
106
107   /* min, max, step and decimals for spin boxes & initial values */
108   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
109   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
110   GroupPoints->SpinBox_DX->SetValue(myMajorRadius);
111   GroupPoints->SpinBox_DY->SetValue(myMinorRadius);
112
113   /* signals and slots connections */
114   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116
117   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119
120   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122
123   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
124   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
125
126   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
127   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
128   
129   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
130
131   /* displays Dialog */
132   GroupPoints->show();
133   this->show();
134
135   return;
136 }
137
138
139 //=================================================================================
140 // function : ClickOnOk()
141 // purpose  :
142 //=================================================================================
143 void BasicGUI_EllipseDlg::ClickOnOk()
144 {
145   this->ClickOnApply();
146   ClickOnCancel();
147   return;
148 }
149
150 //=================================================================================
151 // function : ClickOnApply()
152 // purpose  :
153 //=================================================================================
154 void BasicGUI_EllipseDlg::ClickOnApply()
155 {
156   QAD_Application::getDesktop()->putInfo(tr(""));
157   if (mySimulationTopoDs.IsNull())
158     return;
159   myGeomBase->EraseSimulationShape();
160   mySimulationTopoDs.Nullify();
161
162   if(myOkPoint && myOkDir)
163     myBasicGUI->MakeEllipseAndDisplay(myPoint, myDir, myMajorRadius, myMinorRadius); 
164 }
165
166
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose  : Called when selection as changed or other case
170 //=================================================================================
171 void BasicGUI_EllipseDlg::SelectionIntoArgument()
172 {
173   myGeomBase->EraseSimulationShape();
174   mySimulationTopoDs.Nullify();
175   myEditCurrentArgument->setText("");
176   QString aString = ""; /* name of selection */
177   
178   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
179   if (nbSel != 1) {
180     if(myEditCurrentArgument == GroupPoints->LineEdit1)
181       myOkPoint = false;
182     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
183       myOkDir = false;
184     return;
185   }
186
187   /* nbSel == 1 */
188   TopoDS_Shape S;  
189   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
190     return;  
191  
192   /*  gp_Pnt : not used */
193   if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint)) {
194     GroupPoints->LineEdit1->setText(aString);
195     myOkPoint = true;
196   }    
197   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
198     BRepAdaptor_Curve curv(TopoDS::Edge(S));
199     myDir = curv.Line().Direction();
200     GroupPoints->LineEdit2->setText(aString);
201     myOkDir = true;
202   }
203
204   if(myOkPoint && myOkDir)
205     this->MakeEllipseSimulationAndDisplay();
206   return;
207 }
208
209
210 //=================================================================================
211 // function : SetEditCurrentArgument()
212 // purpose  :
213 //=================================================================================
214 void BasicGUI_EllipseDlg::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     mySelection->AddFilter(myVertexFilter);
223   }
224   else if(send == GroupPoints->PushButton2) {
225     GroupPoints->LineEdit2->setFocus();
226     myEditCurrentArgument = GroupPoints->LineEdit2;
227     mySelection->AddFilter(myEdgeFilter);
228   }
229   this->SelectionIntoArgument();
230
231   return;
232 }
233
234 //=================================================================================
235 // function : LineEditReturnPressed()
236 // purpose  :
237 //=================================================================================
238 void BasicGUI_EllipseDlg::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 BasicGUI_EllipseDlg::ActivateThisDialog()
258 {
259   GEOMBase_Skeleton::ActivateThisDialog();
260   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261   GroupPoints->LineEdit1->setFocus();
262   myEditCurrentArgument = GroupPoints->LineEdit1;
263   mySelection->AddFilter(myVertexFilter);
264   if(!mySimulationTopoDs.IsNull())
265     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
266   return;
267 }
268
269
270 //=================================================================================
271 // function : enterEvent()
272 // purpose  :
273 //=================================================================================
274 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
275 {
276   if (GroupConstructors->isEnabled())
277     return;
278   this->ActivateThisDialog();
279   return;
280 }
281
282
283 //=================================================================================
284 // function : ValueChangedInSpinBox()
285 // purpose  :
286 //=================================================================================
287 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
288 {
289   QObject* send = (QObject*)sender();
290
291   if(send == GroupPoints->SpinBox_DX )
292     myMajorRadius = newValue;
293   else if(send == GroupPoints->SpinBox_DY)
294     myMinorRadius = newValue;
295
296   if (myOkPoint && myOkDir)
297     MakeEllipseSimulationAndDisplay();
298   return;
299 }
300
301
302 //=================================================================================
303 // function : MakeEllipseSimulationAndDisplay()
304 // purpose  :
305 //=================================================================================
306 void BasicGUI_EllipseDlg::MakeEllipseSimulationAndDisplay() 
307 {
308   myGeomBase->EraseSimulationShape();
309   mySimulationTopoDs.Nullify();
310
311   if(myMajorRadius < myMinorRadius)
312     return;
313
314   try {
315     gp_Ax2 anAxis(myPoint, myDir);
316     gp_Elips ellipse(anAxis, myMajorRadius, myMinorRadius);
317     BRepBuilderAPI_MakeEdge MakeEdge(ellipse);
318     mySimulationTopoDs = MakeEdge.Shape();
319     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
320   }
321   catch(Standard_Failure) {
322     MESSAGE("Exception catched in MakeEllipseSimulationAndDisplay");
323   }
324   return;
325 }