b311480e |
1 | // Created on: 1993-02-19 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <BRepAdaptor_Curve.ixx> |
18 | |
19 | #include <BRepAdaptor_HCurve.hxx> |
20 | #include <BRep_Tool.hxx> |
21 | #include <Geom2d_Curve.hxx> |
22 | #include <Geom_Surface.hxx> |
23 | #include <Geom2dAdaptor_HCurve.hxx> |
24 | #include <GeomAdaptor_HSurface.hxx> |
ec357c5c |
25 | #include <Adaptor3d_HCurveOnSurface.hxx> |
26 | #include <Geom_BezierCurve.hxx> |
27 | #include <Geom_BSplineCurve.hxx> |
7fd59977 |
28 | |
29 | //======================================================================= |
30 | //function : BRepAdaptor_Curve |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | BRepAdaptor_Curve::BRepAdaptor_Curve() |
35 | {} |
36 | |
37 | //======================================================================= |
38 | //function : BRepAdaptor_Curve |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E) |
43 | { |
44 | Initialize(E); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : BRepAdaptor_Curve |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E, |
53 | const TopoDS_Face& F) |
54 | { |
55 | Initialize(E,F); |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : Initialize |
60 | //purpose : |
61 | //======================================================================= |
62 | |
63 | void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E) |
64 | { |
65 | myConSurf.Nullify(); |
66 | myEdge = E; |
67 | Standard_Real pf,pl; |
68 | |
69 | TopLoc_Location L; |
70 | Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,pf,pl); |
71 | |
72 | if (!C.IsNull()) { |
73 | myCurve.Load(C,pf,pl); |
74 | } |
75 | else { |
76 | Handle(Geom2d_Curve) PC; |
77 | Handle(Geom_Surface) S; |
78 | BRep_Tool::CurveOnSurface(E,PC,S,L,pf,pl); |
79 | if (!PC.IsNull()) { |
80 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); |
81 | HS->ChangeSurface().Load(S); |
82 | Handle(Geom2dAdaptor_HCurve) HC = new Geom2dAdaptor_HCurve(); |
83 | HC->ChangeCurve2d().Load(PC,pf,pl); |
84 | myConSurf = new Adaptor3d_HCurveOnSurface(); |
543a9964 |
85 | myConSurf->ChangeCurve().Load(HC, HS); |
7fd59977 |
86 | } |
87 | else { |
88 | Standard_NullObject::Raise("BRepAdaptor_Curve::No geometry"); |
89 | } |
90 | } |
91 | myTrsf = L.Transformation(); |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : Initialize |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E, |
100 | const TopoDS_Face& F) |
101 | { |
102 | myConSurf.Nullify(); |
103 | |
104 | myEdge = E; |
105 | TopLoc_Location L; |
106 | Standard_Real pf,pl; |
107 | Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
108 | Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,F,pf,pl); |
109 | |
110 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); |
111 | HS->ChangeSurface().Load(S); |
112 | Handle(Geom2dAdaptor_HCurve) HC = new Geom2dAdaptor_HCurve(); |
113 | HC->ChangeCurve2d().Load(PC,pf,pl); |
114 | myConSurf = new Adaptor3d_HCurveOnSurface(); |
543a9964 |
115 | myConSurf->ChangeCurve().Load(HC, HS); |
7fd59977 |
116 | |
117 | myTrsf = L.Transformation(); |
118 | } |
119 | |
120 | //======================================================================= |
121 | //function : Trsf |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | const gp_Trsf& BRepAdaptor_Curve::Trsf() const |
126 | { |
127 | return myTrsf; |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : Is3DCurve |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | Standard_Boolean BRepAdaptor_Curve::Is3DCurve() const |
136 | { |
137 | return myConSurf.IsNull(); |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : IsCurveOnSurface |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | Standard_Boolean BRepAdaptor_Curve::IsCurveOnSurface() const |
146 | { |
147 | return !myConSurf.IsNull(); |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Curve |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | const GeomAdaptor_Curve& BRepAdaptor_Curve::Curve() const |
156 | { |
157 | return myCurve; |
158 | } |
159 | |
160 | //======================================================================= |
161 | //function : CurveOnSurface |
162 | //purpose : |
163 | //======================================================================= |
164 | |
165 | const Adaptor3d_CurveOnSurface& BRepAdaptor_Curve::CurveOnSurface() const |
166 | { |
167 | return *((Adaptor3d_CurveOnSurface*)&(myConSurf->Curve())); |
168 | } |
169 | |
170 | //======================================================================= |
171 | //function : Edge |
172 | //purpose : |
173 | //======================================================================= |
174 | |
175 | const TopoDS_Edge& BRepAdaptor_Curve::Edge() const |
176 | { |
177 | return myEdge; |
178 | } |
179 | |
180 | //======================================================================= |
181 | //function : Tolerance |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | Standard_Real BRepAdaptor_Curve::Tolerance() const |
186 | { |
187 | return BRep_Tool::Tolerance(myEdge); |
188 | } |
189 | |
190 | //======================================================================= |
191 | //function : FirstParameter |
192 | //purpose : |
193 | //======================================================================= |
194 | |
195 | Standard_Real BRepAdaptor_Curve::FirstParameter() const |
196 | { |
197 | if (myConSurf.IsNull()) { |
198 | return myCurve.FirstParameter(); |
199 | } |
200 | else { |
201 | return myConSurf->FirstParameter(); |
202 | } |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : LastParameter |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | Standard_Real BRepAdaptor_Curve::LastParameter() const |
211 | { |
212 | if (myConSurf.IsNull()) { |
213 | return myCurve.LastParameter(); |
214 | } |
215 | else { |
216 | return myConSurf->LastParameter(); |
217 | } |
218 | } |
219 | |
220 | //======================================================================= |
221 | //function : Continuity |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | GeomAbs_Shape BRepAdaptor_Curve::Continuity() const |
226 | { |
227 | if (myConSurf.IsNull()) { |
228 | return myCurve.Continuity(); |
229 | } |
230 | else { |
231 | return myConSurf->Continuity(); |
232 | } |
233 | } |
234 | |
235 | //======================================================================= |
236 | //function : NbIntervals |
237 | //purpose : |
238 | //======================================================================= |
239 | |
31b1749c |
240 | Standard_Integer BRepAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const |
7fd59977 |
241 | { |
242 | if (myConSurf.IsNull()) { |
243 | return myCurve.NbIntervals(S); |
244 | } |
245 | else { |
246 | return myConSurf->NbIntervals(S); |
247 | } |
248 | } |
249 | |
250 | //======================================================================= |
251 | //function : Intervals |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | void BRepAdaptor_Curve::Intervals(TColStd_Array1OfReal& T, |
31b1749c |
256 | const GeomAbs_Shape S) const |
7fd59977 |
257 | { |
258 | if (myConSurf.IsNull()) { |
259 | myCurve.Intervals(T, S); |
260 | } |
261 | else { |
262 | myConSurf->Intervals(T, S); |
263 | } |
264 | } |
265 | |
266 | |
267 | //======================================================================= |
268 | //function : Trim |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | Handle(Adaptor3d_HCurve) BRepAdaptor_Curve::Trim(const Standard_Real First, |
273 | const Standard_Real Last, |
274 | const Standard_Real Tol) const |
275 | { |
276 | // On fait une copie de this pour garder la trsf. |
277 | Handle(BRepAdaptor_HCurve) res = new BRepAdaptor_HCurve(); |
278 | if (myConSurf.IsNull()){ |
279 | Standard_Real pf = FirstParameter(), pl = LastParameter(); |
280 | Handle(Geom_Curve) C = myCurve.Curve(); |
281 | ((GeomAdaptor_Curve*) (void*) &myCurve)->Load(C,First,Last); |
282 | res->ChangeCurve() = *this; |
283 | ((GeomAdaptor_Curve*) (void*) &myCurve)->Load(C,pf,pl); |
284 | } |
285 | else { |
286 | Handle(Adaptor3d_HCurveOnSurface) sav = myConSurf; |
857ffd5e |
287 | *((Handle(Adaptor3d_HCurveOnSurface)*) (void*) &myConSurf) = |
7fd59977 |
288 | Handle(Adaptor3d_HCurveOnSurface)::DownCast(myConSurf->Trim(First,Last,Tol)); |
289 | res->ChangeCurve() = *this; |
857ffd5e |
290 | *((Handle(Adaptor3d_HCurveOnSurface)*) (void*) &myConSurf) = sav; |
7fd59977 |
291 | } |
292 | return res; |
293 | } |
294 | |
295 | |
296 | //======================================================================= |
297 | //function : IsClosed |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | Standard_Boolean BRepAdaptor_Curve::IsClosed() const |
302 | { |
303 | if (myConSurf.IsNull()) { |
304 | return myCurve.IsClosed(); |
305 | } |
306 | else { |
307 | return myConSurf->IsClosed(); |
308 | } |
309 | } |
310 | |
311 | //======================================================================= |
312 | //function : IsPeriodic |
313 | //purpose : |
314 | //======================================================================= |
315 | |
316 | Standard_Boolean BRepAdaptor_Curve::IsPeriodic() const |
317 | { |
318 | if (myConSurf.IsNull()) { |
319 | return myCurve.IsPeriodic(); |
320 | } |
321 | else { |
322 | return myConSurf->IsPeriodic(); |
323 | } |
324 | } |
325 | |
326 | //======================================================================= |
327 | //function : Period |
328 | //purpose : |
329 | //======================================================================= |
330 | |
331 | Standard_Real BRepAdaptor_Curve::Period() const |
332 | { |
333 | if (myConSurf.IsNull()) { |
334 | return myCurve.Period(); |
335 | } |
336 | else { |
337 | return myConSurf->Period(); |
338 | } |
339 | } |
340 | |
341 | //======================================================================= |
342 | //function : Value |
343 | //purpose : |
344 | //======================================================================= |
345 | |
346 | gp_Pnt BRepAdaptor_Curve::Value(const Standard_Real U) const |
347 | { |
348 | gp_Pnt P; |
349 | if (myConSurf.IsNull()) |
350 | P = myCurve.Value(U); |
351 | else |
352 | P = myConSurf->Value(U); |
353 | P.Transform(myTrsf); |
354 | return P; |
355 | } |
356 | |
357 | //======================================================================= |
358 | //function : D0 |
359 | //purpose : |
360 | //======================================================================= |
361 | |
362 | void BRepAdaptor_Curve::D0(const Standard_Real U, gp_Pnt& P) const |
363 | { |
364 | if (myConSurf.IsNull()) |
365 | myCurve.D0(U,P); |
366 | else |
367 | myConSurf->D0(U,P); |
368 | P.Transform(myTrsf); |
369 | } |
370 | |
371 | //======================================================================= |
372 | //function : D1 |
373 | //purpose : |
374 | //======================================================================= |
375 | |
376 | void BRepAdaptor_Curve::D1(const Standard_Real U, |
377 | gp_Pnt& P, gp_Vec& V) const |
378 | { |
379 | if (myConSurf.IsNull()) |
380 | myCurve.D1(U,P,V); |
381 | else |
382 | myConSurf->D1(U,P,V); |
383 | P.Transform(myTrsf); |
384 | V.Transform(myTrsf); |
385 | } |
386 | |
387 | //======================================================================= |
388 | //function : D2 |
389 | //purpose : |
390 | //======================================================================= |
391 | |
392 | void BRepAdaptor_Curve::D2(const Standard_Real U, |
393 | gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const |
394 | { |
395 | if (myConSurf.IsNull()) |
396 | myCurve.D2(U,P,V1,V2); |
397 | else |
398 | myConSurf->D2(U,P,V1,V2); |
399 | P.Transform(myTrsf); |
400 | V1.Transform(myTrsf); |
401 | V2.Transform(myTrsf); |
402 | } |
403 | |
404 | //======================================================================= |
405 | //function : D3 |
406 | //purpose : |
407 | //======================================================================= |
408 | |
409 | void BRepAdaptor_Curve::D3(const Standard_Real U, |
410 | gp_Pnt& P, |
411 | gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const |
412 | { |
413 | if (myConSurf.IsNull()) |
414 | myCurve.D3(U,P,V1,V2,V3); |
415 | else |
416 | myConSurf->D3(U,P,V1,V2,V3); |
417 | P.Transform(myTrsf); |
418 | V1.Transform(myTrsf); |
419 | V2.Transform(myTrsf); |
420 | V3.Transform(myTrsf); |
421 | } |
422 | |
423 | //======================================================================= |
424 | //function : DN |
425 | //purpose : |
426 | //======================================================================= |
427 | |
428 | gp_Vec BRepAdaptor_Curve::DN(const Standard_Real U, |
429 | const Standard_Integer N) const |
430 | { |
431 | gp_Vec V; |
432 | if (myConSurf.IsNull()) |
433 | V = myCurve.DN(U,N); |
434 | else |
435 | V = myConSurf->DN(U,N); |
436 | V.Transform(myTrsf); |
437 | return V; |
438 | } |
439 | |
440 | //======================================================================= |
441 | //function : Resolution |
442 | //purpose : |
443 | //======================================================================= |
444 | |
445 | Standard_Real BRepAdaptor_Curve::Resolution(const Standard_Real R) const |
446 | { |
447 | if (myConSurf.IsNull()) { |
448 | return myCurve.Resolution(R); |
449 | } |
450 | else { |
451 | return myConSurf->Resolution(R); |
452 | } |
453 | } |
454 | |
455 | //======================================================================= |
456 | //function : GetTYpe |
457 | //purpose : |
458 | //======================================================================= |
459 | |
460 | GeomAbs_CurveType BRepAdaptor_Curve::GetType() const |
461 | { |
462 | if (myConSurf.IsNull()) { |
463 | return myCurve.GetType(); |
464 | } |
465 | else { |
466 | return myConSurf->GetType(); |
467 | } |
468 | } |
469 | |
470 | //======================================================================= |
471 | //function : Line |
472 | //purpose : |
473 | //======================================================================= |
474 | |
475 | gp_Lin BRepAdaptor_Curve::Line() const |
476 | { |
477 | gp_Lin L; |
478 | if (myConSurf.IsNull()) |
479 | L = myCurve.Line(); |
480 | else |
481 | L = myConSurf->Line(); |
482 | L.Transform(myTrsf); |
483 | return L; |
484 | } |
485 | |
486 | //======================================================================= |
487 | //function : Circle |
488 | //purpose : |
489 | //======================================================================= |
490 | |
491 | gp_Circ BRepAdaptor_Curve::Circle() const |
492 | { |
493 | gp_Circ C; |
494 | if (myConSurf.IsNull()) |
495 | C = myCurve.Circle(); |
496 | else |
497 | C = myConSurf->Circle(); |
498 | C.Transform(myTrsf); |
499 | return C; |
500 | } |
501 | |
502 | //======================================================================= |
503 | //function : Ellipse |
504 | //purpose : |
505 | //======================================================================= |
506 | |
507 | gp_Elips BRepAdaptor_Curve::Ellipse() const |
508 | { |
509 | gp_Elips E; |
510 | if (myConSurf.IsNull()) |
511 | E = myCurve.Ellipse(); |
512 | else |
513 | E = myConSurf->Ellipse(); |
514 | E.Transform(myTrsf); |
515 | return E; |
516 | } |
517 | |
518 | //======================================================================= |
519 | //function : Hyperbola |
520 | //purpose : |
521 | //======================================================================= |
522 | |
523 | gp_Hypr BRepAdaptor_Curve::Hyperbola() const |
524 | { |
525 | gp_Hypr H; |
526 | if (myConSurf.IsNull()) |
527 | H = myCurve.Hyperbola(); |
528 | else |
529 | H = myConSurf->Hyperbola(); |
530 | H.Transform(myTrsf); |
531 | return H; |
532 | } |
533 | |
534 | //======================================================================= |
535 | //function : Parabola |
536 | //purpose : |
537 | //======================================================================= |
538 | |
539 | gp_Parab BRepAdaptor_Curve::Parabola() const |
540 | { |
541 | gp_Parab P; |
542 | if (myConSurf.IsNull()) |
543 | P = myCurve.Parabola(); |
544 | else |
545 | P = myConSurf->Parabola(); |
546 | P.Transform(myTrsf); |
547 | return P; |
548 | } |
549 | |
550 | //======================================================================= |
551 | //function : Degree |
552 | //purpose : |
553 | //======================================================================= |
554 | |
555 | Standard_Integer BRepAdaptor_Curve::Degree() const |
556 | { |
557 | if (myConSurf.IsNull()) |
558 | return myCurve.Degree(); |
559 | else |
560 | return myConSurf->Degree(); |
561 | } |
562 | |
563 | //======================================================================= |
564 | //function : IsRational |
565 | //purpose : |
566 | //======================================================================= |
567 | |
568 | Standard_Boolean BRepAdaptor_Curve::IsRational() const |
569 | { |
570 | if (myConSurf.IsNull()) |
571 | return myCurve.IsRational(); |
572 | else |
573 | return myConSurf->IsRational(); |
574 | } |
575 | //======================================================================= |
576 | //function : NbPoles |
577 | //purpose : |
578 | //======================================================================= |
579 | |
580 | Standard_Integer BRepAdaptor_Curve::NbPoles() const |
581 | { |
582 | if (myConSurf.IsNull()) |
583 | return myCurve.NbPoles(); |
584 | else |
585 | return myConSurf->NbPoles(); |
586 | } |
587 | //======================================================================= |
588 | //function : NbKnots |
589 | //purpose : |
590 | //======================================================================= |
591 | |
592 | Standard_Integer BRepAdaptor_Curve::NbKnots() const |
593 | { |
594 | if (myConSurf.IsNull()) |
595 | return myCurve.NbKnots(); |
596 | else |
597 | return myConSurf->NbKnots(); |
598 | } |
599 | |
600 | //======================================================================= |
601 | //function : Bezier |
602 | //purpose : |
603 | //======================================================================= |
604 | |
605 | Handle(Geom_BezierCurve) BRepAdaptor_Curve::Bezier() const |
606 | { |
607 | Handle(Geom_BezierCurve) BC; |
608 | if (myConSurf.IsNull()) { |
609 | BC = myCurve.Bezier(); |
610 | } |
611 | else { |
612 | BC = myConSurf->Bezier(); |
613 | } |
614 | return Handle(Geom_BezierCurve)::DownCast(BC->Transformed(myTrsf)); |
615 | } |
616 | |
617 | |
618 | //======================================================================= |
619 | //function : BSpline |
620 | //purpose : |
621 | //======================================================================= |
622 | |
623 | Handle(Geom_BSplineCurve) BRepAdaptor_Curve::BSpline() const |
624 | { |
625 | Handle(Geom_BSplineCurve) BS; |
626 | if (myConSurf.IsNull()) { |
627 | BS = myCurve.BSpline(); |
628 | } |
629 | else { |
630 | BS = myConSurf->BSpline(); |
631 | } |
632 | return Handle(Geom_BSplineCurve)::DownCast(BS->Transformed(myTrsf)); |
633 | } |