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"
33 #include <Interface_ParamType.hxx>
34 #include <Interface_Protocol.hxx>
35 #include <Interface_Check.hxx>
36 #include <StepData_Protocol.hxx>
38 #include <StepData_StepReaderData.hxx>
39 #include <StepData_StepReaderTool.hxx>
40 #include <StepFile_Read.hxx>
42 #include <Standard_ErrorHandler.hxx>
43 #include <Standard_Failure.hxx>
44 #include <Interface_InterfaceError.hxx>
46 #include <Message_Messenger.hxx>
47 #include <Message.hxx>
49 #include <OSD_OpenFile.hxx>
50 #include <OSD_Timer.hxx>
56 // ## ## ## ## ON SAURA AU MOINS TRAITER UndefinedEntity ## ## ## ##
58 extern "C" void recfile_modeprint (int mode); // controle trace recfile
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
68 // ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ##
70 static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface)
72 static Standard_Integer StepFile_Read (const char* theName,
73 std::istream* theIStream,
74 const Handle(StepData_StepModel)& stepmodel,
75 const Handle(StepData_Protocol)& protocol,
76 const Handle(StepData_FileRecognizer)& recoheader,
77 const Handle(StepData_FileRecognizer)& recodata)
80 recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
82 // if stream is not provided, open file stream here
83 std::istream *aStreamPtr = theIStream;
84 std::ifstream aFileStream;
86 OSD_OpenStream(aFileStream, theName, std::ios_base::in | std::ios_base::binary);
87 aStreamPtr = &aFileStream;
90 if (aStreamPtr->bad())
99 Message::SendInfo() << " ... Step File Reading : '" << theName << "'";
104 if (stepread(*aStreamPtr) != 0) {
109 catch (Standard_Failure const& anException) {
111 Message::SendAlarm() << " ... Exception Raised while reading Step File : '" << theName << "':\n"
112 << anException.GetMessageString()
120 // Continue reading of file despite of possible fails
121 // if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput(newifstream, ficnom); return 1; }
124 Message_Messenger::StreamBuffer sout = Message::SendInfo();
125 sout << " ... STEP File Read ...\n";
130 // Creation du StepReaderData
132 LesTypes[rec_argNondef] = Interface_ParamVoid ;
133 LesTypes[rec_argSub] = Interface_ParamSub ;
134 LesTypes[rec_argIdent] = Interface_ParamIdent ;
135 LesTypes[rec_argInteger] = Interface_ParamInteger ;
136 LesTypes[rec_argFloat] = Interface_ParamReal ;
137 LesTypes[rec_argEnum] = Interface_ParamEnum ;
138 LesTypes[rec_argBinary] = Interface_ParamBinary ;
139 LesTypes[rec_argText] = Interface_ParamText ;
140 LesTypes[rec_argHexa] = Interface_ParamHexa ;
141 LesTypes[rec_argMisc] = Interface_ParamMisc ;
143 Standard_Integer nbhead, nbrec, nbpar;
144 lir_file_nbr (&nbhead,&nbrec,&nbpar); // renvoi par lex/yacc
145 Handle(StepData_StepReaderData) undirec =
146 new StepData_StepReaderData(nbhead,nbrec,nbpar); // creation tableau de records
148 for ( Standard_Integer nr = 1; nr <= nbrec; nr ++) {
149 int nbarg; char* ident; char* typrec = 0;
150 lir_file_rec (&ident, &typrec, &nbarg);
151 undirec->SetRecord (nr, ident, typrec, nbarg);
155 Interface_ParamType newtype;
156 while(lir_file_arg (&typa, &val) == 1) {
157 newtype = LesTypes[typa] ;
158 undirec->AddStepParam (nr, val, newtype);
161 undirec->InitParams(nr);
165 // on a undirec pret pour la suite
169 Message_Messenger::StreamBuffer sout = Message::SendInfo();
170 sout << " ... Step File loaded ...\n";
172 sout << " "<< undirec->NbRecords() << " records (entities,sub-lists,scopes), "<< nbpar << " parameters";
176 // Analyse : par StepReaderTool
178 StepData_StepReaderTool readtool (undirec,protocol);
179 readtool.SetErrorHandle (Standard_True);
181 readtool.PrepareHeader(recoheader); // Header. reco nul -> pour Protocol
182 readtool.Prepare(recodata); // Data. reco nul -> pour Protocol
186 Message_Messenger::StreamBuffer sout = Message::SendInfo();
187 sout << " ... Parameters prepared ...\n";
192 readtool.LoadModel(stepmodel);
193 if (stepmodel->Protocol().IsNull()) stepmodel->SetProtocol (protocol);
200 Message_Messenger::StreamBuffer sout = Message::SendInfo();
201 sout << " ... Objets analysed ...\n";
203 Standard_Integer n = stepmodel->NbEntities();
204 sout << " STEP Loading done : " << n << " Entities";
210 Standard_Integer StepFile_Read(const char* theName,
211 std::istream* theIStream,
212 const Handle(StepData_StepModel)& stepmodel,
213 const Handle(StepData_Protocol)& protocol)
215 Handle(StepData_FileRecognizer) nulreco;
216 return StepFile_Read (theName,theIStream,stepmodel,protocol,nulreco,nulreco);
219 void StepFile_Interrupt (char* mess)
222 Message_Messenger::StreamBuffer sout = Message::SendInfo();
223 sout << " **** StepFile Error : " << mess << " ****" << std::endl;
225 checkread->AddFail(mess);