0022627: Change OCCT memory management defaults
[occt.git] / src / IGESDefs / IGESDefs_ToolAttributeTable.cxx
CommitLineData
7fd59977 1//--------------------------------------------------------------------
2//
3// File Name : IGESDefs_AttributeTable.cxx
4// Date :
5// Author : CKY / Contract Toubro-Larsen
6// Copyright : MATRA-DATAVISION 1993
7//
8//--------------------------------------------------------------------
9
10#include <IGESDefs_ToolAttributeTable.ixx>
11#include <IGESData_ParamCursor.hxx>
12#include <IGESDefs_AttributeDef.hxx>
13#include <TColStd_HArray2OfTransient.hxx>
14#include <TColStd_HArray1OfReal.hxx>
15#include <TColStd_HArray1OfInteger.hxx>
16#include <Interface_HArray1OfHAsciiString.hxx>
17#include <IGESData_HArray1OfIGESEntity.hxx>
18#include <TCollection_HAsciiString.hxx>
19#include <Interface_Macros.hxx>
20#include <IGESData_Dump.hxx>
21
22
23IGESDefs_ToolAttributeTable::IGESDefs_ToolAttributeTable () { }
24
25
26void IGESDefs_ToolAttributeTable::ReadOwnParams
27 (const Handle(IGESDefs_AttributeTable)& ent,
28 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
29{
30 Standard_Integer nr = 1;
31 Standard_Integer j;
32 Standard_Boolean st = Standard_True;
33
34 Handle(IGESDefs_AttributeDef) ab = ent->Definition(); // formerly loaded
35 Handle(TColStd_HArray2OfTransient) list2;
36 if (ab.IsNull()) {
37 PR.AddFail("No Attribute Definition as Structure");
38 return;
39 }
40 Standard_Integer na = ab->NbAttributes();
41
42 if (ent->FormNumber() == 1)
43 st = PR.ReadInteger(PR.Current(),"No. of rows",nr);
44 if (st) list2 = new TColStd_HArray2OfTransient(1,na,1,nr);
45
46// AttributeDef repeated once (Form 0) or <nr> times (Form 1)
47 for (Standard_Integer k = 1; k <= nr; k ++)
48 {
49 for (Standard_Integer i = 1; i <= na; i ++)
50 {
51 Standard_Integer avc = ab->AttributeValueCount(i);
52 Standard_Integer atype = ab->AttributeValueDataType(i);
53 switch (atype)
54 {
55 case 0 :
56 for (j = 1; j <= avc; j ++)
57 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
58 break;
59 case 1 : {
60 Handle(TColStd_HArray1OfInteger) attrInt = new TColStd_HArray1OfInteger(1,avc);
61 list2->SetValue(i,k,attrInt);
62 Standard_Integer item;
63 for (j = 1; j <= avc; j ++) {
64 //st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
65 if (PR.ReadInteger(PR.Current(),"Value",item))
66 attrInt->SetValue(j,item);
67 }
68 }
69 break;
70 case 2 : {
71 Handle(TColStd_HArray1OfReal) attrReal = new TColStd_HArray1OfReal(1,avc);
72 list2->SetValue(i,k,attrReal);
73 Standard_Real item;
74 for (j = 1; j <= avc; j ++) {
75 //st = PR.ReadReal(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
76 if (PR.ReadReal(PR.Current(),"Value",item))
77 attrReal->SetValue(j,item);
78 }
79 }
80 break;
81 case 3 : {
82 Handle(Interface_HArray1OfHAsciiString) attrStr = new Interface_HArray1OfHAsciiString(1,avc);
83 list2->SetValue(i,k,attrStr);
84 Handle(TCollection_HAsciiString) item;
85 for (j = 1; j <= avc; j ++) {
86 //st = PR.ReadText(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
87 if (PR.ReadText(PR.Current(),"Value",item))
88 attrStr->SetValue(j,item);
89 }
90 }
91 break;
92 case 4 : {
93 Handle(IGESData_HArray1OfIGESEntity) attrEnt = new IGESData_HArray1OfIGESEntity(1,avc);
94 list2->SetValue(i,k,attrEnt);
95 Handle(IGESData_IGESEntity) item;
96 for (j = 1; j <= avc; j ++) {
97 //st = PR.ReadEntity(IR,PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
98 if (PR.ReadEntity(IR,PR.Current(),"Value",item))
99 attrEnt->SetValue(j,item);
100 }
101 }
102 break;
103 case 5 :
104 for (j = 1; j <= avc; j ++)
105 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
106 break;
107 case 6 : { // Here item takes value 0 or 1
108 Handle(TColStd_HArray1OfInteger) attrInt = new TColStd_HArray1OfInteger(1,avc);
109 list2->SetValue(i,k,attrInt);
110 Standard_Integer item;
111 for (j = 1; j <= avc; j ++) {
112 //st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
113 if (PR.ReadInteger(PR.Current(),"Value",item))
114 attrInt->SetValue(j,item);
115 }
116 }
117 break;
118 default : break;
119 }
120 }
121 }
122 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
123 ent->Init(list2);
124}
125
126void IGESDefs_ToolAttributeTable::WriteOwnParams
127 (const Handle(IGESDefs_AttributeTable)& ent, IGESData_IGESWriter& IW) const
128{
129 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
130
131 Standard_Integer nr = ent->NbRows();
132 Standard_Integer na = ent->NbAttributes();
133 if (ent->FormNumber() == 1) IW.Send(nr);
134 for (Standard_Integer k = 1; k <= nr; k ++)
135 {
136 for (Standard_Integer i = 1; i <= na; i ++)
137 {
138 Standard_Integer count = ab->AttributeValueCount(i);
139 for (Standard_Integer j = 1;j <= count; j++)
140 {
141 switch(ab->AttributeValueDataType(i))
142 {
143 case 0 : IW.SendVoid(); break;
144 case 1 : IW.Send(ent->AttributeAsInteger(i,k,j)); break;
145 case 2 : IW.Send(ent->AttributeAsReal (i,k,j)); break;
146 case 3 : IW.Send(ent->AttributeAsString (i,k,j)); break;
147 case 4 : IW.Send(ent->AttributeAsEntity (i,k,j)); break;
148 case 5 : IW.SendVoid(); break;
149 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,k,j)); break;
150 default : break;
151 }
152 }
153 }
154 }
155}
156
157void IGESDefs_ToolAttributeTable::OwnShared
158 (const Handle(IGESDefs_AttributeTable)& ent, Interface_EntityIterator& iter) const
159{
160 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
161 Standard_Integer na = ent->NbAttributes();
162 Standard_Integer nr = ent->NbRows();
163 for (Standard_Integer k = 1; k <= nr; k ++)
164 {
165 for (Standard_Integer i = 1; i <= na; i ++)
166 {
167 if (ab->AttributeValueDataType(i) != 4) continue;
168 Standard_Integer avc = ab->AttributeValueCount(i);
169 for (Standard_Integer j = 1; j <= avc; j ++)
170 iter.GetOneItem(ent->AttributeAsEntity(i,k,j));
171 }
172 }
173}
174
175void IGESDefs_ToolAttributeTable::OwnCopy
176 (const Handle(IGESDefs_AttributeTable)& another,
177 const Handle(IGESDefs_AttributeTable)& ent, Interface_CopyTool& TC) const
178{
179 Standard_Integer j = 1;
180 Handle(IGESDefs_AttributeDef) ab = another->Definition();
181 Standard_Integer na = another->NbAttributes();
182 Standard_Integer nr = another->NbRows();
183 Handle(TColStd_HArray2OfTransient) list2 =
184 new TColStd_HArray2OfTransient(1,na,1,nr);
185 for (Standard_Integer k = 1; k <= nr; k ++)
186 {
187 for (Standard_Integer i = 1; i <= na; i ++)
188 {
189 Standard_Integer avc = ab->AttributeValueCount(i);
190 Standard_Integer atype = ab->AttributeValueDataType(i);
191 switch (atype)
192 {
193 case 0 : //// list2->SetValue(i,k,NULL); par defaut
194 break;
195 case 1 : {
196 DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
197 another->AttributeList(i,k));
198 Handle(TColStd_HArray1OfInteger) attrInt =
199 new TColStd_HArray1OfInteger (1,avc);
200 list2->SetValue(i,k,attrInt);
201 for (j = 1; j <= avc; j++)
202 attrInt->SetValue(j,otherInt->Value(j));
203 }
204 break;
205 case 2 : {
206 DeclareAndCast(TColStd_HArray1OfReal,otherReal,
207 another->AttributeList(i,k));
208 Handle(TColStd_HArray1OfReal) attrReal =
209 new TColStd_HArray1OfReal (1,avc);
210 list2->SetValue(i,k,attrReal);
211 for (j = 1; j <= avc; j++)
212 attrReal->SetValue(j,otherReal->Value(j));
213 }
214 break;
215 case 3 : {
216 DeclareAndCast(Interface_HArray1OfHAsciiString,otherStr,
217 another->AttributeList(i,k));
218 Handle(Interface_HArray1OfHAsciiString) attrStr =
219 new Interface_HArray1OfHAsciiString (1,avc);
220 list2->SetValue(i,k,attrStr);
221 for (j = 1; j <= avc; j++)
222 attrStr->SetValue
223 (j,new TCollection_HAsciiString(otherStr->Value(j)));
224 }
225 break;
226 case 4 : {
227 DeclareAndCast(IGESData_HArray1OfIGESEntity,otherEnt,
228 another->AttributeList(i,k));
229 Handle(IGESData_HArray1OfIGESEntity) attrEnt =
230 new IGESData_HArray1OfIGESEntity (1,avc);
231 list2->SetValue(i,k,attrEnt);
232 for (j = 1; j <= avc; j++)
233 attrEnt->SetValue(j,GetCasted(IGESData_IGESEntity,
234 TC.Transferred(otherEnt->Value(j))));
235 }
236 break;
237 case 5 : ///// list2->SetValue(i,k,NULL); par defaut
238 break;
239 case 6 :{ // Here item takes value 0 or 1
240 DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
241 another->AttributeList(i,k));
242 Handle(TColStd_HArray1OfInteger) attrInt =
243 new TColStd_HArray1OfInteger (1,avc);
244 list2->SetValue(i,k,attrInt);
245 for (j = 1; j <= avc; j++)
246 attrInt->SetValue(j,otherInt->Value(j));
247 }
248 break;
249 default : break;
250 }
251 }
252 }
253 ent->Init(list2);
254}
255
256IGESData_DirChecker IGESDefs_ToolAttributeTable::DirChecker
257 (const Handle(IGESDefs_AttributeTable)& /* ent */ ) const
258{
259 IGESData_DirChecker DC(422,0,1);
260 DC.Structure(IGESData_DefReference);
261 DC.GraphicsIgnored();
262 DC.BlankStatusIgnored();
263 DC.HierarchyStatusIgnored();
264 return DC;
265}
266
267void IGESDefs_ToolAttributeTable::OwnCheck
268 (const Handle(IGESDefs_AttributeTable)& ent,
269 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
270{
271 if (ent->Definition().IsNull())
272 if (ent->HasStructure()) ach->AddFail
273 ("Structure in Directory Entry is not an Attribute Definition Table");
274 else ach->AddFail("No Attribute Definition defined");
275 if (ent->FormNumber() == 0 && ent->NbRows() != 1)
276 ach->AddFail("Form 0 with several Rows");
277 if (ent->NbAttributes() != ent->Definition()->NbAttributes())
278 ach->AddFail("Mismatch between Definition (Structure) and Content");
279}
280
281void IGESDefs_ToolAttributeTable::OwnDump
282 (const Handle(IGESDefs_AttributeTable)& ent, const IGESData_IGESDumper& dumper,
283 const Handle(Message_Messenger)& S, const Standard_Integer level) const
284{
285 S << "IGESDefs_AttributeTable" << endl;
286
287 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
288
289 Standard_Integer na = ent->NbAttributes();
290 Standard_Integer nr = ent->NbRows();
291 if (ent->FormNumber() == 1)
292 S << "Number of Rows (i.e. complete sets of Attributes) : " << nr << endl;
293 else S << "One set of Attributes" << endl;
294 S << "Number of defined Attributes : " << na << endl;
295 if (level <= 4) S <<
296 " [ structure : see Structure in Directory Entry; content : level > 4 ]" <<endl;
297 else
298 for (Standard_Integer k = 1; k <= nr; k ++)
299 {
300 for (Standard_Integer i = 1; i <= na; i ++)
301 {
302 Standard_Integer avc = ab->AttributeValueCount(i);
303 S << "[At.no."<<i<<" Row:"<<k<<"]";
304 switch (ab->AttributeValueDataType(i)) {
305 case 0 : S << " (Void) "; break;
306 case 1 : S << " Integer"; break;
307 case 2 : S << " Real "; break;
308 case 3 : S << " String "; break;
309 case 4 : S << " Entity "; break;
310 case 5 : S << " (Not used)"; break;
311 case 6 : S << " Logical"; break;
312 default : break;
313 }
314 S << " :";
315 for (Standard_Integer j = 1;j <= avc; j++) {
316 S << " ";
317 switch(ab->AttributeValueDataType(i)) {
318 case 1 : S << ent->AttributeAsInteger(i,k,j); break;
319 case 2 : S << ent->AttributeAsReal (i,k,j); break;
320 case 3 : IGESData_DumpString(S,ent->AttributeAsString (i,k,j));
321 break;
322 case 4 : dumper.Dump(ent->AttributeAsEntity (i,k,j),S,level-5);
323 break;
324 case 6 : S << (ent->AttributeAsLogical(i,k,j) ? "True" : "False");
325 break;
326 default : break;
327 }
328 }
329 S << endl;
330 }
331 }
332 S << endl;
333}