7fd59977 |
1 | // dce 21.01.99 : move of general message to IGESToBRep_Reader |
2 | |
3 | #include <stdio.h> |
4 | // declarations des programmes C de base : |
5 | #include <Interface_ParamType.hxx> |
6 | #include <IGESData_IGESReaderData.hxx> |
7 | #include <IGESData_IGESReaderTool.hxx> |
8 | #include <IGESData_GeneralModule.hxx> |
9 | #include <Interface_Check.hxx> |
10 | |
11 | #include <Interface_FileParameter.hxx> |
12 | #include <Interface_ParamList.hxx> |
13 | // Pour traiter les exceptions : |
14 | #include <Standard_ErrorHandler.hxx> |
15 | #include <Standard_Failure.hxx> |
16 | |
17 | // definition de base, a inclure pour utiliser |
18 | #include <IGESFile_Read.hxx> |
19 | |
20 | #include "igesread.h" |
21 | |
22 | //#define VERIFPRINT |
23 | |
24 | // MGE 16/06/98 |
25 | // To use Msg class |
26 | #include <Message_Msg.hxx> |
27 | |
28 | // decoupage interne pour faciliter les recuperations d erreurs |
29 | static Standard_Integer recupne,recupnp; // pour affichage en cas de pepin |
30 | static Handle(Interface_Check)& checkread() |
31 | { |
32 | static Handle(Interface_Check) chrd = new Interface_Check; |
33 | return chrd; |
34 | } |
35 | |
36 | static void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR); |
37 | static void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR); |
38 | void IGESFile_Check (int mode,Message_Msg& amsg); |
39 | // void IGESFile_Check2 (int mode,char * code, int num, char * str); |
40 | // void IGESFile_Check3 (int mode,char * code); |
41 | |
42 | // Correspondance entre types igesread et types Interface_ParamFile ... |
43 | static Interface_ParamType LesTypes[10]; |
44 | |
45 | |
46 | // Nouvelle maniere : Protocol suffit |
47 | |
48 | Standard_Integer IGESFile_Read |
49 | (char* nomfic, |
50 | const Handle(IGESData_IGESModel)& amodel, |
51 | const Handle(IGESData_Protocol)& protocol) |
52 | { |
53 | Handle(IGESData_FileRecognizer) nulreco; |
54 | return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_False); |
55 | } |
56 | |
57 | Standard_Integer IGESFile_ReadFNES |
58 | (char* nomfic, |
59 | const Handle(IGESData_IGESModel)& amodel, |
60 | const Handle(IGESData_Protocol)& protocol) |
61 | { |
62 | Handle(IGESData_FileRecognizer) nulreco; |
63 | return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_True); |
64 | } |
65 | |
66 | |
67 | // Ancienne maniere : avec Recognizer |
68 | |
69 | Standard_Integer IGESFile_Read |
70 | (char* nomfic, |
71 | const Handle(IGESData_IGESModel)& amodel, |
72 | const Handle(IGESData_Protocol)& protocol, |
73 | const Handle(IGESData_FileRecognizer)& reco, |
74 | const Standard_Boolean modefnes) |
75 | { |
76 | //==================================== |
77 | Message_Msg Msg1 = Message_Msg("XSTEP_1"); |
78 | Message_Msg Msg15 = Message_Msg("XSTEP_15"); |
79 | //==================================== |
80 | |
81 | char* ficnom = nomfic; // ficnom ? |
82 | int lesect[6]; |
83 | |
84 | // Sending of message : Beginning of the reading |
85 | IGESFile_Check(2, Msg1); |
86 | |
87 | checkread()->Clear(); |
88 | int result = igesread(ficnom,lesect,modefnes); |
89 | |
90 | if (result != 0) return result; |
91 | |
92 | // Chargement des resultats dans un IGESReader |
93 | |
94 | LesTypes[ArgVide] = Interface_ParamVoid; |
95 | LesTypes[ArgQuid] = Interface_ParamMisc; |
96 | LesTypes[ArgChar] = Interface_ParamText; |
97 | LesTypes[ArgInt] = Interface_ParamInteger; |
98 | LesTypes[ArgSign] = Interface_ParamInteger; |
99 | LesTypes[ArgReal] = Interface_ParamReal; |
100 | LesTypes[ArgExp ] = Interface_ParamMisc; // exposant pas termine |
101 | LesTypes[ArgRexp] = Interface_ParamReal; // exposant complet |
102 | LesTypes[ArgMexp] = Interface_ParamEnum; // exposant mais pas de point |
103 | |
104 | |
105 | int nbparts, nbparams; |
106 | iges_stats(&nbparts,&nbparams); // et fait les Initialisations necessaires |
107 | Handle(IGESData_IGESReaderData) IR = |
108 | // new IGESData_IGESReaderData (nbparts, nbparams); |
109 | new IGESData_IGESReaderData((lesect[3]+1)/2, nbparams); |
110 | { |
111 | { |
112 | try { |
113 | OCC_CATCH_SIGNALS |
114 | IGESFile_ReadHeader(IR); |
115 | } // fin essai 1 (global) |
116 | catch (Standard_Failure) { |
117 | // Sending of message : Internal error during the header reading |
118 | Message_Msg Msg11 = Message_Msg("XSTEP_11"); |
119 | IGESFile_Check (1,Msg11); |
120 | } |
121 | } |
122 | |
123 | { |
124 | try { |
125 | OCC_CATCH_SIGNALS |
126 | if (nbparts > 0) IGESFile_ReadContent(IR); |
127 | |
128 | // Sending of message : Loaded data |
129 | } // fin essai 2 (entites) |
130 | catch (Standard_Failure) { |
131 | // Sending of message : Internal error during the content reading |
132 | if (recupnp == 0) { |
133 | Message_Msg Msg13 = Message_Msg("XSTEP_13"); |
134 | Msg13.Arg(recupne); |
135 | IGESFile_Check(1,Msg13); |
136 | } |
137 | else { |
138 | Message_Msg Msg14 = Message_Msg("XSTEP_14"); |
139 | Msg14.Arg(recupne); |
140 | Msg14.Arg(recupnp); |
141 | IGESFile_Check(1, Msg14); |
142 | } |
143 | } |
144 | } |
145 | } |
146 | |
147 | Standard_Integer nbr = IR->NbRecords(); |
148 | // Sending of message : Number of total loaded entities |
149 | Msg15.Arg(nbr); |
150 | IGESFile_Check(2, Msg15); |
151 | iges_finfile(1); |
152 | IGESData_IGESReaderTool IT (IR,protocol); |
153 | IT.Prepare(reco); |
154 | IT.SetErrorHandle(Standard_True); |
155 | |
156 | // Sending of message : Loading of Model : Beginning |
157 | IT.LoadModel(amodel); |
158 | if (amodel->Protocol().IsNull()) amodel->SetProtocol (protocol); |
159 | iges_finfile(2); |
160 | |
161 | // A present, le check |
162 | // Nb warning in global section. |
163 | Standard_Integer nbWarn = checkread()->NbWarnings(), nbFail = checkread()->NbFails(); |
164 | const Handle(Interface_Check)& oldglob = amodel->GlobalCheck(); |
165 | if (nbWarn + nbFail > 0) { |
166 | checkread()->GetMessages (oldglob); |
167 | amodel->SetGlobalCheck (checkread()); |
168 | } |
169 | |
170 | checkread()->Trace(0,1); |
171 | |
172 | return 0; |
173 | } |
174 | |
175 | |
176 | // Decoupage interne |
177 | |
178 | void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR) |
179 | { |
180 | Standard_Integer l=0; //szv#4:S4163:12Mar99 i,j,k not needed |
181 | char* parval; |
182 | int typarg; |
183 | // d abord les start lines (commentaires) |
184 | //szv#4:S4163:12Mar99 optimized |
185 | /* |
186 | while ( (j = iges_lirparam(&typarg,&parval)) != 0) { |
187 | k = -1; |
188 | for (Standard_Integer j = 72; j >= 0; j --) { |
189 | if (parval[j] > 32) { k = j; break; } |
190 | } |
191 | parval[k+1] = '\0'; |
192 | if (k >= 0 || l > 0) IR->AddStartLine (parval); |
193 | l ++; |
194 | } |
195 | // puis la Global Section |
196 | iges_setglobal(); |
197 | while ( (i = iges_lirparam(&typarg,&parval)) != 0) { |
198 | IR->AddGlobal(LesTypes[typarg],parval); |
199 | } |
200 | */ |
201 | while (iges_lirparam(&typarg,&parval) != 0) { |
202 | Standard_Integer j; // svv Jan11 2000 : porting on DEC |
203 | for (j = 72; j >= 0; j--) |
204 | if (parval[j] > 32) break; |
205 | parval[j+1] = '\0'; |
206 | if (j >= 0 || l > 0) IR->AddStartLine (parval); |
207 | l++; |
208 | } |
209 | // puis la Global Section |
210 | iges_setglobal(); |
211 | while (iges_lirparam(&typarg,&parval) != 0) IR->AddGlobal(LesTypes[typarg],parval); |
212 | IR->SetGlobalSection(); |
213 | } |
214 | |
215 | void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR) |
216 | { |
217 | char *res1, *res2, *nom, *num; char* parval; |
218 | int *v; int typarg; |
219 | int nbparam; |
220 | |
221 | |
222 | Standard_Integer nn=0; |
223 | int ns; //szv#4:S4163:12Mar99 i unused |
224 | while ( (ns = iges_lirpart(&v,&res1,&res2,&nom,&num,&nbparam)) != 0) { |
225 | nn++; |
226 | recupnp = 0; |
227 | recupne = (ns+1)/2; // numero entite |
228 | // if(recupne > IR->NbEntities()) { |
229 | // iges_nextpart(); |
230 | // continue; |
231 | // } |
232 | IR->SetDirPart(recupne, |
233 | v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10], |
234 | v[11],v[12],v[13],v[14],v[15],v[16],res1,res2,nom,num); |
235 | while (iges_lirparam(&typarg,&parval) != 0) { //szv#4:S4163:12Mar99 `i=` not needed |
236 | recupnp ++; |
237 | if (typarg == ArgInt || typarg == ArgSign) { |
238 | Standard_Integer nument = atoi(parval); |
239 | if (nument < 0) nument = -nument; |
240 | if (nument & 1) nument = (nument+1)/2; |
241 | else nument = 0; |
242 | IR->AddParam(recupne,parval,LesTypes[typarg],nument); |
243 | } |
244 | else IR->AddParam(recupne,parval,LesTypes[typarg]); |
245 | } |
246 | IR->InitParams(recupne); |
247 | iges_nextpart(); |
248 | } |
249 | } |
250 | |
251 | |
252 | void IGESFile_Check (int mode,Message_Msg& amsg) |
253 | { |
254 | // MGE 20/07/98 |
255 | switch (mode) |
256 | { |
257 | case 0 : checkread()->SendFail (amsg); break; |
258 | case 1 : checkread()->SendWarning (amsg); break; |
259 | case 2 : checkread()->SendMsg (amsg);break; |
260 | default : checkread()->SendMsg (amsg); |
261 | } |
262 | //checkread().Trace(3,-1); |
263 | } |
264 | |
265 | void IGESFile_Check2 (int mode,char * code, int num, char * str) |
266 | { |
267 | // MGE 20/07/98 |
268 | Message_Msg amsg (code); |
269 | amsg.Arg(num); |
270 | amsg.Arg(str); |
271 | |
272 | switch (mode) |
273 | { |
274 | case 0 : checkread()->SendFail (amsg); break; |
275 | case 1 : checkread()->SendWarning (amsg); break; |
276 | case 2 : checkread()->SendMsg (amsg); break; |
277 | default : checkread()->SendMsg (amsg); |
278 | } |
279 | //checkread().Trace(3,-1); |
280 | } |
281 | |
282 | |
283 | void IGESFile_Check3 (int mode,char * code) |
284 | { |
285 | // MGE 20/07/98 |
286 | Message_Msg amsg (code); |
287 | switch (mode) |
288 | { |
289 | case 0 : checkread()->SendFail (amsg); break; |
290 | case 1 : checkread()->SendWarning (amsg); break; |
291 | case 2 : checkread()->SendMsg (amsg); break; |
292 | default : checkread()->SendMsg (amsg); |
293 | } |
294 | //checkread().Trace(3,-1); |
295 | } |