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