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_Builder.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Builder.ixx>
28 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_Iterator.hxx>
34 #include <BRep_Builder.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <BOP_CorrectTolerances.hxx>
42 #include <BRepLib.hxx>
43 #include <NMTTools_PaveFiller.hxx>
45 //=======================================================================
48 //=======================================================================
49 GEOMAlgo_Builder::GEOMAlgo_Builder()
51 GEOMAlgo_BuilderShape()
55 myEntryPoint=0; // Entry point through PerformWithFiller ()
57 //=======================================================================
60 //=======================================================================
61 GEOMAlgo_Builder::~GEOMAlgo_Builder()
63 if (myEntryPoint==1) {
70 //=======================================================================
71 //function : AddCompound
73 //=======================================================================
74 void GEOMAlgo_Builder::AddCompound(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_Builder::AddShape(const TopoDS_Shape& theShape)
90 if (myMapFence.Add(theShape)) {
91 myShapes.Append(theShape);
94 //=======================================================================
97 //=======================================================================
98 const TopTools_ListOfShape& GEOMAlgo_Builder::Shapes()const
102 //=======================================================================
105 //=======================================================================
106 void GEOMAlgo_Builder::Clear()
111 //=======================================================================
112 //function : ClearInternals
114 //=======================================================================
115 void GEOMAlgo_Builder::ClearInternals()
119 for (i=0; i<myNbTypes; ++i){
120 myShapes1[i].Clear();
125 mySplitFaces.Clear();
126 mySameDomainShapes.Clear();
127 myDraftSolids.Clear();
130 //=======================================================================
133 //=======================================================================
134 void GEOMAlgo_Builder::Prepare()
138 Standard_Integer aNb;
141 TopTools_ListIteratorOfListOfShape aIt;
143 aNb=myShapes.Extent();
145 myErrorStatus=10; // No shapes to process
149 // 1. myShape is empty compound
150 aBB.MakeCompound(aC);
154 aIt.Initialize(myShapes);
155 for (; aIt.More(); aIt.Next()) {
156 const TopoDS_Shape& aS=aIt.Value();
160 //=======================================================================
161 //function : PostTreat
163 //=======================================================================
164 void GEOMAlgo_Builder::PostTreat()
166 Standard_Integer aNbS;
168 TopTools_ListOfShape aLS;
170 aIt.Initialize(myShape);
171 for (; aIt.More(); aIt.Next()) {
172 const TopoDS_Shape& aS=aIt.Value();
180 BRepLib::SameParameter(myShape, 1.e-7, Standard_True);
182 //=======================================================================
183 //function : AddShape1
185 //=======================================================================
186 void GEOMAlgo_Builder::AddShape1(const TopoDS_Shape& theShape)
188 Standard_Integer iType;
189 TopAbs_ShapeEnum aType;
191 TopTools_MapOfShape aM;
193 aType=theShape.ShapeType();
194 if (aType==TopAbs_COMPOUND) {
195 aIt.Initialize(theShape);
196 for (; aIt.More(); aIt.Next()) {
197 const TopoDS_Shape& aS=aIt.Value();
202 iType=(Standard_Integer)aType;
203 if (aM.Add(theShape)) {
204 myShapes1[iType].Append(theShape);
207 //=======================================================================
208 //function : BuildResult
210 //=======================================================================
211 void GEOMAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
215 TopAbs_ShapeEnum aType;
217 TopTools_MapOfShape aM;
218 TopTools_ListIteratorOfListOfShape aIt, aItIm;
220 aIt.Initialize(myShapes);
221 for (; aIt.More(); aIt.Next()) {
222 const TopoDS_Shape& aS=aIt.Value();
223 aType=aS.ShapeType();
224 if (aType==theType) {
225 if (myImages.HasImage(aS)){
226 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
227 aItIm.Initialize(aLSIm);
228 for (; aItIm.More(); aItIm.Next()) {
229 const TopoDS_Shape& aSIm=aItIm.Value();
231 aBB.Add(myShape, aSIm);
237 aBB.Add(myShape, aS);
243 //=======================================================================
246 //=======================================================================
247 void GEOMAlgo_Builder::Perform()
253 TopTools_ListIteratorOfListOfShape aIt;
255 aBB.MakeCompound(aCS);
257 aIt.Initialize(myShapes);
258 for (; aIt.More(); aIt.Next()) {
259 const TopoDS_Shape& aS=aIt.Value();
263 NMTTools_PaveFiller* pPF=new NMTTools_PaveFiller;
265 pPF->SetCompositeShape(aCS);
269 PerformInternal(*pPF);
271 //=======================================================================
272 //function : PerformWithFiller
274 //=======================================================================
275 void GEOMAlgo_Builder::PerformWithFiller(const NMTTools_PaveFiller& theDSF)
279 PerformInternal(theDSF);
281 //=======================================================================
282 //function : PerformInternal
284 //=======================================================================
285 void GEOMAlgo_Builder::PerformInternal(const NMTTools_PaveFiller& pPF)
289 Standard_Boolean bIsDone;
292 myPaveFiller=(NMTTools_PaveFiller *)&pPF;
294 bIsDone=myPaveFiller->IsDone();
296 myErrorStatus=2; // PaveFiller is failed
300 // 1. Clear Internal fields
312 FillImagesVertices();
317 BuildResult(TopAbs_VERTEX);
327 BuildResult(TopAbs_EDGE);
332 FillImagesContainers(TopAbs_WIRE);
337 BuildResult(TopAbs_WIRE);
348 BuildResult(TopAbs_FACE);
354 FillImagesContainers(TopAbs_SHELL);
359 BuildResult(TopAbs_SHELL);
369 BuildResult(TopAbs_SOLID);
374 FillImagesContainers(TopAbs_COMPSOLID);
379 BuildResult(TopAbs_COMPSOLID);
384 FillImagesContainers(TopAbs_COMPOUND);
389 BuildResult(TopAbs_COMPOUND);
404 // 1 - The object is just initialized
405 // 2 - PaveFiller is failed
406 // 10 - No shapes to process
407 // 30 - SolidBuilder failed