0032961: Coding - get rid of unused headers [IGESAppli to IGESToBRep]
[occt.git] / src / IGESData / IGESData_FreeFormatEntity.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <IGESData_FreeFormatEntity.hxx>
16 #include <IGESData_IGESEntity.hxx>
17 #include <IGESData_IGESWriter.hxx>
18 #include <Interface_Macros.hxx>
19 #include <Interface_UndefinedContent.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_HAsciiString.hxx>
22
23 IMPLEMENT_STANDARD_RTTIEXT(IGESData_FreeFormatEntity,IGESData_UndefinedEntity)
24
25 //  Donne un acces simple a la constitution d une UndefinedEntity :
26 //  Methodes de UndefinedContent, + Type & Form, + AddEntities (little gadget)
27 IGESData_FreeFormatEntity::IGESData_FreeFormatEntity ()    {  }
28
29     void  IGESData_FreeFormatEntity::SetTypeNumber
30   (const Standard_Integer typenum)
31 {  InitTypeAndForm (typenum,0);  }
32
33     void  IGESData_FreeFormatEntity::SetFormNumber
34   (const Standard_Integer formnum)
35 {  InitTypeAndForm (TypeNumber(), formnum);  }
36
37
38     Standard_Integer  IGESData_FreeFormatEntity::NbParams () const 
39 {  return UndefinedContent()->NbParams();  }
40
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 {
45   Handle(Standard_Transient) anEnt = ent;
46   return UndefinedContent()->ParamData (num, ptype, anEnt, val) &&
47          ! (ent = Handle(IGESData_IGESEntity)::DownCast (anEnt)).IsNull();
48 }
49
50
51     Interface_ParamType  IGESData_FreeFormatEntity::ParamType
52   (const Standard_Integer num) const 
53 {  return UndefinedContent()->ParamType(num);  }
54
55     Standard_Boolean  IGESData_FreeFormatEntity::IsParamEntity
56   (const Standard_Integer num) const 
57 {  return UndefinedContent()->IsParamEntity(num);  }
58
59     Handle(IGESData_IGESEntity)  IGESData_FreeFormatEntity::ParamEntity
60   (const Standard_Integer num) const
61 {
62   return Handle(IGESData_IGESEntity)::DownCast
63     (UndefinedContent()->ParamEntity(num));
64 }
65
66     Standard_Boolean  IGESData_FreeFormatEntity::IsNegativePointer
67   (const Standard_Integer num) const
68 {
69   if (thenegptrs.IsNull()) return Standard_False;
70   Standard_Integer nb = thenegptrs->Length();
71   for (Standard_Integer i = 1; i <= nb; i ++)
72     if (thenegptrs->Value(i) == num) return Standard_True;
73   return Standard_False;
74 }
75
76     Handle(TCollection_HAsciiString)  IGESData_FreeFormatEntity::ParamValue
77   (const Standard_Integer num) const 
78 {  return UndefinedContent()->ParamValue(num);  }
79
80     Handle(TColStd_HSequenceOfInteger)  IGESData_FreeFormatEntity::NegativePointers () const
81       {  return thenegptrs;  }
82
83
84     void  IGESData_FreeFormatEntity::AddLiteral
85   (const Interface_ParamType ptype, const Handle(TCollection_HAsciiString)& val)
86 {  UndefinedContent()->AddLiteral (ptype,val);  }
87
88     void  IGESData_FreeFormatEntity::AddLiteral
89   (const Interface_ParamType ptype, const Standard_CString val)
90 {  UndefinedContent()->AddLiteral (ptype,new TCollection_HAsciiString(val));  }
91
92     void  IGESData_FreeFormatEntity::AddEntity
93   (const Interface_ParamType ptype,
94    const Handle(IGESData_IGESEntity)& ent, const Standard_Boolean negative)
95 {
96   UndefinedContent()->AddEntity (ptype,ent);
97   if (!negative) return;
98   if (thenegptrs.IsNull()) thenegptrs = new TColStd_HSequenceOfInteger();
99   thenegptrs->Append(NbParams());
100 }
101
102     void  IGESData_FreeFormatEntity::AddEntities
103   (const Handle(IGESData_HArray1OfIGESEntity)& ents)
104 {
105   if (ents.IsNull()) {
106     AddLiteral ( Interface_ParamInteger, new TCollection_HAsciiString("0") );
107     return;
108   }
109   AddLiteral ( Interface_ParamInteger, new TCollection_HAsciiString(ents->Length()) );
110   Standard_Integer iup = ents->Upper();
111   for (Standard_Integer i = ents->Lower(); i <= iup; i ++) {
112     AddEntity (Interface_ParamIdent,ents->Value(i));
113   }
114 }
115
116     
117     void  IGESData_FreeFormatEntity::AddNegativePointers
118   (const Handle(TColStd_HSequenceOfInteger)& list)
119 {
120   if (thenegptrs.IsNull()) thenegptrs = new TColStd_HSequenceOfInteger();
121   thenegptrs->Append(list);
122 }
123
124     void  IGESData_FreeFormatEntity::ClearNegativePointers ()
125       {  thenegptrs.Nullify();  }
126
127
128     void IGESData_FreeFormatEntity::WriteOwnParams
129   (IGESData_IGESWriter& IW) const
130 {
131 //  Redefini de UndefinedEntity pour : NegativePointers
132   Standard_Integer neg  = 0;
133   Standard_Integer fneg = 0;
134   if (!thenegptrs.IsNull())
135     if (!thenegptrs->IsEmpty())  {  neg = thenegptrs->Value(1);  fneg = 1;  }
136
137   Standard_Integer nb = UndefinedContent()->NbParams();
138   for (Standard_Integer i = 1; i <= nb; i ++) {
139     Interface_ParamType ptyp = UndefinedContent()->ParamType(i);
140     if (ptyp == Interface_ParamVoid) IW.SendVoid();
141     else if (UndefinedContent()->IsParamEntity(i)) {
142       DeclareAndCast(IGESData_IGESEntity,anent,UndefinedContent()->ParamEntity(i));
143 //  Send Entity : Redefini
144       if (i == neg) {
145         IW.Send(anent,Standard_True);
146         if (fneg >= thenegptrs->Length()) neg = 0;
147         else  {  fneg ++;  neg = thenegptrs->Value(fneg);  }
148       }
149       else IW.Send(anent,Standard_False);
150     }
151     else IW.SendString (UndefinedContent()->ParamValue(i));
152   }
153 }