1 // Copyright (C) 2007-2014 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 <Basics_OCCTVersion.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Solid.hxx>
34 #include <BRep_Builder.hxx>
38 #include <BRepClass3d_SolidClassifier.hxx>
40 #if OCC_VERSION_LARGE > 0x06070100
41 #include <IntTools_Context.hxx>
43 #include <BOPInt_Context.hxx>
46 #include <BOPAlgo_BuilderSolid.hxx>
48 #include <BOPTools.hxx>
49 #include <BOPTools_AlgoTools.hxx>
50 #include <BOPCol_MapOfShape.hxx>
52 //=======================================================================
55 //=======================================================================
56 GEOMAlgo_RemoverWebs::GEOMAlgo_RemoverWebs()
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_RemoverWebs::~GEOMAlgo_RemoverWebs()
68 //=======================================================================
69 //function : CheckData
71 //=======================================================================
72 void GEOMAlgo_RemoverWebs::CheckData()
78 if (myShape.IsNull()) {
83 aIt.Initialize(myShape);
84 for (; aIt.More(); aIt.Next()) {
85 const TopoDS_Shape& aS=aIt.Value();
86 if (aS.ShapeType()!=TopAbs_SOLID) {
92 //=======================================================================
95 //=======================================================================
96 void GEOMAlgo_RemoverWebs::Perform()
108 if (!myContext.IsNull()) {
111 #if OCC_VERSION_LARGE > 0x06070100
112 myContext=new IntTools_Context;
114 myContext=new BOPInt_Context;
121 //=======================================================================
122 //function : BuildSolid
124 //=======================================================================
125 void GEOMAlgo_RemoverWebs::BuildSolid()
127 Standard_Integer i, aNbF, aNbSx, iErr, aNbSI, aNbF2, aNbS, aNbR;
128 TopAbs_Orientation aOr;
129 TopoDS_Iterator aIt1, aIt2;
132 BOPCol_MapOfShape aMFence;
133 BOPCol_IndexedMapOfShape aMSI;
134 BOPCol_IndexedDataMapOfShapeListOfShape aMFS;
135 BOPCol_ListOfShape aSFS;
136 BOPCol_ListIteratorOfListOfShape aItLS;
137 BOPAlgo_BuilderSolid aSB;
139 //modified by NIZNHY-PKV Thu Jul 11 06:54:51 2013f
142 // The compound myShape may contain equal solids
143 // (itz.brep for e.g.). The block is to refine
144 // such data if it is necessary. The shape to treat
145 // will be aShape (not myShape).
149 aIt1.Initialize(myShape);
150 for (aNbS=0; aIt1.More(); aIt1.Next(), ++aNbS) {
151 const TopoDS_Shape& aS=aIt1.Value();
155 aNbR=aMFence.Extent();
157 BOPCol_MapIteratorOfMapOfShape aItMS;
159 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aShape);
161 aItMS.Initialize(aMFence);
162 for (; aItMS.More(); aItMS.Next()) {
163 const TopoDS_Shape& aS=aItMS.Key();
167 //modified by NIZNHY-PKV Thu Jul 11 06:54:54 2013t
172 BOPTools::MapShapesAndAncestors(aShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
175 for (i=1; i<=aNbF; ++i) {
176 const TopoDS_Shape& aFx=aMFS.FindKey(i);
177 aOr=aFx.Orientation();
178 if (aOr==TopAbs_INTERNAL) {
182 aFi.Orientation(TopAbs_FORWARD);
184 aFi.Orientation(TopAbs_REVERSED);
188 const BOPCol_ListOfShape& aLSx=aMFS(i);
199 if (!aNbF2) { // nothing to do here
204 // 2 Internal shapes: edges, vertices
205 aIt1.Initialize(aShape);
206 for (; aIt1.More(); aIt1.Next()) {
207 const TopoDS_Shape& aSD=aIt1.Value();
209 aIt2.Initialize(aSD);
210 for (; aIt2.More(); aIt2.Next()) {
211 const TopoDS_Shape& aSi=aIt2.Value();
212 if (aSi.ShapeType()!=TopAbs_SHELL) {
213 aOr=aSi.Orientation();
214 if (aOr==TopAbs_INTERNAL) {
222 // 3 Solids without internals
223 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, myResult);
225 aSB.SetContext(myContext);
228 iErr=aSB.ErrorStatus();
230 myErrorStatus=20; // SolidBuilder failed
234 const BOPCol_ListOfShape& aLSR=aSB.Areas();
236 // 4 Add the internals
238 AddInternalShapes(aLSR, aMSI);
241 aItLS.Initialize(aLSR);
242 for (; aItLS.More(); aItLS.Next()) {
243 const TopoDS_Shape& aSR=aItLS.Value();
244 aBB.Add(myResult, aSR);
248 //=======================================================================
249 //function : AddInternalShapes
251 //=======================================================================
252 void GEOMAlgo_RemoverWebs::AddInternalShapes(const BOPCol_ListOfShape& aLSR,
253 const BOPCol_IndexedMapOfShape& aMSI)
255 Standard_Integer i, aNbSI;
259 BOPCol_ListIteratorOfListOfShape aItLS;
260 #if OCC_VERSION_LARGE > 0x06070100
261 Handle(IntTools_Context) aCtx=new IntTools_Context;
263 Handle(BOPInt_Context) aCtx=new BOPInt_Context;
267 for (i=1; i<=aNbSI; ++i) {
268 const TopoDS_Shape& aSI=aMSI(i);
270 aItLS.Initialize(aLSR);
271 for (; aItLS.More(); aItLS.Next()) {
272 aSd=*((TopoDS_Solid*)&aItLS.Value());
274 aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
275 if (aState==TopAbs_IN) {
278 BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSd);
287 // 10 - myShape is Null
288 // 11 - myShape contains non-solids
289 // 20 - BuilderSolid failed