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