1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13 
14 //====================================================================
15 //#10 smh 22.12.99 Protection (case of unexisting directory entry in file)
16 //sln 21.01.2002 OCC133: Exception handling was added in method Interface_FileReaderData::BoundEntity
17 //====================================================================
18 
19 #include <Interface_FileParameter.hxx>
20 #include <Interface_FileReaderData.hxx>
21 #include <Interface_ParamList.hxx>
22 #include <Interface_ParamSet.hxx>
23 #include <Standard_ErrorHandler.hxx>
24 #include <Standard_Failure.hxx>
25 #include <Standard_NoSuchObject.hxx>
26 #include <Standard_Transient.hxx>
27 #include <Standard_Type.hxx>
28 #include <TCollection_AsciiString.hxx>
29 
30 IMPLEMENT_STANDARD_RTTIEXT(Interface_FileReaderData,Standard_Transient)
31 
32 //  Stoque les Donnees issues d un Fichier (Conservees sous forme Litterale)
33 //  Chaque norme peut s en servir comme base (listes de parametres litteraux,
34 //  entites associees) et y ajoute ses donnees propres.
35 //  Travaille sous le controle de FileReaderTool
36 //  Optimisation : Champs pas possibles, car Param est const. Dommage
37 //  Donc, on suppose qu on lit un fichier a la fois (hypothese raisonnable)
38 //  On note en champ un numero de fichier, par rapport auquel on optimise
39 static Standard_Integer thefic = 0;
40 static Standard_Integer thenm0 = -1;
41 static Standard_Integer thenp0 = -1;
42 
43 
Interface_FileReaderData(const Standard_Integer nbr,const Standard_Integer npar)44 Interface_FileReaderData::Interface_FileReaderData (const Standard_Integer nbr,
45 						    const Standard_Integer npar)
46      : therrload (0), thenumpar (0,nbr), theents (0,nbr)
47 {
48   theparams = new Interface_ParamSet (npar);
49   thenumpar.Init(0);
50   thenm0 = -1;
51   thenum0 = ++thefic;
52 }
53 
NbRecords() const54     Standard_Integer Interface_FileReaderData::NbRecords () const
55       {  return thenumpar.Upper();  }
56 
NbEntities() const57     Standard_Integer Interface_FileReaderData::NbEntities () const
58 {
59   Standard_Integer nb = 0; Standard_Integer num = 0;
60   while ( (num = FindNextRecord(num)) > 0) nb ++;
61   return nb;
62 }
63 
64 
65 //  ....            Gestion des Parametres attaches aux Records            ....
66 
InitParams(const Standard_Integer num)67     void Interface_FileReaderData::InitParams (const Standard_Integer num)
68 {
69   thenumpar.SetValue (num,theparams->NbParams());
70 }
71 
AddParam(const Standard_Integer,const Standard_CString aval,const Interface_ParamType atype,const Standard_Integer nument)72     void Interface_FileReaderData::AddParam
73   (const Standard_Integer /*num*/,
74    const Standard_CString aval, const Interface_ParamType atype,
75    const Standard_Integer nument)
76 {
77   theparams->Append(aval,-1,atype,nument);
78 }
79 
AddParam(const Standard_Integer,const TCollection_AsciiString & aval,const Interface_ParamType atype,const Standard_Integer nument)80     void Interface_FileReaderData::AddParam
81   (const Standard_Integer /*num*/,
82    const TCollection_AsciiString& aval, const Interface_ParamType atype,
83    const Standard_Integer nument)
84 {
85   theparams->Append(aval.ToCString(),aval.Length(),atype,nument);
86 }
87 
AddParam(const Standard_Integer,const Interface_FileParameter & FP)88     void Interface_FileReaderData::AddParam
89   (const Standard_Integer /*num*/,
90    const Interface_FileParameter& FP)
91 {
92   theparams->Append(FP);
93 }
94 
95 
SetParam(const Standard_Integer num,const Standard_Integer nump,const Interface_FileParameter & FP)96     void Interface_FileReaderData::SetParam
97   (const Standard_Integer num, const Standard_Integer nump,
98    const Interface_FileParameter& FP)
99 {
100     theparams->SetParam(thenumpar(num-1)+nump,FP);
101 }
102 
NbParams(const Standard_Integer num) const103     Standard_Integer Interface_FileReaderData::NbParams
104   (const Standard_Integer num) const
105 {
106   if (num > 1) return (thenumpar(num) - thenumpar(num-1));
107   else if(num ==1) return thenumpar(num);
108   else return theparams->NbParams();
109 }
110 
Handle(Interface_ParamList)111     Handle(Interface_ParamList) Interface_FileReaderData::Params
112   (const Standard_Integer num) const
113 {
114   if (num == 0) return theparams->Params(0,0);  // complet
115   else if(num ==1) return theparams->Params(0,thenumpar(1));
116   else return theparams->Params ( thenumpar(num-1)+1, (thenumpar(num) - thenumpar(num-1)) );
117 }
118 
Param(const Standard_Integer num,const Standard_Integer nump) const119     const Interface_FileParameter& Interface_FileReaderData::Param
120   (const Standard_Integer num, const Standard_Integer nump) const
121 {
122   if (thefic != thenum0) return theparams->Param(thenumpar(num-1)+nump);
123   if (thenm0 != num) {  thenp0 = thenumpar(num-1);  thenm0 = num;  }
124   return theparams->Param (thenp0+nump);
125 }
126 
ChangeParam(const Standard_Integer num,const Standard_Integer nump)127     Interface_FileParameter& Interface_FileReaderData::ChangeParam
128   (const Standard_Integer num, const Standard_Integer nump)
129 {
130   if (thefic != thenum0) return theparams->ChangeParam(thenumpar(num-1)+nump);
131   if (thenm0 != num) {  thenp0 = thenumpar(num-1);  thenm0 = num;  }
132   return theparams->ChangeParam (thenp0+nump);
133 }
134 
ParamType(const Standard_Integer num,const Standard_Integer nump) const135     Interface_ParamType Interface_FileReaderData::ParamType
136   (const Standard_Integer num, const Standard_Integer nump) const
137       {  return Param(num,nump).ParamType();  }
138 
ParamCValue(const Standard_Integer num,const Standard_Integer nump) const139     Standard_CString  Interface_FileReaderData::ParamCValue
140   (const Standard_Integer num, const Standard_Integer nump) const
141       {  return Param(num,nump).CValue();  }
142 
143 
IsParamDefined(const Standard_Integer num,const Standard_Integer nump) const144     Standard_Boolean Interface_FileReaderData::IsParamDefined
145   (const Standard_Integer num, const Standard_Integer nump) const
146       {  return (Param(num,nump).ParamType() != Interface_ParamVoid);  }
147 
ParamNumber(const Standard_Integer num,const Standard_Integer nump) const148     Standard_Integer Interface_FileReaderData::ParamNumber
149   (const Standard_Integer num, const Standard_Integer nump) const
150       {  return Param(num,nump).EntityNumber();  }
151 
Handle(Standard_Transient)152     const Handle(Standard_Transient)& Interface_FileReaderData::ParamEntity
153   (const Standard_Integer num, const Standard_Integer nump) const
154       {  return BoundEntity (Param(num,nump).EntityNumber());  }
155 
ChangeParameter(const Standard_Integer numpar)156     Interface_FileParameter& Interface_FileReaderData::ChangeParameter
157   (const Standard_Integer numpar)
158       {  return theparams->ChangeParam (numpar);  }
159 
ParamPosition(const Standard_Integer numpar,Standard_Integer & num,Standard_Integer & nump) const160     void  Interface_FileReaderData::ParamPosition
161   (const Standard_Integer numpar,
162    Standard_Integer& num, Standard_Integer& nump) const
163 {
164   Standard_Integer nbe = thenumpar.Upper();
165   if (numpar <= 0) {  num = nump = 0;  return;  }
166   for (Standard_Integer i = 1; i <= nbe; i ++) {
167     if (thenumpar(i) > numpar)
168       {  num = i;  nump = numpar - thenumpar(i) +1;  return;  }
169   }
170   num = nbe;  nump = numpar - thenumpar(nbe) +1;
171 }
172 
ParamFirstRank(const Standard_Integer num) const173     Standard_Integer Interface_FileReaderData::ParamFirstRank
174   (const Standard_Integer num) const
175       {  return thenumpar(num);  }
176 
SetErrorLoad(const Standard_Boolean val)177     void  Interface_FileReaderData::SetErrorLoad (const Standard_Boolean val)
178       {  therrload = (val ? 1 : -1);  }
179 
IsErrorLoad() const180     Standard_Boolean  Interface_FileReaderData::IsErrorLoad () const
181       {  return (therrload != 0);  }
182 
ResetErrorLoad()183     Standard_Boolean  Interface_FileReaderData::ResetErrorLoad ()
184       {  Standard_Boolean res = (therrload > 0); therrload = 0;  return res;  }
185 
186 //  ....        Gestion des Entites Associees aux Donnees du Fichier       ....
187 
188 
Handle(Standard_Transient)189 const Handle(Standard_Transient)& Interface_FileReaderData::BoundEntity
190        (const Standard_Integer num) const
191        //      {  return theents(num);  }
192 {
193   if (num >= theents.Lower() && num <= theents.Upper()) {
194     return theents(num);
195   }
196   else {
197     static Handle(Standard_Transient) dummy;
198     return dummy;
199   }
200 }
201 /*  //static Handle(Standard_Transient) dummy;
202   {
203   //smh#10 Protection. If iges entity does not exist, return null pointer.
204     try {
205       OCC_CATCH_SIGNALS
206       Handle(Standard_Transient) temp = theents.Value(num);
207     }
208   ////sln 21.01.2002 OCC133: Exception handling
209  // catch (Standard_OutOfRange) {
210  //   std::cout<<" Catch of sln"<<std::endl;
211 
212  //   return dummy;
213  // }
214     catch (Standard_Failure) {
215 
216     // some work-around, the best would be to modify CDL to
217     // return "Handle(Standard_Transient)" not "const Handle(Standard_Transient)&"
218       static Handle(Standard_Transient) dummy;
219      // std::cout<<" Catch of smh"<<std::endl;
220     return dummy;
221     }
222   }
223    //std::cout<<" Normal"<<std::endl;
224   if (theents.Value(num).IsImmutable()) std::cout << "IMMUTABLE:"<<num<<std::endl;
225   return theents(num);
226 }
227 */
228 
BindEntity(const Standard_Integer num,const Handle (Standard_Transient)& ent)229 void Interface_FileReaderData::BindEntity
230    (const Standard_Integer num, const Handle(Standard_Transient)& ent)
231 //      {  theents.SetValue(num,ent);  }
232 {
233 //  #ifdef OCCT_DEBUG
234 //    if (ent.IsImmutable())
235 //      std::cout << "Bind IMMUTABLE:"<<num<<std::endl;
236 //  #endif
237   theents.SetValue(num,ent);
238 }
239 
Destroy()240 void Interface_FileReaderData::Destroy ()
241 {
242 }
243 
Fastof(const Standard_CString ligne)244 Standard_Real Interface_FileReaderData::Fastof (const Standard_CString ligne)
245 {
246   return Strtod (ligne, 0);
247 }
248