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