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_GenericData.hxx>
29 #include <IGESDefs_ToolGenericData.hxx>
30 #include <Interface_Check.hxx>
31 #include <Interface_CopyTool.hxx>
32 #include <Interface_EntityIterator.hxx>
33 #include <Interface_HArray1OfHAsciiString.hxx>
34 #include <Interface_Macros.hxx>
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>
43 IGESDefs_ToolGenericData::IGESDefs_ToolGenericData () { }
46 void IGESDefs_ToolGenericData::ReadOwnParams
47 (const Handle(IGESDefs_GenericData)& ent,
48 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
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;
57 PR.ReadInteger(PR.Current(), "Number of property values", tempNbPropVal); //szv#4:S4163:12Mar99 `st=` not needed
59 PR.ReadText(PR.Current(), "Property Name", tempName); //szv#4:S4163:12Mar99 `st=` not needed
61 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of TYPE/VALUEs", num);
64 tempTypes = new TColStd_HArray1OfInteger(1, num);
65 tempValues = new TColStd_HArray1OfTransient(1, num);
67 else PR.AddFail("Number of TYPE/VALUEs: Not Positive");
69 if (!tempTypes.IsNull() && !tempValues.IsNull())
70 for ( i = 1; i <= num; i++ )
72 Standard_Integer tempTyp;
73 PR.ReadInteger(PR.Current(), "Type code", tempTyp); //szv#4:S4163:12Mar99 `st=` not needed
74 tempTypes->SetValue(i, tempTyp);
78 PR.SetCurrentNumber(PR.CurrentNumber()+1);
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);
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);
96 case 3: // Character string
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);
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);
113 PR.SetCurrentNumber(PR.CurrentNumber()+1);
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);
129 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
130 ent->Init (tempNbPropVal, tempName, tempTypes, tempValues);
133 void IGESDefs_ToolGenericData::WriteOwnParams
134 (const Handle(IGESDefs_GenericData)& ent, IGESData_IGESWriter& IW) const
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++ )
142 IW.Send(ent->Type(i));
143 switch (ent->Type(i))
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;
157 void IGESDefs_ToolGenericData::OwnShared
158 (const Handle(IGESDefs_GenericData)& ent, Interface_EntityIterator& iter) const
160 Standard_Integer i, num;
161 for ( num = ent->NbTypeValuePairs(), i = 1; i <= num; i++ )
163 if (ent->Type(i) == 4)
164 iter.GetOneItem(ent->ValueAsEntity(i));
168 void IGESDefs_ToolGenericData::OwnCopy
169 (const Handle(IGESDefs_GenericData)& another,
170 const Handle(IGESDefs_GenericData)& ent, Interface_CopyTool& TC) const
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);
181 for (Standard_Integer i = 1; i <= num; i++)
183 tempTypes->SetValue(i, another->Type(i));
184 switch (another->Type(i))
190 Handle(TColStd_HArray1OfInteger) tempObj =
191 new TColStd_HArray1OfInteger(1,1);
192 tempObj->SetValue(1,another->ValueAsInteger(i));
193 tempValues->SetValue(i, tempObj);
198 Handle(TColStd_HArray1OfReal) tempObj =
199 new TColStd_HArray1OfReal(1,1);
200 tempObj->SetValue(1,another->ValueAsReal(i));
201 tempValues->SetValue(i, tempObj);
204 case 3: // Character string
207 (i, new TCollection_HAsciiString(another->ValueAsString(i)));
212 DeclareAndCast(IGESData_IGESEntity, tempObj,
213 TC.Transferred(another->ValueAsEntity(i)));
214 tempValues->SetValue(i, tempObj);
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);
229 ent->Init (tempNbPropVal, tempName, tempTypes, tempValues);
232 IGESData_DirChecker IGESDefs_ToolGenericData::DirChecker
233 (const Handle(IGESDefs_GenericData)& /* ent */ ) const
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();
248 void IGESDefs_ToolGenericData::OwnCheck
249 (const Handle(IGESDefs_GenericData)& ent,
250 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
252 if (ent->NbPropertyValues() != ent->NbTypeValuePairs()*2 + 2)
253 ach->AddFail("Nb. of Property Values not consistent with Nb. of Type/value Pairs");
256 void IGESDefs_ToolGenericData::OwnDump
257 (const Handle(IGESDefs_GenericData)& ent, const IGESData_IGESDumper& dumper,
258 const Handle(Message_Messenger)& S, const Standard_Integer level) const
260 S << "IGESDefs_GenericData" << endl;
261 S << "Number of property values : " << ent->NbPropertyValues() << endl;
262 S << "Property Name : ";
263 IGESData_DumpString(S,ent->Name());
268 S << "Types : " << endl;
269 S << "Values : " << "Count = " << ent->NbTypeValuePairs() << endl;
270 S << " [ as level > 4 for content ]" << endl;
275 Standard_Integer i, num;
276 S << "Types & Values : " << endl;
277 for ( num = ent->NbTypeValuePairs(), i = 1; i <= num; i++ )
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);
285 case 2 : S << " Real , Value : " << ent->ValueAsReal(i);
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;