0022972: Eliminate macro definitions that has compiler-provided analogs (WNT and...
[occt.git] / src / BOPDS / BOPDS_PaveBlock.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Bnd_Box.hxx>
17 #include <BOPDS_ListOfPave.hxx>
18 #include <BOPDS_Pave.hxx>
19 #include <BOPDS_PaveBlock.hxx>
20 #include <BOPDS_VectorOfPave.hxx>
21 #include <NCollection_BaseAllocator.hxx>
22 #include <Standard.hxx>
23 #include <Standard_Type.hxx>
24
25 #include <algorithm>
26 #ifdef _MSC_VER
27 #pragma warning ( disable : 4291 )
28 #endif
29
30 //=======================================================================
31 //function : 
32 //purpose  : 
33 //=======================================================================
34   BOPDS_PaveBlock::BOPDS_PaveBlock()
35 :
36   myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
37   myExtPaves(myAllocator)
38 {
39   myEdge=-1;
40   myOriginalEdge=-1;
41   myTS1=-99.;
42   myTS2=myTS1;
43 }
44 //=======================================================================
45 //function : 
46 //purpose  : 
47 //=======================================================================
48   BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
49 :
50   myAllocator(theAllocator),
51   myExtPaves(theAllocator),
52   myMFence(100, theAllocator)
53 {
54   myEdge=-1;
55   myOriginalEdge=-1;
56   myTS1=-99.;
57   myTS2=myTS1;
58 }
59
60 //=======================================================================
61 //function : SetEdge
62 //purpose  : 
63 //=======================================================================
64   void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge)
65 {
66   myEdge=theEdge;
67 }
68 //=======================================================================
69 //function : Edge
70 //purpose  : 
71 //=======================================================================
72   Standard_Integer BOPDS_PaveBlock::Edge()const
73 {
74   return myEdge;
75 }
76 //=======================================================================
77 //function : HasEdge
78 //purpose  : 
79 //=======================================================================
80   Standard_Boolean BOPDS_PaveBlock::HasEdge()const
81 {
82   return (myEdge>=0);
83 }
84 //=======================================================================
85 //function : HasEdge
86 //purpose  : 
87 //=======================================================================
88   Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const
89 {
90   theEdge=myEdge;
91   return (myEdge>=0);
92 }
93
94 //=======================================================================
95 //function : SetOriginalEdge
96 //purpose  : 
97 //=======================================================================
98   void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge)
99 {
100   myOriginalEdge=theEdge;
101 }
102 //=======================================================================
103 //function : OriginalEdge
104 //purpose  : 
105 //=======================================================================
106   Standard_Integer BOPDS_PaveBlock::OriginalEdge()const
107 {
108   return myOriginalEdge;
109 }
110 //=======================================================================
111 //function : IsSplitEdge
112 //purpose  : 
113 //=======================================================================
114   Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const
115 {
116   return (myEdge!=myOriginalEdge);
117 }
118 //=======================================================================
119 //function : SetPave1
120 //purpose  : 
121 //=======================================================================
122   void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave)
123 {
124   myPave1=thePave;
125 }
126 //=======================================================================
127 //function : Pave1
128 //purpose  : 
129 //=======================================================================
130   const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const
131 {
132   return myPave1;
133 }
134 //=======================================================================
135 //function : SetPave2
136 //purpose  : 
137 //=======================================================================
138   void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave)
139 {
140   myPave2=thePave;
141 }
142 //=======================================================================
143 //function : Pave2
144 //purpose  : 
145 //=======================================================================
146   const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const
147 {
148   return myPave2;
149 }
150 //=======================================================================
151 //function : Range
152 //purpose  : 
153 //=======================================================================
154   void BOPDS_PaveBlock::Range(Standard_Real& theT1,
155                               Standard_Real& theT2)const
156 {
157   theT1=myPave1.Parameter();
158   theT2=myPave2.Parameter();
159 }
160 //=======================================================================
161 //function : Indices
162 //purpose  : 
163 //=======================================================================
164   void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1,
165                                 Standard_Integer& theIndex2)const
166 {
167   theIndex1=myPave1.Index();
168   theIndex2=myPave2.Index();
169 }
170 //=======================================================================
171 //function : HasSameBounds
172 //purpose  : 
173 //=======================================================================
174   Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const
175 {
176   Standard_Boolean bFlag1, bFlag2;
177   Standard_Integer n11, n12, n21, n22;
178   //
179   Indices(n11, n12);
180   theOther->Indices(n21, n22);
181   //
182   bFlag1=(n11==n21) && (n12==n22);
183   bFlag2=(n11==n22) && (n12==n21);
184   //
185   return (bFlag1 || bFlag2);
186 }
187
188
189 //
190 // Extras
191 //
192 //=======================================================================
193 //function : AppendExtPave
194 //purpose  : 
195 //=======================================================================
196   void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave)
197 {
198   if (myMFence.Add(thePave.Index())) {
199     myExtPaves.Append(thePave);
200   }
201 }
202 //=======================================================================
203 //function : AppendExtPave1
204 //purpose  : 
205 //=======================================================================
206   void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave)
207 {
208   myExtPaves.Append(thePave);
209 }
210 //=======================================================================
211 //function : ExtPaves
212 //purpose  : 
213 //=======================================================================
214   const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const 
215 {
216   return myExtPaves;
217 }
218 //=======================================================================
219 //function : ChangeExtPaves
220 //purpose  : 
221 //=======================================================================
222   BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves() 
223 {
224   return myExtPaves;
225 }
226 //=======================================================================
227 //function : IsToUpdate
228 //purpose  : 
229 //=======================================================================
230   Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const 
231 {
232   return !myExtPaves.IsEmpty();
233 }
234 //=======================================================================
235 //function : ContainsParameter
236 //purpose  : 
237 //=======================================================================
238   Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT,
239                                                       const Standard_Real theTol,
240                                                       Standard_Integer& theInd) const
241 {
242   Standard_Boolean bRet;
243   BOPDS_ListIteratorOfListOfPave aIt;
244   //
245   bRet = Standard_False;
246   aIt.Initialize(myExtPaves);
247   for (; aIt.More(); aIt.Next()) {
248     const BOPDS_Pave& aPave = aIt.Value();
249     bRet = (Abs(aPave.Parameter() - theT) < theTol);
250     if (bRet) {
251       theInd = aPave.Index();
252       break;
253     }
254   }
255   return bRet;
256 }
257 //=======================================================================
258 //function : Update
259 //purpose  : 
260 //=======================================================================
261   void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
262                                const Standard_Boolean theFlag)
263 {
264   Standard_Integer i, aNb;
265   BOPDS_Pave aPave1, aPave2;
266   Handle(BOPDS_PaveBlock) aPB;
267   BOPDS_ListIteratorOfListOfPave aIt;
268   //
269   aNb=myExtPaves.Extent();
270   if (theFlag) {
271     aNb=aNb+2;
272   }
273   //
274   if (aNb <= 1) {
275     myExtPaves.Clear();
276     myMFence.Clear();
277     return;
278   }
279   //
280   BOPDS_VectorOfPave pPaves(1, aNb);
281   //
282   i=1;
283   if (theFlag) {
284     pPaves(i) = myPave1; 
285     ++i;
286     pPaves(i) = myPave2; 
287     ++i;
288   }
289   //
290   aIt.Initialize(myExtPaves);
291   for (; aIt.More(); aIt.Next()) {
292     const BOPDS_Pave& aPave=aIt.Value();
293     pPaves(i) = aPave;
294     ++i;
295   }
296   myExtPaves.Clear();
297   myMFence.Clear();
298   //
299   std::sort(pPaves.begin(), pPaves.end());
300   //
301   for (i = 1; i <= aNb; ++i) {
302     const BOPDS_Pave& aPave = pPaves(i);
303     if (i == 1) {
304       aPave1 = aPave;
305       continue;
306     }
307     //
308     aPave2 = aPave;
309     aPB = new BOPDS_PaveBlock;
310     aPB->SetOriginalEdge(myOriginalEdge);
311     aPB->SetPave1(aPave1);
312     aPB->SetPave2(aPave2);
313     //
314     theLPB.Append(aPB);
315     //
316     aPave1 = aPave2;
317   }
318 }
319 // ShrunkData
320 //=======================================================================
321 //function : HasShrunkData
322 //purpose  : 
323 //=======================================================================
324   Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
325 {
326   return (!myShrunkBox.IsVoid());
327 }
328 //=======================================================================
329 //function : SetShrunkData
330 //purpose  : 
331 //=======================================================================
332   void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
333                                       const Standard_Real theT2,
334                                       const Bnd_Box& theBox)
335 {
336   myTS1=theT1;
337   myTS2=theT2;
338   myShrunkBox=theBox;
339 }
340 //=======================================================================
341 //function : ShrunkData
342 //purpose  : 
343 //=======================================================================
344   void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
345                                    Standard_Real& theT2,
346                                    Bnd_Box& theBox)const
347 {
348   theT1=myTS1;
349   theT2=myTS2;
350   theBox=myShrunkBox;
351 }
352 //=======================================================================
353 //function : Dump
354 //purpose  : 
355 //=======================================================================
356   void BOPDS_PaveBlock::Dump()const
357 {
358   printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge);
359   printf(" Pave1:");
360   myPave1.Dump();
361   printf(" Pave2:");
362   myPave2.Dump();
363   printf(" }");
364 }