0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / IGESDefs / IGESDefs_ToolAttributeDef.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
7fd59977 9//
b311480e 10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
7fd59977 12//
b311480e 13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20//--------------------------------------------------------------------
7fd59977 21//--------------------------------------------------------------------
22
23#include <IGESDefs_ToolAttributeDef.ixx>
24#include <IGESData_ParamCursor.hxx>
25#include <IGESGraph_TextDisplayTemplate.hxx>
26#include <TColStd_HArray1OfTransient.hxx>
27#include <IGESData_IGESEntity.hxx>
28#include <TCollection_HAsciiString.hxx>
29#include <TColStd_HArray1OfReal.hxx>
30#include <TColStd_HArray1OfInteger.hxx>
31#include <IGESData_HArray1OfIGESEntity.hxx>
32#include <IGESGraph_HArray1OfTextDisplayTemplate.hxx>
33#include <IGESDefs_HArray1OfHArray1OfTextDisplayTemplate.hxx>
34#include <Interface_HArray1OfHAsciiString.hxx>
35#include <IGESData_Dump.hxx>
36#include <Interface_Macros.hxx>
37#include <stdio.h>
38
39
40IGESDefs_ToolAttributeDef::IGESDefs_ToolAttributeDef () { }
41
42
43void IGESDefs_ToolAttributeDef::ReadOwnParams
44 (const Handle(IGESDefs_AttributeDef)& ent,
45 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
46{
47 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
48 Handle(TCollection_HAsciiString) aName;
49 Standard_Integer aListType;
50 Handle(TColStd_HArray1OfInteger) attrTypes;
51 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
52 Handle(TColStd_HArray1OfInteger) attrValueCounts;
53 Handle(TColStd_HArray1OfTransient) attrValues;
54 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
55 Standard_Integer nbval;
56 Standard_Integer fn = ent->FormNumber();
57
58 if (PR.DefinedElseSkip())
59 PR.ReadText(PR.Current(), "Attribute Table Name", aName); //szv#4:S4163:12Mar99 `st=` not needed
60
61 PR.ReadInteger(PR.Current(), "Attribute List Type", aListType); //szv#4:S4163:12Mar99 `st=` not needed
62
63 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Attributes", nbval);
64 if (st && nbval > 0)
65 {
66 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
67 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
68 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
69 if (fn > 0) attrValues =
70 new TColStd_HArray1OfTransient(1, nbval);
71 if (fn > 1) attrValuePointers =
72 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
73 }
74 else PR.AddFail("Number of Attributes: Not Positive");
75
76 if ( ! attrTypes.IsNull())
77 for (Standard_Integer i = 1; i <= nbval; i++)
78 {
79 Standard_Integer attrType;
80 Standard_Integer attrValueDataType;
81 Standard_Integer avc;
82// Value according type
83 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
84
85 //st = PR.ReadInteger(PR.Current(), "Attribute Type", attrType); //szv#4:S4163:12Mar99 moved in if
86 if (PR.ReadInteger(PR.Current(), "Attribute Type", attrType))
87 attrTypes->SetValue(i, attrType);
88
89 st = PR.ReadInteger(PR.Current(),"Attribute Data Type",attrValueDataType);
90 if (st) attrValueDataTypes->SetValue(i, attrValueDataType);
91
92 if (PR.DefinedElseSkip())
93 st = PR.ReadInteger (PR.Current(),"Attribute Value Count",avc);
94 else avc = 1;
95
96 if (st) {
97 attrValueCounts->SetValue(i, avc);
98 if (fn > 1) attrValuePointer =
99 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
100 }
101
102 if (! attrValues.IsNull())
103 if (fn > 0)
104 {
105 Handle(TColStd_HArray1OfInteger) attrInt;
106 Handle(TColStd_HArray1OfReal) attrReal;
107 Handle(Interface_HArray1OfHAsciiString) attrStr;
108 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
109 switch (attrValueDataType) {
110 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
111 attrValues->SetValue(i,attrInt); break;
112 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
113 attrValues->SetValue(i,attrReal); break;
114 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
115 attrValues->SetValue(i,attrStr); break;
116 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
117 attrValues->SetValue(i,attrEnt); break;
118 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
119 attrValues->SetValue(i,attrInt); break;
120 default : break;
121 }
122 for (Standard_Integer j = 1; j <= avc; j++)
123 {
124 switch(attrValueDataType)
125 {
126 case 0:
127 {
128 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // passer
129//// attrValue->SetValue(j, NULL); par defaut
130 break;
131 }
132 case 1:
133 {
134 Standard_Integer temp;
135 //st = PR.ReadInteger(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
136 if (PR.ReadInteger(PR.Current(), "Attribute Value", temp))
137 attrInt->SetValue(j, temp);
138 }
139 break;
140 case 2:
141 {
142 Standard_Real temp;
143 //st = PR.ReadReal(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
144 if (PR.ReadReal(PR.Current(), "Attribute Value", temp))
145 attrReal->SetValue(j, temp);
146 }
147 break;
148 case 3:
149 {
150 Handle(TCollection_HAsciiString) temp;
151 //st = PR.ReadText(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
152 if (PR.ReadText(PR.Current(), "Attribute Value", temp))
153 attrStr->SetValue(j, temp);
154 }
155 break;
156 case 4:
157 {
158 Handle(IGESData_IGESEntity) temp;
159 //st = PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
160 if (PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp))
161 attrEnt->SetValue(j, temp);
162 }
163 break;
164 case 5:
165 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
166 break;
167 case 6:
168 {
169 Standard_Boolean temp;
170 //st = PR.ReadBoolean(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
171 if (PR.ReadBoolean(PR.Current(), "Attribute Value", temp))
172 attrInt->SetValue(j, (temp ? 1 : 0));
173 }
174 break;
175 }
176 if (fn == 2)
177 {
178 Handle(IGESGraph_TextDisplayTemplate) tempText;
179 //st = PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
180 //STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText); //szv#4:S4163:12Mar99 moved in if
181 if (PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
182 STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText))
183 attrValuePointer->SetValue(j, tempText);
184 }
185 }
186 if (fn == 2)
187 attrValuePointers->SetValue(i, attrValuePointer);
188 }
189 }
190
191 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
192 ent->Init
193 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
194 attrValues, attrValuePointers);
195}
196
197void IGESDefs_ToolAttributeDef::WriteOwnParams
198 (const Handle(IGESDefs_AttributeDef)& ent, IGESData_IGESWriter& IW) const
199{
200 if (ent->HasTableName()) IW.Send(ent->TableName());
201 else IW.SendVoid();
202 IW.Send(ent->ListType());
203 Standard_Integer upper = ent->NbAttributes();
204 IW.Send(upper);
205
206 for (Standard_Integer i = 1; i <= upper; i++)
207 {
208 Standard_Integer check = ent->AttributeValueDataType(i);
209 Standard_Integer count = ent->AttributeValueCount(i);
210 IW.Send(ent->AttributeType(i));
211 IW.Send(check);
212 IW.Send(count);
213 if (ent->FormNumber() > 0)
214 {
215 for (Standard_Integer j = 1; j <= count; j++)
216 {
217 switch (check) {
218 case 0 : IW.SendVoid(); break;
219 case 1 : IW.Send(ent->AttributeAsInteger(i,j)); break;
220 case 2 : IW.Send(ent->AttributeAsReal(i,j)); break;
221 case 3 : IW.Send(ent->AttributeAsString(i,j)); break;
222 case 4 : IW.Send(ent->AttributeAsEntity(i,j)); break;
223 case 5 : IW.SendVoid(); break;
224 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,j)); break;
225 default : break;
226 }
227 if ( ent->FormNumber() == 2)
228 IW.Send(ent->AttributeTextDisplay(i,j));
229 }
230 }
231 }
232}
233
234void IGESDefs_ToolAttributeDef::OwnShared
235 (const Handle(IGESDefs_AttributeDef)& ent, Interface_EntityIterator& iter) const
236{
237 Standard_Integer upper = ent->NbAttributes();
238 for (Standard_Integer i = 1; i <= upper; i++)
239 {
240 Standard_Integer check = ent->AttributeValueDataType(i);
241 Standard_Integer count = ent->AttributeValueCount(i);
242 if (ent->FormNumber() > 0)
243 {
244 for (Standard_Integer j = 1; j <= count; j++)
245 {
246 if ( check == 4 ) iter.GetOneItem(ent->AttributeAsEntity(i,j));
247 if ( ent->FormNumber() == 2)
248 iter.GetOneItem(ent->AttributeTextDisplay(i,j));
249 }
250 }
251 }
252}
253
254
255void IGESDefs_ToolAttributeDef::OwnCopy
256 (const Handle(IGESDefs_AttributeDef)& another,
257 const Handle(IGESDefs_AttributeDef)& ent, Interface_CopyTool& TC) const
258{
259 Handle(TCollection_HAsciiString) aName;
260 if (!another->TableName().IsNull()) aName =
261 new TCollection_HAsciiString(another->TableName());
262 Standard_Integer aListType = another->ListType();
263
264 Handle(TColStd_HArray1OfInteger) attrTypes;
265 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
266 Handle(TColStd_HArray1OfInteger) attrValueCounts;
267 Handle(TColStd_HArray1OfTransient) attrValues;
268 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
269 Standard_Integer nbval = another->NbAttributes();
270
271 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
272 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
273 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
274 if (another->HasValues()) attrValues =
275 new TColStd_HArray1OfTransient(1, nbval);
276 if (another->HasTextDisplay()) attrValuePointers =
277 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
278
279 for (Standard_Integer i = 1; i <= nbval; i++)
280 {
281 Standard_Integer attrType = another->AttributeType(i);
282 attrTypes->SetValue(i, attrType);
283 Standard_Integer attrValueDataType = another->AttributeValueDataType(i);
284 attrValueDataTypes->SetValue(i, attrValueDataType);
285 Standard_Integer avc = another->AttributeValueCount(i);
286 attrValueCounts->SetValue(i, avc);
287 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
288
289 if (another->HasTextDisplay()) attrValuePointer =
290 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
291
292 if (another->HasValues())
293 {
294 Handle(TColStd_HArray1OfInteger) attrInt;
295 Handle(TColStd_HArray1OfReal) attrReal;
296 Handle(Interface_HArray1OfHAsciiString) attrStr;
297 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
298 switch (attrValueDataType) {
299 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
300 attrValues->SetValue(i,attrInt); break;
301 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
302 attrValues->SetValue(i,attrReal); break;
303 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
304 attrValues->SetValue(i,attrStr); break;
305 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
306 attrValues->SetValue(i,attrEnt); break;
307 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
308 attrValues->SetValue(i,attrInt); break;
309 default : break;
310 }
311 for (Standard_Integer j = 1; j <= avc; j ++)
312 {
313 switch(attrValueDataType)
314 {
315 case 0:
316 break;
317 case 1: attrInt->SetValue(j,another->AttributeAsInteger(i,j));
318 break;
319 case 2: attrReal->SetValue(j,another->AttributeAsReal(i,j));
320 break;
321 case 3: attrStr->SetValue(j,new TCollection_HAsciiString
322 (another->AttributeAsString(i,j)));
323 break;
324 case 4: {
325 DeclareAndCast(IGESData_IGESEntity,Ent,TC.Transferred
326 (another->AttributeAsEntity(i,j)));
327 attrEnt->SetValue(j,Ent);
328 }
329 break;
330 case 5:
331 break;
332 case 6: attrInt->SetValue
333 (j,(another->AttributeAsLogical(i,j) ? 1 : 0));
334 break;
335 default : break;
336 }
337 if (another->HasTextDisplay())
338 {
339 DeclareAndCast(IGESGraph_TextDisplayTemplate, temptext,
340 TC.Transferred(another->AttributeTextDisplay(i,j)));
341 attrValuePointer->SetValue (j, temptext);
342 }
343 }
344 if (another->HasTextDisplay())
345 attrValuePointers->SetValue(i, attrValuePointer);
346 }
347 }
348 ent->Init
349 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
350 attrValues, attrValuePointers);
351}
352
353IGESData_DirChecker IGESDefs_ToolAttributeDef::DirChecker
354 (const Handle(IGESDefs_AttributeDef)& /* ent */ ) const
355{
356 IGESData_DirChecker DC (322, 0, 2);
357 DC.Structure(IGESData_DefVoid);
358 DC.LineFont(IGESData_DefAny);
359 DC.LineWeight(IGESData_DefValue);
360 DC.Color(IGESData_DefAny);
361 DC.BlankStatusIgnored();
362 DC.SubordinateStatusRequired(0);
363 DC.UseFlagRequired(2);
364 DC.GraphicsIgnored(1);
365 return DC;
366}
367
368void IGESDefs_ToolAttributeDef::OwnCheck
369 (const Handle(IGESDefs_AttributeDef)& ent,
370 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
371{
372 Standard_Integer nb = ent->NbAttributes();
373 Standard_Integer fn = ent->FormNumber();
374 for (Standard_Integer i = 1; i <= nb; i ++) {
375 char mess[80];
376 if (ent->AttributeType(i) < 0 || ent->AttributeType(i) > 9999) {
377 sprintf(mess,"Attribute Type n0.%d not in <0 - 9999>", ent->AttributeType(i));
378 ach->AddFail(mess);
379 }
380 Standard_Integer aty = ent->AttributeValueDataType(i);
381 if (aty < 0 || aty > 6) {
382 sprintf(mess,"Attribute Value Data Type n0.%d not in <0 - 6>", aty);
383 ach->AddFail(mess);
384 }
385 if (ent->AttributeValueCount(i) <= 0) continue;
386 Handle(Standard_Transient) list = ent->AttributeList(i);
387 if (fn > 0 && ent.IsNull()) {
388 if (aty == 0 || aty == 5) continue;
389 sprintf(mess,"Form Number > 0 and Attribute Value List n0.%d undefined", aty);
390 ach->AddFail(mess);
391 continue;
392 }
393 else if (fn == 0) continue;
394 mess[0] = '\0';
395 switch (aty) {
396 case 1 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
397 sprintf(mess,"Attribute List n0.%d (Integers) badly defined", aty);
398 break;
399 case 2 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfReal)))
400 sprintf(mess,"Attribute List n0.%d (Reals) badly defined", aty);
401 break;
402 case 3 : if (!list->IsKind(STANDARD_TYPE(Interface_HArray1OfHAsciiString)))
403 sprintf(mess,"Attribute List n0.%d (Strings) badly defined", aty);
404 break;
405 case 4 : if (!list->IsKind(STANDARD_TYPE(IGESData_HArray1OfIGESEntity)))
406 sprintf(mess,"Attribute List n0.%d (IGES Pointers) badly defined", aty);
407 break;
408 case 6 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
409 sprintf(mess,"Attribute List n0.%d (Logicals i.e. Integers) badly defined", aty);
410 break;
411 default : break;
412 }
413 if (mess[0] != '\0') ach->AddFail(mess);
414 }
415}
416
417
418void IGESDefs_ToolAttributeDef::OwnDump
419 (const Handle(IGESDefs_AttributeDef)& ent, const IGESData_IGESDumper& dumper,
420 const Handle(Message_Messenger)& S, const Standard_Integer level) const
421{
422 Standard_Integer sublevel = (level > 4) ? 1 : 0;
423
424 S << "IGESDefs_AttributeDef" << endl;
425 S << "Attribute Table Name: ";
426 IGESData_DumpString(S,ent->TableName());
427 S << endl;
428 S << "Attribute List Type : " << ent->ListType() << endl;
429 S << "Number of Attributes : " << ent->NbAttributes() << endl;
430 S << "Attribute Types : " << endl;
431 S << "Attribute Value Data Types : " << endl;
432 S << "Attribute Value Counts : " << endl;
433 if (ent->HasValues()) S << "Attribute Values : " << endl;
434 if (ent->HasTextDisplay()) S << "Attribute Value Entities : " << endl;
435 IGESData_DumpVals(S,-level,1, ent->NbAttributes(),ent->AttributeType);
436 S << endl;
437 if (level > 4)
438 {
439 Standard_Integer upper = ent->NbAttributes();
440 for (Standard_Integer i = 1; i <= upper ; i ++)
441 {
442 Standard_Integer avc = ent->AttributeValueCount(i);
443 Standard_Integer typ = ent->AttributeValueDataType(i);
444 S << "[" << i << "]: ";
445 S << "Attribute Type : " << ent->AttributeType(i) << " ";
446 S << "Value Data Type : " << typ;
447 switch (typ) {
448 case 0 : S << " (Void)"; break;
449 case 1 : S << " : Integer "; break;
450 case 2 : S << " : Real "; break;
451 case 3 : S << " : String "; break;
452 case 4 : S << " : Entity "; break;
453 case 5 : S << " (Not Used)"; break;
454 case 6 : S << " : Logical "; break;
455 default : break;
456 }
457 S << " Count : " << avc << endl;
458 if (ent->HasValues())
459 {
460 if (level <= 5) {
461 S << " [ content (Values) : ask level > 5 ]" << endl;
462 continue;
463 }
464 for (Standard_Integer j = 1; j <= avc; j ++)
465 {
466 S << "[" << j << "]: ";
467 switch(ent->AttributeValueDataType(i))
468 {
469 case 0: S << "(Void) ";
470 break;
471 case 1: S << ent->AttributeAsInteger(i,j);
472 break;
473 case 2: S << ent->AttributeAsReal(i,j);
474 break;
475 case 3: IGESData_DumpString(S,ent->AttributeAsString(i,j));
476 break;
477 case 4: dumper.Dump(ent->AttributeAsEntity(i,j),S,level-5);
478 break;
479 case 5: S << "(Not Used)";
480 break;
481 case 6:
482 S << ( ent->AttributeAsLogical(i,j) ? "True" : "False");
483 break;
484 default : break;
485 }
486 if (ent->HasTextDisplay())
487 {
488 S << " Attribute Value Pointer : ";
489 dumper.Dump (ent->AttributeTextDisplay(i,j),S, sublevel);
490 }
491 S << endl;
492 }
493 }
494 }
495 }
496 S << endl;
497}