1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPDS_PaveBlock.ixx>
16 #include <BOPDS_ListOfPave.hxx>
17 #include <Standard.hxx>
18 #include <NCollection_BaseAllocator.hxx>
22 #pragma warning ( disable : 4291 )
26 void SortShell(const int n, BOPDS_Pave *a);
28 //=======================================================================
31 //=======================================================================
32 BOPDS_PaveBlock::BOPDS_PaveBlock()
34 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
35 myExtPaves(myAllocator)
42 //=======================================================================
45 //=======================================================================
46 BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
48 myAllocator(theAllocator),
49 myExtPaves(theAllocator),
50 myMFence(100, theAllocator)
58 //=======================================================================
61 //=======================================================================
62 void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge)
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer BOPDS_PaveBlock::Edge()const
74 //=======================================================================
77 //=======================================================================
78 Standard_Boolean BOPDS_PaveBlock::HasEdge()const
82 //=======================================================================
85 //=======================================================================
86 Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const
92 //=======================================================================
93 //function : SetOriginalEdge
95 //=======================================================================
96 void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge)
98 myOriginalEdge=theEdge;
100 //=======================================================================
101 //function : OriginalEdge
103 //=======================================================================
104 Standard_Integer BOPDS_PaveBlock::OriginalEdge()const
106 return myOriginalEdge;
108 //=======================================================================
109 //function : IsSplitEdge
111 //=======================================================================
112 Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const
114 return (myEdge!=myOriginalEdge);
116 //=======================================================================
117 //function : SetPave1
119 //=======================================================================
120 void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave)
124 //=======================================================================
127 //=======================================================================
128 const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const
132 //=======================================================================
133 //function : SetPave2
135 //=======================================================================
136 void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave)
140 //=======================================================================
143 //=======================================================================
144 const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const
148 //=======================================================================
151 //=======================================================================
152 void BOPDS_PaveBlock::Range(Standard_Real& theT1,
153 Standard_Real& theT2)const
155 theT1=myPave1.Parameter();
156 theT2=myPave2.Parameter();
158 //=======================================================================
161 //=======================================================================
162 void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1,
163 Standard_Integer& theIndex2)const
165 theIndex1=myPave1.Index();
166 theIndex2=myPave2.Index();
168 //=======================================================================
169 //function : HasSameBounds
171 //=======================================================================
172 Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const
174 Standard_Boolean bFlag1, bFlag2;
175 Standard_Integer n11, n12, n21, n22;
178 theOther->Indices(n21, n22);
180 bFlag1=(n11==n21) && (n12==n22);
181 bFlag2=(n11==n22) && (n12==n21);
183 return (bFlag1 || bFlag2);
190 //=======================================================================
191 //function : AppendExtPave
193 //=======================================================================
194 void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave)
196 if (myMFence.Add(thePave.Index())) {
197 myExtPaves.Append(thePave);
200 //=======================================================================
201 //function : AppendExtPave1
203 //=======================================================================
204 void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave)
206 myExtPaves.Append(thePave);
208 //=======================================================================
209 //function : ExtPaves
211 //=======================================================================
212 const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const
216 //=======================================================================
217 //function : ChangeExtPaves
219 //=======================================================================
220 BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves()
224 //=======================================================================
225 //function : IsToUpdate
227 //=======================================================================
228 Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const
230 return !myExtPaves.IsEmpty();
232 //=======================================================================
233 //function : ContainsParameter
235 //=======================================================================
236 Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT,
237 const Standard_Real theTol)const
239 Standard_Boolean bRet;
241 BOPDS_ListIteratorOfListOfPave aIt;
244 aIt.Initialize(myExtPaves);
245 for (; aIt.More(); aIt.Next()) {
246 dT=aIt.Value().Parameter()-theT;
257 //=======================================================================
260 //=======================================================================
261 void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
262 const Standard_Boolean theFlag)
264 Standard_Integer i, aNb;
266 BOPDS_Pave aPave1, aPave2;
267 Handle(BOPDS_PaveBlock) aPB;
268 BOPDS_ListIteratorOfListOfPave aIt;
270 aNb=myExtPaves.Extent();
275 pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave));
276 for (i=0; i<aNb; ++i) {
277 new (pPaves+i) BOPDS_Pave();
288 aIt.Initialize(myExtPaves);
289 for (; aIt.More(); aIt.Next()) {
290 const BOPDS_Pave& aPave=aIt.Value();
297 SortShell(aNb, pPaves);
299 for (i=0; i<aNb; ++i) {
300 const BOPDS_Pave& aPave=pPaves[i];
307 aPB=new BOPDS_PaveBlock;
308 aPB->SetOriginalEdge(myOriginalEdge);
309 aPB->SetPave1(aPave1);
310 aPB->SetPave2(aPave2);
317 for (i=0; i<aNb; ++i) {
318 pPaves[i].~BOPDS_Pave();
320 myAllocator->Free((Standard_Address&)pPaves);
323 //=======================================================================
324 // function: SortShell
326 //=======================================================================
327 void SortShell(const int n, BOPDS_Pave *a)
329 int nd, i, j, l, d=1;
340 for (i=0; i<nd; ++i) {
349 if (j > -1) goto m30;
351 }//for (i=0; i<nd; ++i)
356 //=======================================================================
357 //function : HasShrunkData
359 //=======================================================================
360 Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
362 return (!myShrunkBox.IsVoid());
364 //=======================================================================
365 //function : SetShrunkData
367 //=======================================================================
368 void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
369 const Standard_Real theT2,
370 const Bnd_Box& theBox)
376 //=======================================================================
377 //function : ShrunkData
379 //=======================================================================
380 void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
381 Standard_Real& theT2,
382 Bnd_Box& theBox)const
388 //=======================================================================
391 //=======================================================================
392 void BOPDS_PaveBlock::Dump()const
394 printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge);