1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Bnd_Box.hxx>
16 #include <BRep_Tool.hxx>
17 #include <BRepAdaptor_Curve.hxx>
18 #include <BRepAdaptor_HSurface.hxx>
19 #include <BRepBndLib.hxx>
21 #include <Prs3d_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>
36 //=========================================================================
39 //=========================================================================
40 void VrmlConverter_WFShape::Add(Standard_OStream& anOStream,
41 const TopoDS_Shape& aShape,
42 const Handle(VrmlConverter_Drawer)& aDrawer)
45 Prs3d_ShapeTool Tool(aShape);
47 if (aDrawer->UIsoAspect()->Number() != 0 ||
48 aDrawer->VIsoAspect()->Number() != 0 ) {
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());
61 S.Initialize(Tool.GetFace());
62 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
63 VrmlConverter_WFRestrictedFace::Add(anOStream, HS,
65 aDrawer->UIsoAspect()->Number(),
66 aDrawer->VIsoAspect()->Number(),
75 if (aDrawer->UIsoAspect()->Number() != 0) {
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();
83 S.Initialize(Tool.GetFace());
84 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
85 VrmlConverter_WFRestrictedFace::Add(anOStream, HS,
87 aDrawer->UIsoAspect()->Number(),
95 if (aDrawer->VIsoAspect()->Number() != 0) {
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();
103 S.Initialize(Tool.GetFace());
104 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
105 VrmlConverter_WFRestrictedFace::Add(anOStream, HS,
106 Standard_False, isoV,
108 aDrawer->VIsoAspect()->Number(),
117 Standard_Integer qnt=0;
118 for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve())
123 // std::cout << "Quantity of Curves = " << qnt << std::endl;
125 // Wire (without any neighbour)
127 if (aDrawer->WireDraw()) {
130 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
131 latmp->SetMaterial(aDrawer->LineAspect()->Material());
132 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
134 aDrawer->SetLineAspect(aDrawer->WireAspect());
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);
144 aDrawer->SetLineAspect(latmp);
150 if (aDrawer->FreeBoundaryDraw()) {
153 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
154 latmp->SetMaterial(aDrawer->LineAspect()->Material());
155 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
157 aDrawer->SetLineAspect(aDrawer->FreeBoundaryAspect());
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);
167 aDrawer->SetLineAspect(latmp);
170 // end of Free boundaries
172 // Unfree boundaries;
173 if (aDrawer->UnFreeBoundaryDraw()) {
176 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
177 latmp->SetMaterial(aDrawer->LineAspect()->Material());
178 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
180 aDrawer->SetLineAspect(aDrawer->UnFreeBoundaryAspect());
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);
190 aDrawer->SetLineAspect(latmp);
193 // end of Unfree boundaries
198 for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex())
203 // std::cout << "Quantity of Vertexes = " << qnt << std::endl;
207 Handle(TColgp_HArray1OfVec) HAV = new TColgp_HArray1OfVec(1,qnt);
210 Standard_Integer i=0;
212 for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex())
215 P = BRep_Tool::Pnt(Tool.GetVertex());
216 V.SetX(P.X()); V.SetY(P.Y()); V.SetZ(P.Z());
220 Handle(VrmlConverter_PointAspect) PA = new VrmlConverter_PointAspect;
221 PA = aDrawer->PointAspect();
225 SEP.Print(anOStream);
228 if (PA->HasMaterial()){
230 Handle(Vrml_Material) MP;
233 MP->Print(anOStream);
236 Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV);
237 C3->Print(anOStream);
244 SEP.Print(anOStream);