0032485: Modeling Algorithms - Add Clone() function for adapters
[occt.git] / src / Adaptor2d / Adaptor2d_Line2d.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <Adaptor2d_Line2d.hxx>
15
16 #include <ElCLib.hxx>
17 #include <Geom2d_BezierCurve.hxx>
18 #include <Geom2d_BSplineCurve.hxx>
19 #include <gp_Circ2d.hxx>
20 #include <gp_Dir2d.hxx>
21 #include <gp_Elips2d.hxx>
22 #include <gp_Hypr2d.hxx>
23 #include <gp_Lin2d.hxx>
24 #include <gp_Parab2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <Precision.hxx>
28 #include <Standard_DomainError.hxx>
29 #include <Standard_NoSuchObject.hxx>
30 #include <Standard_OutOfRange.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(Adaptor2d_Line2d, Adaptor2d_Curve2d)
33
34 //=======================================================================
35 //function : Adaptor2d_Line2d
36 //purpose  : 
37 //=======================================================================
38 Adaptor2d_Line2d::Adaptor2d_Line2d()
39 : myUfirst(0.0), myUlast (0.0)
40 {
41 }
42
43 //=======================================================================
44 //function : Adaptor_Line2d
45 //purpose  : 
46 //=======================================================================
47
48  Adaptor2d_Line2d::Adaptor2d_Line2d(const gp_Pnt2d&     P,
49                                     const gp_Dir2d&     D,
50                                     const Standard_Real UFirst,
51                                     const Standard_Real ULast)
52 : myUfirst(UFirst), myUlast(ULast), myAx2d(P,D)
53 {
54 }
55
56 //=======================================================================
57 //function : ShallowCopy
58 //purpose  : 
59 //=======================================================================
60
61  Handle(Adaptor2d_Curve2d) Adaptor2d_Line2d::ShallowCopy() const
62  {
63    Handle(Adaptor2d_Line2d) aCopy = new Adaptor2d_Line2d();
64
65    aCopy->myUfirst = myUfirst;
66    aCopy->myUlast  = myUlast;
67    aCopy->myAx2d   = myAx2d;
68
69    return aCopy;
70  }
71
72 //=======================================================================
73 //function : Load
74 //purpose  : 
75 //=======================================================================
76
77 void Adaptor2d_Line2d::Load(const gp_Lin2d& L)
78 {
79   myAx2d   =  L.Position();
80   myUfirst = -Precision::Infinite();
81   myUlast  =  Precision::Infinite();
82 }
83
84 //=======================================================================
85 //function : Load
86 //purpose  : 
87 //=======================================================================
88
89 void Adaptor2d_Line2d::Load(const gp_Lin2d& L, const Standard_Real Fi, const Standard_Real La)
90 {
91   myAx2d   =  L.Position();
92   myUfirst =  Fi;
93   myUlast  =  La;
94 }
95
96 //=======================================================================
97 //function : FirstParameter
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Real Adaptor2d_Line2d::FirstParameter() const 
102 {
103   return myUfirst;
104 }
105
106 //=======================================================================
107 //function : LastParameter
108 //purpose  : 
109 //=======================================================================
110
111 Standard_Real Adaptor2d_Line2d::LastParameter() const 
112 {
113   return myUlast;
114 }
115
116 //=======================================================================
117 //function : Continuity
118 //purpose  : 
119 //=======================================================================
120
121 GeomAbs_Shape Adaptor2d_Line2d::Continuity() const 
122 {
123   return GeomAbs_CN;
124 }
125
126 //=======================================================================
127 //function : NbIntervals
128 //purpose  : 
129 //=======================================================================
130
131 //Standard_Integer Adaptor2d_Line2d::NbIntervals(const GeomAbs_Shape S) const 
132 Standard_Integer Adaptor2d_Line2d::NbIntervals(const GeomAbs_Shape ) const 
133 {
134   return 1;
135 }
136
137 //=======================================================================
138 //function : Interval
139 //purpose  : 
140 //=======================================================================
141
142 void Adaptor2d_Line2d::Intervals(TColStd_Array1OfReal& T,
143 //                             const GeomAbs_Shape S) const 
144                                const GeomAbs_Shape ) const 
145 {
146   T(T.Lower())   = myUfirst;
147   T(T.Lower()+1) = myUlast;
148 }
149
150 //=======================================================================
151 //function : Trim
152 //purpose  : 
153 //=======================================================================
154
155 Handle(Adaptor2d_Curve2d) Adaptor2d_Line2d::Trim
156 (const Standard_Real First,
157  const Standard_Real Last,
158  const Standard_Real) const 
159 {
160   Handle(Adaptor2d_Line2d) HL = new Adaptor2d_Line2d();
161   HL->Load(gp_Lin2d(myAx2d),First,Last);
162   return HL;
163 }
164
165 //=======================================================================
166 //function : IsClosed
167 //purpose  : 
168 //=======================================================================
169
170 Standard_Boolean Adaptor2d_Line2d::IsClosed() const 
171 {
172   return Standard_False;
173 }
174
175 //=======================================================================
176 //function : IsPeriodic
177 //purpose  : 
178 //=======================================================================
179
180 Standard_Boolean Adaptor2d_Line2d::IsPeriodic() const 
181 {
182   return Standard_False;
183 }
184
185 //=======================================================================
186 //function : Period
187 //purpose  : 
188 //=======================================================================
189
190 Standard_Real Adaptor2d_Line2d::Period() const 
191 {
192   throw Standard_NoSuchObject();
193 }
194
195 //=======================================================================
196 //function : Value
197 //purpose  : 
198 //=======================================================================
199
200 gp_Pnt2d Adaptor2d_Line2d::Value(const Standard_Real X) const 
201 {
202   return ElCLib::LineValue(X,myAx2d);
203 }
204
205 //=======================================================================
206 //function : D0
207 //purpose  : 
208 //=======================================================================
209
210 void Adaptor2d_Line2d::D0(const Standard_Real X, gp_Pnt2d& P) const 
211 {
212   P = ElCLib::LineValue(X,myAx2d);
213 }
214
215 //=======================================================================
216 //function : D1
217 //purpose  : 
218 //=======================================================================
219
220 void Adaptor2d_Line2d::D1(const Standard_Real X, gp_Pnt2d& P, gp_Vec2d& V) const 
221 {
222   ElCLib::LineD1(X,myAx2d,P,V);
223 }
224
225 //=======================================================================
226 //function : D2
227 //purpose  : 
228 //=======================================================================
229
230 void Adaptor2d_Line2d::D2(const Standard_Real X, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const 
231 {
232   ElCLib::LineD1(X,myAx2d,P,V1);
233   V2.SetCoord(0.,0.);
234 }
235
236 //=======================================================================
237 //function : D3
238 //purpose  : 
239 //=======================================================================
240
241 void Adaptor2d_Line2d::D3(const Standard_Real X, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const 
242 {
243   ElCLib::LineD1(X,myAx2d,P,V1);
244   V2.SetCoord(0.,0.);
245   V3.SetCoord(0.,0.);
246 }
247
248 //=======================================================================
249 //function : DN
250 //purpose  : 
251 //=======================================================================
252
253 //gp_Vec2d Adaptor2d_Line2d::DN(const Standard_Real U, const Standard_Integer N) const 
254 gp_Vec2d Adaptor2d_Line2d::DN(const Standard_Real , const Standard_Integer N) const 
255 {
256   if (N<=0) {throw Standard_OutOfRange();}
257   if (N==1) {
258     return myAx2d.Direction();
259   }
260   return gp_Vec2d(0.,0.);
261 }
262
263 //=======================================================================
264 //function : Resolution
265 //purpose  : 
266 //=======================================================================
267
268 Standard_Real Adaptor2d_Line2d::Resolution(const Standard_Real R3d) const 
269 {
270   return R3d; // nul !!!!
271 }
272
273 //=======================================================================
274 //function : GetType
275 //purpose  : 
276 //=======================================================================
277
278 GeomAbs_CurveType Adaptor2d_Line2d::GetType() const 
279 {
280   return GeomAbs_Line;
281 }
282
283 //=======================================================================
284 //function : Line
285 //purpose  : 
286 //=======================================================================
287
288 gp_Lin2d Adaptor2d_Line2d::Line() const 
289 {
290   return gp_Lin2d(myAx2d);
291 }
292
293 //=======================================================================
294 //function : Circle
295 //purpose  : 
296 //=======================================================================
297
298 gp_Circ2d Adaptor2d_Line2d::Circle() const 
299 {
300   throw Standard_NoSuchObject();
301 }
302
303 //=======================================================================
304 //function : Ellipse
305 //purpose  : 
306 //=======================================================================
307
308 gp_Elips2d Adaptor2d_Line2d::Ellipse() const 
309 {
310   throw Standard_NoSuchObject();
311 }
312
313 //=======================================================================
314 //function : Hyperbola
315 //purpose  : 
316 //=======================================================================
317
318 gp_Hypr2d Adaptor2d_Line2d::Hyperbola() const 
319 {
320   throw Standard_NoSuchObject();
321 }
322
323 //=======================================================================
324 //function : Parabola
325 //purpose  : 
326 //=======================================================================
327
328 gp_Parab2d Adaptor2d_Line2d::Parabola() const 
329 {
330   throw Standard_NoSuchObject();
331 }
332
333 //=======================================================================
334 //function : Degree
335 //purpose  : 
336 //=======================================================================
337
338 Standard_Integer Adaptor2d_Line2d::Degree()  const 
339  {
340   throw Standard_NoSuchObject();
341 }
342 //=======================================================================
343 //function : IsRational
344 //purpose  : 
345 //=======================================================================
346
347 Standard_Boolean Adaptor2d_Line2d::IsRational()  const 
348  {
349   throw Standard_NoSuchObject();
350 }
351 //=======================================================================
352 //function : NbPoles
353 //purpose  : 
354 //=======================================================================
355
356 Standard_Integer Adaptor2d_Line2d::NbPoles()  const 
357  {
358   throw Standard_NoSuchObject();
359 }
360 //=======================================================================
361 //function : NbKnots
362 //purpose  : 
363 //=======================================================================
364
365 Standard_Integer Adaptor2d_Line2d::NbKnots()  const 
366  {
367   throw Standard_NoSuchObject();
368 }
369 //=======================================================================
370 //function : Bezier
371 //purpose  : 
372 //=======================================================================
373
374 Handle(Geom2d_BezierCurve) Adaptor2d_Line2d::Bezier() const 
375 {
376   throw Standard_NoSuchObject();
377 }
378
379 //=======================================================================
380 //function : BSpline
381 //purpose  : 
382 //=======================================================================
383
384 Handle(Geom2d_BSplineCurve) Adaptor2d_Line2d::BSpline() const 
385 {
386   throw Standard_NoSuchObject();
387 }
388