0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / StepData / StepData_StepReaderTool.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <StepData_StepReaderTool.ixx>
15#include <Standard_ErrorHandler.hxx>
16#include <Standard_Failure.hxx>
17#include <StepData_StepModel.hxx>
18#include <Standard_Transient.hxx>
19#include <StepData_ReadWriteModule.hxx>
20#include <StepData_UndefinedEntity.hxx>
21
22#include <Message_Messenger.hxx>
23#include <Message.hxx>
24#include <Interface_Macros.hxx>
25#include <TCollection_AsciiString.hxx>
26
27
28//=======================================================================
29//function : StepData_StepReaderTool
30//purpose :
31//=======================================================================
32
33StepData_StepReaderTool::StepData_StepReaderTool
34 (const Handle(StepData_StepReaderData)& reader,
35 const Handle(StepData_Protocol)& protocol)
36: theglib(protocol) , therlib(protocol)
37{
38 SetData(reader,protocol);
39}
40
41
42//=======================================================================
43//function : Recognize
44//purpose :
45//=======================================================================
46
47Standard_Boolean StepData_StepReaderTool::Recognize(const Standard_Integer num,
48 Handle(Interface_Check)& ach,
49 Handle(Standard_Transient)& ent)
50{
51// Handle(Standard_Transient) bid; // pas exploite
52// return thereco->Evaluate(thetypes.Value(num),bid);
53
54// Recognizer : C est lui qui assure la Reconnaissance (-> Liste limitative)
55 if (!thereco.IsNull()) {
56 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
57 return thereco->Evaluate(stepdat->RecordType(num),ent);
58 }
59
60// Pas de Recognizer : Reconnaissance par la librairie
61 return RecognizeByLib (num,theglib,therlib,ach,ent);
62}
63
64
65// .... Methodes de preparations propres a StepReaderTool ....
66
67
68//=======================================================================
69//function : Prepare
70//purpose :
71//=======================================================================
72
73void StepData_StepReaderTool::Prepare
74 (const Handle(StepData_FileRecognizer)& reco, const Standard_Boolean optim)
75{
76 thereco = reco;
77 Prepare(optim);
78}
79
80
81//=======================================================================
82//function : Prepare
83//purpose :
84//=======================================================================
85
86void StepData_StepReaderTool::Prepare (const Standard_Boolean optim)
87{
88// SetEntityNumbers a ete mis du cote de ReaderData, because beaucoup acces
89 Standard_Boolean erh = ErrorHandle();
90 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
91 if (erh) {
92 try {
93 OCC_CATCH_SIGNALS
94 stepdat->SetEntityNumbers(optim);
95 SetEntities();
96 }
97 catch(Standard_Failure) {
98 Handle(Message_Messenger) sout = Message::DefaultMessenger();
99 sout << " Exception Raised during Preparation :\n";
100 sout << Standard_Failure::Caught()->GetMessageString();
101 sout << "\n Now, trying to continue, but with presomption of failure\n";
102 }
103 }
104 else {
105 stepdat->SetEntityNumbers(optim);
106 SetEntities();
107 }
108}
109
110
111// .... Gestion du Header : Preparation, lecture .... //
112
113
114//=======================================================================
115//function : PrepareHeader
116//purpose :
117//=======================================================================
118
119void StepData_StepReaderTool::PrepareHeader
120 (const Handle(StepData_FileRecognizer)& reco)
121{
122 Standard_Integer i = 0;
123
124// Reconnaissance des types
125 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
126 while ( (i = stepdat->FindNextHeaderRecord(i)) != 0) {
127 Handle(Standard_Transient) ent;
128// On a donne un Recognizer : il fixe une liste limitative de types reconnus
129 if (!reco.IsNull()) {
130 if (!reco->Evaluate(stepdat->RecordType(i),ent)) {
131 ent = Protocol()->UnknownEntity();
132 }
133 } else {
134// Pas de Recognizer : Reconnaissance par la librairie
135 Handle(Interface_Check) ach = new Interface_Check; // faudrait le lister ... ?
136 RecognizeByLib (i,theglib,therlib,ach,ent);
137 }
138 if (ent.IsNull()) ent = Protocol()->UnknownEntity();
139 stepdat->BindEntity(i,ent);
140 }
141
142// Reste la Resolution des references : ne concerne que les sous-listes
143// Assuree par ReaderData
144 stepdat->PrepareHeader();
145}
146
147
148// .... Methodes pour la lecture du Modele (apres preparation) .... //
149
150
151//=======================================================================
152//function : BeginRead
153//purpose :
154//=======================================================================
155
156void StepData_StepReaderTool::BeginRead
157 (const Handle(Interface_InterfaceModel)& amodel)
158{
159 Handle(Message_Messenger) sout = Message::DefaultMessenger();
160 DeclareAndCast(StepData_StepModel,model,amodel);
161 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
162
163 model->ClearHeader();
164 model->SetGlobalCheck(stepdat->GlobalCheck());
165 Standard_Integer i = 0;
166 while ( (i = stepdat->FindNextHeaderRecord(i)) != 0) {
167 Handle(Standard_Transient) ent = stepdat->BoundEntity(i);
168 Handle(Interface_Check) ach = new Interface_Check(ent);
169 AnalyseRecord(i,ent,ach);
170 if (ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity))) {
171 TCollection_AsciiString mess("Header Entity not Recognized, StepType: ");
172 mess.AssignCat(stepdat->RecordType(i));
173 ach->AddWarning(mess.ToCString());
174 }
175 if (ach->HasFailed() || ach->HasWarnings()) {
176 Handle(Interface_Check) mch = model->GlobalCheck();
177 mch->GetMessages(ach); model->SetGlobalCheck(mch);
178 }
179 model->AddHeaderEntity(ent);
180 if (ach->HasWarnings()) {
181 Handle(Interface_Check) mch = model->GlobalCheck();
182 Standard_Integer nbmess = ach->NbWarnings();
183 sout<<nbmess<<" Warnings on Reading Header Entity N0."<<i<<":";
184 if (!ent.IsNull()) sout << ent->DynamicType()->Name() << endl;
185 for (Standard_Integer nf = 1; nf <= nbmess; nf ++)
186 sout << ach->CWarning(nf) << "\n";
187 }
188 if (ach->HasFailed()) {
189 Handle(Interface_Check) mch = model->GlobalCheck();
190 Standard_Integer nbmess = ach->NbFails();
191 sout << " Errors on Reading Header Entity N0."<<i<<":";
192 if (!ent.IsNull()) sout << ent->DynamicType()->Name() << endl;
193 for (Standard_Integer nf = 1; nf <= nbmess; nf ++)
194 sout << ach->CFail(nf) << "\n";
195 }
196 }
197}
198
199
200//=======================================================================
201//function : AnalyseRecord
202//purpose :
203//=======================================================================
204
205Standard_Boolean StepData_StepReaderTool::AnalyseRecord
206 (const Standard_Integer num,
207 const Handle(Standard_Transient)& anent,
208 Handle(Interface_Check)& acheck)
209{
210 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
211 Handle(StepData_ReadWriteModule) module; Standard_Integer CN;
212 if (therlib.Select(anent,module,CN))
213 module->ReadStep(CN,stepdat,num,acheck,anent);
214 else {
215// Pas trouve : tenter UndefinedEntity de StepData
216 DeclareAndCast(StepData_UndefinedEntity,und,anent);
217 if (und.IsNull()) acheck->AddFail
218 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
219 else und->ReadRecord(stepdat,num,acheck);
220 }
221 return (!acheck->HasFailed());
222}
223
224
225//=======================================================================
226//function : EndRead
227//purpose :
228//=======================================================================
229
230void StepData_StepReaderTool::EndRead
231 (const Handle(Interface_InterfaceModel)& amodel)
232{
233 DeclareAndCast(StepData_StepReaderData,stepdat,Data());
234 DeclareAndCast(StepData_StepModel,stepmodel,amodel);
235 if (stepmodel.IsNull()) return;
236 Standard_Integer i = 0;
237 while ( (i = stepdat->FindNextRecord(i)) != 0) {
238 stepmodel->SetIdentLabel(stepdat->BoundEntity(i),stepdat->RecordIdent(i));
239 }
240}