973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <VrmlConverter_WFDeflectionShape.ixx> |
15 | #include <Bnd_Box.hxx> |
16 | #include <gp_Pnt.hxx> |
17 | #include <Prs3d_ShapeTool.hxx> |
18 | #include <BRepAdaptor_HSurface.hxx> |
19 | #include <BRepAdaptor_Curve.hxx> |
20 | #include <BRepBndLib.hxx> |
21 | #include <VrmlConverter_IsoAspect.hxx> |
22 | #include <VrmlConverter_LineAspect.hxx> |
23 | #include <VrmlConverter_WFDeflectionRestrictedFace.hxx> |
24 | #include <VrmlConverter_DeflectionCurve.hxx> |
25 | #include <TColgp_HArray1OfVec.hxx> |
26 | #include <BRep_Tool.hxx> |
27 | #include <VrmlConverter_PointAspect.hxx> |
28 | #include <Vrml_Separator.hxx> |
29 | #include <Vrml_Coordinate3.hxx> |
30 | #include <Vrml_Material.hxx> |
31 | #include <Vrml_PointSet.hxx> |
32 | #include <Precision.hxx> |
33 | |
34 | |
35 | //========================================================================= |
36 | // function: Add |
37 | // purpose |
38 | //========================================================================= |
39 | void VrmlConverter_WFDeflectionShape::Add( Standard_OStream& anOStream, |
40 | const TopoDS_Shape& aShape, |
41 | const Handle (VrmlConverter_Drawer)& aDrawer) |
42 | { |
43 | |
44 | Prs3d_ShapeTool Tool(aShape); |
45 | |
46 | Standard_Real theRequestedDeflection; |
47 | if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE |
48 | { |
49 | Bnd_Box box; |
50 | BRepBndLib::AddClose(aShape, box); |
51 | |
52 | Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal; |
53 | box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax ); |
54 | if (!(box.IsOpenXmin() || box.IsOpenXmax() || |
55 | box.IsOpenYmin() || box.IsOpenYmax() || |
56 | box.IsOpenZmin() || box.IsOpenZmax())) |
57 | { |
58 | |
59 | diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin)); |
60 | diagonal = Max(diagonal, Precision::Confusion()); |
61 | theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal; |
62 | } |
63 | else |
64 | { |
65 | diagonal =1000000.; |
66 | theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal; |
67 | } |
68 | |
69 | } |
70 | else |
71 | { |
72 | theRequestedDeflection = aDrawer->MaximalChordialDeviation(); |
73 | } |
74 | //== |
75 | if (aDrawer->UIsoAspect()->Number() != 0 || |
76 | aDrawer->VIsoAspect()->Number() != 0 ) { |
77 | |
78 | BRepAdaptor_Surface S; |
79 | Standard_Boolean isoU, isoV; |
80 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
81 | isoU = (aDrawer->UIsoAspect()->Number() != 0); |
82 | isoV = (aDrawer->VIsoAspect()->Number() != 0); |
83 | if (Tool.HasSurface()) { |
84 | if (Tool.IsPlanarFace()) { |
85 | isoU = (isoU && aDrawer->IsoOnPlane()); |
86 | isoV = (isoV && aDrawer->IsoOnPlane()); |
87 | } |
88 | if (isoU || isoV) { |
89 | S.Initialize(Tool.GetFace()); |
90 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
91 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
92 | isoU, isoV, |
93 | theRequestedDeflection, |
94 | aDrawer->UIsoAspect()->Number(), |
95 | aDrawer->VIsoAspect()->Number(), |
96 | aDrawer); |
97 | } |
98 | } |
99 | } |
100 | } |
101 | |
102 | else { |
103 | |
104 | if (aDrawer->UIsoAspect()->Number() != 0) { |
105 | |
106 | BRepAdaptor_Surface S; |
107 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
108 | Standard_Boolean isoU = Standard_True; |
109 | if (Tool.HasSurface()) { |
110 | if (Tool.IsPlanarFace()) isoU = aDrawer->IsoOnPlane(); |
111 | if (isoU) { |
112 | S.Initialize(Tool.GetFace()); |
113 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
114 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
115 | isoU, Standard_False, |
116 | theRequestedDeflection, |
117 | aDrawer->UIsoAspect()->Number(), |
118 | 0, |
119 | aDrawer); |
120 | } |
121 | } |
122 | } |
123 | } |
124 | |
125 | if (aDrawer->VIsoAspect()->Number() != 0) { |
126 | |
127 | BRepAdaptor_Surface S; |
128 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
129 | Standard_Boolean isoV = Standard_True; |
130 | if (Tool.HasSurface()) { |
131 | if (Tool.IsPlanarFace()) isoV = aDrawer->IsoOnPlane(); |
132 | if (isoV) { |
133 | S.Initialize(Tool.GetFace()); |
134 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
135 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
136 | Standard_False, isoV, |
137 | theRequestedDeflection, |
138 | 0, |
139 | aDrawer->VIsoAspect()->Number(), |
140 | aDrawer); |
141 | } |
142 | } |
143 | } |
144 | } |
145 | } |
146 | |
147 | //==== |
148 | Standard_Integer qnt=0; |
149 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()) |
150 | { |
151 | qnt++; |
152 | } |
153 | |
154 | // cout << "Quantity of Curves = " << qnt << endl; |
155 | |
156 | // Wire (without any neighbour) |
157 | |
158 | if (aDrawer->WireDraw()) { |
159 | if (qnt != 0) |
160 | { |
161 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
162 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
163 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
164 | |
165 | aDrawer->SetLineAspect(aDrawer->WireAspect()); |
166 | |
167 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
168 | if (Tool.Neighbours() == 0) { |
169 | if (Tool.HasCurve()) { |
170 | BRepAdaptor_Curve C(Tool.GetCurve()); |
171 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
172 | } |
173 | } |
174 | } |
175 | aDrawer->SetLineAspect(latmp); |
176 | } |
177 | } |
178 | //end of wire |
179 | |
180 | // Free boundaries; |
181 | if (aDrawer->FreeBoundaryDraw()) { |
182 | if (qnt != 0) |
183 | { |
184 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
185 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
186 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
187 | |
188 | aDrawer->SetLineAspect(aDrawer->FreeBoundaryAspect()); |
189 | |
190 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
191 | if (Tool.Neighbours() == 1) { |
192 | if (Tool.HasCurve()) { |
193 | BRepAdaptor_Curve C(Tool.GetCurve()); |
194 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
195 | } |
196 | } |
197 | } |
198 | aDrawer->SetLineAspect(latmp); |
199 | } |
200 | } |
201 | // end of Free boundaries |
202 | |
203 | // Unfree boundaries; |
204 | if (aDrawer->UnFreeBoundaryDraw()) { |
205 | if (qnt != 0) |
206 | { |
207 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
208 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
209 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
210 | |
211 | aDrawer->SetLineAspect(aDrawer->UnFreeBoundaryAspect()); |
212 | |
213 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
214 | if (Tool.Neighbours() >= 2) { |
215 | if (Tool.HasCurve()) { |
216 | BRepAdaptor_Curve C(Tool.GetCurve()); |
217 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
218 | } |
219 | } |
220 | } |
221 | aDrawer->SetLineAspect(latmp); |
222 | } |
223 | } |
224 | // end of Unfree boundaries |
225 | |
226 | // Points |
227 | |
228 | qnt=0; |
229 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
230 | { |
231 | qnt++; |
232 | } |
233 | |
234 | // cout << "Quantity of Vertexes = " << qnt << endl; |
235 | |
236 | if (qnt != 0) |
237 | { |
238 | Handle(TColgp_HArray1OfVec) HAV = new TColgp_HArray1OfVec(1,qnt); |
239 | gp_Vec V; |
240 | gp_Pnt P; |
241 | Standard_Integer i=0; |
242 | |
243 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
244 | { |
245 | i++; |
246 | P = BRep_Tool::Pnt(Tool.GetVertex()); |
247 | V.SetX(P.X()); V.SetY(P.Y()); V.SetZ(P.Z()); |
248 | HAV->SetValue (i,V); |
249 | } |
250 | |
251 | Handle(VrmlConverter_PointAspect) PA = new VrmlConverter_PointAspect; |
252 | PA = aDrawer->PointAspect(); |
253 | |
254 | // Separator P { |
255 | Vrml_Separator SEP; |
256 | SEP.Print(anOStream); |
257 | |
258 | // Material |
259 | if (PA->HasMaterial()){ |
260 | |
261 | Handle(Vrml_Material) MP; |
262 | MP = PA->Material(); |
263 | |
264 | MP->Print(anOStream); |
265 | } |
266 | // Coordinate3 |
267 | Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV); |
268 | C3->Print(anOStream); |
269 | |
270 | // PointSet |
271 | Vrml_PointSet PS; |
272 | PS.Print(anOStream); |
273 | |
274 | // Separator P } |
275 | SEP.Print(anOStream); |
276 | } |
277 | |
278 | } |