1 // Created on: 1993-02-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepAdaptor_Curve.ixx>
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>
26 //=======================================================================
27 //function : BRepAdaptor_Curve
29 //=======================================================================
31 BRepAdaptor_Curve::BRepAdaptor_Curve()
34 //=======================================================================
35 //function : BRepAdaptor_Curve
37 //=======================================================================
39 BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E)
44 //=======================================================================
45 //function : BRepAdaptor_Curve
47 //=======================================================================
49 BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E,
55 //=======================================================================
56 //function : Initialize
58 //=======================================================================
60 void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E)
67 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,pf,pl);
70 myCurve.Load(C,pf,pl);
73 Handle(Geom2d_Curve) PC;
74 Handle(Geom_Surface) S;
75 BRep_Tool::CurveOnSurface(E,PC,S,L,pf,pl);
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);
86 Standard_NullObject::Raise("BRepAdaptor_Curve::No geometry");
89 myTrsf = L.Transformation();
92 //=======================================================================
93 //function : Initialize
95 //=======================================================================
97 void BRepAdaptor_Curve::Initialize(const TopoDS_Edge& E,
105 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
106 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,F,pf,pl);
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);
116 myTrsf = L.Transformation();
119 //=======================================================================
122 //=======================================================================
124 const gp_Trsf& BRepAdaptor_Curve::Trsf() const
129 //=======================================================================
130 //function : Is3DCurve
132 //=======================================================================
134 Standard_Boolean BRepAdaptor_Curve::Is3DCurve() const
136 return myConSurf.IsNull();
139 //=======================================================================
140 //function : IsCurveOnSurface
142 //=======================================================================
144 Standard_Boolean BRepAdaptor_Curve::IsCurveOnSurface() const
146 return !myConSurf.IsNull();
149 //=======================================================================
152 //=======================================================================
154 const GeomAdaptor_Curve& BRepAdaptor_Curve::Curve() const
159 //=======================================================================
160 //function : CurveOnSurface
162 //=======================================================================
164 const Adaptor3d_CurveOnSurface& BRepAdaptor_Curve::CurveOnSurface() const
166 return *((Adaptor3d_CurveOnSurface*)&(myConSurf->Curve()));
169 //=======================================================================
172 //=======================================================================
174 const TopoDS_Edge& BRepAdaptor_Curve::Edge() const
179 //=======================================================================
180 //function : Tolerance
182 //=======================================================================
184 Standard_Real BRepAdaptor_Curve::Tolerance() const
186 return BRep_Tool::Tolerance(myEdge);
189 //=======================================================================
190 //function : FirstParameter
192 //=======================================================================
194 Standard_Real BRepAdaptor_Curve::FirstParameter() const
196 if (myConSurf.IsNull()) {
197 return myCurve.FirstParameter();
200 return myConSurf->FirstParameter();
204 //=======================================================================
205 //function : LastParameter
207 //=======================================================================
209 Standard_Real BRepAdaptor_Curve::LastParameter() const
211 if (myConSurf.IsNull()) {
212 return myCurve.LastParameter();
215 return myConSurf->LastParameter();
219 //=======================================================================
220 //function : Continuity
222 //=======================================================================
224 GeomAbs_Shape BRepAdaptor_Curve::Continuity() const
226 if (myConSurf.IsNull()) {
227 return myCurve.Continuity();
230 return myConSurf->Continuity();
234 //=======================================================================
235 //function : NbIntervals
237 //=======================================================================
239 Standard_Integer BRepAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
241 if (myConSurf.IsNull()) {
242 return myCurve.NbIntervals(S);
245 return myConSurf->NbIntervals(S);
249 //=======================================================================
250 //function : Intervals
252 //=======================================================================
254 void BRepAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
255 const GeomAbs_Shape S) const
257 if (myConSurf.IsNull()) {
258 myCurve.Intervals(T, S);
261 myConSurf->Intervals(T, S);
266 //=======================================================================
269 //=======================================================================
271 Handle(Adaptor3d_HCurve) BRepAdaptor_Curve::Trim(const Standard_Real First,
272 const Standard_Real Last,
273 const Standard_Real Tol) const
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);
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;
295 //=======================================================================
296 //function : IsClosed
298 //=======================================================================
300 Standard_Boolean BRepAdaptor_Curve::IsClosed() const
302 if (myConSurf.IsNull()) {
303 return myCurve.IsClosed();
306 return myConSurf->IsClosed();
310 //=======================================================================
311 //function : IsPeriodic
313 //=======================================================================
315 Standard_Boolean BRepAdaptor_Curve::IsPeriodic() const
317 if (myConSurf.IsNull()) {
318 return myCurve.IsPeriodic();
321 return myConSurf->IsPeriodic();
325 //=======================================================================
328 //=======================================================================
330 Standard_Real BRepAdaptor_Curve::Period() const
332 if (myConSurf.IsNull()) {
333 return myCurve.Period();
336 return myConSurf->Period();
340 //=======================================================================
343 //=======================================================================
345 gp_Pnt BRepAdaptor_Curve::Value(const Standard_Real U) const
348 if (myConSurf.IsNull())
349 P = myCurve.Value(U);
351 P = myConSurf->Value(U);
356 //=======================================================================
359 //=======================================================================
361 void BRepAdaptor_Curve::D0(const Standard_Real U, gp_Pnt& P) const
363 if (myConSurf.IsNull())
370 //=======================================================================
373 //=======================================================================
375 void BRepAdaptor_Curve::D1(const Standard_Real U,
376 gp_Pnt& P, gp_Vec& V) const
378 if (myConSurf.IsNull())
381 myConSurf->D1(U,P,V);
386 //=======================================================================
389 //=======================================================================
391 void BRepAdaptor_Curve::D2(const Standard_Real U,
392 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const
394 if (myConSurf.IsNull())
395 myCurve.D2(U,P,V1,V2);
397 myConSurf->D2(U,P,V1,V2);
399 V1.Transform(myTrsf);
400 V2.Transform(myTrsf);
403 //=======================================================================
406 //=======================================================================
408 void BRepAdaptor_Curve::D3(const Standard_Real U,
410 gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const
412 if (myConSurf.IsNull())
413 myCurve.D3(U,P,V1,V2,V3);
415 myConSurf->D3(U,P,V1,V2,V3);
417 V1.Transform(myTrsf);
418 V2.Transform(myTrsf);
419 V3.Transform(myTrsf);
422 //=======================================================================
425 //=======================================================================
427 gp_Vec BRepAdaptor_Curve::DN(const Standard_Real U,
428 const Standard_Integer N) const
431 if (myConSurf.IsNull())
434 V = myConSurf->DN(U,N);
439 //=======================================================================
440 //function : Resolution
442 //=======================================================================
444 Standard_Real BRepAdaptor_Curve::Resolution(const Standard_Real R) const
446 if (myConSurf.IsNull()) {
447 return myCurve.Resolution(R);
450 return myConSurf->Resolution(R);
454 //=======================================================================
457 //=======================================================================
459 GeomAbs_CurveType BRepAdaptor_Curve::GetType() const
461 if (myConSurf.IsNull()) {
462 return myCurve.GetType();
465 return myConSurf->GetType();
469 //=======================================================================
472 //=======================================================================
474 gp_Lin BRepAdaptor_Curve::Line() const
477 if (myConSurf.IsNull())
480 L = myConSurf->Line();
485 //=======================================================================
488 //=======================================================================
490 gp_Circ BRepAdaptor_Curve::Circle() const
493 if (myConSurf.IsNull())
494 C = myCurve.Circle();
496 C = myConSurf->Circle();
501 //=======================================================================
504 //=======================================================================
506 gp_Elips BRepAdaptor_Curve::Ellipse() const
509 if (myConSurf.IsNull())
510 E = myCurve.Ellipse();
512 E = myConSurf->Ellipse();
517 //=======================================================================
518 //function : Hyperbola
520 //=======================================================================
522 gp_Hypr BRepAdaptor_Curve::Hyperbola() const
525 if (myConSurf.IsNull())
526 H = myCurve.Hyperbola();
528 H = myConSurf->Hyperbola();
533 //=======================================================================
534 //function : Parabola
536 //=======================================================================
538 gp_Parab BRepAdaptor_Curve::Parabola() const
541 if (myConSurf.IsNull())
542 P = myCurve.Parabola();
544 P = myConSurf->Parabola();
549 //=======================================================================
552 //=======================================================================
554 Standard_Integer BRepAdaptor_Curve::Degree() const
556 if (myConSurf.IsNull())
557 return myCurve.Degree();
559 return myConSurf->Degree();
562 //=======================================================================
563 //function : IsRational
565 //=======================================================================
567 Standard_Boolean BRepAdaptor_Curve::IsRational() const
569 if (myConSurf.IsNull())
570 return myCurve.IsRational();
572 return myConSurf->IsRational();
574 //=======================================================================
577 //=======================================================================
579 Standard_Integer BRepAdaptor_Curve::NbPoles() const
581 if (myConSurf.IsNull())
582 return myCurve.NbPoles();
584 return myConSurf->NbPoles();
586 //=======================================================================
589 //=======================================================================
591 Standard_Integer BRepAdaptor_Curve::NbKnots() const
593 if (myConSurf.IsNull())
594 return myCurve.NbKnots();
596 return myConSurf->NbKnots();
599 //=======================================================================
602 //=======================================================================
604 Handle(Geom_BezierCurve) BRepAdaptor_Curve::Bezier() const
606 Handle(Geom_BezierCurve) BC;
607 if (myConSurf.IsNull()) {
608 BC = myCurve.Bezier();
611 BC = myConSurf->Bezier();
613 return Handle(Geom_BezierCurve)::DownCast(BC->Transformed(myTrsf));
617 //=======================================================================
620 //=======================================================================
622 Handle(Geom_BSplineCurve) BRepAdaptor_Curve::BSpline() const
624 Handle(Geom_BSplineCurve) BS;
625 if (myConSurf.IsNull()) {
626 BS = myCurve.BSpline();
629 BS = myConSurf->BSpline();
631 return Handle(Geom_BSplineCurve)::DownCast(BS->Transformed(myTrsf));