summaryrefslogtreecommitdiff
path: root/src/StepFile/StepFile_Read.cxx
blob: 5b65127cd7fa06ef78e70e2d6a1e9d0c62d87ddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// File:	StepFile_Read.cxx
// Created:	Fri Aug 30 11:31:31 1991
// Author:	Christian CAILLET
//		<cky@phobox>

//   StepFile_Read

//   routine assurant l enchainement des operations de lecture d un fichier
//   STEP dans un StepModel, en fonction d une cle de reconnaissance
//   Retour de la fonction :
//     0 si OK  (le StepModel a ete charge)
//    -1 si abandon car fichier pas pu etre ouvert
//     1 si erreur en cours de lecture

//   Compilation conditionnelle : concerne les mesures de performances


#include <stdio.h>
#include "recfile.ph"
#include "stepread.ph"
extern "C" void recfile_modeprint (int mode);  // controle trace recfile
          // recfile_modeprint est declare a part

#include <Interface_ParamType.hxx>
#include <Interface_Protocol.hxx>
#include <Interface_Check.hxx>
#include <StepData_Protocol.hxx>

#include <StepData_StepReaderData.hxx>
#include <StepData_StepReaderTool.hxx>
#include <StepFile_Read.hxx>

#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Interface_InterfaceError.hxx>

#include <Message_Messenger.hxx>
#include <Message.hxx>

#define CHRONOMESURE
#ifdef CHRONOMESURE
# include <OSD_Timer.hxx>
#endif

//  ##  ##  ##  ##    ON SAURA AU MOINS TRAITER UndefinedEntity  ##  ##  ##  ##

static Handle(Interface_Check) checkread = new Interface_Check;
static Standard_Integer modepr = 1;

void StepFile_ReadTrace (const Standard_Integer mode)
{
  modepr = mode;   // recfile_modeprint est rappele a chaque lecture de fichier
}


static Standard_Integer StepFile_Read
 (char* nomfic,
  const Handle(StepData_StepModel)& stepmodel,
  const Handle(StepData_Protocol)& protocol,
  const Handle(StepData_FileRecognizer)& recoheader,
  const Handle(StepData_FileRecognizer)& recodata);


Standard_Integer StepFile_Read
 (char* nomfic,
  const Handle(StepData_StepModel)& stepmodel,
  const Handle(StepData_FileRecognizer)& recoheader,
  const Handle(StepData_FileRecognizer)& recodata)
{
  return StepFile_Read
    (nomfic,stepmodel,
     Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()),
     recoheader,recodata);
}

Standard_Integer StepFile_Read
 (char* nomfic,
  const Handle(StepData_StepModel)& stepmodel,
  const Handle(StepData_FileRecognizer)& recoheader,
  const Handle(StepData_Protocol)& protocol)
{
  Handle(StepData_FileRecognizer) nulreco;
  return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco);
}

Standard_Integer StepFile_Read
 (char* nomfic,
  const Handle(StepData_StepModel)& stepmodel,
  const Handle(StepData_Protocol)& protocol)
{
  Handle(StepData_FileRecognizer) nulreco;
  return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco);
}

//  ##  ##  ##  ##  ##  ##    Corps de la Routine    ##  ##  ##  ##  ##  ##

static Interface_ParamType LesTypes[10];   // passage types (recstep/Interface)

Standard_Integer StepFile_Read
 (char* nomfic,
  const Handle(StepData_StepModel)& stepmodel,
  const Handle(StepData_Protocol)& protocol,
  const Handle(StepData_FileRecognizer)& recoheader,
  const Handle(StepData_FileRecognizer)& recodata)

