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.
15 #include <IGESData_ColorEntity.hxx>
16 #include <IGESData_FileRecognizer.hxx>
17 #include <IGESData_IGESEntity.hxx>
18 #include <IGESData_IGESModel.hxx>
19 #include <IGESData_IGESReaderData.hxx>
20 #include <IGESData_IGESReaderTool.hxx>
21 #include <IGESData_LabelDisplayEntity.hxx>
22 #include <IGESData_LevelListEntity.hxx>
23 #include <IGESData_LineFontEntity.hxx>
24 #include <IGESData_ParamCursor.hxx>
25 #include <IGESData_ParamReader.hxx>
26 #include <IGESData_Protocol.hxx>
27 #include <IGESData_ReadWriteModule.hxx>
28 #include <IGESData_TransfEntity.hxx>
29 #include <IGESData_UndefinedEntity.hxx>
30 #include <IGESData_ViewKindEntity.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_InterfaceModel.hxx>
33 #include <Interface_Macros.hxx>
34 #include <Interface_ParamList.hxx>
35 #include <Interface_ReaderModule.hxx>
36 #include <Message_Msg.hxx>
37 #include <Standard_Transient.hxx>
38 #include <TCollection_HAsciiString.hxx>
43 IGESData_IGESReaderTool::IGESData_IGESReaderTool
44 (const Handle(IGESData_IGESReaderData)& reader,
45 const Handle(IGESData_Protocol)& protocol)
46 : theglib(protocol) , therlib(protocol)
47 { SetData (reader,protocol); }
50 // ###########################################################################
51 // ######## PREPARATION ########
53 void IGESData_IGESReaderTool::Prepare
54 (const Handle(IGESData_FileRecognizer)& reco)
56 DeclareAndCast(IGESData_IGESReaderData,igesdat,Data());
57 igesdat->SetEntityNumbers();
60 thelist = igesdat->Params(0);
64 Standard_Boolean IGESData_IGESReaderTool::Recognize
65 (const Standard_Integer num, Handle(Interface_Check)& ach,
66 Handle(Standard_Transient)& ent)
68 DeclareAndCast(IGESData_IGESReaderData,igesdat,Data());
69 thecnum = num; thectyp = igesdat->DirType(num);
70 Handle(IGESData_IGESEntity) anent;
71 Standard_Boolean res = Standard_False;
73 // Recognizer -> Liste limitative
74 if (!thereco.IsNull()) res = thereco->Evaluate(thectyp,anent);
77 else res = RecognizeByLib (num,theglib,therlib,ach,ent);
82 // ###########################################################################
83 // ######## LECTURE (Controle General) ########
85 // (Elements enchaines par la classe de base Interface_FileReaderTool)
87 void IGESData_IGESReaderTool::BeginRead
88 (const Handle(Interface_InterfaceModel)& amodel)
90 DeclareAndCast(IGESData_IGESModel,amod,amodel);
91 DeclareAndCast(IGESData_IGESReaderData,igesdat,Data());
92 const IGESData_GlobalSection& gs = igesdat->GlobalSection();
93 amod->SetStartSection (igesdat->StartSection(),Standard_False);
94 amod->SetGlobalSection (gs);
95 Handle(Interface_Check) glob = amod->GlobalCheck();
96 glob->GetMessages (igesdat->GlobalCheck());
97 amod->SetGlobalCheck (glob);
98 themaxweight = gs.MaxLineWeight();
99 thegradweight = gs.LineWeightGrad();
100 if (thegradweight > 0)
101 { themaxweight = themaxweight/thegradweight; thegradweight = 1; }
102 thedefweight = igesdat->DefaultLineWeight();
106 // Manquent les procedures de reprise sur erreur en cours de route ...
107 Standard_Boolean IGESData_IGESReaderTool::AnalyseRecord
108 (const Standard_Integer num, const Handle(Standard_Transient)& anent,
109 Handle(Interface_Check)& ach)
112 Handle(TCollection_HAsciiString) lab;
114 DeclareAndCast(IGESData_IGESEntity,ent,anent);
115 DeclareAndCast(IGESData_IGESReaderData,igesdat,Data());
117 // Demarrage de la lecture : Faire Clear
120 // UndefinedEntity : une pre-analyse est faite
121 DeclareAndCast(IGESData_UndefinedEntity,undent,ent);
122 if (!undent.IsNull()) {
123 IGESData_DirPart DP = igesdat->DirPart(num); // qui le copie ...
124 undent->ReadDir (igesdat,DP,ach); // DP a pu etre modifie
125 ReadDir (ent,igesdat,DP,ach); // Lecture avec ce DP
127 else ReadDir (ent,igesdat,igesdat->DirPart(num),ach);
129 thestep = IGESData_ReadDir;
131 // Liste de Parametres : controle de son entete
132 // Handle(Interface_ParamList) list = Data()->Params(num);
133 Standard_Integer nbpar = Data()->NbParams(num);
134 Standard_Integer n0par = (num == 1 ? 1 : (Data()->ParamFirstRank(num-1) +1));
136 // Liste vide non admise, sauf si Undefined (par exemple type nul)
137 if (!undent.IsNull()) return Standard_True;
138 // Sending of message : DE : no parameter
139 Message_Msg Msg27 ("XSTEP_27");
141 ach->SendFail(Msg27);
142 return Standard_False;
144 const Interface_FileParameter& FP = thelist->Value(n0par);
145 if ((FP.ParamType() != Interface_ParamInteger) || (atoi(FP.CValue()) != ent->TypeNumber()))
147 // Sending of message : DE : Incorrect type
148 Message_Msg Msg28 ("XSTEP_28");
150 ach->SendFail(Msg28);
151 return Standard_False;
154 IGESData_ParamReader PR (thelist,ach,n0par,nbpar,num);
155 thestep = IGESData_ReadOwn;
156 ReadOwnParams (ent,igesdat,PR);
157 if ((thestep = PR.Stage()) == IGESData_ReadOwn) PR.NextStage();
158 if (thestep == IGESData_ReadEnd) {
159 if (!PR.IsCheckEmpty()) ach = PR.Check();
160 return (!ach->HasFailed());
163 ReadAssocs (ent,igesdat,PR);
164 if ((thestep = PR.Stage()) == IGESData_ReadAssocs) PR.NextStage();
165 if (thestep == IGESData_ReadEnd) {
166 if (!PR.IsCheckEmpty()) ach = PR.Check();
167 return (!ach->HasFailed());
169 ReadProps (ent,igesdat,PR);
170 // thestep = IGESData_ReadEnd;
171 if (!PR.IsCheckEmpty()) ach = PR.Check();
172 return (!ach->HasFailed());
175 void IGESData_IGESReaderTool::EndRead
176 (const Handle(Interface_InterfaceModel)& /* amodel */)
179 DeclareAndCast(IGESData_IGESModel,amod,amodel);
180 DeclareAndCast(IGESData_IGESReaderData,igesdat,Data());
181 amod->SetLineWeights(igesdat->DefaultLineWeight());
187 // ###########################################################################
188 // ######## UNE ENTITE ########
190 // ######## Directory Part ########
192 void IGESData_IGESReaderTool::ReadDir
193 (const Handle(IGESData_IGESEntity)& ent,
194 const Handle(IGESData_IGESReaderData)& IR,
195 const IGESData_DirPart& DP, Handle(Interface_Check)& ach) const
198 Standard_Integer v[17] = {};
199 Standard_Character nom[9] = {}; Standard_Character snum[9] = {}, theRes1[9] = {}, theRes2[9] = {};
200 DP.Values(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],
201 v[12],v[13],v[14],v[15],v[16],theRes1,theRes2,nom,snum);
203 ent->InitTypeAndForm (v[0] , v[16]);
204 Handle(IGESData_IGESEntity) fieldent, Structure, fieldlab;
205 if (v[2] < 0) Structure = GetCasted
206 (IGESData_IGESEntity, IR->BoundEntity( (1-v[2])/2 ));
208 Handle(IGESData_LineFontEntity) Lnf;
210 fieldent = GetCasted(IGESData_IGESEntity, IR->BoundEntity( (1-v[3])/2 ));
211 Lnf = GetCasted(IGESData_LineFontEntity, fieldent);
213 // Sending of message : Incorrect Line Font Pattern
214 Message_Msg Msg29 ("XSTEP_29");
216 Msg29.Arg(thectyp.Type());
217 ach->SendWarning(Msg29);
218 ent->InitDirFieldEntity(4,fieldent);
220 else ent->InitLineFont (Lnf);
222 else ent->InitLineFont(Lnf,v[3]); // ici Lnf Null
224 Handle(IGESData_LevelListEntity) Lvs;
226 fieldent = GetCasted(IGESData_IGESEntity, IR->BoundEntity( (1-v[4])/2 ));
227 Lvs = GetCasted(IGESData_LevelListEntity, fieldent);
229 // Sending of message : Incorrect Line Font Pattern
230 Message_Msg Msg30 ("XSTEP_30");
232 Msg30.Arg(thectyp.Type());
233 ach->SendWarning(Msg30);
234 ent->InitDirFieldEntity(5,fieldent);
236 else ent->InitLevel(Lvs,-1);
238 else ent->InitLevel(Lvs,v[4]); // ici Lvs Null
241 fieldent = GetCasted(IGESData_IGESEntity,IR->BoundEntity( (1+v[5])/2 ));
242 DeclareAndCast(IGESData_ViewKindEntity,View,fieldent);
244 // Sending of message : Incorrect View
245 Message_Msg Msg31 ("XSTEP_31");
247 Msg31.Arg(thectyp.Type());
248 ach->SendWarning(Msg31);
249 ent->InitDirFieldEntity(6,fieldent);
251 else ent->InitView(View);
255 fieldent = GetCasted(IGESData_IGESEntity,IR->BoundEntity( (1+v[6])/2 ));
256 DeclareAndCast(IGESData_TransfEntity,Transf,fieldent);
257 if (Transf.IsNull()) {
258 // Sending of message : Incorrect Transformation Matrix
259 Message_Msg Msg32 ("XSTEP_32");
261 Msg32.Arg(thectyp.Type());
262 ach->SendWarning(Msg32);
263 ent->InitDirFieldEntity(7,fieldent);
265 else ent->InitTransf(Transf);
268 Handle(IGESData_LabelDisplayEntity) Lbd;
270 fieldlab = GetCasted(IGESData_IGESEntity,IR->BoundEntity( (1+v[7])/2 ));
271 Lbd = GetCasted(IGESData_LabelDisplayEntity,fieldent);
273 // Sending of message : Incorrect Label Display
274 Message_Msg Msg33 ("XSTEP_33");
276 Msg33.Arg(thectyp.Type());
277 ach->SendWarning(Msg33);
281 ent->InitStatus (v[8] , v[9] , v[10] , v[11]);
283 Standard_Integer LWeightNum = v[13];
285 Handle(IGESData_ColorEntity) Color;
287 fieldent = GetCasted(IGESData_IGESEntity,IR->BoundEntity( (1-v[14])/2 ));
288 Color = GetCasted(IGESData_ColorEntity, fieldent);
289 //an entity that is not a color entity and has a number corresponding
290 //to the color field should not be considered erroneous
291 if (Color.IsNull()) {
292 // Sending of message : Incorrect Color Number
293 Message_Msg Msg34 ("XSTEP_34");
295 Msg34.Arg(thectyp.Type());
296 ach->SendWarning(Msg34);
297 ent->InitDirFieldEntity(13,Color);
299 else ent->InitColor(Color);
301 else ent->InitColor(Color,v[14]);
303 ent->InitMisc (Structure,Lbd,LWeightNum);
304 ent->InitDirFieldEntity(8,fieldlab);
306 // ignores : 1(type),2(ptrPsect),13(type),16(lignesPsect),17(form)
307 // type et forme sont lus directement du DirPart; autres infos recalculees
309 // Restent a analyser nom (short label) et snum (subscript number)
310 Handle(TCollection_HAsciiString) ShortLabel;
311 Standard_Integer SubScriptN = -1;
312 Standard_Integer iacar = 0;
313 Standard_Integer i; // svv Jan11 2000 : porting on DEC
314 for (i = 0; i < 8; i ++) { if (nom[i] > ' ') iacar = 1; }
315 if (iacar > 0) ShortLabel = new TCollection_HAsciiString(nom);
317 for (i = 0; i < 8; i ++)
318 { if (snum[i] > ' ') iacar = 1; if(snum[i] == 0) break; }
319 if (iacar > 0) SubScriptN = atoi(snum);
320 ent->SetLabel(ShortLabel,SubScriptN);
322 // Enfin, SetLineWeight, tenant compte du defaut
323 ent->SetLineWeight (IR->DefaultLineWeight(),themaxweight,thegradweight);
327 // ######## Partie Specifique ########
329 void IGESData_IGESReaderTool::ReadOwnParams
330 (const Handle(IGESData_IGESEntity)& ent,
331 const Handle(IGESData_IGESReaderData)& IR,
332 IGESData_ParamReader& PR) const
334 Handle(Interface_Check) ach = new Interface_Check();
335 Handle(Interface_ReaderModule) imodule;
338 // Les Modules font tout
339 if (therlib.Select(ent,imodule,CN))
341 Handle(IGESData_ReadWriteModule) module =
342 Handle(IGESData_ReadWriteModule)::DownCast (imodule);
343 module->ReadOwnParams(CN,ent,IR,PR);
345 else if (ent.IsNull()) {
347 // Sending of message : Null Entity
348 Message_Msg Msg35 ("XSTEP_35");
350 ach->SendFail(Msg35);
351 // Cas de UndefinedEntity
352 } else if (ent->IsKind(STANDARD_TYPE(IGESData_UndefinedEntity))) {
353 DeclareAndCast(IGESData_UndefinedEntity,undent,ent);
354 undent->ReadOwnParams(IR,PR);
355 // IGESEntity creee puis non reconnue ... (bizarre, non ?)
357 // IGESData_IGESType DT = ent->IGESType();
358 // Sending of message : Unknown Entity
359 Message_Msg Msg36 ("XSTEP_36");
361 ach->SendFail(Msg36);
366 // ######## Proprietes ########
368 void IGESData_IGESReaderTool::ReadProps
369 (const Handle(IGESData_IGESEntity)& ent,
370 const Handle(IGESData_IGESReaderData)& IR,
371 IGESData_ParamReader& PR) const
374 // Building of Messages
375 //=====================================
376 Message_Msg Msg38 ("XSTEP_38");
377 //Message_Msg Msg221 ("XSTEP_221");
378 //=====================================
379 Handle(Interface_Check) ach = new Interface_Check;
381 Msg38.Arg(thectyp.Type());
382 if (PR.Stage() != IGESData_ReadProps) ach->SendFail(Msg38);
383 Standard_Integer ncur = PR.CurrentNumber();
384 Standard_Integer nbp = PR.NbParams();
385 if (ncur == nbp + 1) { PR.EndAll(); return; }
386 else if (ncur > nbp || ncur == 0) ach->SendWarning(Msg38);
388 Standard_Integer nbprops = 0;
389 if (!PR.DefinedElseSkip()) return;
390 if (!PR.ReadInteger(ncur,nbprops)) {
391 Message_Msg Msg221 ("XSTEP_221");
401 Interface_EntityList props;
403 (IR,PR.CurrentList(nbprops),Msg38, props,Standard_False) )
404 ent->LoadProperties(props);
408 // ######## Associativites ########
410 void IGESData_IGESReaderTool::ReadAssocs
411 (const Handle(IGESData_IGESEntity)& ent,
412 const Handle(IGESData_IGESReaderData)& IR,
413 IGESData_ParamReader& PR) const
416 // Building of Messages
417 //=====================================
418 Message_Msg Msg37 ("XSTEP_37");
419 // Message_Msg Msg220 ("XSTEP_220");
420 //=====================================
422 Msg37.Arg(thectyp.Type());
423 Handle(Interface_Check) ach = new Interface_Check;
424 if (PR.Stage() != IGESData_ReadAssocs) ach->SendFail(Msg37);
425 Standard_Integer ncur = PR.CurrentNumber();
426 Standard_Integer nbp = PR.NbParams();
427 if (ncur == nbp + 1) { PR.EndAll(); return; }
428 else if (ncur > nbp || ncur == 0) ach->SendWarning(Msg37);
430 Standard_Integer nbassocs = 0;
431 if (!PR.DefinedElseSkip()) return;
432 if (!PR.ReadInteger(PR.Current(),nbassocs)){
433 Message_Msg Msg220 ("XSTEP_220");
437 if (nbassocs == 0) return;
438 Interface_EntityList assocs;
440 (IR,PR.CurrentList(nbassocs),Msg37, assocs,Standard_False) )
441 ent->LoadAssociativities(assocs);