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
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>
44 #include <GEOMAlgo_Tools.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();
162 //=======================================================================
163 //function : AddShape1
165 //=======================================================================
166 void GEOMAlgo_Builder::AddShape1(const TopoDS_Shape& theShape)
168 Standard_Integer iType;
169 TopAbs_ShapeEnum aType;
171 TopTools_MapOfShape aM;
173 aType=theShape.ShapeType();
174 if (aType==TopAbs_COMPOUND) {
175 aIt.Initialize(theShape);
176 for (; aIt.More(); aIt.Next()) {
177 const TopoDS_Shape& aS=aIt.Value();
182 iType=(Standard_Integer)aType;
183 if (aM.Add(theShape)) {
184 myShapes1[iType].Append(theShape);
187 //=======================================================================
188 //function : BuildResult
190 //=======================================================================
191 void GEOMAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
195 TopAbs_ShapeEnum aType;
197 TopTools_MapOfShape aM;
198 TopTools_ListIteratorOfListOfShape aIt, aItIm;
200 aIt.Initialize(myShapes);
201 for (; aIt.More(); aIt.Next()) {
202 const TopoDS_Shape& aS=aIt.Value();
203 aType=aS.ShapeType();
204 if (aType==theType) {
205 if (myImages.HasImage(aS)){
206 const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
207 aItIm.Initialize(aLSIm);
208 for (; aItIm.More(); aItIm.Next()) {
209 const TopoDS_Shape& aSIm=aItIm.Value();
211 aBB.Add(myShape, aSIm);
217 aBB.Add(myShape, aS);
223 //=======================================================================
226 //=======================================================================
227 void GEOMAlgo_Builder::Perform()
233 TopTools_ListIteratorOfListOfShape aIt;
235 aBB.MakeCompound(aCS);
237 aIt.Initialize(myShapes);
238 for (; aIt.More(); aIt.Next()) {
239 const TopoDS_Shape& aS=aIt.Value();
243 NMTTools_PaveFiller* pPF=new NMTTools_PaveFiller;
245 pPF->SetCompositeShape(aCS);
249 PerformInternal(*pPF);
251 //=======================================================================
252 //function : PerformWithFiller
254 //=======================================================================
255 void GEOMAlgo_Builder::PerformWithFiller(const NMTTools_PaveFiller& theDSF)
259 PerformInternal(theDSF);
261 //=======================================================================
262 //function : PerformInternal
264 //=======================================================================
265 void GEOMAlgo_Builder::PerformInternal(const NMTTools_PaveFiller& pPF)
269 Standard_Boolean bIsDone;
272 myPaveFiller=(NMTTools_PaveFiller *)&pPF;
274 bIsDone=myPaveFiller->IsDone();
276 myErrorStatus=2; // PaveFiller is failed
280 // 1. Clear Internal fields
292 FillImagesVertices();
297 BuildResult(TopAbs_VERTEX);
307 BuildResult(TopAbs_EDGE);
312 FillImagesContainers(TopAbs_WIRE);
317 BuildResult(TopAbs_WIRE);
328 BuildResult(TopAbs_FACE);
334 FillImagesContainers(TopAbs_SHELL);
339 BuildResult(TopAbs_SHELL);
349 BuildResult(TopAbs_SOLID);
354 FillImagesContainers(TopAbs_COMPSOLID);
359 BuildResult(TopAbs_COMPSOLID);
364 FillImagesContainers(TopAbs_COMPOUND);
369 BuildResult(TopAbs_COMPOUND);
382 void CorrectWires(const TopoDS_Shape& aS);
384 //=======================================================================
385 //function : PostTreat
387 //=======================================================================
388 void GEOMAlgo_Builder::PostTreat()
390 Standard_Integer aNbS;
392 TopTools_ListOfShape aLS;
394 aIt.Initialize(myShape);
395 for (; aIt.More(); aIt.Next()) {
396 const TopoDS_Shape& aS=aIt.Value();
404 BRepLib::SameParameter(myShape, 1.e-7, Standard_True);
406 GEOMAlgo_Tools::CorrectWires(myShape);
412 // 1 - The object is just initialized
413 // 2 - PaveFiller is failed
414 // 10 - No shapes to process
415 // 30 - SolidBuilder failed