7fd59977 |
1 | // dce 21/01/99 S3767 : Suppression of general messages |
2 | #include <Interface_FileReaderTool.ixx> |
3 | #include <Interface_ReportEntity.hxx> |
4 | #include <Interface_InterfaceMismatch.hxx> |
5 | #include <Interface_CheckFailure.hxx> |
6 | #include <Interface_GeneralModule.hxx> |
7 | #include <Interface_ReaderModule.hxx> |
8 | #include <Message_Messenger.hxx> |
9 | #include <Message_Msg.hxx> |
10 | #include <Message.hxx> |
11 | |
12 | #include <Standard_OutOfRange.hxx> |
13 | #include <Standard_ErrorHandler.hxx> |
14 | #include <Standard_Failure.hxx> |
15 | #include <Standard_TypeMismatch.hxx> |
16 | #ifdef WNT |
17 | #include <OSD_Exception.hxx> |
18 | #else |
19 | #include <OSD_Signal.hxx> |
20 | #endif |
21 | #include <stdio.h> |
22 | |
23 | // MGE 16/06/98 |
24 | // To use Msg class |
25 | #include <Message_Msg.hxx> |
26 | // To use TCollectionHAsciiString |
27 | #include <TCollection_HAsciiString.hxx> |
28 | |
29 | // Failure pour recuperer erreur en lecture fichier, |
30 | // TypeMismatch pour message d erreur circonstancie (cas particulier important) |
31 | |
32 | |
33 | // Gere le chargement d un Fichier, prealablement transforme en FileReaderData |
34 | // (de la bonne norme), dans un Modele |
35 | |
36 | |
37 | //======================================================================= |
38 | //function : Interface_FileReaderTool |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | Interface_FileReaderTool::Interface_FileReaderTool () |
43 | { |
44 | themessenger = Message::DefaultMessenger(); |
45 | theerrhand = Standard_True; |
46 | thetrace = 1; |
47 | thenbrep0 = thenbreps = 0; |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : SetData |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | void Interface_FileReaderTool::SetData(const Handle(Interface_FileReaderData)& reader, |
56 | const Handle(Interface_Protocol)& protocol) |
57 | { |
58 | thereader = reader; |
59 | theproto = protocol; |
60 | } |
61 | |
62 | |
63 | //======================================================================= |
64 | //function : Protocol |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | Handle(Interface_Protocol) Interface_FileReaderTool::Protocol () const |
69 | { |
70 | return theproto; |
71 | } |
72 | |
73 | |
74 | //======================================================================= |
75 | //function : Data |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | Handle(Interface_FileReaderData) Interface_FileReaderTool::Data () const |
80 | { |
81 | return thereader; |
82 | } |
83 | |
84 | |
85 | //======================================================================= |
86 | //function : SetModel |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void Interface_FileReaderTool::SetModel |
91 | (const Handle(Interface_InterfaceModel)& amodel) |
92 | { |
93 | themodel = amodel; |
94 | } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : Model |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | Handle(Interface_InterfaceModel) Interface_FileReaderTool::Model () const |
103 | { |
104 | return themodel; |
105 | } |
106 | |
107 | //======================================================================= |
108 | //function : SetMessenger |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | void Interface_FileReaderTool::SetMessenger (const Handle(Message_Messenger)& messenger) |
113 | { |
114 | if ( messenger.IsNull() ) |
115 | themessenger = Message::DefaultMessenger(); |
116 | else |
117 | themessenger = messenger; |
118 | } |
119 | |
120 | //======================================================================= |
121 | //function : Messenger |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | Handle(Message_Messenger) Interface_FileReaderTool::Messenger () const |
126 | { |
127 | return themessenger; |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : SetTraceLevel |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | void Interface_FileReaderTool::SetTraceLevel (const Standard_Integer tracelev) |
136 | { |
137 | thetrace = tracelev; |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : TraceLevel |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | Standard_Integer Interface_FileReaderTool::TraceLevel () const |
146 | { |
147 | return thetrace; |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : SetErrorHandle |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | void Interface_FileReaderTool::SetErrorHandle(const Standard_Boolean err) |
156 | { |
157 | theerrhand = err; |
158 | } |
159 | |
160 | |
161 | //======================================================================= |
162 | //function : ErrorHandle |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | Standard_Boolean Interface_FileReaderTool::ErrorHandle() const |
167 | { |
168 | return theerrhand; |
169 | } |
170 | |
171 | // .... Actions Connexes au CHARGEMENT DU MODELE .... |
172 | |
173 | // SetEntities fait appel a des methodes a fournir : |
174 | // s appuyant sur un Recognizer adapte a l interface : |
175 | // - Recognize fait reco->Evaluate(... : selon record no num) |
176 | // et recupere le resultat |
177 | // ainsi que la definition de l entite inconnue de l interface |
178 | |
179 | |
180 | //======================================================================= |
181 | //function : SetEntities |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | void Interface_FileReaderTool::SetEntities () |
186 | { |
187 | Standard_Integer num; |
188 | thenbreps = 0; thenbrep0 = 0; |
189 | |
190 | for (num = thereader->FindNextRecord(0); num > 0; |
191 | num = thereader->FindNextRecord(num)) { |
192 | Handle(Standard_Transient) newent; |
193 | Handle(Interface_Check) ach = new Interface_Check; |
194 | if (!Recognize (num,ach,newent)) { |
195 | newent = UnknownEntity(); |
196 | if (thereports.IsNull()) thereports = |
197 | new TColStd_HArray1OfTransient (1,thereader->NbRecords()); |
198 | thenbreps ++; thenbrep0 ++; |
199 | thereports->SetValue (num,new Interface_ReportEntity(ach,newent)); |
200 | } |
201 | else if ((ach->NbFails() + ach->NbWarnings() > 0) && !newent.IsNull()) { |
202 | if (thereports.IsNull()) thereports = |
203 | new TColStd_HArray1OfTransient (1,thereader->NbRecords()); |
204 | thenbreps ++; thenbrep0 ++; |
205 | thereports->SetValue (num,new Interface_ReportEntity(ach,newent)); |
206 | } |
207 | thereader->BindEntity (num,newent); |
208 | } |
209 | } |
210 | |
211 | |
212 | //======================================================================= |
213 | //function : RecognizeByLib |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | Standard_Boolean Interface_FileReaderTool::RecognizeByLib(const Standard_Integer num, |
218 | Interface_GeneralLib& glib, |
219 | Interface_ReaderLib& rlib, |
220 | Handle(Interface_Check)& ach, |
221 | Handle(Standard_Transient)& ent) const |
222 | { |
223 | Handle(Interface_GeneralModule) gmod; |
224 | Handle(Interface_ReaderModule) rmod; |
225 | Handle(Interface_Protocol) proto; |
226 | Standard_Integer CN = 0; |
227 | // Chercher dans ReaderLib : Reconnaissance de cas -> CN , proto |
228 | for (rlib.Start(); rlib.More(); rlib.Next()) { |
229 | rmod = rlib.Module(); |
230 | if (rmod.IsNull()) continue; |
231 | CN = rmod->CaseNum(thereader,num); |
232 | if (CN > 0) { proto = rlib.Protocol(); break; } |
233 | } |
234 | if (CN <= 0 || proto.IsNull()) return Standard_False; |
235 | // Se recaler dans GeneralLib : Creation de l entite vide |
236 | Handle(Standard_Type) typrot = proto->DynamicType(); |
237 | for (glib.Start(); glib.More(); glib.Next()) { |
238 | proto = glib.Protocol(); |
239 | if (proto.IsNull()) continue; |
240 | if (proto->DynamicType() != typrot) continue; |
241 | Standard_Boolean res = glib.Module()->NewVoid(CN,ent); |
242 | if (res) return res; |
243 | if (!rmod.IsNull()) return rmod->NewRead (CN,thereader,num,ach,ent); |
244 | // return res; |
245 | } |
246 | return Standard_False; |
247 | } |
248 | |
249 | |
250 | //======================================================================= |
251 | //function : UnknownEntity |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | Handle(Standard_Transient) Interface_FileReaderTool::UnknownEntity() const |
256 | { |
257 | return theproto->UnknownEntity(); |
258 | } |
259 | |
260 | |
261 | //======================================================================= |
262 | //function : NewModel |
263 | //purpose : |
264 | //======================================================================= |
265 | |
266 | Handle(Interface_InterfaceModel) Interface_FileReaderTool::NewModel() const |
267 | { |
268 | return theproto->NewModel(); |
269 | } |
270 | |
271 | |
272 | //======================================================================= |
273 | //function : EndRead |
274 | //purpose : |
275 | //======================================================================= |
276 | |
277 | void Interface_FileReaderTool::EndRead(const Handle(Interface_InterfaceModel)& ) |
278 | { |
279 | } // par defaut, ne fait rien; redefinissable selon besoin |
280 | |
281 | |
282 | // .... (Sa Majeste le) CHARGEMENT DU MODELE .... |
283 | |
284 | |
285 | //======================================================================= |
286 | //function : LoadModel |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | void Interface_FileReaderTool::LoadModel |
291 | (const Handle(Interface_InterfaceModel)& amodel) |
292 | // |
293 | // Methode generale de lecture d un fichier : il est lu via un FileReaderData |
294 | // qui doit y donner acces de la facon la plus performante possible |
295 | // chaque interface definit son FileHeader avec ses methodes, appelees ici |
296 | { |
297 | // MGE 16/06/98 |
298 | // Building of Messages |
299 | //==================================== |
300 | Handle(Message_Messenger) TF = Messenger(); |
301 | //==================================== |
302 | Handle(Interface_Check) ach = new Interface_Check; |
303 | |
304 | SetModel(amodel); |
305 | |
306 | // .. Demarrage : Lecture du Header .. |
307 | if (theerrhand) { |
308 | try { |
309 | OCC_CATCH_SIGNALS |
310 | BeginRead(amodel); // selon la norme |
311 | } |
312 | catch (Standard_Failure) { |
313 | // Sendinf of message : Internal error during the header reading |
314 | Message_Msg Msg11("XSTEP_11"); |
315 | TF->Send (Msg11, Message_Info); |
316 | } |
317 | } |
318 | else |
319 | BeginRead(amodel); // selon la norme |
320 | |
321 | // .. Lecture des Entites .. |
322 | |
323 | amodel->Reservate (thereader->NbEntities()); |
324 | |
325 | Standard_Integer num, num0 = thereader->FindNextRecord(0); |
326 | num = num0; |
327 | |
328 | while (num > 0) { |
329 | Standard_Integer ierr = 0; // erreur sur analyse d une entite |
330 | Handle(Standard_Transient) anent; |
331 | try { |
332 | OCC_CATCH_SIGNALS |
333 | for (num = num0; num > 0; num = thereader->FindNextRecord(num)) { |
334 | num0 = num; |
335 | |
336 | // Lecture sous protection contre crash |
337 | // (fait aussi AddEntity mais pas SetReportEntity) |
338 | anent = LoadedEntity(num); |
339 | |
340 | // Lecture non protegee : utile pour travailler avec dbx |
341 | //// else |
342 | //// anent = LoadedEntity(num); |
343 | |
344 | // .. Fin Lecture .. |
345 | if (anent.IsNull()) { |
346 | // Sending of message : Number of ignored Null Entities |
347 | Message_Msg Msg21("XSTEP_21"); |
348 | Msg21.Arg(amodel->NbEntities()); |
349 | TF->Send (Msg21, Message_Info); |
350 | continue; |
351 | } |
352 | // LoadedEntity fait AddEntity MAIS PAS SetReport (en bloc a la fin) |
353 | |
354 | } // ---- fin boucle sur entites |
355 | num0 = 0; // plus rien |
356 | } // ---- fin du try, le catch suit |
357 | |
358 | // En cas d erreur NON PREVUE par l analyse, recuperation par defaut |
359 | // Attention : la recuperation peut elle-meme planter ... (cf ierr) |
360 | catch (Standard_Failure) { |
361 | // Au passage suivant, on attaquera le record suivant |
362 | num0 = thereader->FindNextRecord(num); //:g9 abv 28 May 98: tr8_as2_ug.stp - infinite cycle: (0); |
363 | |
364 | Handle(Standard_Failure) afail = Standard_Failure::Caught(); |
365 | #ifdef WNT |
366 | if (afail.IsNull() || afail->IsKind(STANDARD_TYPE(OSD_Exception))) ierr = 2; |
367 | #else |
368 | if (afail.IsNull() || afail->IsKind(STANDARD_TYPE(OSD_Signal))) ierr = 2; |
369 | #endif |
370 | //:abv 03Apr00: anent is actually a previous one: if (anent.IsNull()) |
371 | anent = thereader->BoundEntity(num); |
372 | if (anent.IsNull()) { |
373 | if (thetrace > 0) |
374 | { |
375 | // Sending of message : Number of ignored Null Entities |
376 | Message_Msg Msg21("XSTEP_21"); |
377 | Msg21.Arg(amodel->NbEntities()+1); |
378 | TF->Send (Msg21, Message_Info); |
379 | continue; |
380 | } |
381 | } |
382 | /*Handle(Interface_Check)*/ ach = new Interface_Check(anent); |
383 | //: abv 03 Apr 00: trj3_s1-tc-214.stp: generate a message on exception |
384 | Message_Msg Msg278("XSTEP_278"); |
385 | Msg278.Arg(amodel->StringLabel(anent)); |
386 | ach->SendFail (Msg278); |
387 | |
388 | if (ierr == 2) { |
389 | // Sending of message : reading of entity failed |
390 | Message_Msg Msg22("XSTEP_22"); |
391 | Msg22.Arg(amodel->StringLabel(anent)); |
392 | TF->Send (Msg22, Message_Info); |
393 | return; |
394 | } |
395 | |
396 | if (!ierr) { |
397 | //char mess[100]; svv #2 |
398 | ierr = 1; |
399 | // ce qui serait bien ici serait de recuperer le texte de l erreur pour ach ... |
400 | if (thetrace > 0) { |
401 | // Sending of message : recovered entity |
402 | Message_Msg Msg23("XSTEP_23"); |
403 | Msg23.Arg(num); |
404 | TF->Send (Msg23, Message_Info); |
405 | } |
406 | |
407 | // Finalement, on charge une Entite Inconnue |
408 | thenbreps ++; |
409 | Handle(Interface_ReportEntity) rep = |
410 | new Interface_ReportEntity(ach,anent); |
411 | Handle(Standard_Transient) undef = UnknownEntity(); |
412 | AnalyseRecord(num,undef,ach); |
413 | rep->SetContent(undef); |
414 | |
415 | if (thereports.IsNull()) thereports = |
416 | new TColStd_HArray1OfTransient (1,thereader->NbRecords()); |
417 | thenbreps ++; |
418 | thereports->SetValue (num,rep); |
419 | //if(isValid) |
420 | amodel->AddEntity (anent); // pas fait par LoadedEntity ... |
421 | } |
422 | else { |
423 | if (thetrace > 0) { |
424 | // Sending of message : reading of entity failed |
425 | Message_Msg Msg22("XSTEP_22"); |
426 | Msg22.Arg(amodel->StringLabel(anent)); |
427 | TF->Send (Msg22, Message_Info); |
428 | } |
429 | // On garde <rep> telle quelle : pas d analyse fichier supplementaire, |
430 | // Mais la phase preliminaire eventuelle est conservee |
431 | // (en particulier, on garde trace du Type lu du fichier, etc...) |
432 | } |
433 | } // ----- fin complete du try/catch |
434 | } // ----- fin du while |
435 | |
436 | // .. Ajout des Reports, silya |
437 | if (!thereports.IsNull()) { |
438 | if (thetrace > 0) |
439 | { |
440 | // Sending of message : report |
441 | Message_Msg Msg24("XSTEP_24"); |
442 | Msg24.Arg(thenbreps); |
443 | TF->Send (Msg24, Message_Info); |
444 | } |
445 | amodel->Reservate (-thenbreps-10); |
446 | thenbreps = thereports->Upper(); |
447 | for (Standard_Integer nr = 1; nr <= thenbreps; nr ++) { |
448 | if (thereports->Value(nr).IsNull()) continue; |
449 | Handle(Standard_Transient) anent = thereader->BoundEntity (nr); |
450 | Handle(Interface_ReportEntity) rep = |
451 | Handle(Interface_ReportEntity)::DownCast(thereports->Value(nr)); |
452 | amodel->SetReportEntity (-amodel->Number(anent),rep); |
453 | } |
454 | } |
455 | |
456 | // Conclusion : peut ne rien faire : selon necessite |
457 | if (theerrhand) { |
458 | try { |
459 | OCC_CATCH_SIGNALS |
460 | EndRead(amodel); // selon la norme |
461 | } |
462 | catch (Standard_Failure) { |
463 | // Sendinf of message : Internal error during the header reading |
464 | Message_Msg Msg11("XSTEP_11"); |
465 | TF->Send (Msg11, Message_Info); |
466 | } |
467 | } |
468 | else |
469 | EndRead(amodel); // selon la norme |
470 | } |
471 | |
472 | |
473 | //======================================================================= |
474 | //function : LoadedEntity |
475 | //purpose : |
476 | //======================================================================= |
477 | |
478 | Handle(Standard_Transient) Interface_FileReaderTool::LoadedEntity |
479 | (const Standard_Integer num) |
480 | { |
481 | Handle(Standard_Transient) anent = thereader->BoundEntity(num); |
482 | Handle(Interface_Check) ach = new Interface_Check(anent); |
483 | Handle(Interface_ReportEntity) rep; // entite Report, s il y a lieu |
484 | Standard_Integer irep = 0; |
485 | //Standard_Integer nbe = 0; svv #2 |
486 | if (thenbrep0 > 0) { |
487 | rep = Handle(Interface_ReportEntity)::DownCast(thereports->Value(num)); |
488 | if (!rep.IsNull()) { irep = num; ach = rep->Check(); } |
489 | } |
490 | |
491 | // Trace Entite Inconnue |
492 | if (thetrace >= 2 && theproto->IsUnknownEntity(anent)) { |
493 | Handle(Message_Messenger) TF = Messenger(); |
494 | Message_Msg Msg22("XSTEP_22"); |
495 | // Sending of message : reading of entity failed |
496 | Msg22.Arg(themodel->StringLabel(anent)->String()); |
497 | TF->Send (Msg22, Message_Info); |
498 | } |
499 | // .. Chargement proprement dit : Specifique de la Norme .. |
500 | AnalyseRecord(num,anent,ach); |
501 | |
502 | // .. Ajout dans le modele de l entite telle quelle .. |
503 | // ATTENTION, ReportEntity traitee en bloc apres les Load |
504 | themodel->AddEntity(anent); |
505 | |
506 | // Erreur ou Correction : On cree une ReportEntity qui memorise le Check, |
507 | // l Entite, et en cas d Erreur une UndefinedEntity pour les Parametres |
508 | |
509 | // On exploite ici le flag IsLoadError : s il a ete defini (a vrai ou faux) |
510 | // il a priorite sur les fails du check. Sinon, ce sont les fails qui parlent |
511 | |
512 | Standard_Integer nbf = ach->NbFails(); |
513 | Standard_Integer nbw = ach->NbWarnings(); |
514 | if (nbf + nbw > 0) { |
515 | //Standard_Integer n0; svv #2 |
516 | themodel->NbEntities(); |
517 | rep = new Interface_ReportEntity(ach,anent); |
518 | if (irep == 0) { |
519 | if (thereports.IsNull()) thereports = |
520 | new TColStd_HArray1OfTransient (1,thereader->NbRecords()); |
521 | irep = num; |
522 | thenbreps ++; |
523 | } |
524 | thereports->SetValue(irep,rep); |
525 | |
526 | if ( thetrace >= 2) |
527 | ach->Print (Messenger(),2); |
528 | } |
529 | |
530 | // Rechargement ? si oui, dans une UnknownEntity fournie par le protocole |
531 | if (thereader->IsErrorLoad()) nbf = (thereader->ResetErrorLoad() ? 1 : 0); |
532 | if (nbf > 0) { |
533 | Handle(Standard_Transient) undef = UnknownEntity(); |
534 | AnalyseRecord(num,undef,ach); |
535 | rep->SetContent(undef); |
536 | } |
537 | |
538 | // Conclusion (Unknown : traite en externe because traitement Raise) |
539 | //// if (irep > 0) themodel->SetReportEntity (nbe,rep); en bloc a la fin |
540 | |
541 | return anent; |
542 | } |
543 | |
544 | |
545 | //======================================================================= |
546 | //function : Destroy |
547 | //purpose : |
548 | //======================================================================= |
549 | |
550 | void Interface_FileReaderTool::Destroy(){} |
551 | |