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