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 | |
7fd59977 |
14 | |
b9fbc699 |
15 | #include <IFSelect_WorkLibrary.hxx> |
7fd59977 |
16 | #include <Interface_EntityIterator.hxx> |
17 | #include <Interface_Graph.hxx> |
18 | #include <Interface_Static.hxx> |
b9fbc699 |
19 | #include <Message.hxx> |
20 | #include <Message_Messenger.hxx> |
7fd59977 |
21 | #include <StepBasic_ApplicationContext.hxx> |
42cf5bc1 |
22 | #include <StepBasic_ConversionBasedUnit.hxx> |
7fd59977 |
23 | #include <StepBasic_DocumentProductEquivalence.hxx> |
d402d481 |
24 | #include <StepBasic_LengthMeasureWithUnit.hxx> |
42cf5bc1 |
25 | #include <StepBasic_MeasureWithUnit.hxx> |
26 | #include <StepBasic_NamedUnit.hxx> |
d402d481 |
27 | #include <StepBasic_PlaneAngleMeasureWithUnit.hxx> |
42cf5bc1 |
28 | #include <StepBasic_ProductDefinitionContext.hxx> |
29 | #include <StepBasic_ProductDefinitionFormation.hxx> |
42cf5bc1 |
30 | #include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx> |
42cf5bc1 |
31 | #include <StepBasic_SiUnitAndLengthUnit.hxx> |
d402d481 |
32 | #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx> |
33 | #include <StepBasic_SiUnitAndSolidAngleUnit.hxx> |
42cf5bc1 |
34 | #include <StepBasic_SiUnitName.hxx> |
35 | #include <StepBasic_SolidAngleMeasureWithUnit.hxx> |
42cf5bc1 |
36 | #include <STEPConstruct_UnitContext.hxx> |
42cf5bc1 |
37 | #include <STEPControl_Controller.hxx> |
38 | #include <STEPControl_Reader.hxx> |
d402d481 |
39 | #include <StepData_StepModel.hxx> |
42cf5bc1 |
40 | #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx> |
41 | #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx> |
42 | #include <StepRepr_GlobalUncertaintyAssignedContext.hxx> |
43 | #include <StepRepr_GlobalUnitAssignedContext.hxx> |
44 | #include <StepRepr_MappedItem.hxx> |
45 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
46 | #include <StepRepr_ProductDefinitionShape.hxx> |
47 | #include <StepRepr_PropertyDefinition.hxx> |
d402d481 |
48 | #include <StepRepr_RepresentationContext.hxx> |
42cf5bc1 |
49 | #include <StepRepr_RepresentationMap.hxx> |
50 | #include <StepRepr_RepresentationRelationship.hxx> |
51 | #include <StepRepr_ShapeAspect.hxx> |
c6f530b8 |
52 | #include <StepShape_ManifoldSolidBrep.hxx> |
42cf5bc1 |
53 | #include <StepShape_ShapeDefinitionRepresentation.hxx> |
54 | #include <StepShape_ShapeRepresentation.hxx> |
c6f530b8 |
55 | #include <StepShape_ShellBasedSurfaceModel.hxx> |
42cf5bc1 |
56 | #include <TCollection_AsciiString.hxx> |
d402d481 |
57 | #include <TColStd_Array1OfAsciiString.hxx> |
58 | #include <TColStd_Array1OfReal.hxx> |
42cf5bc1 |
59 | #include <TColStd_HSequenceOfTransient.hxx> |
60 | #include <TColStd_MapOfAsciiString.hxx> |
61 | #include <TColStd_SequenceOfAsciiString.hxx> |
62 | #include <Transfer_TransientProcess.hxx> |
42cf5bc1 |
63 | #include <XSControl_TransferReader.hxx> |
64 | #include <XSControl_WorkSession.hxx> |
65 | |
7fd59977 |
66 | //======================================================================= |
67 | //function : STEPControl_Reader |
68 | //purpose : |
69 | //======================================================================= |
7fd59977 |
70 | STEPControl_Reader::STEPControl_Reader () |
71 | { |
72 | STEPControl_Controller::Init(); |
73 | SetNorm ("STEP"); |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : STEPControl_Reader |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | STEPControl_Reader::STEPControl_Reader |
82 | (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch) |
83 | { |
84 | STEPControl_Controller::Init(); |
85 | SetWS (WS,scratch); |
86 | SetNorm ("STEP"); |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : StepModel |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | Handle(StepData_StepModel) STEPControl_Reader::StepModel () const |
95 | { |
96 | return Handle(StepData_StepModel)::DownCast(Model()); |
97 | } |
98 | |
b9fbc699 |
99 | //======================================================================= |
100 | //function : ReadFile |
101 | //purpose : |
102 | //======================================================================= |
103 | IFSelect_ReturnStatus STEPControl_Reader::ReadFile(const Standard_CString filename) |
104 | { |
105 | Handle(IFSelect_WorkLibrary) aLibrary = WS()->WorkLibrary(); |
106 | Handle(Interface_Protocol) aProtocol = WS()->Protocol(); |
107 | if (aLibrary.IsNull()) return IFSelect_RetVoid; |
108 | if (aProtocol.IsNull()) return IFSelect_RetVoid; |
109 | Handle(StepData_StepModel) aStepModel = new StepData_StepModel; |
110 | aStepModel->InternalParameters.InitFromStatic(); |
111 | aStepModel->SetSourceCodePage(aStepModel->InternalParameters.ReadCodePage); |
112 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
113 | try { |
114 | OCC_CATCH_SIGNALS |
115 | Standard_Integer stat = aLibrary->ReadFile(filename, aStepModel, aProtocol); |
116 | if (stat == 0) status = IFSelect_RetDone; |
117 | else if (stat < 0) status = IFSelect_RetError; |
118 | else status = IFSelect_RetFail; |
119 | } |
120 | catch (Standard_Failure const& anException) { |
121 | Message_Messenger::StreamBuffer sout = Message::SendInfo(); |
122 | sout << " **** Interruption ReadFile par Exception : ****\n"; |
123 | sout << anException.GetMessageString(); |
124 | sout << "\n Abandon" << std::endl; |
125 | status = IFSelect_RetFail; |
126 | } |
127 | if (status != IFSelect_RetDone) return status; |
128 | WS()->SetModel(aStepModel); |
129 | WS()->SetLoadedFile(filename); |
130 | WS()->InitTransferReader(4); |
131 | return status; |
132 | } |
133 | |
134 | //======================================================================= |
135 | //function : ReadFile |
136 | //purpose : |
137 | //======================================================================= |
138 | IFSelect_ReturnStatus STEPControl_Reader::ReadFile(const Standard_CString filename, |
139 | const StepData_ConfParameters& theParams) |
140 | { |
141 | Handle(IFSelect_WorkLibrary) aLibrary = WS()->WorkLibrary(); |
142 | Handle(Interface_Protocol) aProtocol = WS()->Protocol(); |
143 | if (aLibrary.IsNull()) return IFSelect_RetVoid; |
144 | if (aProtocol.IsNull()) return IFSelect_RetVoid; |
145 | Handle(StepData_StepModel) aStepModel = new StepData_StepModel; |
146 | aStepModel->InternalParameters = theParams; |
147 | aStepModel->SetSourceCodePage(aStepModel->InternalParameters.ReadCodePage); |
148 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
149 | try { |
150 | OCC_CATCH_SIGNALS |
151 | Standard_Integer stat = aLibrary->ReadFile(filename, aStepModel, aProtocol); |
152 | if (stat == 0) status = IFSelect_RetDone; |
153 | else if (stat < 0) status = IFSelect_RetError; |
154 | else status = IFSelect_RetFail; |
155 | } |
156 | catch (Standard_Failure const& anException) { |
157 | Message_Messenger::StreamBuffer sout = Message::SendInfo(); |
158 | sout << " **** Interruption ReadFile par Exception : ****\n"; |
159 | sout << anException.GetMessageString(); |
160 | sout << "\n Abandon" << std::endl; |
161 | status = IFSelect_RetFail; |
162 | } |
163 | if (status != IFSelect_RetDone) return status; |
164 | WS()->SetModel(aStepModel); |
165 | WS()->SetLoadedFile(filename); |
166 | WS()->InitTransferReader(4); |
167 | return status; |
168 | } |
169 | |
170 | //======================================================================= |
171 | //function : ReadStream |
172 | //purpose : |
173 | //======================================================================= |
174 | IFSelect_ReturnStatus STEPControl_Reader::ReadStream(const Standard_CString theName, |
175 | std::istream& theIStream) |
176 | { |
177 | Handle(IFSelect_WorkLibrary) aLibrary = WS()->WorkLibrary(); |
178 | Handle(Interface_Protocol) aProtocol = WS()->Protocol(); |
179 | if (aLibrary.IsNull()) return IFSelect_RetVoid; |
180 | if (aProtocol.IsNull()) return IFSelect_RetVoid; |
181 | Handle(StepData_StepModel) aStepModel = new StepData_StepModel; |
182 | aStepModel->InternalParameters.InitFromStatic(); |
183 | aStepModel->SetSourceCodePage(aStepModel->InternalParameters.ReadCodePage); |
184 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
185 | try { |
186 | OCC_CATCH_SIGNALS |
187 | Standard_Integer stat = aLibrary->ReadStream(theName, theIStream, aStepModel, aProtocol); |
188 | if (stat == 0) status = IFSelect_RetDone; |
189 | else if (stat < 0) status = IFSelect_RetError; |
190 | else status = IFSelect_RetFail; |
191 | } |
192 | catch (Standard_Failure const& anException) { |
193 | Message_Messenger::StreamBuffer sout = Message::SendInfo(); |
194 | sout << " **** Interruption ReadFile par Exception : ****\n"; |
195 | sout << anException.GetMessageString(); |
196 | sout << "\n Abandon" << std::endl; |
197 | status = IFSelect_RetFail; |
198 | } |
199 | if (status != IFSelect_RetDone) return status; |
200 | WS()->SetModel(aStepModel); |
201 | WS()->SetLoadedFile(theName); |
202 | WS()->InitTransferReader(4); |
203 | return status; |
204 | } |
205 | |
206 | //======================================================================= |
207 | //function : ReadStream |
208 | //purpose : |
209 | //======================================================================= |
210 | IFSelect_ReturnStatus STEPControl_Reader::ReadStream(const Standard_CString theName, |
211 | const StepData_ConfParameters& theParams, |
212 | std::istream& theIStream) |
213 | { |
214 | Handle(IFSelect_WorkLibrary) aLibrary = WS()->WorkLibrary(); |
215 | Handle(Interface_Protocol) aProtocol = WS()->Protocol(); |
216 | if (aLibrary.IsNull()) return IFSelect_RetVoid; |
217 | if (aProtocol.IsNull()) return IFSelect_RetVoid; |
218 | Handle(StepData_StepModel) aStepModel = new StepData_StepModel; |
219 | aStepModel->InternalParameters = theParams; |
220 | aStepModel->SetSourceCodePage(aStepModel->InternalParameters.ReadCodePage); |
221 | IFSelect_ReturnStatus status = IFSelect_RetVoid; |
222 | try { |
223 | OCC_CATCH_SIGNALS |
224 | Standard_Integer stat = aLibrary->ReadStream(theName, theIStream, aStepModel, aProtocol); |
225 | if (stat == 0) status = IFSelect_RetDone; |
226 | else if (stat < 0) status = IFSelect_RetError; |
227 | else status = IFSelect_RetFail; |
228 | } |
229 | catch (Standard_Failure const& anException) { |
230 | Message_Messenger::StreamBuffer sout = Message::SendInfo(); |
231 | sout << " **** Interruption ReadFile par Exception : ****\n"; |
232 | sout << anException.GetMessageString(); |
233 | sout << "\n Abandon" << std::endl; |
234 | status = IFSelect_RetFail; |
235 | } |
236 | if (status != IFSelect_RetDone) return status; |
237 | WS()->SetModel(aStepModel); |
238 | WS()->SetLoadedFile(theName); |
239 | WS()->InitTransferReader(4); |
240 | return status; |
241 | } |
242 | |
7fd59977 |
243 | //======================================================================= |
244 | //function : TransferRoot |
245 | //purpose : |
246 | //======================================================================= |
247 | |
7e785937 |
248 | Standard_Boolean STEPControl_Reader::TransferRoot (const Standard_Integer num, |
249 | const Message_ProgressRange& theProgress) |
7fd59977 |
250 | { |
7e785937 |
251 | return TransferOneRoot(num, theProgress); |
7fd59977 |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : NbRootsForTransfer |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | Standard_Integer STEPControl_Reader::NbRootsForTransfer() |
260 | { |
261 | if (therootsta) return theroots.Length(); |
262 | therootsta = Standard_True; |
263 | |
b9fbc699 |
264 | Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast(WS()->Model()); |
7fd59977 |
265 | //theroots.Clear(); |
266 | Standard_Integer nb = Model()->NbEntities(); |
267 | for (Standard_Integer i = 1; i <= nb; i ++) { |
268 | Handle(Standard_Transient) ent = Model()->Value(i); |
b9fbc699 |
269 | if (aStepModel->InternalParameters.ReadAllShapes == 1) { |
c6f530b8 |
270 | // Special case to read invalid shape_representation without links to shapes. |
271 | if (ent->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) { |
272 | Interface_EntityIterator aShareds = WS()->Graph().Sharings(ent); |
273 | if (!aShareds.More()) { |
274 | theroots.Append(ent); |
275 | WS()->TransferReader()->TransientProcess()->RootsForTransfer()->Append(ent); |
276 | } |
277 | } |
278 | if (ent->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) { |
279 | Interface_EntityIterator aShareds = WS()->Graph().Sharings(ent); |
280 | if (!aShareds.More()) { |
281 | theroots.Append(ent); |
282 | WS()->TransferReader()->TransientProcess()->RootsForTransfer()->Append(ent); |
283 | } |
284 | } |
285 | } |
7fd59977 |
286 | if(ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) { |
287 | // PTV 31.01.2003 TRJ11 exclude Product Definition With Associated Document from roots |
288 | if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments))) { |
289 | // check if PDWAD-> PDF <-Document_Product_Equivalence. |
290 | Standard_Boolean iSexclude = Standard_False; |
291 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD = |
292 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(ent); |
293 | Interface_EntityIterator PDWADsubs = WS()->Graph().Shareds(PDWAD); |
294 | for (PDWADsubs.Start(); PDWADsubs.More(); PDWADsubs.Next()) { |
295 | if ( !PDWADsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionFormation))) |
296 | continue; |
297 | Handle(StepBasic_ProductDefinitionFormation) localPDF = |
298 | Handle(StepBasic_ProductDefinitionFormation)::DownCast(PDWADsubs.Value()); |
299 | Interface_EntityIterator PDFsubs = WS()->Graph().Sharings(localPDF); |
300 | for( PDFsubs.Start(); PDFsubs.More(); PDFsubs.Next() ) |
301 | if (PDFsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_DocumentProductEquivalence))) { |
302 | iSexclude = Standard_True; |
303 | break; |
304 | } |
305 | if (iSexclude) |
306 | break; |
307 | } |
308 | if (iSexclude) { |
0797d9d3 |
309 | #ifdef OCCT_DEBUG |
04232180 |
310 | std::cout << "Warning: STEPControl_Reader::NbRootsForTransfer exclude PDWAD from roots" << std::endl; |
7fd59977 |
311 | #endif |
312 | continue; |
313 | } |
314 | } |
315 | Handle(StepBasic_ProductDefinition) PD = |
316 | Handle(StepBasic_ProductDefinition)::DownCast(ent); |
317 | Standard_Boolean IsRoot = Standard_True; |
318 | const Interface_Graph& graph = WS()->Graph(); |
319 | // determinate roots used NextAssemblyUsageOccurrence |
320 | Interface_EntityIterator subs = graph.Sharings(PD); |
321 | for(subs.Start(); subs.More(); subs.Next()) { |
322 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
323 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value()); |
324 | if (NAUO.IsNull()) continue; |
325 | if (PD==NAUO->RelatedProductDefinition()) IsRoot=Standard_False; |
326 | } |
327 | // determinate roots used ProductDefinitionContext |
328 | if(IsRoot) { |
b9fbc699 |
329 | StepData_ConfParameters::ReadMode_ProductContext aProdContMode = aStepModel->InternalParameters.ReadProductContext; |
330 | TCollection_AsciiString str1 = aStepModel->InternalParameters.GetString(aProdContMode); |
331 | Standard_Integer ICS = aStepModel->InternalParameters.ReadProductContext; |
7fd59977 |
332 | if(ICS>1) { |
333 | subs = graph.Shareds(PD); |
334 | for(subs.Start(); subs.More(); subs.Next()) { |
335 | Handle(StepBasic_ProductDefinitionContext) PDC = |
336 | Handle(StepBasic_ProductDefinitionContext)::DownCast(subs.Value()); |
337 | if (PDC.IsNull()) continue; |
338 | const char *str2 = PDC->LifeCycleStage()->String().ToCString(); |
339 | const char *str3 = PDC->Name()->String().ToCString(); |
b9fbc699 |
340 | if( !( strcasecmp(str1.ToCString(),str2)==0 || strcasecmp(str1.ToCString(),str3) == 0)) |
7fd59977 |
341 | IsRoot=Standard_False; |
342 | } |
343 | } |
344 | } |
345 | // determinate roots used ProductDefinitionFormationRelationship |
346 | //subs = graph.Shareds(PD); |
347 | //for(subs.Start(); subs.More(); subs.Next()) { |
348 | // Handle(StepBasic_ProductDefinitionFormation) PDF = |
349 | // Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value()); |
350 | // if (PDF.IsNull()) continue; |
351 | // Interface_EntityIterator subs1 = graph.Sharings(PDF); |
352 | // for(subs1.Start(); subs1.More(); subs1.Next()) { |
353 | // Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = |
354 | // Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs1.Value()); |
355 | // if (PDFR.IsNull()) continue; |
356 | // if (PDF==PDFR->RelatedProductDefinition()) IsRoot=Standard_False; |
357 | // } |
358 | //} |
359 | if (IsRoot) { |
360 | theroots.Append(ent); |
7f56eba8 |
361 | WS()->TransferReader()->TransientProcess()->RootsForTransfer()->Append(ent); |
7fd59977 |
362 | } |
363 | } |
b9fbc699 |
364 | bool aProdMode = aStepModel->InternalParameters.ReadProductMode; |
365 | if(!aProdMode) { |
7fd59977 |
366 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) { |
367 | Standard_Boolean IsRoot = Standard_True; |
368 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
369 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(ent); |
370 | Handle(StepRepr_PropertyDefinition) PropDef = SDR->Definition().PropertyDefinition(); |
371 | if(!PropDef.IsNull()) { |
372 | Handle(StepBasic_ProductDefinition) PD = PropDef->Definition().ProductDefinition(); |
373 | if(!PD.IsNull()) IsRoot = Standard_False; |
374 | if(IsRoot) { |
375 | Handle(StepRepr_ShapeAspect) SA = PropDef->Definition().ShapeAspect(); |
376 | if(!SA.IsNull()) { |
377 | Handle(StepRepr_ProductDefinitionShape) PDS = SA->OfShape(); |
378 | PD = PDS->Definition().ProductDefinition(); |
379 | if(!PD.IsNull()) IsRoot = Standard_False; |
380 | } |
381 | } |
382 | if(IsRoot) { |
383 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
384 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(PropDef->Definition().ProductDefinitionRelationship()); |
385 | if(!NAUO.IsNull()) IsRoot = Standard_False; |
386 | } |
387 | if(IsRoot) { |
388 | Handle(StepShape_ShapeRepresentation) SR = |
389 | Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); |
390 | if(SR.IsNull()) IsRoot = Standard_False; |
391 | } |
392 | } |
393 | if(IsRoot) { |
394 | theroots.Append(ent); |
7f56eba8 |
395 | WS()->TransferReader()->TransientProcess()->RootsForTransfer()->Append(ent); |
7fd59977 |
396 | } |
397 | } |
398 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) { |
399 | Standard_Boolean IsRoot = Standard_True; |
400 | Handle(StepShape_ShapeRepresentation) SR = |
401 | Handle(StepShape_ShapeRepresentation)::DownCast(ent); |
402 | const Interface_Graph& graph = WS()->Graph(); |
403 | Interface_EntityIterator subs = graph.Sharings(SR); |
404 | for(subs.Start(); subs.More() && IsRoot; subs.Next()) { |
405 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
406 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); |
407 | if(!SDR.IsNull()) IsRoot = Standard_False; |
408 | if(IsRoot) { |
409 | Handle(StepRepr_RepresentationRelationship) RR = |
410 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs.Value()); |
411 | if(!RR.IsNull()) { |
412 | Handle(StepShape_ShapeRepresentation) SR2 = |
413 | Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); |
414 | if(SR==SR2) |
415 | SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); |
a965c45b |
416 | if(!SR2.IsNull()) |
417 | { |
418 | Interface_EntityIterator subs2 = graph.Sharings(SR2); |
419 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
420 | Handle(StepShape_ShapeDefinitionRepresentation) SDR2 = |
421 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); |
422 | if(!SDR2.IsNull()) IsRoot = Standard_False; |
423 | //else { |
424 | // if(SR==SRR->Rep2()) IsRoot = Standard_False; |
425 | //} |
426 | } |
7fd59977 |
427 | } |
428 | } |
429 | } |
430 | if(IsRoot) { |
431 | Handle(StepRepr_RepresentationMap) RM = |
432 | Handle(StepRepr_RepresentationMap)::DownCast(subs.Value()); |
433 | if(!RM.IsNull()) { |
434 | Interface_EntityIterator subs2 = graph.Sharings(RM); |
435 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
436 | Handle(StepRepr_MappedItem) MI = Handle(StepRepr_MappedItem)::DownCast(subs2.Value()); |
437 | if(!MI.IsNull()) { |
438 | Interface_EntityIterator subs3 = graph.Sharings(MI); |
439 | for(subs3.Start(); subs3.More(); subs3.Next()) { |
440 | Handle(StepShape_ShapeRepresentation) SR2 = |
441 | Handle(StepShape_ShapeRepresentation)::DownCast(subs3.Value()); |
442 | if(!SR2.IsNull()) IsRoot = Standard_False; |
443 | } |
444 | } |
445 | } |
446 | } |
447 | } |
448 | } |
449 | if(IsRoot) { |
450 | theroots.Append(ent); |
7f56eba8 |
451 | WS()->TransferReader()->TransientProcess()->RootsForTransfer()->Append(ent); |
7fd59977 |
452 | } |
453 | } |
454 | } |
455 | |
456 | } |
457 | |
458 | |
459 | return theroots.Length(); |
460 | } |
461 | |
d402d481 |
462 | //======================================================================= |
463 | //function : FileUnits |
464 | //purpose : |
465 | //======================================================================= |
466 | |
467 | void STEPControl_Reader::FileUnits( TColStd_SequenceOfAsciiString& theUnitLengthNames, |
468 | TColStd_SequenceOfAsciiString& theUnitAngleNames, |
469 | TColStd_SequenceOfAsciiString& theUnitSolidAngleNames) |
470 | { |
471 | Standard_Integer nbroots = NbRootsForTransfer(); |
472 | if(!nbroots) |
473 | return; |
474 | enum |
475 | { |
476 | LENGTH = 0, |
477 | ANLGE = 1, |
478 | SOLID_ANGLE = 2 |
479 | }; |
480 | const Interface_Graph& graph = WS()->Graph(); |
481 | TColStd_MapOfAsciiString aMapUnits[3]; |
482 | |
51740958 |
483 | for(Standard_Integer i = 1; i <= nbroots; i++) |
d402d481 |
484 | { |
485 | Handle(Standard_Transient) anEnt = theroots(i); |
486 | Standard_Integer num = graph.EntityNumber(anEnt); |
487 | if(!num ) |
488 | continue; |
489 | Handle(StepBasic_ProductDefinition) aProdDef = |
490 | Handle(StepBasic_ProductDefinition)::DownCast(anEnt); |
491 | Handle(StepShape_ShapeDefinitionRepresentation) aShapeDefRepr; |
492 | if(!aProdDef.IsNull()) |
493 | { |
494 | Interface_EntityIterator subsPD = graph.Sharings(aProdDef); |
495 | for(subsPD.Start(); subsPD.More() && aShapeDefRepr.IsNull(); subsPD.Next()) |
496 | { |
497 | Handle(StepRepr_ProductDefinitionShape) aProdDefShape = |
498 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subsPD.Value()); |
499 | if(aProdDefShape.IsNull()) |
500 | continue; |
501 | Interface_EntityIterator subsSR = graph.Sharings(aProdDefShape); |
502 | Handle(StepShape_ShapeRepresentation) SR; |
503 | for(subsSR.Start(); subsSR.More() && aShapeDefRepr.IsNull(); subsSR.Next()) |
504 | { |
505 | Handle(StepShape_ShapeDefinitionRepresentation) aCurShapeDefRepr = |
506 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subsSR.Value()); |
507 | if(aCurShapeDefRepr.IsNull()) |
508 | continue; |
509 | Handle(StepRepr_Representation) aUseRepr = aCurShapeDefRepr->UsedRepresentation(); |
510 | if(aUseRepr.IsNull()) |
511 | continue; |
512 | Handle(StepShape_ShapeRepresentation) aShapeRepr = |
513 | Handle(StepShape_ShapeRepresentation)::DownCast(aUseRepr); |
514 | if(aShapeRepr.IsNull()) |
515 | continue; |
516 | aShapeDefRepr = aCurShapeDefRepr; |
517 | |
518 | } |
519 | |
520 | |
521 | } |
522 | |
523 | } |
524 | else |
525 | aShapeDefRepr = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEnt); |
526 | if(!aShapeDefRepr.IsNull()) |
527 | { |
528 | Handle(StepShape_ShapeRepresentation) aShapeRepr = |
529 | Handle(StepShape_ShapeRepresentation)::DownCast(aShapeDefRepr->UsedRepresentation()); |
530 | Handle(StepRepr_RepresentationContext) aRepCont = aShapeRepr->ContextOfItems(); |
531 | if (aRepCont.IsNull()) |
532 | continue; |
533 | TColStd_Array1OfAsciiString aNameUnits(1,3); |
534 | TColStd_Array1OfReal aFactorUnits(1,3); |
535 | if(findUnits(aRepCont,aNameUnits,aFactorUnits)) |
536 | { |
537 | Standard_Integer k = LENGTH; |
538 | for ( ; k <= SOLID_ANGLE ; k++) |
539 | { |
540 | if(!aMapUnits[k].Contains(aNameUnits(k+1))) |
541 | { |
542 | aMapUnits[k].Add(aNameUnits(k+1)); |
543 | TColStd_SequenceOfAsciiString& anUnitSeq = (k == LENGTH ? |
544 | theUnitLengthNames : ( k == ANLGE ? theUnitAngleNames : theUnitSolidAngleNames )); |
545 | anUnitSeq.Append(aNameUnits(k+1)); |
546 | } |
547 | } |
548 | } |
549 | |
550 | } |
551 | |
552 | } |
553 | //for case when units was not found through PDF or SDR |
554 | if(theUnitLengthNames.IsEmpty()) |
555 | { |
7f56eba8 |
556 | const Handle(Interface_InterfaceModel) &aModel = WS()->Model(); |
d402d481 |
557 | if(aModel.IsNull()) |
558 | return; |
51740958 |
559 | Standard_Integer nb = aModel->NbEntities(); |
560 | for(Standard_Integer i = 1; i <= nb; i++) |
d402d481 |
561 | { |
562 | Handle(Standard_Transient) anEnt = aModel->Value(i); |
563 | Handle(StepRepr_RepresentationContext) aRepCont = Handle(StepRepr_RepresentationContext)::DownCast(anEnt); |
564 | if (aRepCont.IsNull()) |
565 | continue; |
566 | TColStd_Array1OfAsciiString aNameUnits(1,3); |
567 | TColStd_Array1OfReal aFactorUnits(1,3); |
568 | if(findUnits(aRepCont,aNameUnits,aFactorUnits)) |
569 | { |
570 | Standard_Integer k = LENGTH; |
571 | for ( ; k <= SOLID_ANGLE ; k++) |
572 | { |
573 | if(!aMapUnits[k].Contains(aNameUnits(k+1))) |
574 | { |
575 | aMapUnits[k].Add(aNameUnits(k+1)); |
576 | TColStd_SequenceOfAsciiString& anUnitSeq = (k == LENGTH ? |
577 | theUnitLengthNames : ( k == ANLGE ? theUnitAngleNames : theUnitSolidAngleNames )); |
578 | anUnitSeq.Append(aNameUnits(k+1)); |
579 | } |
580 | } |
581 | } |
582 | } |
583 | } |
584 | } |
585 | |
da80ff68 |
586 | //======================================================================= |
587 | //function : SetSystemLengthUnit |
588 | //purpose : |
589 | //======================================================================= |
590 | void STEPControl_Reader::SetSystemLengthUnit(const Standard_Real theLengthUnit) |
591 | { |
b9fbc699 |
592 | if (StepModel().IsNull()) |
593 | { |
594 | return; |
595 | } |
da80ff68 |
596 | StepModel()->SetLocalLengthUnit(theLengthUnit); |
597 | } |
598 | |
599 | //======================================================================= |
600 | //function : SystemLengthUnit |
601 | //purpose : |
602 | //======================================================================= |
603 | Standard_Real STEPControl_Reader::SystemLengthUnit() const |
604 | { |
b9fbc699 |
605 | if (StepModel().IsNull()) |
606 | { |
607 | return 1.; |
608 | } |
da80ff68 |
609 | return StepModel()->LocalLengthUnit(); |
610 | } |
611 | |
d402d481 |
612 | //======================================================================= |
613 | //function : getSiName |
614 | //purpose : |
615 | //======================================================================= |
616 | |
e9c15c4c |
617 | inline static TCollection_AsciiString getSiName(const Handle(StepBasic_SiUnit)& theUnit) |
d402d481 |
618 | { |
619 | |
620 | TCollection_AsciiString aName; |
e9c15c4c |
621 | if (theUnit->HasPrefix()) { |
622 | switch (theUnit->Prefix()) { |
623 | case StepBasic_spExa: aName += "exa"; break; |
624 | case StepBasic_spPeta: aName += "peta"; break; |
625 | case StepBasic_spTera: aName += "tera"; break; |
626 | case StepBasic_spGiga: aName += "giga"; break; |
627 | case StepBasic_spMega: aName += "mega"; break; |
628 | case StepBasic_spHecto: aName += "hecto"; break; |
629 | case StepBasic_spDeca: aName += "deca"; break; |
630 | case StepBasic_spDeci: aName += "deci"; break; |
631 | |
632 | case StepBasic_spPico: aName += "pico"; break; |
633 | case StepBasic_spFemto: aName += "femto"; break; |
634 | case StepBasic_spAtto: aName += "atto"; break; |
635 | |
636 | case StepBasic_spKilo : aName += "kilo"; break; |
637 | case StepBasic_spCenti :aName += "centi"; break; |
638 | case StepBasic_spMilli :aName += "milli"; break; |
639 | case StepBasic_spMicro :aName += "micro"; break; |
640 | case StepBasic_spNano :aName += "nano"; break; |
641 | default: break; |
d402d481 |
642 | }; |
e9c15c4c |
643 | } |
d402d481 |
644 | |
e9c15c4c |
645 | switch(theUnit->Name()) { |
d402d481 |
646 | case StepBasic_sunMetre : aName += "metre"; break; |
647 | case StepBasic_sunRadian : aName += "radian"; break; |
648 | case StepBasic_sunSteradian : aName += "steradian"; break; |
649 | default: break; |
650 | }; |
651 | return aName; |
652 | } |
653 | |
654 | //======================================================================= |
655 | //function : findUnits |
656 | //purpose : |
657 | //======================================================================= |
658 | |
659 | Standard_Boolean STEPControl_Reader::findUnits( |
660 | const Handle(StepRepr_RepresentationContext)& theRepCont, |
661 | TColStd_Array1OfAsciiString& theNameUnits, |
662 | TColStd_Array1OfReal& theFactorUnits) |
663 | { |
664 | Handle(StepRepr_GlobalUnitAssignedContext) aContext; |
665 | Handle(StepRepr_GlobalUncertaintyAssignedContext) aTol; |
666 | |
667 | if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) { |
668 | aContext = Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext):: |
669 | DownCast(theRepCont)->GlobalUnitAssignedContext(); |
670 | } |
671 | |
672 | |
673 | if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) { |
674 | aContext = Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx):: |
675 | DownCast(theRepCont)->GlobalUnitAssignedContext(); |
676 | |
677 | } |
678 | if(aContext.IsNull()) |
679 | return Standard_False; |
680 | // Start Computation |
681 | Handle(StepBasic_HArray1OfNamedUnit) anUnits = aContext->Units(); |
682 | Standard_Integer nbU = aContext->NbUnits(); |
683 | Standard_Integer nbFind = 0; |
684 | for (Standard_Integer i = 1; i <= nbU; i++) { |
685 | Handle(StepBasic_NamedUnit) aNamedUnit = aContext->UnitsValue(i); |
686 | Handle(StepBasic_ConversionBasedUnit) aConvUnit = |
687 | Handle(StepBasic_ConversionBasedUnit)::DownCast(aNamedUnit); |
688 | Standard_Integer anInd = 0; |
689 | TCollection_AsciiString aName; |
690 | Standard_Real anUnitFact = 0; |
691 | if( !aConvUnit.IsNull() ) |
692 | { |
693 | Handle(StepBasic_MeasureWithUnit) aMeasWithUnit = |
694 | aConvUnit->ConversionFactor(); |
695 | |
696 | if(aMeasWithUnit.IsNull()) |
697 | continue; |
698 | |
699 | if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ) |
700 | anInd = 1; |
701 | else if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ) |
702 | anInd = 2; |
703 | else if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_SolidAngleMeasureWithUnit)) ) |
704 | anInd = 3; |
705 | if(!anInd) |
706 | continue; |
707 | aName = aConvUnit->Name()->String(); |
708 | anUnitFact = aMeasWithUnit->ValueComponent(); |
709 | } |
710 | else |
711 | { |
712 | Handle(StepBasic_SiUnit) aSiUnit = Handle(StepBasic_SiUnit)::DownCast(aNamedUnit); |
713 | if( aSiUnit.IsNull()) |
714 | continue; |
715 | if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) |
716 | anInd =1; |
717 | else if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) |
718 | anInd = 2; |
719 | else if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndSolidAngleUnit))) |
720 | anInd = 3; |
721 | if( !anInd ) |
722 | continue; |
723 | anUnitFact = (!aSiUnit->HasPrefix() ? |
724 | 1. : STEPConstruct_UnitContext::ConvertSiPrefix(aSiUnit->Prefix())); |
e9c15c4c |
725 | aName = getSiName(aSiUnit); |
d402d481 |
726 | |
727 | |
728 | } |
729 | if( !anInd ) |
730 | continue; |
731 | |
732 | theNameUnits.SetValue(anInd, aName); |
733 | theFactorUnits.SetValue(anInd, anUnitFact); |
734 | nbFind++; |
735 | |
736 | } |
dde68833 |
737 | |
738 | return nbFind != 0; |
d402d481 |
739 | } |