1 // Created on: 1991-08-30
2 // Created by: Christian CAILLET
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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
26 // Compilation conditionnelle : concerne les mesures de performances
31 #include "stepread.ph"
32 extern "C" void recfile_modeprint (int mode); // controle trace recfile
33 // recfile_modeprint est declare a part
35 #include <Interface_ParamType.hxx>
36 #include <Interface_Protocol.hxx>
37 #include <Interface_Check.hxx>
38 #include <StepData_Protocol.hxx>
40 #include <StepData_StepReaderData.hxx>
41 #include <StepData_StepReaderTool.hxx>
42 #include <StepFile_Read.hxx>
44 #include <Standard_ErrorHandler.hxx>
45 #include <Standard_Failure.hxx>
46 #include <Interface_InterfaceError.hxx>
48 #include <Message_Messenger.hxx>
49 #include <Message.hxx>
54 # include <OSD_Timer.hxx>
58 // ## ## ## ## ON SAURA AU MOINS TRAITER UndefinedEntity ## ## ## ##
60 static Handle(Interface_Check) checkread = new Interface_Check;
61 static Standard_Integer modepr = 1;
63 void StepFile_ReadTrace (const Standard_Integer mode)
65 modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier
69 static Standard_Integer StepFile_Read
71 const Handle(StepData_StepModel)& stepmodel,
72 const Handle(StepData_Protocol)& protocol,
73 const Handle(StepData_FileRecognizer)& recoheader,
74 const Handle(StepData_FileRecognizer)& recodata);
77 Standard_Integer StepFile_Read
79 const Handle(StepData_StepModel)& stepmodel,
80 const Handle(StepData_FileRecognizer)& recoheader,
81 const Handle(StepData_FileRecognizer)& recodata)
85 Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()),
89 Standard_Integer StepFile_Read
91 const Handle(StepData_StepModel)& stepmodel,
92 const Handle(StepData_FileRecognizer)& recoheader,
93 const Handle(StepData_Protocol)& protocol)
95 Handle(StepData_FileRecognizer) nulreco;
96 return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco);
99 Standard_Integer StepFile_Read
101 const Handle(StepData_StepModel)& stepmodel,
102 const Handle(StepData_Protocol)& protocol)
104 Handle(StepData_FileRecognizer) nulreco;
105 return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco);
108 // ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ##
110 static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface)
112 Standard_Integer StepFile_Read
114 const Handle(StepData_StepModel)& stepmodel,
115 const Handle(StepData_Protocol)& protocol,
116 const Handle(StepData_FileRecognizer)& recoheader,
117 const Handle(StepData_FileRecognizer)& recodata)
120 Handle(Message_Messenger) sout = Message::DefaultMessenger();
121 char *ficnom = nomfic ; // because const (non reconnu par C)
124 recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
125 FILE* newin = stepread_setinput(ficnom);
126 if (!newin) return -1;
132 sout << " ... Step File Reading : " << ficnom << "" << Message_EndLine;
137 if (stepread () != 0) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
139 catch (Standard_Failure const& anException) {
141 sout << " ... Exception Raised while reading Step File : " << ficnom << ":\n" << Message_EndLine;
142 sout << anException.GetMessageString();
143 sout << " ..." << Message_EndLine;
147 stepread_endinput (newin,ficnom);
150 // Continue reading of file despite of possible fails
151 //if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
153 sout << " ... STEP File Read ... " << Message_EndLine;
158 // Creation du StepReaderData
160 LesTypes[rec_argNondef] = Interface_ParamVoid ;
161 LesTypes[rec_argSub] = Interface_ParamSub ;
162 LesTypes[rec_argIdent] = Interface_ParamIdent ;
163 LesTypes[rec_argInteger] = Interface_ParamInteger ;
164 LesTypes[rec_argFloat] = Interface_ParamReal ;
165 LesTypes[rec_argEnum] = Interface_ParamEnum ;
166 LesTypes[rec_argBinary] = Interface_ParamBinary ;
167 LesTypes[rec_argText] = Interface_ParamText ;
168 LesTypes[rec_argHexa] = Interface_ParamHexa ;
169 LesTypes[rec_argMisc] = Interface_ParamMisc ;
171 Standard_Integer nbhead, nbrec, nbpar;
172 lir_file_nbr (&nbhead,&nbrec,&nbpar); // renvoi par lex/yacc
173 Handle(StepData_StepReaderData) undirec =
174 new StepData_StepReaderData(nbhead,nbrec,nbpar); // creation tableau de records
176 for ( Standard_Integer nr = 1; nr <= nbrec; nr ++) {
177 int nbarg; char* ident; char* typrec = 0;
178 lir_file_rec (&ident, &typrec, &nbarg);
179 undirec->SetRecord (nr, ident, typrec, nbarg);
183 Interface_ParamType newtype;
184 while(lir_file_arg (&typa, &val) == 1) {
185 newtype = LesTypes[typa] ;
186 undirec->AddStepParam (nr, val, newtype);
189 undirec->InitParams(nr);
193 // on a undirec pret pour la suite
196 sout << " ... Step File loaded ... " << Message_EndLine;
198 sout << " "<< undirec->NbRecords () <<
199 " records (entities,sub-lists,scopes), "<< nbpar << " parameters\n" << Message_EndLine;
202 // Analyse : par StepReaderTool
204 StepData_StepReaderTool readtool (undirec,protocol);
205 readtool.SetErrorHandle (Standard_True);
207 readtool.PrepareHeader(recoheader); // Header. reco nul -> pour Protocol
208 readtool.Prepare(recodata); // Data. reco nul -> pour Protocol
211 sout << " ... Parameters prepared ... ";
215 readtool.LoadModel(stepmodel);
216 if (stepmodel->Protocol().IsNull()) stepmodel->SetProtocol (protocol);
222 sout << " ... Objets analysed ... " << Message_EndLine;
224 n = stepmodel->NbEntities() ;
225 sout << " STEP Loading done : " << n << " Entities" << Message_EndLine;
228 stepread_endinput (newin,ficnom); return 0 ;
231 void StepFile_Interrupt (char* mess)
234 Handle(Message_Messenger) sout = Message::DefaultMessenger();
235 sout << " **** StepFile Error : " << mess << " ****" << Message_EndLine;
237 checkread->AddFail(mess);