1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 // dce 21.01.99 : move of general message to IGESToBRep_Reader
17 // declarations des programmes C de base :
18 #include <IGESData_IGESReaderData.hxx>
19 #include <IGESData_IGESReaderTool.hxx>
20 #include <IGESData_GeneralModule.hxx>
21 #include <Interface_Check.hxx>
23 // Pour traiter les exceptions :
24 #include <Standard_ErrorHandler.hxx>
25 #include <Standard_Failure.hxx>
27 // definition de base, a inclure pour utiliser
28 #include <IGESFile_Read.hxx>
36 #include <Message_Msg.hxx>
38 // decoupage interne pour faciliter les recuperations d erreurs
39 static Standard_Integer recupne,recupnp; // pour affichage en cas de pepin
40 static Handle(Interface_Check)& checkread()
42 static Handle(Interface_Check) chrd = new Interface_Check;
46 static void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR);
47 static void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR);
48 void IGESFile_Check (int mode,Message_Msg& amsg);
49 // void IGESFile_Check2 (int mode,char * code, int num, char * str);
50 // void IGESFile_Check3 (int mode,char * code);
52 // Correspondance entre types igesread et types Interface_ParamFile ...
53 static Interface_ParamType LesTypes[10];
56 // Nouvelle maniere : Protocol suffit
58 Standard_Integer IGESFile_Read
60 const Handle(IGESData_IGESModel)& amodel,
61 const Handle(IGESData_Protocol)& protocol)
63 Handle(IGESData_FileRecognizer) nulreco;
64 return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_False);
67 Standard_Integer IGESFile_ReadFNES
69 const Handle(IGESData_IGESModel)& amodel,
70 const Handle(IGESData_Protocol)& protocol)
72 Handle(IGESData_FileRecognizer) nulreco;
73 return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_True);
77 // Ancienne maniere : avec Recognizer
79 Standard_Integer IGESFile_Read
81 const Handle(IGESData_IGESModel)& amodel,
82 const Handle(IGESData_Protocol)& protocol,
83 const Handle(IGESData_FileRecognizer)& reco,
84 const Standard_Boolean modefnes)
86 //====================================
87 Message_Msg Msg1 = Message_Msg("XSTEP_1");
88 Message_Msg Msg15 = Message_Msg("XSTEP_15");
89 //====================================
91 char* ficnom = nomfic; // ficnom ?
94 // Sending of message : Beginning of the reading
95 IGESFile_Check(2, Msg1);
98 int result = igesread(ficnom,lesect,modefnes);
100 if (result != 0) return result;
102 // Chargement des resultats dans un IGESReader
104 LesTypes[ArgVide] = Interface_ParamVoid;
105 LesTypes[ArgQuid] = Interface_ParamMisc;
106 LesTypes[ArgChar] = Interface_ParamText;
107 LesTypes[ArgInt] = Interface_ParamInteger;
108 LesTypes[ArgSign] = Interface_ParamInteger;
109 LesTypes[ArgReal] = Interface_ParamReal;
110 LesTypes[ArgExp ] = Interface_ParamMisc; // exposant pas termine
111 LesTypes[ArgRexp] = Interface_ParamReal; // exposant complet
112 LesTypes[ArgMexp] = Interface_ParamEnum; // exposant mais pas de point
115 int nbparts, nbparams;
116 iges_stats(&nbparts,&nbparams); // et fait les Initialisations necessaires
117 Handle(IGESData_IGESReaderData) IR =
118 // new IGESData_IGESReaderData (nbparts, nbparams);
119 new IGESData_IGESReaderData((lesect[3]+1)/2, nbparams);
124 IGESFile_ReadHeader(IR);
125 } // fin essai 1 (global)
126 catch (Standard_Failure const&) {
127 // Sending of message : Internal error during the header reading
128 Message_Msg Msg11 = Message_Msg("XSTEP_11");
129 IGESFile_Check (1,Msg11);
136 if (nbparts > 0) IGESFile_ReadContent(IR);
138 // Sending of message : Loaded data
139 } // fin essai 2 (entites)
140 catch (Standard_Failure const&) {
141 // Sending of message : Internal error during the content reading
143 Message_Msg Msg13 = Message_Msg("XSTEP_13");
145 IGESFile_Check(1,Msg13);
148 Message_Msg Msg14 = Message_Msg("XSTEP_14");
151 IGESFile_Check(1, Msg14);
157 Standard_Integer nbr = IR->NbRecords();
158 // Sending of message : Number of total loaded entities
160 IGESFile_Check(2, Msg15);
162 IGESData_IGESReaderTool IT (IR,protocol);
164 IT.SetErrorHandle(Standard_True);
166 // Sending of message : Loading of Model : Beginning
167 IT.LoadModel(amodel);
168 if (amodel->Protocol().IsNull()) amodel->SetProtocol (protocol);
171 // A present, le check
172 // Nb warning in global section.
173 Standard_Integer nbWarn = checkread()->NbWarnings(), nbFail = checkread()->NbFails();
174 const Handle(Interface_Check)& oldglob = amodel->GlobalCheck();
175 if (nbWarn + nbFail > 0) {
176 checkread()->GetMessages (oldglob);
177 amodel->SetGlobalCheck (checkread());
180 checkread()->Trace(0,1);
188 void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR)
190 Standard_Integer l=0; //szv#4:S4163:12Mar99 i,j,k not needed
193 // d abord les start lines (commentaires)
194 //szv#4:S4163:12Mar99 optimized
196 while ( (j = iges_lirparam(&typarg,&parval)) != 0) {
198 for (Standard_Integer j = 72; j >= 0; j --) {
199 if (parval[j] > 32) { k = j; break; }
202 if (k >= 0 || l > 0) IR->AddStartLine (parval);
205 // puis la Global Section
207 while ( (i = iges_lirparam(&typarg,&parval)) != 0) {
208 IR->AddGlobal(LesTypes[typarg],parval);
211 while (iges_lirparam(&typarg,&parval) != 0) {
212 Standard_Integer j; // svv Jan11 2000 : porting on DEC
213 for (j = 72; j >= 0; j--)
214 if (parval[j] > 32) break;
216 if (j >= 0 || l > 0) IR->AddStartLine (parval);
219 // puis la Global Section
221 while (iges_lirparam(&typarg,&parval) != 0) IR->AddGlobal(LesTypes[typarg],parval);
222 IR->SetGlobalSection();
225 void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR)
227 char *res1, *res2, *nom, *num; char* parval;
232 Standard_Integer nn=0;
233 int ns; //szv#4:S4163:12Mar99 i unused
234 while ( (ns = iges_lirpart(&v,&res1,&res2,&nom,&num,&nbparam)) != 0) {
237 recupne = (ns+1)/2; // numero entite
238 // if(recupne > IR->NbEntities()) {
242 IR->SetDirPart(recupne,
243 v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],
244 v[11],v[12],v[13],v[14],v[15],v[16],res1,res2,nom,num);
245 while (iges_lirparam(&typarg,&parval) != 0) { //szv#4:S4163:12Mar99 `i=` not needed
247 if (typarg == ArgInt || typarg == ArgSign) {
248 Standard_Integer nument = atoi(parval);
249 if (nument < 0) nument = -nument;
250 if (nument & 1) nument = (nument+1)/2;
252 IR->AddParam(recupne,parval,LesTypes[typarg],nument);
254 else IR->AddParam(recupne,parval,LesTypes[typarg]);
256 IR->InitParams(recupne);
262 void IGESFile_Check (int mode,Message_Msg& amsg)
267 case 0 : checkread()->SendFail (amsg); break;
268 case 1 : checkread()->SendWarning (amsg); break;
269 case 2 : checkread()->SendMsg (amsg);break;
270 default : checkread()->SendMsg (amsg);
272 //checkread().Trace(3,-1);
275 void IGESFile_Check2 (int mode,char * code, int num, char * str)
278 Message_Msg amsg (code);
284 case 0 : checkread()->SendFail (amsg); break;
285 case 1 : checkread()->SendWarning (amsg); break;
286 case 2 : checkread()->SendMsg (amsg); break;
287 default : checkread()->SendMsg (amsg);
289 //checkread().Trace(3,-1);
293 void IGESFile_Check3 (int mode,char * code)
296 Message_Msg amsg (code);
299 case 0 : checkread()->SendFail (amsg); break;
300 case 1 : checkread()->SendWarning (amsg); break;
301 case 2 : checkread()->SendMsg (amsg); break;
302 default : checkread()->SendMsg (amsg);
304 //checkread().Trace(3,-1);