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