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_Builder.cxx
25 // Author: Peter KURNEV
27 #include <GEOMAlgo_Builder.ixx>
29 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopoDS_Iterator.hxx>
35 #include <BRep_Builder.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <BOP_CorrectTolerances.hxx>
43 #include <BRepLib.hxx>
44 #include <NMTTools_PaveFiller.hxx>
46 //=======================================================================
49 //=======================================================================
50 GEOMAlgo_Builder::GEOMAlgo_Builder()
52 GEOMAlgo_BuilderShape()
56 myEntryPoint=0; // Entry point through PerformWithFiller ()
58 //=======================================================================
61 //=======================================================================
62 GEOMAlgo_Builder::~GEOMAlgo_Builder()
64 if (myEntryPoint==1) {
71 //=======================================================================
72 //function : AddCompound
74 //=======================================================================
75 void GEOMAlgo_Builder::AddCompound(const TopoDS_Shape& theShape)
79 aIt.Initialize(theShape);
80 for (; aIt.More(); aIt.Next()) {
81 const TopoDS_Shape& aS=aIt.Value();
85 //=======================================================================
88 //=======================================================================
89 void GEOMAlgo_Builder::AddShape(const TopoDS_Shape& theShape)
91 if (myMapFence.Add(theShape)) {
92 myShapes.Append(theShape);
95 //=======================================================================
98 //=======================================================================
99 const TopTools_ListOfShape& GEOMAlgo_Builder::Shapes()const
103 //=======================================================================
106 //=======================================================================
107 void GEOMAlgo_Builder::Clear()
112 //=======================================================================
113 //function : ClearInternals
115 //=======================================================================
116 void GEOMAlgo_Builder::ClearInternals()
120 for (i=0; i<myNbTypes; ++i){
121 myShapes1[i].Clear();
126 mySplitFaces.Clear();
127 mySameDomainShapes.Clear();
128 myDraftSolids.Clear();
131 //=======================================================================
134 //=======================================================================
135 void GEOMAlgo_Builder::Prepare()
139 Standard_Integer aNb;
142 TopTools_ListIteratorOfListOfShape aIt;
144 aNb=myShapes.Extent();
146 myErrorStatus=10; // No shapes to process
150 // 1. myShape is empty compound
151 aBB.MakeCompound(aC);
155 aIt.Initialize(myShapes);
156 for (; aIt.More(); aIt.Next()) {
157 const TopoDS_Shape& aS=aIt.Value();
161 //=======================================================================
162 //function : PostTreat
164 //=======================================================================
165 void GEOMAlgo_Builder::PostTreat()
167 Standard_Integer aNbS;
169 TopTools_ListOfShape aLS;
171 aIt.Initialize(myShape);
172 for (; aIt.More(); aIt.Next()) {
173 const TopoDS_Shape& aS=aIt.Value();
181 BRepLib::SameParameter(myShape, 1.e-7, Standard_True);
183 //=======================================================================
184 //function : AddShape1
186 //=======================================================================
187 void GEOMAlgo_Builder::AddShape1(const TopoDS_Shape& theShape)
189 Standard_Integer iType;
190 TopAbs_ShapeEnum aType;
192 TopTools_MapOfShape aM;
194 aType=theShape.ShapeType();
195 if (aType==TopAbs_COMPOUND) {
196 aIt.Initialize(theShape);
197 for (; aIt.More(); aIt.Next()) {
198 const TopoDS_Shape& aS=aIt.Value();
203 iType=(Standard_Integer)aType;
204 if (aM.Add(theShape)) {
205 myShapes1[iType].Append(theShape);
208 //=======================================================================
209 //function : BuildResult
211 //=======================================================================
212 void GEOMAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
216 TopAbs_ShapeEnum aType;
218 TopTools_MapOfShape aM;
219 TopTools_ListIteratorOfListOfShape aIt, aItIm;
221 aIt.Initialize(myShapes);
222 for (; aIt.More(); aIt.Next()) {
223 const TopoDS_Shape& aS=aIt.Value();
224 aType=aS.ShapeType();
225 if (aType==theType) {
226 if (myImages.HasImage(aS)){
227 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
228 aItIm.Initialize(aLSIm);
229 for (; aItIm.More(); aItIm.Next()) {
230 const TopoDS_Shape& aSIm=aItIm.Value();
232 aBB.Add(myShape, aSIm);
238 aBB.Add(myShape, aS);
244 //=======================================================================
247 //=======================================================================
248 void GEOMAlgo_Builder::Perform()
254 TopTools_ListIteratorOfListOfShape aIt;
256 aBB.MakeCompound(aCS);
258 aIt.Initialize(myShapes);
259 for (; aIt.More(); aIt.Next()) {
260 const TopoDS_Shape& aS=aIt.Value();
264 NMTTools_PaveFiller* pPF=new NMTTools_PaveFiller;
266 pPF->SetCompositeShape(aCS);
270 PerformInternal(*pPF);
272 //=======================================================================
273 //function : PerformWithFiller
275 //=======================================================================
276 void GEOMAlgo_Builder::PerformWithFiller(const NMTTools_PaveFiller& theDSF)
280 PerformInternal(theDSF);
282 //=======================================================================
283 //function : PerformInternal
285 //=======================================================================
286 void GEOMAlgo_Builder::PerformInternal(const NMTTools_PaveFiller& pPF)
290 Standard_Boolean bIsDone;
293 myPaveFiller=(NMTTools_PaveFiller *)&pPF;
295 bIsDone=myPaveFiller->IsDone();
297 myErrorStatus=2; // PaveFiller is failed
301 // 1. Clear Internal fields
313 FillImagesVertices();
318 BuildResult(TopAbs_VERTEX);
328 BuildResult(TopAbs_EDGE);
333 FillImagesContainers(TopAbs_WIRE);
338 BuildResult(TopAbs_WIRE);
349 BuildResult(TopAbs_FACE);
355 FillImagesContainers(TopAbs_SHELL);
360 BuildResult(TopAbs_SHELL);
370 BuildResult(TopAbs_SOLID);
375 FillImagesContainers(TopAbs_COMPSOLID);
380 BuildResult(TopAbs_COMPSOLID);
385 FillImagesContainers(TopAbs_COMPOUND);
390 BuildResult(TopAbs_COMPOUND);
405 // 1 - The object is just initialized
406 // 2 - PaveFiller is failed
407 // 10 - No shapes to process
408 // 30 - SolidBuilder failed