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