1 // Copyright (C) 2007-2024 CEA, EDF
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 #if OCC_VERSION_LARGE < 0x07070000
170 void GEOMAlgo_Splitter::PostTreat()
172 void GEOMAlgo_Splitter::PostTreat(const Message_ProgressRange& theRange)
175 if (myLimit!=TopAbs_SHAPE) {
176 Standard_Integer i, aNbS;
179 TopTools_IndexedMapOfShape aMx;
181 aBB.MakeCompound(aC);
183 TopExp::MapShapes(myShape, myLimit, aMx);
185 for (i=1; i<=aNbS; ++i) {
186 const TopoDS_Shape& aS=aMx(i);
190 Standard_Integer iType, iLimit, iTypeX;
191 TopAbs_ShapeEnum aType, aTypeX;
192 NCollection_List<TopoDS_Shape> aLSP, aLSX;
193 NCollection_List<TopoDS_Shape>::Iterator aIt, aItX, aItIm;
194 NCollection_Map<TopoDS_Shape> aM;
196 iLimit=(Standard_Integer)myLimit;
198 // 1. Collect the shapes to process aLSP
199 aIt.Initialize(myArguments);
200 for (; aIt.More(); aIt.Next()) {
201 const TopoDS_Shape& aS=aIt.Value();
202 if (myMapTools.Contains(aS)) {
206 aType=aS.ShapeType();
207 iType=(Standard_Integer)aType;
213 else if (aType==TopAbs_COMPOUND) {
216 TreatCompound(aS, aLSX);
218 aItX.Initialize(aLSX);
219 for (; aItX.More(); aItX.Next()) {
220 const TopoDS_Shape& aSX=aItX.Value();
221 aTypeX=aSX.ShapeType();
222 iTypeX=(Standard_Integer)aTypeX;
229 }// for (; aIt.More(); aIt.Next()) {
232 TopExp::MapShapes(aC, aMx);
234 aIt.Initialize(aLSP);
235 for (; aIt.More(); aIt.Next()) {
236 const TopoDS_Shape& aS=aIt.Value();
237 if (myImages.IsBound(aS)) {
238 const NCollection_List<TopoDS_Shape>& aLSIm=myImages.Find(aS);
239 aItIm.Initialize(aLSIm);
240 for (; aItIm.More(); aItIm.Next()) {
241 const TopoDS_Shape& aSIm=aItIm.Value();
243 if (!aMx.Contains(aSIm)) {
251 if (!aMx.Contains(aS)) {
257 }// if (myLimitMode) {
259 }//if (myLimit!=TopAbs_SHAPE) {
261 Standard_Integer aNbS;
263 NCollection_List<TopoDS_Shape> aLS;
265 aIt.Initialize(myShape);
266 for (; aIt.More(); aIt.Next()) {
267 const TopoDS_Shape& aS=aIt.Value();
275 #if OCC_VERSION_LARGE < 0x07070000
276 BOPAlgo_Builder::PostTreat();
278 BOPAlgo_Builder::PostTreat(theRange);
281 //=======================================================================
282 //function : TreatCompound
284 //=======================================================================
285 void TreatCompound(const TopoDS_Shape& aC1,
286 NCollection_List<TopoDS_Shape>& aLSX)
288 Standard_Integer aNbC1;
289 TopAbs_ShapeEnum aType;
290 NCollection_List<TopoDS_Shape> aLC, aLC1;
291 NCollection_List<TopoDS_Shape>::Iterator aIt, aIt1;
292 TopoDS_Iterator aItC;
298 for (; aIt.More(); aIt.Next()) {
299 const TopoDS_Shape& aC=aIt.Value(); //C is compound
302 for (; aItC.More(); aItC.Next()) {
303 const TopoDS_Shape& aS=aItC.Value();
304 aType=aS.ShapeType();
305 if (aType==TopAbs_COMPOUND) {
320 aIt.Initialize(aLC1);
321 for (; aIt.More(); aIt.Next()) {
322 const TopoDS_Shape& aSC=aIt.Value();
331 // 1 - The object is just initialized
332 // 2 - PaveFiller is failed
333 // 10 - No shapes to process
334 // 30 - SolidBuilder failed