summaryrefslogtreecommitdiff
path: root/src/IGESDefs/IGESDefs_ToolAttributeTable.cxx
blob: 2d022fab46483e9b2fd42c39c273522d39858b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
//--------------------------------------------------------------------
//
//  File Name : IGESDefs_AttributeTable.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------

#include <IGESDefs_ToolAttributeTable.ixx>
#include <IGESData_ParamCursor.hxx>
#include <IGESDefs_AttributeDef.hxx>
#include <TColStd_HArray2OfTransient.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <Interface_HArray1OfHAsciiString.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <TCollection_HAsciiString.hxx>
#include <Interface_Macros.hxx>
#include <IGESData_Dump.hxx>


IGESDefs_ToolAttributeTable::IGESDefs_ToolAttributeTable ()    {  }


void  IGESDefs_ToolAttributeTable::ReadOwnParams
  (const Handle(IGESDefs_AttributeTable)& ent,
   const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
{ 
  Standard_Integer nr = 1;
  Standard_Integer j;
  Standard_Boolean st = Standard_True;

  Handle(IGESDefs_AttributeDef) ab = ent->Definition();  // formerly loaded
  Handle(TColStd_HArray2OfTransient) list2;
  if (ab.IsNull()) {
    PR.AddFail("No Attribute Definition as Structure");
    return;
  }
  Standard_Integer na = ab->NbAttributes();

  if (ent->FormNumber() == 1)
    st = PR.ReadInteger(PR.Current(),"No. of rows",nr);
  if (st) list2 = new TColStd_HArray2OfTransient(1,na,1,nr);

//  AttributeDef repeated once (Form 0) or <nr> times (Form 1)
  for (Standard_Integer k = 1; k <= nr; k ++)
    {
      for (Standard_Integer i = 1; i <= na; i ++)
	{
	  Standard_Integer avc   = ab->AttributeValueCount(i);
	  Standard_Integer atype = ab->AttributeValueDataType(i);
	  switch (atype)
	    {
            case 0 : 
	      for (j = 1; j <= avc; j ++)
		PR.SetCurrentNumber(PR.CurrentNumber() + 1);  // skip
	      break;
            case 1 : {
	      Handle(TColStd_HArray1OfInteger) attrInt = new TColStd_HArray1OfInteger(1,avc);
	      list2->SetValue(i,k,attrInt);
	      Standard_Integer item;
	      for (j = 1; j <= avc; j ++)  {
		//st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
		if (PR.ReadInteger(PR.Current(),"Value",item))
		  attrInt->SetValue(j,item);
	      }
	    }
	      break;
            case 2 : {
	      Handle(TColStd_HArray1OfReal) attrReal = new TColStd_HArray1OfReal(1,avc);
	      list2->SetValue(i,k,attrReal);
	      Standard_Real item;
	      for (j = 1; j <= avc; j ++) {
		//st = PR.ReadReal(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
		if (PR.ReadReal(PR.Current(),"Value",item))
		  attrReal->SetValue(j,item);
	      }
	    }
	      break;
	    case 3 : {
	      Handle(Interface_HArray1OfHAsciiString) attrStr =	new Interface_HArray1OfHAsciiString(1,avc);
	      list2->SetValue(i,k,attrStr);
	      Handle(TCollection_HAsciiString) item;
	      for (j = 1; j <= avc; j ++) {
		//st = PR.ReadText(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
		if (PR.ReadText(PR.Current(),"Value",item))
		  attrStr->SetValue(j,item);
	      }
	    }
	      break;
	    case 4 : {
	      Handle(IGESData_HArray1OfIGESEntity) attrEnt = new IGESData_HArray1OfIGESEntity(1,avc);
	      list2->SetValue(i,k,attrEnt);
	      Handle(IGESData_IGESEntity) item;
	      for (j = 1; j <= avc; j ++) {
		//st = PR.ReadEntity(IR,PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
		if (PR.ReadEntity(IR,PR.Current(),"Value",item))
		  attrEnt->SetValue(j,item);
	      }
	    }
	      break;
	    case 5 :
	      for (j = 1; j <= avc; j ++)
		  PR.SetCurrentNumber(PR.CurrentNumber() + 1);  // skip
	      break;
	    case 6 : {    // Here item takes value 0 or 1
	      Handle(TColStd_HArray1OfInteger) attrInt  = new TColStd_HArray1OfInteger(1,avc);
	      list2->SetValue(i,k,attrInt);
	      Standard_Integer item;
	      for (j = 1; j <= avc; j ++) {
		  //st = PR.ReadInteger(PR.Current(),"Value",item); //szv#4:S4163:12Mar99 moved in if
		  if (PR.ReadInteger(PR.Current(),"Value",item))
		    attrInt->SetValue(j,item);
		}
	    }
	      break;
              default : break;
	    }
	}
    }
  DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
  ent->Init(list2);
}

void  IGESDefs_ToolAttributeTable::WriteOwnParams
  (const Handle(IGESDefs_AttributeTable)& ent, IGESData_IGESWriter& IW) const 
{
  Handle(IGESDefs_AttributeDef) ab = ent->Definition();

  Standard_Integer nr = ent->NbRows();
  Standard_Integer na = ent->NbAttributes();
  if (ent->FormNumber() == 1) IW.Send(nr);
  for (Standard_Integer k = 1; k <= nr; k ++)
    {
      for (Standard_Integer i = 1; i <= na; i ++)
	{
          Standard_Integer count = ab->AttributeValueCount(i);
	  for (Standard_Integer j = 1;j <= count; j++)
	    {
	      switch(ab->AttributeValueDataType(i))
		{
		case 0 : IW.SendVoid();  break;
		case 1 : IW.Send(ent->AttributeAsInteger(i,k,j));  break;
		case 2 : IW.Send(ent->AttributeAsReal   (i,k,j));  break;
		case 3 : IW.Send(ent->AttributeAsString (i,k,j));  break;
		case 4 : IW.Send(ent->AttributeAsEntity (i,k,j));  break;
		case 5 : IW.SendVoid();  break;
		case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,k,j)); break;
		default : break;
		}
	    }
	}
    }
}

