0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BOPDS / BOPDS_PaveBlock.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
4e57c75e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
4e57c75e 5//
d5f74e42 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
973c2be1 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.
4e57c75e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
4e57c75e 14
42cf5bc1 15
16#include <Bnd_Box.hxx>
4e57c75e 17#include <BOPDS_ListOfPave.hxx>
42cf5bc1 18#include <BOPDS_Pave.hxx>
19#include <BOPDS_PaveBlock.hxx>
7a76337e 20#include <BOPDS_VectorOfPave.hxx>
4e57c75e 21#include <NCollection_BaseAllocator.hxx>
42cf5bc1 22#include <Standard.hxx>
23#include <Standard_Type.hxx>
4e57c75e 24
7a76337e 25#include <algorithm>
4e57c75e 26#ifdef WNT
27#pragma warning ( disable : 4291 )
28#endif
29
4e57c75e 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)const
240{
241 Standard_Boolean bRet;
242 Standard_Real dT;
243 BOPDS_ListIteratorOfListOfPave aIt;
244 //
245 bRet=Standard_False;
246 aIt.Initialize(myExtPaves);
247 for (; aIt.More(); aIt.Next()) {
248 dT=aIt.Value().Parameter()-theT;
249 if (dT<0.) {
250 dT=-dT;
251 }
252 if (dT<theTol) {
253 bRet=!bRet;
254 break;
255 }
256 }
257 return bRet;
258}
259//=======================================================================
260//function : Update
261//purpose :
262//=======================================================================
263 void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
264 const Standard_Boolean theFlag)
265{
266 Standard_Integer i, aNb;
4e57c75e 267 BOPDS_Pave aPave1, aPave2;
268 Handle(BOPDS_PaveBlock) aPB;
269 BOPDS_ListIteratorOfListOfPave aIt;
270 //
271 aNb=myExtPaves.Extent();
272 if (theFlag) {
273 aNb=aNb+2;
274 }
275 //
7a76337e 276 if (aNb <= 1) {
277 myExtPaves.Clear();
278 myMFence.Clear();
279 return;
4e57c75e 280 }
281 //
7a76337e 282 BOPDS_VectorOfPave pPaves(1, aNb);
283 //
284 i=1;
4e57c75e 285 if (theFlag) {
7a76337e 286 pPaves(i) = myPave1;
4e57c75e 287 ++i;
7a76337e 288 pPaves(i) = myPave2;
4e57c75e 289 ++i;
290 }
291 //
292 aIt.Initialize(myExtPaves);
293 for (; aIt.More(); aIt.Next()) {
294 const BOPDS_Pave& aPave=aIt.Value();
7a76337e 295 pPaves(i) = aPave;
4e57c75e 296 ++i;
297 }
298 myExtPaves.Clear();
299 myMFence.Clear();
300 //
7a76337e 301 std::sort(pPaves.begin(), pPaves.end());
4e57c75e 302 //
7a76337e 303 for (i = 1; i <= aNb; ++i) {
304 const BOPDS_Pave& aPave = pPaves(i);
305 if (i == 1) {
306 aPave1 = aPave;
4e57c75e 307 continue;
308 }
309 //
7a76337e 310 aPave2 = aPave;
311 aPB = new BOPDS_PaveBlock;
4e57c75e 312 aPB->SetOriginalEdge(myOriginalEdge);
313 aPB->SetPave1(aPave1);
314 aPB->SetPave2(aPave2);
315 //
316 theLPB.Append(aPB);
317 //
7a76337e 318 aPave1 = aPave2;
4e57c75e 319 }
4e57c75e 320}
4e57c75e 321// ShrunkData
322//=======================================================================
323//function : HasShrunkData
324//purpose :
325//=======================================================================
326 Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
327{
328 return (!myShrunkBox.IsVoid());
329}
330//=======================================================================
331//function : SetShrunkData
332//purpose :
333//=======================================================================
334 void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
335 const Standard_Real theT2,
336 const Bnd_Box& theBox)
337{
338 myTS1=theT1;
339 myTS2=theT2;
340 myShrunkBox=theBox;
341}
342//=======================================================================
343//function : ShrunkData
344//purpose :
345//=======================================================================
346 void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
347 Standard_Real& theT2,
348 Bnd_Box& theBox)const
349{
350 theT1=myTS1;
351 theT2=myTS2;
352 theBox=myShrunkBox;
353}
354//=======================================================================
355//function : Dump
356//purpose :
357//=======================================================================
358 void BOPDS_PaveBlock::Dump()const
359{
360 printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge);
361 printf(" Pave1:");
362 myPave1.Dump();
363 printf(" Pave2:");
364 myPave2.Dump();
365 printf(" }");
366}