7fd59977 |
1 | #include <VrmlConverter_WFRestrictedFace.ixx> |
2 | #include <Hatch_Hatcher.hxx> |
3 | #include <gp_Pnt.hxx> |
4 | #include <VrmlConverter_IsoAspect.hxx> |
5 | #include <Adaptor3d_IsoCurve.hxx> |
6 | #include <Bnd_Box2d.hxx> |
7 | #include <BndLib_Add2dCurve.hxx> |
8 | #include <Precision.hxx> |
9 | #include <StdPrs_ToolRFace.hxx> |
10 | #include <VrmlConverter_Curve.hxx> |
11 | #include <Vrml_Material.hxx> |
12 | #include <Vrml_Separator.hxx> |
13 | |
14 | //========================================================================= |
15 | // function: Add 1 |
16 | // purpose |
17 | //========================================================================= |
18 | void VrmlConverter_WFRestrictedFace::Add |
19 | (Standard_OStream& anOStream, |
20 | const Handle(BRepAdaptor_HSurface)& aFace, |
21 | const Standard_Boolean DrawUIso, |
22 | const Standard_Boolean DrawVIso, |
23 | const Standard_Integer NBUiso, |
24 | const Standard_Integer NBViso, |
25 | const Handle(VrmlConverter_Drawer)& aDrawer) |
26 | { |
27 | Standard_Real aLimit = aDrawer->MaximalParameterValue(); |
28 | Standard_Integer nbPoints = aDrawer->Discretisation(); |
29 | |
30 | StdPrs_ToolRFace ToolRst (aFace); |
31 | |
32 | // compute bounds of the restriction |
33 | Standard_Real UMin,UMax,VMin,VMax; |
34 | Standard_Integer i; |
35 | gp_Pnt2d P1,P2; |
36 | Bnd_Box2d B; |
37 | |
38 | for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { |
39 | Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); |
40 | BndLib_Add2dCurve::Add(*TheRCurve, Precision::PConfusion(), B); |
41 | } |
42 | |
43 | B.Get(UMin, VMin, UMax, VMax); |
44 | |
45 | // load the infinite isos |
46 | Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented()); |
47 | Standard_Boolean UClosed = aFace->IsUClosed(); |
48 | Standard_Boolean VClosed = aFace->IsVClosed(); |
49 | |
50 | if ( ! UClosed ) { |
51 | UMin = UMin + ( UMax - UMin) /1000.; |
52 | UMax = UMax - ( UMax - UMin) /1000.; |
53 | } |
54 | |
55 | if ( ! VClosed ) { |
56 | VMin = VMin + ( VMax - VMin) /1000.; |
57 | VMax = VMax - ( VMax - VMin) /1000.; |
58 | } |
59 | |
60 | if (DrawUIso){ |
61 | if (NBUiso > 0) { |
62 | UClosed = Standard_False; |
63 | Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso); |
64 | for (i=1; i<=NBUiso;i++){ |
65 | isobuild.AddXLine(UMin+du*i); |
66 | } |
67 | } |
68 | } |
69 | if (DrawVIso){ |
70 | if ( NBViso > 0) { |
71 | VClosed = Standard_False; |
72 | Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso); |
73 | for (i=1; i<=NBViso;i++){ |
74 | isobuild.AddYLine(VMin+dv*i); |
75 | } |
76 | } |
77 | } |
78 | |
79 | // trim the isos |
80 | Standard_Real U1, U2, U, DU; |
81 | |
82 | for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) { |
83 | TopAbs_Orientation Orient = ToolRst.Orientation(); |
84 | if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) { |
85 | Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value(); |
86 | U1 = TheRCurve->FirstParameter(); |
87 | U2 = TheRCurve->LastParameter(); |
88 | if (TheRCurve->GetType() != GeomAbs_Line) { |
89 | DU = (U2-U1)/(nbPoints-1); |
90 | P2 = TheRCurve->Value(U1); |
91 | for (i = 2; i <= nbPoints; i++) { |
92 | U = U1 + (i-1)*DU; |
93 | P1 = P2; |
94 | P2 = TheRCurve->Value(U); |
95 | if(Orient == TopAbs_FORWARD ) |
96 | isobuild.Trim(P1,P2); |
97 | else |
98 | isobuild.Trim(P2,P1); |
99 | } |
100 | } |
101 | else { |
102 | P1 = TheRCurve->Value(U1); |
103 | P2 = TheRCurve->Value(U2); |
104 | if(Orient == TopAbs_FORWARD ) |
105 | isobuild.Trim(P1,P2); |
106 | else |
107 | isobuild.Trim(P2,P1); |
108 | } |
109 | } |
110 | } |
111 | |
112 | |
113 | // draw the isos |
114 | |
115 | |
116 | Adaptor3d_IsoCurve anIso; |
117 | anIso.Load(aFace); |
118 | Standard_Integer NumberOfLines = isobuild.NbLines(); |
119 | |
120 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
121 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
122 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
123 | |
124 | Handle(VrmlConverter_IsoAspect) iautmp = new VrmlConverter_IsoAspect; |
125 | iautmp->SetMaterial(aDrawer->UIsoAspect()->Material()); |
126 | iautmp->SetHasMaterial(aDrawer->UIsoAspect()->HasMaterial()); |
127 | iautmp->SetNumber(aDrawer->UIsoAspect()->Number()); |
128 | |
129 | Handle(VrmlConverter_IsoAspect) iavtmp = new VrmlConverter_IsoAspect; |
130 | iavtmp->SetMaterial(aDrawer->VIsoAspect()->Material()); |
131 | iavtmp->SetHasMaterial(aDrawer->VIsoAspect()->HasMaterial()); |
132 | iavtmp->SetNumber(aDrawer->VIsoAspect()->Number()); |
133 | |
134 | Handle(VrmlConverter_LineAspect) laU = new VrmlConverter_LineAspect; |
135 | Handle(VrmlConverter_LineAspect) laV = new VrmlConverter_LineAspect; |
136 | |
137 | laU = aDrawer->UIsoAspect(); |
138 | laV = aDrawer->VIsoAspect(); |
139 | |
140 | // cout << endl; |
141 | |
142 | // cout << "Face:aDrawer>UMaterial1 = " << aDrawer->UIsoAspect()->HasMaterial() << endl; |
143 | // cout << "Face:aDrawer>VMaterial1 = " << aDrawer->VIsoAspect()->HasMaterial() << endl; |
144 | // cout << "Face:aDrawer>LineAspect1 = " << aDrawer->LineAspect()->HasMaterial() << endl; |
145 | // cout << "Face:la1 = " << latmp->HasMaterial() << endl; |
146 | // cout << "Face:laU1 = " << laU->HasMaterial() << endl; |
147 | // cout << "Face:laV1 = " << laV->HasMaterial() << endl; |
148 | // cout << "Face:iau1 = " << iautmp->HasMaterial() << endl; |
149 | // cout << "Face:iav1 = " << iavtmp->HasMaterial() << endl; |
150 | |
151 | |
152 | // creation of Vrml objects |
153 | |
154 | // Separator 1 { |
155 | Vrml_Separator SE1; |
156 | Vrml_Separator SE2; |
157 | Vrml_Separator SE3; |
158 | |
159 | Standard_Boolean flag = Standard_False; // to check a call of Vrml_Separator.Print(anOStream) |
160 | |
161 | SE1.Print(anOStream); |
162 | |
163 | if (DrawUIso) { |
164 | if (NBUiso > 0) { |
165 | |
166 | if (laU->HasMaterial()){ |
167 | |
168 | Handle(Vrml_Material) MU; |
169 | MU = laU->Material(); |
170 | |
171 | MU->Print(anOStream); |
172 | laU->SetHasMaterial(Standard_False); |
173 | |
174 | flag = Standard_True; |
175 | // Separator 2 { |
176 | SE2.Print(anOStream); |
177 | } |
178 | aDrawer->SetLineAspect(laU); |
179 | |
180 | |
181 | for (i = 1; i <= NumberOfLines; i++) { |
182 | if (isobuild.IsXLine(i)) |
183 | { |
184 | Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i); |
185 | Standard_Real Coord = isobuild.Coordinate(i); |
186 | for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) { |
187 | Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j); |
188 | |
189 | b1 = b1 == RealFirst() ? - aLimit : b1; |
190 | b2 = b2 == RealLast() ? aLimit : b2; |
191 | |
192 | anIso.Load(GeomAbs_IsoU,Coord,b1,b2); |
193 | |
194 | VrmlConverter_Curve::Add(anIso, aDrawer, anOStream); |
195 | } |
196 | } |
197 | } |
198 | |
199 | if (flag){ |
200 | // Separator 2 } |
201 | SE2.Print(anOStream); |
202 | flag = Standard_False; |
203 | } |
204 | } |
205 | } |
206 | |
207 | if (DrawVIso) { |
208 | if ( NBViso > 0) { |
209 | if (laV->HasMaterial()){ |
210 | |
211 | Handle(Vrml_Material) MV; |
212 | MV = laV->Material(); |
213 | |
214 | MV->Print(anOStream); |
215 | laV->SetHasMaterial(Standard_False); |
216 | flag = Standard_True; |
217 | |
218 | // Separator 3 { |
219 | SE3.Print(anOStream); |
220 | } |
221 | |
222 | aDrawer->SetLineAspect(laV); |
223 | |
224 | for (i = 1; i <= NumberOfLines; i++) { |
225 | if (isobuild.IsYLine(i)) |
226 | { |
227 | Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i); |
228 | Standard_Real Coord = isobuild.Coordinate(i); |
229 | for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) { |
230 | Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j); |
231 | |
232 | b1 = b1 == RealFirst() ? - aLimit : b1; |
233 | b2 = b2 == RealLast() ? aLimit : b2; |
234 | |
235 | anIso.Load(GeomAbs_IsoV,Coord,b1,b2); |
236 | |
237 | VrmlConverter_Curve::Add(anIso, aDrawer, anOStream); |
238 | } |
239 | } |
240 | } |
241 | |
242 | if (flag){ |
243 | // Separator 3 } |
244 | SE3.Print(anOStream); |
245 | flag = Standard_False; |
246 | } |
247 | } |
248 | } |
249 | |
250 | // Separator 1 } |
251 | SE1.Print(anOStream); |
252 | |
253 | aDrawer->SetLineAspect(latmp); |
254 | aDrawer->SetUIsoAspect(iautmp); |
255 | aDrawer->SetVIsoAspect(iavtmp); |
256 | |
257 | // cout << endl; |
258 | |
259 | // cout << "Face:aDrawer>UMaterial4 = " << aDrawer->UIsoAspect()->HasMaterial() << endl; |
260 | // cout << "Face:aDrawer>VMaterial4 = " << aDrawer->VIsoAspect()->HasMaterial() << endl; |
261 | // cout << "Face:aDrawer>LineAspect4 = " << aDrawer->LineAspect()->HasMaterial() << endl; |
262 | // cout << "Face:la4 = " << latmp->HasMaterial() << endl; |
263 | // cout << "Face:laU4 = " << laU->HasMaterial() << endl; |
264 | // cout << "Face:laV4 = " << laV->HasMaterial() << endl; |
265 | // cout << "Face:iau4 = " << iautmp->HasMaterial() << endl; |
266 | // cout << "Face:iav4 = " << iavtmp->HasMaterial() << endl; |
267 | |
268 | } |
269 | |
270 | |
271 | //========================================================================= |
272 | // function: Add 2 |
273 | // purpose |
274 | //========================================================================= |
275 | void VrmlConverter_WFRestrictedFace::Add |
276 | (Standard_OStream& anOStream, |
277 | const Handle(BRepAdaptor_HSurface)& aFace, |
278 | const Handle (VrmlConverter_Drawer)& aDrawer){ |
279 | |
280 | Standard_Integer finu = aDrawer->UIsoAspect()->Number(); |
281 | Standard_Integer finv = aDrawer->VIsoAspect()->Number(); |
282 | |
283 | VrmlConverter_WFRestrictedFace::Add ( |
284 | anOStream, |
285 | aFace, |
286 | Standard_True, |
287 | Standard_True, |
288 | finu, |
289 | finv, |
290 | aDrawer); |
291 | |
292 | } |
293 | |
294 | |
295 | //========================================================================= |
296 | // function: AddUIso |
297 | // purpose |
298 | //========================================================================= |
299 | void VrmlConverter_WFRestrictedFace::AddUIso |
300 | (Standard_OStream& anOStream, |
301 | const Handle(BRepAdaptor_HSurface)& aFace, |
302 | const Handle (VrmlConverter_Drawer)& aDrawer) { |
303 | |
304 | Standard_Integer finu = aDrawer->UIsoAspect()->Number(); |
305 | Standard_Integer finv = aDrawer->VIsoAspect()->Number(); |
306 | |
307 | VrmlConverter_WFRestrictedFace::Add ( |
308 | anOStream, |
309 | aFace, |
310 | Standard_True, |
311 | Standard_False, |
312 | finu, |
313 | finv, |
314 | aDrawer); |
315 | } |
316 | |
317 | |
318 | //========================================================================= |
319 | // function: AddVIso |
320 | // purpose |
321 | //========================================================================= |
322 | void VrmlConverter_WFRestrictedFace::AddVIso |
323 | (Standard_OStream& anOStream, |
324 | const Handle(BRepAdaptor_HSurface)& aFace, |
325 | const Handle (VrmlConverter_Drawer)& aDrawer) { |
326 | |
327 | Standard_Integer finu = aDrawer->UIsoAspect()->Number(); |
328 | Standard_Integer finv = aDrawer->VIsoAspect()->Number(); |
329 | |
330 | VrmlConverter_WFRestrictedFace::Add ( |
331 | anOStream, |
332 | aFace, |
333 | Standard_False, |
334 | Standard_True, |
335 | finu, |
336 | finv, |
337 | aDrawer); |
338 | } |
339 | |