void  IGESDefs_ToolAttributeTable::OwnShared
  (const Handle(IGESDefs_AttributeTable)& ent, Interface_EntityIterator& iter) const
{
  Handle(IGESDefs_AttributeDef) ab = ent->Definition();
  Standard_Integer na = ent->NbAttributes();
  Standard_Integer nr = ent->NbRows();
  for (Standard_Integer k = 1; k <= nr; k ++)
    {
      for (Standard_Integer i = 1; i <= na; i ++)
	{
	  if (ab->AttributeValueDataType(i) != 4) continue;
          Standard_Integer avc = ab->AttributeValueCount(i);
	  for (Standard_Integer j = 1; j <= avc; j ++)
	    iter.GetOneItem(ent->AttributeAsEntity(i,k,j));
	}
    }
}

void  IGESDefs_ToolAttributeTable::OwnCopy
  (const Handle(IGESDefs_AttributeTable)& another,
   const Handle(IGESDefs_AttributeTable)& ent, Interface_CopyTool& TC) const
{ 
  Standard_Integer j = 1;
  Handle(IGESDefs_AttributeDef) ab = another->Definition();
  Standard_Integer na = another->NbAttributes();
  Standard_Integer nr = another->NbRows();
  Handle(TColStd_HArray2OfTransient) list2 =
    new TColStd_HArray2OfTransient(1,na,1,nr);
  for (Standard_Integer k = 1; k <= nr; k ++)
    {
      for (Standard_Integer i = 1; i <= na; i ++)
	{
	  Standard_Integer avc   = ab->AttributeValueCount(i);
	  Standard_Integer atype = ab->AttributeValueDataType(i);
	  switch (atype)
	    {
            case 0 : ////    list2->SetValue(i,k,NULL);    par defaut
	      break;
            case 1 : {
	      DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
			     another->AttributeList(i,k));
	      Handle(TColStd_HArray1OfInteger) attrInt  =
		new TColStd_HArray1OfInteger (1,avc);
	      list2->SetValue(i,k,attrInt);
	      for (j = 1; j <= avc; j++)
		attrInt->SetValue(j,otherInt->Value(j));
	    }
	      break;
            case 2 : {
	      DeclareAndCast(TColStd_HArray1OfReal,otherReal,
			     another->AttributeList(i,k));
	      Handle(TColStd_HArray1OfReal) attrReal  =
		new TColStd_HArray1OfReal (1,avc);
	      list2->SetValue(i,k,attrReal);
	      for (j = 1; j <= avc; j++)
		attrReal->SetValue(j,otherReal->Value(j));
	    }
	      break;
	    case 3 : {
	      DeclareAndCast(Interface_HArray1OfHAsciiString,otherStr,
			     another->AttributeList(i,k));
	      Handle(Interface_HArray1OfHAsciiString) attrStr  =
		new Interface_HArray1OfHAsciiString (1,avc);
	      list2->SetValue(i,k,attrStr);
	      for (j = 1; j <= avc; j++)
		attrStr->SetValue
		  (j,new TCollection_HAsciiString(otherStr->Value(j)));
	    }
	      break;
	    case 4 : {
	      DeclareAndCast(IGESData_HArray1OfIGESEntity,otherEnt,
			     another->AttributeList(i,k));
	      Handle(IGESData_HArray1OfIGESEntity) attrEnt  =
		new IGESData_HArray1OfIGESEntity (1,avc);
	      list2->SetValue(i,k,attrEnt);
	      for (j = 1; j <= avc; j++)
		attrEnt->SetValue(j,GetCasted(IGESData_IGESEntity,
					      TC.Transferred(otherEnt->Value(j))));
	    }
	      break;
	    case 5 : /////	      list2->SetValue(i,k,NULL);    par defaut
	      break;
	    case 6 :{    // Here item takes value 0 or 1
	      DeclareAndCast(TColStd_HArray1OfInteger,otherInt,
			     another->AttributeList(i,k));
	      Handle(TColStd_HArray1OfInteger) attrInt  =
		new TColStd_HArray1OfInteger (1,avc);
	      list2->SetValue(i,k,attrInt);
	      for (j = 1; j <= avc; j++)
		attrInt->SetValue(j,otherInt->Value(j));
	    }
	      break;
              default : break;
	    }
	}
    }
  ent->Init(list2);
}

