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_ToolAttributeTable.ixx>
24 #include <IGESData_ParamCursor.hxx>
25 #include <IGESDefs_AttributeDef.hxx>
26 #include <TColStd_HArray2OfTransient.hxx>
27 #include <TColStd_HArray1OfReal.hxx>
28 #include <TColStd_HArray1OfInteger.hxx>
29 #include <Interface_HArray1OfHAsciiString.hxx>
30 #include <IGESData_HArray1OfIGESEntity.hxx>
31 #include <TCollection_HAsciiString.hxx>
32 #include <Interface_Macros.hxx>
33 #include <IGESData_Dump.hxx>
36 IGESDefs_ToolAttributeTable::IGESDefs_ToolAttributeTable () { }
39 void IGESDefs_ToolAttributeTable::ReadOwnParams
40 (const Handle(IGESDefs_AttributeTable)& ent,
41 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
43 Standard_Integer nr = 1;
45 Standard_Boolean st = Standard_True;
47 Handle(IGESDefs_AttributeDef) ab = ent->Definition(); // formerly loaded
48 Handle(TColStd_HArray2OfTransient) list2;
50 PR.AddFail("No Attribute Definition as Structure");
53 Standard_Integer na = ab->NbAttributes();
55 if (ent->FormNumber() == 1)
56 st = PR.ReadInteger(PR.Current(),"No. of rows",nr);
57 if (st) list2 = new TColStd_HArray2OfTransient(1,na,1,nr);
59 // AttributeDef repeated once (Form 0) or <nr> times (Form 1)
60 for (Standard_Integer k = 1; k <= nr; k ++)
62 for (Standard_Integer i = 1; i <= na; i ++)
64 Standard_Integer avc = ab->AttributeValueCount(i);
65 Standard_Integer atype = ab->AttributeValueDataType(i);
69 for (j = 1; j <= avc; j ++)
70 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
73 Handle(TColStd_HArray1OfInteger) attrInt = new TColStd_HArray1OfInteger(1,avc);
74 list2->SetValue(i,k,attrInt);
75 Standard_Integer item;
76 for (j = 1; j <= avc; j ++) {
77 //st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
78 if (PR.ReadInteger(PR.Current(),"Value",item))
79 attrInt->SetValue(j,item);
84 Handle(TColStd_HArray1OfReal) attrReal = new TColStd_HArray1OfReal(1,avc);
85 list2->SetValue(i,k,attrReal);
87 for (j = 1; j <= avc; j ++) {
88 //st = PR.ReadReal(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
89 if (PR.ReadReal(PR.Current(),"Value",item))
90 attrReal->SetValue(j,item);
95 Handle(Interface_HArray1OfHAsciiString) attrStr = new Interface_HArray1OfHAsciiString(1,avc);
96 list2->SetValue(i,k,attrStr);
97 Handle(TCollection_HAsciiString) item;
98 for (j = 1; j <= avc; j ++) {
99 //st = PR.ReadText(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
100 if (PR.ReadText(PR.Current(),"Value",item))
101 attrStr->SetValue(j,item);
106 Handle(IGESData_HArray1OfIGESEntity) attrEnt = new IGESData_HArray1OfIGESEntity(1,avc);
107 list2->SetValue(i,k,attrEnt);
108 Handle(IGESData_IGESEntity) item;
109 for (j = 1; j <= avc; j ++) {
110 //st = PR.ReadEntity(IR,PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
111 if (PR.ReadEntity(IR,PR.Current(),"Value",item))
112 attrEnt->SetValue(j,item);
117 for (j = 1; j <= avc; j ++)
118 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
120 case 6 : { // Here item takes value 0 or 1
121 Handle(TColStd_HArray1OfInteger) attrInt = new TColStd_HArray1OfInteger(1,avc);
122 list2->SetValue(i,k,attrInt);
123 Standard_Integer item;
124 for (j = 1; j <= avc; j ++) {
125 //st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
126 if (PR.ReadInteger(PR.Current(),"Value",item))
127 attrInt->SetValue(j,item);
135 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
139 void IGESDefs_ToolAttributeTable::WriteOwnParams
140 (const Handle(IGESDefs_AttributeTable)& ent, IGESData_IGESWriter& IW) const
142 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
144 Standard_Integer nr = ent->NbRows();
145 Standard_Integer na = ent->NbAttributes();
146 if (ent->FormNumber() == 1) IW.Send(nr);
147 for (Standard_Integer k = 1; k <= nr; k ++)
149 for (Standard_Integer i = 1; i <= na; i ++)
151 Standard_Integer count = ab->AttributeValueCount(i);
152 for (Standard_Integer j = 1;j <= count; j++)
154 switch(ab->AttributeValueDataType(i))
156 case 0 : IW.SendVoid(); break;
157 case 1 : IW.Send(ent->AttributeAsInteger(i,k,j)); break;
158 case 2 : IW.Send(ent->AttributeAsReal (i,k,j)); break;
159 case 3 : IW.Send(ent->AttributeAsString (i,k,j)); break;
160 case 4 : IW.Send(ent->AttributeAsEntity (i,k,j)); break;
161 case 5 : IW.SendVoid(); break;
162 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,k,j)); break;
170 void IGESDefs_ToolAttributeTable::OwnShared
171 (const Handle(IGESDefs_AttributeTable)& ent, Interface_EntityIterator& iter) const
173 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
174 Standard_Integer na = ent->NbAttributes();
175 Standard_Integer nr = ent->NbRows();
176 for (Standard_Integer k = 1; k <= nr; k ++)
178 for (Standard_Integer i = 1; i <= na; i ++)
180 if (ab->AttributeValueDataType(i) != 4) continue;
181 Standard_Integer avc = ab->AttributeValueCount(i);
182 for (Standard_Integer j = 1; j <= avc; j ++)
183 iter.GetOneItem(ent->AttributeAsEntity(i,k,j));
188 void IGESDefs_ToolAttributeTable::OwnCopy
189 (const Handle(IGESDefs_AttributeTable)& another,
190 const Handle(IGESDefs_AttributeTable)& ent, Interface_CopyTool& TC) const
192 Standard_Integer j = 1;
193 Handle(IGESDefs_AttributeDef) ab = another->Definition();
194 Standard_Integer na = another->NbAttributes();
195 Standard_Integer nr = another->NbRows();
196 Handle(TColStd_HArray2OfTransient) list2 =
197 new TColStd_HArray2OfTransient(1,na,1,nr);
198 for (Standard_Integer k = 1; k <= nr; k ++)
200 for (Standard_Integer i = 1; i <= na; i ++)
202 Standard_Integer avc = ab->AttributeValueCount(i);
203 Standard_Integer atype = ab->AttributeValueDataType(i);
206 case 0 : //// list2->SetValue(i,k,NULL); par defaut
209 DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
210 another->AttributeList(i,k));
211 Handle(TColStd_HArray1OfInteger) attrInt =
212 new TColStd_HArray1OfInteger (1,avc);
213 list2->SetValue(i,k,attrInt);
214 for (j = 1; j <= avc; j++)
215 attrInt->SetValue(j,otherInt->Value(j));
219 DeclareAndCast(TColStd_HArray1OfReal,otherReal,
220 another->AttributeList(i,k));
221 Handle(TColStd_HArray1OfReal) attrReal =
222 new TColStd_HArray1OfReal (1,avc);
223 list2->SetValue(i,k,attrReal);
224 for (j = 1; j <= avc; j++)
225 attrReal->SetValue(j,otherReal->Value(j));
229 DeclareAndCast(Interface_HArray1OfHAsciiString,otherStr,
230 another->AttributeList(i,k));
231 Handle(Interface_HArray1OfHAsciiString) attrStr =
232 new Interface_HArray1OfHAsciiString (1,avc);
233 list2->SetValue(i,k,attrStr);
234 for (j = 1; j <= avc; j++)
236 (j,new TCollection_HAsciiString(otherStr->Value(j)));
240 DeclareAndCast(IGESData_HArray1OfIGESEntity,otherEnt,
241 another->AttributeList(i,k));
242 Handle(IGESData_HArray1OfIGESEntity) attrEnt =
243 new IGESData_HArray1OfIGESEntity (1,avc);
244 list2->SetValue(i,k,attrEnt);
245 for (j = 1; j <= avc; j++)
246 attrEnt->SetValue(j,GetCasted(IGESData_IGESEntity,
247 TC.Transferred(otherEnt->Value(j))));
250 case 5 : ///// list2->SetValue(i,k,NULL); par defaut
252 case 6 :{ // Here item takes value 0 or 1
253 DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
254 another->AttributeList(i,k));
255 Handle(TColStd_HArray1OfInteger) attrInt =
256 new TColStd_HArray1OfInteger (1,avc);
257 list2->SetValue(i,k,attrInt);
258 for (j = 1; j <= avc; j++)
259 attrInt->SetValue(j,otherInt->Value(j));
269 IGESData_DirChecker IGESDefs_ToolAttributeTable::DirChecker
270 (const Handle(IGESDefs_AttributeTable)& /* ent */ ) const
272 IGESData_DirChecker DC(422,0,1);
273 DC.Structure(IGESData_DefReference);
274 DC.GraphicsIgnored();
275 DC.BlankStatusIgnored();
276 DC.HierarchyStatusIgnored();
280 void IGESDefs_ToolAttributeTable::OwnCheck
281 (const Handle(IGESDefs_AttributeTable)& ent,
282 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
284 if (ent->Definition().IsNull()) {
285 if (ent->HasStructure()) ach->AddFail
286 ("Structure in Directory Entry is not an Attribute Definition Table");
287 else ach->AddFail("No Attribute Definition defined");
289 if (ent->FormNumber() == 0 && ent->NbRows() != 1)
290 ach->AddFail("Form 0 with several Rows");
291 if (ent->NbAttributes() != ent->Definition()->NbAttributes())
292 ach->AddFail("Mismatch between Definition (Structure) and Content");
295 void IGESDefs_ToolAttributeTable::OwnDump
296 (const Handle(IGESDefs_AttributeTable)& ent, const IGESData_IGESDumper& dumper,
297 const Handle(Message_Messenger)& S, const Standard_Integer level) const
299 S << "IGESDefs_AttributeTable" << endl;
301 Handle(IGESDefs_AttributeDef) ab = ent->Definition();
303 Standard_Integer na = ent->NbAttributes();
304 Standard_Integer nr = ent->NbRows();
305 if (ent->FormNumber() == 1)
306 S << "Number of Rows (i.e. complete sets of Attributes) : " << nr << endl;
307 else S << "One set of Attributes" << endl;
308 S << "Number of defined Attributes : " << na << endl;
310 " [ structure : see Structure in Directory Entry; content : level > 4 ]" <<endl;
312 for (Standard_Integer k = 1; k <= nr; k ++)
314 for (Standard_Integer i = 1; i <= na; i ++)
316 Standard_Integer avc = ab->AttributeValueCount(i);
317 S << "[At.no."<<i<<" Row:"<<k<<"]";
318 switch (ab->AttributeValueDataType(i)) {
319 case 0 : S << " (Void) "; break;
320 case 1 : S << " Integer"; break;
321 case 2 : S << " Real "; break;
322 case 3 : S << " String "; break;
323 case 4 : S << " Entity "; break;
324 case 5 : S << " (Not used)"; break;
325 case 6 : S << " Logical"; break;
329 for (Standard_Integer j = 1;j <= avc; j++) {
331 switch(ab->AttributeValueDataType(i)) {
332 case 1 : S << ent->AttributeAsInteger(i,k,j); break;
333 case 2 : S << ent->AttributeAsReal (i,k,j); break;
334 case 3 : IGESData_DumpString(S,ent->AttributeAsString (i,k,j));
336 case 4 : dumper.Dump(ent->AttributeAsEntity (i,k,j),S,level-5);
338 case 6 : S << (ent->AttributeAsLogical(i,k,j) ? "True" : "False");