1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
20 //--------------------------------------------------------------------
21 //--------------------------------------------------------------------
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>
40 IGESDefs_ToolAttributeDef::IGESDefs_ToolAttributeDef () { }
43 void IGESDefs_ToolAttributeDef::ReadOwnParams
44 (const Handle(IGESDefs_AttributeDef)& ent,
45 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
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();
58 if (PR.DefinedElseSkip())
59 PR.ReadText(PR.Current(), "Attribute Table Name", aName); //szv#4:S4163:12Mar99 `st=` not needed
61 PR.ReadInteger(PR.Current(), "Attribute List Type", aListType); //szv#4:S4163:12Mar99 `st=` not needed
63 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Attributes", nbval);
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);
74 else PR.AddFail("Number of Attributes: Not Positive");
76 if ( ! attrTypes.IsNull())
77 for (Standard_Integer i = 1; i <= nbval; i++)
79 Standard_Integer attrType;
80 Standard_Integer attrValueDataType;
82 // Value according type
83 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
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);
89 st = PR.ReadInteger(PR.Current(),"Attribute Data Type",attrValueDataType);
90 if (st) attrValueDataTypes->SetValue(i, attrValueDataType);
92 if (PR.DefinedElseSkip())
93 st = PR.ReadInteger (PR.Current(),"Attribute Value Count",avc);
97 attrValueCounts->SetValue(i, avc);
98 if (fn > 1) attrValuePointer =
99 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
102 if (! attrValues.IsNull())
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;
122 for (Standard_Integer j = 1; j <= avc; j++)
124 switch(attrValueDataType)
128 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // passer
129 //// attrValue->SetValue(j, NULL); par defaut
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);
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);
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);
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);
165 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
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));
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);
187 attrValuePointers->SetValue(i, attrValuePointer);
191 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
193 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
194 attrValues, attrValuePointers);
197 void IGESDefs_ToolAttributeDef::WriteOwnParams
198 (const Handle(IGESDefs_AttributeDef)& ent, IGESData_IGESWriter& IW) const
200 if (ent->HasTableName()) IW.Send(ent->TableName());
202 IW.Send(ent->ListType());
203 Standard_Integer upper = ent->NbAttributes();
206 for (Standard_Integer i = 1; i <= upper; i++)
208 Standard_Integer check = ent->AttributeValueDataType(i);
209 Standard_Integer count = ent->AttributeValueCount(i);
210 IW.Send(ent->AttributeType(i));
213 if (ent->FormNumber() > 0)
215 for (Standard_Integer j = 1; j <= count; j++)
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;
227 if ( ent->FormNumber() == 2)
228 IW.Send(ent->AttributeTextDisplay(i,j));
234 void IGESDefs_ToolAttributeDef::OwnShared
235 (const Handle(IGESDefs_AttributeDef)& ent, Interface_EntityIterator& iter) const
237 Standard_Integer upper = ent->NbAttributes();
238 for (Standard_Integer i = 1; i <= upper; i++)
240 Standard_Integer check = ent->AttributeValueDataType(i);
241 Standard_Integer count = ent->AttributeValueCount(i);
242 if (ent->FormNumber() > 0)
244 for (Standard_Integer j = 1; j <= count; j++)
246 if ( check == 4 ) iter.GetOneItem(ent->AttributeAsEntity(i,j));
247 if ( ent->FormNumber() == 2)
248 iter.GetOneItem(ent->AttributeTextDisplay(i,j));
255 void IGESDefs_ToolAttributeDef::OwnCopy
256 (const Handle(IGESDefs_AttributeDef)& another,
257 const Handle(IGESDefs_AttributeDef)& ent, Interface_CopyTool& TC) const
259 Handle(TCollection_HAsciiString) aName;
260 if (!another->TableName().IsNull()) aName =
261 new TCollection_HAsciiString(another->TableName());
262 Standard_Integer aListType = another->ListType();
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();
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);
279 for (Standard_Integer i = 1; i <= nbval; i++)
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;
289 if (another->HasTextDisplay()) attrValuePointer =
290 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
292 if (another->HasValues())
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;
311 for (Standard_Integer j = 1; j <= avc; j ++)
313 switch(attrValueDataType)
317 case 1: attrInt->SetValue(j,another->AttributeAsInteger(i,j));
319 case 2: attrReal->SetValue(j,another->AttributeAsReal(i,j));
321 case 3: attrStr->SetValue(j,new TCollection_HAsciiString
322 (another->AttributeAsString(i,j)));
325 DeclareAndCast(IGESData_IGESEntity,Ent,TC.Transferred
326 (another->AttributeAsEntity(i,j)));
327 attrEnt->SetValue(j,Ent);
332 case 6: attrInt->SetValue
333 (j,(another->AttributeAsLogical(i,j) ? 1 : 0));
337 if (another->HasTextDisplay())
339 DeclareAndCast(IGESGraph_TextDisplayTemplate, temptext,
340 TC.Transferred(another->AttributeTextDisplay(i,j)));
341 attrValuePointer->SetValue (j, temptext);
344 if (another->HasTextDisplay())
345 attrValuePointers->SetValue(i, attrValuePointer);
349 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
350 attrValues, attrValuePointers);
353 IGESData_DirChecker IGESDefs_ToolAttributeDef::DirChecker
354 (const Handle(IGESDefs_AttributeDef)& /* ent */ ) const
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);
368 void IGESDefs_ToolAttributeDef::OwnCheck
369 (const Handle(IGESDefs_AttributeDef)& ent,
370 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
372 Standard_Integer nb = ent->NbAttributes();
373 Standard_Integer fn = ent->FormNumber();
374 for (Standard_Integer i = 1; i <= nb; i ++) {
376 if (ent->AttributeType(i) < 0 || ent->AttributeType(i) > 9999) {
377 sprintf(mess,"Attribute Type n0.%d not in <0 - 9999>", ent->AttributeType(i));
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);
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);
393 else if (fn == 0) continue;
396 case 1 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
397 sprintf(mess,"Attribute List n0.%d (Integers) badly defined", aty);
399 case 2 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfReal)))
400 sprintf(mess,"Attribute List n0.%d (Reals) badly defined", aty);
402 case 3 : if (!list->IsKind(STANDARD_TYPE(Interface_HArray1OfHAsciiString)))
403 sprintf(mess,"Attribute List n0.%d (Strings) badly defined", aty);
405 case 4 : if (!list->IsKind(STANDARD_TYPE(IGESData_HArray1OfIGESEntity)))
406 sprintf(mess,"Attribute List n0.%d (IGES Pointers) badly defined", aty);
408 case 6 : if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
409 sprintf(mess,"Attribute List n0.%d (Logicals i.e. Integers) badly defined", aty);
413 if (mess[0] != '\0') ach->AddFail(mess);
418 void IGESDefs_ToolAttributeDef::OwnDump
419 (const Handle(IGESDefs_AttributeDef)& ent, const IGESData_IGESDumper& dumper,
420 const Handle(Message_Messenger)& S, const Standard_Integer level) const
422 Standard_Integer sublevel = (level > 4) ? 1 : 0;
424 S << "IGESDefs_AttributeDef" << endl;
425 S << "Attribute Table Name: ";
426 IGESData_DumpString(S,ent->TableName());
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);
439 Standard_Integer upper = ent->NbAttributes();
440 for (Standard_Integer i = 1; i <= upper ; i ++)
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;
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;
457 S << " Count : " << avc << endl;
458 if (ent->HasValues())
461 S << " [ content (Values) : ask level > 5 ]" << endl;
464 for (Standard_Integer j = 1; j <= avc; j ++)
466 S << "[" << j << "]: ";
467 switch(ent->AttributeValueDataType(i))
469 case 0: S << "(Void) ";
471 case 1: S << ent->AttributeAsInteger(i,j);
473 case 2: S << ent->AttributeAsReal(i,j);
475 case 3: IGESData_DumpString(S,ent->AttributeAsString(i,j));
477 case 4: dumper.Dump(ent->AttributeAsEntity(i,j),S,level-5);
479 case 5: S << "(Not Used)";
482 S << ( ent->AttributeAsLogical(i,j) ? "True" : "False");
486 if (ent->HasTextDisplay())
488 S << " Attribute Value Pointer : ";
489 dumper.Dump (ent->AttributeTextDisplay(i,j),S, sublevel);