Salome HOME
Bug 0020233: Infinite loop in boolean operation with a sphere with r=0
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:        NMTTools_PaveFiller.cxx
23 // Created:     Fri Dec  5 14:58:54 2003
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <NMTTools_PaveFiller.ixx>
28 //
29 #include <BOPTColStd_Failure.hxx>
30 #include <NMTDS_ShapesDataStructure.hxx>
31 #include <NMTTools_DEProcessor.hxx>
32 #include <NMTDS_Iterator.hxx>
33 #include <NMTDS_InterfPool.hxx>
34
35 //=======================================================================
36 // function: NMTTools_PaveFiller::NMTTools_PaveFiller
37 // purpose: 
38 //=======================================================================
39   NMTTools_PaveFiller::NMTTools_PaveFiller()
40 {
41   myDS=NULL;
42   myDSIt=NULL;
43   myIsDone=Standard_False;
44   myNbSources=0;
45   myNbEdges=0;
46   myIP=NULL;
47 }
48 //=======================================================================
49 // function: ~
50 // purpose: 
51 //=======================================================================
52   NMTTools_PaveFiller::~NMTTools_PaveFiller()
53 {
54   Clear();
55 }
56 //=======================================================================
57 // function: Clear
58 // purpose: 
59 //=======================================================================
60   void NMTTools_PaveFiller::Clear()
61 {
62   if (myDSIt) {
63     delete myDSIt;
64   } 
65   if (myDS) {
66     delete myDS;
67   }
68   myDSIt=NULL;
69   myDS=NULL;
70   
71   if (myIP) {
72     delete myIP;
73   }
74   myIP=NULL;
75 }
76 //=======================================================================
77 // function: SetCompositeShape
78 // purpose: 
79 //=======================================================================
80   void NMTTools_PaveFiller::SetCompositeShape(const TopoDS_Shape& aS)
81 {
82   myCompositeShape=aS;
83 }
84 //=======================================================================
85 // function: CompositeShape
86 // purpose: 
87 //=======================================================================
88   const TopoDS_Shape& NMTTools_PaveFiller::CompositeShape()const
89 {
90   return myCompositeShape;
91 }
92 //=======================================================================
93 // function:  DS
94 // purpose: 
95 //=======================================================================
96   NMTDS_PShapesDataStructure NMTTools_PaveFiller::DS()
97 {
98   return myDS;
99 }
100 //=======================================================================
101 // function: DSIt
102 // purpose: 
103 //=======================================================================
104   NMTDS_PIterator NMTTools_PaveFiller::DSIt()
105 {
106   return myDSIt;
107 }
108 //=======================================================================
109 // function:  IP
110 // purpose: 
111 //=======================================================================
112   NMTDS_PInterfPool NMTTools_PaveFiller::IP()
113 {
114   return myIP;
115 }
116 //=======================================================================
117 // function:IsDone
118 // purpose: 
119 //=======================================================================
120   Standard_Boolean NMTTools_PaveFiller::IsDone() const
121 {
122   return myIsDone;
123 }
124 //=======================================================================
125 // function: Context
126 // purpose: 
127 //=======================================================================
128   const IntTools_Context& NMTTools_PaveFiller::Context() const
129 {
130   return myContext;
131 }
132 //=======================================================================
133 // function: ChangeContext
134 // purpose: 
135 //=======================================================================
136   IntTools_Context& NMTTools_PaveFiller::ChangeContext() 
137 {
138   return myContext;
139 }
140 //=======================================================================
141 // function: PavePool
142 // purpose: 
143 //=======================================================================
144   const BOPTools_PavePool& NMTTools_PaveFiller::PavePool() const
145 {
146   return myPavePool;
147 }
148 //=======================================================================
149 // function: ChangePavePool
150 // purpose: 
151 //=======================================================================
152   BOPTools_PavePool& NMTTools_PaveFiller::ChangePavePool()
153 {
154   return myPavePool;
155 }
156 //=======================================================================
157 // function:  CommonBlockPool
158 // purpose: 
159 //=======================================================================
160   const NMTTools_CommonBlockPool& NMTTools_PaveFiller::CommonBlockPool() const
161 {
162   return myCommonBlockPool;
163 }
164 //=======================================================================
165 // function:  ChangeCommonBlockPool
166 // purpose: 
167 //=======================================================================
168   NMTTools_CommonBlockPool& NMTTools_PaveFiller::ChangeCommonBlockPool()
169 {
170   return myCommonBlockPool;
171 }
172 //=======================================================================
173 // function:  SplitShapesPool
174 // purpose: 
175 //=======================================================================
176   const BOPTools_SplitShapesPool& NMTTools_PaveFiller::SplitShapesPool() const
177 {
178   return mySplitShapesPool;
179 }
180 //=======================================================================
181 // function:  ChangeSplitShapesPool
182 // purpose: 
183 //=======================================================================
184   BOPTools_SplitShapesPool& NMTTools_PaveFiller::ChangeSplitShapesPool()
185 {
186   return mySplitShapesPool;
187 }
188 //=======================================================================
189 // function: Init
190 // purpose: 
191 //=======================================================================
192   void NMTTools_PaveFiller::Init()
193 {
194   myIsDone=Standard_False;
195   if (myCompositeShape.IsNull()) {
196     return;
197   }
198   //
199   Clear();
200   // 1.
201   myDS=new NMTDS_ShapesDataStructure;
202   myDS->SetCompositeShape(myCompositeShape);
203   myDS->Init();
204   //
205   // 2.
206   myDSIt=new NMTDS_Iterator;
207   myDSIt->SetDS(myDS);
208   myDSIt->Prepare();
209   //
210   // 3.
211   myNbSources=myDS->NumberOfShapesOfTheObject()+
212               myDS->NumberOfShapesOfTheTool();
213   myNbEdges=myDS->NbEdges();
214   //
215   // 4
216   myIP=new NMTDS_InterfPool;
217 }
218
219 //=======================================================================
220 // function: Perform
221 // purpose: 
222 //=======================================================================
223   void NMTTools_PaveFiller::Perform()
224 {
225   myIsDone=Standard_False;
226   //
227   //----------------
228   try {
229     // 0.
230     // Modified Thu Sep 14 14:35:18 2006 
231     // Contribution of Samtech www.samcef.com BEGIN
232     Init();
233     // Contribution of Samtech www.samcef.com END
234     //1.VV
235     //
236     PerformVV();
237     //
238     // 2.VE
239     myPavePool.Resize (myNbEdges);
240     
241     PrepareEdges();
242
243     PerformVE();
244     //
245     // 3.VF
246     PerformVF();
247     //
248     // 4.EE
249     myCommonBlockPool.Resize (myNbEdges);
250     mySplitShapesPool.Resize (myNbEdges);
251     myPavePoolNew    .Resize (myNbEdges);
252
253     PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
254     PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
255     //
256     PerformEE();
257     //
258     RefinePavePool ();
259     //
260     myPavePoolNew.Destroy();
261     myPavePoolNew.Resize (myNbEdges);
262     //
263     // 5.EF
264     PreparePaveBlocks(TopAbs_EDGE, TopAbs_FACE);
265     PerformEF();
266     //
267     RefinePavePool();
268     //
269     myPavePoolNew.Destroy();
270     
271     MakeSplitEdges();
272
273     UpdateCommonBlocks();
274     //
275     // 6. FF
276     PerformFF ();
277     //
278     MakeBlocks();
279     //
280     MakePCurves();
281     //
282     // 7.Postprocessing 
283     UpdatePaveBlocks();
284     //
285     NMTTools_DEProcessor aDEP(*this);
286     aDEP.Do();
287     //
288     // Modified to treat Alone Vertices Thu Sep 14 14:35:18 2006 
289     // Contribution of Samtech www.samcef.com BEGIN
290     MakeAloneVertices();
291     // Contribution of Samtech www.samcef.com END
292     //
293     myIsDone=Standard_True;
294   }
295   catch (BOPTColStd_Failure& ) {
296   }
297 }