1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_RemoverWebs.cxx
23 // Created: Thu Mar 28 07:40:32 2013
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_RemoverWebs.hxx>
27 #include <GEOMAlgo_ShapeAlgo.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Solid.hxx>
32 #include <BRep_Builder.hxx>
36 #include <BRepClass3d_SolidClassifier.hxx>
38 #include <IntTools_Context.hxx>
40 #include <BOPAlgo_BuilderSolid.hxx>
42 #include <BOPTools_AlgoTools.hxx>
43 #include <TopTools_MapOfShape.hxx>
45 //=======================================================================
48 //=======================================================================
49 GEOMAlgo_RemoverWebs::GEOMAlgo_RemoverWebs()
54 //=======================================================================
57 //=======================================================================
58 GEOMAlgo_RemoverWebs::~GEOMAlgo_RemoverWebs()
61 //=======================================================================
62 //function : CheckData
64 //=======================================================================
65 void GEOMAlgo_RemoverWebs::CheckData()
71 if (myShape.IsNull()) {
76 aIt.Initialize(myShape);
77 for (; aIt.More(); aIt.Next()) {
78 const TopoDS_Shape& aS=aIt.Value();
79 if (aS.ShapeType()!=TopAbs_SOLID) {
85 //=======================================================================
88 //=======================================================================
89 void GEOMAlgo_RemoverWebs::Perform()
101 if (!myContext.IsNull()) {
104 myContext=new IntTools_Context;
110 //=======================================================================
111 //function : BuildSolid
113 //=======================================================================
114 void GEOMAlgo_RemoverWebs::BuildSolid()
116 Standard_Integer i, aNbF, aNbSx, iErr, aNbSI, aNbF2, aNbS, aNbR;
117 TopAbs_Orientation aOr;
118 TopoDS_Iterator aIt1, aIt2;
121 TopTools_MapOfShape aMFence;
122 TopTools_IndexedMapOfShape aMSI;
123 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
124 TopTools_ListOfShape aSFS;
125 TopTools_ListIteratorOfListOfShape aItLS;
126 BOPAlgo_BuilderSolid aSB;
128 //modified by NIZNHY-PKV Thu Jul 11 06:54:51 2013f
131 // The compound myShape may contain equal solids
132 // (itz.brep for e.g.). The block is to refine
133 // such data if it is necessary. The shape to treat
134 // will be aShape (not myShape).
138 aIt1.Initialize(myShape);
139 for (aNbS=0; aIt1.More(); aIt1.Next(), ++aNbS) {
140 const TopoDS_Shape& aS=aIt1.Value();
144 aNbR=aMFence.Extent();
146 TopTools_MapIteratorOfMapOfShape aItMS;
148 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aShape);
150 aItMS.Initialize(aMFence);
151 for (; aItMS.More(); aItMS.Next()) {
152 const TopoDS_Shape& aS=aItMS.Key();
156 //modified by NIZNHY-PKV Thu Jul 11 06:54:54 2013t
161 TopExp::MapShapesAndAncestors(aShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
164 for (i=1; i<=aNbF; ++i) {
165 const TopoDS_Shape& aFx=aMFS.FindKey(i);
166 aOr=aFx.Orientation();
167 if (aOr==TopAbs_INTERNAL) {
171 aFi.Orientation(TopAbs_FORWARD);
173 aFi.Orientation(TopAbs_REVERSED);
177 const TopTools_ListOfShape& aLSx=aMFS(i);
188 if (!aNbF2) { // nothing to do here
193 // 2 Internal shapes: edges, vertices
194 aIt1.Initialize(aShape);
195 for (; aIt1.More(); aIt1.Next()) {
196 const TopoDS_Shape& aSD=aIt1.Value();
198 aIt2.Initialize(aSD);
199 for (; aIt2.More(); aIt2.Next()) {
200 const TopoDS_Shape& aSi=aIt2.Value();
201 if (aSi.ShapeType()!=TopAbs_SHELL) {
202 aOr=aSi.Orientation();
203 if (aOr==TopAbs_INTERNAL) {
211 // 3 Solids without internals
212 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, myResult);
214 aSB.SetContext(myContext);
217 iErr=aSB.HasErrors();
219 myErrorStatus=20; // SolidBuilder failed
223 const TopTools_ListOfShape& aLSR=aSB.Areas();
225 // 4 Add the internals
227 AddInternalShapes(aLSR, aMSI);
230 aItLS.Initialize(aLSR);
231 for (; aItLS.More(); aItLS.Next()) {
232 const TopoDS_Shape& aSR=aItLS.Value();
233 aBB.Add(myResult, aSR);
237 //=======================================================================
238 //function : AddInternalShapes
240 //=======================================================================
241 void GEOMAlgo_RemoverWebs::AddInternalShapes(const TopTools_ListOfShape& aLSR,
242 const TopTools_IndexedMapOfShape& aMSI)
244 Standard_Integer i, aNbSI;
248 TopTools_ListIteratorOfListOfShape aItLS;
249 Handle(IntTools_Context) aCtx=new IntTools_Context;
252 for (i=1; i<=aNbSI; ++i) {
253 const TopoDS_Shape& aSI=aMSI(i);
255 aItLS.Initialize(aLSR);
256 for (; aItLS.More(); aItLS.Next()) {
257 aSd=*((TopoDS_Solid*)&aItLS.Value());
259 aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
260 if (aState==TopAbs_IN) {
263 BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSd);
272 // 10 - myShape is Null
273 // 11 - myShape contains non-solids
274 // 20 - BuilderSolid failed