0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BOPDS / BOPDS_PaveBlock.cxx
... / ...
CommitLineData
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 <BOPDS_Pave.hxx>
17#include <BOPDS_PaveBlock.hxx>
18#include <BOPDS_VectorOfPave.hxx>
19#include <NCollection_BaseAllocator.hxx>
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <algorithm>
24IMPLEMENT_STANDARD_RTTIEXT(BOPDS_PaveBlock,Standard_Transient)
25
26//=======================================================================
27//function :
28//purpose :
29//=======================================================================
30 BOPDS_PaveBlock::BOPDS_PaveBlock()
31:
32 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
33 myExtPaves(myAllocator)
34{
35 myEdge=-1;
36 myOriginalEdge=-1;
37 myTS1=-99.;
38 myTS2=myTS1;
39 myIsSplittable=Standard_False;
40}
41//=======================================================================
42//function :
43//purpose :
44//=======================================================================
45 BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
46:
47 myAllocator(theAllocator),
48 myExtPaves(theAllocator),
49 myMFence(100, theAllocator)
50{
51 myEdge=-1;
52 myOriginalEdge=-1;
53 myTS1=-99.;
54 myTS2=myTS1;
55 myIsSplittable=Standard_False;
56}
57
58//=======================================================================
59//function : SetEdge
60//purpose :
61//=======================================================================
62 void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge)
63{
64 myEdge=theEdge;
65}
66//=======================================================================
67//function : Edge
68//purpose :
69//=======================================================================
70 Standard_Integer BOPDS_PaveBlock::Edge()const
71{
72 return myEdge;
73}
74//=======================================================================
75//function : HasEdge
76//purpose :
77//=======================================================================
78 Standard_Boolean BOPDS_PaveBlock::HasEdge()const
79{
80 return (myEdge>=0);
81}
82//=======================================================================
83//function : HasEdge
84//purpose :
85//=======================================================================
86 Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const
87{
88 theEdge=myEdge;
89 return (myEdge>=0);
90}
91
92//=======================================================================
93//function : SetOriginalEdge
94//purpose :
95//=======================================================================
96 void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge)
97{
98 myOriginalEdge=theEdge;
99}
100//=======================================================================
101//function : OriginalEdge
102//purpose :
103//=======================================================================
104 Standard_Integer BOPDS_PaveBlock::OriginalEdge()const
105{
106 return myOriginalEdge;
107}
108//=======================================================================
109//function : IsSplitEdge
110//purpose :
111//=======================================================================
112 Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const
113{
114 return (myEdge!=myOriginalEdge);
115}
116//=======================================================================
117//function : SetPave1
118//purpose :
119//=======================================================================
120 void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave)
121{
122 myPave1=thePave;
123}
124//=======================================================================
125//function : Pave1
126//purpose :
127//=======================================================================
128 const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const
129{
130 return myPave1;
131}
132//=======================================================================
133//function : SetPave2
134//purpose :
135//=======================================================================
136 void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave)
137{
138 myPave2=thePave;
139}
140//=======================================================================
141//function : Pave2
142//purpose :
143//=======================================================================
144 const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const
145{
146 return myPave2;
147}
148//=======================================================================
149//function : Range
150//purpose :
151//=======================================================================
152 void BOPDS_PaveBlock::Range(Standard_Real& theT1,
153 Standard_Real& theT2)const
154{
155 theT1=myPave1.Parameter();
156 theT2=myPave2.Parameter();
157}
158//=======================================================================
159//function : Indices
160//purpose :
161//=======================================================================
162 void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1,
163 Standard_Integer& theIndex2)const
164{
165 theIndex1=myPave1.Index();
166 theIndex2=myPave2.Index();
167}
168//=======================================================================
169//function : HasSameBounds
170//purpose :
171//=======================================================================
172 Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const
173{
174 Standard_Boolean bFlag1, bFlag2;
175 Standard_Integer n11, n12, n21, n22;
176 //
177 Indices(n11, n12);
178 theOther->Indices(n21, n22);
179 //
180 bFlag1=(n11==n21) && (n12==n22);
181 bFlag2=(n11==n22) && (n12==n21);
182 //
183 return (bFlag1 || bFlag2);
184}
185
186
187//
188// Extras
189//
190//=======================================================================
191//function : AppendExtPave
192//purpose :
193//=======================================================================
194 void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave)
195{
196 if (myMFence.Add(thePave.Index())) {
197 myExtPaves.Append(thePave);
198 }
199}
200//=======================================================================
201//function : AppendExtPave1
202//purpose :
203//=======================================================================
204 void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave)
205{
206 myExtPaves.Append(thePave);
207}
208//=======================================================================
209//function : RemoveExtPave
210//purpose :
211//=======================================================================
212void BOPDS_PaveBlock::RemoveExtPave(const Standard_Integer theVertNum)
213{
214 if (myMFence.Contains(theVertNum))
215 {
216 BOPDS_ListOfPave::Iterator itPaves(myExtPaves);
217 while (itPaves.More())
218 {
219 if (itPaves.Value().Index() == theVertNum)
220 myExtPaves.Remove(itPaves);
221 else
222 itPaves.Next();
223 }
224 myMFence.Remove(theVertNum);
225 }
226}
227//=======================================================================
228//function : ExtPaves
229//purpose :
230//=======================================================================
231 const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const
232{
233 return myExtPaves;
234}
235//=======================================================================
236//function : ChangeExtPaves
237//purpose :
238//=======================================================================
239 BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves()
240{
241 return myExtPaves;
242}
243//=======================================================================
244//function : IsToUpdate
245//purpose :
246//=======================================================================
247 Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const
248{
249 return !myExtPaves.IsEmpty();
250}
251//=======================================================================
252//function : ContainsParameter
253//purpose :
254//=======================================================================
255 Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT,
256 const Standard_Real theTol,
257 Standard_Integer& theInd) const
258{
259 Standard_Boolean bRet;
260 BOPDS_ListIteratorOfListOfPave aIt;
261 //
262 bRet = Standard_False;
263 aIt.Initialize(myExtPaves);
264 for (; aIt.More(); aIt.Next()) {
265 const BOPDS_Pave& aPave = aIt.Value();
266 bRet = (Abs(aPave.Parameter() - theT) < theTol);
267 if (bRet) {
268 theInd = aPave.Index();
269 break;
270 }
271 }
272 return bRet;
273}
274//=======================================================================
275//function : Update
276//purpose :
277//=======================================================================
278 void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB,
279 const Standard_Boolean theFlag)
280{
281 Standard_Integer i, aNb;
282 BOPDS_Pave aPave1, aPave2;
283 Handle(BOPDS_PaveBlock) aPB;
284 BOPDS_ListIteratorOfListOfPave aIt;
285 //
286 aNb=myExtPaves.Extent();
287 if (theFlag) {
288 aNb=aNb+2;
289 }
290 //
291 if (aNb <= 1) {
292 myExtPaves.Clear();
293 myMFence.Clear();
294 return;
295 }
296 //
297 BOPDS_VectorOfPave pPaves(1, aNb);
298 //
299 i=1;
300 if (theFlag) {
301 pPaves(i) = myPave1;
302 ++i;
303 pPaves(i) = myPave2;
304 ++i;
305 }
306 //
307 aIt.Initialize(myExtPaves);
308 for (; aIt.More(); aIt.Next()) {
309 const BOPDS_Pave& aPave=aIt.Value();
310 pPaves(i) = aPave;
311 ++i;
312 }
313 myExtPaves.Clear();
314 myMFence.Clear();
315 //
316 std::sort(pPaves.begin(), pPaves.end());
317 //
318 for (i = 1; i <= aNb; ++i) {
319 const BOPDS_Pave& aPave = pPaves(i);
320 if (i == 1) {
321 aPave1 = aPave;
322 continue;
323 }
324 //
325 aPave2 = aPave;
326 aPB = new BOPDS_PaveBlock;
327 aPB->SetOriginalEdge(myOriginalEdge);
328 aPB->SetPave1(aPave1);
329 aPB->SetPave2(aPave2);
330 //
331 theLPB.Append(aPB);
332 //
333 aPave1 = aPave2;
334 }
335}
336// ShrunkData
337//=======================================================================
338//function : HasShrunkData
339//purpose :
340//=======================================================================
341 Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const
342{
343 return (!myShrunkBox.IsVoid());
344}
345//=======================================================================
346//function : SetShrunkData
347//purpose :
348//=======================================================================
349 void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1,
350 const Standard_Real theT2,
351 const Bnd_Box& theBox,
352 const Standard_Boolean theIsSplittable)
353{
354 myTS1=theT1;
355 myTS2=theT2;
356 myShrunkBox=theBox;
357 myIsSplittable=theIsSplittable;
358}
359//=======================================================================
360//function : ShrunkData
361//purpose :
362//=======================================================================
363 void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1,
364 Standard_Real& theT2,
365 Bnd_Box& theBox,
366 Standard_Boolean& theIsSplittable) const
367{
368 theT1=myTS1;
369 theT2=myTS2;
370 theBox=myShrunkBox;
371 theIsSplittable=myIsSplittable;
372}
373//=======================================================================
374//function : Dump
375//purpose :
376//=======================================================================
377 void BOPDS_PaveBlock::Dump()const
378{
379 printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge);
380 printf(" Pave1:");
381 myPave1.Dump();
382 printf(" Pave2:");
383 myPave2.Dump();
384 printf(" }");
385}