1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <DrawTrSurf_Curve2d.ixx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom2d_OffsetCurve.hxx>
22 #include <Geom2d_Line.hxx>
23 #include <Geom2d_Parabola.hxx>
24 #include <Geom2d_Hyperbola.hxx>
25 #include <Geom2dAdaptor_Curve.hxx>
26 #include <Geom_Plane.hxx>
27 #include <GeomTools_Curve2dSet.hxx>
28 #include <Geom2dLProp_CLProps2d.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <Precision.hxx>
33 static Standard_Real DrawTrSurf_CurveLimit = 400;
34 extern Standard_Boolean Draw_Bounds;
36 //=======================================================================
37 //function : DrawTrSurf_Curve2d
39 //=======================================================================
41 DrawTrSurf_Curve2d::DrawTrSurf_Curve2d (const Handle(Geom2d_Curve)& C,
42 const Standard_Boolean DispOrigin) :
43 DrawTrSurf_Drawable (50)
47 disporigin = DispOrigin ;
48 dispcurvradius = Standard_False;
54 //=======================================================================
55 //function : DrawTrSurf_Curve2d
57 //=======================================================================
59 DrawTrSurf_Curve2d::DrawTrSurf_Curve2d (const Handle(Geom2d_Curve)& C,
60 const Draw_Color& aColor,
61 const Standard_Integer Discret,
62 const Standard_Boolean DispOrigin,
63 const Standard_Boolean DispCurvRadius,
64 const Standard_Real RadiusMax,
65 const Standard_Real RadiusRatio) :
66 DrawTrSurf_Drawable (Discret)
70 disporigin = DispOrigin ;
71 dispcurvradius = DispCurvRadius;
72 radiusmax = RadiusMax;
73 radiusratio = RadiusRatio;
77 //=======================================================================
80 //=======================================================================
82 void DrawTrSurf_Curve2d::DrawOn (Draw_Display& dis) const
85 Standard_Real First = curv->FirstParameter();
86 Standard_Real Last = curv->LastParameter();
87 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
88 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
90 if (firstInf || lastInf) {
92 Standard_Real delta = 1;
93 if (firstInf && lastInf) {
100 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
106 First = Last - delta;
108 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
114 Last = First + delta;
116 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
122 Geom2dAdaptor_Curve C2d(curv,First,Last);
123 DrawCurve2dOn (C2d, dis);
127 Draw_Bounds = Standard_False;
131 if (v.Magnitude() > gp::Resolution()) {
132 Standard_Real L = 20 / dis.Zoom();
133 Standard_Real H = 10 / dis.Zoom();
135 p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
137 p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
141 Draw_Bounds = Standard_True;
144 // Draw the curvature Radius
145 if (dispcurvradius && (C2d.GetType() != GeomAbs_Line)) {
147 Standard_Integer intrv, nbintv = C2d.NbIntervals(GeomAbs_CN);
148 TColStd_Array1OfReal TI(1,nbintv+1);
149 C2d.Intervals(TI,GeomAbs_CN);
150 Standard_Real Resolution = 1.0e-9, Curvature;
151 Geom2dLProp_CLProps2d LProp(curv, 2, Resolution);
154 for (intrv = 1; intrv <= nbintv; intrv++) {
155 Standard_Real t = TI(intrv);
156 Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
157 Standard_Real LRad, ratio;
158 for (ii = 1; ii <= GetDiscretisation(); ii++) {
159 LProp.SetParameter(t);
160 if (LProp.IsTangentDefined()) {
161 Curvature = Abs(LProp.Curvature());
162 if ( Curvature > Resolution) {
166 ratio = ( ( LRad > radiusmax) ? radiusmax/LRad : 1 );
167 ratio *= radiusratio;
168 LProp.CentreOfCurvature(P2);
170 dis.DrawTo(P1.Translated(ratio*V));
181 //=======================================================================
184 //=======================================================================
185 Handle(Draw_Drawable3D) DrawTrSurf_Curve2d::Copy()const
187 Handle(DrawTrSurf_Curve2d) DC = new DrawTrSurf_Curve2d
188 (Handle(Geom2d_Curve)::DownCast(curv->Copy()),
190 GetDiscretisation());
196 //=======================================================================
199 //=======================================================================
201 void DrawTrSurf_Curve2d::Dump(Standard_OStream& S) const
203 GeomTools_Curve2dSet::PrintCurve2d(curv,S);
207 //=======================================================================
210 //=======================================================================
212 void DrawTrSurf_Curve2d::Whatis(Draw_Interpretor& S)const
218 //=======================================================================
221 //=======================================================================
223 Standard_Boolean DrawTrSurf_Curve2d::Is3D() const
225 return Standard_False;