1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //pdn S4135 05.04.99 comment uninitialized Interface_Static::IVal("iges.convert.read");
18 #include <IGESData_IGESEntity.hxx>
19 #include <IGESData_IGESReaderData.hxx>
20 #include <IGESData_IGESType.hxx>
21 #include <IGESData_ParamCursor.hxx>
22 #include <IGESData_ParamReader.hxx>
23 #include <IGESData_Status.hxx>
24 #include <Interface_Check.hxx>
25 #include <Interface_EntityList.hxx>
26 #include <Interface_FileParameter.hxx>
27 #include <Interface_FileReaderData.hxx>
28 #include <Interface_InterfaceError.hxx>
29 #include <Interface_Macros.hxx>
30 #include <Interface_ParamList.hxx>
31 #include <Interface_Static.hxx>
32 #include <Message_Msg.hxx>
33 #include <TCollection_HAsciiString.hxx>
37 static Standard_Integer testconv = -1; // cf parametre de session
39 // .... Gestion generale (etat, courant ...) ....
42 //=======================================================================
43 //function : IGESData_ParamReader
45 //=======================================================================
47 IGESData_ParamReader::IGESData_ParamReader(const Handle(Interface_ParamList)& list,
48 const Handle(Interface_Check)& ach,
49 const Standard_Integer base,
50 const Standard_Integer nbpar,
51 const Standard_Integer /*num*/)
54 theparams = list; thecheck = ach; thelast = Standard_True;
56 thenbpar = (nbpar > 0 ? nbpar : list->Length());
62 //=======================================================================
63 //function : EntityNumber
65 //=======================================================================
67 Standard_Integer IGESData_ParamReader::EntityNumber () const
73 //=======================================================================
76 //=======================================================================
78 void IGESData_ParamReader::Clear ()
81 thestage = IGESData_ReadOwn;
82 pbrealint=pbrealform=0;
86 //=======================================================================
87 //function : CurrentNumber
89 //=======================================================================
91 Standard_Integer IGESData_ParamReader::CurrentNumber () const
97 //=======================================================================
98 //function : SetCurrentNumber
100 //=======================================================================
102 void IGESData_ParamReader::SetCurrentNumber (const Standard_Integer num)
104 //if (num <= NbParams() + 1) thecurr = num; // NbParams+1 : "fin d'objet"
110 //=======================================================================
113 //=======================================================================
115 IGESData_ReadStage IGESData_ParamReader::Stage () const
121 //=======================================================================
122 //function : NextStage
124 //=======================================================================
126 void IGESData_ParamReader::NextStage ()
128 if (thestage != IGESData_ReadEnd) thestage =
129 (IGESData_ReadStage) (((long) thestage) + 1);
133 //=======================================================================
136 //=======================================================================
138 void IGESData_ParamReader::EndAll ()
140 thestage = IGESData_ReadEnd;
144 // .... Acces de base aux parametres ....
147 //=======================================================================
148 //function : NbParams
150 //=======================================================================
152 Standard_Integer IGESData_ParamReader::NbParams () const
154 return (thenbpar - 1);
158 //=======================================================================
159 //function : ParamType
161 //=======================================================================
163 Interface_ParamType IGESData_ParamReader::ParamType
164 (const Standard_Integer num) const
166 return theparams->Value(num+thebase).ParamType();
170 //=======================================================================
171 //function : ParamValue
173 //=======================================================================
175 Standard_CString IGESData_ParamReader::ParamValue
176 (const Standard_Integer num) const
178 return theparams->Value(num+thebase).CValue();
182 //=======================================================================
183 //function : IsParamDefined
185 //=======================================================================
187 Standard_Boolean IGESData_ParamReader::IsParamDefined
188 (const Standard_Integer num) const
190 if (num >= thenbpar) return Standard_False;
191 return (theparams->Value(num+thebase).ParamType() != Interface_ParamVoid);
195 //=======================================================================
196 //function : IsParamEntity
198 //=======================================================================
200 Standard_Boolean IGESData_ParamReader::IsParamEntity
201 (const Standard_Integer num) const
203 return (ParamNumber(num) != 0);
207 //=======================================================================
208 //function : ParamNumber
210 //=======================================================================
212 Standard_Integer IGESData_ParamReader::ParamNumber
213 (const Standard_Integer num) const
215 return theparams->Value(num+thebase).EntityNumber();
219 //=======================================================================
220 //function : ParamEntity
222 //=======================================================================
224 Handle(IGESData_IGESEntity) IGESData_ParamReader::ParamEntity
225 (const Handle(IGESData_IGESReaderData)& IR, const Standard_Integer num)
227 Standard_Integer n = ParamNumber(num);
228 if (n == 0) thecheck->AddFail("IGES ParamReader : ParamEntity, bad param");
229 return GetCasted(IGESData_IGESEntity,IR->BoundEntity(n));
233 // .... Assistance a la lecture ....
235 // Les fonctions Read* offrent les services suivants :
236 // Gestion des erreurs : le Check est alimente, par Fail ou Corrected selon
237 // Si Fail, retour de fonction False (peut etre utile), sinon True
238 // En outre, un Status est gere (de type enum DataState)
239 // (peut etre interroge suite a appel Read* si retour True/False trop court)
241 // Gestion du pointeur courant (sur option, nais elle est mise par defaut) :
242 // Les parametres sont designes via un ParmCursor, qui peut etre fabrique par
243 // les methodes ad hoc Current et CurrentList, et qui peut demander a avancer
244 // le pointeur courant une fois la lecture faite
245 // En outre, pour un HArray1, on peut preciser index de depart
248 //=======================================================================
251 //=======================================================================
253 IGESData_ParamCursor IGESData_ParamReader::Current () const
255 return IGESData_ParamCursor(thecurr);
259 //=======================================================================
260 //function : CurrentList
262 //=======================================================================
264 IGESData_ParamCursor IGESData_ParamReader::CurrentList
265 (const Standard_Integer nb, const Standard_Integer size) const
267 return IGESData_ParamCursor(thecurr,nb,size);
271 // PrepareRead for MoniTool
274 //=======================================================================
275 //function : PrepareRead
277 //=======================================================================
279 Standard_Boolean IGESData_ParamReader::PrepareRead
280 (const IGESData_ParamCursor& PC, const Standard_Boolean several,
281 const Standard_Integer size)
283 theindex = PC.Start();
284 themaxind = PC.Limit();
285 thenbitem = PC.Count();
286 theitemsz = PC.ItemSize();
287 theoffset = PC.Offset();
288 thetermsz = PC.TermSize();
289 if (!several && thenbitem > 1) {
290 // AddFail (mess," : List not allowed","");
291 return Standard_False;
294 if (thetermsz % size != 0) {
295 return Standard_False;
298 if (theindex <= 0 || (themaxind-1) > NbParams()) {
299 return Standard_False;
302 SetCurrentNumber (themaxind); //themaxind : prochain index
303 thelast = Standard_True;
304 return Standard_True;
308 //=======================================================================
309 //function : PrepareRead
311 //=======================================================================
313 Standard_Boolean IGESData_ParamReader::PrepareRead
314 (const IGESData_ParamCursor& PC, const Standard_CString mess,
315 const Standard_Boolean several, const Standard_Integer size)
317 theindex = PC.Start();
318 themaxind = PC.Limit();
319 thenbitem = PC.Count();
320 theitemsz = PC.ItemSize();
321 theoffset = PC.Offset();
322 thetermsz = PC.TermSize();
323 if (!several && thenbitem > 1) {
324 AddFail (mess," : List not allowed","");
325 return Standard_False;
328 if (thetermsz % size != 0) {
329 AddFail (mess," : term size mismatch","");
330 return Standard_False;
333 if (theindex <= 0 || (themaxind-1) > NbParams()) {
334 if (thenbitem == 1) AddFail (mess," : Parameter number out of range","");
335 //else AddFail (mess," : too many values to read" ,"");
336 else AddWarning (mess," : too many values to read" ,"");
337 return Standard_False;
339 if (PC.Advance()) SetCurrentNumber (themaxind); //themaxind : prochain index
340 thelast = Standard_True;
341 return Standard_True;
345 // theindex donne le debut de la lecture; tjrs cale sur debut d item
346 // thenbterm donne debut a lire dans l item
347 // Ainsi, l indice vrai est theindex + thenbterm
348 // thenbterm avance par +nb. Quand il a depasse thetermsz, item suivant
349 // theindex est lui-meme limite (critere d arret) a themaxind
352 //=======================================================================
353 //function : FirstRead
355 //=======================================================================
357 Standard_Integer IGESData_ParamReader::FirstRead (const Standard_Integer nb)
359 theindex += theoffset; // On se cale d office sur le debut du terme a lire
360 Standard_Integer res = theindex;
362 if (thenbterm >= thetermsz) {
363 theindex += theitemsz;
370 //=======================================================================
371 //function : NextRead
373 //=======================================================================
375 Standard_Integer IGESData_ParamReader::NextRead (const Standard_Integer nb)
377 Standard_Integer res = theindex;
378 if (theindex >= themaxind) res = 0;
379 thenbterm += nb; // Par Item : en lire thetermsz, puis item suivant
380 if (thenbterm >= thetermsz) {
381 theindex += theitemsz;
388 //=======================================================================
389 //function : DefinedElseSkip
391 //=======================================================================
393 Standard_Boolean IGESData_ParamReader::DefinedElseSkip ()
395 if (thecurr > NbParams()) return Standard_False; // Skip en butee
396 if (IsParamDefined(thecurr)) return Standard_True; // Defined
397 SetCurrentNumber (thecurr+1); // Skip
398 return Standard_False;
402 // ReadInteger for MoniTool
404 //=======================================================================
405 //function : ReadInteger
407 //=======================================================================
409 Standard_Boolean IGESData_ParamReader::ReadInteger (const IGESData_ParamCursor& PC,
410 Standard_Integer& val)
412 if (!PrepareRead(PC,Standard_False)) return Standard_False;
413 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
414 if (FP.ParamType() != Interface_ParamInteger) {
415 if (FP.ParamType() == Interface_ParamVoid){
417 return Standard_True;
419 return Standard_False;
421 val = atoi(FP.CValue());
422 return Standard_True;
426 //=======================================================================
427 //function : ReadInteger
429 //=======================================================================
431 Standard_Boolean IGESData_ParamReader::ReadInteger
432 (const IGESData_ParamCursor& PC, const Standard_CString mess,
433 Standard_Integer& val)
435 if (!PrepareRead(PC,mess,Standard_False)) return Standard_False;
436 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
437 if (FP.ParamType() != Interface_ParamInteger) {
438 if (FP.ParamType() == Interface_ParamVoid)
439 { val = 0; return Standard_True; } // DEFAULT
440 AddFail (mess," : not given as an Integer","");
441 return Standard_False;
443 val = atoi(FP.CValue());
444 return Standard_True;
448 // ReadBoolean for MoniTool
450 //=======================================================================
451 //function : ReadBoolean
453 //=======================================================================
455 Standard_Boolean IGESData_ParamReader::ReadBoolean
456 (const IGESData_ParamCursor& PC, const Message_Msg& amsg,
457 Standard_Boolean& val, const Standard_Boolean exact)
459 if (!PrepareRead(PC,Standard_False)) return Standard_False;
460 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
461 if (FP.ParamType() != Interface_ParamInteger) {
462 if (FP.ParamType() == Interface_ParamVoid) {
463 val = Standard_False;
464 return Standard_True;
467 return Standard_False;
470 // Un Booleen, c est 0/1. Mais on peut tolerer d autres valeurs
471 // On peut toujours consulter LastReadStatus apres la lecture pour etre sur
472 Standard_Integer flag = atoi (FP.CValue());
473 if (flag != 0 && flag != 1) {
476 thelast = Standard_True;
477 return Standard_False;
484 return Standard_True;
488 //=======================================================================
489 //function : ReadBoolean
491 //=======================================================================
493 Standard_Boolean IGESData_ParamReader::ReadBoolean
494 (const IGESData_ParamCursor& PC, const Standard_CString mess,
495 Standard_Boolean& val, const Standard_Boolean exact)
497 if (!PrepareRead(PC,mess,Standard_False)) return Standard_False;
498 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
499 if (FP.ParamType() != Interface_ParamInteger) {
500 if (FP.ParamType() == Interface_ParamVoid)
502 val = Standard_False;
503 return Standard_True;
505 AddFail (mess," : not an Integer (for Boolean)","");
506 return Standard_False;
509 // Un Booleen, c est 0/1. Mais on peut tolerer d autres valeurs
510 // On peut toujours consulter LastReadStatus apres la lecture pour etre sur
511 Standard_Integer flag = atoi (FP.CValue());
512 if (flag != 0 && flag != 1) {
514 sprintf(ssem," : Value is not 0/1, but %s",FP.CValue());
516 AddFail (mess,ssem," : Value is not 0/1, but %s");
517 thelast = Standard_True;
518 return Standard_False;
520 else AddWarning (mess,ssem," : Value is not 0/1, but %s");
523 return Standard_True;
527 // ReadReal for MoniTool
529 //=======================================================================
530 //function : ReadReal
532 //=======================================================================
534 Standard_Boolean IGESData_ParamReader::ReadReal (const IGESData_ParamCursor& PC,
537 if (!PrepareRead(PC,Standard_False)) return Standard_False;
538 // return ReadingReal (theindex,amsg,val);
539 return ReadingReal (theindex,val);
543 //=======================================================================
544 //function : ReadReal
546 //=======================================================================
548 Standard_Boolean IGESData_ParamReader::ReadReal
549 (const IGESData_ParamCursor& PC,const Standard_CString mess,
552 if (!PrepareRead(PC,mess,Standard_False)) return Standard_False;
553 return ReadingReal (theindex,mess,val);
557 // ReadXY for MoniTool
559 //=======================================================================
562 //=======================================================================
564 Standard_Boolean IGESData_ParamReader::ReadXY
565 (const IGESData_ParamCursor& PC,Message_Msg& /*amsg*/, gp_XY& val)
567 if (!PrepareRead(PC,Standard_False,2)) return Standard_False;
568 Standard_Real X,Y = 0.;
569 Standard_Boolean stat =
570 (ReadingReal (theindex ,X) &&
571 ReadingReal (theindex+1,Y) );
572 if (stat) val.SetCoord(X,Y);
577 //=======================================================================
580 //=======================================================================
582 Standard_Boolean IGESData_ParamReader::ReadXY
583 (const IGESData_ParamCursor& PC, const Standard_CString mess, gp_XY& val)
585 if (!PrepareRead(PC,mess,Standard_False,2)) return Standard_False;
586 Standard_Real X,Y = 0.;
587 Standard_Boolean stat =
588 (ReadingReal (theindex ,mess,X) &&
589 ReadingReal (theindex+1,mess,Y) );
590 if (stat) val.SetCoord(X,Y);
595 // ReadXYZ for MoniTool
597 //=======================================================================
600 //=======================================================================
602 Standard_Boolean IGESData_ParamReader::ReadXYZ
603 (const IGESData_ParamCursor& PC,Message_Msg& /*amsg*/, gp_XYZ& val)
605 if (!PrepareRead(PC,Standard_False,3)) return Standard_False;
606 Standard_Real X,Y = 0.,Z = 0.;
607 Standard_Boolean stat =
608 (ReadingReal (theindex ,X) &&
609 ReadingReal (theindex+1,Y) &&
610 ReadingReal (theindex+2,Z) );
611 if (stat) val.SetCoord(X,Y,Z);
612 return Standard_True;
616 //=======================================================================
619 //=======================================================================
621 Standard_Boolean IGESData_ParamReader::ReadXYZ
622 (const IGESData_ParamCursor& PC, const Standard_CString mess, gp_XYZ& val)
624 if (!PrepareRead(PC,mess,Standard_False,3)) return Standard_False;
625 Standard_Real X,Y = 0.,Z = 0.;
626 Standard_Boolean stat =
627 (ReadingReal (theindex ,mess,X) &&
628 ReadingReal (theindex+1,mess,Y) &&
629 ReadingReal (theindex+2,mess,Z) );
630 if (stat) val.SetCoord(X,Y,Z);
631 return Standard_True;
635 // ReadText for MoniTool
637 //=======================================================================
638 //function : ReadText
640 //=======================================================================
642 Standard_Boolean IGESData_ParamReader::ReadText
643 (const IGESData_ParamCursor& PC, const Message_Msg& amsg,
644 Handle(TCollection_HAsciiString)& val)
646 if (!PrepareRead(PC,Standard_False)) return Standard_False;
647 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
648 if (FP.ParamType() != Interface_ParamText) {
649 if (FP.ParamType() == Interface_ParamVoid) {
650 val = new TCollection_HAsciiString("");
651 return Standard_True;
654 return Standard_False;
656 Handle(TCollection_HAsciiString) tval = new TCollection_HAsciiString (FP.CValue());
657 Standard_Integer lnt = tval->Length();
658 Standard_Integer lnh = tval->Location(1,'H',1,lnt);
659 if (lnh <= 1 || lnh >= lnt) {
661 return Standard_False;
663 Standard_Integer hol = atoi (tval->SubString(1,lnh-1)->ToCString());
664 if (hol != (lnt-lnh)) SendWarning (amsg);
666 val = new TCollection_HAsciiString(tval->SubString(lnh+1,lnt)->ToCString());
667 return Standard_True;
671 //=======================================================================
672 //function : ReadText
674 //=======================================================================
676 Standard_Boolean IGESData_ParamReader::ReadText
677 (const IGESData_ParamCursor& PC, const Standard_CString mess,
678 Handle(TCollection_HAsciiString)& val)
680 if (!PrepareRead(PC,mess,Standard_False)) return Standard_False;
681 const Interface_FileParameter& FP = theparams->Value(theindex+thebase);
682 if (FP.ParamType() != Interface_ParamText) {
683 if (FP.ParamType() == Interface_ParamVoid) {
684 val = new TCollection_HAsciiString("");
685 return Standard_True;
687 AddFail (mess," : not given as a Text","");
688 return Standard_False;
690 Handle(TCollection_HAsciiString) tval = new TCollection_HAsciiString (FP.CValue());
691 Standard_Integer lnt = tval->Length();
692 Standard_Integer lnh = tval->Location(1,'H',1,lnt);
693 if (lnh <= 1 || lnh >= lnt) {
694 AddFail (mess," : not in Hollerith Form","");
695 return Standard_False;
698 Standard_Integer hol = atoi (tval->SubString(1,lnh-1)->ToCString());
699 if (hol != (lnt-lnh)) AddWarning (mess," : bad Hollerith count ","");
701 val = new TCollection_HAsciiString(tval->SubString(lnh+1,lnt)->ToCString());
702 return Standard_True;
706 // ReadEntity for MoniTool
708 //=======================================================================
709 //function : ReadEntity
711 //=======================================================================
713 Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESReaderData)& IR,
714 const IGESData_ParamCursor& PC,
715 IGESData_Status& aStatus,
716 Handle(IGESData_IGESEntity)& val,
717 const Standard_Boolean canbenul)
719 aStatus = IGESData_EntityError;
720 if (!PrepareRead(PC,Standard_False)) return Standard_False;
721 Standard_Integer nval;
722 // if (!ReadingEntityNumber(theindex,amsg,nval)) return Standard_False;
723 if (!ReadingEntityNumber(theindex,nval)) return Standard_False;
727 aStatus = IGESData_ReferenceError;
728 // Message_Msg Msg216 ("IGESP_216");
729 // amsg.Arg(amsg.Value());
732 thelast = Standard_True;
735 aStatus = IGESData_EntityOK;
738 else val = GetCasted(IGESData_IGESEntity,IR->BoundEntity(nval));
739 if (val.IsNull()) return canbenul;
741 if (val->TypeNumber() == 0) { // Null ou pas encore rempli ...
742 if (IR->DirType(nval).Type() == 0) { // le vrai critere (un peu cher)
745 aStatus = IGESData_EntityError;
746 // Message_Msg Msg217 ("IGES_217");
747 //amsg.Arg(Msg217.Value());
749 thelast = Standard_True;
752 aStatus = IGESData_EntityOK;
756 aStatus = IGESData_EntityOK;
757 return Standard_True;
761 //=======================================================================
762 //function : ReadEntity
764 //=======================================================================
766 Standard_Boolean IGESData_ParamReader::ReadEntity
767 (const Handle(IGESData_IGESReaderData)& IR, const IGESData_ParamCursor& PC,
768 const Standard_CString mess, Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul)
770 if (!PrepareRead(PC,mess,Standard_False)) return Standard_False;
771 Standard_Integer nval;
772 if (!ReadingEntityNumber(theindex,mess,nval)) return Standard_False;
776 AddFail (mess," : Null Reference","");
777 thelast = Standard_True;
781 else val = GetCasted(IGESData_IGESEntity,IR->BoundEntity(nval));
782 if (val.IsNull()) return canbenul;
784 if (val->TypeNumber() == 0) { // Null ou pas encore rempli ...
785 if (IR->DirType(nval).Type() == 0) { // le vrai critere (un peu cher)
788 AddFail (mess," : IGES Null Entity","");
789 thelast = Standard_True;
794 return Standard_True;
798 // ReadEntity for MoniTool
800 //=======================================================================
801 //function : ReadEntity
803 //=======================================================================
805 Standard_Boolean IGESData_ParamReader::ReadEntity (const Handle(IGESData_IGESReaderData)& IR,
806 const IGESData_ParamCursor& PC,
807 IGESData_Status& aStatus,
808 const Handle(Standard_Type)& type,
809 Handle(IGESData_IGESEntity)& val,
810 const Standard_Boolean canbenul)
812 Standard_Boolean res = ReadEntity (IR,PC,aStatus,val,canbenul);
816 if (val.IsNull()) return res;
817 if (!val->IsKind(type)) {
818 aStatus = IGESData_TypeError;
819 // Message_Msg Msg218 ("IGES_218");
820 //amsg.Arg(Msg218.Value());
822 thelast = Standard_True;
824 return Standard_False;
826 return Standard_True;
830 //=======================================================================
831 //function : ReadEntity
833 //=======================================================================
835 Standard_Boolean IGESData_ParamReader::ReadEntity
836 (const Handle(IGESData_IGESReaderData)& IR,
837 const IGESData_ParamCursor& PC, const Standard_CString mess,
838 const Handle(Standard_Type)& type,
839 Handle(IGESData_IGESEntity)& val, const Standard_Boolean canbenul)
841 Standard_Boolean res = ReadEntity (IR,PC,mess,val,canbenul);
842 if (!res) return res;
843 if (val.IsNull()) return res;
844 if (!val->IsKind(type)) {
845 AddFail (mess," : Incorrect Type","");
846 thelast = Standard_True;
848 return Standard_False;
850 return Standard_True;
854 // ReadInts for MoniTool
856 //=======================================================================
857 //function : ReadInts
859 //=======================================================================
861 Standard_Boolean IGESData_ParamReader::ReadInts
862 (const IGESData_ParamCursor& PC, const Message_Msg& amsg ,
863 Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index)
865 if (!PrepareRead(PC,Standard_True)) return Standard_False;
866 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
867 val = new TColStd_HArray1OfInteger (index,index+thenbitem*thetermsz-1);
868 Standard_Integer ind = index;
870 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
871 const Interface_FileParameter& FP = theparams->Value(i+thebase);
872 if (FP.ParamType() == Interface_ParamInteger) {
873 val->SetValue (ind, atoi(FP.CValue())); ind ++;
874 } else if (FP.ParamType() == Interface_ParamVoid) {
875 val->SetValue (ind,0); ind ++; // DEFAULT : rien a dire
878 return Standard_False;
881 return Standard_True;
885 //=======================================================================
886 //function : ReadInts
888 //=======================================================================
890 Standard_Boolean IGESData_ParamReader::ReadInts
891 (const IGESData_ParamCursor& PC, const Standard_CString mess,
892 Handle(TColStd_HArray1OfInteger)& val, const Standard_Integer index)
894 if (!PrepareRead(PC,mess,Standard_True)) return Standard_False;
895 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
896 val = new TColStd_HArray1OfInteger (index,index+thenbitem*thetermsz-1);
897 Standard_Integer ind = index;
899 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
900 const Interface_FileParameter& FP = theparams->Value(i+thebase);
901 if (FP.ParamType() == Interface_ParamInteger) {
902 val->SetValue (ind, atoi(FP.CValue())); ind ++;
903 } else if (FP.ParamType() == Interface_ParamVoid) {
904 val->SetValue (ind,0); ind ++; // DEFAULT : rien a dire
907 sprintf(ssem," : not an Integer, rank %d",i);
908 AddFail (mess,ssem," : not an Integer, rank %d");
909 return Standard_False;
912 return Standard_True;
916 // ReadReals for MoniTool
918 //=======================================================================
919 //function : ReadReals
921 //=======================================================================
923 Standard_Boolean IGESData_ParamReader::ReadReals
924 (const IGESData_ParamCursor& PC,Message_Msg& /*amsg*/,
925 Handle(TColStd_HArray1OfReal)& val, const Standard_Integer index)
927 if (!PrepareRead(PC,Standard_True)) return Standard_False;
928 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
929 val = new TColStd_HArray1OfReal (index,index+thenbitem*thetermsz-1);
930 Standard_Integer ind = index;
932 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
934 if (!ReadingReal(i,rval)) return Standard_False;
935 val->SetValue (ind, rval); ind ++;
937 return Standard_True;
941 //=======================================================================
942 //function : ReadReals
944 //=======================================================================
946 Standard_Boolean IGESData_ParamReader::ReadReals
947 (const IGESData_ParamCursor& PC, const Standard_CString mess,
948 Handle(TColStd_HArray1OfReal)& val, const Standard_Integer index)
950 if (!PrepareRead(PC,mess,Standard_True)) return Standard_False;
951 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
952 val = new TColStd_HArray1OfReal (index,index+thenbitem*thetermsz-1);
953 Standard_Integer ind = index;
955 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
957 if (!ReadingReal(i,mess,rval)) return Standard_False;
958 val->SetValue (ind, rval); ind ++;
960 return Standard_True;
964 // ReadTexts for MoniTool
966 //=======================================================================
967 //function : ReadTexts
969 //=======================================================================
971 Standard_Boolean IGESData_ParamReader::ReadTexts
972 (const IGESData_ParamCursor& PC, const Message_Msg& amsg ,
973 Handle(Interface_HArray1OfHAsciiString)& val, const Standard_Integer index)
975 if (!PrepareRead(PC,Standard_True)) return Standard_False;
976 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
977 val = new Interface_HArray1OfHAsciiString(index,index+thenbitem*thetermsz-1);
978 Standard_Integer ind = index;
980 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
981 const Interface_FileParameter& FP = theparams->Value(i+thebase);
982 if (FP.ParamType() != Interface_ParamText) {
983 if (FP.ParamType() == Interface_ParamVoid) {
984 val->SetValue (ind, new TCollection_HAsciiString(""));
986 //AddWarning (mess," : empty text",""); DEFAULT : rien a dire
990 return Standard_False;
992 Handle(TCollection_HAsciiString) tval = new TCollection_HAsciiString (FP.CValue());
993 // IGESFile_Read a filtre
994 Standard_Integer lnt = tval->Length();
995 Standard_Integer lnh = tval->Location(1,'H',1,lnt);
996 if (lnh <= 1 || lnh >= lnt) {
998 return Standard_False;
1000 Standard_Integer hol = atoi (tval->SubString(1,lnh-1)->ToCString());
1001 if (hol != (lnt-lnh)) SendWarning(amsg);
1003 val->SetValue (ind, new TCollection_HAsciiString
1004 (tval->SubString(lnh+1,lnt)->ToCString()));
1007 return Standard_True;
1011 //=======================================================================
1012 //function : ReadTexts
1014 //=======================================================================
1016 Standard_Boolean IGESData_ParamReader::ReadTexts
1017 (const IGESData_ParamCursor& PC, const Standard_CString mess,
1018 Handle(Interface_HArray1OfHAsciiString)& val, const Standard_Integer index)
1020 if (!PrepareRead(PC,mess,Standard_True)) return Standard_False;
1021 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
1022 val = new Interface_HArray1OfHAsciiString(index,index+thenbitem*thetermsz-1);
1023 Standard_Integer ind = index;
1025 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
1026 const Interface_FileParameter& FP = theparams->Value(i+thebase);
1027 if (FP.ParamType() != Interface_ParamText) {
1028 if (FP.ParamType() == Interface_ParamVoid) {
1029 val->SetValue (ind, new TCollection_HAsciiString(""));
1031 //AddWarning (mess," : empty text",""); DEFAULT : rien a dire
1034 AddFail (mess," : not given as a Text","");
1035 return Standard_False;
1037 Handle(TCollection_HAsciiString) tval = new TCollection_HAsciiString (FP.CValue());
1038 // IGESFile_Read a filtre
1039 Standard_Integer lnt = tval->Length();
1040 Standard_Integer lnh = tval->Location(1,'H',1,lnt);
1041 if (lnh <= 1 || lnh >= lnt) {
1042 AddFail (mess," : not in Hollerith Form","");
1043 return Standard_False;
1045 Standard_Integer hol = atoi (tval->SubString(1,lnh-1)->ToCString());
1046 if (hol != (lnt-lnh)) AddWarning(mess," : bad Hollerith count ","");
1048 val->SetValue (ind, new TCollection_HAsciiString
1049 (tval->SubString(lnh+1,lnt)->ToCString()));
1052 return Standard_True;
1056 // ReadEnts for MoniTool
1058 //=======================================================================
1059 //function : ReadEnts
1061 //=======================================================================
1063 Standard_Boolean IGESData_ParamReader::ReadEnts
1064 (const Handle(IGESData_IGESReaderData)& IR,
1065 const IGESData_ParamCursor& PC, const Message_Msg& amsg ,
1066 Handle(IGESData_HArray1OfIGESEntity)& val, const Standard_Integer index)
1068 if (!PrepareRead(PC,Standard_True)) return Standard_False;
1069 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
1070 Standard_Integer indmax = index+thenbitem*thetermsz-1;
1071 val = new IGESData_HArray1OfIGESEntity (index , indmax);
1072 Standard_Integer ind = index;
1073 Standard_Integer nbneg = 0, nbnul = 0;
1075 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1076 for (i = FirstRead(); i > 0; i = NextRead()) {
1077 Standard_Integer nval;
1078 if (!ReadingEntityNumber(i,nval)) nval = 0; //return Standard_False;
1079 if (nval < 0) nbneg ++;
1081 DeclareAndCast(IGESData_IGESEntity,anent,IR->BoundEntity(nval));
1082 if (anent.IsNull()) nbnul ++;
1083 else if (IR->DirType(nval).Type() == 0) nbnul ++;
1084 else { val->SetValue (ind, anent); ind ++; }
1087 if (ind == indmax+1) { } // tableau complet
1088 else if (ind == index) val.Nullify(); // tableau vide
1090 // Trous : ils ont ete elimines, mais le tableau est a retailler
1091 Handle(IGESData_HArray1OfIGESEntity) tab =
1092 new IGESData_HArray1OfIGESEntity (index , ind-1);
1093 for (i = index; i < ind; i ++) tab->SetValue (i,val->Value(i));
1099 return Standard_True;
1103 //=======================================================================
1104 //function : ReadEnts
1106 //=======================================================================
1108 Standard_Boolean IGESData_ParamReader::ReadEnts
1109 (const Handle(IGESData_IGESReaderData)& IR,
1110 const IGESData_ParamCursor& PC, const Standard_CString mess,
1111 Handle(IGESData_HArray1OfIGESEntity)& val, const Standard_Integer index)
1113 if (!PrepareRead(PC,mess,Standard_True)) return Standard_False;
1114 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
1115 Standard_Integer indmax = index+thenbitem*thetermsz-1;
1116 val = new IGESData_HArray1OfIGESEntity (index , indmax);
1117 Standard_Integer ind = index;
1118 Standard_Integer nbneg = 0, nbnul = 0;
1120 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1121 for (i = FirstRead(); i > 0; i = NextRead()) {
1122 Standard_Integer nval;
1123 if (!ReadingEntityNumber(i,mess,nval)) nval = 0; //return Standard_False;
1124 if (nval < 0) nbneg ++;
1126 DeclareAndCast(IGESData_IGESEntity,anent,IR->BoundEntity(nval));
1127 if (anent.IsNull()) nbnul ++;
1128 else if (IR->DirType(nval).Type() == 0) nbnul ++;
1129 else { val->SetValue (ind, anent); ind ++; }
1132 if (ind == indmax+1) { } // tableau complet
1133 else if (ind == index) val.Nullify(); // tableau vide
1135 // Trous : ils ont ete elimines, mais le tableau est a retailler
1136 Handle(IGESData_HArray1OfIGESEntity) tab =
1137 new IGESData_HArray1OfIGESEntity (index , ind-1);
1138 for (i = index; i < ind; i ++) tab->SetValue (i,val->Value(i));
1144 sprintf(mest,"Skipped Negative Pointer(s), count %d",nbneg);
1145 AddWarning (mest,"Skipped Negative Pointer(s), count %d");
1148 sprintf(mest,"Skipped Null Type Entity(ies), count %d",nbnul);
1149 AddWarning (mest,"Skipped Null Type Entity(ies), count %d");
1151 return Standard_True;
1155 // ReadEntList for MoniTool
1157 //=======================================================================
1158 //function : ReadEntList
1160 //=======================================================================
1162 Standard_Boolean IGESData_ParamReader::ReadEntList
1163 (const Handle(IGESData_IGESReaderData)& IR,
1164 const IGESData_ParamCursor& PC, Message_Msg& amsg,
1165 Interface_EntityList& val, const Standard_Boolean ord)
1168 if (!PrepareRead(PC,Standard_True)) return Standard_False;
1170 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
1171 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
1172 Standard_Integer nval;
1173 if (!ReadingEntityNumber(i,nval)) return Standard_False;
1176 Message_Msg Msg219 ("XSTEP_219");
1177 amsg.Arg(Msg219.Value());
1180 if (nval <= 0) continue;
1181 DeclareAndCast(IGESData_IGESEntity,anent,IR->BoundEntity(nval));
1184 Message_Msg Msg216 ("XSTEP_216");
1185 amsg.Arg(Msg216.Value());
1188 else if (IR->DirType(nval).Type() == 0)
1190 Message_Msg Msg217 ("XSTEP_217");
1191 SendWarning(TCollection_AsciiString(Msg217.Value()).ToCString());
1193 else if (ord) val.Append (anent);
1194 else val.Add (anent);
1196 return Standard_True;
1200 //=======================================================================
1201 //function : ReadEntList
1203 //=======================================================================
1205 Standard_Boolean IGESData_ParamReader::ReadEntList
1206 (const Handle(IGESData_IGESReaderData)& IR,
1207 const IGESData_ParamCursor& PC, const Standard_CString mess,
1208 Interface_EntityList& val, const Standard_Boolean ord)
1210 if (!PrepareRead(PC,mess,Standard_True)) return Standard_False;
1212 if (thenbitem == 0) return Standard_True; // vide : retour Null ...
1213 for (Standard_Integer i = FirstRead(); i > 0; i = NextRead()) {
1214 Standard_Integer nval;
1215 if (!ReadingEntityNumber(i,mess,nval)) return Standard_False;
1216 if (nval < 0) AddWarning(" Negative Pointer, skipped","");
1217 if (nval <= 0) continue;
1218 DeclareAndCast(IGESData_IGESEntity,anent,IR->BoundEntity(nval));
1219 if (anent.IsNull()) AddWarning(" Null Pointer, skipped","");
1220 else if (IR->DirType(nval).Type() == 0) AddWarning(" Pointer to IGES Null Entity, skipped","");
1221 else if (ord) val.Append (anent);
1222 else val.Add (anent);
1224 return Standard_True;
1228 // ReadingReal for MoniTool
1230 //=======================================================================
1231 //function : ReadingReal
1233 //=======================================================================
1235 Standard_Boolean IGESData_ParamReader::ReadingReal (const Standard_Integer num,
1238 const Interface_FileParameter& FP = theparams->Value(num+thebase);
1239 if(FP.ParamType() == Interface_ParamInteger) {
1241 if (testconv < 0) testconv = 0; //Interface_Static::IVal("iges.convert.read");
1245 // sprintf(ssem,": Integer converted to Real, 1st rank=%d",num);
1246 // AddWarning (mess,ssem,"At least one Integer converted to Real, 1st rank=%d");
1249 Standard_Integer ival = atoi(FP.CValue());
1251 return Standard_True;
1254 Standard_CString orig = FP.CValue();
1255 Standard_Integer i , j = 0;
1256 for (i = 0; i < 50; i ++) {
1257 if (orig[i] == 'D' || orig[i] == 'd')
1260 text[j++] = orig[i];
1261 if (orig[i] == '\0') break;
1263 if (FP.ParamType() == Interface_ParamReal)
1265 else if (FP.ParamType() == Interface_ParamEnum) { // convention
1267 if (testconv < 0) testconv = 0; //Interface_Static::IVal("iges.convert.read");
1271 // sprintf(ssem,"Real with no decimal point (added), 1st rank=%d",num);
1272 // AddWarning (mess,ssem,"Real with no decimal point (added), 1st rank=%d");
1275 // Par convention (pas d enum explicite dans IGES), signifie
1276 // "reconnu comme flottant mais pas blanc-bleu" c-a-d sans point decimal
1277 // mais avec exposant (sinon ce serait un entier)
1278 // -> un message avertissement + on ajoute le point puis on convertit
1281 } else if (FP.ParamType() == Interface_ParamVoid) {
1282 val = 0.0; // DEFAULT
1285 // sprintf(ssem,": not given as Real, rank %d",num);
1286 // AddFail (mess,ssem,": not given as Real, rank %d");
1287 /* TCollection_AsciiString mess = amsg.Value();
1288 if ((mess.Search("ter %d"))||(mess.Search("tre %d")))
1289 amsg.AddInteger(num); // Parameter index
1291 return Standard_False;
1293 return Standard_True;
1297 //=======================================================================
1298 //function : ReadingReal
1300 //=======================================================================
1302 Standard_Boolean IGESData_ParamReader::ReadingReal
1303 (const Standard_Integer num, const Standard_CString mess,
1306 const Interface_FileParameter& FP = theparams->Value(num+thebase);
1307 if (FP.ParamType() == Interface_ParamInteger) {
1309 if (testconv < 0) testconv = 0; //Interface_Static::IVal("iges.convert.read");
1313 sprintf(ssem,": Integer converted to Real, 1st rank=%d",num);
1314 AddWarning (mess,ssem,"At least one Integer converted to Real, 1st rank=%d");
1317 Standard_Integer ival = atoi(FP.CValue());
1319 return Standard_True;
1322 Standard_CString orig = FP.CValue();
1323 Standard_Integer i , j = 0;
1324 for (i = 0; i < 50; i ++) {
1325 if (orig[i] == 'D' || orig[i] == 'd')
1328 text[j++] = orig[i];
1329 if (orig[i] == '\0') break;
1331 if (FP.ParamType() == Interface_ParamReal)
1333 else if (FP.ParamType() == Interface_ParamEnum) { // convention
1335 if (testconv < 0) testconv = 0; //Interface_Static::IVal("iges.convert.read");
1339 sprintf(ssem,"Real with no decimal point (added), 1st rank=%d",num);
1340 AddWarning (mess,ssem,"Real with no decimal point (added), 1st rank=%d");
1343 // Par convention (pas d enum explicite dans IGES), signifie
1344 // "reconnu comme flottant mais pas blanc-bleu" c-a-d sans point decimal
1345 // mais avec exposant (sinon ce serait un entier)
1346 // -> un message avertissement + on ajoute le point puis on convertit
1349 } else if (FP.ParamType() == Interface_ParamVoid) {
1350 val = 0.0; // DEFAULT
1352 val = 0.0; // DEFAULT
1354 sprintf(ssem,": not given as Real, rank %d",num);
1355 AddFail (mess,ssem,": not given as Real, rank %d");
1356 return Standard_False;
1358 return Standard_True;
1362 // ReadingEntityNumber for MoniTool
1364 //=======================================================================
1365 //function : ReadingEntityNumber
1367 //=======================================================================
1369 Standard_Boolean IGESData_ParamReader::ReadingEntityNumber (const Standard_Integer num,
1370 Standard_Integer& val)
1372 const Interface_FileParameter& FP = theparams->Value(num+thebase);
1373 val = ParamNumber(num);
1375 Standard_Boolean nulref = Standard_False;
1376 if (FP.ParamType() == Interface_ParamInteger)
1377 nulref = (atoi(FP.CValue()) == 0);
1378 else if (FP.ParamType() == Interface_ParamVoid) nulref = Standard_True;
1380 // AddFail (mess," : cannot refer to an Entity","");
1381 thelast = Standard_True;
1382 return Standard_False;
1385 return Standard_True;
1389 //=======================================================================
1390 //function : ReadingEntityNumber
1392 //=======================================================================
1394 Standard_Boolean IGESData_ParamReader::ReadingEntityNumber
1395 (const Standard_Integer num, const Standard_CString mess,
1396 Standard_Integer& val)
1398 const Interface_FileParameter& FP = theparams->Value(num+thebase);
1399 val = ParamNumber(num);
1401 Standard_Boolean nulref = Standard_False;
1402 if (FP.ParamType() == Interface_ParamInteger)
1403 nulref = (atoi(FP.CValue()) == 0);
1404 else if (FP.ParamType() == Interface_ParamVoid) nulref = Standard_True;
1406 AddFail (mess," : cannot refer to an Entity","");
1407 thelast = Standard_True;
1408 return Standard_False;
1411 return Standard_True;
1415 //=======================================================================
1416 //function : SendFail
1418 //=======================================================================
1420 void IGESData_ParamReader::SendFail (const Message_Msg& amsg)
1422 thecheck->SendFail (amsg);
1423 thelast = Standard_False;
1427 //=======================================================================
1428 //function : SendWarning
1430 //=======================================================================
1432 void IGESData_ParamReader::SendWarning (const Message_Msg& amsg)
1434 thecheck->SendWarning (amsg);
1435 thelast = Standard_False;
1440 // .... Gestion courante du statut de lecture ....
1443 //=======================================================================
1444 //function : AddFail
1446 //=======================================================================
1448 void IGESData_ParamReader::AddFail(const Standard_CString idm,
1449 const Handle(TCollection_HAsciiString)& afail,
1450 const Handle(TCollection_HAsciiString)& bfail)
1452 afail->Insert (1,idm);
1453 if (bfail != afail) bfail->Insert (1,idm);
1454 thecheck->AddFail (afail,bfail);
1455 thelast = Standard_False;
1459 //=======================================================================
1460 //function : AddFail
1462 //=======================================================================
1464 void IGESData_ParamReader::AddFail(const Standard_CString idm,
1465 const Standard_CString afail,
1466 const Standard_CString bfail)
1468 Handle(TCollection_HAsciiString) af = new TCollection_HAsciiString(afail);
1469 Handle(TCollection_HAsciiString) bf = af;
1470 if (bfail[0] != '\0') bf = new TCollection_HAsciiString(bfail);
1471 AddFail (idm, af,bf);
1475 //=======================================================================
1476 //function : AddWarning
1478 //=======================================================================
1480 void IGESData_ParamReader::AddWarning(const Standard_CString idm,
1481 const Handle(TCollection_HAsciiString)& aw,
1482 const Handle(TCollection_HAsciiString)& bw)
1485 if (bw != aw) bw->Insert (1,idm);
1486 thecheck->AddWarning (aw,bw);
1490 //=======================================================================
1491 //function : AddWarning
1493 //=======================================================================
1495 void IGESData_ParamReader::AddWarning(const Standard_CString idm,
1496 const Standard_CString awarn,
1497 const Standard_CString bwarn)
1499 Handle(TCollection_HAsciiString) aw = new TCollection_HAsciiString(awarn);
1500 Handle(TCollection_HAsciiString) bw = aw;
1501 if (bwarn[0] != '\0') bw = new TCollection_HAsciiString(bwarn);
1502 AddWarning (idm, aw,bw);
1506 //=======================================================================
1507 //function : AddFail
1509 //=======================================================================
1511 void IGESData_ParamReader::AddFail(const Standard_CString afail,
1512 const Standard_CString bfail)
1514 thelast = Standard_False;
1515 thecheck->AddFail(afail,bfail);
1519 //=======================================================================
1520 //function : AddFail
1522 //=======================================================================
1524 void IGESData_ParamReader::AddFail(const Handle(TCollection_HAsciiString)& afail,
1525 const Handle(TCollection_HAsciiString)& bfail)
1527 thelast = Standard_False;
1528 thecheck->AddFail(afail,bfail);
1532 //=======================================================================
1533 //function : AddWarning
1535 //=======================================================================
1537 void IGESData_ParamReader::AddWarning(const Standard_CString amess,
1538 const Standard_CString bmess)
1540 thecheck->AddWarning(amess,bmess);
1544 //=======================================================================
1545 //function : AddWarning
1547 //=======================================================================
1549 void IGESData_ParamReader::AddWarning(const Handle(TCollection_HAsciiString)& amess,
1550 const Handle(TCollection_HAsciiString)& bmess)
1552 thecheck->AddWarning(amess,bmess);
1556 //=======================================================================
1559 //=======================================================================
1561 void IGESData_ParamReader::Mend (const Standard_CString pref)
1563 thecheck->Mend (pref);
1564 thelast = Standard_True;
1568 //=======================================================================
1569 //function : HasFailed
1571 //=======================================================================
1573 Standard_Boolean IGESData_ParamReader::HasFailed () const
1576 } //thecheck.HasFailed();
1579 //=======================================================================
1582 //=======================================================================
1584 const Handle(Interface_Check)& IGESData_ParamReader::Check () const
1590 //=======================================================================
1593 //=======================================================================
1595 Handle(Interface_Check)& IGESData_ParamReader::CCheck ()
1601 //=======================================================================
1602 //function : IsCheckEmpty
1604 //=======================================================================
1606 Standard_Boolean IGESData_ParamReader::IsCheckEmpty () const
1608 return (!thecheck->HasFailed() && !thecheck->HasWarnings());