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