0024096: Eliminate compiler warning C4505 in MSVC++ with warning level 4
[occt.git] / src / DrawTrSurf / DrawTrSurf_Curve.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
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.
8//
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.
11//
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.
18
7fd59977 19#include <DrawTrSurf_Curve.ixx>
20#include <GeomAdaptor_Curve.hxx>
21#include <GeomTools_CurveSet.hxx>
22#include <GeomLProp_CLProps.hxx>
23#include <Precision.hxx>
24#include <gp.hxx>
25#include <gp_Pnt2d.hxx>
26#include <gp_Dir2d.hxx>
27#include <gp_Vec.hxx>
28#include <gp_Vec2d.hxx>
29#include <TColStd_Array1OfReal.hxx>
30
31Standard_Real DrawTrSurf_CurveLimit = 400;
32extern Standard_Boolean Draw_Bounds;
33
34
35//=======================================================================
36//function : DrawTrSurf_Curve
37//purpose :
38//=======================================================================
39
40DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
41 const Standard_Boolean DispOrigin) :
42 DrawTrSurf_Drawable (16, 0.01, 1),
43 curv(C),
44 look(Draw_vert),
45 disporigin(DispOrigin),
46 dispcurvradius(Standard_False),
47 radiusmax(1.0e3),
48 radiusratio(0.1)
49{
50}
51
52
53
54//=======================================================================
55//function : DrawTrSurf_Curve
56//purpose :
57//=======================================================================
58
59DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
60 const Draw_Color& aColor,
61 const Standard_Integer Discret,
62 const Standard_Real Deflection,
63 const Standard_Integer DrawMode,
64 const Standard_Boolean DispOrigin,
65 const Standard_Boolean DispCurvRadius,
66 const Standard_Real RadiusMax,
67 const Standard_Real RadiusRatio) :
68 DrawTrSurf_Drawable (Discret,Deflection, DrawMode),
69 curv(C),
70 look(aColor),
71 disporigin(DispOrigin),
72 dispcurvradius(DispCurvRadius),
73 radiusmax(RadiusMax),
74 radiusratio(RadiusRatio)
75{
76}
77
78
79//=======================================================================
80//function : DrawOn
81//purpose :
82//=======================================================================
83
84void DrawTrSurf_Curve::DrawOn (Draw_Display& dis) const
85{
86 Standard_Real First = curv->FirstParameter();
87 Standard_Real Last = curv->LastParameter();
88 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
89 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
90
91 if (firstInf || lastInf) {
92 gp_Pnt P1,P2;
93 Standard_Real delta = 1;
94 if (firstInf && lastInf) {
95 do {
96 delta *= 2;
97 First = - delta;
98 Last = delta;
99 curv->D0(First,P1);
100 curv->D0(Last,P2);
101 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
102 }
103 else if (firstInf) {
104 curv->D0(Last,P2);
105 do {
106 delta *= 2;
107 First = Last - delta;
108 curv->D0(First,P1);
109 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
110 }
111 else if (lastInf) {
112 curv->D0(First,P1);
113 do {
114 delta *= 2;
115 Last = First + delta;
116 curv->D0(Last,P2);
117 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
118 }
119 }
120
121 dis.SetColor (look);
122 GeomAdaptor_Curve C(curv,First,Last);
123 DrawCurveOn(C,dis);
124
125 // mark the orientation
126 if (disporigin) {
127 Draw_Bounds = Standard_False;
128 gp_Pnt P;
129 gp_Vec V;
130 C.D1(Last,P,V);
131 gp_Pnt2d p1,p2;
132 dis.Project(P,p1);
133 P.Translate(V);
134 dis.Project(P,p2);
135 gp_Vec2d v(p1,p2);
136 if (v.Magnitude() > gp::Resolution()) {
137 Standard_Real L = 20 / dis.Zoom();
138 Standard_Real H = 10 / dis.Zoom();
139 gp_Dir2d d(v);
140 p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
141 dis.MoveTo(p2);
142 p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
143 dis.DrawTo(p1);
144 dis.DrawTo(p2);
145 }
146 Draw_Bounds = Standard_True;
147 }
148// Draw the curvature Radius
149 if (dispcurvradius && (C.GetType() != GeomAbs_Line)) {
150 Standard_Integer ii;
151 Standard_Integer intrv, nbintv = C.NbIntervals(GeomAbs_CN);
152 TColStd_Array1OfReal TI(1,nbintv+1);
153 C.Intervals(TI,GeomAbs_CN);
154 Standard_Real Resolution = 1.0e-9, Curvature;
155 GeomLProp_CLProps LProp(curv, 2, Resolution);
156 gp_Pnt P1, P2;
157
158 for (intrv = 1; intrv <= nbintv; intrv++) {
159 Standard_Real t = TI(intrv);
160 Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
161 Standard_Real LRad, ratio;
162 for (ii = 1; ii <= GetDiscretisation(); ii++) {
163 LProp.SetParameter(t);
164 if (LProp.IsTangentDefined()) {
165 Curvature = Abs(LProp.Curvature());
166 if ( Curvature > Resolution) {
167 curv->D0(t, P1);
168 dis.MoveTo(P1);
169 LRad = 1./Curvature;
170 ratio = ( ( LRad > radiusmax) ? radiusmax/LRad : 1 );
171 ratio *= radiusratio;
172 LProp.CentreOfCurvature(P2);
173 gp_Vec V(P1, P2);
174 dis.DrawTo(P1.Translated(ratio*V));
175 }
176 }
177 t += step;
178 }
179 }
180 }
181}
182
183
184//=======================================================================
185//function : Copy
186//purpose :
187//=======================================================================
188
189Handle(Draw_Drawable3D) DrawTrSurf_Curve::Copy()const
190{
191 Handle(DrawTrSurf_Curve) DC = new DrawTrSurf_Curve
192 (Handle(Geom_Curve)::DownCast(curv->Copy()),
193 look,
194 GetDiscretisation(),GetDeflection(),GetDrawMode());
195
196 return DC;
197}
198
199
200//=======================================================================
201//function : Dump
202//purpose :
203//=======================================================================
204
205void DrawTrSurf_Curve::Dump(Standard_OStream& S)const
206{
207 GeomTools_CurveSet::PrintCurve(curv,S);
208}
209
210
211//=======================================================================
212//function : Whatis
213//purpose :
214//=======================================================================
215
216void DrawTrSurf_Curve::Whatis(Draw_Interpretor& S)const
217{
218 S << " a 3d curve";
219}