0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_makesolids.cxx
1 // Created on: 1996-03-07
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <gp_Pnt.hxx>
22 #include <Standard_NoSuchObject.hxx>
23 #include <Standard_ProgramError.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TopExp.hxx>
26 #include <TopoDS.hxx>
27 #include <TopoDS_Compound.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopOpeBRepBuild_Builder.hxx>
34 #include <TopOpeBRepBuild_define.hxx>
35 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
36 #include <TopOpeBRepBuild_FaceBuilder.hxx>
37 #include <TopOpeBRepBuild_GTopo.hxx>
38 #include <TopOpeBRepBuild_HBuilder.hxx>
39 #include <TopOpeBRepBuild_PaveSet.hxx>
40 #include <TopOpeBRepBuild_ShapeSet.hxx>
41 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
42 #include <TopOpeBRepBuild_SolidBuilder.hxx>
43 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
44 #include <TopOpeBRepDS_BuildTool.hxx>
45 #include <TopOpeBRepDS_CurveIterator.hxx>
46 #include <TopOpeBRepDS_HDataStructure.hxx>
47 #include <TopOpeBRepDS_PointIterator.hxx>
48 #include <TopOpeBRepDS_SurfaceIterator.hxx>
49 #include <TopOpeBRepTool.hxx>
50 #include <TopOpeBRepTool_ShapeExplorer.hxx>
51 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
52 #include <TopTools_IndexedMapOfOrientedShape.hxx>
53
54 #ifdef OCCT_DEBUG
55 Standard_EXPORT void debgsobu(const Standard_Integer /*iSO*/) {}
56 #endif
57
58 //=======================================================================
59 //function : GSFSMakeSolids
60 //purpose  : 
61 //=======================================================================
62 void TopOpeBRepBuild_Builder::GSFSMakeSolids      
63 (const TopoDS_Shape& SOF,TopOpeBRepBuild_ShellFaceSet& SFS,TopTools_ListOfShape& LOSO)
64 {
65 #ifdef OCCT_DEBUG
66   Standard_Integer iSO; Standard_Boolean tSPS = GtraceSPS(SOF,iSO);
67   if(tSPS){GdumpSHA(SOF, (char *) "#--- GSFSMakeSolids ");std::cout<<std::endl;}
68 #endif
69   
70   Standard_Boolean ForceClass = Standard_True;
71   TopOpeBRepBuild_SolidBuilder SOBU;
72   SOBU.InitSolidBuilder(SFS,ForceClass);
73   GSOBUMakeSolids(SOF,SOBU,LOSO);
74   
75 } // GSFSMakeSolids
76
77 //=======================================================================
78 //function : GSOBUMakeSolids
79 //purpose  : 
80 //=======================================================================
81 void TopOpeBRepBuild_Builder::GSOBUMakeSolids
82 (const TopoDS_Shape& SOF,TopOpeBRepBuild_SolidBuilder& SOBU,TopTools_ListOfShape& LOSO)
83 {
84 #ifdef OCCT_DEBUG
85   Standard_Integer iSO; Standard_Boolean tSPS = GtraceSPS(SOF,iSO);
86   if(tSPS){GdumpSHA(SOF, (char *) "#--- GSOBUMakeSolids ");std::cout<<std::endl;}
87   if(tSPS){GdumpSOBU(SOBU);debgsobu(iSO);}
88 #endif
89   
90   TopoDS_Shape newSolid;
91   TopoDS_Shape newShell;
92   Standard_Integer nfa = 0;
93   Standard_Integer nsh = 0;
94   SOBU.InitSolid();
95   for (; SOBU.MoreSolid(); SOBU.NextSolid()) {
96
97     myBuildTool.MakeSolid(newSolid);
98     nsh = SOBU.InitShell();
99     for (; SOBU.MoreShell(); SOBU.NextShell()) {
100       Standard_Boolean isold = SOBU.IsOldShell();
101       if (isold) newShell = SOBU.OldShell();
102       else {
103         myBuildTool.MakeShell(newShell);
104         nfa = SOBU.InitFace();
105         for (; SOBU.MoreFace(); SOBU.NextFace()) {
106           TopoDS_Shape F = SOBU.Face();
107           myBuildTool.AddShellFace(newShell,F);
108         }
109       }
110       
111       // caractere closed du nouveau shell newShell
112       if ( !isold ) {
113         Standard_Boolean closed = Standard_True;        
114         TopTools_IndexedDataMapOfShapeListOfShape edgemap;
115         TopExp::MapShapesAndAncestors
116           (newShell,TopAbs_EDGE,TopAbs_FACE,edgemap);
117         Standard_Integer iedge,nedge = edgemap.Extent(); 
118         for (iedge = 1; iedge <= nedge; iedge++) {
119           const TopoDS_Shape& E = edgemap.FindKey(iedge);
120           TopAbs_Orientation oE = E.Orientation();
121           if (oE == TopAbs_INTERNAL || 
122               oE == TopAbs_EXTERNAL) continue;
123           const TopoDS_Edge& EE = TopoDS::Edge(E);
124           Standard_Boolean degen = BRep_Tool::Degenerated(EE);
125           if (degen) continue;
126           Standard_Integer nbf = edgemap(iedge).Extent();
127           if (nbf < 2) {
128             closed = Standard_False;
129             break;
130           }
131         }
132         myBuildTool.Closed(newShell,closed); 
133       } // !isold
134
135       myBuildTool.AddSolidShell(newSolid,newShell);
136
137     }
138
139     TopExp_Explorer ex(newSolid,TopAbs_VERTEX);
140     Standard_Boolean isempty = ex.More();    
141     if (!isempty) {
142       continue;
143     }
144
145     Standard_Boolean newSolidOK = Standard_True;
146     if (nsh == 1 && nfa == 1) {
147       TopExp_Explorer exp(newSolid,TopAbs_EDGE);
148       Standard_Boolean hasnondegenerated = Standard_False;
149       for(;exp.More(); exp.Next()) {
150         const TopoDS_Edge& e = TopoDS::Edge(exp.Current());
151         if ( !BRep_Tool::Degenerated(e) ) {
152           hasnondegenerated = Standard_True;
153           break;
154         }
155       }
156       newSolidOK = hasnondegenerated;
157       if ( !newSolidOK ) continue;
158     }
159
160     TopTools_ListOfShape newSolidLOS;
161     RegularizeSolid(SOF,newSolid,newSolidLOS);
162     LOSO.Append(newSolidLOS);
163 //    LOSO.Append(newSolid);
164   }
165 } // GSOBUMakeSolids