0022807: Loading of STEP entities in model during reading of STEP file requires redun...
[occt.git] / src / Interface / Interface_BitMap.cxx
CommitLineData
7fd59977 1#include <Interface_BitMap.ixx>
2#include <TCollection_AsciiString.hxx>
3#include <Standard_NotImplemented.hxx>
4
bc650d41
G
5Interface_BitMap::Interface_BitMap()
6{
7 Initialize(0);
8}
9
10
11Interface_BitMap::Interface_BitMap
12(const Standard_Integer nbitems, const Standard_Integer resflags)
13{
14 Initialize(nbitems,resflags);
15}
7fd59977 16
bc650d41 17void Interface_BitMap::Initialize(const Standard_Integer nbitems, const Standard_Integer resflags)
7fd59977 18{
19 thenbitems = nbitems;
20 thenbwords = nbitems/32 + 1;
21 thenbflags = 0;
bc650d41
G
22 if(nbitems)
23 {
24 theflags = new TColStd_HArray1OfInteger (0,thenbwords*(resflags+1));
25 theflags->Init(0);
26 }
27}
28
29Interface_BitMap::Interface_BitMap
30(const Interface_BitMap& other, const Standard_Boolean copied)
31{
32
33 Initialize(other,copied);
7fd59977 34}
35
bc650d41
G
36void Interface_BitMap::Initialize(const Interface_BitMap& other,
37 const Standard_Boolean copied)
7fd59977 38{
39 other.Internals (thenbitems,thenbwords,thenbflags,theflags,thenames);
40 if (!copied) return;
41 Standard_Integer nb = theflags->Upper ();
42 Handle(TColStd_HArray1OfInteger) flags = new TColStd_HArray1OfInteger(0,nb);
43 Standard_Integer i; // svv Jan11 2000 : porting on DEC
44 for (i = 0; i <= nb; i ++)
45 flags->SetValue (i,theflags->Value(i));
46 theflags = flags;
47 if (thenames.IsNull()) return;
48 nb = thenames->Length();
49 Handle(TColStd_HSequenceOfAsciiString) names = new TColStd_HSequenceOfAsciiString();
50 for (i = 1; i <= nb; i ++)
51 names->Append ( TCollection_AsciiString(thenames->Value(i)) );
52 thenames = names;
53}
54
bc650d41
G
55void Interface_BitMap::Internals
56(Standard_Integer& nbitems, Standard_Integer& nbwords,
57 Standard_Integer& nbflags,
58 Handle(TColStd_HArray1OfInteger)& flags,
59 Handle(TColStd_HSequenceOfAsciiString)& names) const
7fd59977 60{
61 nbitems = thenbitems; nbwords = thenbwords; nbflags = thenbflags;
62 flags = theflags; names = thenames;
63}
64
65
bc650d41 66void Interface_BitMap::Reservate (const Standard_Integer moreflags)
7fd59977 67{
68 Standard_Integer nb = theflags->Upper ();
69 Standard_Integer nbflags = nb / thenbwords - 1; // flag 0 non compte ...
70 if (nbflags >= thenbflags + moreflags) return;
71 Standard_Integer nbw = thenbwords * (thenbflags+moreflags+2);
72 Handle(TColStd_HArray1OfInteger) flags = new TColStd_HArray1OfInteger(0,nbw);
73 Standard_Integer i; // svv Jan11 2000 : porting on DEC
74 for (i = 0; i <= nb; i ++)
75 flags->SetValue (i,theflags->Value(i));
76 for (i = nb+1; i <= nbw; i ++) flags->SetValue (i,0);
77 theflags = flags;
78}
79
80
bc650d41 81void Interface_BitMap::SetLength (const Standard_Integer nbitems)
7fd59977 82{
83 Standard_Integer nbw = nbitems/32 + 1;
84 if (nbw == thenbwords) return;
85 Handle(TColStd_HArray1OfInteger) flags =
86 new TColStd_HArray1OfInteger(0,nbw*(thenbflags+1));
87 if (nbw > thenbwords) flags->Init(0);
88 Standard_Integer nbmots = (nbw > thenbwords ? thenbwords : nbw);
89 Standard_Integer i0 = 0, i1 = 0;
90 for (Standard_Integer nf = 0; nf <= thenbflags; nf ++) {
91 for (Standard_Integer i = 0; i < nbmots; i ++)
92 flags->SetValue (i1+i,theflags->Value(i0+i));
93 i0 += thenbwords; i1 += nbw;
94 }
95 theflags = flags;
96 thenbitems = nbitems;
97 thenbwords = nbw;
98}
99
100
bc650d41 101Standard_Integer Interface_BitMap::AddFlag (const Standard_CString name)
7fd59977 102{
103 Reservate(1);
104 Standard_Integer deja = 0;
105 if (thenames.IsNull()) thenames = new TColStd_HSequenceOfAsciiString();
106 else {
107 Standard_Integer i, nb = thenames->Length();
108 for (i = 1; i <= nb; i ++) {
109 if (thenames->Value(i).IsEqual("."))
bc650d41 110 { thenames->ChangeValue(i).AssignCat(name); deja = i; }
7fd59977 111 }
112 }
113 if (!deja) thenames->Append (TCollection_AsciiString(name));
114 thenbflags ++;
115 return (deja ? deja : thenbflags);
116}
117
bc650d41
G
118Standard_Integer Interface_BitMap::AddSomeFlags
119(const Standard_Integer more)
7fd59977 120{
121 Reservate(more);
122 if (thenames.IsNull()) thenames = new TColStd_HSequenceOfAsciiString();
123 for (Standard_Integer i = 1; i <= more; i ++)
124 thenames->Append (TCollection_AsciiString(""));
125 thenbflags += more;
126 return thenbflags;
127}
128
bc650d41
G
129Standard_Boolean Interface_BitMap::RemoveFlag
130(const Standard_Integer num)
7fd59977 131{
132 if (num < 1 || num > thenames->Length()) return Standard_False;
133 if (num == thenames->Length()) thenames->Remove (thenames->Length());
134 else thenames->ChangeValue(num).AssignCat(".");
135 thenbflags --;
136 return Standard_True;
137}
138
bc650d41
G
139Standard_Boolean Interface_BitMap::SetFlagName
140(const Standard_Integer num, const Standard_CString name)
7fd59977 141{
142 if (num < 1 || num > thenames->Length()) return Standard_False;
143 Standard_Integer deja = (name[0] == '\0' ? 0 : FlagNumber (name) );
144 if (deja != 0 && deja != num) return Standard_False;
145 thenames->ChangeValue(num).AssignCat(name);
146 return Standard_True;
147}
148
bc650d41
G
149Standard_Integer Interface_BitMap::NbFlags () const
150{ return thenbflags; }
7fd59977 151
bc650d41
G
152Standard_Integer Interface_BitMap::Length () const
153{ return thenbitems; }
7fd59977 154
bc650d41
G
155Standard_CString Interface_BitMap::FlagName
156(const Standard_Integer num) const
7fd59977 157{
158 if (theflags.IsNull()) return "";
159 if (num < 1 || num > thenames->Length()) return "";
160 return thenames->Value(num).ToCString();
161}
162
bc650d41
G
163Standard_Integer Interface_BitMap::FlagNumber
164(const Standard_CString name) const
7fd59977 165{
166 if (name[0] == '\0') return 0;
167 if (thenames.IsNull()) return 0;
168 Standard_Integer i, nb = thenames->Length();
169 for (i = 1; i <= nb; i ++)
170 if (thenames->Value(i).IsEqual(name)) return i;
171 return 0;
172}
173
174
175// Les valeurs ...
176
bc650d41
G
177Standard_Boolean Interface_BitMap::Value
178(const Standard_Integer item, const Standard_Integer flag) const
7fd59977 179{
180 Standard_Integer numw = (thenbwords * flag) + (item >> 5);
181 const Standard_Integer& val = theflags->Value (numw);
182 if (val == 0 ) return Standard_False;
183 if (val == ~(0)) return Standard_True;
184 Standard_Integer numb = item & 31;
185 return ( ((1 << numb) & val) != 0);
186}
187
bc650d41
G
188void Interface_BitMap::SetValue
189(const Standard_Integer item, const Standard_Boolean val,
190 const Standard_Integer flag) const
7fd59977 191{
192 if (val) SetTrue (item,flag);
193 else SetFalse (item,flag);
194}
195
bc650d41
G
196void Interface_BitMap::SetTrue
197(const Standard_Integer item, const Standard_Integer flag) const
7fd59977 198{
199 Standard_Integer numw = (thenbwords * flag) + (item >> 5);
200 Standard_Integer numb = item & 31;
201 theflags->ChangeValue (numw) |= (1 << numb);
202}
203
bc650d41
G
204void Interface_BitMap::SetFalse
205(const Standard_Integer item, const Standard_Integer flag) const
7fd59977 206{
207 Standard_Integer numw = (thenbwords * flag) + (item >> 5);
208 Standard_Integer& val = theflags->ChangeValue (numw);
209 if (val == 0) return;
210 Standard_Integer numb = item & 31;
211 theflags->ChangeValue (numw) &= ~(1 << numb);
212}
213
bc650d41
G
214Standard_Boolean Interface_BitMap::CTrue
215(const Standard_Integer item, const Standard_Integer flag) const
7fd59977 216{
217 Standard_Integer numw = (thenbwords * flag) + (item >> 5);
218 Standard_Integer numb = item & 31;
219 Standard_Integer& val = theflags->ChangeValue (numw);
220 Standard_Integer res, mot = (1 << numb);
221
222 if (val == 0) { val = mot; return Standard_False; }
223 else { res = val & mot; val |= mot; }
224 return (res != 0);
225}
226
bc650d41
G
227Standard_Boolean Interface_BitMap::CFalse
228(const Standard_Integer item, const Standard_Integer flag) const
7fd59977 229{
230 Standard_Integer numw = (thenbwords * flag) + (item >> 5);
231 Standard_Integer numb = item & 31;
232 Standard_Integer& val = theflags->ChangeValue (numw);
233 Standard_Integer res, mot = ~(1 << numb);
234
235 if (val == ~(0)) { val = mot; return Standard_False; }
236 else { res = val | mot; val &= mot; }
237 return (res != 0);
238}
239
240
bc650d41
G
241void Interface_BitMap::Init
242(const Standard_Boolean val, const Standard_Integer flag) const
7fd59977 243{
244 Standard_Integer i, ii = thenbwords, i1 = thenbwords *flag;
245 if (flag < 0) { i1 = 0; ii = thenbwords*(thenbflags+1); }
246 if (val) for (i = 0; i < ii; i ++) theflags->SetValue (i1+i,~(0));
247 else for (i = 0; i < ii; i ++) theflags->SetValue (i1+i, 0 );
248}
bc650d41
G
249
250void Interface_BitMap::Clear()
251{
252 theflags.Nullify();
253 Initialize(0);
254}