0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / DrawTrSurf / DrawTrSurf_Curve.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
42cf5bc1 15
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>
7fd59977 21#include <GeomAdaptor_Curve.hxx>
7fd59977 22#include <GeomLProp_CLProps.hxx>
42cf5bc1 23#include <GeomTools_CurveSet.hxx>
7fd59977 24#include <gp.hxx>
7fd59977 25#include <gp_Dir2d.hxx>
42cf5bc1 26#include <gp_Pnt2d.hxx>
7fd59977 27#include <gp_Vec.hxx>
28#include <gp_Vec2d.hxx>
42cf5bc1 29#include <Precision.hxx>
30#include <Standard_Type.hxx>
7fd59977 31#include <TColStd_Array1OfReal.hxx>
32
33Standard_Real DrawTrSurf_CurveLimit = 400;
34extern Standard_Boolean Draw_Bounds;
35
36
37//=======================================================================
38//function : DrawTrSurf_Curve
39//purpose :
40//=======================================================================
41
42DrawTrSurf_Curve::DrawTrSurf_Curve (const Handle(Geom_Curve)& C,
43 const Standard_Boolean DispOrigin) :
44 DrawTrSurf_Drawable (16, 0.01, 1),
45 curv(C),
46 look(Draw_vert),
47 disporigin(DispOrigin),
48 dispcurvradius(Standard_False),
49 radiusmax(1.0e3),
50 radiusratio(0.1)
51{
52}
53
54
55
56//=======================================================================
57//function : DrawTrSurf_Curve
58//purpose :
59//=======================================================================
60
61DrawTrSurf_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),
71 curv(C),
72 look(aColor),
73 disporigin(DispOrigin),
74 dispcurvradius(DispCurvRadius),
75 radiusmax(RadiusMax),
76 radiusratio(RadiusRatio)
77{
78}
79
80
81//=======================================================================
82//function : DrawOn
83//purpose :
84//=======================================================================
85
86void DrawTrSurf_Curve::DrawOn (Draw_Display& dis) const
87{
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);
92
93 if (firstInf || lastInf) {
94 gp_Pnt P1,P2;
95 Standard_Real delta = 1;
96 if (firstInf && lastInf) {
97 do {
98 delta *= 2;
99 First = - delta;
100 Last = delta;
101 curv->D0(First,P1);
102 curv->D0(Last,P2);
103 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
104 }
105 else if (firstInf) {
106 curv->D0(Last,P2);
107 do {
108 delta *= 2;
109 First = Last - delta;
110 curv->D0(First,P1);
111 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
112 }
113 else if (lastInf) {
114 curv->D0(First,P1);
115 do {
116 delta *= 2;
117 Last = First + delta;
118 curv->D0(Last,P2);
119 } while (P1.Distance(P2) < DrawTrSurf_CurveLimit);
120 }
121 }
122
123 dis.SetColor (look);
124 GeomAdaptor_Curve C(curv,First,Last);
125 DrawCurveOn(C,dis);
126
127 // mark the orientation
128 if (disporigin) {
129 Draw_Bounds = Standard_False;
130 gp_Pnt P;
131 gp_Vec V;
132 C.D1(Last,P,V);
133 gp_Pnt2d p1,p2;
134 dis.Project(P,p1);
135 P.Translate(V);
136 dis.Project(P,p2);
137 gp_Vec2d v(p1,p2);
138 if (v.Magnitude() > gp::Resolution()) {
139 Standard_Real L = 20 / dis.Zoom();
140 Standard_Real H = 10 / dis.Zoom();
141 gp_Dir2d d(v);
142 p2.SetCoord(p1.X() - L*d.X() - H*d.Y(), p1.Y() - L*d.Y() + H*d.X());
143 dis.MoveTo(p2);
144 p2.SetCoord(p1.X() - L*d.X() + H*d.Y(), p1.Y() - L*d.Y() - H*d.X());
145 dis.DrawTo(p1);
146 dis.DrawTo(p2);
147 }
148 Draw_Bounds = Standard_True;
149 }
150// Draw the curvature Radius
151 if (dispcurvradius && (C.GetType() != GeomAbs_Line)) {
152 Standard_Integer ii;
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);
158 gp_Pnt P1, P2;
159
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) {
169 curv->D0(t, P1);
170 dis.MoveTo(P1);
171 LRad = 1./Curvature;
172 ratio = ( ( LRad > radiusmax) ? radiusmax/LRad : 1 );
173 ratio *= radiusratio;
174 LProp.CentreOfCurvature(P2);
175 gp_Vec V(P1, P2);
176 dis.DrawTo(P1.Translated(ratio*V));
177 }
178 }
179 t += step;
180 }
181 }
182 }
183}
184
185
186//=======================================================================
187//function : Copy
188//purpose :
189//=======================================================================
190
191Handle(Draw_Drawable3D) DrawTrSurf_Curve::Copy()const
192{
193 Handle(DrawTrSurf_Curve) DC = new DrawTrSurf_Curve
194 (Handle(Geom_Curve)::DownCast(curv->Copy()),
195 look,
196 GetDiscretisation(),GetDeflection(),GetDrawMode());
197
198 return DC;
199}
200
201
202//=======================================================================
203//function : Dump
204//purpose :
205//=======================================================================
206
207void DrawTrSurf_Curve::Dump(Standard_OStream& S)const
208{
209 GeomTools_CurveSet::PrintCurve(curv,S);
210}
211
212
213//=======================================================================
214//function : Whatis
215//purpose :
216//=======================================================================
217
218void DrawTrSurf_Curve::Whatis(Draw_Interpretor& S)const
219{
220 S << " a 3d curve";
221}