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 <Interface_ParamType.hxx>
19 #include <IGESData_IGESReaderData.hxx>
20 #include <IGESData_IGESReaderTool.hxx>
21 #include <IGESData_GeneralModule.hxx>
22 #include <Interface_Check.hxx>
24 #include <Interface_FileParameter.hxx>
25 #include <Interface_ParamList.hxx>
26 // Pour traiter les exceptions :
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_Failure.hxx>
30 // definition de base, a inclure pour utiliser
31 #include <IGESFile_Read.hxx>
39 #include <Message_Msg.hxx>
41 // decoupage interne pour faciliter les recuperations d erreurs
42 static Standard_Integer recupne,recupnp; // pour affichage en cas de pepin
43 static Handle(Interface_Check)& checkread()
45 static Handle(Interface_Check) chrd = new Interface_Check;
49 static void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR);
50 static void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR);
51 void IGESFile_Check (int mode,Message_Msg& amsg);
52 // void IGESFile_Check2 (int mode,char * code, int num, char * str);
53 // void IGESFile_Check3 (int mode,char * code);
55 // Correspondance entre types igesread et types Interface_ParamFile ...
56 static Interface_ParamType LesTypes[10];
59 // Nouvelle maniere : Protocol suffit
61 Standard_Integer IGESFile_Read
63 const Handle(IGESData_IGESModel)& amodel,
64 const Handle(IGESData_Protocol)& protocol)
66 Handle(IGESData_FileRecognizer) nulreco;
67 return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_False);
70 Standard_Integer IGESFile_ReadFNES
72 const Handle(IGESData_IGESModel)& amodel,
73 const Handle(IGESData_Protocol)& protocol)
75 Handle(IGESData_FileRecognizer) nulreco;
76 return IGESFile_Read(nomfic,amodel,protocol,nulreco,Standard_True);
80 // Ancienne maniere : avec Recognizer
82 Standard_Integer IGESFile_Read
84 const Handle(IGESData_IGESModel)& amodel,
85 const Handle(IGESData_Protocol)& protocol,
86 const Handle(IGESData_FileRecognizer)& reco,
87 const Standard_Boolean modefnes)
89 //====================================
90 Message_Msg Msg1 = Message_Msg("XSTEP_1");
91 Message_Msg Msg15 = Message_Msg("XSTEP_15");
92 //====================================
94 char* ficnom = nomfic; // ficnom ?
97 // Sending of message : Beginning of the reading
98 IGESFile_Check(2, Msg1);
100 checkread()->Clear();
101 int result = igesread(ficnom,lesect,modefnes);
103 if (result != 0) return result;
105 // Chargement des resultats dans un IGESReader
107 LesTypes[ArgVide] = Interface_ParamVoid;
108 LesTypes[ArgQuid] = Interface_ParamMisc;
109 LesTypes[ArgChar] = Interface_ParamText;
110 LesTypes[ArgInt] = Interface_ParamInteger;
111 LesTypes[ArgSign] = Interface_ParamInteger;
112 LesTypes[ArgReal] = Interface_ParamReal;
113 LesTypes[ArgExp ] = Interface_ParamMisc; // exposant pas termine
114 LesTypes[ArgRexp] = Interface_ParamReal; // exposant complet
115 LesTypes[ArgMexp] = Interface_ParamEnum; // exposant mais pas de point
118 int nbparts, nbparams;
119 iges_stats(&nbparts,&nbparams); // et fait les Initialisations necessaires
120 Handle(IGESData_IGESReaderData) IR =
121 // new IGESData_IGESReaderData (nbparts, nbparams);
122 new IGESData_IGESReaderData((lesect[3]+1)/2, nbparams);
127 IGESFile_ReadHeader(IR);
128 } // fin essai 1 (global)
129 catch (Standard_Failure const&) {
130 // Sending of message : Internal error during the header reading
131 Message_Msg Msg11 = Message_Msg("XSTEP_11");
132 IGESFile_Check (1,Msg11);
139 if (nbparts > 0) IGESFile_ReadContent(IR);
141 // Sending of message : Loaded data
142 } // fin essai 2 (entites)
143 catch (Standard_Failure const&) {
144 // Sending of message : Internal error during the content reading
146 Message_Msg Msg13 = Message_Msg("XSTEP_13");
148 IGESFile_Check(1,Msg13);
151 Message_Msg Msg14 = Message_Msg("XSTEP_14");
154 IGESFile_Check(1, Msg14);
160 Standard_Integer nbr = IR->NbRecords();
161 // Sending of message : Number of total loaded entities
163 IGESFile_Check(2, Msg15);
165 IGESData_IGESReaderTool IT (IR,protocol);
167 IT.SetErrorHandle(Standard_True);
169 // Sending of message : Loading of Model : Beginning
170 IT.LoadModel(amodel);
171 if (amodel->Protocol().IsNull()) amodel->SetProtocol (protocol);
174 // A present, le check
175 // Nb warning in global section.
176 Standard_Integer nbWarn = checkread()->NbWarnings(), nbFail = checkread()->NbFails();
177 const Handle(Interface_Check)& oldglob = amodel->GlobalCheck();
178 if (nbWarn + nbFail > 0) {
179 checkread()->GetMessages (oldglob);
180 amodel->SetGlobalCheck (checkread());
183 checkread()->Trace(0,1);
191 void IGESFile_ReadHeader (const Handle(IGESData_IGESReaderData)& IR)
193 Standard_Integer l=0; //szv#4:S4163:12Mar99 i,j,k not needed
196 // d abord les start lines (commentaires)
197 //szv#4:S4163:12Mar99 optimized
199 while ( (j = iges_lirparam(&typarg,&parval)) != 0) {
201 for (Standard_Integer j = 72; j >= 0; j --) {
202 if (parval[j] > 32) { k = j; break; }
205 if (k >= 0 || l > 0) IR->AddStartLine (parval);
208 // puis la Global Section
210 while ( (i = iges_lirparam(&typarg,&parval)) != 0) {
211 IR->AddGlobal(LesTypes[typarg],parval);
214 while (iges_lirparam(&typarg,&parval) != 0) {
215 Standard_Integer j; // svv Jan11 2000 : porting on DEC
216 for (j = 72; j >= 0; j--)
217 if (parval[j] > 32) break;
219 if (j >= 0 || l > 0) IR->AddStartLine (parval);
222 // puis la Global Section
224 while (iges_lirparam(&typarg,&parval) != 0) IR->AddGlobal(LesTypes[typarg],parval);
225 IR->SetGlobalSection();
228 void IGESFile_ReadContent (const Handle(IGESData_IGESReaderData)& IR)
230 char *res1, *res2, *nom, *num; char* parval;
235 Standard_Integer nn=0;
236 int ns; //szv#4:S4163:12Mar99 i unused
237 while ( (ns = iges_lirpart(&v,&res1,&res2,&nom,&num,&nbparam)) != 0) {
240 recupne = (ns+1)/2; // numero entite
241 // if(recupne > IR->NbEntities()) {
245 IR->SetDirPart(recupne,
246 v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],
247 v[11],v[12],v[13],v[14],v[15],v[16],res1,res2,nom,num);
248 while (iges_lirparam(&typarg,&parval) != 0) { //szv#4:S4163:12Mar99 `i=` not needed
250 if (typarg == ArgInt || typarg == ArgSign) {
251 Standard_Integer nument = atoi(parval);
252 if (nument < 0) nument = -nument;
253 if (nument & 1) nument = (nument+1)/2;
255 IR->AddParam(recupne,parval,LesTypes[typarg],nument);
257 else IR->AddParam(recupne,parval,LesTypes[typarg]);
259 IR->InitParams(recupne);
265 void IGESFile_Check (int mode,Message_Msg& amsg)
270 case 0 : checkread()->SendFail (amsg); break;
271 case 1 : checkread()->SendWarning (amsg); break;
272 case 2 : checkread()->SendMsg (amsg);break;
273 default : checkread()->SendMsg (amsg);
275 //checkread().Trace(3,-1);
278 void IGESFile_Check2 (int mode,char * code, int num, char * str)
281 Message_Msg amsg (code);
287 case 0 : checkread()->SendFail (amsg); break;
288 case 1 : checkread()->SendWarning (amsg); break;
289 case 2 : checkread()->SendMsg (amsg); break;
290 default : checkread()->SendMsg (amsg);
292 //checkread().Trace(3,-1);
296 void IGESFile_Check3 (int mode,char * code)
299 Message_Msg amsg (code);
302 case 0 : checkread()->SendFail (amsg); break;
303 case 1 : checkread()->SendWarning (amsg); break;
304 case 2 : checkread()->SendMsg (amsg); break;
305 default : checkread()->SendMsg (amsg);
307 //checkread().Trace(3,-1);