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 | // |
973c2be1 |
5 | // This library is free software; you can redistribute it and / or modify it |
6 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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_WFShape.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_WFRestrictedFace.hxx> |
24 | #include <VrmlConverter_Curve.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 | |
33 | //========================================================================= |
34 | // function: Add |
35 | // purpose |
36 | //========================================================================= |
37 | void VrmlConverter_WFShape::Add(Standard_OStream& anOStream, |
38 | const TopoDS_Shape& aShape, |
39 | const Handle(VrmlConverter_Drawer)& aDrawer) |
40 | { |
41 | |
42 | Prs3d_ShapeTool Tool(aShape); |
43 | |
44 | if (aDrawer->UIsoAspect()->Number() != 0 || |
45 | aDrawer->VIsoAspect()->Number() != 0 ) { |
46 | |
47 | BRepAdaptor_Surface S; |
48 | Standard_Boolean isoU, isoV; |
49 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
50 | isoU = (aDrawer->UIsoAspect()->Number() != 0); |
51 | isoV = (aDrawer->VIsoAspect()->Number() != 0); |
52 | if (Tool.HasSurface()) { |
53 | if (Tool.IsPlanarFace()) { |
54 | isoU = (isoU && aDrawer->IsoOnPlane()); |
55 | isoV = (isoV && aDrawer->IsoOnPlane()); |
56 | } |
57 | if (isoU || isoV) { |
58 | S.Initialize(Tool.GetFace()); |
59 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
60 | VrmlConverter_WFRestrictedFace::Add(anOStream, HS, |
61 | isoU, isoV, |
62 | aDrawer->UIsoAspect()->Number(), |
63 | aDrawer->VIsoAspect()->Number(), |
64 | aDrawer); |
65 | } |
66 | } |
67 | } |
68 | } |
69 | |
70 | else { |
71 | |
72 | if (aDrawer->UIsoAspect()->Number() != 0) { |
73 | |
74 | BRepAdaptor_Surface S; |
75 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
76 | Standard_Boolean isoU = Standard_True; |
77 | if (Tool.HasSurface()) { |
78 | if (Tool.IsPlanarFace()) isoU = aDrawer->IsoOnPlane(); |
79 | if (isoU) { |
80 | S.Initialize(Tool.GetFace()); |
81 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
82 | VrmlConverter_WFRestrictedFace::Add(anOStream, HS, |
83 | isoU, Standard_False, |
84 | aDrawer->UIsoAspect()->Number(), |
85 | 0, |
86 | aDrawer); |
87 | } |
88 | } |
89 | } |
90 | } |
91 | |
92 | if (aDrawer->VIsoAspect()->Number() != 0) { |
93 | |
94 | BRepAdaptor_Surface S; |
95 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
96 | Standard_Boolean isoV = Standard_True; |
97 | if (Tool.HasSurface()) { |
98 | if (Tool.IsPlanarFace()) isoV = aDrawer->IsoOnPlane(); |
99 | if (isoV) { |
100 | S.Initialize(Tool.GetFace()); |
101 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
102 | VrmlConverter_WFRestrictedFace::Add(anOStream, HS, |
103 | Standard_False, isoV, |
104 | 0, |
105 | aDrawer->VIsoAspect()->Number(), |
106 | aDrawer); |
107 | } |
108 | } |
109 | } |
110 | } |
111 | } |
112 | |
113 | //==== |
114 | Standard_Integer qnt=0; |
115 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()) |
116 | { |
117 | qnt++; |
118 | } |
119 | |
120 | // cout << "Quantity of Curves = " << qnt << endl; |
121 | |
122 | // Wire (without any neighbour) |
123 | |
124 | if (aDrawer->WireDraw()) { |
125 | if (qnt != 0) |
126 | { |
127 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
128 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
129 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
130 | |
131 | aDrawer->SetLineAspect(aDrawer->WireAspect()); |
132 | |
133 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
134 | if (Tool.Neighbours() == 0) { |
135 | if (Tool.HasCurve()) { |
136 | BRepAdaptor_Curve C(Tool.GetCurve()); |
137 | VrmlConverter_Curve::Add(C, aDrawer, anOStream); |
138 | } |
139 | } |
140 | } |
141 | aDrawer->SetLineAspect(latmp); |
142 | } |
143 | } |
144 | //end of wire |
145 | |
146 | // Free boundaries; |
147 | if (aDrawer->FreeBoundaryDraw()) { |
148 | if (qnt != 0) |
149 | { |
150 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
151 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
152 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
153 | |
154 | aDrawer->SetLineAspect(aDrawer->FreeBoundaryAspect()); |
155 | |
156 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
157 | if (Tool.Neighbours() == 1) { |
158 | if (Tool.HasCurve()) { |
159 | BRepAdaptor_Curve C(Tool.GetCurve()); |
160 | VrmlConverter_Curve::Add(C, aDrawer, anOStream); |
161 | } |
162 | } |
163 | } |
164 | aDrawer->SetLineAspect(latmp); |
165 | } |
166 | } |
167 | // end of Free boundaries |
168 | |
169 | // Unfree boundaries; |
170 | if (aDrawer->UnFreeBoundaryDraw()) { |
171 | if (qnt != 0) |
172 | { |
173 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
174 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
175 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
176 | |
177 | aDrawer->SetLineAspect(aDrawer->UnFreeBoundaryAspect()); |
178 | |
179 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
180 | if (Tool.Neighbours() >= 2) { |
181 | if (Tool.HasCurve()) { |
182 | BRepAdaptor_Curve C(Tool.GetCurve()); |
183 | VrmlConverter_Curve::Add(C, aDrawer, anOStream); |
184 | } |
185 | } |
186 | } |
187 | aDrawer->SetLineAspect(latmp); |
188 | } |
189 | } |
190 | // end of Unfree boundaries |
191 | |
192 | // Points |
193 | |
194 | qnt=0; |
195 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
196 | { |
197 | qnt++; |
198 | } |
199 | |
200 | // cout << "Quantity of Vertexes = " << qnt << endl; |
201 | |
202 | if (qnt != 0) |
203 | { |
204 | Handle(TColgp_HArray1OfVec) HAV = new TColgp_HArray1OfVec(1,qnt); |
205 | gp_Vec V; |
206 | gp_Pnt P; |
207 | Standard_Integer i=0; |
208 | |
209 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
210 | { |
211 | i++; |
212 | P = BRep_Tool::Pnt(Tool.GetVertex()); |
213 | V.SetX(P.X()); V.SetY(P.Y()); V.SetZ(P.Z()); |
214 | HAV->SetValue (i,V); |
215 | } |
216 | |
217 | Handle(VrmlConverter_PointAspect) PA = new VrmlConverter_PointAspect; |
218 | PA = aDrawer->PointAspect(); |
219 | |
220 | // Separator P { |
221 | Vrml_Separator SEP; |
222 | SEP.Print(anOStream); |
223 | |
224 | // Material |
225 | if (PA->HasMaterial()){ |
226 | |
227 | Handle(Vrml_Material) MP; |
228 | MP = PA->Material(); |
229 | |
230 | MP->Print(anOStream); |
231 | } |
232 | // Coordinate3 |
233 | Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV); |
234 | C3->Print(anOStream); |
235 | |
236 | // PointSet |
237 | Vrml_PointSet PS; |
238 | PS.Print(anOStream); |
239 | |
240 | // Separator P } |
241 | SEP.Print(anOStream); |
242 | } |
243 | |
244 | } |
245 | |