1 // Copyright (C) 2007-2008 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
22 // File: GEOMAlgo_Splitter.cxx
23 // 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);
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()) {
244 //modified by NIZNHY-PKV Fri Oct 30 11:07:08 2009 f
246 TopExp::MapShapes(aC, aMx);
247 //modified by NIZNHY-PKV Fri Oct 30 11:12:30 2009t
250 aIt.Initialize(aLSP);
251 for (; aIt.More(); aIt.Next()) {
252 const TopoDS_Shape& aS=aIt.Value();
253 if (myImages.HasImage(aS)) {
254 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
255 aItIm.Initialize(aLSIm);
256 for (; aItIm.More(); aItIm.Next()) {
257 const TopoDS_Shape& aSIm=aItIm.Value();
259 //modified by NIZNHY-PKV Fri Oct 30 11:09:57 2009f
260 if (!aMx.Contains(aSIm)) {
264 //modified by NIZNHY-PKV Fri Oct 30 11:10:02 2009
270 //modified by NIZNHY-PKV Fri Oct 30 11:10:46 2009f
271 if (!aMx.Contains(aS)) {
275 //modified by NIZNHY-PKV Fri Oct 30 11:11:00 2009t
279 }// if (myLimitMode) {
281 }//if (myLimit!=TopAbs_SHAPE) {
283 GEOMAlgo_Builder::PostTreat();
285 //=======================================================================
286 //function : TreatCompound
288 //=======================================================================
289 void TreatCompound(const TopoDS_Shape& aC1,
290 TopTools_ListOfShape& aLSX)
292 Standard_Integer aNbC1;
293 TopAbs_ShapeEnum aType;
294 TopTools_ListOfShape aLC, aLC1;
295 TopTools_ListIteratorOfListOfShape aIt, aIt1;
296 TopoDS_Iterator aItC;
302 for (; aIt.More(); aIt.Next()) {
303 const TopoDS_Shape& aC=aIt.Value(); //C is compound
306 for (; aItC.More(); aItC.Next()) {
307 const TopoDS_Shape& aS=aItC.Value();
308 aType=aS.ShapeType();
309 if (aType==TopAbs_COMPOUND) {
324 aIt.Initialize(aLC1);
325 for (; aIt.More(); aIt.Next()) {
326 const TopoDS_Shape& aSC=aIt.Value();
335 // 1 - The object is just initialized
336 // 2 - PaveFiller is failed
337 // 10 - No shapes to process
338 // 30 - SolidBuilder failed