IGESData_DirChecker  IGESDefs_ToolAttributeTable::DirChecker
  (const Handle(IGESDefs_AttributeTable)& /* ent */ ) const 
{ 
  IGESData_DirChecker DC(422,0,1);
  DC.Structure(IGESData_DefReference);
  DC.GraphicsIgnored();
  DC.BlankStatusIgnored();
  DC.HierarchyStatusIgnored();
  return DC;
}

void  IGESDefs_ToolAttributeTable::OwnCheck
  (const Handle(IGESDefs_AttributeTable)& ent,
   const Interface_ShareTool& , Handle(Interface_Check)& ach) const 
{
  if (ent->Definition().IsNull()) {
    if (ent->HasStructure()) ach->AddFail
      ("Structure in Directory Entry is not an Attribute Definition Table");
    else ach->AddFail("No Attribute Definition defined");
  }
  if (ent->FormNumber() == 0 && ent->NbRows() != 1)
    ach->AddFail("Form 0 with several Rows");
  if (ent->NbAttributes() != ent->Definition()->NbAttributes())
    ach->AddFail("Mismatch between Definition (Structure) and Content");
}

void  IGESDefs_ToolAttributeTable::OwnDump
  (const Handle(IGESDefs_AttributeTable)& ent, const IGESData_IGESDumper& dumper,
   const Handle(Message_Messenger)& S, const Standard_Integer level) const
{ 
  S << "IGESDefs_AttributeTable" << endl;

  Handle(IGESDefs_AttributeDef) ab = ent->Definition();

  Standard_Integer na = ent->NbAttributes();
  Standard_Integer nr = ent->NbRows();
  if (ent->FormNumber() == 1)
    S << "Number of Rows (i.e. complete sets of Attributes) : " << nr << endl;
  else S << "One set of Attributes" << endl;
  S << "Number of defined Attributes : " << na << endl;
  if (level <= 4) S <<
    " [ structure : see Structure in Directory Entry; content : level > 4 ]" <<endl;
  else
    for (Standard_Integer k = 1; k <= nr; k ++)
      {
	for (Standard_Integer i = 1; i <= na; i ++)
	  {
	    Standard_Integer avc = ab->AttributeValueCount(i);
	    S << "[At.no."<<i<<" Row:"<<k<<"]";
	    switch (ab->AttributeValueDataType(i)) {
	      case 0 : S << "  (Void) ";   break;
	      case 1 : S << "  Integer";  break;
	      case 2 : S << "  Real   ";  break;
	      case 3 : S << "  String ";  break;
	      case 4 : S << "  Entity ";  break;
	      case 5 : S << " (Not used)"; break;
	      case 6 : S << "  Logical";  break;
	      default : break;
	    }
	    S << " :";
	    for (Standard_Integer j = 1;j <= avc; j++) {
	      S << "  ";
	      switch(ab->AttributeValueDataType(i)) {
		case 1 : S << ent->AttributeAsInteger(i,k,j);  break;
		case 2 : S << ent->AttributeAsReal   (i,k,j);  break;
		case 3 : IGESData_DumpString(S,ent->AttributeAsString (i,k,j));
		  break;
		case 4 : dumper.Dump(ent->AttributeAsEntity (i,k,j),S,level-5);
		  break;
		case 6 : S << (ent->AttributeAsLogical(i,k,j) ? "True" : "False");
		  break;
		default : break;
	      }
	    }
	    S << endl;
	  }
      }
  S << endl;
}