1 // Copyright (C) 2007-2016 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 // File: GEOMAlgo_Splitter.cxx
24 // Created: Thu Sep 06 10:54:04 2012
25 // Author: Peter KURNEV
29 #include <GEOMAlgo_Splitter.hxx>
31 #include <TopAbs_ShapeEnum.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_Iterator.hxx>
37 #include <BRep_Builder.hxx>
39 #include <BOPCol_MapOfShape.hxx>
40 #include <BOPCol_ListOfShape.hxx>
42 #include <BOPTools.hxx>
44 #include <Basics_OCCTVersion.hxx>
47 void TreatCompound(const TopoDS_Shape& aC,
48 BOPCol_ListOfShape& aLSX);
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
58 myMapTools(100, myAllocator)
63 //=======================================================================
66 //=======================================================================
67 GEOMAlgo_Splitter::GEOMAlgo_Splitter
68 (const Handle(NCollection_BaseAllocator)& theAllocator)
70 BOPAlgo_Builder(theAllocator),
72 myMapTools(100, myAllocator)
77 //=======================================================================
80 //=======================================================================
81 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
84 //=======================================================================
87 //=======================================================================
88 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
90 if (myMapTools.Add(theShape)) {
91 myTools.Append(theShape);
93 AddArgument(theShape);
96 //=======================================================================
99 //=======================================================================
100 const BOPCol_ListOfShape& GEOMAlgo_Splitter::Tools()const
104 //=======================================================================
105 //function : SetLimit
107 //=======================================================================
108 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
112 //=======================================================================
115 //=======================================================================
116 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
120 //=======================================================================
121 //function : SetLimitMode
123 //=======================================================================
124 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
128 //=======================================================================
129 //function : LimitMode
131 //=======================================================================
132 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
136 //=======================================================================
139 //=======================================================================
140 void GEOMAlgo_Splitter::Clear()
144 myLimit=TopAbs_SHAPE;
145 BOPAlgo_Builder::Clear();
147 //=======================================================================
148 //function : BuildResult
150 //=======================================================================
151 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
153 #if OCC_VERSION_LARGE <= 0x07010000
157 TopAbs_ShapeEnum aType;
159 BOPCol_MapOfShape aM;
160 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
162 aIt.Initialize(myArguments);
163 for (; aIt.More(); aIt.Next()) {
164 const TopoDS_Shape& aS=aIt.Value();
165 aType=aS.ShapeType();
166 if (aType==theType && !myMapTools.Contains(aS)) {
167 if (myImages.IsBound(aS)) {
168 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
169 aItIm.Initialize(aLSIm);
170 for (; aItIm.More(); aItIm.Next()) {
171 const TopoDS_Shape& aSIm=aItIm.Value();
173 aBB.Add(myShape, aSIm);
179 aBB.Add(myShape, aS);
185 //=======================================================================
186 //function : PostTreat
188 //=======================================================================
189 void GEOMAlgo_Splitter::PostTreat()
191 if (myLimit!=TopAbs_SHAPE) {
192 Standard_Integer i, aNbS;
195 BOPCol_IndexedMapOfShape aMx;
197 aBB.MakeCompound(aC);
199 BOPTools::MapShapes(myShape, myLimit, aMx);
201 for (i=1; i<=aNbS; ++i) {
202 const TopoDS_Shape& aS=aMx(i);
206 Standard_Integer iType, iLimit, iTypeX;
207 TopAbs_ShapeEnum aType, aTypeX;
208 BOPCol_ListOfShape aLSP, aLSX;
209 BOPCol_ListIteratorOfListOfShape aIt, aItX, aItIm;
210 BOPCol_MapOfShape aM;
212 iLimit=(Standard_Integer)myLimit;
214 // 1. Collect the shapes to process aLSP
215 aIt.Initialize(myArguments);
216 for (; aIt.More(); aIt.Next()) {
217 const TopoDS_Shape& aS=aIt.Value();
218 if (myMapTools.Contains(aS)) {
222 aType=aS.ShapeType();
223 iType=(Standard_Integer)aType;
229 else if (aType==TopAbs_COMPOUND) {
232 TreatCompound(aS, aLSX);
234 aItX.Initialize(aLSX);
235 for (; aItX.More(); aItX.Next()) {
236 const TopoDS_Shape& aSX=aItX.Value();
237 aTypeX=aSX.ShapeType();
238 iTypeX=(Standard_Integer)aTypeX;
245 }// for (; aIt.More(); aIt.Next()) {
248 BOPTools::MapShapes(aC, aMx);
250 aIt.Initialize(aLSP);
251 for (; aIt.More(); aIt.Next()) {
252 const TopoDS_Shape& aS=aIt.Value();
253 if (myImages.IsBound(aS)) {
254 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
255 aItIm.Initialize(aLSIm);
256 for (; aItIm.More(); aItIm.Next()) {
257 const TopoDS_Shape& aSIm=aItIm.Value();
259 if (!aMx.Contains(aSIm)) {
267 if (!aMx.Contains(aS)) {
273 }// if (myLimitMode) {
275 }//if (myLimit!=TopAbs_SHAPE) {
277 Standard_Integer aNbS;
279 BOPCol_ListOfShape aLS;
281 aIt.Initialize(myShape);
282 for (; aIt.More(); aIt.Next()) {
283 const TopoDS_Shape& aS=aIt.Value();
291 BOPAlgo_Builder::PostTreat();
293 //=======================================================================
294 //function : TreatCompound
296 //=======================================================================
297 void TreatCompound(const TopoDS_Shape& aC1,
298 BOPCol_ListOfShape& aLSX)
300 Standard_Integer aNbC1;
301 TopAbs_ShapeEnum aType;
302 BOPCol_ListOfShape aLC, aLC1;
303 BOPCol_ListIteratorOfListOfShape aIt, aIt1;
304 TopoDS_Iterator aItC;
310 for (; aIt.More(); aIt.Next()) {
311 const TopoDS_Shape& aC=aIt.Value(); //C is compound
314 for (; aItC.More(); aItC.Next()) {
315 const TopoDS_Shape& aS=aItC.Value();
316 aType=aS.ShapeType();
317 if (aType==TopAbs_COMPOUND) {
332 aIt.Initialize(aLC1);
333 for (; aIt.More(); aIt.Next()) {
334 const TopoDS_Shape& aSC=aIt.Value();
343 // 1 - The object is just initialized
344 // 2 - PaveFiller is failed
345 // 10 - No shapes to process
346 // 30 - SolidBuilder failed