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
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_Splitter.ixx>
29 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopoDS_Iterator.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepLib.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <BOP_CorrectTolerances.hxx>
49 void TreatCompound(const TopoDS_Shape& aC,
50 TopTools_ListOfShape& aLSX);
52 //=======================================================================
55 //=======================================================================
56 GEOMAlgo_Splitter::GEOMAlgo_Splitter()
63 //=======================================================================
66 //=======================================================================
67 GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
70 //=======================================================================
71 //function : AddToolCompound
73 //=======================================================================
74 void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
78 aIt.Initialize(theShape);
79 for (; aIt.More(); aIt.Next()) {
80 const TopoDS_Shape& aS=aIt.Value();
84 //=======================================================================
87 //=======================================================================
88 void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
90 if (myMapTools.Add(theShape)) {
91 myTools.Append(theShape);
96 //=======================================================================
99 //=======================================================================
100 const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const
104 //=======================================================================
105 //function : SetLimit
107 //=======================================================================
108 void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
112 //=======================================================================
115 //=======================================================================
116 TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
120 //=======================================================================
121 //function : SetLimitMode
123 //=======================================================================
124 void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
128 //=======================================================================
129 //function : LimitMode
131 //=======================================================================
132 Standard_Integer GEOMAlgo_Splitter::LimitMode()const
136 //=======================================================================
139 //=======================================================================
140 void GEOMAlgo_Splitter::Clear()
144 myLimit=TopAbs_SHAPE;
145 GEOMAlgo_Builder::Clear();
147 //=======================================================================
148 //function : BuildResult
150 //=======================================================================
151 void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
155 TopAbs_ShapeEnum aType;
157 TopTools_MapOfShape aM;
158 TopTools_ListIteratorOfListOfShape aIt, aItIm;
160 aIt.Initialize(myShapes);
161 for (; aIt.More(); aIt.Next()) {
162 const TopoDS_Shape& aS=aIt.Value();
163 aType=aS.ShapeType();
164 if (aType==theType && !myMapTools.Contains(aS)) {
165 if (myImages.HasImage(aS)) {
166 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
167 aItIm.Initialize(aLSIm);
168 for (; aItIm.More(); aItIm.Next()) {
169 const TopoDS_Shape& aSIm=aItIm.Value();
171 aBB.Add(myShape, aSIm);
177 aBB.Add(myShape, aS);
183 //=======================================================================
184 //function : PostTreat
186 //=======================================================================
187 void GEOMAlgo_Splitter::PostTreat()
189 if (myLimit!=TopAbs_SHAPE) {
190 Standard_Integer i, aNbS;
193 TopTools_IndexedMapOfShape aMx;
195 aBB.MakeCompound(aC);
197 TopExp::MapShapes(myShape, myLimit, aMx);
199 for (i=1; i<=aNbS; ++i) {
200 const TopoDS_Shape& aS=aMx(i);
203 //modified by NIZNHY-PKV Thu Feb 15 17:09:32 2007f
205 Standard_Integer iType, iLimit, iTypeX;
206 TopAbs_ShapeEnum aType, aTypeX;
207 TopTools_ListOfShape aLSP, aLSX;
208 TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
209 TopTools_MapOfShape aM;
211 iLimit=(Standard_Integer)myLimit;
213 // 1. Collect the shapes to process aLSP
214 aIt.Initialize(myShapes);
215 for (; aIt.More(); aIt.Next()) {
216 const TopoDS_Shape& aS=aIt.Value();
217 if (myMapTools.Contains(aS)) {
221 aType=aS.ShapeType();
222 iType=(Standard_Integer)aType;
228 else if (aType==TopAbs_COMPOUND) {
231 TreatCompound(aS, aLSX);
233 aItX.Initialize(aLSX);
234 for (; aItX.More(); aItX.Next()) {
235 const TopoDS_Shape& aSX=aItX.Value();
236 aTypeX=aSX.ShapeType();
237 iTypeX=(Standard_Integer)aTypeX;
244 }// for (; aIt.More(); aIt.Next()) {
247 aIt.Initialize(aLSP);
248 for (; aIt.More(); aIt.Next()) {
249 const TopoDS_Shape& aS=aIt.Value();
250 if (myImages.HasImage(aS)) {
251 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
252 aItIm.Initialize(aLSIm);
253 for (; aItIm.More(); aItIm.Next()) {
254 const TopoDS_Shape& aSIm=aItIm.Value();
266 }// if (myLimitMode) {
267 //modified by NIZNHY-PKV Thu Feb 15 17:09:34 2007t
269 }//if (myLimit!=TopAbs_SHAPE) {
271 GEOMAlgo_Builder::PostTreat();
273 //=======================================================================
274 //function : TreatCompound
276 //=======================================================================
277 void TreatCompound(const TopoDS_Shape& aC1,
278 TopTools_ListOfShape& aLSX)
280 Standard_Integer aNbC1;
281 TopAbs_ShapeEnum aType;
282 TopTools_ListOfShape aLC, aLC1;
283 TopTools_ListIteratorOfListOfShape aIt, aIt1;
284 TopoDS_Iterator aItC;
290 for (; aIt.More(); aIt.Next()) {
291 const TopoDS_Shape& aC=aIt.Value(); //C is compound
294 for (; aItC.More(); aItC.Next()) {
295 const TopoDS_Shape& aS=aItC.Value();
296 aType=aS.ShapeType();
297 if (aType==TopAbs_COMPOUND) {
312 aIt.Initialize(aLC1);
313 for (; aIt.More(); aIt.Next()) {
314 const TopoDS_Shape& aSC=aIt.Value();
323 // 1 - The object is just initialized
324 // 2 - PaveFiller is failed
325 // 10 - No shapes to process
326 // 30 - SolidBuilder failed