0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / IGESDefs / IGESDefs_ToolGenericData.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
7fd59977 6//
d5f74e42 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
973c2be1 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.
7fd59977 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16//--------------------------------------------------------------------
7fd59977 17//--------------------------------------------------------------------
18
42cf5bc1 19#include <IGESData_DirChecker.hxx>
20#include <IGESData_Dump.hxx>
7fd59977 21#include <IGESData_HArray1OfIGESEntity.hxx>
42cf5bc1 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_GenericData.hxx>
29#include <IGESDefs_ToolGenericData.hxx>
30#include <Interface_Check.hxx>
31#include <Interface_CopyTool.hxx>
32#include <Interface_EntityIterator.hxx>
7fd59977 33#include <Interface_HArray1OfHAsciiString.hxx>
34#include <Interface_Macros.hxx>
42cf5bc1 35#include <Interface_ShareTool.hxx>
36#include <Message_Messenger.hxx>
37#include <Standard_DomainError.hxx>
38#include <TCollection_HAsciiString.hxx>
39#include <TColStd_HArray1OfInteger.hxx>
40#include <TColStd_HArray1OfReal.hxx>
41#include <TColStd_HArray1OfTransient.hxx>
7fd59977 42
43IGESDefs_ToolGenericData::IGESDefs_ToolGenericData () { }
44
45
46void IGESDefs_ToolGenericData::ReadOwnParams
47 (const Handle(IGESDefs_GenericData)& ent,
48 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
49{
50 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
51 Standard_Integer i, num;
52 Standard_Integer tempNbPropVal;
53 Handle(TCollection_HAsciiString) tempName;
54 Handle(TColStd_HArray1OfInteger) tempTypes;
55 Handle(TColStd_HArray1OfTransient) tempValues;
56
57 PR.ReadInteger(PR.Current(), "Number of property values", tempNbPropVal); //szv#4:S4163:12Mar99 `st=` not needed
58
59 PR.ReadText(PR.Current(), "Property Name", tempName); //szv#4:S4163:12Mar99 `st=` not needed
60
61 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of TYPE/VALUEs", num);
62 if (st && num > 0)
63 {
64 tempTypes = new TColStd_HArray1OfInteger(1, num);
65 tempValues = new TColStd_HArray1OfTransient(1, num);
66 }
67 else PR.AddFail("Number of TYPE/VALUEs: Not Positive");
68
69 if (!tempTypes.IsNull() && !tempValues.IsNull())
70 for ( i = 1; i <= num; i++ )
71 {
72 Standard_Integer tempTyp;
73 PR.ReadInteger(PR.Current(), "Type code", tempTyp); //szv#4:S4163:12Mar99 `st=` not needed
74 tempTypes->SetValue(i, tempTyp);
75 switch (tempTyp)
76 {
77 case 0: // No value
78 PR.SetCurrentNumber(PR.CurrentNumber()+1);
79 break;
80 case 1: // Integer
81 {
82 Handle(TColStd_HArray1OfInteger) tempObj;
83 //st = PR.ReadInts(PR.CurrentList(1), "Integer value", tempObj); //szv#4:S4163:12Mar99 moved in if
84 if (PR.ReadInts(PR.CurrentList(1), "Integer value", tempObj))
85 tempValues->SetValue(i, tempObj);
86 }
87 break;
88 case 2: // Real
89 {
90 Handle(TColStd_HArray1OfReal) tempObj;
91 //st = PR.ReadReals(PR.CurrentList(1), "Real value", tempObj); //szv#4:S4163:12Mar99 moved in if
92 if (PR.ReadReals(PR.CurrentList(1), "Real value", tempObj))
93 tempValues->SetValue(i, tempObj);
94 }
95 break;
96 case 3: // Character string
97 {
98 Handle(TCollection_HAsciiString) tempObj;
99 //st = PR.ReadText(PR.Current(), "String value", tempObj); //szv#4:S4163:12Mar99 moved in if
100 if (PR.ReadText(PR.Current(), "String value", tempObj))
101 tempValues->SetValue(i, tempObj);
102 }
103 break;
104 case 4: // Pointer
105 {
106 Handle(IGESData_IGESEntity) tempEntity;
107 //st = PR.ReadEntity(IR, PR.Current(), "Entity value", tempEntity); //szv#4:S4163:12Mar99 moved in if
108 if (PR.ReadEntity(IR, PR.Current(), "Entity value", tempEntity))
109 tempValues->SetValue(i, tempEntity);
110 }
111 break;
112 case 5: // Not used
113 PR.SetCurrentNumber(PR.CurrentNumber()+1);
114 break;
115 case 6: // Logical
116 {
117 Handle(TColStd_HArray1OfInteger) tempObj = new TColStd_HArray1OfInteger(1, 1);
118 Standard_Boolean tempBool;
119 //st = PR.ReadBoolean(PR.Current(), "Boolean value", tempBool); //szv#4:S4163:12Mar99 moved in if
120 if (PR.ReadBoolean(PR.Current(), "Boolean value", tempBool)) {
121 tempObj->SetValue(1, (tempBool ? 1 : 0));
122 tempValues->SetValue(i, tempObj);
123 }
124 }
125 break;
126 }
127 }
128
129 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
130 ent->Init (tempNbPropVal, tempName, tempTypes, tempValues);
131}
132
133void IGESDefs_ToolGenericData::WriteOwnParams
134 (const Handle(IGESDefs_GenericData)& ent, IGESData_IGESWriter& IW) const
135{
136 Standard_Integer i, num;
137 IW.Send(ent->NbPropertyValues());
138 IW.Send(ent->Name());
139 IW.Send(ent->NbTypeValuePairs());
140 for ( num = ent->NbTypeValuePairs(), i = 1; i <= num; i++ )
141 {
142 IW.Send(ent->Type(i));
143 switch (ent->Type(i))
144 {
145 case 0 : IW.SendVoid(); break;
146 case 1 : IW.Send(ent->ValueAsInteger(i)); break;
147 case 2 : IW.Send(ent->ValueAsReal(i)); break;
148 case 3 : IW.Send(ent->ValueAsString(i)); break;
149 case 4 : IW.Send(ent->ValueAsEntity(i)); break;
150 case 5 : IW.SendVoid(); break;
151 case 6 : IW.SendBoolean(ent->ValueAsLogical(i)); break;
152 default : break;
153 }
154 }
155}
156
157void IGESDefs_ToolGenericData::OwnShared
158 (const Handle(IGESDefs_GenericData)& ent, Interface_EntityIterator& iter) const
159{
160 Standard_Integer i, num;
161 for ( num = ent->NbTypeValuePairs(), i = 1; i <= num; i++ )
162 {
163 if (ent->Type(i) == 4)
164 iter.GetOneItem(ent->ValueAsEntity(i));
165 }
166}
167
168void IGESDefs_ToolGenericData::OwnCopy
169 (const Handle(IGESDefs_GenericData)& another,
170 const Handle(IGESDefs_GenericData)& ent, Interface_CopyTool& TC) const
171{
172 Standard_Integer num = another->NbTypeValuePairs();
173 Standard_Integer tempNbPropVal = another->NbPropertyValues();
174 Handle(TCollection_HAsciiString) tempName =
175 new TCollection_HAsciiString(another->Name());
176 Handle(TColStd_HArray1OfInteger) tempTypes =
177 new TColStd_HArray1OfInteger(1, num);
178 Handle(TColStd_HArray1OfTransient) tempValues =
179 new TColStd_HArray1OfTransient(1, num);
180
181 for (Standard_Integer i = 1; i <= num; i++)
182 {
183 tempTypes->SetValue(i, another->Type(i));
184 switch (another->Type(i))
185 {
186 case 0: // No value
187 break;
188 case 1: // Integer
189 {
190 Handle(TColStd_HArray1OfInteger) tempObj =
191 new TColStd_HArray1OfInteger(1,1);
192 tempObj->SetValue(1,another->ValueAsInteger(i));
193 tempValues->SetValue(i, tempObj);
194 }
195 break;
196 case 2: // Real
197 {
198 Handle(TColStd_HArray1OfReal) tempObj =
199 new TColStd_HArray1OfReal(1,1);
200 tempObj->SetValue(1,another->ValueAsReal(i));
201 tempValues->SetValue(i, tempObj);
202 }
203 break;
204 case 3: // Character string
205 {
206 tempValues->SetValue
207 (i, new TCollection_HAsciiString(another->ValueAsString(i)));
208 }
209 break;
210 case 4: // Pointer
211 {
212 DeclareAndCast(IGESData_IGESEntity, tempObj,
213 TC.Transferred(another->ValueAsEntity(i)));
214 tempValues->SetValue(i, tempObj);
215 }
216 break;
217 case 5: // Not used
218 break;
219 case 6: // Logical
220 {
221 Handle(TColStd_HArray1OfInteger) tempObj =
222 new TColStd_HArray1OfInteger(1,1);
223 tempObj->SetValue(1, (another->ValueAsLogical(i) ? 1 : 0) );
224 tempValues->SetValue(i, tempObj);
225 }
226 break;
227 }
228 }
229 ent->Init (tempNbPropVal, tempName, tempTypes, tempValues);
230}
231
232IGESData_DirChecker IGESDefs_ToolGenericData::DirChecker
233 (const Handle(IGESDefs_GenericData)& /* ent */ ) const
234{
235 IGESData_DirChecker DC(406, 27);
236 DC.Structure(IGESData_DefVoid);
237 DC.GraphicsIgnored();
238 DC.LineFont(IGESData_DefVoid);
239 DC.LineWeight(IGESData_DefVoid);
240 DC.Color(IGESData_DefVoid);
241 DC.BlankStatusIgnored();
242 DC.SubordinateStatusRequired(1);
243 DC.UseFlagRequired(2);
244 DC.HierarchyStatusIgnored();
245 return DC;
246}
247
248void IGESDefs_ToolGenericData::OwnCheck
249 (const Handle(IGESDefs_GenericData)& ent,
250 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
251{
252 if (ent->NbPropertyValues() != ent->NbTypeValuePairs()*2 + 2)
253 ach->AddFail("Nb. of Property Values not consistent with Nb. of Type/value Pairs");
254}
255
256void IGESDefs_ToolGenericData::OwnDump
257 (const Handle(IGESDefs_GenericData)& ent, const IGESData_IGESDumper& dumper,
258 const Handle(Message_Messenger)& S, const Standard_Integer level) const
259{
260 S << "IGESDefs_GenericData" << endl;
261 S << "Number of property values : " << ent->NbPropertyValues() << endl;
262 S << "Property Name : ";
263 IGESData_DumpString(S,ent->Name());
264 S << endl;
265 switch (level)
266 {
267 case 4:
268 S << "Types : " << endl;
586db386 269 S << "Values : Count = " << ent->NbTypeValuePairs() << endl;
7fd59977 270 S << " [ as level > 4 for content ]" << endl;
271 break;
272 case 5:
273 case 6:
274 {
275 Standard_Integer i, num;
276 S << "Types & Values : " << endl;
277 for ( num = ent->NbTypeValuePairs(), i = 1; i <= num; i++ )
278 {
279 S << "[" << i << "]: ";
280 S << "Type : " << ent->Type(i);
281 switch (ent->Type(i)) {
282 case 0 : S << " (Void)"; break;
283 case 1 : S << " Integer, Value : " << ent->ValueAsInteger(i);
284 break;
285 case 2 : S << " Real , Value : " << ent->ValueAsReal(i);
286 break;
287 case 3 : S << " String , Value : ";
288 IGESData_DumpString(S,ent->ValueAsString(i)); break;
289 case 4 : S << " Entity , Value : ";
290 dumper.Dump(ent->ValueAsEntity(i),S,level-1); break;
291 case 5 : S << " (Not used)"; break;
292 case 6 : S << " Logical, Value : "
293 << (ent->ValueAsLogical(i) ? "True" : "False"); break;
294 default : break;
295 }
296 S << endl;
297 }
298 }
299 }
300 S << endl;
301}