1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 #include <BOPDS_PaveBlock.ixx>
21 #include <BOPDS_ListOfPave.hxx>
22 #include <Standard.hxx>
23 #include <NCollection_BaseAllocator.hxx>
27 #pragma warning ( disable : 4291 )
31 void SortShell(const int n, BOPDS_Pave *a);
33 //=======================================================================
36 //=======================================================================
37 BOPDS_PaveBlock::BOPDS_PaveBlock()
39 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
40 myExtPaves(myAllocator)
47 //=======================================================================
50 //=======================================================================
51 BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
53 myAllocator(theAllocator),
54 myExtPaves(theAllocator),
55 myMFence(100, theAllocator)
63 //=======================================================================
66 //=======================================================================
67 void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge)
71 //=======================================================================
74 //=======================================================================
75 Standard_Integer BOPDS_PaveBlock::Edge()const
79 //=======================================================================
82 //=======================================================================
83 Standard_Boolean BOPDS_PaveBlock::HasEdge()const
87 //=======================================================================
90 //=======================================================================
91 Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const
97 //=======================================================================
98 //function : SetOriginalEdge
100 //=======================================================================
101 void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge)
103 myOriginalEdge=theEdge;
105 //=======================================================================
106 //function : OriginalEdge
108 //=======================================================================
109 Standard_Integer BOPDS_PaveBlock::OriginalEdge()const
111 return myOriginalEdge;
113 //=======================================================================
114 //function : IsSplitEdge
116 //=======================================================================
117 Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const
119 return (myEdge!=myOriginalEdge);
121 //=======================================================================
122 //function : SetPave1
124 //=======================================================================
125 void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave)
129 //=======================================================================
132 //=======================================================================
133 const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const
137 //=======================================================================
138 //function : SetPave2
140 //=======================================================================
141 void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave)
145 //=======================================================================
148 //=======================================================================
149 const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const
153 //=======================================================================
156 //=======================================================================
157 void BOPDS_PaveBlock::Range(Standard_Real& theT1,
158 Standard_Real& theT2)const
160 theT1=myPave1.Parameter();
161 theT2=myPave2.Parameter();
163 //=======================================================================
166 //=======================================================================
167 void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1,
168 Standard_Integer& theIndex2)const
170 theIndex1=myPave1.Index();
171 theIndex2=myPave2.Index();
173 //=======================================================================
174 //function : HasSameBounds
176 //=======================================================================
177 Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const
179 Standard_Boolean bFlag1, bFlag2;
180 Standard_Integer n11, n12, n21, n22;
183 theOther->Indices(n21, n22);
185 bFlag1=(n11==n21) && (n12==n22);
186 bFlag2=(n11==n22) && (n12==n21);
188 return (bFlag1 || bFlag2);
195 //=======================================================================
196 //function : AppendExtPave
198 //=======================================================================
199 void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave)
201 if (myMFence.Add(thePave.Index())) {
202 myExtPaves.Append(thePave);
205 //=======================================================================
206 //function : AppendExtPave1
208 //=======================================================================
209 void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave)
211 myExtPaves.Append(thePave);
213 //=======================================================================
214 //function : ExtPaves
216 //=======================================================================
217 const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const
221 //=======================================================================
222 //function : ChangeExtPaves
224 //=======================================================================
225 BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves()
229 //=======================================================================
230 //function : IsToUpdate
232 //=======================================================================
233 Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const
235 return !myExtPaves.IsEmpty();
237 //=======================================================================
238 //function : ContainsParameter
240 //=======================================================================
241 Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT,
242 const Standard_Real theTol)const
244 Standard_Boolean bRet;
246 BOPDS_ListIteratorOfListOfPave aIt;
249 aIt.Initialize(myExtPaves);
250 for (; aIt.More(); aIt.Next()) {
251 dT=aIt.Value().Parameter()-theT;
262 //=======================================================================
265 //=======================================================================
266 void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
267 const Standard_Boolean theFlag)
269 Standard_Integer i, aNb;
271 BOPDS_Pave aPave1, aPave2;
272 Handle(BOPDS_PaveBlock) aPB;
273 BOPDS_ListIteratorOfListOfPave aIt;
275 aNb=myExtPaves.Extent();
280 pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave));
281 for (i=0; i<aNb; ++i) {
282 new (pPaves+i) BOPDS_Pave();
293 aIt.Initialize(myExtPaves);
294 for (; aIt.More(); aIt.Next()) {
295 const BOPDS_Pave& aPave=aIt.Value();
302 SortShell(aNb, pPaves);
304 for (i=0; i<aNb; ++i) {
305 const BOPDS_Pave& aPave=pPaves[i];
312 aPB=new BOPDS_PaveBlock;
313 aPB->SetOriginalEdge(myOriginalEdge);
314 aPB->SetPave1(aPave1);
315 aPB->SetPave2(aPave2);
322 for (i=0; i<aNb; ++i) {
323 pPaves[i].~BOPDS_Pave();
325 myAllocator->Free((Standard_Address&)pPaves);
328 //=======================================================================
329 // function: SortShell
331 //=======================================================================
332 void SortShell(const int n, BOPDS_Pave *a)
334 int nd, i, j, l, d=1;
345 for (i=0; i<nd; ++i) {
354 if (j > -1) goto m30;
356 }//for (i=0; i<nd; ++i)
362 //=======================================================================
363 //function : SetCommonBlock
365 //=======================================================================
366 void BOPDS_PaveBlock::SetCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
370 //=======================================================================
371 //function : CommonBlock
373 //=======================================================================
374 const Handle(BOPDS_CommonBlock)& BOPDS_PaveBlock::CommonBlock()const
376 return myCommonBlock;
378 //=======================================================================
379 //function : IsCommonBlock
381 //=======================================================================
382 Standard_Boolean BOPDS_PaveBlock::IsCommonBlock()const
384 return (!myCommonBlock.IsNull());
386 //=======================================================================
387 //function : IsCommonBlockOnEdge
389 //=======================================================================
390 Standard_Boolean BOPDS_PaveBlock::IsCommonBlockOnEdge()const
392 if (!myCommonBlock.IsNull()) {
393 return (myCommonBlock->PaveBlocks().Extent()>1);
395 return Standard_False;
397 //=======================================================================
398 //function : RealPaveBlock
400 //=======================================================================
401 Handle(BOPDS_PaveBlock) BOPDS_PaveBlock::RealPaveBlock()const
403 if (IsCommonBlock()) {
404 const Handle(BOPDS_PaveBlock)& aPB1=myCommonBlock->PaveBlock1();
410 //=======================================================================
411 //function : HasShrunkData
413 //=======================================================================
414 Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
416 return (!myShrunkBox.IsVoid());
418 //=======================================================================
419 //function : SetShrunkData
421 //=======================================================================
422 void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
423 const Standard_Real theT2,
424 const Bnd_Box& theBox)
430 //=======================================================================
431 //function : ShrunkData
433 //=======================================================================
434 void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
435 Standard_Real& theT2,
436 Bnd_Box& theBox)const
442 //=======================================================================
445 //=======================================================================
446 void BOPDS_PaveBlock::Dump()const
448 printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge);