Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1991-08-30 |
2 | // Created by: Christian CAILLET | |
3 | // Copyright (c) 1991-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
973c2be1 | 8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
10 | // by the Free Software Foundation, with special exception defined in the file | |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | // StepFile_Read | |
18 | ||
19 | // routine assurant l enchainement des operations de lecture d un fichier | |
20 | // STEP dans un StepModel, en fonction d une cle de reconnaissance | |
21 | // Retour de la fonction : | |
22 | // 0 si OK (le StepModel a ete charge) | |
23 | // -1 si abandon car fichier pas pu etre ouvert | |
24 | // 1 si erreur en cours de lecture | |
25 | ||
26 | // Compilation conditionnelle : concerne les mesures de performances | |
27 | ||
28 | ||
29 | #include <stdio.h> | |
30 | #include "recfile.ph" | |
31 | #include "stepread.ph" | |
32 | extern "C" void recfile_modeprint (int mode); // controle trace recfile | |
33 | // recfile_modeprint est declare a part | |
34 | ||
35 | #include <Interface_ParamType.hxx> | |
36 | #include <Interface_Protocol.hxx> | |
37 | #include <Interface_Check.hxx> | |
38 | #include <StepData_Protocol.hxx> | |
39 | ||
40 | #include <StepData_StepReaderData.hxx> | |
41 | #include <StepData_StepReaderTool.hxx> | |
42 | #include <StepFile_Read.hxx> | |
43 | ||
44 | #include <Standard_ErrorHandler.hxx> | |
45 | #include <Standard_Failure.hxx> | |
46 | #include <Interface_InterfaceError.hxx> | |
47 | ||
48 | #include <Message_Messenger.hxx> | |
49 | #include <Message.hxx> | |
50 | ||
51 | #define CHRONOMESURE | |
52 | #ifdef CHRONOMESURE | |
53 | # include <OSD_Timer.hxx> | |
54 | #endif | |
55 | ||
56 | // ## ## ## ## ON SAURA AU MOINS TRAITER UndefinedEntity ## ## ## ## | |
57 | ||
58 | static Handle(Interface_Check) checkread = new Interface_Check; | |
59 | static Standard_Integer modepr = 1; | |
60 | ||
61 | void StepFile_ReadTrace (const Standard_Integer mode) | |
62 | { | |
63 | modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier | |
64 | } | |
65 | ||
66 | ||
67 | static Standard_Integer StepFile_Read | |
68 | (char* nomfic, | |
69 | const Handle(StepData_StepModel)& stepmodel, | |
70 | const Handle(StepData_Protocol)& protocol, | |
71 | const Handle(StepData_FileRecognizer)& recoheader, | |
72 | const Handle(StepData_FileRecognizer)& recodata); | |
73 | ||
74 | ||
75 | Standard_Integer StepFile_Read | |
76 | (char* nomfic, | |
77 | const Handle(StepData_StepModel)& stepmodel, | |
78 | const Handle(StepData_FileRecognizer)& recoheader, | |
79 | const Handle(StepData_FileRecognizer)& recodata) | |
80 | { | |
81 | return StepFile_Read | |
82 | (nomfic,stepmodel, | |
83 | Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()), | |
84 | recoheader,recodata); | |
85 | } | |
86 | ||
87 | Standard_Integer StepFile_Read | |
88 | (char* nomfic, | |
89 | const Handle(StepData_StepModel)& stepmodel, | |
90 | const Handle(StepData_FileRecognizer)& recoheader, | |
91 | const Handle(StepData_Protocol)& protocol) | |
92 | { | |
93 | Handle(StepData_FileRecognizer) nulreco; | |
94 | return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco); | |
95 | } | |
96 | ||
97 | Standard_Integer StepFile_Read | |
98 | (char* nomfic, | |
99 | const Handle(StepData_StepModel)& stepmodel, | |
100 | const Handle(StepData_Protocol)& protocol) | |
101 | { | |
102 | Handle(StepData_FileRecognizer) nulreco; | |
103 | return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco); | |
104 | } | |
105 | ||
106 | // ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ## | |
107 | ||
108 | static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface) | |
109 | ||
110 | Standard_Integer StepFile_Read | |
111 | (char* nomfic, | |
112 | const Handle(StepData_StepModel)& stepmodel, | |
113 | const Handle(StepData_Protocol)& protocol, | |
114 | const Handle(StepData_FileRecognizer)& recoheader, | |
115 | const Handle(StepData_FileRecognizer)& recodata) | |
116 | ||
117 | { | |
118 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); | |
119 | char *ficnom = nomfic ; // because const (non reconnu par C) | |
120 | ||
121 | checkread->Clear(); | |
122 | recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) ); | |
123 | FILE* newin = stepread_setinput(ficnom); | |
124 | if (!newin) return -1; | |
125 | #ifdef CHRONOMESURE | |
126 | Standard_Integer n ; | |
127 | OSD_Timer c ; | |
128 | c.Reset () ; | |
129 | c.Start(); | |
130 | sout << " ... Step File Reading : " << ficnom << "" << endl; | |
131 | #endif | |
132 | ||
133 | try { | |
134 | OCC_CATCH_SIGNALS | |
135 | if (stepread () != 0) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; } | |
136 | } | |
137 | catch (Standard_Failure) { | |
138 | sout << " ... Exception Raised while reading Step File : " << ficnom << ":\n" << endl; | |
139 | sout << Standard_Failure::Caught()->GetMessageString(); | |
140 | sout << " ..." << endl; | |
141 | lir_file_fin(3); | |
142 | stepread_endinput (newin,ficnom); | |
143 | return 1; | |
144 | } | |
145 | // Continue reading of file despite of possible fails | |
146 | //if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; } | |
147 | #ifdef CHRONOMESURE | |
148 | sout << " ... STEP File Read ... " << endl; | |
149 | c.Show(); | |
150 | #endif | |
151 | ||
152 | ||
153 | // Creation du StepReaderData | |
154 | ||
155 | LesTypes[rec_argNondef] = Interface_ParamVoid ; | |
156 | LesTypes[rec_argSub] = Interface_ParamSub ; | |
157 | LesTypes[rec_argIdent] = Interface_ParamIdent ; | |
158 | LesTypes[rec_argInteger] = Interface_ParamInteger ; | |
159 | LesTypes[rec_argFloat] = Interface_ParamReal ; | |
160 | LesTypes[rec_argEnum] = Interface_ParamEnum ; | |
161 | LesTypes[rec_argBinary] = Interface_ParamBinary ; | |
162 | LesTypes[rec_argText] = Interface_ParamText ; | |
163 | LesTypes[rec_argHexa] = Interface_ParamHexa ; | |
164 | LesTypes[rec_argMisc] = Interface_ParamMisc ; | |
165 | ||
166 | Standard_Integer nbhead, nbrec, nbpar; | |
167 | lir_file_nbr (&nbhead,&nbrec,&nbpar); // renvoi par lex/yacc | |
168 | Handle(StepData_StepReaderData) undirec = | |
169 | new StepData_StepReaderData(nbhead,nbrec,nbpar); // creation tableau de records | |
170 | ||
171 | for ( Standard_Integer nr = 1; nr <= nbrec; nr ++) { | |
172 | int nbarg; char* ident; char* typrec ; | |
173 | lir_file_rec (&ident, &typrec, &nbarg); | |
174 | undirec->SetRecord (nr, ident, typrec, nbarg); | |
175 | ||
176 | if (nbarg>0) { | |
177 | int typa; char* val; | |
178 | Interface_ParamType newtype; | |
179 | while(lir_file_arg (&typa, &val) == 1) { | |
180 | newtype = LesTypes[typa] ; | |
181 | undirec->AddStepParam (nr, val, newtype); | |
182 | } | |
183 | } | |
184 | undirec->InitParams(nr); | |
185 | lir_file_finrec(); | |
186 | } | |
187 | lir_file_fin(1); | |
188 | // on a undirec pret pour la suite | |
189 | ||
190 | #ifdef CHRONOMESURE | |
191 | sout << " ... Step File loaded ... " << endl; | |
192 | c.Show(); | |
193 | sout << " "<< undirec->NbRecords () << | |
194 | " records (entities,sub-lists,scopes), "<< nbpar << " parameters\n" << endl; | |
195 | #endif | |
196 | ||
197 | // Analyse : par StepReaderTool | |
198 | ||
199 | StepData_StepReaderTool readtool (undirec,protocol); | |
200 | readtool.SetErrorHandle (Standard_True); | |
201 | ||
202 | readtool.PrepareHeader(recoheader); // Header. reco nul -> pour Protocol | |
203 | readtool.Prepare(recodata); // Data. reco nul -> pour Protocol | |
bc650d41 | 204 | |
7fd59977 | 205 | #ifdef CHRONOMESURE |
206 | sout << " ... Parameters prepared ... "; | |
207 | c.Show(); | |
208 | #endif | |
209 | ||
210 | readtool.LoadModel(stepmodel); | |
211 | if (stepmodel->Protocol().IsNull()) stepmodel->SetProtocol (protocol); | |
212 | lir_file_fin(2); | |
bc650d41 G |
213 | |
214 | readtool.Clear(); | |
215 | undirec.Nullify(); | |
7fd59977 | 216 | #ifdef CHRONOMESURE |
217 | sout << " ... Objets analysed ... " << endl; | |
218 | c.Show(); | |
219 | n = stepmodel->NbEntities() ; | |
220 | sout << " STEP Loading done : " << n << " Entities" << endl; | |
221 | #endif | |
bc650d41 | 222 | |
7fd59977 | 223 | stepread_endinput (newin,ficnom); return 0 ; |
224 | } | |
225 | ||
226 | void StepFile_Interrupt (char* mess) | |
227 | { | |
228 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); | |
229 | sout << " **** StepFile Error : " << mess << " ****" << endl; | |
230 | checkread->AddFail(mess); | |
231 | } |