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 | |
7fd59977 |
16 | #include <Adaptor3d_IsoCurve.hxx> |
42cf5bc1 |
17 | #include <Draw_Color.hxx> |
18 | #include <Draw_Display.hxx> |
19 | #include <Draw_Drawable3D.hxx> |
20 | #include <DrawTrSurf_Surface.hxx> |
ec357c5c |
21 | #include <Geom_Surface.hxx> |
42cf5bc1 |
22 | #include <GeomAdaptor_HSurface.hxx> |
23 | #include <GeomTools_SurfaceSet.hxx> |
24 | #include <Precision.hxx> |
25 | #include <Standard_Type.hxx> |
7fd59977 |
26 | |
27 | Standard_Real DrawTrSurf_SurfaceLimit = 400; |
28 | |
29 | |
30 | //======================================================================= |
31 | //function : DrawTrSurf_Surface |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | DrawTrSurf_Surface::DrawTrSurf_Surface (const Handle(Geom_Surface)& S) |
36 | : DrawTrSurf_Drawable (16, 0.01, 1) |
37 | { |
38 | surf = S; |
39 | boundsLook = Draw_jaune; |
40 | isosLook = Draw_bleu; |
41 | nbUIsos = 1; |
42 | nbVIsos = 1; |
43 | } |
44 | |
45 | |
46 | |
47 | |
48 | //======================================================================= |
49 | //function : DrawTrSurf_Surface |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | DrawTrSurf_Surface::DrawTrSurf_Surface |
54 | (const Handle(Geom_Surface)& S, const Standard_Integer Nu, |
55 | const Standard_Integer Nv, |
56 | const Draw_Color& BoundsColor, const Draw_Color& IsosColor, |
57 | const Standard_Integer Discret, const Standard_Real Deflection, |
58 | const Standard_Integer DrawMode) |
59 | : DrawTrSurf_Drawable (Discret, Deflection, DrawMode) |
60 | { |
61 | surf = S; |
62 | boundsLook = BoundsColor; |
63 | isosLook = IsosColor; |
64 | nbUIsos = Abs(Nu); |
65 | nbVIsos = Abs(Nv); |
66 | } |
67 | |
68 | |
69 | |
70 | //======================================================================= |
71 | //function : DrawOn |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | void DrawTrSurf_Surface::DrawOn (Draw_Display& dis) const |
76 | { |
77 | DrawOn(dis,Standard_True); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : DrawOn |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void DrawTrSurf_Surface::DrawOn (Draw_Display& dis, |
86 | const Standard_Boolean Iso) const |
87 | { |
88 | Standard_Real UFirst, ULast, VFirst, VLast; |
89 | surf->Bounds (UFirst, ULast, VFirst, VLast); |
90 | |
91 | Standard_Boolean UfirstInf = Precision::IsNegativeInfinite(UFirst); |
92 | Standard_Boolean UlastInf = Precision::IsPositiveInfinite(ULast); |
93 | Standard_Boolean VfirstInf = Precision::IsNegativeInfinite(VFirst); |
94 | Standard_Boolean VlastInf = Precision::IsPositiveInfinite(VLast); |
95 | |
96 | if (UfirstInf || UlastInf) { |
97 | gp_Pnt P1,P2; |
98 | Standard_Real v; |
99 | if (VfirstInf && VlastInf) |
100 | v = 0; |
101 | else if (VfirstInf) |
102 | v = VLast; |
103 | else if (VlastInf) |
104 | v = VFirst; |
105 | else |
106 | v = (VFirst + VLast) / 2; |
107 | |
108 | Standard_Real delta = 1.; |
109 | |
110 | if (UfirstInf && UlastInf) { |
111 | do { |
112 | delta *= 2; |
113 | UFirst = - delta; |
114 | ULast = delta; |
115 | surf->D0(UFirst,v,P1); |
116 | surf->D0(ULast,v,P2); |
117 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
118 | } |
119 | else if (UfirstInf) { |
120 | surf->D0(ULast,v,P2); |
121 | do { |
122 | delta *= 2; |
123 | UFirst = ULast - delta; |
124 | surf->D0(UFirst,v,P1); |
125 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
126 | } |
127 | else if (UlastInf) { |
128 | surf->D0(UFirst,v,P1); |
129 | do { |
130 | delta *= 2; |
131 | ULast = UFirst + delta; |
132 | surf->D0(ULast,v,P2); |
133 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
134 | } |
135 | } |
136 | |
137 | if (VfirstInf || VlastInf) { |
138 | gp_Pnt P1,P2; |
139 | Standard_Real u = (UFirst + ULast) /2 ; |
140 | |
141 | Standard_Real delta = 1.; |
142 | |
143 | if (VfirstInf && VlastInf) { |
144 | do { |
145 | delta *= 2; |
146 | VFirst = - delta; |
147 | VLast = delta; |
148 | surf->D0(u,VFirst,P1); |
149 | surf->D0(u,VLast,P2); |
150 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
151 | } |
152 | else if (VfirstInf) { |
153 | surf->D0(u,VLast,P2); |
154 | do { |
155 | delta *= 2; |
156 | VFirst = VLast - delta; |
157 | surf->D0(u,VFirst,P1); |
158 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
159 | } |
160 | else if (VlastInf) { |
161 | surf->D0(u,VFirst,P1); |
162 | do { |
163 | delta *= 2; |
164 | VLast = VFirst + delta; |
165 | surf->D0(u,VLast,P2); |
166 | } while (P1.Distance(P2) < DrawTrSurf_SurfaceLimit); |
167 | } |
168 | } |
169 | |
170 | |
171 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); |
172 | HS->ChangeSurface().Load(surf,UFirst,ULast,VFirst,VLast); |
173 | |
174 | Adaptor3d_IsoCurve C(HS); |
175 | |
176 | if (Iso) { |
177 | dis.SetColor(isosLook); |
178 | Standard_Integer i, j; |
179 | |
180 | Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1); |
181 | Standard_Real U = UFirst; |
182 | for (i = 1; i <= nbUIsos; i++) { |
183 | U += Du; |
184 | DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast,dis); |
185 | } |
186 | |
187 | Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1); |
188 | Standard_Real V = VFirst; |
189 | for (j = 1; j <= nbVIsos; j++) { |
190 | V += Dv; |
191 | DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast,dis); |
192 | } |
193 | } |
194 | |
195 | // draw bounds |
196 | dis.SetColor(boundsLook); |
197 | if (!UfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast,dis); |
198 | if (!UlastInf) DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast,dis); |
199 | if (!VfirstInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast,dis); |
200 | if (!VlastInf) DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast,dis); |
201 | |
202 | // draw marker |
203 | DrawIsoCurveOn(C,GeomAbs_IsoU, |
204 | UFirst+(ULast-UFirst)/10., |
205 | VFirst, VFirst + (VLast-VFirst)/10., |
206 | dis); |
207 | } |
208 | |
209 | |
210 | |
211 | //======================================================================= |
212 | //function : ShowIsos |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | void DrawTrSurf_Surface::ShowIsos ( const Standard_Integer Nu, |
217 | const Standard_Integer Nv) |
218 | { |
219 | nbUIsos = Abs(Nu); |
220 | nbVIsos = Abs(Nv); |
221 | } |
222 | |
223 | |
224 | //======================================================================= |
225 | //function : ClearIsos |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | void DrawTrSurf_Surface::ClearIsos () |
230 | { |
231 | nbUIsos = 0; |
232 | nbVIsos = 0; |
233 | } |
234 | |
235 | |
236 | //======================================================================= |
237 | //function : Copy |
238 | //purpose : |
239 | //======================================================================= |
240 | |
241 | Handle(Draw_Drawable3D) DrawTrSurf_Surface::Copy() const |
242 | { |
243 | Handle(DrawTrSurf_Surface) DS = new DrawTrSurf_Surface |
244 | (Handle(Geom_Surface)::DownCast(surf->Copy()), |
245 | nbUIsos,nbVIsos,boundsLook,isosLook, |
246 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
247 | |
248 | return DS; |
249 | } |
250 | |
251 | |
252 | //======================================================================= |
253 | //function : Dump |
254 | //purpose : |
255 | //======================================================================= |
256 | |
257 | void DrawTrSurf_Surface::Dump(Standard_OStream& S)const |
258 | { |
259 | GeomTools_SurfaceSet::PrintSurface(surf,S); |
260 | } |
261 | |
262 | |
263 | //======================================================================= |
264 | //function : Whatis |
265 | //purpose : |
266 | //======================================================================= |
267 | |
268 | void DrawTrSurf_Surface::Whatis(Draw_Interpretor& S)const |
269 | { |
270 | S << "a surface"; |
271 | } |