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