1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
19 #include <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.hxx>
21 #include <IGESData_HArray1OfIGESEntity.hxx>
22 #include <IGESData_IGESDumper.hxx>
23 #include <IGESData_IGESEntity.hxx>
24 #include <IGESData_IGESReaderData.hxx>
25 #include <IGESData_IGESWriter.hxx>
26 #include <IGESData_ParamCursor.hxx>
27 #include <IGESData_ParamReader.hxx>
28 #include <IGESDefs_AttributeDef.hxx>
29 #include <IGESDefs_HArray1OfHArray1OfTextDisplayTemplate.hxx>
30 #include <IGESDefs_ToolAttributeDef.hxx>
31 #include <IGESGraph_HArray1OfTextDisplayTemplate.hxx>
32 #include <IGESGraph_TextDisplayTemplate.hxx>
33 #include <Interface_Check.hxx>
34 #include <Interface_CopyTool.hxx>
35 #include <Interface_EntityIterator.hxx>
36 #include <Interface_HArray1OfHAsciiString.hxx>
37 #include <Interface_Macros.hxx>
38 #include <Interface_ShareTool.hxx>
39 #include <Message_Messenger.hxx>
40 #include <Standard_DomainError.hxx>
41 #include <TCollection_HAsciiString.hxx>
42 #include <TColStd_HArray1OfInteger.hxx>
43 #include <TColStd_HArray1OfReal.hxx>
44 #include <TColStd_HArray1OfTransient.hxx>
47 IGESDefs_ToolAttributeDef::IGESDefs_ToolAttributeDef () { }
50 void IGESDefs_ToolAttributeDef::ReadOwnParams
51 (const Handle(IGESDefs_AttributeDef)& ent,
52 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
54 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
55 Handle(TCollection_HAsciiString) aName;
56 Standard_Integer aListType;
57 Handle(TColStd_HArray1OfInteger) attrTypes;
58 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
59 Handle(TColStd_HArray1OfInteger) attrValueCounts;
60 Handle(TColStd_HArray1OfTransient) attrValues;
61 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
62 Standard_Integer nbval;
63 Standard_Integer fn = ent->FormNumber();
65 if (PR.DefinedElseSkip())
66 PR.ReadText(PR.Current(), "Attribute Table Name", aName); //szv#4:S4163:12Mar99 `st=` not needed
68 PR.ReadInteger(PR.Current(), "Attribute List Type", aListType); //szv#4:S4163:12Mar99 `st=` not needed
70 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Attributes", nbval);
73 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
74 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
75 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
76 if (fn > 0) attrValues =
77 new TColStd_HArray1OfTransient(1, nbval);
78 if (fn > 1) attrValuePointers =
79 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
81 else PR.AddFail("Number of Attributes: Not Positive");
83 if ( ! attrTypes.IsNull())
84 for (Standard_Integer i = 1; i <= nbval; i++)
86 Standard_Integer attrType;
87 Standard_Integer attrValueDataType;
89 // Value according type
90 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
92 //st = PR.ReadInteger(PR.Current(), "Attribute Type", attrType); //szv#4:S4163:12Mar99 moved in if
93 if (PR.ReadInteger(PR.Current(), "Attribute Type", attrType))
94 attrTypes->SetValue(i, attrType);
96 st = PR.ReadInteger(PR.Current(),"Attribute Data Type",attrValueDataType);
97 if (st) attrValueDataTypes->SetValue(i, attrValueDataType);
99 if (PR.DefinedElseSkip())
100 st = PR.ReadInteger (PR.Current(),"Attribute Value Count",avc);
104 attrValueCounts->SetValue(i, avc);
105 if (fn > 1) attrValuePointer =
106 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
109 if (! attrValues.IsNull())
112 Handle(TColStd_HArray1OfInteger) attrInt;
113 Handle(TColStd_HArray1OfReal) attrReal;
114 Handle(Interface_HArray1OfHAsciiString) attrStr;
115 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
116 switch (attrValueDataType) {
117 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
118 attrValues->SetValue(i,attrInt); break;
119 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
120 attrValues->SetValue(i,attrReal); break;
121 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
122 attrValues->SetValue(i,attrStr); break;
123 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
124 attrValues->SetValue(i,attrEnt); break;
125 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
126 attrValues->SetValue(i,attrInt); break;
129 for (Standard_Integer j = 1; j <= avc; j++)
131 switch(attrValueDataType)
135 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // passer
136 //// attrValue->SetValue(j, NULL); par defaut
141 Standard_Integer temp;
142 //st = PR.ReadInteger(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
143 if (PR.ReadInteger(PR.Current(), "Attribute Value", temp))
144 attrInt->SetValue(j, temp);
150 //st = PR.ReadReal(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
151 if (PR.ReadReal(PR.Current(), "Attribute Value", temp))
152 attrReal->SetValue(j, temp);
157 Handle(TCollection_HAsciiString) temp;
158 //st = PR.ReadText(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
159 if (PR.ReadText(PR.Current(), "Attribute Value", temp))
160 attrStr->SetValue(j, temp);
165 Handle(IGESData_IGESEntity) temp;
166 //st = PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
167 if (PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp))
168 attrEnt->SetValue(j, temp);
172 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
176 Standard_Boolean temp;
177 //st = PR.ReadBoolean(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
178 if (PR.ReadBoolean(PR.Current(), "Attribute Value", temp))
179 attrInt->SetValue(j, (temp ? 1 : 0));
185 Handle(IGESGraph_TextDisplayTemplate) tempText;
186 //st = PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
187 //STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText); //szv#4:S4163:12Mar99 moved in if
188 if (PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
189 STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText))
190 attrValuePointer->SetValue(j, tempText);
194 attrValuePointers->SetValue(i, attrValuePointer);
198 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
200 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
201 attrValues, attrValuePointers);
204 void IGESDefs_ToolAttributeDef::WriteOwnParams
205 (const Handle(IGESDefs_AttributeDef)& ent, IGESData_IGESWriter& IW) const
207 if (ent->HasTableName()) IW.Send(ent->TableName());
209 IW.Send(ent->ListType());
210 Standard_Integer upper = ent->NbAttributes();
213 for (Standard_Integer i = 1; i <= upper; i++)
215 Standard_Integer check = ent->AttributeValueDataType(i);
216 Standard_Integer count = ent->AttributeValueCount(i);
217 IW.Send(ent->AttributeType(i));
220 if (ent->FormNumber() > 0)
222 for (Standard_Integer j = 1; j <= count; j++)
225 case 0 : IW.SendVoid(); break;
226 case 1 : IW.Send(ent->AttributeAsInteger(i,j)); break;
227 case 2 : IW.Send(ent->AttributeAsReal(i,j)); break;
228 case 3 : IW.Send(ent->AttributeAsString(i,j)); break;
229 case 4 : IW.Send(ent->AttributeAsEntity(i,j)); break;
230 case 5 : IW.SendVoid(); break;
231 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,j)); break;
234 if ( ent->FormNumber() == 2)
235 IW.Send(ent->AttributeTextDisplay(i,j));
241 void IGESDefs_ToolAttributeDef::OwnShared
242 (const Handle(IGESDefs_AttributeDef)& ent, Interface_EntityIterator& iter) const
244 Standard_Integer upper = ent->NbAttributes();
245 for (Standard_Integer i = 1; i <= upper; i++)
247 Standard_Integer check = ent->AttributeValueDataType(i);
248 Standard_Integer count = ent->AttributeValueCount(i);
249 if (ent->FormNumber() > 0)
251 for (Standard_Integer j = 1; j <= count; j++)
253 if ( check == 4 ) iter.GetOneItem(ent->AttributeAsEntity(i,j));
254 if ( ent->FormNumber() == 2)
255 iter.GetOneItem(ent->AttributeTextDisplay(i,j));
262 void IGESDefs_ToolAttributeDef::OwnCopy
263 (const Handle(IGESDefs_AttributeDef)& another,
264 const Handle(IGESDefs_AttributeDef)& ent, Interface_CopyTool& TC) const
266 Handle(TCollection_HAsciiString) aName;
267 if (!another->TableName().IsNull()) aName =
268 new TCollection_HAsciiString(another->TableName());
269 Standard_Integer aListType = another->ListType();
271 Handle(TColStd_HArray1OfInteger) attrTypes;
272 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
273 Handle(TColStd_HArray1OfInteger) attrValueCounts;
274 Handle(TColStd_HArray1OfTransient) attrValues;
275 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
276 Standard_Integer nbval = another->NbAttributes();
278 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
279 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
280 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
281 if (another->HasValues()) attrValues =
282 new TColStd_HArray1OfTransient(1, nbval);
283 if (another->HasTextDisplay()) attrValuePointers =
284 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
286 for (Standard_Integer i = 1; i <= nbval; i++)
288 Standard_Integer attrType = another->AttributeType(i);
289 attrTypes->SetValue(i, attrType);
290 Standard_Integer attrValueDataType = another->AttributeValueDataType(i);
291 attrValueDataTypes->SetValue(i, attrValueDataType);
292 Standard_Integer avc = another->AttributeValueCount(i);
293 attrValueCounts->SetValue(i, avc);
294 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
296 if (another->HasTextDisplay()) attrValuePointer =
297 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
299 if (another->HasValues())
301 Handle(TColStd_HArray1OfInteger) attrInt;
302 Handle(TColStd_HArray1OfReal) attrReal;
303 Handle(Interface_HArray1OfHAsciiString) attrStr;
304 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
305 switch (attrValueDataType) {
306 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
307 attrValues->SetValue(i,attrInt); break;
308 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
309 attrValues->SetValue(i,attrReal); break;
310 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
311 attrValues->SetValue(i,attrStr); break;
312 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
313 attrValues->SetValue(i,attrEnt); break;
314 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
315 attrValues->SetValue(i,attrInt); break;
318 for (Standard_Integer j = 1; j <= avc; j ++)
320 switch(attrValueDataType)
324 case 1: attrInt->SetValue(j,another->AttributeAsInteger(i,j));
326 case 2: attrReal->SetValue(j,another->AttributeAsReal(i,j));
328 case 3: attrStr->SetValue(j,new TCollection_HAsciiString
329 (another->AttributeAsString(i,j)));
332 DeclareAndCast(IGESData_IGESEntity,Ent,TC.Transferred
333 (another->AttributeAsEntity(i,j)));
334 attrEnt->SetValue(j,Ent);
339 case 6: attrInt->SetValue
340 (j,(another->AttributeAsLogical(i,j) ? 1 : 0));
344 if (another->HasTextDisplay())
346 DeclareAndCast(IGESGraph_TextDisplayTemplate, temptext,
347 TC.Transferred(another->AttributeTextDisplay(i,j)));
348 attrValuePointer->SetValue (j, temptext);
351 if (another->HasTextDisplay())
352 attrValuePointers->SetValue(i, attrValuePointer);
356 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
357 attrValues, attrValuePointers);
360 IGESData_DirChecker IGESDefs_ToolAttributeDef::DirChecker
361 (const Handle(IGESDefs_AttributeDef)& /* ent */ ) const
363 IGESData_DirChecker DC (322, 0, 2);
364 DC.Structure(IGESData_DefVoid);
365 DC.LineFont(IGESData_DefAny);
366 DC.LineWeight(IGESData_DefValue);
367 DC.Color(IGESData_DefAny);
368 DC.BlankStatusIgnored();
369 DC.SubordinateStatusRequired(0);
370 DC.UseFlagRequired(2);
371 DC.GraphicsIgnored(1);
375 void IGESDefs_ToolAttributeDef::OwnCheck
376 (const Handle(IGESDefs_AttributeDef)& ent,
377 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
379 Standard_Integer nb = ent->NbAttributes();
380 Standard_Integer fn = ent->FormNumber();
381 for (Standard_Integer i = 1; i <= nb; i ++) {
383 if (ent->AttributeType(i) < 0 || ent->AttributeType(i) > 9999) {
384 sprintf(mess,"Attribute Type n0.%d not in <0 - 9999>", ent->AttributeType(i));
387 Standard_Integer aty = ent->AttributeValueDataType(i);
388 if (aty < 0 || aty > 6) {
389 sprintf(mess,"Attribute Value Data Type n0.%d not in <0 - 6>", aty);
392 if (ent->AttributeValueCount(i) <= 0) continue;
393 Handle(Standard_Transient) list = ent->AttributeList(i);
394 if (fn > 0 && ent.IsNull()) {
395 if (aty == 0 || aty == 5) continue;
396 sprintf(mess,"Form Number > 0 and Attribute Value List n0.%d undefined", aty);
400 else if (fn == 0) continue;
403 case 1 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
404 sprintf(mess,"Attribute List n0.%d (Integers) badly defined", aty);
406 case 2 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfReal)))
407 sprintf(mess,"Attribute List n0.%d (Reals) badly defined", aty);
409 case 3 : if (!list->IsKind(STANDARD_TYPE(Interface_HArray1OfHAsciiString)))
410 sprintf(mess,"Attribute List n0.%d (Strings) badly defined", aty);
412 case 4 : if (!list->IsKind(STANDARD_TYPE(IGESData_HArray1OfIGESEntity)))
413 sprintf(mess,"Attribute List n0.%d (IGES Pointers) badly defined", aty);
415 case 6 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
416 sprintf(mess,"Attribute List n0.%d (Logicals i.e. Integers) badly defined", aty);
420 if (mess[0] != '\0') ach->AddFail(mess);
425 void IGESDefs_ToolAttributeDef::OwnDump
426 (const Handle(IGESDefs_AttributeDef)& ent, const IGESData_IGESDumper& dumper,
427 const Handle(Message_Messenger)& S, const Standard_Integer level) const
429 Standard_Integer sublevel = (level > 4) ? 1 : 0;
431 S << "IGESDefs_AttributeDef" << endl;
432 S << "Attribute Table Name: ";
433 IGESData_DumpString(S,ent->TableName());
435 S << "Attribute List Type : " << ent->ListType() << endl;
436 S << "Number of Attributes : " << ent->NbAttributes() << endl;
437 S << "Attribute Types : " << endl;
438 S << "Attribute Value Data Types : " << endl;
439 S << "Attribute Value Counts : " << endl;
440 if (ent->HasValues()) S << "Attribute Values : " << endl;
441 if (ent->HasTextDisplay()) S << "Attribute Value Entities : " << endl;
442 IGESData_DumpVals(S,-level,1, ent->NbAttributes(),ent->AttributeType);
446 Standard_Integer upper = ent->NbAttributes();
447 for (Standard_Integer i = 1; i <= upper ; i ++)
449 Standard_Integer avc = ent->AttributeValueCount(i);
450 Standard_Integer typ = ent->AttributeValueDataType(i);
451 S << "[" << i << "]: ";
452 S << "Attribute Type : " << ent->AttributeType(i) << " ";
453 S << "Value Data Type : " << typ;
455 case 0 : S << " (Void)"; break;
456 case 1 : S << " : Integer "; break;
457 case 2 : S << " : Real "; break;
458 case 3 : S << " : String "; break;
459 case 4 : S << " : Entity "; break;
460 case 5 : S << " (Not Used)"; break;
461 case 6 : S << " : Logical "; break;
464 S << " Count : " << avc << endl;
465 if (ent->HasValues())
468 S << " [ content (Values) : ask level > 5 ]" << endl;
471 for (Standard_Integer j = 1; j <= avc; j ++)
473 S << "[" << j << "]: ";
474 switch(ent->AttributeValueDataType(i))
476 case 0: S << "(Void) ";
478 case 1: S << ent->AttributeAsInteger(i,j);
480 case 2: S << ent->AttributeAsReal(i,j);
482 case 3: IGESData_DumpString(S,ent->AttributeAsString(i,j));
484 case 4: dumper.Dump(ent->AttributeAsEntity(i,j),S,level-5);
486 case 5: S << "(Not Used)";
489 S << ( ent->AttributeAsLogical(i,j) ? "True" : "False");
493 if (ent->HasTextDisplay())
495 S << " Attribute Value Pointer : ";
496 dumper.Dump (ent->AttributeTextDisplay(i,j),S, sublevel);