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