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