1 // Copyright (C) 2007-2015 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
23 #include <GEOMAlgo_Splitter.hxx>
25 #include <TopAbs_ShapeEnum.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Compound.hxx>
29 #include <TopoDS_Iterator.hxx>
31 #include <BRep_Builder.hxx>
33 #include <BOPCol_MapOfShape.hxx>
34 #include <BOPCol_ListOfShape.hxx>
36 #include <BOPTools.hxx>
40 void TreatCompound(const TopoDS_Shape& aC,
41 BOPCol_ListOfShape& aLSX);
43 //=======================================================================
46 //=======================================================================
47 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
51 myMapTools(100, myAllocator)
56 //=======================================================================
59 //=======================================================================
60 GEOMAlgo_Splitter::GEOMAlgo_Splitter
61 (const Handle(NCollection_BaseAllocator)& theAllocator)
63 BOPAlgo_Builder(theAllocator),
65 myMapTools(100, myAllocator)
70 //=======================================================================
73 //=======================================================================
74 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
77 //=======================================================================
80 //=======================================================================
81 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
83 if (myMapTools.Add(theShape)) {
84 myTools.Append(theShape);
86 AddArgument(theShape);
89 //=======================================================================
92 //=======================================================================
93 const BOPCol_ListOfShape& GEOMAlgo_Splitter::Tools()const
97 //=======================================================================
100 //=======================================================================
101 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
105 //=======================================================================
108 //=======================================================================
109 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
113 //=======================================================================
114 //function : SetLimitMode
116 //=======================================================================
117 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
121 //=======================================================================
122 //function : LimitMode
124 //=======================================================================
125 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
129 //=======================================================================
132 //=======================================================================
133 void GEOMAlgo_Splitter::Clear()
137 myLimit=TopAbs_SHAPE;
138 BOPAlgo_Builder::Clear();
140 //=======================================================================
141 //function : BuildResult
143 //=======================================================================
144 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
148 TopAbs_ShapeEnum aType;
150 BOPCol_MapOfShape aM;
151 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
153 aIt.Initialize(myArguments);
154 for (; aIt.More(); aIt.Next()) {
155 const TopoDS_Shape& aS=aIt.Value();
156 aType=aS.ShapeType();
157 if (aType==theType && !myMapTools.Contains(aS)) {
158 if (myImages.IsBound(aS)) {
159 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
160 aItIm.Initialize(aLSIm);
161 for (; aItIm.More(); aItIm.Next()) {
162 const TopoDS_Shape& aSIm=aItIm.Value();
164 aBB.Add(myShape, aSIm);
170 aBB.Add(myShape, aS);
176 //=======================================================================
177 //function : PostTreat
179 //=======================================================================
180 void GEOMAlgo_Splitter::PostTreat()
182 if (myLimit!=TopAbs_SHAPE) {
183 Standard_Integer i, aNbS;
186 BOPCol_IndexedMapOfShape aMx;
188 aBB.MakeCompound(aC);
190 BOPTools::MapShapes(myShape, myLimit, aMx);
192 for (i=1; i<=aNbS; ++i) {
193 const TopoDS_Shape& aS=aMx(i);
197 Standard_Integer iType, iLimit, iTypeX;
198 TopAbs_ShapeEnum aType, aTypeX;
199 BOPCol_ListOfShape aLSP, aLSX;
200 BOPCol_ListIteratorOfListOfShape aIt, aItX, aItIm;
201 BOPCol_MapOfShape aM;
203 iLimit=(Standard_Integer)myLimit;
205 // 1. Collect the shapes to process aLSP
206 aIt.Initialize(myArguments);
207 for (; aIt.More(); aIt.Next()) {
208 const TopoDS_Shape& aS=aIt.Value();
209 if (myMapTools.Contains(aS)) {
213 aType=aS.ShapeType();
214 iType=(Standard_Integer)aType;
220 else if (aType==TopAbs_COMPOUND) {
223 TreatCompound(aS, aLSX);
225 aItX.Initialize(aLSX);
226 for (; aItX.More(); aItX.Next()) {
227 const TopoDS_Shape& aSX=aItX.Value();
228 aTypeX=aSX.ShapeType();
229 iTypeX=(Standard_Integer)aTypeX;
236 }// for (; aIt.More(); aIt.Next()) {
239 BOPTools::MapShapes(aC, aMx);
241 aIt.Initialize(aLSP);
242 for (; aIt.More(); aIt.Next()) {
243 const TopoDS_Shape& aS=aIt.Value();
244 if (myImages.IsBound(aS)) {
245 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
246 aItIm.Initialize(aLSIm);
247 for (; aItIm.More(); aItIm.Next()) {
248 const TopoDS_Shape& aSIm=aItIm.Value();
250 if (!aMx.Contains(aSIm)) {
258 if (!aMx.Contains(aS)) {
264 }// if (myLimitMode) {
266 }//if (myLimit!=TopAbs_SHAPE) {
268 Standard_Integer aNbS;
270 BOPCol_ListOfShape aLS;
272 aIt.Initialize(myShape);
273 for (; aIt.More(); aIt.Next()) {
274 const TopoDS_Shape& aS=aIt.Value();
282 BOPAlgo_Builder::PostTreat();
284 //=======================================================================
285 //function : TreatCompound
287 //=======================================================================
288 void TreatCompound(const TopoDS_Shape& aC1,
289 BOPCol_ListOfShape& aLSX)
291 Standard_Integer aNbC1;
292 TopAbs_ShapeEnum aType;
293 BOPCol_ListOfShape aLC, aLC1;
294 BOPCol_ListIteratorOfListOfShape aIt, aIt1;
295 TopoDS_Iterator aItC;
301 for (; aIt.More(); aIt.Next()) {
302 const TopoDS_Shape& aC=aIt.Value(); //C is compound
305 for (; aItC.More(); aItC.Next()) {
306 const TopoDS_Shape& aS=aItC.Value();
307 aType=aS.ShapeType();
308 if (aType==TopAbs_COMPOUND) {
323 aIt.Initialize(aLC1);
324 for (; aIt.More(); aIt.Next()) {
325 const TopoDS_Shape& aSC=aIt.Value();
334 // 1 - The object is just initialized
335 // 2 - PaveFiller is failed
336 // 10 - No shapes to process
337 // 30 - SolidBuilder failed