1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Draw_Color.hxx>
17 #include <Draw_Display.hxx>
18 #include <Draw_Drawable3D.hxx>
19 #include <DrawTrSurf_Curve.hxx>
20 #include <Geom_Curve.hxx>
21 #include <GeomAdaptor_Curve.hxx>
22 #include <GeomLProp_CLProps.hxx>
23 #include <GeomTools_CurveSet.hxx>
25 #include <gp_Dir2d.hxx>
26 #include <gp_Pnt2d.hxx>
28 #include <gp_Vec2d.hxx>
29 #include <Precision.hxx>
30 #include <Standard_Type.hxx>
31 #include <TColStd_Array1OfReal.hxx>
33 Standard_Real DrawTrSurf_CurveLimit = 400;
34 extern Standard_Boolean Draw_Bounds;
37 //=======================================================================
38 //function : DrawTrSurf_Curve
40 //=======================================================================
42 DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
43 const Standard_Boolean DispOrigin) :
44 DrawTrSurf_Drawable (16, 0.01, 1),
47 disporigin(DispOrigin),
48 dispcurvradius(Standard_False),
56 //=======================================================================
57 //function : DrawTrSurf_Curve
59 //=======================================================================
61 DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
62 const Draw_Color& aColor,
63 const Standard_Integer Discret,
64 const Standard_Real Deflection,
65 const Standard_Integer DrawMode,
66 const Standard_Boolean DispOrigin,
67 const Standard_Boolean DispCurvRadius,
68 const Standard_Real RadiusMax,
69 const Standard_Real RadiusRatio) :
70 DrawTrSurf_Drawable (Discret,Deflection, DrawMode),
73 disporigin(DispOrigin),
74 dispcurvradius(DispCurvRadius),
76 radiusratio(RadiusRatio)
81 //=======================================================================
84 //=======================================================================
86 void DrawTrSurf_Curve::DrawOn (Draw_Display& dis) const
88 Standard_Real First = curv->FirstParameter();
89 Standard_Real Last = curv->LastParameter();
90 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
91 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
93 if (firstInf || lastInf) {
95 Standard_Real delta = 1;
96 if (firstInf && lastInf) {
103 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
109 First = Last - delta;
111 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
117 Last = First + delta;
119 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
124 GeomAdaptor_Curve C(curv,First,Last);
127 // mark the orientation
129 Draw_Bounds = Standard_False;
138 if (v.Magnitude() > gp::Resolution()) {
139 Standard_Real L = 20 / dis.Zoom();
140 Standard_Real H = 10 / dis.Zoom();
142 p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
144 p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
148 Draw_Bounds = Standard_True;
150 // Draw the curvature Radius
151 if (dispcurvradius && (C.GetType() != GeomAbs_Line)) {
153 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
154 TColStd_Array1OfReal TI(1,nbintv+1);
155 C.Intervals(TI,GeomAbs_CN);
156 Standard_Real Resolution = 1.0e-9, Curvature;
157 GeomLProp_CLProps LProp(curv, 2, Resolution);
160 for (intrv = 1; intrv <= nbintv; intrv++) {
161 Standard_Real t = TI(intrv);
162 Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
163 Standard_Real LRad, ratio;
164 for (ii = 1; ii <= GetDiscretisation(); ii++) {
165 LProp.SetParameter(t);
166 if (LProp.IsTangentDefined()) {
167 Curvature = Abs(LProp.Curvature());
168 if ( Curvature > Resolution) {
172 ratio = ( ( LRad > radiusmax) ? radiusmax/LRad : 1 );
173 ratio *= radiusratio;
174 LProp.CentreOfCurvature(P2);
176 dis.DrawTo(P1.Translated(ratio*V));
186 //=======================================================================
189 //=======================================================================
191 Handle(Draw_Drawable3D) DrawTrSurf_Curve::Copy()const
193 Handle(DrawTrSurf_Curve) DC = new DrawTrSurf_Curve
194 (Handle(Geom_Curve)::DownCast(curv->Copy()),
196 GetDiscretisation(),GetDeflection(),GetDrawMode());
202 //=======================================================================
205 //=======================================================================
207 void DrawTrSurf_Curve::Dump(Standard_OStream& S)const
209 GeomTools_CurveSet::PrintCurve(curv,S);
213 //=======================================================================
216 //=======================================================================
218 void DrawTrSurf_Curve::Whatis(Draw_Interpretor& S)const