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