1 // Copyright (C) 2007-2013 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.
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 <BOPInt_Context.hxx>
40 #include <BOPAlgo_BuilderSolid.hxx>
42 #include <BOPTools.hxx>
43 #include <BOPTools_AlgoTools.hxx>
44 #include <BOPCol_MapOfShape.hxx>
46 //=======================================================================
49 //=======================================================================
50 GEOMAlgo_RemoverWebs::GEOMAlgo_RemoverWebs()
55 //=======================================================================
58 //=======================================================================
59 GEOMAlgo_RemoverWebs::~GEOMAlgo_RemoverWebs()
62 //=======================================================================
63 //function : CheckData
65 //=======================================================================
66 void GEOMAlgo_RemoverWebs::CheckData()
72 if (myShape.IsNull()) {
77 aIt.Initialize(myShape);
78 for (; aIt.More(); aIt.Next()) {
79 const TopoDS_Shape& aS=aIt.Value();
80 if (aS.ShapeType()!=TopAbs_SOLID) {
86 //=======================================================================
89 //=======================================================================
90 void GEOMAlgo_RemoverWebs::Perform()
102 if (!myContext.IsNull()) {
105 myContext=new BOPInt_Context;
111 //=======================================================================
112 //function : BuildSolid
114 //=======================================================================
115 void GEOMAlgo_RemoverWebs::BuildSolid()
117 Standard_Integer i, aNbF, aNbSx, iErr, aNbSI, aNbF2, aNbS, aNbR;
118 TopAbs_Orientation aOr;
119 TopoDS_Iterator aIt1, aIt2;
122 BOPCol_MapOfShape aMFence;
123 BOPCol_IndexedMapOfShape aMSI;
124 BOPCol_IndexedDataMapOfShapeListOfShape aMFS;
125 BOPCol_ListOfShape aSFS;
126 BOPCol_ListIteratorOfListOfShape aItLS;
127 BOPAlgo_BuilderSolid aSB;
129 //modified by NIZNHY-PKV Thu Jul 11 06:54:51 2013f
132 // The compound myShape may contain equal solids
133 // (itz.brep for e.g.). The block is to refine
134 // such data if it is necessary. The shape to treat
135 // will be aShape (not myShape).
139 aIt1.Initialize(myShape);
140 for (aNbS=0; aIt1.More(); aIt1.Next(), ++aNbS) {
141 const TopoDS_Shape& aS=aIt1.Value();
145 aNbR=aMFence.Extent();
147 BOPCol_MapIteratorOfMapOfShape aItMS;
149 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aShape);
151 aItMS.Initialize(aMFence);
152 for (; aItMS.More(); aItMS.Next()) {
153 const TopoDS_Shape& aS=aItMS.Key();
157 //modified by NIZNHY-PKV Thu Jul 11 06:54:54 2013t
162 BOPTools::MapShapesAndAncestors(aShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
165 for (i=1; i<=aNbF; ++i) {
166 const TopoDS_Shape& aFx=aMFS.FindKey(i);
167 aOr=aFx.Orientation();
168 if (aOr==TopAbs_INTERNAL) {
172 aFi.Orientation(TopAbs_FORWARD);
174 aFi.Orientation(TopAbs_REVERSED);
178 const BOPCol_ListOfShape& aLSx=aMFS(i);
189 if (!aNbF2) { // nothing to do here
194 // 2 Internal shapes: edges, vertices
195 aIt1.Initialize(aShape);
196 for (; aIt1.More(); aIt1.Next()) {
197 const TopoDS_Shape& aSD=aIt1.Value();
199 aIt2.Initialize(aSD);
200 for (; aIt2.More(); aIt2.Next()) {
201 const TopoDS_Shape& aSi=aIt2.Value();
202 if (aSi.ShapeType()!=TopAbs_SHELL) {
203 aOr=aSi.Orientation();
204 if (aOr==TopAbs_INTERNAL) {
212 // 3 Solids without internals
213 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, myResult);
215 aSB.SetContext(myContext);
218 iErr=aSB.ErrorStatus();
220 myErrorStatus=20; // SolidBuilder failed
224 const BOPCol_ListOfShape& aLSR=aSB.Areas();
226 // 4 Add the internals
228 AddInternalShapes(aLSR, aMSI);
231 aItLS.Initialize(aLSR);
232 for (; aItLS.More(); aItLS.Next()) {
233 const TopoDS_Shape& aSR=aItLS.Value();
234 aBB.Add(myResult, aSR);
238 //=======================================================================
239 //function : AddInternalShapes
241 //=======================================================================
242 void GEOMAlgo_RemoverWebs::AddInternalShapes(const BOPCol_ListOfShape& aLSR,
243 const BOPCol_IndexedMapOfShape& aMSI)
245 Standard_Integer i, aNbSI;
249 BOPCol_ListIteratorOfListOfShape aItLS;
250 Handle(BOPInt_Context) aCtx;
252 aCtx=new BOPInt_Context;
255 for (i=1; i<=aNbSI; ++i) {
256 const TopoDS_Shape& aSI=aMSI(i);
258 aItLS.Initialize(aLSR);
259 for (; aItLS.More(); aItLS.Next()) {
260 aSd=*((TopoDS_Solid*)&aItLS.Value());
262 aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
263 if (aState==TopAbs_IN) {
266 BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSd);
275 // 10 - myShape is Null
276 // 11 - myShape contains non-solids
277 // 20 - BuilderSolid failed