1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IGESData_FreeFormatEntity.ixx>
15 #include <Interface_UndefinedContent.hxx>
16 #include <Interface_InterfaceError.hxx>
17 #include <IGESData_IGESEntity.hxx>
18 #include <TCollection_HAsciiString.hxx>
19 #include <Interface_Macros.hxx>
23 // Donne un acces simple a la constitution d une UndefinedEntity :
24 // Methodes de UndefinedContent, + Type & Form, + AddEntities (little gadget)
27 IGESData_FreeFormatEntity::IGESData_FreeFormatEntity () { }
29 void IGESData_FreeFormatEntity::SetTypeNumber
30 (const Standard_Integer typenum)
31 { InitTypeAndForm (typenum,0); }
33 void IGESData_FreeFormatEntity::SetFormNumber
34 (const Standard_Integer formnum)
35 { InitTypeAndForm (TypeNumber(), formnum); }
38 Standard_Integer IGESData_FreeFormatEntity::NbParams () const
39 { return UndefinedContent()->NbParams(); }
41 Standard_Boolean IGESData_FreeFormatEntity::ParamData
42 (const Standard_Integer num, Interface_ParamType& ptype,
43 Handle(IGESData_IGESEntity)& ent, Handle(TCollection_HAsciiString)& val) const
44 { return UndefinedContent()->ParamData (num,ptype,ent,val); }
47 Interface_ParamType IGESData_FreeFormatEntity::ParamType
48 (const Standard_Integer num) const
49 { return UndefinedContent()->ParamType(num); }
51 Standard_Boolean IGESData_FreeFormatEntity::IsParamEntity
52 (const Standard_Integer num) const
53 { return UndefinedContent()->IsParamEntity(num); }
55 Handle(IGESData_IGESEntity) IGESData_FreeFormatEntity::ParamEntity
56 (const Standard_Integer num) const
58 return Handle(IGESData_IGESEntity)::DownCast
59 (UndefinedContent()->ParamEntity(num));
62 Standard_Boolean IGESData_FreeFormatEntity::IsNegativePointer
63 (const Standard_Integer num) const
65 if (thenegptrs.IsNull()) return Standard_False;
66 Standard_Integer nb = thenegptrs->Length();
67 for (Standard_Integer i = 1; i <= nb; i ++)
68 if (thenegptrs->Value(i) == num) return Standard_True;
69 return Standard_False;
72 Handle(TCollection_HAsciiString) IGESData_FreeFormatEntity::ParamValue
73 (const Standard_Integer num) const
74 { return UndefinedContent()->ParamValue(num); }
76 Handle(TColStd_HSequenceOfInteger) IGESData_FreeFormatEntity::NegativePointers () const
77 { return thenegptrs; }
80 void IGESData_FreeFormatEntity::AddLiteral
81 (const Interface_ParamType ptype, const Handle(TCollection_HAsciiString)& val)
82 { UndefinedContent()->AddLiteral (ptype,val); }
84 void IGESData_FreeFormatEntity::AddLiteral
85 (const Interface_ParamType ptype, const Standard_CString val)
86 { UndefinedContent()->AddLiteral (ptype,new TCollection_HAsciiString(val)); }
88 void IGESData_FreeFormatEntity::AddEntity
89 (const Interface_ParamType ptype,
90 const Handle(IGESData_IGESEntity)& ent, const Standard_Boolean negative)
92 UndefinedContent()->AddEntity (ptype,ent);
93 if (!negative) return;
94 if (thenegptrs.IsNull()) thenegptrs = new TColStd_HSequenceOfInteger();
95 thenegptrs->Append(NbParams());
98 void IGESData_FreeFormatEntity::AddEntities
99 (const Handle(IGESData_HArray1OfIGESEntity)& ents)
102 AddLiteral ( Interface_ParamInteger, new TCollection_HAsciiString("0") );
105 AddLiteral ( Interface_ParamInteger, new TCollection_HAsciiString(ents->Length()) );
106 Standard_Integer iup = ents->Upper();
107 for (Standard_Integer i = ents->Lower(); i <= iup; i ++) {
108 AddEntity (Interface_ParamIdent,ents->Value(i));
113 void IGESData_FreeFormatEntity::AddNegativePointers
114 (const Handle(TColStd_HSequenceOfInteger)& list)
116 if (thenegptrs.IsNull()) thenegptrs = new TColStd_HSequenceOfInteger();
117 thenegptrs->Append(list);
120 void IGESData_FreeFormatEntity::ClearNegativePointers ()
121 { thenegptrs.Nullify(); }
124 void IGESData_FreeFormatEntity::WriteOwnParams
125 (IGESData_IGESWriter& IW) const
127 // Redefini de UndefinedEntity pour : NegativePointers
128 Standard_Integer neg = 0;
129 Standard_Integer fneg = 0;
130 if (!thenegptrs.IsNull())
131 if (!thenegptrs->IsEmpty()) { neg = thenegptrs->Value(1); fneg = 1; }
133 Standard_Integer nb = UndefinedContent()->NbParams();
134 for (Standard_Integer i = 1; i <= nb; i ++) {
135 Interface_ParamType ptyp = UndefinedContent()->ParamType(i);
136 if (ptyp == Interface_ParamVoid) IW.SendVoid();
137 else if (UndefinedContent()->IsParamEntity(i)) {
138 DeclareAndCast(IGESData_IGESEntity,anent,UndefinedContent()->ParamEntity(i));
139 // Send Entity : Redefini
141 IW.Send(anent,Standard_True);
142 if (fneg >= thenegptrs->Length()) neg = 0;
143 else { fneg ++; neg = thenegptrs->Value(fneg); }
145 else IW.Send(anent,Standard_False);
147 else IW.SendString (UndefinedContent()->ParamValue(i));