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