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 | #include <STEPControl_Reader.ixx> |
15 | #include <STEPControl_Controller.hxx> |
16 | #include <XSControl_Controller.hxx> |
17 | #include <XSControl_TransferReader.hxx> |
18 | #include <Interface_ShareFlags.hxx> |
19 | |
20 | #include <STEPControl_ActorRead.hxx> |
21 | |
22 | #include <StepBasic_ProductDefinition.hxx> |
23 | #include <Interface_EntityIterator.hxx> |
24 | #include <Interface_Graph.hxx> |
25 | #include <Interface_Static.hxx> |
26 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
27 | #include <StepBasic_ProductDefinitionContext.hxx> |
28 | #include <StepBasic_ApplicationContext.hxx> |
29 | #include <TCollection_AsciiString.hxx> |
30 | #include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx> |
31 | #include <StepBasic_DocumentProductEquivalence.hxx> |
32 | #include <StepShape_ShapeDefinitionRepresentation.hxx> |
33 | #include <StepShape_ShapeRepresentation.hxx> |
34 | #include <StepRepr_PropertyDefinition.hxx> |
35 | #include <StepRepr_RepresentationRelationship.hxx> |
36 | #include <StepRepr_ShapeAspect.hxx> |
37 | #include <StepRepr_ProductDefinitionShape.hxx> |
38 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
39 | #include <StepRepr_RepresentationMap.hxx> |
40 | #include <StepRepr_MappedItem.hxx> |
41 | #include <Transfer_TransientProcess.hxx> |
42 | #include <TColStd_HSequenceOfTransient.hxx> |
d402d481 |
43 | #include <TColStd_MapOfAsciiString.hxx> |
44 | #include <StepBasic_SiUnitName.hxx> |
45 | #include <StepBasic_SiPrefix.hxx> |
46 | #include <StepRepr_GlobalUnitAssignedContext.hxx> |
47 | #include <StepRepr_RepresentationContext.hxx> |
48 | #include <StepRepr_GlobalUncertaintyAssignedContext.hxx> |
49 | #include <StepRepr_GlobalUncertaintyAssignedContext.hxx> |
50 | #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx> |
51 | #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx> |
52 | #include <StepBasic_HArray1OfNamedUnit.hxx> |
53 | #include <StepBasic_NamedUnit.hxx> |
54 | #include <StepBasic_ConversionBasedUnit.hxx> |
55 | #include <StepBasic_SiUnitAndLengthUnit.hxx> |
56 | #include <StepBasic_SiUnitAndLengthUnit.hxx> |
57 | #include <StepBasic_SolidAngleUnit.hxx> |
58 | #include <StepBasic_MeasureWithUnit.hxx> |
59 | #include <StepBasic_LengthMeasureWithUnit.hxx> |
60 | #include <StepBasic_PlaneAngleMeasureWithUnit.hxx> |
61 | #include <StepBasic_SolidAngleMeasureWithUnit.hxx> |
62 | #include <STEPConstruct_UnitContext.hxx> |
63 | #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx> |
64 | #include <StepBasic_SiUnitAndSolidAngleUnit.hxx> |
65 | #include <XSControl_WorkSession.hxx> |
66 | #include <StepData_StepModel.hxx> |
67 | #include <TColStd_SequenceOfAsciiString.hxx> |
68 | #include <StepRepr_RepresentationContext.hxx> |
69 | #include <TColStd_Array1OfAsciiString.hxx> |
70 | #include <TColStd_Array1OfReal.hxx> |
71 | |
7fd59977 |
72 | //======================================================================= |
73 | //function : STEPControl_Reader |
74 | //purpose : |
75 | //======================================================================= |
76 | |
77 | STEPControl_Reader::STEPControl_Reader () |
78 | { |
79 | STEPControl_Controller::Init(); |
80 | SetNorm ("STEP"); |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : STEPControl_Reader |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | STEPControl_Reader::STEPControl_Reader |
89 | (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch) |
90 | { |
91 | STEPControl_Controller::Init(); |
92 | SetWS (WS,scratch); |
93 | SetNorm ("STEP"); |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : StepModel |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | Handle(StepData_StepModel) STEPControl_Reader::StepModel () const |
102 | { |
103 | return Handle(StepData_StepModel)::DownCast(Model()); |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : TransferRoot |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | Standard_Boolean STEPControl_Reader::TransferRoot (const Standard_Integer num) |
112 | { |
113 | return TransferOneRoot (num); |
114 | } |
115 | |
116 | //======================================================================= |
117 | //function : NbRootsForTransfer |
118 | //purpose : |
119 | //======================================================================= |
120 | |
121 | Standard_Integer STEPControl_Reader::NbRootsForTransfer() |
122 | { |
123 | if (therootsta) return theroots.Length(); |
124 | therootsta = Standard_True; |
125 | |
126 | //theroots.Clear(); |
127 | Standard_Integer nb = Model()->NbEntities(); |
128 | for (Standard_Integer i = 1; i <= nb; i ++) { |
129 | Handle(Standard_Transient) ent = Model()->Value(i); |
130 | if(ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) { |
131 | // PTV 31.01.2003 TRJ11 exclude Product Definition With Associated Document from roots |
132 | if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments))) { |
133 | // check if PDWAD-> PDF <-Document_Product_Equivalence. |
134 | Standard_Boolean iSexclude = Standard_False; |
135 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD = |
136 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(ent); |
137 | Interface_EntityIterator PDWADsubs = WS()->Graph().Shareds(PDWAD); |
138 | for (PDWADsubs.Start(); PDWADsubs.More(); PDWADsubs.Next()) { |
139 | if ( !PDWADsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionFormation))) |
140 | continue; |
141 | Handle(StepBasic_ProductDefinitionFormation) localPDF = |
142 | Handle(StepBasic_ProductDefinitionFormation)::DownCast(PDWADsubs.Value()); |
143 | Interface_EntityIterator PDFsubs = WS()->Graph().Sharings(localPDF); |
144 | for( PDFsubs.Start(); PDFsubs.More(); PDFsubs.Next() ) |
145 | if (PDFsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_DocumentProductEquivalence))) { |
146 | iSexclude = Standard_True; |
147 | break; |
148 | } |
149 | if (iSexclude) |
150 | break; |
151 | } |
152 | if (iSexclude) { |
153 | #ifdef DEB |
154 | cout << "Warning: STEPControl_Reader::NbRootsForTransfer exclude PDWAD from roots" << endl; |
155 | #endif |
156 | continue; |
157 | } |
158 | } |
159 | Handle(StepBasic_ProductDefinition) PD = |
160 | Handle(StepBasic_ProductDefinition)::DownCast(ent); |
161 | Standard_Boolean IsRoot = Standard_True; |
162 | const Interface_Graph& graph = WS()->Graph(); |
163 | // determinate roots used NextAssemblyUsageOccurrence |
164 | Interface_EntityIterator subs = graph.Sharings(PD); |
165 | for(subs.Start(); subs.More(); subs.Next()) { |
166 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
167 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value()); |
168 | if (NAUO.IsNull()) continue; |
169 | if (PD==NAUO->RelatedProductDefinition()) IsRoot=Standard_False; |
170 | } |
171 | // determinate roots used ProductDefinitionContext |
172 | if(IsRoot) { |
173 | const char *str1 = Interface_Static::CVal("read.step.product.context"); |
174 | Standard_Integer ICS = Interface_Static::IVal("read.step.product.context"); |
175 | if(ICS>1) { |
176 | subs = graph.Shareds(PD); |
177 | for(subs.Start(); subs.More(); subs.Next()) { |
178 | Handle(StepBasic_ProductDefinitionContext) PDC = |
179 | Handle(StepBasic_ProductDefinitionContext)::DownCast(subs.Value()); |
180 | if (PDC.IsNull()) continue; |
181 | const char *str2 = PDC->LifeCycleStage()->String().ToCString(); |
182 | const char *str3 = PDC->Name()->String().ToCString(); |
183 | if( !( strcasecmp(str1,str2)==0 || strcasecmp(str1,str3)==0 ) ) |
184 | IsRoot=Standard_False; |
185 | } |
186 | } |
187 | } |
188 | // determinate roots used ProductDefinitionFormationRelationship |
189 | //subs = graph.Shareds(PD); |
190 | //for(subs.Start(); subs.More(); subs.Next()) { |
191 | // Handle(StepBasic_ProductDefinitionFormation) PDF = |
192 | // Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value()); |
193 | // if (PDF.IsNull()) continue; |
194 | // Interface_EntityIterator subs1 = graph.Sharings(PDF); |
195 | // for(subs1.Start(); subs1.More(); subs1.Next()) { |
196 | // Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = |
197 | // Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs1.Value()); |
198 | // if (PDFR.IsNull()) continue; |
199 | // if (PDF==PDFR->RelatedProductDefinition()) IsRoot=Standard_False; |
200 | // } |
201 | //} |
202 | if (IsRoot) { |
203 | theroots.Append(ent); |
204 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
205 | } |
206 | } |
207 | TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode"); |
208 | if(!aProdMode.IsEqual("ON")) { |
209 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) { |
210 | Standard_Boolean IsRoot = Standard_True; |
211 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
212 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(ent); |
213 | Handle(StepRepr_PropertyDefinition) PropDef = SDR->Definition().PropertyDefinition(); |
214 | if(!PropDef.IsNull()) { |
215 | Handle(StepBasic_ProductDefinition) PD = PropDef->Definition().ProductDefinition(); |
216 | if(!PD.IsNull()) IsRoot = Standard_False; |
217 | if(IsRoot) { |
218 | Handle(StepRepr_ShapeAspect) SA = PropDef->Definition().ShapeAspect(); |
219 | if(!SA.IsNull()) { |
220 | Handle(StepRepr_ProductDefinitionShape) PDS = SA->OfShape(); |
221 | PD = PDS->Definition().ProductDefinition(); |
222 | if(!PD.IsNull()) IsRoot = Standard_False; |
223 | } |
224 | } |
225 | if(IsRoot) { |
226 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
227 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(PropDef->Definition().ProductDefinitionRelationship()); |
228 | if(!NAUO.IsNull()) IsRoot = Standard_False; |
229 | } |
230 | if(IsRoot) { |
231 | Handle(StepShape_ShapeRepresentation) SR = |
232 | Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); |
233 | if(SR.IsNull()) IsRoot = Standard_False; |
234 | } |
235 | } |
236 | if(IsRoot) { |
237 | theroots.Append(ent); |
238 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
239 | } |
240 | } |
241 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) { |
242 | Standard_Boolean IsRoot = Standard_True; |
243 | Handle(StepShape_ShapeRepresentation) SR = |
244 | Handle(StepShape_ShapeRepresentation)::DownCast(ent); |
245 | const Interface_Graph& graph = WS()->Graph(); |
246 | Interface_EntityIterator subs = graph.Sharings(SR); |
247 | for(subs.Start(); subs.More() && IsRoot; subs.Next()) { |
248 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
249 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); |
250 | if(!SDR.IsNull()) IsRoot = Standard_False; |
251 | if(IsRoot) { |
252 | Handle(StepRepr_RepresentationRelationship) RR = |
253 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs.Value()); |
254 | if(!RR.IsNull()) { |
255 | Handle(StepShape_ShapeRepresentation) SR2 = |
256 | Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); |
257 | if(SR==SR2) |
258 | SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); |
259 | Interface_EntityIterator subs2 = graph.Sharings(SR2); |
260 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
261 | Handle(StepShape_ShapeDefinitionRepresentation) SDR2 = |
262 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); |
263 | if(!SDR2.IsNull()) IsRoot = Standard_False; |
264 | //else { |
265 | // if(SR==SRR->Rep2()) IsRoot = Standard_False; |
266 | //} |
267 | } |
268 | } |
269 | } |
270 | if(IsRoot) { |
271 | Handle(StepRepr_RepresentationMap) RM = |
272 | Handle(StepRepr_RepresentationMap)::DownCast(subs.Value()); |
273 | if(!RM.IsNull()) { |
274 | Interface_EntityIterator subs2 = graph.Sharings(RM); |
275 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
276 | Handle(StepRepr_MappedItem) MI = Handle(StepRepr_MappedItem)::DownCast(subs2.Value()); |
277 | if(!MI.IsNull()) { |
278 | Interface_EntityIterator subs3 = graph.Sharings(MI); |
279 | for(subs3.Start(); subs3.More(); subs3.Next()) { |
280 | Handle(StepShape_ShapeRepresentation) SR2 = |
281 | Handle(StepShape_ShapeRepresentation)::DownCast(subs3.Value()); |
282 | if(!SR2.IsNull()) IsRoot = Standard_False; |
283 | } |
284 | } |
285 | } |
286 | } |
287 | } |
288 | } |
289 | if(IsRoot) { |
290 | theroots.Append(ent); |
291 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
292 | } |
293 | } |
294 | } |
295 | |
296 | } |
297 | |
298 | |
299 | return theroots.Length(); |
300 | } |
301 | |
d402d481 |
302 | //======================================================================= |
303 | //function : FileUnits |
304 | //purpose : |
305 | //======================================================================= |
306 | |
307 | void STEPControl_Reader::FileUnits( TColStd_SequenceOfAsciiString& theUnitLengthNames, |
308 | TColStd_SequenceOfAsciiString& theUnitAngleNames, |
309 | TColStd_SequenceOfAsciiString& theUnitSolidAngleNames) |
310 | { |
311 | Standard_Integer nbroots = NbRootsForTransfer(); |
312 | if(!nbroots) |
313 | return; |
314 | enum |
315 | { |
316 | LENGTH = 0, |
317 | ANLGE = 1, |
318 | SOLID_ANGLE = 2 |
319 | }; |
320 | const Interface_Graph& graph = WS()->Graph(); |
321 | TColStd_MapOfAsciiString aMapUnits[3]; |
322 | |
323 | Standard_Integer i =1; |
324 | for( ; i <= nbroots; i++) |
325 | { |
326 | Handle(Standard_Transient) anEnt = theroots(i); |
327 | Standard_Integer num = graph.EntityNumber(anEnt); |
328 | if(!num ) |
329 | continue; |
330 | Handle(StepBasic_ProductDefinition) aProdDef = |
331 | Handle(StepBasic_ProductDefinition)::DownCast(anEnt); |
332 | Handle(StepShape_ShapeDefinitionRepresentation) aShapeDefRepr; |
333 | if(!aProdDef.IsNull()) |
334 | { |
335 | Interface_EntityIterator subsPD = graph.Sharings(aProdDef); |
336 | for(subsPD.Start(); subsPD.More() && aShapeDefRepr.IsNull(); subsPD.Next()) |
337 | { |
338 | Handle(StepRepr_ProductDefinitionShape) aProdDefShape = |
339 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subsPD.Value()); |
340 | if(aProdDefShape.IsNull()) |
341 | continue; |
342 | Interface_EntityIterator subsSR = graph.Sharings(aProdDefShape); |
343 | Handle(StepShape_ShapeRepresentation) SR; |
344 | for(subsSR.Start(); subsSR.More() && aShapeDefRepr.IsNull(); subsSR.Next()) |
345 | { |
346 | Handle(StepShape_ShapeDefinitionRepresentation) aCurShapeDefRepr = |
347 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subsSR.Value()); |
348 | if(aCurShapeDefRepr.IsNull()) |
349 | continue; |
350 | Handle(StepRepr_Representation) aUseRepr = aCurShapeDefRepr->UsedRepresentation(); |
351 | if(aUseRepr.IsNull()) |
352 | continue; |
353 | Handle(StepShape_ShapeRepresentation) aShapeRepr = |
354 | Handle(StepShape_ShapeRepresentation)::DownCast(aUseRepr); |
355 | if(aShapeRepr.IsNull()) |
356 | continue; |
357 | aShapeDefRepr = aCurShapeDefRepr; |
358 | |
359 | } |
360 | |
361 | |
362 | } |
363 | |
364 | } |
365 | else |
366 | aShapeDefRepr = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEnt); |
367 | if(!aShapeDefRepr.IsNull()) |
368 | { |
369 | Handle(StepShape_ShapeRepresentation) aShapeRepr = |
370 | Handle(StepShape_ShapeRepresentation)::DownCast(aShapeDefRepr->UsedRepresentation()); |
371 | Handle(StepRepr_RepresentationContext) aRepCont = aShapeRepr->ContextOfItems(); |
372 | if (aRepCont.IsNull()) |
373 | continue; |
374 | TColStd_Array1OfAsciiString aNameUnits(1,3); |
375 | TColStd_Array1OfReal aFactorUnits(1,3); |
376 | if(findUnits(aRepCont,aNameUnits,aFactorUnits)) |
377 | { |
378 | Standard_Integer k = LENGTH; |
379 | for ( ; k <= SOLID_ANGLE ; k++) |
380 | { |
381 | if(!aMapUnits[k].Contains(aNameUnits(k+1))) |
382 | { |
383 | aMapUnits[k].Add(aNameUnits(k+1)); |
384 | TColStd_SequenceOfAsciiString& anUnitSeq = (k == LENGTH ? |
385 | theUnitLengthNames : ( k == ANLGE ? theUnitAngleNames : theUnitSolidAngleNames )); |
386 | anUnitSeq.Append(aNameUnits(k+1)); |
387 | } |
388 | } |
389 | } |
390 | |
391 | } |
392 | |
393 | } |
394 | //for case when units was not found through PDF or SDR |
395 | if(theUnitLengthNames.IsEmpty()) |
396 | { |
397 | Handle(Interface_InterfaceModel) aModel = WS()->Model(); |
398 | if(aModel.IsNull()) |
399 | return; |
400 | Standard_Integer i = 1, nb = aModel->NbEntities(); |
401 | for( ; i <= nb; i++) |
402 | { |
403 | Handle(Standard_Transient) anEnt = aModel->Value(i); |
404 | Handle(StepRepr_RepresentationContext) aRepCont = Handle(StepRepr_RepresentationContext)::DownCast(anEnt); |
405 | if (aRepCont.IsNull()) |
406 | continue; |
407 | TColStd_Array1OfAsciiString aNameUnits(1,3); |
408 | TColStd_Array1OfReal aFactorUnits(1,3); |
409 | if(findUnits(aRepCont,aNameUnits,aFactorUnits)) |
410 | { |
411 | Standard_Integer k = LENGTH; |
412 | for ( ; k <= SOLID_ANGLE ; k++) |
413 | { |
414 | if(!aMapUnits[k].Contains(aNameUnits(k+1))) |
415 | { |
416 | aMapUnits[k].Add(aNameUnits(k+1)); |
417 | TColStd_SequenceOfAsciiString& anUnitSeq = (k == LENGTH ? |
418 | theUnitLengthNames : ( k == ANLGE ? theUnitAngleNames : theUnitSolidAngleNames )); |
419 | anUnitSeq.Append(aNameUnits(k+1)); |
420 | } |
421 | } |
422 | } |
423 | } |
424 | } |
425 | } |
426 | |
427 | //======================================================================= |
428 | //function : getSiName |
429 | //purpose : |
430 | //======================================================================= |
431 | |
e9c15c4c |
432 | inline static TCollection_AsciiString getSiName(const Handle(StepBasic_SiUnit)& theUnit) |
d402d481 |
433 | { |
434 | |
435 | TCollection_AsciiString aName; |
e9c15c4c |
436 | if (theUnit->HasPrefix()) { |
437 | switch (theUnit->Prefix()) { |
438 | case StepBasic_spExa: aName += "exa"; break; |
439 | case StepBasic_spPeta: aName += "peta"; break; |
440 | case StepBasic_spTera: aName += "tera"; break; |
441 | case StepBasic_spGiga: aName += "giga"; break; |
442 | case StepBasic_spMega: aName += "mega"; break; |
443 | case StepBasic_spHecto: aName += "hecto"; break; |
444 | case StepBasic_spDeca: aName += "deca"; break; |
445 | case StepBasic_spDeci: aName += "deci"; break; |
446 | |
447 | case StepBasic_spPico: aName += "pico"; break; |
448 | case StepBasic_spFemto: aName += "femto"; break; |
449 | case StepBasic_spAtto: aName += "atto"; break; |
450 | |
451 | case StepBasic_spKilo : aName += "kilo"; break; |
452 | case StepBasic_spCenti :aName += "centi"; break; |
453 | case StepBasic_spMilli :aName += "milli"; break; |
454 | case StepBasic_spMicro :aName += "micro"; break; |
455 | case StepBasic_spNano :aName += "nano"; break; |
456 | default: break; |
d402d481 |
457 | }; |
e9c15c4c |
458 | } |
d402d481 |
459 | |
e9c15c4c |
460 | switch(theUnit->Name()) { |
d402d481 |
461 | case StepBasic_sunMetre : aName += "metre"; break; |
462 | case StepBasic_sunRadian : aName += "radian"; break; |
463 | case StepBasic_sunSteradian : aName += "steradian"; break; |
464 | default: break; |
465 | }; |
466 | return aName; |
467 | } |
468 | |
469 | //======================================================================= |
470 | //function : findUnits |
471 | //purpose : |
472 | //======================================================================= |
473 | |
474 | Standard_Boolean STEPControl_Reader::findUnits( |
475 | const Handle(StepRepr_RepresentationContext)& theRepCont, |
476 | TColStd_Array1OfAsciiString& theNameUnits, |
477 | TColStd_Array1OfReal& theFactorUnits) |
478 | { |
479 | Handle(StepRepr_GlobalUnitAssignedContext) aContext; |
480 | Handle(StepRepr_GlobalUncertaintyAssignedContext) aTol; |
481 | |
482 | if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) { |
483 | aContext = Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext):: |
484 | DownCast(theRepCont)->GlobalUnitAssignedContext(); |
485 | } |
486 | |
487 | |
488 | if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) { |
489 | aContext = Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx):: |
490 | DownCast(theRepCont)->GlobalUnitAssignedContext(); |
491 | |
492 | } |
493 | if(aContext.IsNull()) |
494 | return Standard_False; |
495 | // Start Computation |
496 | Handle(StepBasic_HArray1OfNamedUnit) anUnits = aContext->Units(); |
497 | Standard_Integer nbU = aContext->NbUnits(); |
498 | Standard_Integer nbFind = 0; |
499 | for (Standard_Integer i = 1; i <= nbU; i++) { |
500 | Handle(StepBasic_NamedUnit) aNamedUnit = aContext->UnitsValue(i); |
501 | Handle(StepBasic_ConversionBasedUnit) aConvUnit = |
502 | Handle(StepBasic_ConversionBasedUnit)::DownCast(aNamedUnit); |
503 | Standard_Integer anInd = 0; |
504 | TCollection_AsciiString aName; |
505 | Standard_Real anUnitFact = 0; |
506 | if( !aConvUnit.IsNull() ) |
507 | { |
508 | Handle(StepBasic_MeasureWithUnit) aMeasWithUnit = |
509 | aConvUnit->ConversionFactor(); |
510 | |
511 | if(aMeasWithUnit.IsNull()) |
512 | continue; |
513 | |
514 | if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ) |
515 | anInd = 1; |
516 | else if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ) |
517 | anInd = 2; |
518 | else if( aMeasWithUnit->IsKind(STANDARD_TYPE(StepBasic_SolidAngleMeasureWithUnit)) ) |
519 | anInd = 3; |
520 | if(!anInd) |
521 | continue; |
522 | aName = aConvUnit->Name()->String(); |
523 | anUnitFact = aMeasWithUnit->ValueComponent(); |
524 | } |
525 | else |
526 | { |
527 | Handle(StepBasic_SiUnit) aSiUnit = Handle(StepBasic_SiUnit)::DownCast(aNamedUnit); |
528 | if( aSiUnit.IsNull()) |
529 | continue; |
530 | if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) |
531 | anInd =1; |
532 | else if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) |
533 | anInd = 2; |
534 | else if(aSiUnit->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndSolidAngleUnit))) |
535 | anInd = 3; |
536 | if( !anInd ) |
537 | continue; |
538 | anUnitFact = (!aSiUnit->HasPrefix() ? |
539 | 1. : STEPConstruct_UnitContext::ConvertSiPrefix(aSiUnit->Prefix())); |
e9c15c4c |
540 | aName = getSiName(aSiUnit); |
d402d481 |
541 | |
542 | |
543 | } |
544 | if( !anInd ) |
545 | continue; |
546 | |
547 | theNameUnits.SetValue(anInd, aName); |
548 | theFactorUnits.SetValue(anInd, anUnitFact); |
549 | nbFind++; |
550 | |
551 | } |
552 | |
553 | return (nbFind); |
554 | } |
555 | |