1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GEOMAlgo_Splitter.hxx>
22 #include <TopAbs_ShapeEnum.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Compound.hxx>
26 #include <TopoDS_Iterator.hxx>
28 #include <BRep_Builder.hxx>
31 void TreatCompound(const TopoDS_Shape& aC,
32 NCollection_List<TopoDS_Shape>& aLSX);
34 //=======================================================================
37 //=======================================================================
38 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
42 myMapTools(100, myAllocator)
47 //=======================================================================
50 //=======================================================================
51 GEOMAlgo_Splitter::GEOMAlgo_Splitter
52 (const Handle(NCollection_BaseAllocator)& theAllocator)
54 BOPAlgo_Builder(theAllocator),
56 myMapTools(100, myAllocator)
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
68 //=======================================================================
71 //=======================================================================
72 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
74 if (myMapTools.Add(theShape)) {
75 myTools.Append(theShape);
77 AddArgument(theShape);
80 //=======================================================================
83 //=======================================================================
84 const NCollection_List<TopoDS_Shape>& GEOMAlgo_Splitter::Tools()const
88 //=======================================================================
91 //=======================================================================
92 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
96 //=======================================================================
99 //=======================================================================
100 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
104 //=======================================================================
105 //function : SetLimitMode
107 //=======================================================================
108 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
112 //=======================================================================
113 //function : LimitMode
115 //=======================================================================
116 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
120 //=======================================================================
123 //=======================================================================
124 void GEOMAlgo_Splitter::Clear()
128 myLimit=TopAbs_SHAPE;
129 BOPAlgo_Builder::Clear();
131 //=======================================================================
132 //function : BuildResult
134 //=======================================================================
135 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
137 TopAbs_ShapeEnum aType;
139 NCollection_Map<TopoDS_Shape> aM;
140 NCollection_List<TopoDS_Shape>::Iterator aIt, aItIm;
142 aIt.Initialize(myArguments);
143 for (; aIt.More(); aIt.Next()) {
144 const TopoDS_Shape& aS=aIt.Value();
145 aType=aS.ShapeType();
146 if (aType==theType && !myMapTools.Contains(aS)) {
147 if (myImages.IsBound(aS)) {
148 const NCollection_List<TopoDS_Shape>& aLSIm=myImages.Find(aS);
149 aItIm.Initialize(aLSIm);
150 for (; aItIm.More(); aItIm.Next()) {
151 const TopoDS_Shape& aSIm=aItIm.Value();
153 aBB.Add(myShape, aSIm);
159 aBB.Add(myShape, aS);
165 //=======================================================================
166 //function : PostTreat
168 //=======================================================================
169 void GEOMAlgo_Splitter::PostTreat()
171 if (myLimit!=TopAbs_SHAPE) {
172 Standard_Integer i, aNbS;
175 TopTools_IndexedMapOfShape aMx;
177 aBB.MakeCompound(aC);
179 TopExp::MapShapes(myShape, myLimit, aMx);
181 for (i=1; i<=aNbS; ++i) {
182 const TopoDS_Shape& aS=aMx(i);
186 Standard_Integer iType, iLimit, iTypeX;
187 TopAbs_ShapeEnum aType, aTypeX;
188 NCollection_List<TopoDS_Shape> aLSP, aLSX;
189 NCollection_List<TopoDS_Shape>::Iterator aIt, aItX, aItIm;
190 NCollection_Map<TopoDS_Shape> aM;
192 iLimit=(Standard_Integer)myLimit;
194 // 1. Collect the shapes to process aLSP
195 aIt.Initialize(myArguments);
196 for (; aIt.More(); aIt.Next()) {
197 const TopoDS_Shape& aS=aIt.Value();
198 if (myMapTools.Contains(aS)) {
202 aType=aS.ShapeType();
203 iType=(Standard_Integer)aType;
209 else if (aType==TopAbs_COMPOUND) {
212 TreatCompound(aS, aLSX);
214 aItX.Initialize(aLSX);
215 for (; aItX.More(); aItX.Next()) {
216 const TopoDS_Shape& aSX=aItX.Value();
217 aTypeX=aSX.ShapeType();
218 iTypeX=(Standard_Integer)aTypeX;
225 }// for (; aIt.More(); aIt.Next()) {
228 TopExp::MapShapes(aC, aMx);
230 aIt.Initialize(aLSP);
231 for (; aIt.More(); aIt.Next()) {
232 const TopoDS_Shape& aS=aIt.Value();
233 if (myImages.IsBound(aS)) {
234 const NCollection_List<TopoDS_Shape>& aLSIm=myImages.Find(aS);
235 aItIm.Initialize(aLSIm);
236 for (; aItIm.More(); aItIm.Next()) {
237 const TopoDS_Shape& aSIm=aItIm.Value();
239 if (!aMx.Contains(aSIm)) {
247 if (!aMx.Contains(aS)) {
253 }// if (myLimitMode) {
255 }//if (myLimit!=TopAbs_SHAPE) {
257 Standard_Integer aNbS;
259 NCollection_List<TopoDS_Shape> aLS;
261 aIt.Initialize(myShape);
262 for (; aIt.More(); aIt.Next()) {
263 const TopoDS_Shape& aS=aIt.Value();
271 BOPAlgo_Builder::PostTreat();
273 //=======================================================================
274 //function : TreatCompound
276 //=======================================================================
277 void TreatCompound(const TopoDS_Shape& aC1,
278 NCollection_List<TopoDS_Shape>& aLSX)
280 Standard_Integer aNbC1;
281 TopAbs_ShapeEnum aType;
282 NCollection_List<TopoDS_Shape> aLC, aLC1;
283 NCollection_List<TopoDS_Shape>::Iterator aIt, aIt1;
284 TopoDS_Iterator aItC;
290 for (; aIt.More(); aIt.Next()) {
291 const TopoDS_Shape& aC=aIt.Value(); //C is compound
294 for (; aItC.More(); aItC.Next()) {
295 const TopoDS_Shape& aS=aItC.Value();
296 aType=aS.ShapeType();
297 if (aType==TopAbs_COMPOUND) {
312 aIt.Initialize(aLC1);
313 for (; aIt.More(); aIt.Next()) {
314 const TopoDS_Shape& aSC=aIt.Value();
323 // 1 - The object is just initialized
324 // 2 - PaveFiller is failed
325 // 10 - No shapes to process
326 // 30 - SolidBuilder failed