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