Salome HOME
Merging with WPdev
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Splitter.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_Splitter.cxx
21 // Created:     
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25 #include <GEOMAlgo_Splitter.ixx>
26
27 #include <TopAbs_ShapeEnum.hxx>
28
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Iterator.hxx>
32
33 #include <TopExp.hxx>
34
35 #include <BRep_Builder.hxx>
36 #include <BRepLib.hxx>
37
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42
43 #include <BOP_CorrectTolerances.hxx>
44
45 #include <NMTTools_DSFiller.hxx>
46
47 //=======================================================================
48 //function : 
49 //purpose  : 
50 //=======================================================================
51   GEOMAlgo_Splitter::GEOMAlgo_Splitter()
52 :
53   GEOMAlgo_Builder()
54 {
55   myLimit=TopAbs_SHAPE;
56 }
57 //=======================================================================
58 //function : ~
59 //purpose  : 
60 //=======================================================================
61   GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
62 {
63 }
64 //=======================================================================
65 //function : AddToolCompound
66 //purpose  : 
67 //=======================================================================
68   void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
69 {
70   TopoDS_Iterator aIt;
71   //
72   aIt.Initialize(theShape);
73   for (; aIt.More(); aIt.Next()) {
74     const TopoDS_Shape& aS=aIt.Value();
75     AddTool(aS);
76   }
77 }
78 //=======================================================================
79 //function : AddTool
80 //purpose  : 
81 //=======================================================================
82   void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
83 {
84   if (myMapTools.Add(theShape)) {
85     myTools.Append(theShape);
86     //
87     AddShape(theShape);
88   }
89 }
90 //=======================================================================
91 //function : Tools
92 //purpose  : 
93 //=======================================================================
94   const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const
95 {
96   return myTools;
97 }
98 //=======================================================================
99 //function : SetLimit
100 //purpose  : 
101 //=======================================================================
102   void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit) 
103 {
104   myLimit=aLimit;
105 }
106 //=======================================================================
107 //function : Limit
108 //purpose  : 
109 //=======================================================================
110   TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
111 {
112   return myLimit;
113 }
114 //=======================================================================
115 //function : Clear
116 //purpose  : 
117 //=======================================================================
118   void GEOMAlgo_Splitter::Clear()
119 {
120   myTools.Clear();
121   myMapTools.Clear();
122   myLimit=TopAbs_SHAPE;
123   GEOMAlgo_Builder::Clear();
124 }
125 //=======================================================================
126 //function : BuildResult
127 //purpose  : 
128 //=======================================================================
129   void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
130 {
131   myErrorStatus=0;
132   //
133   TopAbs_ShapeEnum aType;
134   BRep_Builder aBB;
135   TopTools_MapOfShape aM;
136   TopTools_ListIteratorOfListOfShape aIt, aItIm;
137   //
138   aIt.Initialize(myShapes);
139   for (; aIt.More(); aIt.Next()) {
140     const TopoDS_Shape& aS=aIt.Value();
141     aType=aS.ShapeType();
142     if (aType==theType && !myMapTools.Contains(aS)) {
143       if (myImages.HasImage(aS)) {
144         const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
145         aItIm.Initialize(aLSIm);
146         for (; aItIm.More(); aItIm.Next()) {
147           const TopoDS_Shape& aSIm=aItIm.Value();
148           if (aM.Add(aSIm)) {
149             aBB.Add(myShape, aSIm);
150           }
151         }
152       }
153       else {
154         if (aM.Add(aS)) {
155           aBB.Add(myShape, aS);
156         }
157       }
158     }
159   }
160 }
161 //=======================================================================
162 //function : PostTreat
163 //purpose  : 
164 //=======================================================================
165   void GEOMAlgo_Splitter::PostTreat()
166 {
167   if (myLimit!=TopAbs_SHAPE) {
168     Standard_Integer i, aNbS;
169     BRep_Builder aBB;
170     TopoDS_Compound aC;
171     TopTools_IndexedMapOfShape aM;
172     //
173     aBB.MakeCompound(aC);
174     //
175     TopExp::MapShapes(myShape, myLimit, aM);
176     aNbS=aM.Extent();
177     for (i=1; i<=aNbS; ++i) {
178       const TopoDS_Shape& aS=aM(i);
179       aBB.Add(aC, aS);
180     }
181     myShape=aC;
182   }
183   //
184   GEOMAlgo_Builder::PostTreat();
185   //
186 }
187 //
188 // myErrorStatus
189 // 
190 // 0  - Ok
191 // 1  - The object is just initialized
192 // 2  - DSFiller is failed
193 // 10 - No shapes to process
194 // 30 - SolidBuilder failed