1 // Copyright (C) 2007-2023 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 #if OCC_VERSION_LARGE < 0x07070000
184 void GEOMAlgo_Splitter::PostTreat()
186 void GEOMAlgo_Splitter::PostTreat(const Message_ProgressRange& theRange)
189 if (myLimit!=TopAbs_SHAPE) {
190 Standard_Integer i, aNbS;
193 TopTools_IndexedMapOfShape aMx;
195 aBB.MakeCompound(aC);
197 TopExp::MapShapes(myShape, myLimit, aMx);
199 for (i=1; i<=aNbS; ++i) {
200 const TopoDS_Shape& aS=aMx(i);
204 Standard_Integer iType, iLimit, iTypeX;
205 TopAbs_ShapeEnum aType, aTypeX;
206 TopTools_ListOfShape aLSP, aLSX;
207 TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
208 TopTools_MapOfShape aM;
210 iLimit=(Standard_Integer)myLimit;
212 // 1. Collect the shapes to process aLSP
213 aIt.Initialize(myArguments);
214 for (; aIt.More(); aIt.Next()) {
215 const TopoDS_Shape& aS=aIt.Value();
216 if (myMapTools.Contains(aS)) {
220 aType=aS.ShapeType();
221 iType=(Standard_Integer)aType;
227 else if (aType==TopAbs_COMPOUND) {
230 TreatCompound(aS, aLSX);
232 aItX.Initialize(aLSX);
233 for (; aItX.More(); aItX.Next()) {
234 const TopoDS_Shape& aSX=aItX.Value();
235 aTypeX=aSX.ShapeType();
236 iTypeX=(Standard_Integer)aTypeX;
243 }// for (; aIt.More(); aIt.Next()) {
246 TopExp::MapShapes(aC, aMx);
248 aIt.Initialize(aLSP);
249 for (; aIt.More(); aIt.Next()) {
250 const TopoDS_Shape& aS=aIt.Value();
251 if (myImages.IsBound(aS)) {
252 const TopTools_ListOfShape& aLSIm=myImages.Find(aS);
253 aItIm.Initialize(aLSIm);
254 for (; aItIm.More(); aItIm.Next()) {
255 const TopoDS_Shape& aSIm=aItIm.Value();
257 if (!aMx.Contains(aSIm)) {
265 if (!aMx.Contains(aS)) {
271 }// if (myLimitMode) {
273 }//if (myLimit!=TopAbs_SHAPE) {
275 Standard_Integer aNbS;
277 TopTools_ListOfShape aLS;
279 aIt.Initialize(myShape);
280 for (; aIt.More(); aIt.Next()) {
281 const TopoDS_Shape& aS=aIt.Value();
289 #if OCC_VERSION_LARGE < 0x07070000
290 BOPAlgo_Builder::PostTreat();
292 BOPAlgo_Builder::PostTreat(theRange);
295 //=======================================================================
296 //function : TreatCompound
298 //=======================================================================
299 void TreatCompound(const TopoDS_Shape& aC1,
300 TopTools_ListOfShape& aLSX)
302 Standard_Integer aNbC1;
303 TopAbs_ShapeEnum aType;
304 TopTools_ListOfShape aLC, aLC1;
305 TopTools_ListIteratorOfListOfShape aIt, aIt1;
306 TopoDS_Iterator aItC;
312 for (; aIt.More(); aIt.Next()) {
313 const TopoDS_Shape& aC=aIt.Value(); //C is compound
316 for (; aItC.More(); aItC.Next()) {
317 const TopoDS_Shape& aS=aItC.Value();
318 aType=aS.ShapeType();
319 if (aType==TopAbs_COMPOUND) {
334 aIt.Initialize(aLC1);
335 for (; aIt.More(); aIt.Next()) {
336 const TopoDS_Shape& aSC=aIt.Value();
345 // 1 - The object is just initialized
346 // 2 - PaveFiller is failed
347 // 10 - No shapes to process
348 // 30 - SolidBuilder failed