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 #include <GEOMAlgo_Splitter.hxx>
25 #include <TopAbs_ShapeEnum.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Compound.hxx>
29 #include <TopoDS_Iterator.hxx>
31 #include <BRep_Builder.hxx>
34 void TreatCompound(const TopoDS_Shape& aC,
35 NCollection_List<TopoDS_Shape>& aLSX);
37 //=======================================================================
40 //=======================================================================
41 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
45 myMapTools(100, myAllocator)
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_Splitter::GEOMAlgo_Splitter
55 (const Handle(NCollection_BaseAllocator)& theAllocator)
57 BOPAlgo_Builder(theAllocator),
59 myMapTools(100, myAllocator)
64 //=======================================================================
67 //=======================================================================
68 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
71 //=======================================================================
74 //=======================================================================
75 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
77 if (myMapTools.Add(theShape)) {
78 myTools.Append(theShape);
80 AddArgument(theShape);
83 //=======================================================================
86 //=======================================================================
87 const NCollection_List<TopoDS_Shape>& GEOMAlgo_Splitter::Tools()const
91 //=======================================================================
94 //=======================================================================
95 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
99 //=======================================================================
102 //=======================================================================
103 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
107 //=======================================================================
108 //function : SetLimitMode
110 //=======================================================================
111 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
115 //=======================================================================
116 //function : LimitMode
118 //=======================================================================
119 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
123 //=======================================================================
126 //=======================================================================
127 void GEOMAlgo_Splitter::Clear()
131 myLimit=TopAbs_SHAPE;
132 BOPAlgo_Builder::Clear();
134 //=======================================================================
135 //function : BuildResult
137 //=======================================================================
138 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
140 TopAbs_ShapeEnum aType;
142 NCollection_Map<TopoDS_Shape> aM;
143 NCollection_List<TopoDS_Shape>::Iterator aIt, aItIm;
145 aIt.Initialize(myArguments);
146 for (; aIt.More(); aIt.Next()) {
147 const TopoDS_Shape& aS=aIt.Value();
148 aType=aS.ShapeType();
149 if (aType==theType && !myMapTools.Contains(aS)) {
150 if (myImages.IsBound(aS)) {
151 const NCollection_List<TopoDS_Shape>& aLSIm=myImages.Find(aS);
152 aItIm.Initialize(aLSIm);
153 for (; aItIm.More(); aItIm.Next()) {
154 const TopoDS_Shape& aSIm=aItIm.Value();
156 aBB.Add(myShape, aSIm);
162 aBB.Add(myShape, aS);
168 //=======================================================================
169 //function : PostTreat
171 //=======================================================================
172 void GEOMAlgo_Splitter::PostTreat()
174 if (myLimit!=TopAbs_SHAPE) {
175 Standard_Integer i, aNbS;
178 TopTools_IndexedMapOfShape aMx;
180 aBB.MakeCompound(aC);
182 TopExp::MapShapes(myShape, myLimit, aMx);
184 for (i=1; i<=aNbS; ++i) {
185 const TopoDS_Shape& aS=aMx(i);
189 Standard_Integer iType, iLimit, iTypeX;
190 TopAbs_ShapeEnum aType, aTypeX;
191 NCollection_List<TopoDS_Shape> aLSP, aLSX;
192 NCollection_List<TopoDS_Shape>::Iterator aIt, aItX, aItIm;
193 NCollection_Map<TopoDS_Shape> aM;
195 iLimit=(Standard_Integer)myLimit;
197 // 1. Collect the shapes to process aLSP
198 aIt.Initialize(myArguments);
199 for (; aIt.More(); aIt.Next()) {
200 const TopoDS_Shape& aS=aIt.Value();
201 if (myMapTools.Contains(aS)) {
205 aType=aS.ShapeType();
206 iType=(Standard_Integer)aType;
212 else if (aType==TopAbs_COMPOUND) {
215 TreatCompound(aS, aLSX);
217 aItX.Initialize(aLSX);
218 for (; aItX.More(); aItX.Next()) {
219 const TopoDS_Shape& aSX=aItX.Value();
220 aTypeX=aSX.ShapeType();
221 iTypeX=(Standard_Integer)aTypeX;
228 }// for (; aIt.More(); aIt.Next()) {
231 TopExp::MapShapes(aC, aMx);
233 aIt.Initialize(aLSP);
234 for (; aIt.More(); aIt.Next()) {
235 const TopoDS_Shape& aS=aIt.Value();
236 if (myImages.IsBound(aS)) {
237 const NCollection_List<TopoDS_Shape>& aLSIm=myImages.Find(aS);
238 aItIm.Initialize(aLSIm);
239 for (; aItIm.More(); aItIm.Next()) {
240 const TopoDS_Shape& aSIm=aItIm.Value();
242 if (!aMx.Contains(aSIm)) {
250 if (!aMx.Contains(aS)) {
256 }// if (myLimitMode) {
258 }//if (myLimit!=TopAbs_SHAPE) {
260 Standard_Integer aNbS;
262 NCollection_List<TopoDS_Shape> aLS;
264 aIt.Initialize(myShape);
265 for (; aIt.More(); aIt.Next()) {
266 const TopoDS_Shape& aS=aIt.Value();
274 BOPAlgo_Builder::PostTreat();
276 //=======================================================================
277 //function : TreatCompound
279 //=======================================================================
280 void TreatCompound(const TopoDS_Shape& aC1,
281 NCollection_List<TopoDS_Shape>& aLSX)
283 Standard_Integer aNbC1;
284 TopAbs_ShapeEnum aType;
285 NCollection_List<TopoDS_Shape> aLC, aLC1;
286 NCollection_List<TopoDS_Shape>::Iterator aIt, aIt1;
287 TopoDS_Iterator aItC;
293 for (; aIt.More(); aIt.Next()) {
294 const TopoDS_Shape& aC=aIt.Value(); //C is compound
297 for (; aItC.More(); aItC.Next()) {
298 const TopoDS_Shape& aS=aItC.Value();
299 aType=aS.ShapeType();
300 if (aType==TopAbs_COMPOUND) {
315 aIt.Initialize(aLC1);
316 for (; aIt.More(); aIt.Next()) {
317 const TopoDS_Shape& aSC=aIt.Value();
326 // 1 - The object is just initialized
327 // 2 - PaveFiller is failed
328 // 10 - No shapes to process
329 // 30 - SolidBuilder failed