0027960: Configuration - fix compilation of OSD_Directory with MinGW-w64
[occt.git] / src / StepFile / StepFile_Read.cxx
CommitLineData
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//
d5f74e42 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
973c2be1 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"
32extern "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
0797d9d3 51#ifdef OCCT_DEBUG
7fd59977 52#define CHRONOMESURE
53#ifdef CHRONOMESURE
54# include <OSD_Timer.hxx>
55#endif
0797d9d3 56#endif
7fd59977 57
58// ## ## ## ## ON SAURA AU MOINS TRAITER UndefinedEntity ## ## ## ##
59
60static Handle(Interface_Check) checkread = new Interface_Check;
61static Standard_Integer modepr = 1;
62
63void StepFile_ReadTrace (const Standard_Integer mode)
64{
65 modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier
66}
67
68
69static Standard_Integer StepFile_Read
70 (char* nomfic,
71 const Handle(StepData_StepModel)& stepmodel,
72 const Handle(StepData_Protocol)& protocol,
73 const Handle(StepData_FileRecognizer)& recoheader,
74 const Handle(StepData_FileRecognizer)& recodata);
75
76
77Standard_Integer StepFile_Read
78 (char* nomfic,
79 const Handle(StepData_StepModel)& stepmodel,
80 const Handle(StepData_FileRecognizer)& recoheader,
81 const Handle(StepData_FileRecognizer)& recodata)
82{
83 return StepFile_Read
84 (nomfic,stepmodel,
85 Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()),
86 recoheader,recodata);
87}
88
89Standard_Integer StepFile_Read
90 (char* nomfic,
91 const Handle(StepData_StepModel)& stepmodel,
92 const Handle(StepData_FileRecognizer)& recoheader,
93 const Handle(StepData_Protocol)& protocol)
94{
95 Handle(StepData_FileRecognizer) nulreco;
96 return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco);
97}
98
99Standard_Integer StepFile_Read
100 (char* nomfic,
101 const Handle(StepData_StepModel)& stepmodel,
102 const Handle(StepData_Protocol)& protocol)
103{
104 Handle(StepData_FileRecognizer) nulreco;
105 return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco);
106}
107
108// ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ##
109
110static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface)
111
112Standard_Integer StepFile_Read
113 (char* nomfic,
114 const Handle(StepData_StepModel)& stepmodel,
115 const Handle(StepData_Protocol)& protocol,
116 const Handle(StepData_FileRecognizer)& recoheader,
117 const Handle(StepData_FileRecognizer)& recodata)
118
119{
120 Handle(Message_Messenger) sout = Message::DefaultMessenger();
121 char *ficnom = nomfic ; // because const (non reconnu par C)
122
123 checkread->Clear();
124 recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
125 FILE* newin = stepread_setinput(ficnom);
126 if (!newin) return -1;
127#ifdef CHRONOMESURE
128 Standard_Integer n ;
129 OSD_Timer c ;
130 c.Reset () ;
131 c.Start();
132 sout << " ... Step File Reading : " << ficnom << "" << endl;
133#endif
134
135 try {
136 OCC_CATCH_SIGNALS
137 if (stepread () != 0) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
138 }
139 catch (Standard_Failure) {
0797d9d3 140#ifdef OCCT_DEBUG
7fd59977 141 sout << " ... Exception Raised while reading Step File : " << ficnom << ":\n" << endl;
142 sout << Standard_Failure::Caught()->GetMessageString();
143 sout << " ..." << endl;
0797d9d3 144#endif
7fd59977 145 lir_file_fin(3);
146 stepread_endinput (newin,ficnom);
147 return 1;
148 }
149 // Continue reading of file despite of possible fails
150 //if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
151#ifdef CHRONOMESURE
152 sout << " ... STEP File Read ... " << endl;
153 c.Show();
154#endif
155
156
157// Creation du StepReaderData
158
159 LesTypes[rec_argNondef] = Interface_ParamVoid ;
160 LesTypes[rec_argSub] = Interface_ParamSub ;
161 LesTypes[rec_argIdent] = Interface_ParamIdent ;
162 LesTypes[rec_argInteger] = Interface_ParamInteger ;
163 LesTypes[rec_argFloat] = Interface_ParamReal ;
164 LesTypes[rec_argEnum] = Interface_ParamEnum ;
165 LesTypes[rec_argBinary] = Interface_ParamBinary ;
166 LesTypes[rec_argText] = Interface_ParamText ;
167 LesTypes[rec_argHexa] = Interface_ParamHexa ;
168 LesTypes[rec_argMisc] = Interface_ParamMisc ;
169
170 Standard_Integer nbhead, nbrec, nbpar;
171 lir_file_nbr (&nbhead,&nbrec,&nbpar); // renvoi par lex/yacc
172 Handle(StepData_StepReaderData) undirec =
173 new StepData_StepReaderData(nbhead,nbrec,nbpar); // creation tableau de records
174
175 for ( Standard_Integer nr = 1; nr <= nbrec; nr ++) {
c7854818 176 int nbarg; char* ident; char* typrec = 0;
7fd59977 177 lir_file_rec (&ident, &typrec, &nbarg);
178 undirec->SetRecord (nr, ident, typrec, nbarg);
179
180 if (nbarg>0) {
181 int typa; char* val;
182 Interface_ParamType newtype;
183 while(lir_file_arg (&typa, &val) == 1) {
184 newtype = LesTypes[typa] ;
185 undirec->AddStepParam (nr, val, newtype);
186 }
187 }
188 undirec->InitParams(nr);
189 lir_file_finrec();
190 }
191 lir_file_fin(1);
192// on a undirec pret pour la suite
193
194#ifdef CHRONOMESURE
195 sout << " ... Step File loaded ... " << endl;
196 c.Show();
197 sout << " "<< undirec->NbRecords () <<
198 " records (entities,sub-lists,scopes), "<< nbpar << " parameters\n" << endl;
199#endif
200
201// Analyse : par StepReaderTool
202
203 StepData_StepReaderTool readtool (undirec,protocol);
204 readtool.SetErrorHandle (Standard_True);
205
206 readtool.PrepareHeader(recoheader); // Header. reco nul -> pour Protocol
207 readtool.Prepare(recodata); // Data. reco nul -> pour Protocol
bc650d41 208
7fd59977 209#ifdef CHRONOMESURE
210 sout << " ... Parameters prepared ... ";
211 c.Show();
212#endif
213
214 readtool.LoadModel(stepmodel);
215 if (stepmodel->Protocol().IsNull()) stepmodel->SetProtocol (protocol);
216 lir_file_fin(2);
bc650d41
G
217
218 readtool.Clear();
219 undirec.Nullify();
7fd59977 220#ifdef CHRONOMESURE
221 sout << " ... Objets analysed ... " << endl;
222 c.Show();
223 n = stepmodel->NbEntities() ;
224 sout << " STEP Loading done : " << n << " Entities" << endl;
225#endif
bc650d41 226
7fd59977 227 stepread_endinput (newin,ficnom); return 0 ;
228}
229
230void StepFile_Interrupt (char* mess)
231{
0797d9d3 232#ifdef OCCT_DEBUG
7fd59977 233 Handle(Message_Messenger) sout = Message::DefaultMessenger();
234 sout << " **** StepFile Error : " << mess << " ****" << endl;
0797d9d3 235#endif
7fd59977 236 checkread->AddFail(mess);
237}