1 // Created on: 1995-05-04
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1995-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 <Adaptor3d_Curve.hxx>
19 #include <ChFiDS_ElSpine.hxx>
20 #include <ChFiDS_SurfData.hxx>
21 #include <ElCLib.hxx>
22 #include <Geom_BezierCurve.hxx>
23 #include <Geom_BSplineCurve.hxx>
24 #include <Geom_Curve.hxx>
25 #include <gp_Ax1.hxx>
26 #include <gp_Circ.hxx>
27 #include <gp_Elips.hxx>
28 #include <gp_Hypr.hxx>
29 #include <gp_Lin.hxx>
30 #include <gp_Parab.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Vec.hxx>
33 #include <Precision.hxx>
34 #include <Standard_DomainError.hxx>
35 #include <Standard_NoSuchObject.hxx>
36 #include <Standard_OutOfRange.hxx>
37
IMPLEMENT_STANDARD_RTTIEXT(ChFiDS_ElSpine,Adaptor3d_Curve)38 IMPLEMENT_STANDARD_RTTIEXT(ChFiDS_ElSpine, Adaptor3d_Curve)
39
40 //=======================================================================
41 //function : ChFiDS_ElSpine
42 //purpose :
43 //=======================================================================
44 ChFiDS_ElSpine::ChFiDS_ElSpine()
45 : pfirst (0.0),
46 plast (0.0),
47 period (0.0),
48 periodic (Standard_False),
49 pfirstsav (Precision::Infinite()),
50 plastsav (Precision::Infinite())
51 {
52 }
53
54 //=======================================================================
55 //function : ShallowCopy
56 //purpose :
57 //=======================================================================
Handle(Adaptor3d_Curve)58 Handle(Adaptor3d_Curve) ChFiDS_ElSpine::ShallowCopy() const
59 {
60 Handle(ChFiDS_ElSpine) aCopy = new ChFiDS_ElSpine();
61
62 const Handle(Adaptor3d_Curve) aCurve = curve.ShallowCopy();
63 const GeomAdaptor_Curve& aGeomCurve = *(Handle(GeomAdaptor_Curve)::DownCast(aCurve));
64 aCopy->curve = aGeomCurve;
65
66 aCopy->ptfirst = ptfirst;
67 aCopy->ptlast = ptlast;
68 aCopy->tgfirst = tgfirst;
69 aCopy->tglast = tglast;
70 aCopy->VerticesWithTangents = VerticesWithTangents;
71 aCopy->previous = previous;
72 aCopy->next = next;
73 aCopy->pfirst = pfirst;
74 aCopy->plast = plast;
75 aCopy->period = period;
76 aCopy->periodic = periodic;
77 aCopy->pfirstsav = pfirstsav;
78 aCopy->plastsav = plastsav;
79
80 return aCopy;
81 }
82
83 //=======================================================================
84 //function : FirstParameter
85 //purpose :
86 //=======================================================================
87
FirstParameter() const88 Standard_Real ChFiDS_ElSpine::FirstParameter() const
89 {
90 return pfirst;
91 }
92
93
94 //=======================================================================
95 //function : LastParameter
96 //purpose :
97 //=======================================================================
98
LastParameter() const99 Standard_Real ChFiDS_ElSpine::LastParameter() const
100 {
101 return plast;
102 }
103
104 //=======================================================================
105 //function : GetSavedFirstParameter
106 //purpose :
107 //=======================================================================
108
GetSavedFirstParameter() const109 Standard_Real ChFiDS_ElSpine::GetSavedFirstParameter() const
110 {
111 return pfirstsav;
112 }
113
114 //=======================================================================
115 //function : GetSavedLastParameter
116 //purpose :
117 //=======================================================================
118
GetSavedLastParameter() const119 Standard_Real ChFiDS_ElSpine::GetSavedLastParameter() const
120 {
121 return plastsav;
122 }
123
124 //=======================================================================
125 //function : Continuity
126 //purpose :
127 //=======================================================================
128
Continuity() const129 GeomAbs_Shape ChFiDS_ElSpine::Continuity() const
130 {
131 return curve.Continuity();
132 }
133
134 //=======================================================================
135 //function : NbIntervals
136 //purpose :
137 //=======================================================================
138
NbIntervals(const GeomAbs_Shape S) const139 Standard_Integer ChFiDS_ElSpine::NbIntervals(const GeomAbs_Shape S) const
140 {
141 return curve.NbIntervals(S);
142 }
143
144 //=======================================================================
145 //function : Intervals
146 //purpose :
147 //=======================================================================
148
Intervals(TColStd_Array1OfReal & T,const GeomAbs_Shape S) const149 void ChFiDS_ElSpine::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) const
150 {
151 curve.Intervals(T,S);
152 }
153
154 //=======================================================================
155 //function : Trim
156 //purpose :
157 //=======================================================================
158
Handle(Adaptor3d_Curve)159 Handle(Adaptor3d_Curve) ChFiDS_ElSpine::Trim(const Standard_Real First,
160 const Standard_Real Last,
161 const Standard_Real Tol) const
162 {
163 return curve.Trim(First,Last,Tol);
164 }
165
166 //=======================================================================
167 //function : Resolution
168 //purpose :
169 //=======================================================================
170
Resolution(const Standard_Real R3d) const171 Standard_Real ChFiDS_ElSpine::Resolution(const Standard_Real R3d) const
172 {
173 return curve.Resolution(R3d);
174 }
175
176
177 //=======================================================================
178 //function : Resolution
179 //purpose :
180 //=======================================================================
181
GetType() const182 GeomAbs_CurveType ChFiDS_ElSpine::GetType() const
183 {
184 return curve.GetType();
185 }
186
187
188 //=======================================================================
189 //function : IsPeriodic
190 //purpose :
191 //=======================================================================
192
IsPeriodic() const193 Standard_Boolean ChFiDS_ElSpine::IsPeriodic() const
194 {
195 return periodic;
196 }
197
198
199 //=======================================================================
200 //function : SetPeriodic
201 //purpose :
202 //=======================================================================
203
SetPeriodic(const Standard_Boolean I)204 void ChFiDS_ElSpine::SetPeriodic(const Standard_Boolean I)
205 {
206 periodic = I;
207 period = plast - pfirst;
208 }
209
210
211
212 //=======================================================================
213 //function : Period
214 //purpose :
215 //=======================================================================
216
Period() const217 Standard_Real ChFiDS_ElSpine::Period() const
218 {
219 if(!periodic) throw Standard_Failure("ElSpine non periodique");
220 return period;
221 }
222
223
224 //=======================================================================
225 //function : Value
226 //purpose :
227 //=======================================================================
228
Value(const Standard_Real AbsC) const229 gp_Pnt ChFiDS_ElSpine::Value(const Standard_Real AbsC) const
230 {
231 return curve.Value(AbsC);
232 }
233
234
235 //=======================================================================
236 //function : D0
237 //purpose :
238 //=======================================================================
239
D0(const Standard_Real AbsC,gp_Pnt & P) const240 void ChFiDS_ElSpine::D0(const Standard_Real AbsC, gp_Pnt& P) const
241 {
242 curve.D0(AbsC,P);
243 }
244
245
246 //=======================================================================
247 //function : D1
248 //purpose :
249 //=======================================================================
250
D1(const Standard_Real AbsC,gp_Pnt & P,gp_Vec & V1) const251 void ChFiDS_ElSpine::D1(const Standard_Real AbsC, gp_Pnt& P, gp_Vec& V1)
252 const
253 {
254 curve.D1(AbsC,P,V1);
255 }
256
257
258 //=======================================================================
259 //function : D2
260 //purpose :
261 //=======================================================================
262
D2(const Standard_Real AbsC,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2) const263 void ChFiDS_ElSpine::D2(const Standard_Real AbsC,
264 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const
265 {
266 curve.D2(AbsC,P,V1,V2);
267 }
268
269 //=======================================================================
270 //function : D3
271 //purpose :
272 //=======================================================================
273
D3(const Standard_Real AbsC,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2,gp_Vec & V3) const274 void ChFiDS_ElSpine::D3(const Standard_Real AbsC,
275 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const
276 {
277 curve.D3(AbsC,P,V1,V2,V3);
278 }
279
280
281 //=======================================================================
282 //function : FirstParameter
283 //purpose :
284 //=======================================================================
285
FirstParameter(const Standard_Real P)286 void ChFiDS_ElSpine::FirstParameter(const Standard_Real P)
287 {
288 pfirst = P;
289 }
290
291
292 //=======================================================================
293 //function : LastParameter
294 //purpose :
295 //=======================================================================
296
LastParameter(const Standard_Real P)297 void ChFiDS_ElSpine::LastParameter(const Standard_Real P)
298 {
299 plast = P;
300 }
301
302 //=======================================================================
303 //function : SaveFirstParameter
304 //purpose :
305 //=======================================================================
306
SaveFirstParameter()307 void ChFiDS_ElSpine::SaveFirstParameter()
308 {
309 pfirstsav = pfirst;
310 }
311
312 //=======================================================================
313 //function : SaveLastParameter
314 //purpose :
315 //=======================================================================
316
SaveLastParameter()317 void ChFiDS_ElSpine::SaveLastParameter()
318 {
319 plastsav = plast;
320 }
321
322
323 //=======================================================================
324 //function : SetOrigin
325 //purpose :
326 //=======================================================================
327
SetOrigin(const Standard_Real O)328 void ChFiDS_ElSpine::SetOrigin(const Standard_Real O)
329 {
330 if(!periodic) throw Standard_Failure("Elspine non periodique");
331 Handle(Geom_BSplineCurve) bs = Handle(Geom_BSplineCurve)::DownCast(curve.Curve());
332 if(!bs.IsNull()) {
333 bs->SetOrigin(O,Precision::PConfusion());
334 curve.Load(bs);
335 }
336 }
337
338 //=======================================================================
339 //function : SetFirstPointAndTgt
340 //purpose :
341 //=======================================================================
342
SetFirstPointAndTgt(const gp_Pnt & P,const gp_Vec & T)343 void ChFiDS_ElSpine::SetFirstPointAndTgt(const gp_Pnt& P,
344 const gp_Vec& T)
345 {
346 ptfirst = P;
347 tgfirst = T;
348 }
349
350 //=======================================================================
351 //function : SetLastPointAndTgt
352 //purpose :
353 //=======================================================================
354
SetLastPointAndTgt(const gp_Pnt & P,const gp_Vec & T)355 void ChFiDS_ElSpine::SetLastPointAndTgt(const gp_Pnt& P,
356 const gp_Vec& T)
357 {
358 ptlast = P;
359 tglast = T;
360 }
361
362 //=======================================================================
363 //function : AddVertexWithTangent
364 //purpose :
365 //=======================================================================
366
AddVertexWithTangent(const gp_Ax1 & anAx1)367 void ChFiDS_ElSpine::AddVertexWithTangent(const gp_Ax1& anAx1)
368 {
369 VerticesWithTangents.Append(anAx1);
370 }
371
372 //=======================================================================
373 //function : FirstPointAndTgt
374 //purpose :
375 //=======================================================================
376
FirstPointAndTgt(gp_Pnt & P,gp_Vec & T) const377 void ChFiDS_ElSpine::FirstPointAndTgt(gp_Pnt& P,
378 gp_Vec& T) const
379 {
380 P = ptfirst;
381 T = tgfirst;
382 }
383
384 //=======================================================================
385 //function : LastPointAndTgt
386 //purpose :
387 //=======================================================================
388
LastPointAndTgt(gp_Pnt & P,gp_Vec & T) const389 void ChFiDS_ElSpine::LastPointAndTgt(gp_Pnt& P,
390 gp_Vec& T) const
391 {
392 P = ptlast;
393 T = tglast;
394 }
395
396 //=======================================================================
397 //function : NbVertices
398 //purpose :
399 //=======================================================================
400
NbVertices() const401 Standard_Integer ChFiDS_ElSpine::NbVertices() const
402 {
403 return VerticesWithTangents.Length();
404 }
405
406 //=======================================================================
407 //function : VertexWithTangent
408 //purpose :
409 //=======================================================================
410
VertexWithTangent(const Standard_Integer Index) const411 const gp_Ax1& ChFiDS_ElSpine::VertexWithTangent(const Standard_Integer Index) const
412 {
413 return VerticesWithTangents(Index);
414 }
415
416 //=======================================================================
417 //function : SetCurve
418 //purpose :
419 //=======================================================================
420
SetCurve(const Handle (Geom_Curve)& C)421 void ChFiDS_ElSpine::SetCurve(const Handle(Geom_Curve)& C)
422 {
423 curve.Load(C);
424 }
425
426 //=======================================================================
427 //function : Previous
428 //purpose :
429 //=======================================================================
430
Handle(ChFiDS_SurfData)431 const Handle(ChFiDS_SurfData)& ChFiDS_ElSpine::Previous() const
432 {
433 return previous;
434 }
435
436
437 //=======================================================================
438 //function : ChangePrevious
439 //purpose :
440 //=======================================================================
441
Handle(ChFiDS_SurfData)442 Handle(ChFiDS_SurfData)& ChFiDS_ElSpine::ChangePrevious()
443 {
444 return previous;
445 }
446
447 //=======================================================================
448 //function : Next
449 //purpose :
450 //=======================================================================
451
Handle(ChFiDS_SurfData)452 const Handle(ChFiDS_SurfData)& ChFiDS_ElSpine::Next() const
453 {
454 return next;
455 }
456
457
458 //=======================================================================
459 //function : ChangeNext
460 //purpose :
461 //=======================================================================
462
Handle(ChFiDS_SurfData)463 Handle(ChFiDS_SurfData)& ChFiDS_ElSpine::ChangeNext()
464 {
465 return next;
466 }
467
468 // --
469 // -- The following methods must be called when GetType returned
470 // -- the corresponding type.
471 // --
472
473 //=======================================================================
474 //function : Line
475 //purpose :
476 //=======================================================================
477
Line() const478 gp_Lin ChFiDS_ElSpine::Line() const
479 {
480 return curve.Line();
481 }
482
483 //=======================================================================
484 //function : Circle
485 //purpose :
486 //=======================================================================
487
Circle() const488 gp_Circ ChFiDS_ElSpine::Circle() const
489 {
490 return curve.Circle();
491 }
492
493 //=======================================================================
494 //function : Ellipse
495 //purpose :
496 //=======================================================================
497
Ellipse() const498 gp_Elips ChFiDS_ElSpine::Ellipse() const
499 {
500 return curve.Ellipse();
501 }
502
503 //=======================================================================
504 //function : Hyperbola
505 //purpose :
506 //=======================================================================
507
Hyperbola() const508 gp_Hypr ChFiDS_ElSpine::Hyperbola() const
509 {
510 return curve.Hyperbola();
511 }
512
513 //=======================================================================
514 //function : Parabola
515 //purpose :
516 //=======================================================================
517
Parabola() const518 gp_Parab ChFiDS_ElSpine::Parabola() const
519 {
520 return curve.Parabola();
521 }
522
523 //=======================================================================
524 //function : Bezier
525 //purpose :
526 //=======================================================================
527
Handle(Geom_BezierCurve)528 Handle(Geom_BezierCurve) ChFiDS_ElSpine::Bezier() const
529 {
530 return curve.Bezier();
531 }
532
533 //=======================================================================
534 //function : BSpline
535 //purpose :
536 //=======================================================================
537
Handle(Geom_BSplineCurve)538 Handle(Geom_BSplineCurve) ChFiDS_ElSpine::BSpline() const
539 {
540 return curve.BSpline();
541 }
542