0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Aspect / Aspect_GenId.cxx
CommitLineData
b311480e 1// Created on: 1992-05-14
2// Created by: NW,JPB,CAL
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Aspect_GenId.hxx>
19#include <Aspect_IdentDefinitionError.hxx>
7fd59977 20
a9568545 21// =======================================================================
22// function : Aspect_GenId
23// purpose :
24// =======================================================================
25Aspect_GenId::Aspect_GenId()
26: myFreeCount (INT_MAX / 2 + 1),
27 myLength (INT_MAX / 2 + 1),
28 myLowerBound (0),
29 myUpperBound (INT_MAX / 2)
30{
31 //
7fd59977 32}
33
a9568545 34// =======================================================================
35// function : Aspect_GenId
36// purpose :
37// =======================================================================
38Aspect_GenId::Aspect_GenId (const Standard_Integer theLow,
39 const Standard_Integer theUpper)
40: myFreeCount (theUpper - theLow + 1),
41 myLength (theUpper - theLow + 1),
42 myLowerBound (theLow),
43 myUpperBound (theUpper)
44{
45 if (theLow > theUpper)
46 {
9775fa61 47 throw Aspect_IdentDefinitionError("GenId Create Error: wrong interval");
a9568545 48 }
7fd59977 49}
50
a9568545 51// =======================================================================
52// function : Free
53// purpose :
54// =======================================================================
55void Aspect_GenId::Free()
56{
57 myFreeCount = myLength;
58 myFreeIds.Clear();
7fd59977 59}
60
a9568545 61// =======================================================================
62// function : Free
63// purpose :
64// =======================================================================
65void Aspect_GenId::Free (const Standard_Integer theId)
66{
67 if (theId >= myLowerBound
68 && theId <= myUpperBound)
69 {
70 if (myFreeCount + myFreeIds.Extent() + 1 == myLength)
71 {
72 myFreeCount = myLength;
73 myFreeIds.Clear();
74 }
75 else
76 {
77 myFreeIds.Prepend (theId);
78 }
79 }
7fd59977 80}
81
a9568545 82// =======================================================================
1c728f2d 83// function : Next
a9568545 84// purpose :
85// =======================================================================
1c728f2d 86Standard_Integer Aspect_GenId::Next()
a9568545 87{
1c728f2d 88 Standard_Integer aNewId = 0;
89 if (!Next (aNewId))
90 {
91 throw Aspect_IdentDefinitionError("Aspect_GenId::Next(), Error: Available == 0");
92 }
93 return aNewId;
7fd59977 94}
95
a9568545 96// =======================================================================
97// function : Next
98// purpose :
99// =======================================================================
1c728f2d 100Standard_Boolean Aspect_GenId::Next (Standard_Integer& theId)
a9568545 101{
102 if (!myFreeIds.IsEmpty())
103 {
1c728f2d 104 theId = myFreeIds.First();
a9568545 105 myFreeIds.RemoveFirst();
1c728f2d 106 return Standard_True;
a9568545 107 }
108 else if (myFreeCount < 1)
109 {
1c728f2d 110 return Standard_False;
a9568545 111 }
112
113 --myFreeCount;
1c728f2d 114 theId = myLowerBound + myLength - myFreeCount - 1;
115 return Standard_True;
a9568545 116}