0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Geom / Geom_Parabola.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <ElCLib.hxx>
19 #include <Geom_Geometry.hxx>
20 #include <Geom_Parabola.hxx>
21 #include <gp_Ax1.hxx>
22 #include <gp_Ax2.hxx>
23 #include <gp_Parab.hxx>
24 #include <gp_Pnt.hxx>
25 #include <gp_Trsf.hxx>
26 #include <gp_Vec.hxx>
27 #include <gp_XYZ.hxx>
28 #include <Precision.hxx>
29 #include <Standard_ConstructionError.hxx>
30 #include <Standard_RangeError.hxx>
31 #include <Standard_Type.hxx>
32
33 IMPLEMENT_STANDARD_RTTIEXT(Geom_Parabola,Geom_Conic)
34
35 typedef Geom_Parabola         Parabola;
36 typedef gp_Ax1  Ax1;
37 typedef gp_Ax2  Ax2;
38 typedef gp_Pnt  Pnt;
39 typedef gp_Trsf Trsf;
40 typedef gp_Vec  Vec;
41 typedef gp_XYZ  XYZ;
42
43 //=======================================================================
44 //function : Copy
45 //purpose  : 
46 //=======================================================================
47
48 Handle(Geom_Geometry) Geom_Parabola::Copy() const {
49
50    Handle(Geom_Parabola) Prb;
51    Prb = new Parabola (pos, focalLength);
52    return Prb;
53 }
54
55
56
57 //=======================================================================
58 //function : Geom_Parabola
59 //purpose  : 
60 //=======================================================================
61
62 Geom_Parabola::Geom_Parabola (const gp_Parab& Prb) 
63  : focalLength (Prb.Focal()) 
64 { pos = Prb.Position(); }
65
66
67 //=======================================================================
68 //function : Geom_Parabola
69 //purpose  : 
70 //=======================================================================
71
72 Geom_Parabola::Geom_Parabola (const Ax2& A2, const Standard_Real Focal) 
73  : focalLength (Focal) {
74    
75   if(Focal < 0.0)  throw Standard_ConstructionError();
76   pos = A2;
77 }
78
79
80 //=======================================================================
81 //function : Geom_Parabola
82 //purpose  : 
83 //=======================================================================
84
85 Geom_Parabola::Geom_Parabola (const Ax1& D, const Pnt& F) {
86
87    gp_Parab Prb (D, F);
88    pos = Prb.Position();
89    focalLength = Prb.Focal();
90 }
91
92 //=======================================================================
93 //function : ReversedParameter
94 //purpose  : 
95 //=======================================================================
96
97 Standard_Real Geom_Parabola::ReversedParameter( const Standard_Real U) const
98 {
99   return (-U);
100 }
101
102
103 //=======================================================================
104 //function : IsClosed
105 //purpose  : 
106 //=======================================================================
107
108 Standard_Boolean Geom_Parabola::IsClosed () const { return Standard_False; }
109
110 //=======================================================================
111 //function : IsPeriodic
112 //purpose  : 
113 //=======================================================================
114
115 Standard_Boolean Geom_Parabola::IsPeriodic () const     {  return Standard_False; }
116
117 //=======================================================================
118 //function : Eccentricity
119 //purpose  : 
120 //=======================================================================
121
122 Standard_Real Geom_Parabola::Eccentricity () const      { return 1.0; }
123
124 //=======================================================================
125 //function : FirstParameter
126 //purpose  : 
127 //=======================================================================
128
129 Standard_Real Geom_Parabola::FirstParameter () const    
130 { return -Precision::Infinite(); }
131
132 //=======================================================================
133 //function : Focal
134 //purpose  : 
135 //=======================================================================
136
137 Standard_Real Geom_Parabola::Focal () const             { return focalLength; }
138
139 //=======================================================================
140 //function : LastParameter
141 //purpose  : 
142 //=======================================================================
143
144 Standard_Real Geom_Parabola::LastParameter () const     
145 { return Precision::Infinite(); }
146
147 //=======================================================================
148 //function : Parameter
149 //purpose  : 
150 //=======================================================================
151
152 Standard_Real Geom_Parabola::Parameter () const         { return 2.0 * focalLength; }
153
154 //=======================================================================
155 //function : SetFocal
156 //purpose  : 
157 //=======================================================================
158
159 void Geom_Parabola::SetFocal (const Standard_Real Focal) {
160
161    if (Focal < 0.0)  throw Standard_ConstructionError();
162    focalLength = Focal;
163 }
164
165
166 //=======================================================================
167 //function : SetParab
168 //purpose  : 
169 //=======================================================================
170
171 void Geom_Parabola::SetParab (const gp_Parab& Prb) {
172
173    focalLength = Prb.Focal ();
174    pos = Prb.Position ();
175 }
176
177
178 //=======================================================================
179 //function : Directrix
180 //purpose  : 
181 //=======================================================================
182
183 Ax1 Geom_Parabola::Directrix () const {
184
185    gp_Parab Prb (pos, focalLength);
186    return Prb.Directrix();
187 }
188
189
190 //=======================================================================
191 //function : D0
192 //purpose  : 
193 //=======================================================================
194
195 void Geom_Parabola::D0 (const Standard_Real U, Pnt& P) const {
196
197    P = ElCLib::ParabolaValue (U, pos, focalLength);
198 }
199
200
201 //=======================================================================
202 //function : D1
203 //purpose  : 
204 //=======================================================================
205
206 void Geom_Parabola::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {
207
208   ElCLib::ParabolaD1 (U, pos, focalLength, P, V1);
209 }
210
211
212 //=======================================================================
213 //function : D2
214 //purpose  : 
215 //=======================================================================
216
217 void Geom_Parabola::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const {
218
219    ElCLib::ParabolaD2 (U, pos, focalLength, P, V1, V2);
220 }
221
222
223 //=======================================================================
224 //function : D3
225 //purpose  : 
226 //=======================================================================
227
228 void Geom_Parabola::D3 (const Standard_Real U, 
229                         Pnt& P, Vec& V1, Vec& V2, Vec& V3) const {
230
231    ElCLib::ParabolaD2 (U, pos, focalLength, P, V1, V2);
232    V3.SetCoord (0.0, 0.0, 0.0);
233 }
234
235
236 //=======================================================================
237 //function : DN
238 //purpose  : 
239 //=======================================================================
240
241 Vec Geom_Parabola::DN (const Standard_Real U, const Standard_Integer N) const {
242
243   Standard_RangeError_Raise_if (N < 1, " ");
244    return ElCLib::ParabolaDN (U, pos, focalLength, N);
245 }
246
247
248 //=======================================================================
249 //function : Focus
250 //purpose  : 
251 //=======================================================================
252
253 Pnt Geom_Parabola::Focus () const {
254
255   Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
256   pos.Location().Coord (Xp, Yp, Zp);
257   pos.XDirection().Coord (Xd, Yd, Zd);
258   return Pnt (Xp + focalLength*Xd, Yp + focalLength*Yd, Zp + focalLength*Zd);
259 }
260
261
262 //=======================================================================
263 //function : Parab
264 //purpose  : 
265 //=======================================================================
266
267 gp_Parab Geom_Parabola::Parab () const {
268
269    return gp_Parab (pos, focalLength);
270 }
271
272
273 //=======================================================================
274 //function : Transform
275 //purpose  : 
276 //=======================================================================
277
278 void Geom_Parabola::Transform (const Trsf& T) {
279
280   focalLength *= Abs(T.ScaleFactor());
281   pos.Transform (T);
282 }
283
284
285
286 //=======================================================================
287 //function : TransformedParameter
288 //purpose  : 
289 //=======================================================================
290
291 Standard_Real Geom_Parabola::TransformedParameter(const Standard_Real U,
292                                                   const gp_Trsf& T) const
293 {
294   if (Precision::IsInfinite(U)) return U;
295   return U * Abs(T.ScaleFactor());
296 }
297
298
299 //=======================================================================
300 //function : TransformedParameter
301 //purpose  : 
302 //=======================================================================
303
304 Standard_Real Geom_Parabola::ParametricTransformation(const gp_Trsf& T) const
305 {
306   return Abs(T.ScaleFactor());
307 }
308
309