1 // Copyright (C) 2007-2012 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>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Solid.hxx>
31 #include <BRep_Builder.hxx>
33 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
34 #include <TopTools_IndexedMapOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <TopTools_MapIteratorOfMapOfShape.hxx>
42 #include <BRepClass3d_SolidClassifier.hxx>
44 #include <IntTools_Context.hxx>
46 #include <GEOMAlgo_ShapeAlgo.hxx>
47 #include <GEOMAlgo_BuilderSolid.hxx>
48 #include <GEOMAlgo_Tools3D.hxx>
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_RemoverWebs::GEOMAlgo_RemoverWebs()
59 //=======================================================================
62 //=======================================================================
63 GEOMAlgo_RemoverWebs::~GEOMAlgo_RemoverWebs()
66 //=======================================================================
67 //function : CheckData
69 //=======================================================================
70 void GEOMAlgo_RemoverWebs::CheckData()
76 if (myShape.IsNull()) {
81 aIt.Initialize(myShape);
82 for (; aIt.More(); aIt.Next()) {
83 const TopoDS_Shape& aS=aIt.Value();
84 if (aS.ShapeType()!=TopAbs_SOLID) {
90 //=======================================================================
93 //=======================================================================
94 void GEOMAlgo_RemoverWebs::Perform()
106 if (!myContext.IsNull()) {
109 myContext=new IntTools_Context;
115 //=======================================================================
116 //function : BuildSolid
118 //=======================================================================
119 void GEOMAlgo_RemoverWebs::BuildSolid()
121 Standard_Integer i, aNbF, aNbSx, iErr, aNbSI, aNbF2, aNbS, aNbR;
122 TopAbs_Orientation aOr;
123 TopoDS_Iterator aIt1, aIt2;
126 TopTools_MapOfShape aMFence;
127 TopTools_IndexedMapOfShape aMSI;
128 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
129 TopTools_ListOfShape aSFS;
130 TopTools_ListIteratorOfListOfShape aItLS;
131 GEOMAlgo_BuilderSolid aSB;
133 //modified by NIZNHY-PKV Fri Jul 12 07:22:58 2013f
136 // The compound myShape may contain equal solids
137 // (itz.brep for e.g.). The block is to refine
138 // such data if it is necessary. The shape to treat
139 // will be aShape (not myShape).
143 aIt1.Initialize(myShape);
144 for (aNbS=0; aIt1.More(); aIt1.Next(), ++aNbS) {
145 const TopoDS_Shape& aS=aIt1.Value();
149 aNbR=aMFence.Extent();
151 TopTools_MapIteratorOfMapOfShape aItMS;
153 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aShape);
155 aItMS.Initialize(aMFence);
156 for (; aItMS.More(); aItMS.Next()) {
157 const TopoDS_Shape& aS=aItMS.Key();
161 //modified by NIZNHY-PKV Fri Jul 12 07:23:02 2013t
166 TopExp::MapShapesAndAncestors(aShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
169 for (i=1; i<=aNbF; ++i) {
170 const TopoDS_Shape& aFx=aMFS.FindKey(i);
171 aOr=aFx.Orientation();
172 if (aOr==TopAbs_INTERNAL) {
176 aFi.Orientation(TopAbs_FORWARD);
178 aFi.Orientation(TopAbs_REVERSED);
182 const TopTools_ListOfShape& aLSx=aMFS(i);
193 if (!aNbF2) { // nothing to do here
198 // 2 Internal shapes: edges, vertices
199 aIt1.Initialize(aShape);
200 for (; aIt1.More(); aIt1.Next()) {
201 const TopoDS_Shape& aSD=aIt1.Value();
203 aIt2.Initialize(aSD);
204 for (; aIt2.More(); aIt2.Next()) {
205 const TopoDS_Shape& aSi=aIt2.Value();
206 if (aSi.ShapeType()!=TopAbs_SHELL) {
207 aOr=aSi.Orientation();
208 if (aOr==TopAbs_INTERNAL) {
216 // 3 Solids without internals
217 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, myResult);
219 aSB.SetContext(myContext);
222 iErr=aSB.ErrorStatus();
224 myErrorStatus=20; // SolidBuilder failed
228 const TopTools_ListOfShape& aLSR=aSB.Areas();
230 // 4 Add the internals
232 AddInternalShapes(aLSR, aMSI);
235 aItLS.Initialize(aLSR);
236 for (; aItLS.More(); aItLS.Next()) {
237 const TopoDS_Shape& aSR=aItLS.Value();
238 aBB.Add(myResult, aSR);
242 //=======================================================================
243 //function : AddInternalShapes
245 //=======================================================================
246 void GEOMAlgo_RemoverWebs::AddInternalShapes(const TopTools_ListOfShape& aLSR,
247 const TopTools_IndexedMapOfShape& aMSI)
249 Standard_Integer i, aNbSI;
253 TopTools_ListIteratorOfListOfShape aItLS;
254 Handle(IntTools_Context) aCtx;
256 aCtx=new IntTools_Context;
259 for (i=1; i<=aNbSI; ++i) {
260 const TopoDS_Shape& aSI=aMSI(i);
262 aItLS.Initialize(aLSR);
263 for (; aItLS.More(); aItLS.Next()) {
264 aSd=*((TopoDS_Solid*)&aItLS.Value());
266 aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
267 if (aState==TopAbs_IN) {
270 BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSd);
279 // 10 - myShape is Null
280 // 11 - myShape contains non-solids
281 // 20 - BuilderSolid failed