{
  Handle(Message_Messenger) sout = Message::DefaultMessenger();
  char *ficnom = nomfic ;  // because const (non reconnu par C)

  checkread->Clear();
  recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
  FILE* newin = stepread_setinput(ficnom);
  if (!newin) return -1;
#ifdef CHRONOMESURE
  Standard_Integer n ; 
  OSD_Timer c ; 
  c.Reset () ; 
  c.Start();
  sout << "      ...    Step File Reading : " << ficnom << "" << endl;  
#endif

  try {
    OCC_CATCH_SIGNALS
    if (stepread () != 0) {  lir_file_fin(3);  stepread_endinput (newin,ficnom);  return 1;  }
  }
  catch (Standard_Failure) {
    sout << " ...  Exception Raised while reading Step File : " << ficnom << ":\n" << endl;
    sout << Standard_Failure::Caught()->GetMessageString();  
    sout << "    ..." << endl;
    lir_file_fin(3);  
    stepread_endinput (newin,ficnom);  
    return 1;
  }
  // Continue reading of file despite of possible fails
  //if (checkread->HasFailed()) {  lir_file_fin(3);  stepread_endinput (newin,ficnom);  return 1;  }
#ifdef CHRONOMESURE
  sout << "      ...    STEP File   Read    ... " << endl;  
  c.Show(); 
#endif


//  Creation du StepReaderData

  LesTypes[rec_argNondef]    = Interface_ParamVoid ;
  LesTypes[rec_argSub]       = Interface_ParamSub ;
  LesTypes[rec_argIdent]     = Interface_ParamIdent ;
  LesTypes[rec_argInteger]   = Interface_ParamInteger ;
  LesTypes[rec_argFloat]     = Interface_ParamReal ;
  LesTypes[rec_argEnum]      = Interface_ParamEnum ;
  LesTypes[rec_argBinary]    = Interface_ParamBinary ;
  LesTypes[rec_argText]      = Interface_ParamText ;
  LesTypes[rec_argHexa]      = Interface_ParamHexa ;
  LesTypes[rec_argMisc]      = Interface_ParamMisc ;

  Standard_Integer nbhead, nbrec, nbpar;
  lir_file_nbr (&nbhead,&nbrec,&nbpar);  // renvoi par lex/yacc
  Handle(StepData_StepReaderData) undirec =
    new StepData_StepReaderData(nbhead,nbrec,nbpar);  // creation tableau de records

  for ( Standard_Integer nr = 1; nr <= nbrec; nr ++) {
    int nbarg; char* ident; char* typrec ;
    lir_file_rec (&ident, &typrec, &nbarg);
    undirec->SetRecord (nr, ident, typrec, nbarg);

    if (nbarg>0) {
      int typa; char* val;
      Interface_ParamType newtype;
      while(lir_file_arg (&typa, &val) == 1) {
        newtype = LesTypes[typa] ;
        undirec->AddStepParam (nr, val, newtype);
      }
    }
    undirec->InitParams(nr);
    lir_file_finrec();
  }
  lir_file_fin(1);
//  on a undirec pret pour la suite

#ifdef CHRONOMESURE
  sout << "      ... Step File loaded  ... " << endl; 
  c.Show();
  sout << "   "<< undirec->NbRecords () <<
      " records (entities,sub-lists,scopes), "<< nbpar << " parameters\n" << endl;
#endif

//   Analyse : par StepReaderTool

  StepData_StepReaderTool readtool (undirec,protocol);
  readtool.SetErrorHandle (Standard_True);

  readtool.PrepareHeader(recoheader);  // Header. reco nul -> pour Protocol
  readtool.Prepare(recodata);          // Data.   reco nul -> pour Protocol
#ifdef CHRONOMESURE
  sout << "      ... Parameters prepared ... "; 
  c.Show(); 
#endif

  readtool.LoadModel(stepmodel);
  if (stepmodel->Protocol().IsNull()) stepmodel->SetProtocol (protocol);
  lir_file_fin(2);
#ifdef CHRONOMESURE
  sout << "      ...   Objets analysed  ... " << endl; 
  c.Show();
  n = stepmodel->NbEntities() ;
  sout << "  STEP Loading done : " << n << " Entities" << endl;
#endif

  stepread_endinput (newin,ficnom);  return 0 ;
}

void StepFile_Interrupt (char* mess)
{
  Handle(Message_Messenger) sout = Message::DefaultMessenger();
  sout << "    ****    StepFile Error : " << mess << "    ****" << endl;
  checkread->AddFail(mess);
}