0026586: Eliminate compile warnings obtained by building occt with vc14: declaration...
[occt.git] / src / StepData / StepData_StepReaderData.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// abv 09.04.99 S4136: eliminate parameter step.readaccept.void
15// sln 04,10.2001. BUC61003. Prevent exception which may occur during reading of complex entity (if entity's items are not in alphabetical order)
42cf5bc1 16
17#include <Interface_Check.hxx>
7fd59977 18#include <Interface_FileParameter.hxx>
42cf5bc1 19#include <Interface_HArray1OfHAsciiString.hxx>
20#include <Interface_Macros.hxx>
7fd59977 21#include <Interface_ParamList.hxx>
7fd59977 22#include <Interface_Static.hxx>
42cf5bc1 23#include <Message.hxx>
24#include <Message_Messenger.hxx>
25#include <Standard_Transient.hxx>
26#include <Standard_Type.hxx>
27#include <StepData_EnumTool.hxx>
28#include <StepData_ESDescr.hxx>
29#include <StepData_Field.hxx>
30#include <StepData_FieldList.hxx>
31#include <StepData_PDescr.hxx>
32#include <StepData_SelectArrReal.hxx>
33#include <StepData_SelectInt.hxx>
7fd59977 34#include <StepData_SelectMember.hxx>
35#include <StepData_SelectNamed.hxx>
36#include <StepData_SelectReal.hxx>
42cf5bc1 37#include <StepData_SelectType.hxx>
38#include <StepData_StepModel.hxx>
39#include <StepData_StepReaderData.hxx>
40#include <TCollection_AsciiString.hxx>
41#include <TCollection_HAsciiString.hxx>
42#include <TColStd_Array1OfInteger.hxx>
43#include <TColStd_HArray1OfInteger.hxx>
44#include <TColStd_HArray1OfReal.hxx>
45#include <TColStd_HArray1OfTransient.hxx>
7fd59977 46#include <TColStd_HSequenceOfReal.hxx>
42cf5bc1 47#include <TColStd_IndexedMapOfInteger.hxx>
48#include <TColStd_SequenceOfInteger.hxx>
7fd59977 49
50#include <stdio.h>
7fd59977 51// Le Header est constitue d entites analogues dans leur principe a celles
52// du Data, a ceci pres qu elles sont sans identifieur, et ne peuvent ni
53// referencer, ni etre referencees (que ce soit avec Header ou avec Data)
54// Ainsi, dans StepReaderData, le Header est constitue des "thenbhead" 1res Entites
7fd59977 55// #########################################################################
56// .... Creation et Acces de base aux donnees atomiques du fichier ....
7fd59977 57typedef TCollection_HAsciiString String;
7fd59977 58static char txtmes[200]; // plus commode que redeclarer partout
59
60
61static Standard_Boolean initstr = Standard_False;
62
63#define Maxlst 64
64//static TCollection_AsciiString subl[Maxlst]; // Maxlst : minimum 10
65
66static Standard_Integer acceptvoid = 0;
67
68// ---------- Fonctions Utilitaires ----------
69
70//=======================================================================
71//function : CleanText
72//purpose :
73//=======================================================================
74static void CleanText (const Handle(TCollection_HAsciiString)& val)
75{
76 Standard_Integer n = val->Length(); // avant reduction
77 val->Remove(n);
78 val->Remove(1);
79// Ne pas oublier de traiter les caracteres speciaux
80 for (Standard_Integer i = n-2; i > 0; i --) {
81 char uncar = val->Value(i);
82 if (uncar == '\n')
83 { val->Remove(i); if (i < n-2) uncar = val->Value(i); }
84 if (uncar == '\'' && i < n-2) {
85 if (val->Value(i+1) == '\'') { val->Remove(i+1); continue; }
86 }
87 if (uncar == '\\' && i < n-2) {
88 if (val->Value(i+1) == '\\') { val->Remove(i+1); continue; }
89 }
90 else if (uncar == '\\' && i < n-3) {
91 if (val->Value(i+2) == '\\') {
92 if (val->Value(i+1) == 'N')
93 { val->SetValue(i,'\n'); val->Remove(i+1,2); continue; }
94 if (val->Value(i+1) == 'T')
95 { val->SetValue(i,'\t'); val->Remove(i+1,2); continue; }
96 }
97 }
98 }
99}
100
101// ------------- METHODES -------------
102
103//=======================================================================
104//function : StepData_StepReaderData
105//purpose :
106//=======================================================================
107
108StepData_StepReaderData::StepData_StepReaderData
109 (const Standard_Integer nbheader, const Standard_Integer nbtotal,
110 const Standard_Integer nbpar)
111: Interface_FileReaderData (nbtotal,nbpar), theidents (1,nbtotal),
112 thetypes (1,nbtotal) //, themults (1,nbtotal)
113{
114// char textnum[10];
115 thenbscop = 0; thenbents = 0; thelastn = 0; thenbhead = nbheader;
116 //themults.Init(0);
117 thecheck = new Interface_Check;
118//:S4136 acceptvoid = Interface_Static::IVal("step.readaccept.void");
119 if (initstr) return;
120 //for (Standard_Integer i = 0; i < Maxlst; i ++) {
121 // sprintf(textnum,"$%d",i+1);
122 // subl[i].AssignCat(textnum);
123 //}
124 initstr = Standard_True;
125}
126
127
128//=======================================================================
129//function : SetRecord
130//purpose :
131//=======================================================================
132
133void StepData_StepReaderData::SetRecord (const Standard_Integer num,
134 const Standard_CString ident,
135 const Standard_CString type,
136 const Standard_Integer /* nbpar */)
137{
138 Standard_Integer numlst;
139/*
140 if (strcmp(type,"/ * (SUB) * /") == 0) { // defini dans recfile.pc
141 thetypes.SetValue (num,sublist);
142 } else {
143 thenbents ++; // total de termes propres du fichier
144 thetypes.SetValue(num,TCollection_AsciiString(type));
145// if (strcmp(ident,"SCOPE") != 0) thenbscop ++; // ?? a verifier
146 }
147*/
148 if (type[0] != '(') thenbents ++; // total de termes propres du fichier
149
150 //thetypes.ChangeValue(num).SetValue(1,type); gka memory
151 //============================================
152 Standard_Integer index = 0;
153 TCollection_AsciiString strtype(type);
154 if(thenametypes.Contains(type))
155 index = thenametypes.FindIndex(strtype);
156 else index = thenametypes.Add(strtype);
157 thetypes.ChangeValue(num) = index;
158 //===========================================
159
160 if (ident[0] == '$') {
161 if (strlen(ident) > 2) numlst = atoi(&ident[1]);
162 else numlst = ident[1] - 48;
163 if (thelastn < numlst) thelastn = numlst; // plus fort n0 de sous-liste
164 theidents.SetValue(num,-2-numlst);
165 } else if (ident[0] == '#') {
166 numlst = atoi(&ident[1]);
167 theidents.SetValue(num,numlst);
168 if (numlst == 0 && num > thenbhead) {
169// Header, ou bien Type Complexe ...
170// Si Type Complexe, retrouver Type Precedent (on considere que c est rare)
171// On chaine le type precedent sur le suivant
172// VERIFICATION que les types sont en ordre alphabetique
173 for (Standard_Integer prev = num-1; prev > thenbhead; prev --) {
174 if (theidents(prev) >= 0) {
175
176 //themults.SetValue(prev,num);
177 themults.Bind(prev,num);
178 if(thenametypes.FindKey(thetypes.Value(num)).IsLess(thenametypes.FindKey(thetypes.Value(prev)))) {
179 //if (thetypes.Value(num).IsLess(thetypes.Value(prev)))
180
181// ERREUR : Type complexe pas en ordre alphabetique. On enregistre.
182 TCollection_AsciiString errm("Complex Type incorrect : ");
183 errm.AssignCat(thenametypes.FindKey(thetypes.Value(prev)));
184 errm.AssignCat(" / ");
185 errm.AssignCat(thenametypes.FindKey(thetypes.Value(num)));
186 errm.AssignCat(" ... ");
187 thecheck->AddFail(errm.ToCString(),"Complex Type incorrect : ");
188// On Affiche a l ecran, le plus de donnees possibles
189 while (theidents(prev) <= 0) {
190 prev --; if (prev <= 0) break;
191 }
192 Handle(Message_Messenger) sout = Message::DefaultMessenger();
193 sout << " *** Error on Record " << num << " (on " << NbRecords()
194 << " -> " << num*100/NbRecords() << " % in File) ***";
195 if (prev > 0) sout << " Ident #" << theidents(prev);
196 sout << "\n" << errm << endl;
197 }
198 break;
199 }
200 }
201 }
202 }
203 else if (!strcmp(ident,"SCOPE")) {
204 theidents.SetValue(num,-1); // SCOPE
205 thenbscop ++;
206 }
207 else if (!strcmp(ident,"ENDSCOPE")) theidents.SetValue(num,-2); // ENDSCOPE
208// Reste 0
209
210 // InitParams(num);
211}
212
213
214//=======================================================================
215//function : AddStepParam
216//purpose :
217//=======================================================================
218
219void StepData_StepReaderData::AddStepParam (const Standard_Integer num,
220 const Standard_CString aval,
221 const Interface_ParamType atype,
222 const Standard_Integer nument)
223{
224 if (atype == Interface_ParamSub) {
225 Standard_Integer numid = 0;
226 if (aval[2] != '\0') {
227 numid = atoi(&aval[1]);
228// if (numid <= Maxlst) Interface_FileReaderData::AddParam
229// (num,subl[numid-1].ToCString(),atype,numid);
230 Interface_FileReaderData::AddParam (num,aval,atype,numid);
231 } else {
232 char *numlstchar = (char *)(aval+1);
233 numid = (*numlstchar) - 48; // -48 ('0') -1 (adresse [] depuis 0)
234// Interface_FileReaderData::AddParam (num,subl[numid].ToCString(),atype,numid);
235 Interface_FileReaderData::AddParam (num,aval,atype,numid);
236 }
237 } else if (atype == Interface_ParamIdent) {
238 Standard_Integer numid = atoi(&aval[1]);
239 Interface_FileReaderData::AddParam (num,aval,atype,numid);
240 } else {
241 Interface_FileReaderData::AddParam (num,aval,atype,nument);
242 }
243
244// Interface_FileReaderData::AddParam (num,parval,atype,numid);
245}
246
247
248//=======================================================================
249//function : RecordType
250//purpose :
251//=======================================================================
252
253const TCollection_AsciiString& StepData_StepReaderData::RecordType
254 (const Standard_Integer num) const
255{
256 return thenametypes.FindKey(thetypes.Value(num));
257}
258
259
260//=======================================================================
261//function : CType
262//purpose :
263//=======================================================================
264
265Standard_CString StepData_StepReaderData::CType(const Standard_Integer num) const
266{
267 return thenametypes.FindKey(thetypes.Value(num)).ToCString();
268}
269
270
271//=======================================================================
272//function : RecordIdent
273//purpose :
274//=======================================================================
275
276Standard_Integer StepData_StepReaderData::RecordIdent (const Standard_Integer num) const
277{
278 return theidents(num);
279}
280
281
282// ########################################################################
283// .... Aides a la lecture des parametres, adaptees a STEP ....
284
285
286//=======================================================================
287//function : SubListNumber
288//purpose :
289//=======================================================================
290
291Standard_Integer StepData_StepReaderData::SubListNumber (const Standard_Integer num,
292 const Standard_Integer nump,
293 const Standard_Boolean aslast) const
294{
295 if (nump == 0 || nump > NbParams(num)) return 0;
296 const Interface_FileParameter& FP = Param(num,nump);
297 if (FP.ParamType() != Interface_ParamSub) return 0;
298 if (aslast) { if(nump != NbParams(num)) return 0; }
299 return FP.EntityNumber();
300}
301
302
303//=======================================================================
304//function : IsComplex
305//purpose :
306//=======================================================================
307
308Standard_Boolean StepData_StepReaderData::IsComplex(const Standard_Integer num) const
309{
310 //return (themults(num) != 0);
311 return themults.IsBound(num);
312}
313
314
315//=======================================================================
316//function : ComplexType
317//purpose :
318//=======================================================================
319
320void StepData_StepReaderData::ComplexType(const Standard_Integer num,
321 TColStd_SequenceOfAsciiString& types) const
322{
323 if (theidents(num) < 0) return;
324 for (Standard_Integer i = num; i > 0; i = NextForComplex(i)) {
325 types.Append(RecordType(i));
326 }
327}
328
329
330//=======================================================================
331//function : NextForComplex
332//purpose :
333//=======================================================================
334
335Standard_Integer StepData_StepReaderData::NextForComplex
336 (const Standard_Integer num) const
337{
338 Standard_Integer next =0;
339 if(themults.IsBound(num))
340 next = themults.Find(num);
341 return next;
342}
343
344
345//=======================================================================
346//function : stepstrcmp
347//purpose :
348//=======================================================================
349static Standard_Boolean stepstrcmp(const Standard_CString type,
350 const Standard_CString name)
351{
352// name peut etre d un tenant ou de deux : auquel cas il a une partie LONGUE
353// et une partie COURTE separees par un blanc
354// Attention : False pour dire OK, True sinon (car remplace strcmp)
355 Standard_Integer i,j = 0; Standard_Boolean res = Standard_False;
356 for (i = 0; name[i] != '\0' && type[i] != '\0' && !res ; i ++) {
d029c7ef 357 if (name[i] == ' ' && type[i] == '\0') { j = i; break; }
7fd59977 358 if (type[i] != name[i]) res = Standard_True;
359 }
360 if (!res || (j == 0)) return res;
361// Pas trouve et un blanc suit : on continue
362 for (i = j+1; name[i] != '\0'; i ++) {
363 if (type[i-j-1] != name[i]) return Standard_True;
364 }
365 return Standard_False;
366}
367
368
369//=======================================================================
370//function : NamedForComplex
371//purpose :
372//=======================================================================
373
374Standard_Boolean StepData_StepReaderData::NamedForComplex
375 (const Standard_CString name, const Standard_Integer num0,
376 Standard_Integer& num, Handle(Interface_Check)& ach) const
377{
378 //Standard_Boolean stat = Standard_True;
379 Standard_Integer n = (num <= 0 ? num0 : NextForComplex(num));
380 // sln 04,10.2001. BUC61003. if(n==0) the next function is not called in order to avoid exception
381 if ((n!=0) && (!stepstrcmp (RecordType(n).ToCString(),name)))
382 { num = n; return Standard_True; }
383
384 if (n == 0) /*stat =*/ NamedForComplex (name,num0,n,ach); // on a rembobine
385// Pas dans l ordre alphabetique : boucler
386 Handle(String) errmess = new String("Parameter n0.%d (%s) not a LIST");
387 sprintf (txtmes,errmess->ToCString(),num0,name);
388 for (n = num0; n > 0; n = NextForComplex(n)) {
389 if (!stepstrcmp (RecordType(n).ToCString(),name)) {
390 num = n;
391 errmess = new String("Complex Record n0.%d, member type %s not in alphabetic order");
392 sprintf (txtmes,errmess->ToCString(),num0,name);
393 ach->AddWarning(txtmes,errmess->ToCString());
394 return Standard_False;
395 }
396 }
397 num = 0;
398 errmess = new String("Complex Record n0.%d, member type %s not found");
399 sprintf (txtmes,errmess->ToCString(),num0,name);
400 ach->AddFail (txtmes,errmess->ToCString());
401 return Standard_False;
402}
403
404// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
405
406
407//=======================================================================
408//function : CheckNbParams
409//purpose :
410//=======================================================================
411
412Standard_Boolean StepData_StepReaderData::CheckNbParams(const Standard_Integer num,
413 const Standard_Integer nbreq,
414 Handle(Interface_Check)& ach,
415 const Standard_CString mess) const
416{
417 if (NbParams(num) == nbreq) return Standard_True;
418 Handle(String) errmess;
419 if (mess[0] == '\0') errmess = new String("Count of Parameters is not %d");
420 else errmess = new String("Count of Parameters is not %d for %s");
421 sprintf (txtmes,errmess->ToCString(),nbreq,mess);
422 ach->AddFail (txtmes,errmess->ToCString());
423 return Standard_False;
424}
425
426
427//=======================================================================
428//function : ReadSubList
429//purpose :
430//=======================================================================
431
432Standard_Boolean StepData_StepReaderData::ReadSubList(const Standard_Integer num,
433 const Standard_Integer nump,
434 const Standard_CString mess,
435 Handle(Interface_Check)& ach,
436 Standard_Integer& numsub,
437 const Standard_Boolean optional,
438 const Standard_Integer /* lenmin */,
439 const Standard_Integer /* lenmax */) const
440{
441 numsub = SubListNumber (num,nump,Standard_False);
442 if (numsub > 0) return Standard_True;
443// Si optionel indefini, on passe l eponge
444 numsub = 0;
445 Standard_Boolean isvoid = (Param(num,nump).ParamType() == Interface_ParamVoid);
446 if (isvoid && optional) return Standard_False;
447
448 Handle(String) errmess = new String("Parameter n0.%d (%s) not a LIST");
449 sprintf (txtmes,errmess->ToCString(),nump,mess);
450 if (acceptvoid && isvoid) ach->AddWarning(txtmes,errmess->ToCString());
451 else { ach->AddFail(txtmes,errmess->ToCString()); return Standard_False; }
452 return Standard_True;
453}
454
455
456// ... Facilites pour LateBinding
457
458
459//=======================================================================
460//function : ReadSub
461//purpose :
462//=======================================================================
463
464Standard_Integer StepData_StepReaderData::ReadSub(const Standard_Integer numsub,
465 const Standard_CString mess,
466 Handle(Interface_Check)& ach,
467 const Handle(StepData_PDescr)& descr,
468 Handle(Standard_Transient)& val) const
469{
470 Standard_Integer nbp = NbParams(numsub);
471 if (nbp == 0) return 0; // liste vide = Handle Null
472 const TCollection_AsciiString& rectyp = RecordType (numsub);
473 if (nbp == 1 && rectyp.ToCString()[0] != '(') {
474 // c est un type avec un parametre -> SelectNamed
475 // cf ReadSelect mais ici, on est deja sur le contenu du parametre
476 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
477 val = sn;
478 sn->SetName (rectyp.ToCString());
479 if (ReadAny (numsub,1,mess,ach,descr,sn)) return sn->Kind();
480 else return 0;
481 }
482
483 // cas courant : faire un HArray1 de ... de ... de quoi au fait
484 const Interface_FileParameter& FP0 = Param(numsub,1);
485 Interface_ParamType FT, FT0 = FP0.ParamType();
486 Standard_CString str = FP0.CValue();
487 Handle(TColStd_HArray1OfTransient) htr;
488 Handle(TColStd_HArray1OfInteger) hin;
489 Handle(TColStd_HArray1OfReal) hre;
490 Handle(Interface_HArray1OfHAsciiString) hst;
491 Standard_Integer kod = 0;
492 switch (FT0) {
493 case Interface_ParamMisc : return -1;
494 case Interface_ParamInteger : kod = 1; break;
495 case Interface_ParamReal : kod = 5; break;
496 case Interface_ParamIdent : kod = 7; break;
497 case Interface_ParamVoid : kod = 0; break;
498 case Interface_ParamText : kod = 6; break;
499 case Interface_ParamEnum : kod = 4; break; // a confirmer(logical)
500 /* kod = 4;
501 if ( str[0] == '.' && str[2] == '.' && str[3] == '\0' &&
502 (str[1] == 'T' || str[1] == 'F' || str[1] == 'U') ) kod = 3;
503 break; */ // svv #2
504 case Interface_ParamLogical : return -1;
505 case Interface_ParamSub : kod = 0; break;
506 case Interface_ParamHexa : return -1;
507 case Interface_ParamBinary : return -1;
508 default : return -1;
509 }
510 if (kod == 1 || kod == 3) { hin = new TColStd_HArray1OfInteger (1,nbp); val = hin; }
511 else if (kod == 5) { hre = new TColStd_HArray1OfReal (1,nbp); val = hre; }
512 else if (kod == 6) { hst = new Interface_HArray1OfHAsciiString (1,nbp); val = hst; }
513 else { htr = new TColStd_HArray1OfTransient (1,nbp); val = htr; }
514// Attention : si type variable, faudra changer son fusil d epaule -> htr
515
516 for (Standard_Integer ip = 1; ip <= nbp; ip ++) {
517 const Interface_FileParameter& FP = Param(numsub,ip);
518 str = FP.CValue();
519 FT = FP.ParamType();
520 switch (kod) {
521 case 1 : {
522 if (FT != Interface_ParamInteger) { kod = 0; break; }
523 hin->SetValue (ip,atoi(str)); break;
524 }
525 case 2 :
526 case 3 : {
527 if (FT != Interface_ParamEnum) { kod = 0; break; }
528 if (!strcmp(str,".F.")) hin->SetValue (ip,0);
529 else if (!strcmp(str,".T.")) hin->SetValue (ip,1);
530 else if (!strcmp(str,".U.")) hin->SetValue (ip,2);
531 else kod = 0;
532 break;
533 }
534 case 4 : {
535 if (FT != Interface_ParamEnum) { kod = 0; break; }
536 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
537 sn->SetEnum (-1,str);
538 htr->SetValue (ip,sn); break;
539 }
540 case 5 : {
541 if (FT != Interface_ParamReal) { kod = 0; break; }
542 hre->SetValue (ip,Interface_FileReaderData::Fastof(str)); break;
543 }
544 case 6 : {
545 if (FT != Interface_ParamText) { kod = 0; break; }
546 Handle(TCollection_HAsciiString) txt = new TCollection_HAsciiString(str);
547 CleanText (txt); hst->SetValue (ip,txt); break;
548 }
549 case 7 : {
550 Handle(Standard_Transient) ent = BoundEntity (FP.EntityNumber());
551 htr->SetValue (ip,ent); break;
552 }
553 default : break;
554 }
555// Restent les autres cas ... tout est possible. cf le type du Param
556 if (kod > 0) continue;
557// Il faut passer au transient ...
558 if (htr.IsNull()) {
559 htr = new TColStd_HArray1OfTransient (1,nbp); val = htr;
560 Standard_Integer jp;
561 if (!hin.IsNull()) {
562 for (jp = 1; jp < ip; jp ++) {
563 Handle(StepData_SelectInt) sin = new StepData_SelectInt;
564 sin->SetInt (hin->Value(jp));
565 htr->SetValue (jp,sin);
566 }
567 }
568 if (!hre.IsNull()) {
569 for (jp = 1; jp < ip; jp ++) {
570 Handle(StepData_SelectReal) sre = new StepData_SelectReal;
571 sre->SetReal (hre->Value(jp));
572 htr->SetValue (jp,sre);
573 }
574 }
575 if (!hst.IsNull()) {
576 for (jp = 1; jp < ip; jp ++) {
577 htr->SetValue (jp,hst->Value(jp));
578 }
579 }
580 }
581// A present, faut y aller : lire le champ et le mettre en place
582// Ce qui suit ressemble fortement a ReadAny ...
583
584 switch (FT) {
585 case Interface_ParamMisc : break;
586 case Interface_ParamInteger : {
587 Handle(StepData_SelectInt) sin = new StepData_SelectInt;
588 sin->SetInteger (atoi(str));
589 htr->SetValue (ip,sin); break;
590 }
591 case Interface_ParamReal : {
592 Handle(StepData_SelectReal) sre = new StepData_SelectReal;
593 sre->SetReal (Interface_FileReaderData::Fastof(str)); break;
594 //htr->SetValue (ip,sre); break; svv #2: unreachable
595 }
596 case Interface_ParamIdent : htr->SetValue (ip,BoundEntity (FP.EntityNumber())); break;
597 case Interface_ParamVoid : break;
598 case Interface_ParamEnum : {
599 Handle(StepData_SelectInt) sin;
600 Handle(StepData_SelectNamed) sna;
601 Standard_Integer logic = -1;
602// PTV 16.09.2000
603// set the default value of StepData_Logical
604 StepData_Logical slog = StepData_LUnknown;
605 if ( str[0] == '.' && str[2] == '.' && str[3] == '\0') {
606 if (str[1] == 'F') { slog = StepData_LFalse; logic = 0; }
607 else if (str[1] == 'T') { slog = StepData_LTrue; logic = 1; }
608 else if (str[1] == 'U') { slog = StepData_LUnknown; logic = 2; }
609 }
610 if (logic >= 0)
611 { sin = new StepData_SelectInt; sin->SetLogical(slog); htr->SetValue(ip,sin); }
612 else { sna = new StepData_SelectNamed;
613 sna->SetEnum (logic,str); htr->SetValue (ip,sna); }
614 break;
615 }
616 case Interface_ParamLogical : break;
617 case Interface_ParamText : {
618 Handle(TCollection_HAsciiString) txt = new TCollection_HAsciiString(str);
619 CleanText (txt); htr->SetValue (ip,txt); break;
620 }
621 case Interface_ParamSub : {
622 Handle(Standard_Transient) sub;
623 Standard_Integer nent = FP.EntityNumber();
624 Standard_Integer kind = ReadSub (nent,mess,ach,descr,sub); if (kind < 0) break;
625 htr->SetValue(ip,sub); break;
626 }
627 case Interface_ParamHexa : break;
628 case Interface_ParamBinary : break;
629 default : break;
630 }
631 return -1;
632 }
633 return 8; // pour Any
634}
635
636
637//=======================================================================
638//function : ReadMember
639//purpose :
640//=======================================================================
641
642Standard_Boolean StepData_StepReaderData::ReadMember(const Standard_Integer num,
643 const Standard_Integer nump,
644 const Standard_CString mess,
645 Handle(Interface_Check)& ach,
646 Handle(StepData_SelectMember)& val) const
647{
648 Handle(Standard_Transient) v = val;
649 Handle(StepData_PDescr) nuldescr;
650 if (v.IsNull()) return ReadAny (num,nump,mess,ach,nuldescr,val);
651 Standard_Boolean res = ReadAny (num,nump,mess,ach,nuldescr,v);
652 if (v == val) return res;
653 // changement -> refus
654 Handle(String) errmess =
655 new String("Parameter n0.%d (%s) : does not match SELECT clause");
656 sprintf (txtmes,errmess->ToCString(),nump,mess);
657 ach->AddFail(txtmes,errmess->ToCString());
658 return Standard_False;
659}
660
661
662//=======================================================================
663//function : ReadField
664//purpose :
665//=======================================================================
666
667Standard_Boolean StepData_StepReaderData::ReadField(const Standard_Integer num,
668 const Standard_Integer nump,
669 const Standard_CString mess,
670 Handle(Interface_Check)& ach,
671 const Handle(StepData_PDescr)& descr,
672 StepData_Field& fild) const
673{
674 const Interface_FileParameter& FP = Param(num,nump);
675 Standard_CString str = FP.CValue();
676 Standard_Boolean OK = Standard_True;
677 Standard_Integer nent, kind;
678 Handle(TCollection_HAsciiString) txt;
679 Handle(Standard_Transient) sub;
680 Interface_ParamType FT = FP.ParamType();
681 switch (FT) {
682 case Interface_ParamMisc : OK = Standard_False; break;
683 case Interface_ParamInteger : fild.SetInteger (atoi(str)); break;
684 case Interface_ParamReal :
685 fild.SetReal (Interface_FileReaderData::Fastof(str)); break;
686 case Interface_ParamIdent :
687 nent = FP.EntityNumber();
688 if (nent > 0) fild.SetEntity (BoundEntity(nent));
689 break;
690 case Interface_ParamVoid : break;
691 case Interface_ParamText :
692 txt = new TCollection_HAsciiString(str);
693 CleanText (txt); fild.Set (txt); break;
694 case Interface_ParamEnum :
695 if (!strcmp(str,".T.")) fild.SetLogical (StepData_LTrue);
696 else if (!strcmp(str,".F.")) fild.SetLogical (StepData_LFalse);
697 else if (!strcmp(str,".U.")) fild.SetLogical (StepData_LUnknown);
698 else fild.SetEnum (-1,str);
699 break;
700 case Interface_ParamLogical : OK = Standard_False; break;
701 case Interface_ParamSub :
702 nent = FP.EntityNumber();
703 kind = ReadSub (nent,mess,ach,descr,sub); if (kind < 0) break;
704 fild.Clear(kind); fild.Set (sub); break;
705 case Interface_ParamHexa : OK = Standard_False; break;
706 case Interface_ParamBinary : OK = Standard_False; break;
707 default : OK = Standard_False; break;
708 }
709
710 if (!OK) {
711 if (!strcmp(str,"*")) fild.SetDerived();
712 }
713 return Standard_True;
714}
715
716
717//=======================================================================
718//function : ReadList
719//purpose :
720//=======================================================================
721
722Standard_Boolean StepData_StepReaderData::ReadList(const Standard_Integer num,
723 Handle(Interface_Check)& ach,
724 const Handle(StepData_ESDescr)& descr,
725 StepData_FieldList& list) const
726{
727 // controler nbs egaux
728 Standard_Integer i,nb = list.NbFields();
729 if (!CheckNbParams (num,nb,ach,descr->TypeName())) return Standard_False;
730 for (i = 1; i <= nb; i ++) {
731 Handle(StepData_PDescr) pde = descr->Field(i);
732 StepData_Field& fild = list.CField(i);
733 ReadField (num,i,pde->Name(),ach,pde,fild);
734 }
735 return Standard_True;
736}
737
738
739//=======================================================================
740//function : ReadAny
741//purpose :
742//=======================================================================
743
744Standard_Boolean StepData_StepReaderData::ReadAny(const Standard_Integer num,
745 const Standard_Integer nump,
746 const Standard_CString mess,
747 Handle(Interface_Check)& ach,
748 const Handle(StepData_PDescr)& descr,
749 Handle(Standard_Transient)& val) const
750{
751 const Interface_FileParameter& FP = Param(num,nump);
752 Standard_CString str = FP.CValue();
753 Interface_ParamType FT = FP.ParamType();
754
755// A present, faut y aller : lire le champ et le mettre en place
756 switch (FT) {
757 case Interface_ParamMisc : break;
758 case Interface_ParamInteger : {
759 if (!val.IsNull()) {
760 DeclareAndCast(StepData_SelectMember,sm,val);
761 sm->SetInteger(atoi(str));
762 return Standard_True;
763 }
764 Handle(StepData_SelectInt) sin = new StepData_SelectInt;
765 sin->SetInteger (atoi(str));
766 val = sin;
767 return Standard_True;
768 }
769 case Interface_ParamReal : {
770 if (!val.IsNull()) {
771 DeclareAndCast(StepData_SelectMember,sm,val);
772 sm->SetReal (Interface_FileReaderData::Fastof(str));
773 return Standard_True;
774 }
775 Handle(StepData_SelectReal) sre = new StepData_SelectReal;
776 sre->SetReal (Interface_FileReaderData::Fastof(str));
777 val = sre;
778 return Standard_True;
779 }
780 case Interface_ParamIdent : {
781 Standard_Integer nent = FP.EntityNumber();
782 if (nent > 0) val = BoundEntity(nent);
783 return (!val.IsNull());
784 }
785 case Interface_ParamVoid : break;
786 case Interface_ParamEnum : {
787 Handle(StepData_SelectMember) sm;
788 if (!val.IsNull()) sm = GetCasted(StepData_SelectMember,val);
789 Handle(StepData_SelectInt) sin;
790 Handle(StepData_SelectNamed) sna;
791 Standard_Integer logic = -1;
792
793 // PTV 16.09.2000
794 // set the default value of StepData_Logical
795 StepData_Logical slog = StepData_LUnknown;
796 if ( str[0] == '.' && str[2] == '.' && str[3] == '\0') {
797 if (str[1] == 'F') { slog = StepData_LFalse; logic = 0; }
798 else if (str[1] == 'T') { slog = StepData_LTrue; logic = 1; }
799 else if (str[1] == 'U') { slog = StepData_LUnknown; logic = 2; }
800 }
801 if (logic >= 0) {
802 if (!sm.IsNull()) sm->SetLogical(slog);
803 else {
804 sin = new StepData_SelectInt; val = sin;
805 sin->SetLogical(slog);
806 }
807 }
808 else {
809 if (!sm.IsNull()) sm->SetEnum (logic,str);
810 else {
811 sna = new StepData_SelectNamed; val = sna; // Named sans nom...
812 sna->SetEnum (logic,str);
813 }
814 } // -> Select general
815 return Standard_True;
816 }
817 case Interface_ParamLogical : break;
818 case Interface_ParamText : {
819 Handle(TCollection_HAsciiString) txt = new TCollection_HAsciiString(str);
820 CleanText (txt);
821
822 // PDN May 2000: for reading SOURCE_ITEM (external references)
823 if (!val.IsNull()) {
824 DeclareAndCast(StepData_SelectMember,sm,val);
825 sm->SetString (txt->ToCString());
826 return Standard_True;
827 }
828
829 val = txt;
830 return Standard_True;
831 }
832 case Interface_ParamSub : {
833 Standard_Integer numsub = SubListNumber (num,nump,Standard_False);
834 Standard_Integer nbp = NbParams(numsub);
835 if (nbp == 0) return Standard_False; // liste vide = Handle Null
836 const TCollection_AsciiString& rectyp = RecordType (numsub);
837 if (nbp == 1 && rectyp.ToCString()[0] != '(') {
838 // SelectNamed because Field !!!
839 // skl 15.01.2003 (for members with array of real)
840 DeclareAndCast(StepData_SelectArrReal,sma,val);
841 if(!sma.IsNull()) {
842 Standard_Integer numsub2 = SubListNumber (numsub,1,Standard_False);
843 Standard_Integer nbp2 = NbParams(numsub2);
844 if(nbp2>1) {
845 if( Param(numsub2,1).ParamType() == Interface_ParamReal ) {
846 if (!sma->SetName (rectyp.ToCString())) return Standard_False;
847 Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal;
848 for(Standard_Integer i=1; i<=nbp2; i++) {
849 if( Param(numsub2,i).ParamType() != Interface_ParamReal ) continue;
850 Handle(StepData_SelectReal) sm1 = new StepData_SelectReal;
851 if( !ReadAny(numsub2,i,mess,ach,descr,sm1) ) continue;
852 aSeq->Append(sm1->Real());
853 }
854 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,aSeq->Length());
855 for(Standard_Integer nr=1; nr<=aSeq->Length(); nr++) {
856 anArr->SetValue(nr,aSeq->Value(nr));
857 }
858 sma->SetArrReal(anArr);
859 return Standard_True;
860 }
861 }
862 }
863 DeclareAndCast(StepData_SelectMember,sm,val);
864 if (sm.IsNull()) {
865 sm = new StepData_SelectNamed;
866 val = sm;
867 }
868 if (!sm->SetName (rectyp.ToCString())) return Standard_False; // loupe
869 return ReadAny (numsub,1,mess,ach,descr,val);
870 }
871 }
872 default : break;
873 }
874 return Standard_False;
875}
876
877
878// ....
879
880
881//=======================================================================
882//function : ReadXY
883//purpose :
884//=======================================================================
885
886Standard_Boolean StepData_StepReaderData::ReadXY(const Standard_Integer num,
887 const Standard_Integer nump,
888 const Standard_CString mess,
889 Handle(Interface_Check)& ach,
890 Standard_Real& X, Standard_Real& Y) const
891{
892 Handle(String) errmess; // Null si pas d erreur
893 Standard_Integer numsub = SubListNumber(num,nump,Standard_False);
894 if (numsub != 0) {
895 if (NbParams(numsub) == 2) {
896 const Interface_FileParameter& FPX = Param(numsub,1);
897 if (FPX.ParamType() == Interface_ParamReal) X =
898 Interface_FileReaderData::Fastof(FPX.CValue());
899 else errmess = new String("Parameter n0.%d (%s) : (X,Y) X not a Real");
900
901 const Interface_FileParameter& FPY = Param(numsub,2);
902 if (FPY.ParamType() == Interface_ParamReal) Y =
903 Interface_FileReaderData::Fastof( FPY.CValue());
904 else errmess = new String("Parameter n0.%d (%s) : (X,Y) Y not a Real");
905
906 }
907 else errmess = new String("Parameter n0.%d (%s) : (X,Y) has not 2 params");
908 }
909 else errmess = new String("Parameter n0.%d (%s) : (X,Y) not a SubList");
910
911 if (errmess.IsNull()) return Standard_True;
912 sprintf (txtmes,errmess->ToCString(),nump,mess);
913 ach->AddFail(txtmes,errmess->ToCString());
914 return Standard_False;
915}
916
917
918//=======================================================================
919//function : ReadXYZ
920//purpose :
921//=======================================================================
922
923Standard_Boolean StepData_StepReaderData::ReadXYZ(const Standard_Integer num,
924 const Standard_Integer nump,
925 const Standard_CString mess,
926 Handle(Interface_Check)& ach,
927 Standard_Real& X, Standard_Real& Y,
928 Standard_Real& Z) const
929{
930 Handle(String) errmess; // Null si pas d erreur
931 Standard_Integer numsub = SubListNumber(num,nump,Standard_False);
932 if (numsub != 0) {
933 if (NbParams(numsub) == 3) {
934 const Interface_FileParameter& FPX = Param(numsub,1);
935 if (FPX.ParamType() == Interface_ParamReal) X =
936 Interface_FileReaderData::Fastof(FPX.CValue());
937 else errmess = new String("Parameter n0.%d (%s) : (X,Y,Z) X not a Real");
938
939 const Interface_FileParameter& FPY = Param(numsub,2);
940 if (FPY.ParamType() == Interface_ParamReal) Y =
941 Interface_FileReaderData::Fastof(FPY.CValue());
942 else errmess = new String("Parameter n0.%d (%s) : (X,Y,Z) Y not a Real");
943
944 const Interface_FileParameter& FPZ = Param(numsub,3);
945 if (FPZ.ParamType() == Interface_ParamReal) Z =
946 Interface_FileReaderData::Fastof(FPZ.CValue());
947 else errmess = new String("Parameter n0.%d (%s) : (X,Y,Z) Z not a Real");
948
949 }
950 else errmess = new String("Parameter n0.%d (%s) : (X,Y,Z) has not 3 params");
951 }
952 else errmess = new String("Parameter n0.%d (%s) : (X,Y,Z) not a SubList");
953
954 if (errmess.IsNull()) return Standard_True;
955 sprintf (txtmes,errmess->ToCString(),nump,mess);
956 ach->AddFail(txtmes,errmess->ToCString());
957 return Standard_False;
958}
959
960
961//=======================================================================
962//function : ReadReal
963//purpose :
964//=======================================================================
965
966Standard_Boolean StepData_StepReaderData::ReadReal(const Standard_Integer num,
967 const Standard_Integer nump,
968 const Standard_CString mess,
969 Handle(Interface_Check)& ach,
970 Standard_Real& val) const
971{
972 Handle(String) errmess; // Null si pas d erreur
973 if (nump > 0 && nump <= NbParams(num)) {
974 const Interface_FileParameter& FP = Param(num,nump);
975 if (FP.ParamType() == Interface_ParamReal) val =
976 Interface_FileReaderData::Fastof(FP.CValue());
977 else errmess = new String("Parameter n0.%d (%s) not a Real");
978 }
979 else errmess = new String("Parameter n0.%d (%s) absent");
980
981 if (errmess.IsNull()) return Standard_True;
982 sprintf (txtmes,errmess->ToCString(),nump,mess);
983 ach->AddFail(txtmes,errmess->ToCString());
984 return Standard_False;
985}
986
987
988// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
989
990
991//=======================================================================
992//function : ReadEntity
993//purpose :
994//=======================================================================
995
996Standard_Boolean StepData_StepReaderData::ReadEntity(const Standard_Integer num,
997 const Standard_Integer nump,
998 const Standard_CString mess,
999 Handle(Interface_Check)& ach,
1000 const Handle(Standard_Type)& atype,
1001 Handle(Standard_Transient)& ent) const
1002{
1003 Handle(String) errmess; // Null si pas d erreur
1004 Standard_Boolean warn = Standard_False;
1005 if (nump > 0 && nump <= NbParams(num)) {
1006 const Interface_FileParameter& FP = Param(num,nump);
1007 Standard_Integer nent = FP.EntityNumber();
1008 if (FP.ParamType() == Interface_ParamIdent) {
1009 warn = (acceptvoid > 0);
1010 if (nent > 0) {
1011 Handle(Standard_Transient) entent = BoundEntity(nent);
1012 if (entent.IsNull() || !entent->IsKind(atype))
1013 errmess = new String("Parameter n0.%d (%s) : Entity has illegal type");
1014 else ent = entent;
1015 }
1016 else errmess = new String("Parameter n0.%d (%s) : Unresolved reference");
1017 }
1018 else {
1019 if (acceptvoid && FP.ParamType() == Interface_ParamVoid) warn = Standard_True;
1020 errmess = new String("Parameter n0.%d (%s) not an Entity");
1021 }
1022 }
1023 else {
1024 warn = (acceptvoid > 0);
1025 errmess = new String("Parameter n0.%d (%s) absent");
1026 }
1027
1028 if (errmess.IsNull()) return Standard_True;
1029 sprintf (txtmes,errmess->ToCString(),nump,mess);
1030 if (warn) ach->AddWarning(txtmes,errmess->ToCString());
1031 else ach->AddFail(txtmes,errmess->ToCString());
1032 return Standard_False;
1033}
1034
1035
1036//=======================================================================
1037//function : ReadEntity
1038//purpose :
1039//=======================================================================
1040
1041Standard_Boolean StepData_StepReaderData::ReadEntity(const Standard_Integer num,
1042 const Standard_Integer nump,
1043 const Standard_CString mess,
1044 Handle(Interface_Check)& ach,
1045 StepData_SelectType& sel) const
1046{
1047 Handle(String) errmess; // Null si pas d erreur
1048 Standard_Boolean warn = Standard_False;
1049 if (nump > 0 && nump <= NbParams(num)) {
1050 const Interface_FileParameter& FP = Param(num,nump);
1051 Standard_Integer nent = FP.EntityNumber();
1052 if (FP.ParamType() == Interface_ParamIdent) {
1053 warn = (acceptvoid > 0);
1054 if (nent > 0) {
1055 Handle(Standard_Transient) entent = BoundEntity(nent);
1056 if (!sel.Matches(entent))
1057 errmess = new String("Parameter n0.%d (%s) : Entity has illegal type");
1058 else
1059 sel.SetValue(entent);
1060 }
1061 else
1062 errmess = new String("Parameter n0.%d (%s) : Unresolved reference");
1063 }
1064 else if (FP.ParamType() == Interface_ParamVoid) {
1065 if (acceptvoid) warn = Standard_True;
1066 errmess = new String("Parameter n0.%d (%s) not an Entity");
1067 }
1068 else {
1069 // Cas restant : on s interesse en fait au SelectMember ...
1070 Handle(Standard_Transient) sm = sel.NewMember();
1071 // SelectMember qui assure ce role. Peut etre specialise
1072 if (!ReadAny (num,nump,mess,ach,sel.Description(),sm))
1073 errmess = new String("Parameter n0.%d (%s) : could not be read");
1074 if (!sel.Matches(sm))
1075 errmess = new String("Parameter n0.%d (%s) : illegal parameter type");
1076 else
1077 sel.SetValue(sm);
1078 }
1079 }
1080 else {
1081 warn = (acceptvoid > 0);
1082 errmess = new String("Parameter n0.%d (%s) absent");
1083 }
1084
1085 if (errmess.IsNull()) return Standard_True;
1086 sprintf (txtmes,errmess->ToCString(),nump,mess);
1087 if (warn) ach->AddWarning(txtmes,errmess->ToCString());
1088 else ach->AddFail(txtmes,errmess->ToCString());
1089 return Standard_False;
1090}
1091
1092
1093// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
1094
1095
1096//=======================================================================
1097//function : ReadInteger
1098//purpose :
1099//=======================================================================
1100
1101Standard_Boolean StepData_StepReaderData::ReadInteger(const Standard_Integer num,
1102 const Standard_Integer nump,
1103 const Standard_CString mess,
1104 Handle(Interface_Check)& ach,
1105 Standard_Integer& val) const
1106{
1107 Handle(String) errmess; // Null si pas d erreur
1108 if (nump > 0 && nump <= NbParams(num)) {
1109 const Interface_FileParameter& FP = Param(num,nump);
1110 if (FP.ParamType() == Interface_ParamInteger) val = atoi(FP.CValue());
1111 else errmess = new String("Parameter n0.%d (%s) not an Integer");
1112 }
1113 else errmess = new String("Parameter n0.%d (%s) absent");
1114
1115 if (errmess.IsNull()) return Standard_True;
1116 sprintf (txtmes,errmess->ToCString(),nump,mess);
1117 ach->AddFail(txtmes,errmess->ToCString());
1118 return Standard_False;
1119}
1120
1121
1122//=======================================================================
1123//function : ReadBoolean
1124//purpose :
1125//=======================================================================
1126
1127Standard_Boolean StepData_StepReaderData::ReadBoolean(const Standard_Integer num,
1128 const Standard_Integer nump,
1129 const Standard_CString mess,
1130 Handle(Interface_Check)& ach,
1131 Standard_Boolean& flag) const
1132{
1133 Handle(String) errmess; // Null si pas d erreur
1134 if (nump > 0 && nump <= NbParams(num)) {
1135 const Interface_FileParameter& FP = Param(num,nump);
1136 if (FP.ParamType() == Interface_ParamEnum) {
1137 Standard_CString txt = FP.CValue();
1138 if (!strcmp(txt,".T.")) flag = Standard_True;
1139 else if (!strcmp(txt,".F.")) flag = Standard_False;
1140 else errmess = new String("Parameter n0.%d (%s) : Incorrect Boolean Value");
1141 }
1142 else errmess = new String("Parameter n0.%d (%s) not a Boolean");
1143 }
1144 else errmess = new String("Parameter n0.%d (%s) absent");
1145
1146 if (errmess.IsNull()) return Standard_True;
1147 sprintf (txtmes,errmess->ToCString(),nump,mess);
1148 ach->AddFail(txtmes,errmess->ToCString());
1149 return Standard_False;
1150}
1151
1152
1153//=======================================================================
1154//function : ReadLogical
1155//purpose :
1156//=======================================================================
1157
1158Standard_Boolean StepData_StepReaderData::ReadLogical(const Standard_Integer num,
1159 const Standard_Integer nump,
1160 const Standard_CString mess,
1161 Handle(Interface_Check)& ach,
1162 StepData_Logical& flag) const
1163{
1164 Handle(String) errmess; // Null si pas d erreur
1165 if (nump > 0 && nump <= NbParams(num)) {
1166 const Interface_FileParameter& FP = Param(num,nump);
1167 if (FP.ParamType() == Interface_ParamEnum) {
1168 Standard_CString txt = FP.CValue();
1169 if (!strcmp(txt,".T.")) flag = StepData_LTrue;
1170 else if (!strcmp(txt,".F.")) flag = StepData_LFalse;
1171 else if (!strcmp(txt,".U.")) flag = StepData_LUnknown;
1172 else errmess = new String("Parameter n0.%d (%s) : Incorrect Logical Value");
1173 }
1174 else errmess = new String("Parameter n0.%d (%s) not a Logical");
1175 }
1176 else errmess = new String("Parameter n0.%d (%s) absent");
1177
1178 if (errmess.IsNull()) return Standard_True;
1179 sprintf (txtmes,errmess->ToCString(),nump,mess);
1180 ach->AddFail(txtmes,errmess->ToCString());
1181 return Standard_False;
1182}
1183
1184
1185//=======================================================================
1186//function : ReadString
1187//purpose :
1188//=======================================================================
1189
1190Standard_Boolean StepData_StepReaderData::ReadString(const Standard_Integer num,
1191 const Standard_Integer nump,
1192 const Standard_CString mess,
1193 Handle(Interface_Check)& ach,
1194 Handle(TCollection_HAsciiString)& val) const
1195{
1196 Handle(String) errmess; // Null si pas d erreur
1197 Standard_Boolean warn = Standard_False;
1198 if (nump > 0 && nump <= NbParams(num)) {
1199 const Interface_FileParameter& FP = Param(num,nump);
1200 if (FP.ParamType() == Interface_ParamText) {
1201 /*Standard_CString anStr = FP.CValue();
1202 if(strlen(anStr) < 3)
1203 val = new TCollection_HAsciiString("");
1204 else {
1205 val = new TCollection_HAsciiString(FP.CValue());
1206 CleanText (val);
1207 }*/
1208 val = new TCollection_HAsciiString(FP.CValue());
1209 CleanText (val);
1210 } else {
1211 if (acceptvoid && FP.ParamType() == Interface_ParamVoid) warn = Standard_True;
1212 errmess = new String("Parameter n0.%d (%s) not a quoted String");
1213 }
1214 }
1215 else errmess = new String("Parameter n0.%d (%s) absent");
1216
1217 if (errmess.IsNull()) return Standard_True;
1218 sprintf (txtmes,errmess->ToCString(),nump,mess);
1219 if (warn) ach->AddWarning(txtmes,errmess->ToCString());
1220 else ach->AddFail(txtmes,errmess->ToCString());
1221 return Standard_False;
1222}
1223
1224
1225//=======================================================================
1226//function : ReadEnumParam
1227//purpose :
1228//=======================================================================
1229
1230Standard_Boolean StepData_StepReaderData::ReadEnumParam(const Standard_Integer num,
1231 const Standard_Integer nump,
1232 const Standard_CString mess,
1233 Handle(Interface_Check)& ach,
1234 Standard_CString& text) const
1235{
1236 Handle(String) errmess; // Null si pas d erreur
1237 Standard_Boolean warn = Standard_False;
1238 if (nump > 0 && nump <= NbParams(num)) {
1239 const Interface_FileParameter& FP = Param(num,nump);
1240 if (FP.ParamType() == Interface_ParamEnum) {
1241 text = FP.CValue();
1242 warn = (acceptvoid > 0);
1243 } else if (FP.ParamType() == Interface_ParamVoid) {
1244 errmess =
1245 new String("Parameter n0.%d (%s) : Undefined Enumeration not allowed");
1246 warn = (acceptvoid > 0);
1247 }
1248 else errmess = new String("Parameter n0.%d (%s) not an Enumeration");
1249 }
1250 else errmess = new String("Parameter n0.%d (%s) absent");
1251
1252 if (errmess.IsNull()) return Standard_True;
1253 sprintf (txtmes,errmess->ToCString(),nump,mess);
1254 if (warn) ach->AddWarning(txtmes,errmess->ToCString());
1255 else ach->AddFail(txtmes,errmess->ToCString());
1256 return Standard_False;
1257}
1258
1259
1260//=======================================================================
1261//function : FailEnumValue
1262//purpose :
1263//=======================================================================
1264
1265void StepData_StepReaderData::FailEnumValue(const Standard_Integer /* num */,
1266 const Standard_Integer nump,
1267 const Standard_CString mess,
1268 Handle(Interface_Check)& ach) const
1269{
1270 Handle(String) errmess =
1271 new String("Parameter n0.%d (%s) : Incorrect Enumeration Value");
1272 sprintf (txtmes,errmess->ToCString(),nump,mess);
1273 ach->AddFail(txtmes,errmess->ToCString());
1274}
1275
1276
1277//=======================================================================
1278//function : ReadEnum
1279//purpose :
1280//=======================================================================
1281
1282Standard_Boolean StepData_StepReaderData::ReadEnum(const Standard_Integer num,
1283 const Standard_Integer nump,
1284 const Standard_CString mess,
1285 Handle(Interface_Check)& ach,
1286 const StepData_EnumTool& enumtool,
1287 Standard_Integer& val) const
1288{
1289// reprendre avec ReadEnumParam ?
1290 Handle(String) errmess; // Null si pas d erreur
1291 Standard_Boolean warn = Standard_False;
1292 if (nump > 0 && nump <= NbParams(num)) {
1293 const Interface_FileParameter& FP = Param(num,nump);
1294 if (FP.ParamType() == Interface_ParamEnum) {
1295 val = enumtool.Value (FP.CValue());
1296 if (val >= 0) return Standard_True;
1297 else errmess = new String("Parameter n0.%d (%s) : Incorrect Enumeration Value");
1298 warn = (acceptvoid > 0);
1299 }
1300 else if (FP.ParamType() == Interface_ParamVoid) {
1301 val = enumtool.NullValue();
1302 if (val < 0) errmess =
1303 new String("Parameter n0.%d (%s) : Undefined Enumeration not allowed");
1304 warn = (acceptvoid > 0);
1305 }
1306 else errmess = new String("Parameter n0.%d (%s) not an Enumeration");
1307 }
1308 else errmess = new String("Parameter n0.%d (%s) absent");
1309
1310 if (errmess.IsNull()) return Standard_True;
1311 sprintf (txtmes,errmess->ToCString(),nump,mess);
1312 if (warn)
1313 ach->AddWarning(txtmes,errmess->ToCString());
1314 else
1315 ach->AddFail(txtmes,errmess->ToCString());
1316 return Standard_False;
1317}
1318
1319
1320//=======================================================================
1321//function : ReadTypedParam
1322//purpose :
1323//=======================================================================
1324
1325Standard_Boolean StepData_StepReaderData::ReadTypedParam(const Standard_Integer num,
1326 const Standard_Integer nump,
1327 const Standard_Boolean mustbetyped,
1328 const Standard_CString mess,
1329 Handle(Interface_Check)& ach,
1330 Standard_Integer& numr,
1331 Standard_Integer& numrp,
1332 TCollection_AsciiString& typ) const
1333{
1334 Handle(String) errmess; // Null si pas d erreur
1335 if (nump > 0 && nump <= NbParams(num)) {
1336 const Interface_FileParameter& FP = Param(num,nump);
1337 if (FP.ParamType() != Interface_ParamSub) {
1338 // Pas une sous-liste : OK si admis
1339 numr = num; numrp = nump; typ.Clear();
1340 if (mustbetyped) {
1341 errmess = new String("Parameter n0.%d (%s) : single, not typed");
1342 sprintf (txtmes,errmess->ToCString(),nump,mess);
1343 ach->AddFail(txtmes,errmess->ToCString());
1344 return Standard_False;
1345 }
1346 return Standard_True;
1347 }
1348 numr = FP.EntityNumber(); numrp = 1;
1349 if (NbParams(numr) != 1) errmess =
1350 new String("Parameter n0.%d (%s) : SubList, not typed");
1351 typ = RecordType(numr);
1352 }
1353 else errmess = new String("Parameter n0.%d (%s) absent");
1354
1355 if (errmess.IsNull()) return Standard_True;
1356 sprintf (txtmes,errmess->ToCString(),nump,mess);
1357 ach->AddFail(txtmes,errmess->ToCString());
1358 return Standard_False;
1359}
1360
1361
1362//=======================================================================
1363//function : CheckDerived
1364//purpose :
1365//=======================================================================
1366
1367Standard_Boolean StepData_StepReaderData::CheckDerived(const Standard_Integer num,
1368 const Standard_Integer nump,
1369 const Standard_CString mess,
1370 Handle(Interface_Check)& ach,
1371 const Standard_Boolean errstat) const
1372{
1373 Handle(String) errmess; // Null si pas d erreur
1374 Standard_Boolean warn = !errstat;
1375 if (nump > 0 && nump <= NbParams(num)) {
1376 if (!strcmp(Param(num,nump).CValue(),"*")) return Standard_True;
1377 else errmess = new String("Parameter n0.%d (%s) not Derived");
1378 if (acceptvoid) warn = Standard_True;
1379 }
1380 else errmess = new String("Parameter n0.%d (%s) absent");
1381
1382 if (errmess.IsNull()) return Standard_True;
1383 sprintf (txtmes,errmess->ToCString(),nump,mess);
1384 if (warn) ach->AddWarning (txtmes,errmess->ToCString());
1385 else ach->AddFail (txtmes,errmess->ToCString());
1386 return Standard_False;
1387}
1388
1389
1390// #########################################################################
1391// .... Methodes specifiques (demandees par FileReaderData) .... //
1392
1393
1394//=======================================================================
1395//function : NbEntities
1396//purpose :
1397//=======================================================================
1398
1399Standard_Integer StepData_StepReaderData::NbEntities () const // redefined
1400{
1401 return thenbents;
1402}
1403
1404
1405//=======================================================================
1406//function : FindNextRecord
1407//purpose :
1408//=======================================================================
1409
1410Standard_Integer StepData_StepReaderData::FindNextRecord
1411 (const Standard_Integer num) const
1412{
1413 // retourne, sur un numero d enregistrement donne (par num), le suivant qui
1414 // definit une entite, ou 0 si c est fini :
1415 // passe le Header (nbhend premiers records) et
1416 // saute les enregistrements SCOPE et ENDSCOPE et les SOUS-LISTES
1417
1418 if (num < 0) return 0 ;
1419 Standard_Integer num1 = num + 1 ; if (num == 0) num1 = thenbhead + 1;
1420 Standard_Integer max = NbRecords() ;
1421
1422 while (num1 <= max ) {
1423 if (theidents(num1) > 0) return num1;
1424
1425 // SCOPE,ENDSCOPE et Sous-Liste ont un identifieur fictif: -1,-2 respectivement
1426 // et SUBLIST ont un negatif. Seule une vraie entite a un Ident positif
1427 num1 ++ ;
1428 }
1429 return 0;
1430}
1431
1432
1433//=======================================================================
1434//function : FindEntityNumber
1435//purpose :
1436//=======================================================================
1437
1438Standard_Integer StepData_StepReaderData::FindEntityNumber(const Standard_Integer num,
1439 const Standard_Integer id) const
1440{
1441 // Soit un "Id" : recherche dans les Parametres de type Ident de <num>,
1442 // si un d eux designe #Id justement. Si oui, retourne son EntityNumber
1443 if (num == 0) return 0;
1444 Standard_Integer nb = NbParams(num);
1445 for (Standard_Integer i = 1; i <= nb; i ++) {
1446 const Interface_FileParameter& FP = Param(num,i);
1447 if (FP.ParamType() != Interface_ParamIdent) continue;
1448 Standard_Integer ixp = atoi( &FP.CValue()[1] );
1449 if (ixp == id) return FP.EntityNumber();
1450 }
1451 return 0; // ici, pas trouve
1452}
1453
1454
1455// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
1456// .... La fonction qui suit merite une attention speciale ....
1457
1458
1459// Cette methode precharge les EntityNumbers dans les Params : ils designent
1460// les Entites proprement dites dans la liste lue par BoundEntity
1461// Interet : adresse de meme les sous-listes (Num->no record dans le Direc)
1462// resultat exploite par ParamEntity et ParamNumber
1463
1464// En l absence de SCOPE, ou si les "ident" sont strictement ordonnes, a coup
1465// sur ils ne sont pas dupliques, on peut utiliser une IndexedMap en toute
1466// confiance. Sinon, il faut balayer dans le fichier, mais avec les SCOPES
1467// cela va beaucoup plus vite (s ils sont assez gros) : on s y retrouve.
1468
1469// Pour la recherche par balayage, On opere en plusieurs etapes
1470// Avant toute chose, le chargement a deja fait une preparation : les idents
1471// (Entity, SubList) sont deja en entiers (rapidite de lecture), en particulier
1472// dans les EntityNumber : ainsi, on lit cet ident, on le traite, et on remet
1473// a la place un vrai numero de Record
1474//
1475// D abord, on passe le directory en table d entiers, sous-listes expurgees
1476// en // , table inverse vers cette table, car les sous-listes peuvent par
1477// contre designer des objets ...
1478
1479// Pour les sous-listes, on exploite leur mode de construction : elles sont
1480// enregistrees AVANT d etre referencees. Un tableau "subn" note donc pour
1481// chaque numero de sous-liste (relatif a une entite qui suit, et reference
1482// par elle ou une autre sous-liste qui suit egalement), son n0 de record
1483// REMARQUE : ceci marche aussi pour le Header, traite par l occasion
1484
1485
1486//=======================================================================
1487//function : SetEntityNumbers
1488//purpose :
1489//=======================================================================
1490
1491void StepData_StepReaderData::SetEntityNumbers(const Standard_Boolean withmap)
1492{
1493 Handle(Message_Messenger) sout = Message::DefaultMessenger();
1494// Passe initiale : Resolution directe par Map
1495// si tout passe (pas de collision), OK. Sinon, autres passes a prevoir
1496// On resoud du meme coup les sous-listes
1497 Standard_Integer nbdirec = NbRecords() ;
1d37eeb6 1498 TColStd_Array1OfInteger subn(0, thelastn);
7fd59977 1499
1500 Standard_Boolean pbmap = Standard_False; // au moins un conflit
1501 Standard_Integer nbmap = 0;
1502 TColStd_IndexedMapOfInteger imap(thenbents);
1d37eeb6 1503 TColStd_Array1OfInteger indm(0, nbdirec); // Index Map -> Record Number (seulement si map)
7fd59977 1504
1505 Standard_Integer num; // svv Jan11 2000 : porting on DEC
1506 for (num = 1 ; num <= nbdirec ; num ++) {
1507 Standard_Integer ident = theidents(num);
1508 if (ident > 0) { // Ident normal -> Map ?
1509// Map : si Recouvrement, l inhiber. Sinon, noter index
1510 Standard_Integer indmap = imap.Add(ident);
1511 if (indmap <= nbmap) {
1512 indmap = imap.FindIndex(ident); // plus sur
1d37eeb6 1513 indm(indmap) = -1; // Map -> pb
7fd59977 1514 pbmap = Standard_True;
1515// pbmap signifie qu une autre passe sera necessaire ...
1516 } else {
1517 nbmap = indmap;
1d37eeb6 1518 indm(indmap) = num; // Map ->ident
7fd59977 1519 }
1520 }
1521 }
1522
1523 for (num = 1 ; num <= nbdirec ; num ++) {
1524 Standard_Integer ident = theidents(num);
1d37eeb6 1525 if (ident < -2) subn(-(ident+2)) = num; // toujours a jour ...
7fd59977 1526
1527 Standard_Integer nba = NbParams(num) ;
1528 Standard_Integer nda = (num == 1 ? 0 : ParamFirstRank(num-1));
1529
1530 for (Standard_Integer na = nba ; na > 0 ; na --) {
1531// On traite : les sous-listes (sf subn), les idents (si Map dit OK ...)
1532 Interface_FileParameter& FP = ChangeParameter (nda+na);
1533// Interface_FileParameter& FP = ChangeParam (num,na);
1534 Interface_ParamType letype = FP.ParamType();
1535 if (letype == Interface_ParamSub) {
1536 Standard_Integer numsub = FP.EntityNumber();
1537 if (numsub > thelastn) {
1538 sout<<"Bad Sub.N0, Record "<<num<<" Param "<<na<<":$"<<numsub<<endl;
1539 continue;
1540 }
1d37eeb6 1541 FP.SetEntityNumber(subn(numsub));
7fd59977 1542 } else if (letype == Interface_ParamIdent) {
1543 Standard_Integer id = FP.EntityNumber();
1544 Standard_Integer indmap = imap.FindIndex(id);
1545 if (indmap > 0) { // la map a trouve
1d37eeb6 1546 Standard_Integer num0 = indm(indmap);
7fd59977 1547 if (num0 > 0) FP.SetEntityNumber(num0); // ET VOILA, on a resolu
1548 else FP.SetEntityNumber(-id); // CONFLIT -> faudra resoudre ...
1549 } else { // NON RESOLU, si pas pbmap, le dire
1550 FP.SetEntityNumber(-id);
1551 if (pbmap) continue; // pbmap : on se retrouvera
1552 char failmess[100];
1553// ... Construire le Check ...
1554 sprintf(failmess,
1555 "Unresolved Reference, Ent.Id.#%d Param.n0 %d (Id.#%d)",
1556 ident,na,id);
1557 thecheck->AddFail(failmess,"Unresolved Reference");
1558// ... Et sortir message un peu plus complet
1559 sout << "*** ERR StepReaderData *** Pour Entite #"<< ident
1560 << "\n Type:" << RecordType(num)
1561 << " Param.n0 " << na << ": #" << id << " Non trouve" << endl ;
1562 } // FIN Mapping
1563 } // FIN Traitement Reference
1564 } // FIN Boucle Parametres
1565 } // FIN Boucle Repertoires
1566
7fd59977 1567 if (!pbmap) {
1d37eeb6 1568 return;
7fd59977 1569 }
1570 sout << " -- 2nd pass required --";
1571
1572 Standard_Integer nbseq = thenbents+2*thenbscop;
1d37eeb6
D
1573 TColStd_Array1OfInteger inds(0, nbseq); // n0 Record/Entite
1574 TColStd_Array1OfInteger indi(0, nbseq); // Idents/scopes
1575 TColStd_Array1OfInteger indr(0, nbdirec); // inverse de nds
1576 Handle(TColStd_HArray1OfInteger) indx; // pour EXPORT (silya)
7fd59977 1577
1578 imap.Clear();
1579 Standard_Boolean iamap = withmap; // (par defaut True)
1580 nbmap = 0;
1581
1582 TColStd_SequenceOfInteger scopile; // chainage des scopes note par pile
1583 Standard_Integer nr = 0 ;
1584 for (num = 1 ; num <= nbdirec ; num ++) {
1585 Standard_Integer ident = theidents(num);
1586 if (ident < -2) { // SOUS-LISTE (cas le plus courant)
1d37eeb6 1587 indr(num) = nr + 1; // recherche basee sur nr (objet qui suit)
7fd59977 1588 } else if (ident >= 0) { // Ident normal
1d37eeb6 1589 nr ++; inds(nr) = num; indi(nr) = ident; indr(num) = nr;
7fd59977 1590 if (ident > 0) { // et non (iamap && ident > 0)
1591// Map : si Recouvrement, l inhiber. Sinon, noter index
1592 Standard_Integer indmap = imap.Add(ident);
1593 if (indmap <= nbmap) {
1594 Standard_Boolean errorscope = Standard_False;
1595 indmap = imap.FindIndex(ident); // plus sur
1596 pbmap = Standard_True;
1597 if (thenbscop == 0) errorscope = Standard_True;
1598// Numeros identiques alors quilnya pas de SCOPE ? ERREUR !
1599// (Bien sur, silya des SCOPES, on passe au travers, mais bon...)
1600 else {
1601// Silya des SCOPES, tachons d y voir de plus pres pour signaler un probleme
1602// Erreur si MEME groupe SCOPE
1603// ATTENTION, on recherche, non dans tous les records, mais dans les records
1604// CHAINES, cf nr et non num (pas de sous-liste, chainage scope-endscope)
1605 Standard_Integer fromscope = nr;
1d37eeb6 1606 Standard_Integer toscope = indm(indmap);
7fd59977 1607 if (toscope < 0) toscope = -toscope;
302f96fb 1608 for(;;) {
7fd59977 1609 fromscope --; // iteration de base
1610 if (fromscope <= toscope) {
1611 errorscope = Standard_True; // BANG, on est dessus
1612 break;
1613 }
1d37eeb6 1614 Standard_Integer idtest = indi(fromscope);
7fd59977 1615 if (idtest >= 0) continue; // le suivant (enfin, le precedent)
1616 if (idtest == -1) break; // pas meme niveau, donc c est OK
1617 if (idtest == -3) {
1d37eeb6 1618 fromscope = inds(fromscope);
7fd59977 1619 if (fromscope < toscope) break; // on sort, pas en meme niveau
1620 }
1621 }
1622 }
1623 if (errorscope) {
1624// On est dedans : le signaler
1625 char ligne[80];
1626 sprintf(ligne,"Ident defined SEVERAL TIMES : #%d",ident);
1627 thecheck->AddFail(ligne,"Ident defined SEVERAL TIMES : #%d");
1628 sout << "StepReaderData:SetEntityNumbers, " << ligne << endl;
1629 }
1d37eeb6 1630 if (indm(indmap) > 0) indm(indmap) = -indm(indmap); // Pas pour Map
7fd59977 1631// Cas Normal pour la Map
1632 } else {
1633 nbmap = indmap;
1d37eeb6 1634 indm(indmap) = nr; // Map ->(indm)->inds
7fd59977 1635 }
1636 }
1637 } else if (ident == -1) { // SCOPE
1d37eeb6 1638 nr ++; inds(nr) = num; indi(nr) = -1; indr(num) = 0;
7fd59977 1639 scopile.Append(nr) ;
1640 } else if (ident == -2) { // ENDSCOPE
1641 Standard_Integer nscop = scopile.Last() ; // chainage SCOPE-ENDSCOPE
1642 scopile.Remove(scopile.Length()) ;
1d37eeb6 1643 nr ++; inds(nr) = nscop; indi(nr) = -3; indr(num) = 0; inds(nscop) = nr;
7fd59977 1644 if (NbParams(num) > 0) {
1645// EXPORT : traitement special greffe sur celui de SCOPE (sans le perturber)
1d37eeb6
D
1646 if (indx.IsNull()) {
1647 indx = new TColStd_HArray1OfInteger(0, nbseq);
1648 for (Standard_Integer ixp = 0; ixp <= nbseq; ixp ++) indx->ChangeValue(ixp) = 0;
7fd59977 1649 }
1d37eeb6 1650 indx->ChangeValue(nr) = num; indx->ChangeValue(nscop) = num;
7fd59977 1651 }
1652 } else if (ident == 0) { // HEADER
1d37eeb6 1653 indr(num) = 0;
7fd59977 1654 }
1655 }
1656
1657// .. Resolution des EXPORT, silyena et silya besoin ..
1658// Pour chaque valeur de EXPORT qui n a pas ete resolue par la MAP,
1659// determiner sa position locale par recherche en arriere depuis ENDSCOPE
1d37eeb6 1660 if ((!iamap || pbmap) && !indx.IsNull()) {
7fd59977 1661 for (nr = 0; nr <= nbseq; nr ++) {
1d37eeb6
D
1662 if (indx->Value(nr) == 0 && indi(nr) != -3) continue; // ENDSCOPE + EXPORT
1663 num = indx->Value(nr);
7fd59977 1664 Standard_Integer nba = NbParams(num);
1665 for (Standard_Integer na = 1; na <= nba; na ++) {
1666 Interface_FileParameter& FP = ChangeParam (num,na);
1667 if (FP.ParamType() != Interface_ParamIdent) continue;
1668 Standard_Integer id = - FP.EntityNumber();
1669 if (id < 0) continue; // deja resolu en tete
1670/* if (imap.Contains(id)) { et voila
1d37eeb6 1671 FP.SetEntityNumber(indm(imap.FindIndex(id)));
7fd59977 1672 continue;
1673 } */
1674
1675// Recherche du Id demande : si EXPORT imbrique, deja resolu mais il faut
1676// regarder ! (inutile par contre d aller y voir : c est deja fait, car
1677// un EXPORT imbrique a ete traite AVANT celui qui imbrique)
1678 Standard_Integer n0 = nr-1 ;
1d37eeb6 1679 if (indi(n0) == -3) n0 --; // si on suit juste un ENDSCOPE
7fd59977 1680 while (n0 > 0) {
1d37eeb6 1681 Standard_Integer irec = indi(n0);
7fd59977 1682 if (irec == id) { // trouve
1d37eeb6 1683 FP.SetEntityNumber(inds(n0));
7fd59977 1684 break ;
1685 }
1686 if (irec == -1) break; // SCOPE : fin de ce SCOPE/ENDSCOPE
1687 if (irec == -3) {
1688// gare a EXPORT : si un EXPORT detient Id, noter son Numero deja calcule
1689// Attention : Id a lire depuis CValue car EntityNumber deja resolu
1d37eeb6 1690 Standard_Integer nok = FindEntityNumber (indx->Value(n0),id);
7fd59977 1691 if (nok > 0) {
1692 FP.SetEntityNumber(nok);
1693 break;
1694 }
1d37eeb6 1695 n0 = inds(n0); // ENDSCOPE ou EXPORT infructueux : le sauter
7fd59977 1696 } // fin traitement sur un ENDSCOPE ou EXPORT
1697 n0 -- ;
1698 } // fin resolution d un Parametre EXPORT
1699 } // fin resolution de la liste d un EXPORT
1700 } // fin bouclage sur les EXPORT
1701 }
1702
1703// Exploitation de la table : bouclage porte sur la table
1704
1705// Traitement des sous-listes : se fait dans la foulee, par gestion d une pile
1706// basee sur la constitution des sous-listes
1707 Standard_Integer maxsubpil = 30; // pile simulee avec un Array : tres fort
1708 Handle(TColStd_HArray1OfInteger) subpile = // ... gagne de la memoire ...
1709 new TColStd_HArray1OfInteger (1,maxsubpil);
1710 Standard_Integer nbsubpil = 0; // ... et tellement plus rapide !
1711
1712 for (num = 1 ; num <= nbdirec ; num ++) {
1d37eeb6 1713 nr = indr(num);
7fd59977 1714 if (nr == 0) continue; // pas un objet ou une sous-liste
1715 Standard_Integer nba = NbParams(num) ;
1716 for (Standard_Integer na = nba ; na > 0 ; na --) {
1717// On lit depuis la fin : cela permet de traiter les sous-listes dans la foulee
1718// Sinon, on devrait noter qu il y a eu des sous-listes et reprendre ensuite
1719
1720 Interface_FileParameter& FP = ChangeParam (num,na);
1721 Interface_ParamType letype = FP.ParamType();
1722 if (letype == Interface_ParamSub) {
1723// parametre type sous-liste : numero de la sous-liste lu par depilement
1724 FP.SetEntityNumber(subpile->Value(nbsubpil));
1725 nbsubpil --; // subpile->Remove(nbsubpil);
1726
1727 } else if (letype == Interface_ParamIdent) {
1728// parametre type ident (reference une entite) : chercher ident demande
1729 Standard_Integer id = - FP.EntityNumber();
1730 if (id < 0) continue; // deja resolu en tete
1731
1732// Voila : on va chercher id dans ndi; algorithme de balayage
1733 Standard_Integer pass, sens, nok, n0,irec; pass = sens = nok = 0;
1734 if (!iamap) pass = 1; // si map non disponible
1735 while (pass < 3) {
1736 pass ++ ;
1737// MAP disponible
1738 if (pass == 1) { // MAP DISPONIBLE
1739 Standard_Integer indmap = imap.FindIndex(id);
1740 if (indmap > 0) { // la map a trouve
1d37eeb6 1741 nok = indm(indmap);
7fd59977 1742 if (nok < 0) continue; // CONFLIT -> faut resoudre ...
1743 break;
1744 }
1745 else continue;
1746 }
1747// 1re Passe : REMONTEE -> Debut fichier
1748 if (sens == 0 && nr > 1) {
1749 n0 = nr-1 ;
1d37eeb6 1750 if (indi(n0) == -3) n0 --; // si on suit juste un ENDSCOPE
7fd59977 1751 while (n0 > 0) {
1d37eeb6 1752 irec = indi(n0);
7fd59977 1753 if (irec == id) { // trouve
1754 nok = n0 ; break ;
1755 }
1756// ENDSCOPE : Attention a EXPORT sinon sauter
1757 if (irec == -3) {
1d37eeb6 1758 if (indx.IsNull()) n0 = inds(n0);
7fd59977 1759 else {
1760// EXPORT, il faut regarder
1d37eeb6 1761 nok = FindEntityNumber (indx->Value(n0),id);
7fd59977 1762 if (nok > 0) break;
1d37eeb6 1763 n0 = inds(n0); // ENDSCOPE : le sauter
7fd59977 1764 }
1765 }
1766 n0 -- ;
1767 }
1768// 2me Passe : DESCENTE -> Fin fichier
1769 } else if (nr < nbseq) { // descente -> fin fichier
1770 n0 = nr+1 ;
1771 while (n0 <= nbseq) {
1d37eeb6 1772 irec = indi(n0);
7fd59977 1773 if (irec == id) { // trouve
1774 nok = n0 ; break ;
1775 }
1776// SCOPE : Attention a EXPORT sinon sauter
1777 if (irec == -1) {
1d37eeb6 1778 if (indx.IsNull()) n0 = inds(n0);
7fd59977 1779 else {
1780// EXPORT, il faut regarder
1d37eeb6 1781 nok = FindEntityNumber (indx->Value(n0),id);
7fd59977 1782 if (nok > 0) break;
1d37eeb6 1783 n0 = inds(n0); // SCOPE : le sauter
7fd59977 1784 }
1785 }
1786 n0 ++ ;
1787 }
1788 }
1789 if (nok > 0) break ;
1790 sens = 1 - sens ; // passe suivante
1791 }
1792 // ici on a nok, numero trouve
1793 if (nok > 0) {
1d37eeb6 1794 Standard_Integer num0 = inds(nok);
7fd59977 1795 FP.SetEntityNumber(num0); // ET VOILA, on a resolu
1796
1797 // pas trouve : le signaler
1798 } else {
1799// Alimenter le Check ... Pour cela, determiner n0 Entite et Ident
1800 char failmess[100];
1801 Standard_Integer nument = 0;
1802 Standard_Integer n0ent; // svv Jan11 2000 : porting on DEC
1803 for (n0ent = 1; n0ent <= nr; n0ent ++) {
1d37eeb6 1804 if (indi(n0ent) > 0) nument ++;
7fd59977 1805 }
1806 Standard_Integer ident = RecordIdent(num);
1807 if (ident < 0) {
1808 for (n0ent = num + 1; n0ent <= nbdirec; n0ent ++) {
1809 ident = RecordIdent(n0ent); if (ident > 0) break;
1810 }
1811 }
1812// ... Construire le Check ...
1813 sprintf(failmess,
1814 "Unresolved Reference, Ent.n0 %d (Id.#%d) Param.n0 %d (Id.#%d)",
1815 nument,ident,na,id);
1816 thecheck->AddFail(failmess,"Unresolved Reference");
1817// ... Et sortir message un peu plus complet
1818 sout << "*** ERR StepReaderData *** Pour Entite "<<nument
1819 <<", a "<< (nr*100)/nbseq<<"% de DATA : #"<< ident
1820 << "\n Type:" << RecordType(num)
1821 << " Param.n0 " << na << ": #" << id << " Non trouve" << endl ;
1822 FP.SetEntityNumber(0); // -> Reference non resolue
1823 }
1824 }
1825 }
1826// Si ce record est lui-meme une sous-liste, empiler !
1d37eeb6 1827 if (inds(nr) != num) {
7fd59977 1828 if (nbsubpil >= maxsubpil) {
1829 maxsubpil = maxsubpil+30;
1830 Handle(TColStd_HArray1OfInteger) newsubpil =
1831 new TColStd_HArray1OfInteger (1,maxsubpil);
1832 for (Standard_Integer bidpil = 1; bidpil <= maxsubpil - 30; bidpil ++)
1833 newsubpil->SetValue(bidpil,subpile->Value(bidpil));
1834 subpile = newsubpil;
1835 }
1836 nbsubpil ++;
1837 subpile->SetValue(nbsubpil,num); // Append(num);
1838 }
1839 }
7fd59977 1840}
1841
1842
1843// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
1844// .... Gestion du Header : Preparation, lecture ....
1845
1846
1847//=======================================================================
1848//function : FindNextHeaderRecord
1849//purpose :
1850//=======================================================================
1851
1852Standard_Integer StepData_StepReaderData::FindNextHeaderRecord
1853 (const Standard_Integer num) const
1854{
1855// retourne, sur un numero d enregistrement donne (par num), le suivant qui
1856// definit une entite, ou 0 si c est fini :
1857// Opere comme FindNextRecord mais ne balaie que le Header
1858
1859 if (num < 0) return 0 ;
1860 Standard_Integer num1 = num + 1 ;
1861 Standard_Integer max = thenbhead;
1862
1863 while (num1 <= max ) {
1864// SCOPE,ENDSCOPE et Sous-Liste ont un identifieur negatif
1865// Ne retenir que les Idents positifs ou nuls (nul : pas d Ident dans Header)
1866 if ( RecordIdent(num1) >= 0) return num1 ;
1867 num1 ++ ;
1868 }
1869 return 0;
1870}
1871
1872
1873//=======================================================================
1874//function : PrepareHeader
1875//purpose :
1876//=======================================================================
1877
1878void StepData_StepReaderData::PrepareHeader ()
1879{
1880// Resolution des references : ne concerne que les sous-listes
1881// deja faite par SetEntityNumbers donc pas de souci a se faire
1882
1883/*
1884// Algorithme repris et adapte de SetEntityNumbers
1885// Traitement des sous-listes : se fait dans la foulee, par gestion d une pile
1886// basee sur la constitution des sous-listes
1887 TColStd_SequenceOfInteger subpile;
1888 Standard_Integer nbsubpil = 0; // profondeur de pile mais plus rapide ...
1889
1890 for (Standard_Integer num = 1 ; num <= thenbhead ; num ++) {
1891 Standard_Integer nba = NbParams(num) ;
1892 for (Standard_Integer na = nba ; na > 0 ; na --) {
1893.. On lit depuis la fin : cela permet de traiter les sous-listes dans la foulee
1894.. Sinon, on devrait noter qu il y a eu des sous-listes et reprendre ensuite
1895
1896 Interface_FileParameter& FP = ChangeParam(num,na);
1897 Interface_ParamType letype = FP.ParamType();
1898 if (letype == Interface_ParamSub) {
1899.. parametre type sous-liste : numero de la sous-liste lu par depilement
1900 FP.SetEntityNumber(subpile.Last());
1901.. .. SetParam(num,na,FP);
1902 subpile.Remove(nbsubpil);
1903 nbsubpil --;
1904 }
1905 }
1906.. Si c est une sous-liste, empiler
1907 if (RecordIdent(num) < -2) {
1908 subpile.Append(num);
1909 nbsubpil ++;
1910 }
1911 }
1912*/
1913}
1914
1915
1916//=======================================================================
1917//function : GlobalCheck
1918//purpose :
1919//=======================================================================
1920
1921const Handle(Interface_Check) StepData_StepReaderData::GlobalCheck () const
1922{
1923 return thecheck;
1924}