0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / IGESDefs / IGESDefs_ToolAttributeDef.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_AttributeDef.hxx>
7fd59977 29#include <IGESDefs_HArray1OfHArray1OfTextDisplayTemplate.hxx>
42cf5bc1 30#include <IGESDefs_ToolAttributeDef.hxx>
31#include <IGESGraph_HArray1OfTextDisplayTemplate.hxx>
32#include <IGESGraph_TextDisplayTemplate.hxx>
33#include <Interface_Check.hxx>
34#include <Interface_CopyTool.hxx>
35#include <Interface_EntityIterator.hxx>
7fd59977 36#include <Interface_HArray1OfHAsciiString.hxx>
7fd59977 37#include <Interface_Macros.hxx>
42cf5bc1 38#include <Interface_ShareTool.hxx>
39#include <Message_Messenger.hxx>
40#include <Standard_DomainError.hxx>
41#include <TCollection_HAsciiString.hxx>
42#include <TColStd_HArray1OfInteger.hxx>
43#include <TColStd_HArray1OfReal.hxx>
44#include <TColStd_HArray1OfTransient.hxx>
7fd59977 45
42cf5bc1 46#include <stdio.h>
7fd59977 47IGESDefs_ToolAttributeDef::IGESDefs_ToolAttributeDef () { }
48
49
50void IGESDefs_ToolAttributeDef::ReadOwnParams
51 (const Handle(IGESDefs_AttributeDef)& ent,
52 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53{
54 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
55 Handle(TCollection_HAsciiString) aName;
56 Standard_Integer aListType;
57 Handle(TColStd_HArray1OfInteger) attrTypes;
58 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
59 Handle(TColStd_HArray1OfInteger) attrValueCounts;
60 Handle(TColStd_HArray1OfTransient) attrValues;
61 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
62 Standard_Integer nbval;
63 Standard_Integer fn = ent->FormNumber();
64
65 if (PR.DefinedElseSkip())
66 PR.ReadText(PR.Current(), "Attribute Table Name", aName); //szv#4:S4163:12Mar99 `st=` not needed
67
68 PR.ReadInteger(PR.Current(), "Attribute List Type", aListType); //szv#4:S4163:12Mar99 `st=` not needed
69
70 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Attributes", nbval);
71 if (st && nbval > 0)
72 {
73 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
74 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
75 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
76 if (fn > 0) attrValues =
77 new TColStd_HArray1OfTransient(1, nbval);
78 if (fn > 1) attrValuePointers =
79 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
80 }
81 else PR.AddFail("Number of Attributes: Not Positive");
82
83 if ( ! attrTypes.IsNull())
84 for (Standard_Integer i = 1; i <= nbval; i++)
85 {
86 Standard_Integer attrType;
87 Standard_Integer attrValueDataType;
88 Standard_Integer avc;
89// Value according type
90 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
91
92 //st = PR.ReadInteger(PR.Current(), "Attribute Type", attrType); //szv#4:S4163:12Mar99 moved in if
93 if (PR.ReadInteger(PR.Current(), "Attribute Type", attrType))
94 attrTypes->SetValue(i, attrType);
95
96 st = PR.ReadInteger(PR.Current(),"Attribute Data Type",attrValueDataType);
97 if (st) attrValueDataTypes->SetValue(i, attrValueDataType);
98
99 if (PR.DefinedElseSkip())
100 st = PR.ReadInteger (PR.Current(),"Attribute Value Count",avc);
101 else avc = 1;
102
103 if (st) {
104 attrValueCounts->SetValue(i, avc);
105 if (fn > 1) attrValuePointer =
106 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
107 }
108
109 if (! attrValues.IsNull())
110 if (fn > 0)
111 {
112 Handle(TColStd_HArray1OfInteger) attrInt;
113 Handle(TColStd_HArray1OfReal) attrReal;
114 Handle(Interface_HArray1OfHAsciiString) attrStr;
115 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
116 switch (attrValueDataType) {
117 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
118 attrValues->SetValue(i,attrInt); break;
119 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
120 attrValues->SetValue(i,attrReal); break;
121 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
122 attrValues->SetValue(i,attrStr); break;
123 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
124 attrValues->SetValue(i,attrEnt); break;
125 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
126 attrValues->SetValue(i,attrInt); break;
127 default : break;
128 }
129 for (Standard_Integer j = 1; j <= avc; j++)
130 {
131 switch(attrValueDataType)
132 {
133 case 0:
134 {
135 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // passer
136//// attrValue->SetValue(j, NULL); par defaut
137 break;
138 }
139 case 1:
140 {
141 Standard_Integer temp;
142 //st = PR.ReadInteger(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
143 if (PR.ReadInteger(PR.Current(), "Attribute Value", temp))
144 attrInt->SetValue(j, temp);
145 }
146 break;
147 case 2:
148 {
149 Standard_Real temp;
150 //st = PR.ReadReal(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
151 if (PR.ReadReal(PR.Current(), "Attribute Value", temp))
152 attrReal->SetValue(j, temp);
153 }
154 break;
155 case 3:
156 {
157 Handle(TCollection_HAsciiString) temp;
158 //st = PR.ReadText(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
159 if (PR.ReadText(PR.Current(), "Attribute Value", temp))
160 attrStr->SetValue(j, temp);
161 }
162 break;
163 case 4:
164 {
165 Handle(IGESData_IGESEntity) temp;
166 //st = PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
167 if (PR.ReadEntity(IR, PR.Current(), "Attribute Value", temp))
168 attrEnt->SetValue(j, temp);
169 }
170 break;
171 case 5:
172 PR.SetCurrentNumber(PR.CurrentNumber() + 1); // skip
173 break;
174 case 6:
175 {
176 Standard_Boolean temp;
177 //st = PR.ReadBoolean(PR.Current(), "Attribute Value", temp); //szv#4:S4163:12Mar99 moved in if
178 if (PR.ReadBoolean(PR.Current(), "Attribute Value", temp))
179 attrInt->SetValue(j, (temp ? 1 : 0));
180 }
181 break;
182 }
183 if (fn == 2)
184 {
185 Handle(IGESGraph_TextDisplayTemplate) tempText;
186 //st = PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
187 //STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText); //szv#4:S4163:12Mar99 moved in if
188 if (PR.ReadEntity(IR,PR.Current(),"Attribute Val. Pointer",
189 STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempText))
190 attrValuePointer->SetValue(j, tempText);
191 }
192 }
193 if (fn == 2)
194 attrValuePointers->SetValue(i, attrValuePointer);
195 }
196 }
197
198 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
199 ent->Init
200 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
201 attrValues, attrValuePointers);
202}
203
204void IGESDefs_ToolAttributeDef::WriteOwnParams
205 (const Handle(IGESDefs_AttributeDef)& ent, IGESData_IGESWriter& IW) const
206{
207 if (ent->HasTableName()) IW.Send(ent->TableName());
208 else IW.SendVoid();
209 IW.Send(ent->ListType());
210 Standard_Integer upper = ent->NbAttributes();
211 IW.Send(upper);
212
213 for (Standard_Integer i = 1; i <= upper; i++)
214 {
215 Standard_Integer check = ent->AttributeValueDataType(i);
216 Standard_Integer count = ent->AttributeValueCount(i);
217 IW.Send(ent->AttributeType(i));
218 IW.Send(check);
219 IW.Send(count);
220 if (ent->FormNumber() > 0)
221 {
222 for (Standard_Integer j = 1; j <= count; j++)
223 {
224 switch (check) {
225 case 0 : IW.SendVoid(); break;
226 case 1 : IW.Send(ent->AttributeAsInteger(i,j)); break;
227 case 2 : IW.Send(ent->AttributeAsReal(i,j)); break;
228 case 3 : IW.Send(ent->AttributeAsString(i,j)); break;
229 case 4 : IW.Send(ent->AttributeAsEntity(i,j)); break;
230 case 5 : IW.SendVoid(); break;
231 case 6 : IW.SendBoolean(ent->AttributeAsLogical(i,j)); break;
232 default : break;
233 }
234 if ( ent->FormNumber() == 2)
235 IW.Send(ent->AttributeTextDisplay(i,j));
236 }
237 }
238 }
239}
240
241void IGESDefs_ToolAttributeDef::OwnShared
242 (const Handle(IGESDefs_AttributeDef)& ent, Interface_EntityIterator& iter) const
243{
244 Standard_Integer upper = ent->NbAttributes();
245 for (Standard_Integer i = 1; i <= upper; i++)
246 {
247 Standard_Integer check = ent->AttributeValueDataType(i);
248 Standard_Integer count = ent->AttributeValueCount(i);
249 if (ent->FormNumber() > 0)
250 {
251 for (Standard_Integer j = 1; j <= count; j++)
252 {
253 if ( check == 4 ) iter.GetOneItem(ent->AttributeAsEntity(i,j));
254 if ( ent->FormNumber() == 2)
255 iter.GetOneItem(ent->AttributeTextDisplay(i,j));
256 }
257 }
258 }
259}
260
261
262void IGESDefs_ToolAttributeDef::OwnCopy
263 (const Handle(IGESDefs_AttributeDef)& another,
264 const Handle(IGESDefs_AttributeDef)& ent, Interface_CopyTool& TC) const
265{
266 Handle(TCollection_HAsciiString) aName;
267 if (!another->TableName().IsNull()) aName =
268 new TCollection_HAsciiString(another->TableName());
269 Standard_Integer aListType = another->ListType();
270
271 Handle(TColStd_HArray1OfInteger) attrTypes;
272 Handle(TColStd_HArray1OfInteger) attrValueDataTypes;
273 Handle(TColStd_HArray1OfInteger) attrValueCounts;
274 Handle(TColStd_HArray1OfTransient) attrValues;
275 Handle(IGESDefs_HArray1OfHArray1OfTextDisplayTemplate) attrValuePointers;
276 Standard_Integer nbval = another->NbAttributes();
277
278 attrTypes = new TColStd_HArray1OfInteger(1, nbval);
279 attrValueDataTypes = new TColStd_HArray1OfInteger(1, nbval);
280 attrValueCounts = new TColStd_HArray1OfInteger(1, nbval);
281 if (another->HasValues()) attrValues =
282 new TColStd_HArray1OfTransient(1, nbval);
283 if (another->HasTextDisplay()) attrValuePointers =
284 new IGESDefs_HArray1OfHArray1OfTextDisplayTemplate(1, nbval);
285
286 for (Standard_Integer i = 1; i <= nbval; i++)
287 {
288 Standard_Integer attrType = another->AttributeType(i);
289 attrTypes->SetValue(i, attrType);
290 Standard_Integer attrValueDataType = another->AttributeValueDataType(i);
291 attrValueDataTypes->SetValue(i, attrValueDataType);
292 Standard_Integer avc = another->AttributeValueCount(i);
293 attrValueCounts->SetValue(i, avc);
294 Handle(IGESGraph_HArray1OfTextDisplayTemplate) attrValuePointer;
295
296 if (another->HasTextDisplay()) attrValuePointer =
297 new IGESGraph_HArray1OfTextDisplayTemplate(1, avc);
298
299 if (another->HasValues())
300 {
301 Handle(TColStd_HArray1OfInteger) attrInt;
302 Handle(TColStd_HArray1OfReal) attrReal;
303 Handle(Interface_HArray1OfHAsciiString) attrStr;
304 Handle(IGESData_HArray1OfIGESEntity) attrEnt;
305 switch (attrValueDataType) {
306 case 1 : attrInt = new TColStd_HArray1OfInteger (1,avc);
307 attrValues->SetValue(i,attrInt); break;
308 case 2 : attrReal = new TColStd_HArray1OfReal (1,avc);
309 attrValues->SetValue(i,attrReal); break;
310 case 3 : attrStr = new Interface_HArray1OfHAsciiString(1,avc);
311 attrValues->SetValue(i,attrStr); break;
312 case 4 : attrEnt = new IGESData_HArray1OfIGESEntity (1,avc);
313 attrValues->SetValue(i,attrEnt); break;
314 case 6 : attrInt = new TColStd_HArray1OfInteger (1,avc);
315 attrValues->SetValue(i,attrInt); break;
316 default : break;
317 }
318 for (Standard_Integer j = 1; j <= avc; j ++)
319 {
320 switch(attrValueDataType)
321 {
322 case 0:
323 break;
324 case 1: attrInt->SetValue(j,another->AttributeAsInteger(i,j));
325 break;
326 case 2: attrReal->SetValue(j,another->AttributeAsReal(i,j));
327 break;
328 case 3: attrStr->SetValue(j,new TCollection_HAsciiString
329 (another->AttributeAsString(i,j)));
330 break;
331 case 4: {
332 DeclareAndCast(IGESData_IGESEntity,Ent,TC.Transferred
333 (another->AttributeAsEntity(i,j)));
334 attrEnt->SetValue(j,Ent);
335 }
336 break;
337 case 5:
338 break;
339 case 6: attrInt->SetValue
340 (j,(another->AttributeAsLogical(i,j) ? 1 : 0));
341 break;
342 default : break;
343 }
344 if (another->HasTextDisplay())
345 {
346 DeclareAndCast(IGESGraph_TextDisplayTemplate, temptext,
347 TC.Transferred(another->AttributeTextDisplay(i,j)));
348 attrValuePointer->SetValue (j, temptext);
349 }
350 }
351 if (another->HasTextDisplay())
352 attrValuePointers->SetValue(i, attrValuePointer);
353 }
354 }
355 ent->Init
356 (aName, aListType, attrTypes, attrValueDataTypes, attrValueCounts,
357 attrValues, attrValuePointers);
358}
359
360IGESData_DirChecker IGESDefs_ToolAttributeDef::DirChecker
361 (const Handle(IGESDefs_AttributeDef)& /* ent */ ) const
362{
363 IGESData_DirChecker DC (322, 0, 2);
364 DC.Structure(IGESData_DefVoid);
365 DC.LineFont(IGESData_DefAny);
366 DC.LineWeight(IGESData_DefValue);
367 DC.Color(IGESData_DefAny);
368 DC.BlankStatusIgnored();
369 DC.SubordinateStatusRequired(0);
370 DC.UseFlagRequired(2);
371 DC.GraphicsIgnored(1);
372 return DC;
373}
374
375void IGESDefs_ToolAttributeDef::OwnCheck
376 (const Handle(IGESDefs_AttributeDef)& ent,
377 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
378{
379 Standard_Integer nb = ent->NbAttributes();
380 Standard_Integer fn = ent->FormNumber();
381 for (Standard_Integer i = 1; i <= nb; i ++) {
382 char mess[80];
383 if (ent->AttributeType(i) < 0 || ent->AttributeType(i) > 9999) {
384 sprintf(mess,"Attribute Type n0.%d not in <0 - 9999>", ent->AttributeType(i));
385 ach->AddFail(mess);
386 }
387 Standard_Integer aty = ent->AttributeValueDataType(i);
388 if (aty < 0 || aty > 6) {
389 sprintf(mess,"Attribute Value Data Type n0.%d not in <0 - 6>", aty);
390 ach->AddFail(mess);
391 }
392 if (ent->AttributeValueCount(i) <= 0) continue;
393 Handle(Standard_Transient) list = ent->AttributeList(i);
394 if (fn > 0 && ent.IsNull()) {
395 if (aty == 0 || aty == 5) continue;
396 sprintf(mess,"Form Number > 0 and Attribute Value List n0.%d undefined", aty);
397 ach->AddFail(mess);
398 continue;
399 }
400 else if (fn == 0) continue;
401 mess[0] = '\0';
c48e2889 402 switch (aty)
403 {
404 case 1:
405 if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
406 {
407 sprintf(mess,"Attribute List n0.%d (Integers) badly defined", aty);
408 }
409 break;
410 case 2:
411 if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfReal)))
412 {
413 sprintf(mess,"Attribute List n0.%d (Reals) badly defined", aty);
414 }
415 break;
416 case 3:
417 if (!list->IsKind(STANDARD_TYPE(Interface_HArray1OfHAsciiString)))
418 {
419 sprintf(mess,"Attribute List n0.%d (Strings) badly defined", aty);
420 }
421 break;
422 case 4:
423 if (!list->IsKind(STANDARD_TYPE(IGESData_HArray1OfIGESEntity)))
424 {
425 sprintf(mess,"Attribute List n0.%d (IGES Pointers) badly defined", aty);
426 }
427 break;
428 case 6:
429 if (!list->IsKind(STANDARD_TYPE(TColStd_HArray1OfInteger)))
430 {
431 sprintf(mess,"Attribute List n0.%d (Logicals i.e. Integers) badly defined", aty);
432 }
433 break;
434 default:
435 break;
7fd59977 436 }
437 if (mess[0] != '\0') ach->AddFail(mess);
438 }
439}
440
441
442void IGESDefs_ToolAttributeDef::OwnDump
443 (const Handle(IGESDefs_AttributeDef)& ent, const IGESData_IGESDumper& dumper,
0ebe5b0a 444 Standard_OStream& S, const Standard_Integer level) const
7fd59977 445{
446 Standard_Integer sublevel = (level > 4) ? 1 : 0;
447
0ebe5b0a 448 S << "IGESDefs_AttributeDef\n"
449 << "Attribute Table Name: ";
7fd59977 450 IGESData_DumpString(S,ent->TableName());
0ebe5b0a 451 S << "\n"
452 << "Attribute List Type : " << ent->ListType() << "\n"
453 << "Number of Attributes : " << ent->NbAttributes() << "\n"
454 << "Attribute Types :\n"
455 << "Attribute Value Data Types :\n"
456 << "Attribute Value Counts :\n";
457 if (ent->HasValues()) S << "Attribute Values :\n";
458 if (ent->HasTextDisplay()) S << "Attribute Value Entities :\n";
7fd59977 459 IGESData_DumpVals(S,-level,1, ent->NbAttributes(),ent->AttributeType);
0ebe5b0a 460 S << "\n";
7fd59977 461 if (level > 4)
462 {
463 Standard_Integer upper = ent->NbAttributes();
464 for (Standard_Integer i = 1; i <= upper ; i ++)
465 {
466 Standard_Integer avc = ent->AttributeValueCount(i);
467 Standard_Integer typ = ent->AttributeValueDataType(i);
0ebe5b0a 468 S << "[" << i << "]: "
469 << "Attribute Type : " << ent->AttributeType(i) << " "
470 << "Value Data Type : " << typ;
7fd59977 471 switch (typ) {
472 case 0 : S << " (Void)"; break;
473 case 1 : S << " : Integer "; break;
474 case 2 : S << " : Real "; break;
475 case 3 : S << " : String "; break;
476 case 4 : S << " : Entity "; break;
477 case 5 : S << " (Not Used)"; break;
478 case 6 : S << " : Logical "; break;
479 default : break;
480 }
0ebe5b0a 481 S << " Count : " << avc << "\n";
7fd59977 482 if (ent->HasValues())
483 {
484 if (level <= 5) {
0ebe5b0a 485 S << " [ content (Values) : ask level > 5 ]\n";
7fd59977 486 continue;
487 }
488 for (Standard_Integer j = 1; j <= avc; j ++)
489 {
490 S << "[" << j << "]: ";
491 switch(ent->AttributeValueDataType(i))
492 {
493 case 0: S << "(Void) ";
494 break;
495 case 1: S << ent->AttributeAsInteger(i,j);
496 break;
497 case 2: S << ent->AttributeAsReal(i,j);
498 break;
499 case 3: IGESData_DumpString(S,ent->AttributeAsString(i,j));
500 break;
501 case 4: dumper.Dump(ent->AttributeAsEntity(i,j),S,level-5);
502 break;
503 case 5: S << "(Not Used)";
504 break;
505 case 6:
506 S << ( ent->AttributeAsLogical(i,j) ? "True" : "False");
507 break;
508 default : break;
509 }
510 if (ent->HasTextDisplay())
511 {
512 S << " Attribute Value Pointer : ";
513 dumper.Dump (ent->AttributeTextDisplay(i,j),S, sublevel);
514 }
0ebe5b0a 515 S << std::endl;
7fd59977 516 }
517 }
518 }
519 }
0ebe5b0a 520 S << std::endl;
7fd59977 521}