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 <TopTools_MapOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
45 void TreatCompound(const TopoDS_Shape& aC,
46 TopTools_ListOfShape& aLSX);
48 //=======================================================================
51 //=======================================================================
52 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
56 myMapTools(100, myAllocator)
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_Splitter::GEOMAlgo_Splitter
66 (const Handle(NCollection_BaseAllocator)& theAllocator)
68 BOPAlgo_Builder(theAllocator),
70 myMapTools(100, myAllocator)
75 //=======================================================================
78 //=======================================================================
79 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
82 //=======================================================================
85 //=======================================================================
86 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
88 if (myMapTools.Add(theShape)) {
89 myTools.Append(theShape);
91 AddArgument(theShape);
94 //=======================================================================
97 //=======================================================================
98 const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const
102 //=======================================================================
103 //function : SetLimit
105 //=======================================================================
106 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
110 //=======================================================================
113 //=======================================================================
114 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
118 //=======================================================================
119 //function : SetLimitMode
121 //=======================================================================
122 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
126 //=======================================================================
127 //function : LimitMode
129 //=======================================================================
130 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
134 //=======================================================================
137 //=======================================================================
138 void GEOMAlgo_Splitter::Clear()
142 myLimit=TopAbs_SHAPE;
143 BOPAlgo_Builder::Clear();
145 //=======================================================================
146 //function : BuildResult
148 //=======================================================================
149 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
151 TopAbs_ShapeEnum aType;
153 TopTools_MapOfShape aM;
154 TopTools_ListIteratorOfListOfShape aIt, aItIm;
156 aIt.Initialize(myArguments);
157 for (; aIt.More(); aIt.Next()) {
158 const TopoDS_Shape& aS=aIt.Value();
159 aType=aS.ShapeType();
160 if (aType==theType && !myMapTools.Contains(aS)) {
161 if (myImages.IsBound(aS)) {
162 const TopTools_ListOfShape& aLSIm=myImages.Find(aS);
163 aItIm.Initialize(aLSIm);
164 for (; aItIm.More(); aItIm.Next()) {
165 const TopoDS_Shape& aSIm=aItIm.Value();
167 aBB.Add(myShape, aSIm);
173 aBB.Add(myShape, aS);
179 //=======================================================================
180 //function : PostTreat
182 //=======================================================================
183 void GEOMAlgo_Splitter::PostTreat()
185 if (myLimit!=TopAbs_SHAPE) {
186 Standard_Integer i, aNbS;
189 TopTools_IndexedMapOfShape aMx;
191 aBB.MakeCompound(aC);
193 TopExp::MapShapes(myShape, myLimit, aMx);
195 for (i=1; i<=aNbS; ++i) {
196 const TopoDS_Shape& aS=aMx(i);
200 Standard_Integer iType, iLimit, iTypeX;
201 TopAbs_ShapeEnum aType, aTypeX;
202 TopTools_ListOfShape aLSP, aLSX;
203 TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
204 TopTools_MapOfShape aM;
206 iLimit=(Standard_Integer)myLimit;
208 // 1. Collect the shapes to process aLSP
209 aIt.Initialize(myArguments);
210 for (; aIt.More(); aIt.Next()) {
211 const TopoDS_Shape& aS=aIt.Value();
212 if (myMapTools.Contains(aS)) {
216 aType=aS.ShapeType();
217 iType=(Standard_Integer)aType;
223 else if (aType==TopAbs_COMPOUND) {
226 TreatCompound(aS, aLSX);
228 aItX.Initialize(aLSX);
229 for (; aItX.More(); aItX.Next()) {
230 const TopoDS_Shape& aSX=aItX.Value();
231 aTypeX=aSX.ShapeType();
232 iTypeX=(Standard_Integer)aTypeX;
239 }// for (; aIt.More(); aIt.Next()) {
242 TopExp::MapShapes(aC, aMx);
244 aIt.Initialize(aLSP);
245 for (; aIt.More(); aIt.Next()) {
246 const TopoDS_Shape& aS=aIt.Value();
247 if (myImages.IsBound(aS)) {
248 const TopTools_ListOfShape& aLSIm=myImages.Find(aS);
249 aItIm.Initialize(aLSIm);
250 for (; aItIm.More(); aItIm.Next()) {
251 const TopoDS_Shape& aSIm=aItIm.Value();
253 if (!aMx.Contains(aSIm)) {
261 if (!aMx.Contains(aS)) {
267 }// if (myLimitMode) {
269 }//if (myLimit!=TopAbs_SHAPE) {
271 Standard_Integer aNbS;
273 TopTools_ListOfShape aLS;
275 aIt.Initialize(myShape);
276 for (; aIt.More(); aIt.Next()) {
277 const TopoDS_Shape& aS=aIt.Value();
285 BOPAlgo_Builder::PostTreat();
287 //=======================================================================
288 //function : TreatCompound
290 //=======================================================================
291 void TreatCompound(const TopoDS_Shape& aC1,
292 TopTools_ListOfShape& aLSX)
294 Standard_Integer aNbC1;
295 TopAbs_ShapeEnum aType;
296 TopTools_ListOfShape aLC, aLC1;
297 TopTools_ListIteratorOfListOfShape aIt, aIt1;
298 TopoDS_Iterator aItC;
304 for (; aIt.More(); aIt.Next()) {
305 const TopoDS_Shape& aC=aIt.Value(); //C is compound
308 for (; aItC.More(); aItC.Next()) {
309 const TopoDS_Shape& aS=aItC.Value();
310 aType=aS.ShapeType();
311 if (aType==TopAbs_COMPOUND) {
326 aIt.Initialize(aLC1);
327 for (; aIt.More(); aIt.Next()) {
328 const TopoDS_Shape& aSC=aIt.Value();
337 // 1 - The object is just initialized
338 // 2 - PaveFiller is failed
339 // 10 - No shapes to process
340 // 30 - SolidBuilder failed