]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMAlgo/GEOMAlgo_Splitter.cxx
Salome HOME
IPAL21297: errors for Netgen_1D_2D
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Splitter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:        GEOMAlgo_Splitter.cxx
23 // Created:     
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <GEOMAlgo_Splitter.ixx>
28
29 #include <TopAbs_ShapeEnum.hxx>
30
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopoDS_Iterator.hxx>
34
35 #include <TopExp.hxx>
36
37 #include <BRep_Builder.hxx>
38 #include <BRepLib.hxx>
39
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44
45 #include <BOP_CorrectTolerances.hxx>
46
47
48 static 
49   void TreatCompound(const TopoDS_Shape& aC, 
50                      TopTools_ListOfShape& aLSX);
51
52 //=======================================================================
53 //function : 
54 //purpose  : 
55 //=======================================================================
56   GEOMAlgo_Splitter::GEOMAlgo_Splitter()
57 :
58   GEOMAlgo_Builder()
59 {
60   myLimit=TopAbs_SHAPE;
61   myLimitMode=0;
62 }
63 //=======================================================================
64 //function : ~
65 //purpose  : 
66 //=======================================================================
67   GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
68 {
69 }
70 //=======================================================================
71 //function : AddToolCompound
72 //purpose  : 
73 //=======================================================================
74   void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
75 {
76   TopoDS_Iterator aIt;
77   //
78   aIt.Initialize(theShape);
79   for (; aIt.More(); aIt.Next()) {
80     const TopoDS_Shape& aS=aIt.Value();
81     AddTool(aS);
82   }
83 }
84 //=======================================================================
85 //function : AddTool
86 //purpose  : 
87 //=======================================================================
88   void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
89 {
90   if (myMapTools.Add(theShape)) {
91     myTools.Append(theShape);
92     //
93     AddShape(theShape);
94   }
95 }
96 //=======================================================================
97 //function : Tools
98 //purpose  : 
99 //=======================================================================
100   const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const
101 {
102   return myTools;
103 }
104 //=======================================================================
105 //function : SetLimit
106 //purpose  : 
107 //=======================================================================
108   void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit) 
109 {
110   myLimit=aLimit;
111 }
112 //=======================================================================
113 //function : Limit
114 //purpose  : 
115 //=======================================================================
116   TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
117 {
118   return myLimit;
119 }
120 //=======================================================================
121 //function : SetLimitMode
122 //purpose  : 
123 //=======================================================================
124   void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
125 {
126   myLimitMode=aMode;
127 }
128 //=======================================================================
129 //function : LimitMode
130 //purpose  : 
131 //=======================================================================
132   Standard_Integer GEOMAlgo_Splitter::LimitMode()const
133 {
134   return myLimitMode;
135 }
136 //=======================================================================
137 //function : Clear
138 //purpose  : 
139 //=======================================================================
140   void GEOMAlgo_Splitter::Clear()
141 {
142   myTools.Clear();
143   myMapTools.Clear();
144   myLimit=TopAbs_SHAPE;
145   GEOMAlgo_Builder::Clear();
146 }
147 //=======================================================================
148 //function : BuildResult
149 //purpose  : 
150 //=======================================================================
151   void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
152 {
153   myErrorStatus=0;
154   //
155   TopAbs_ShapeEnum aType;
156   BRep_Builder aBB;
157   TopTools_MapOfShape aM;
158   TopTools_ListIteratorOfListOfShape aIt, aItIm;
159   //
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();
170           if (aM.Add(aSIm)) {
171             aBB.Add(myShape, aSIm);
172           }
173         }
174       }
175       else {
176         if (aM.Add(aS)) {
177           aBB.Add(myShape, aS);
178         }
179       }
180     }
181   }
182 }
183 //=======================================================================
184 //function : PostTreat
185 //purpose  : 
186 //=======================================================================
187   void GEOMAlgo_Splitter::PostTreat()
188 {
189   if (myLimit!=TopAbs_SHAPE) {
190     Standard_Integer i, aNbS;
191     BRep_Builder aBB;
192     TopoDS_Compound aC;
193     TopTools_IndexedMapOfShape aMx;
194     //
195     aBB.MakeCompound(aC);
196     //
197     TopExp::MapShapes(myShape, myLimit, aMx);
198     aNbS=aMx.Extent();
199     for (i=1; i<=aNbS; ++i) {
200       const TopoDS_Shape& aS=aMx(i);
201       aBB.Add(aC, aS);
202     }
203     //modified by NIZNHY-PKV Thu Feb 15 17:09:32 2007f
204     if (myLimitMode) {
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;
210       //
211       iLimit=(Standard_Integer)myLimit; 
212       //
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)) {
218           continue;
219         }
220         //
221         aType=aS.ShapeType();
222         iType=(Standard_Integer)aType;
223         //
224         if (iType>iLimit) {
225           aLSP.Append(aS);
226         }
227         //
228         else if (aType==TopAbs_COMPOUND) {
229           aLSX.Clear();
230           //
231           TreatCompound(aS, aLSX);
232           //
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;
238             //
239             if (iTypeX>iLimit) {
240               aLSP.Append(aSX);
241             }
242           }
243         }
244       }// for (; aIt.More(); aIt.Next()) {
245       //
246       // 2. Add them to aC
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();
255             if (aM.Add(aSIm)) {
256               aBB.Add(aC, aSIm);
257             }
258           }
259         }
260         else {
261           if (aM.Add(aS)) {
262             aBB.Add(aC, aS);
263           }
264         }
265       }
266     }// if (myLimitMode) {
267     //modified by NIZNHY-PKV Thu Feb 15 17:09:34 2007t
268     myShape=aC;
269   }//if (myLimit!=TopAbs_SHAPE) {
270   //
271   GEOMAlgo_Builder::PostTreat();
272 }
273 //=======================================================================
274 //function : TreatCompound
275 //purpose  : 
276 //=======================================================================
277 void TreatCompound(const TopoDS_Shape& aC1, 
278                    TopTools_ListOfShape& aLSX)
279 {
280   Standard_Integer aNbC1;
281   TopAbs_ShapeEnum aType;
282   TopTools_ListOfShape aLC, aLC1;
283   TopTools_ListIteratorOfListOfShape aIt, aIt1;
284   TopoDS_Iterator aItC;
285   //
286   aLC.Append (aC1);
287   while(1) {
288     aLC1.Clear();
289     aIt.Initialize(aLC);
290     for (; aIt.More(); aIt.Next()) {
291       const TopoDS_Shape& aC=aIt.Value(); //C is compound
292       //
293       aItC.Initialize(aC);
294       for (; aItC.More(); aItC.Next()) {
295         const TopoDS_Shape& aS=aItC.Value();
296         aType=aS.ShapeType();
297         if (aType==TopAbs_COMPOUND) {
298           aLC1.Append(aS);
299         }
300         else {
301           aLSX.Append(aS);
302         }
303       }
304     }
305     //
306     aNbC1=aLC1.Extent();
307     if (!aNbC1) {
308       break;
309     }
310     //
311     aLC.Clear();
312     aIt.Initialize(aLC1);
313     for (; aIt.More(); aIt.Next()) {
314       const TopoDS_Shape& aSC=aIt.Value();
315       aLC.Append(aSC);
316     }
317   }// while(1)
318 }
319 //
320 // myErrorStatus
321 // 
322 // 0  - Ok
323 // 1  - The object is just initialized
324 // 2  - PaveFiller is failed
325 // 10 - No shapes to process
326 // 30 - SolidBuilder failed