1 // Copyright (C) 2007-2010 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.
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 // Author: Peter KURNEV
26 #include <GEOMAlgo_Splitter.ixx>
28 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_Iterator.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepLib.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <BOP_CorrectTolerances.hxx>
48 void TreatCompound(const TopoDS_Shape& aC,
49 TopTools_ListOfShape& aLSX);
51 //=======================================================================
54 //=======================================================================
55 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
62 //=======================================================================
65 //=======================================================================
66 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
69 //=======================================================================
70 //function : AddToolCompound
72 //=======================================================================
73 void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
77 aIt.Initialize(theShape);
78 for (; aIt.More(); aIt.Next()) {
79 const TopoDS_Shape& aS=aIt.Value();
83 //=======================================================================
86 //=======================================================================
87 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
89 if (myMapTools.Add(theShape)) {
90 myTools.Append(theShape);
95 //=======================================================================
98 //=======================================================================
99 const TopTools_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 GEOMAlgo_Builder::Clear();
146 //=======================================================================
147 //function : BuildResult
149 //=======================================================================
150 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
154 TopAbs_ShapeEnum aType;
156 TopTools_MapOfShape aM;
157 TopTools_ListIteratorOfListOfShape aIt, aItIm;
159 aIt.Initialize(myShapes);
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.HasImage(aS)) {
165 const TopTools_ListOfShape& aLSIm=myImages.Image(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 TopTools_IndexedMapOfShape aMx;
194 aBB.MakeCompound(aC);
196 TopExp::MapShapes(myShape, myLimit, aMx);
198 for (i=1; i<=aNbS; ++i) {
199 const TopoDS_Shape& aS=aMx(i);
204 Standard_Integer iType, iLimit, iTypeX;
205 TopAbs_ShapeEnum aType, aTypeX;
206 TopTools_ListOfShape aLSP, aLSX;
207 TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
208 TopTools_MapOfShape aM;
210 iLimit=(Standard_Integer)myLimit;
212 // 1. Collect the shapes to process aLSP
213 aIt.Initialize(myShapes);
214 for (; aIt.More(); aIt.Next()) {
215 const TopoDS_Shape& aS=aIt.Value();
216 if (myMapTools.Contains(aS)) {
220 aType=aS.ShapeType();
221 iType=(Standard_Integer)aType;
227 else if (aType==TopAbs_COMPOUND) {
230 TreatCompound(aS, aLSX);
232 aItX.Initialize(aLSX);
233 for (; aItX.More(); aItX.Next()) {
234 const TopoDS_Shape& aSX=aItX.Value();
235 aTypeX=aSX.ShapeType();
236 iTypeX=(Standard_Integer)aTypeX;
243 }// for (; aIt.More(); aIt.Next()) {
245 //modified by NIZNHY-PKV Fri Oct 30 11:07:08 2009 f
247 TopExp::MapShapes(aC, aMx);
248 //modified by NIZNHY-PKV Fri Oct 30 11:12:30 2009t
251 aIt.Initialize(aLSP);
252 for (; aIt.More(); aIt.Next()) {
253 const TopoDS_Shape& aS=aIt.Value();
254 if (myImages.HasImage(aS)) {
255 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
256 aItIm.Initialize(aLSIm);
257 for (; aItIm.More(); aItIm.Next()) {
258 const TopoDS_Shape& aSIm=aItIm.Value();
260 //modified by NIZNHY-PKV Fri Oct 30 11:09:57 2009f
261 if (!aMx.Contains(aSIm)) {
265 //modified by NIZNHY-PKV Fri Oct 30 11:10:02 2009
271 //modified by NIZNHY-PKV Fri Oct 30 11:10:46 2009f
272 if (!aMx.Contains(aS)) {
276 //modified by NIZNHY-PKV Fri Oct 30 11:11:00 2009t
280 }// if (myLimitMode) {
282 }//if (myLimit!=TopAbs_SHAPE) {
284 GEOMAlgo_Builder::PostTreat();
286 //=======================================================================
287 //function : TreatCompound
289 //=======================================================================
290 void TreatCompound(const TopoDS_Shape& aC1,
291 TopTools_ListOfShape& aLSX)
293 Standard_Integer aNbC1;
294 TopAbs_ShapeEnum aType;
295 TopTools_ListOfShape aLC, aLC1;
296 TopTools_ListIteratorOfListOfShape aIt, aIt1;
297 TopoDS_Iterator aItC;
303 for (; aIt.More(); aIt.Next()) {
304 const TopoDS_Shape& aC=aIt.Value(); //C is compound
307 for (; aItC.More(); aItC.Next()) {
308 const TopoDS_Shape& aS=aItC.Value();
309 aType=aS.ShapeType();
310 if (aType==TopAbs_COMPOUND) {
325 aIt.Initialize(aLC1);
326 for (; aIt.More(); aIt.Next()) {
327 const TopoDS_Shape& aSC=aIt.Value();
336 // 1 - The object is just initialized
337 // 2 - PaveFiller is failed
338 // 10 - No shapes to process
339 // 30 - SolidBuilder failed