1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_Builder.cxx
22 // Author: Peter KURNEV
25 #include <GEOMAlgo_Builder.ixx>
27 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Iterator.hxx>
33 #include <BRep_Builder.hxx>
35 #include <TopTools_MapOfShape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <BOP_CorrectTolerances.hxx>
41 #include <NMTTools_DSFiller.hxx>
43 #include <BRepLib.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();
267 NMTTools_DSFiller* pDSF=new NMTTools_DSFiller;
269 pDSF->SetCompositeShape(aCS);
273 PerformInternal(*pDSF);
275 //=======================================================================
276 //function : PerformWithFiller
278 //=======================================================================
279 void GEOMAlgo_Builder::PerformWithFiller(const NMTTools_DSFiller& theDSF)
283 PerformInternal(theDSF);
285 //=======================================================================
286 //function : PerformInternal
288 //=======================================================================
289 void GEOMAlgo_Builder::PerformInternal(const NMTTools_DSFiller& theDSF)
293 Standard_Boolean bIsDone;
296 myDSFiller=(NMTTools_DSFiller *)&theDSF;
298 bIsDone=myDSFiller->IsDone();
300 myErrorStatus=2; // DSFiller is failed
304 // 1. Clear Internal fields
316 FillImagesVertices();
321 BuildResult(TopAbs_VERTEX);
331 BuildResult(TopAbs_EDGE);
336 FillImagesContainers(TopAbs_WIRE);
341 BuildResult(TopAbs_WIRE);
352 BuildResult(TopAbs_FACE);
358 FillImagesContainers(TopAbs_SHELL);
363 BuildResult(TopAbs_SHELL);
373 BuildResult(TopAbs_SOLID);
378 FillImagesContainers(TopAbs_COMPSOLID);
383 BuildResult(TopAbs_COMPSOLID);
388 FillImagesContainers(TopAbs_COMPOUND);
393 BuildResult(TopAbs_COMPOUND);
408 // 1 - The object is just initialized
409 // 2 - DSFiller is failed
410 // 10 - No shapes to process
411 // 30 - SolidBuilder failed