1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_Splitter.cxx
22 // Author: Peter KURNEV
25 #include <GEOMAlgo_Splitter.ixx>
27 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Iterator.hxx>
35 #include <BRep_Builder.hxx>
36 #include <BRepLib.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <BOP_CorrectTolerances.hxx>
47 void TreatCompound(const TopoDS_Shape& aC,
48 TopTools_ListOfShape& aLSX);
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
68 //=======================================================================
69 //function : AddToolCompound
71 //=======================================================================
72 void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
76 aIt.Initialize(theShape);
77 for (; aIt.More(); aIt.Next()) {
78 const TopoDS_Shape& aS=aIt.Value();
82 //=======================================================================
85 //=======================================================================
86 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
88 if (myMapTools.Add(theShape)) {
89 myTools.Append(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 GEOMAlgo_Builder::Clear();
145 //=======================================================================
146 //function : BuildResult
148 //=======================================================================
149 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
153 TopAbs_ShapeEnum aType;
155 TopTools_MapOfShape aM;
156 TopTools_ListIteratorOfListOfShape aIt, aItIm;
158 aIt.Initialize(myShapes);
159 for (; aIt.More(); aIt.Next()) {
160 const TopoDS_Shape& aS=aIt.Value();
161 aType=aS.ShapeType();
162 if (aType==theType && !myMapTools.Contains(aS)) {
163 if (myImages.HasImage(aS)) {
164 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
165 aItIm.Initialize(aLSIm);
166 for (; aItIm.More(); aItIm.Next()) {
167 const TopoDS_Shape& aSIm=aItIm.Value();
169 aBB.Add(myShape, aSIm);
175 aBB.Add(myShape, aS);
181 //=======================================================================
182 //function : PostTreat
184 //=======================================================================
185 void GEOMAlgo_Splitter::PostTreat()
187 if (myLimit!=TopAbs_SHAPE) {
188 Standard_Integer i, aNbS;
191 TopTools_IndexedMapOfShape aMx;
193 aBB.MakeCompound(aC);
195 TopExp::MapShapes(myShape, myLimit, aMx);
197 for (i=1; i<=aNbS; ++i) {
198 const TopoDS_Shape& aS=aMx(i);
201 //modified by NIZNHY-PKV Thu Feb 15 17:09:32 2007f
203 Standard_Integer iType, iLimit, iTypeX;
204 TopAbs_ShapeEnum aType, aTypeX;
205 TopTools_ListOfShape aLSP, aLSX;
206 TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
207 TopTools_MapOfShape aM;
209 iLimit=(Standard_Integer)myLimit;
211 // 1. Collect the shapes to process aLSP
212 aIt.Initialize(myShapes);
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 aIt.Initialize(aLSP);
246 for (; aIt.More(); aIt.Next()) {
247 const TopoDS_Shape& aS=aIt.Value();
248 if (myImages.HasImage(aS)) {
249 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
250 aItIm.Initialize(aLSIm);
251 for (; aItIm.More(); aItIm.Next()) {
252 const TopoDS_Shape& aSIm=aItIm.Value();
264 }// if (myLimitMode) {
265 //modified by NIZNHY-PKV Thu Feb 15 17:09:34 2007t
267 }//if (myLimit!=TopAbs_SHAPE) {
269 GEOMAlgo_Builder::PostTreat();
271 //=======================================================================
272 //function : TreatCompound
274 //=======================================================================
275 void TreatCompound(const TopoDS_Shape& aC1,
276 TopTools_ListOfShape& aLSX)
278 Standard_Integer aNbC1;
279 TopAbs_ShapeEnum aType;
280 TopTools_ListOfShape aLC, aLC1;
281 TopTools_ListIteratorOfListOfShape aIt, aIt1;
282 TopoDS_Iterator aItC;
288 for (; aIt.More(); aIt.Next()) {
289 const TopoDS_Shape& aC=aIt.Value(); //C is compound
292 for (; aItC.More(); aItC.Next()) {
293 const TopoDS_Shape& aS=aItC.Value();
294 aType=aS.ShapeType();
295 if (aType==TopAbs_COMPOUND) {
310 aIt.Initialize(aLC1);
311 for (; aIt.More(); aIt.Next()) {
312 const TopoDS_Shape& aSC=aIt.Value();
321 // 1 - The object is just initialized
322 // 2 - PaveFiller is failed
323 // 10 - No shapes to process
324 // 30 - SolidBuilder failed