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 // 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>
46 void TreatCompound(const TopoDS_Shape& aC,
47 BOPCol_ListOfShape& aLSX);
49 //=======================================================================
52 //=======================================================================
53 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
57 myMapTools(100, myAllocator)
62 //=======================================================================
65 //=======================================================================
66 GEOMAlgo_Splitter::GEOMAlgo_Splitter
67 (const Handle(NCollection_BaseAllocator)& theAllocator)
69 BOPAlgo_Builder(theAllocator),
71 myMapTools(100, myAllocator)
76 //=======================================================================
79 //=======================================================================
80 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
83 //=======================================================================
86 //=======================================================================
87 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
89 if (myMapTools.Add(theShape)) {
90 myTools.Append(theShape);
92 AddArgument(theShape);
95 //=======================================================================
98 //=======================================================================
99 const BOPCol_ListOfShape& GEOMAlgo_Splitter::Tools()const
103 //=======================================================================
104 //function : SetLimit
106 //=======================================================================
107 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
111 //=======================================================================
114 //=======================================================================
115 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
119 //=======================================================================
120 //function : SetLimitMode
122 //=======================================================================
123 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
127 //=======================================================================
128 //function : LimitMode
130 //=======================================================================
131 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
135 //=======================================================================
138 //=======================================================================
139 void GEOMAlgo_Splitter::Clear()
143 myLimit=TopAbs_SHAPE;
144 BOPAlgo_Builder::Clear();
146 //=======================================================================
147 //function : BuildResult
149 //=======================================================================
150 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
154 TopAbs_ShapeEnum aType;
156 BOPCol_MapOfShape aM;
157 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
159 aIt.Initialize(myArguments);
160 for (; aIt.More(); aIt.Next()) {
161 const TopoDS_Shape& aS=aIt.Value();
162 aType=aS.ShapeType();
163 if (aType==theType && !myMapTools.Contains(aS)) {
164 if (myImages.IsBound(aS)) {
165 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
166 aItIm.Initialize(aLSIm);
167 for (; aItIm.More(); aItIm.Next()) {
168 const TopoDS_Shape& aSIm=aItIm.Value();
170 aBB.Add(myShape, aSIm);
176 aBB.Add(myShape, aS);
182 //=======================================================================
183 //function : PostTreat
185 //=======================================================================
186 void GEOMAlgo_Splitter::PostTreat()
188 if (myLimit!=TopAbs_SHAPE) {
189 Standard_Integer i, aNbS;
192 BOPCol_IndexedMapOfShape aMx;
194 aBB.MakeCompound(aC);
196 BOPTools::MapShapes(myShape, myLimit, aMx);
198 for (i=1; i<=aNbS; ++i) {
199 const TopoDS_Shape& aS=aMx(i);
203 Standard_Integer iType, iLimit, iTypeX;
204 TopAbs_ShapeEnum aType, aTypeX;
205 BOPCol_ListOfShape aLSP, aLSX;
206 BOPCol_ListIteratorOfListOfShape aIt, aItX, aItIm;
207 BOPCol_MapOfShape aM;
209 iLimit=(Standard_Integer)myLimit;
211 // 1. Collect the shapes to process aLSP
212 aIt.Initialize(myArguments);
213 for (; aIt.More(); aIt.Next()) {
214 const TopoDS_Shape& aS=aIt.Value();
215 if (myMapTools.Contains(aS)) {
219 aType=aS.ShapeType();
220 iType=(Standard_Integer)aType;
226 else if (aType==TopAbs_COMPOUND) {
229 TreatCompound(aS, aLSX);
231 aItX.Initialize(aLSX);
232 for (; aItX.More(); aItX.Next()) {
233 const TopoDS_Shape& aSX=aItX.Value();
234 aTypeX=aSX.ShapeType();
235 iTypeX=(Standard_Integer)aTypeX;
242 }// for (; aIt.More(); aIt.Next()) {
245 BOPTools::MapShapes(aC, aMx);
247 aIt.Initialize(aLSP);
248 for (; aIt.More(); aIt.Next()) {
249 const TopoDS_Shape& aS=aIt.Value();
250 if (myImages.IsBound(aS)) {
251 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
252 aItIm.Initialize(aLSIm);
253 for (; aItIm.More(); aItIm.Next()) {
254 const TopoDS_Shape& aSIm=aItIm.Value();
256 if (!aMx.Contains(aSIm)) {
264 if (!aMx.Contains(aS)) {
270 }// if (myLimitMode) {
272 }//if (myLimit!=TopAbs_SHAPE) {
274 Standard_Integer aNbS;
276 BOPCol_ListOfShape aLS;
278 aIt.Initialize(myShape);
279 for (; aIt.More(); aIt.Next()) {
280 const TopoDS_Shape& aS=aIt.Value();
288 BOPAlgo_Builder::PostTreat();
290 //=======================================================================
291 //function : TreatCompound
293 //=======================================================================
294 void TreatCompound(const TopoDS_Shape& aC1,
295 BOPCol_ListOfShape& aLSX)
297 Standard_Integer aNbC1;
298 TopAbs_ShapeEnum aType;
299 BOPCol_ListOfShape aLC, aLC1;
300 BOPCol_ListIteratorOfListOfShape aIt, aIt1;
301 TopoDS_Iterator aItC;
307 for (; aIt.More(); aIt.Next()) {
308 const TopoDS_Shape& aC=aIt.Value(); //C is compound
311 for (; aItC.More(); aItC.Next()) {
312 const TopoDS_Shape& aS=aItC.Value();
313 aType=aS.ShapeType();
314 if (aType==TopAbs_COMPOUND) {
329 aIt.Initialize(aLC1);
330 for (; aIt.More(); aIt.Next()) {
331 const TopoDS_Shape& aSC=aIt.Value();
340 // 1 - The object is just initialized
341 // 2 - PaveFiller is failed
342 // 10 - No shapes to process
343 // 30 - SolidBuilder failed