Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-08-15 |
2 | // Created by: Andrey BETENEV | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
16 | #include <STEPCAFControl_Reader.ixx> | |
17 | ||
18 | #include <Quantity_Color.hxx> | |
19 | #include <TCollection_HAsciiString.hxx> | |
20 | #include <TopoDS_Shape.hxx> | |
21 | #include <TopoDS_Iterator.hxx> | |
22 | #include <TopTools_MapOfShape.hxx> | |
23 | #include <TopoDS_Compound.hxx> | |
24 | ||
25 | #include <Transfer_TransientProcess.hxx> | |
26 | #include <TransferBRep.hxx> | |
27 | #include <Transfer_Binder.hxx> | |
28 | #include <Interface_InterfaceModel.hxx> | |
29 | #include <XSControl_TransferReader.hxx> | |
30 | ||
31 | #include <StepBasic_Product.hxx> | |
32 | #include <StepBasic_ProductDefinition.hxx> | |
33 | #include <StepBasic_ProductDefinitionRelationship.hxx> | |
34 | #include <StepBasic_ProductDefinitionFormation.hxx> | |
35 | #include <StepShape_ContextDependentShapeRepresentation.hxx> | |
36 | #include <StepShape_ShapeDefinitionRepresentation.hxx> | |
37 | #include <StepShape_ShapeDefinitionRepresentation.hxx> | |
38 | #include <StepRepr_ProductDefinitionShape.hxx> | |
39 | #include <StepRepr_PropertyDefinition.hxx> | |
40 | #include <StepRepr_ShapeAspect.hxx> | |
41 | #include <StepRepr_MeasureRepresentationItem.hxx> | |
42 | #include <StepRepr_DescriptiveRepresentationItem.hxx> | |
02a0b964 | 43 | #include <StepRepr_SequenceOfRepresentationItem.hxx> |
7fd59977 | 44 | #include <StepVisual_StyledItem.hxx> |
45 | #include <StepAP214_AppliedExternalIdentificationAssignment.hxx> | |
46 | ||
47 | #include <STEPConstruct.hxx> | |
48 | #include <STEPConstruct_Styles.hxx> | |
49 | #include <STEPConstruct_ExternRefs.hxx> | |
50 | #include <STEPConstruct_UnitContext.hxx> | |
51 | #include <STEPCAFControl_Controller.hxx> | |
52 | #include <STEPCAFControl_DataMapOfSDRExternFile.hxx> | |
53 | ||
54 | #include <TDataStd_Name.hxx> | |
55 | #include <TDF_Label.hxx> | |
56 | #include <XCAFDoc_ColorTool.hxx> | |
57 | #include <XCAFDoc_ShapeTool.hxx> | |
58 | #include <XCAFDoc_DocumentTool.hxx> | |
59 | #include <XCAFDoc_DimTolTool.hxx> | |
60 | #include <XCAFDoc_MaterialTool.hxx> | |
61 | #include <XCAFDoc_DataMapOfShapeLabel.hxx> | |
62 | #include <STEPConstruct_ValidationProps.hxx> | |
63 | #include <StepRepr_Representation.hxx> | |
64 | #include <XCAFDoc_Area.hxx> | |
65 | #include <XCAFDoc_Volume.hxx> | |
66 | #include <XCAFDoc_Centroid.hxx> | |
67 | #include <StepVisual_PresentationLayerAssignment.hxx> | |
68 | #include <TColStd_HSequenceOfTransient.hxx> | |
69 | #include <StepVisual_LayeredItem.hxx> | |
70 | #include <XCAFDoc_LayerTool.hxx> | |
71 | #include <Interface_EntityIterator.hxx> | |
72 | #include <StepRepr_ShapeRepresentationRelationship.hxx> | |
73 | #include <STEPConstruct_Assembly.hxx> | |
74 | #include <TDF_Tool.hxx> | |
75 | #include <StepVisual_Invisibility.hxx> | |
76 | #include <TDataStd_UAttribute.hxx> | |
77 | #include <XCAFDoc.hxx> | |
78 | #include <OSD_Path.hxx> | |
79 | #include <TColStd_SequenceOfHAsciiString.hxx> | |
80 | ||
81 | #include <TDataStd_TreeNode.hxx> | |
82 | #include <TNaming_NamedShape.hxx> | |
83 | #include <BRep_Builder.hxx> | |
84 | ||
85 | #include <STEPCAFControl_DataMapOfShapePD.hxx> | |
86 | #include <STEPCAFControl_DataMapOfPDExternFile.hxx> | |
87 | #include <StepVisual_PresentationStyleByContext.hxx> | |
88 | #include <StepVisual_StyleContextSelect.hxx> | |
89 | #include <StepRepr_RepresentedDefinition.hxx> | |
90 | #include <StepRepr_CharacterizedDefinition.hxx> | |
91 | #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx> | |
92 | #include <XCAFDoc_GraphNode.hxx> | |
93 | #include <STEPCAFControl_Reader.hxx> | |
94 | ||
95 | // skl 21.08.2003 for reading G&DT | |
96 | #include <StepShape_DimensionalSize.hxx> | |
97 | #include <StepDimTol_GeometricTolerance.hxx> | |
98 | #include <StepShape_EdgeCurve.hxx> | |
99 | #include <StepShape_DimensionalCharacteristicRepresentation.hxx> | |
100 | #include <StepShape_ShapeDimensionRepresentation.hxx> | |
101 | #include <StepRepr_ValueRange.hxx> | |
102 | #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx> | |
103 | #include <StepBasic_MeasureWithUnit.hxx> | |
104 | #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx> | |
105 | #include <StepDimTol_ModifiedGeometricTolerance.hxx> | |
106 | #include <StepDimTol_GeometricToleranceWithDatumReference.hxx> | |
107 | //#include <StepRepr_CompoundItemDefinition.hxx> | |
108 | //#include <StepRepr_CompoundItemDefinitionMember.hxx> | |
109 | #include <TColStd_HArray1OfTransient.hxx> | |
110 | #include <StepRepr_HArray1OfRepresentationItem.hxx> | |
111 | #include <TColStd_IndexedDataMapOfTransientTransient.hxx> | |
112 | //#include <StepBasic_ConversionBasedUnit.hxx> | |
113 | #include <StepBasic_Unit.hxx> | |
114 | #include <StepBasic_NamedUnit.hxx> | |
115 | #include <StepBasic_SiUnit.hxx> | |
116 | #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx> | |
117 | #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx> | |
118 | #include <StepBasic_DerivedUnit.hxx> | |
119 | #include <StepBasic_DerivedUnitElement.hxx> | |
120 | #include <StepBasic_MeasureValueMember.hxx> | |
121 | ||
122 | //#include <TDataStd_Real.hxx> | |
123 | //#include <TDataStd_Constraint.hxx> | |
124 | //#include <TDataStd_ConstraintEnum.hxx> | |
125 | //#include <TNaming_Tool.hxx> | |
126 | //#include <AIS_InteractiveObject.hxx> | |
127 | //#include <TPrsStd_ConstraintTools.hxx> | |
128 | //#include <AIS_DiameterDimension.hxx> | |
129 | //#include <TPrsStd_Position.hxx> | |
130 | //#include <TPrsStd_AISPresentation.hxx> | |
131 | //#include <TNaming_Builder.hxx> | |
132 | #include <TColStd_HArray1OfReal.hxx> | |
133 | #include <StepShape_AdvancedFace.hxx> | |
134 | #include <StepDimTol_HArray1OfDatumReference.hxx> | |
135 | #include <StepDimTol_DatumReference.hxx> | |
136 | #include <StepDimTol_Datum.hxx> | |
137 | #include <StepDimTol_DatumFeature.hxx> | |
138 | #include <StepRepr_ShapeAspectRelationship.hxx> | |
139 | ||
140 | #include <StepDimTol_AngularityTolerance.hxx> | |
141 | #include <StepDimTol_CircularRunoutTolerance.hxx> | |
142 | #include <StepDimTol_CoaxialityTolerance.hxx> | |
143 | #include <StepDimTol_ConcentricityTolerance.hxx> | |
144 | #include <StepDimTol_ParallelismTolerance.hxx> | |
145 | #include <StepDimTol_PerpendicularityTolerance.hxx> | |
146 | #include <StepDimTol_SymmetryTolerance.hxx> | |
147 | #include <StepDimTol_TotalRunoutTolerance.hxx> | |
148 | #include <StepDimTol_CylindricityTolerance.hxx> | |
149 | #include <StepDimTol_FlatnessTolerance.hxx> | |
150 | #include <StepDimTol_LineProfileTolerance.hxx> | |
151 | #include <StepDimTol_PositionTolerance.hxx> | |
152 | #include <StepDimTol_RoundnessTolerance.hxx> | |
153 | #include <StepDimTol_StraightnessTolerance.hxx> | |
154 | #include <StepDimTol_SurfaceProfileTolerance.hxx> | |
155 | ||
156 | #include <StepShape_SolidModel.hxx> | |
157 | #include <StepShape_ShellBasedSurfaceModel.hxx> | |
158 | #include <StepShape_GeometricSet.hxx> | |
1d2b1ccb | 159 | #include <StepBasic_ProductDefinition.hxx> |
02a0b964 | 160 | #include <NCollection_DataMap.hxx> |
161 | #include <StepShape_ManifoldSolidBrep.hxx> | |
162 | #include <Interface_Static.hxx> | |
163 | #include <TColStd_MapOfTransient.hxx> | |
164 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> | |
165 | #include <TopTools_ListOfShape.hxx> | |
166 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
167 | #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx> | |
168 | #include <StepShape_ClosedShell.hxx> | |
169 | #include <StepShape_HArray1OfFace.hxx> | |
170 | #include <StepShape_HArray1OfFaceBound.hxx> | |
171 | #include <StepShape_Loop.hxx> | |
172 | #include <StepShape_EdgeLoop.hxx> | |
173 | #include <StepShape_HArray1OfOrientedEdge.hxx> | |
174 | #include <StepShape_HArray1OfShell.hxx> | |
ec357c5c | 175 | #include <StepShape_ShapeRepresentation.hxx> |
c04c30b3 | 176 | #include <StepShape_OpenShell.hxx> |
177 | #include <StepShape_Vertex.hxx> | |
ec357c5c | 178 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
179 | #include <StepRepr_AssemblyComponentUsage.hxx> | |
180 | #include <StepRepr_PropertyDefinitionRepresentation.hxx> | |
181 | #include <StepRepr_RepresentationItem.hxx> | |
182 | #include <StepRepr_RepresentationRelationship.hxx> | |
7fd59977 | 183 | |
0797d9d3 | 184 | #ifdef OCCT_DEBUG |
02a0b964 | 185 | //! Converts address of the passed shape (TShape) to string. |
186 | //! \param theShape [in] Shape to dump. | |
187 | //! \return corresponding string. | |
188 | TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape) | |
189 | { | |
190 | std::string anAddrStr; | |
191 | std::ostringstream ost; | |
192 | ost << theShape.TShape().Access(); | |
193 | anAddrStr = ost.str(); | |
194 | ||
195 | TCollection_AsciiString aStr = | |
196 | TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]"); | |
197 | ||
198 | return aStr; | |
199 | } | |
200 | #endif | |
201 | ||
202 | //======================================================================= | |
203 | //function : IsEqual | |
204 | //purpose : global function to check equality of topological shapes | |
205 | //======================================================================= | |
206 | ||
207 | inline Standard_Boolean IsEqual(const TopoDS_Shape& theShape1, | |
208 | const TopoDS_Shape& theShape2) | |
209 | { | |
210 | return theShape1.IsEqual(theShape2); | |
211 | } | |
7fd59977 | 212 | |
02a0b964 | 213 | //======================================================================= |
214 | //function : AllocateSubLabel | |
215 | //purpose : | |
216 | //======================================================================= | |
217 | ||
218 | static TDF_Label AllocateSubLabel(TDF_Label& theRoot) | |
219 | { | |
220 | return TDF_TagSource::NewChild(theRoot); | |
221 | } | |
7fd59977 | 222 | |
223 | //======================================================================= | |
224 | //function : STEPCAFControl_Reader | |
225 | //purpose : | |
226 | //======================================================================= | |
227 | ||
228 | STEPCAFControl_Reader::STEPCAFControl_Reader (): | |
229 | myColorMode( Standard_True ), | |
230 | myNameMode ( Standard_True ), | |
231 | myLayerMode( Standard_True ), | |
232 | myPropsMode( Standard_True ), | |
c24d4017 | 233 | mySHUOMode ( Standard_False ), |
7fd59977 | 234 | myGDTMode ( Standard_True ), |
235 | myMatMode ( Standard_True ) | |
236 | { | |
237 | STEPCAFControl_Controller::Init(); | |
238 | myFiles = new STEPCAFControl_DictionaryOfExternFile; | |
239 | } | |
240 | ||
241 | ||
242 | //======================================================================= | |
243 | //function : STEPCAFControl_Reader | |
244 | //purpose : | |
245 | //======================================================================= | |
246 | ||
247 | STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS, | |
02a0b964 | 248 | const Standard_Boolean scratch) : |
7fd59977 | 249 | myColorMode( Standard_True ), |
250 | myNameMode ( Standard_True ), | |
251 | myLayerMode( Standard_True ), | |
252 | myPropsMode( Standard_True ), | |
c24d4017 | 253 | mySHUOMode ( Standard_False ), |
7fd59977 | 254 | myGDTMode ( Standard_True ), |
255 | myMatMode ( Standard_True ) | |
256 | { | |
257 | STEPCAFControl_Controller::Init(); | |
258 | Init ( WS, scratch ); | |
259 | } | |
260 | ||
261 | ||
262 | //======================================================================= | |
263 | //function : Init | |
264 | //purpose : | |
265 | //======================================================================= | |
266 | ||
267 | void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS, | |
268 | const Standard_Boolean scratch) | |
269 | { | |
270 | // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" ); | |
271 | myReader.SetWS (WS,scratch); | |
272 | myFiles = new STEPCAFControl_DictionaryOfExternFile; | |
273 | } | |
274 | ||
275 | ||
276 | //======================================================================= | |
277 | //function : ReadFile | |
278 | //purpose : | |
279 | //======================================================================= | |
280 | ||
281 | IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename) | |
282 | { | |
283 | return myReader.ReadFile ( filename ); | |
284 | } | |
285 | ||
286 | ||
287 | //======================================================================= | |
288 | //function : NbRootsForTransfer | |
289 | //purpose : | |
290 | //======================================================================= | |
291 | ||
292 | Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer () | |
293 | { | |
294 | return myReader.NbRootsForTransfer(); | |
295 | } | |
296 | ||
297 | ||
298 | //======================================================================= | |
299 | //function : TransferOneRoot | |
300 | //purpose : | |
301 | //======================================================================= | |
302 | ||
303 | Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num, | |
304 | Handle(TDocStd_Document) &doc) | |
305 | { | |
306 | TDF_LabelSequence Lseq; | |
307 | return Transfer ( myReader, num, doc, Lseq ); | |
308 | } | |
309 | ||
310 | ||
311 | //======================================================================= | |
312 | //function : Transfer | |
313 | //purpose : | |
314 | //======================================================================= | |
315 | ||
316 | Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc) | |
317 | { | |
318 | TDF_LabelSequence Lseq; | |
319 | return Transfer ( myReader, 0, doc, Lseq ); | |
320 | } | |
321 | ||
322 | ||
323 | //======================================================================= | |
324 | //function : Perform | |
325 | //purpose : | |
326 | //======================================================================= | |
327 | ||
328 | Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename, | |
329 | Handle(TDocStd_Document) &doc) | |
330 | { | |
331 | if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False; | |
332 | return Transfer ( doc ); | |
333 | } | |
334 | ||
335 | ||
336 | //======================================================================= | |
337 | //function : Perform | |
338 | //purpose : | |
339 | //======================================================================= | |
340 | ||
341 | Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename, | |
342 | Handle(TDocStd_Document) &doc) | |
343 | { | |
344 | if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False; | |
345 | return Transfer ( doc ); | |
346 | } | |
347 | ||
348 | ||
349 | //======================================================================= | |
350 | //function : ExternFiles | |
351 | //purpose : | |
352 | //======================================================================= | |
353 | ||
354 | const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const | |
355 | { | |
356 | return myFiles; | |
357 | } | |
358 | ||
359 | ||
360 | //======================================================================= | |
361 | //function : ExternFile | |
362 | //purpose : | |
363 | //======================================================================= | |
364 | ||
365 | Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name, | |
366 | Handle(STEPCAFControl_ExternFile) &ef) const | |
367 | { | |
368 | ef.Nullify(); | |
369 | if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) ) | |
370 | return Standard_False; | |
371 | ef = myFiles->Item ( name ); | |
372 | return Standard_True; | |
373 | } | |
374 | ||
375 | ||
376 | //======================================================================= | |
377 | //function : Reader | |
378 | //purpose : | |
379 | //======================================================================= | |
380 | ||
381 | STEPControl_Reader &STEPCAFControl_Reader::ChangeReader () | |
382 | { | |
383 | return myReader; | |
384 | } | |
385 | ||
386 | ||
387 | //======================================================================= | |
388 | //function : Reader | |
389 | //purpose : | |
390 | //======================================================================= | |
391 | ||
392 | const STEPControl_Reader &STEPCAFControl_Reader::Reader () const | |
393 | { | |
394 | return myReader; | |
395 | } | |
396 | ||
397 | ||
398 | //======================================================================= | |
399 | //function : FillShapesMap | |
400 | //purpose : auxiliary: fill a map by all compounds and their components | |
401 | //======================================================================= | |
402 | ||
403 | static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map) | |
404 | { | |
405 | TopoDS_Shape S0 = S; | |
406 | TopLoc_Location loc; | |
407 | S0.Location ( loc ); | |
408 | map.Add ( S0 ); | |
409 | if ( S.ShapeType() != TopAbs_COMPOUND ) return; | |
410 | for ( TopoDS_Iterator it(S); it.More(); it.Next() ) | |
411 | FillShapesMap ( it.Value(), map ); | |
412 | } | |
413 | ||
414 | ||
415 | //======================================================================= | |
416 | //function : Transfer | |
417 | //purpose : basic working method | |
418 | //======================================================================= | |
419 | ||
420 | Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader, | |
421 | const Standard_Integer nroot, | |
422 | Handle(TDocStd_Document) &doc, | |
423 | TDF_LabelSequence &Lseq, | |
424 | const Standard_Boolean asOne) | |
425 | { | |
426 | reader.ClearShapes(); | |
427 | Standard_Integer i; | |
428 | ||
429 | // Read all shapes | |
430 | Standard_Integer num = reader.NbRootsForTransfer(); | |
431 | if ( num <=0 ) return Standard_False; | |
432 | if ( nroot ) { | |
433 | if ( nroot > num ) return Standard_False; | |
44d7c408 | 434 | reader.TransferOneRoot ( nroot ); |
7fd59977 | 435 | } |
436 | else { | |
437 | for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i ); | |
438 | } | |
439 | num = reader.NbShapes(); | |
440 | if ( num <=0 ) return Standard_False; | |
441 | ||
442 | // Fill a map of (top-level) shapes resulting from that transfer | |
443 | // Only these shapes will be considered further | |
444 | TopTools_MapOfShape ShapesMap, NewShapesMap; | |
445 | for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap ); | |
446 | ||
447 | // Collect information on shapes originating from SDRs | |
448 | // this will be used to distinguish compounds representing assemblies | |
449 | // from the ones representing hybrid models and shape sets | |
450 | STEPCAFControl_DataMapOfShapePD ShapePDMap; | |
451 | STEPCAFControl_DataMapOfPDExternFile PDFileMap; | |
452 | Handle(Interface_InterfaceModel) Model = reader.Model(); | |
453 | Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess(); | |
454 | Standard_Integer nb = Model->NbEntities(); | |
455 | ||
456 | Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient; | |
457 | ||
458 | for (i = 1; i <= nb; i ++) { | |
459 | Handle(Standard_Transient) enti = Model->Value(i); | |
460 | if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) { | |
461 | // sequence for acceleration ReadMaterials | |
462 | SeqPDS->Append(enti); | |
463 | } | |
464 | if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) { | |
465 | Handle(StepBasic_ProductDefinition) PD = | |
466 | Handle(StepBasic_ProductDefinition)::DownCast(enti); | |
467 | Standard_Integer index = TP->MapIndex(PD); | |
468 | if ( index >0 ) { | |
469 | Handle(Transfer_Binder) binder = TP->MapItem (index); | |
470 | TopoDS_Shape S = TransferBRep::ShapeResult(binder); | |
471 | if ( ! S.IsNull() && ShapesMap.Contains(S) ) { | |
472 | NewShapesMap.Add(S); | |
473 | ShapePDMap.Bind ( S, PD ); | |
474 | Handle(STEPCAFControl_ExternFile) EF; | |
475 | PDFileMap.Bind ( PD, EF ); | |
476 | } | |
477 | } | |
478 | } | |
479 | if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) { | |
480 | Standard_Integer index = TP->MapIndex(enti); | |
481 | if ( index >0 ) { | |
482 | Handle(Transfer_Binder) binder = TP->MapItem (index); | |
483 | TopoDS_Shape S = TransferBRep::ShapeResult(binder); | |
484 | if ( ! S.IsNull() && ShapesMap.Contains(S) ) | |
485 | NewShapesMap.Add(S); | |
486 | } | |
487 | } | |
488 | } | |
489 | ||
490 | // get directory name of the main file | |
491 | OSD_Path mainfile ( reader.WS()->LoadedFile() ); | |
492 | mainfile.SetName ( "" ); | |
493 | mainfile.SetExtension ( "" ); | |
494 | TCollection_AsciiString dpath; | |
495 | mainfile.SystemName ( dpath ); | |
496 | ||
497 | // Load external references (only for relevant SDRs) | |
498 | // and fill map SDR -> extern file | |
499 | STEPConstruct_ExternRefs ExtRefs ( reader.WS() ); | |
500 | ExtRefs.LoadExternRefs(); | |
501 | for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) { | |
502 | // check extern ref format | |
503 | Handle(TCollection_HAsciiString) format = ExtRefs.Format(i); | |
504 | if ( ! format.IsNull() ) { | |
505 | static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" ); | |
506 | static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" ); | |
507 | if ( ! format->IsSameString ( ap203, Standard_False ) && | |
508 | ! format->IsSameString ( ap214, Standard_False ) ) { | |
0797d9d3 | 509 | #ifdef OCCT_DEBUG |
7fd59977 | 510 | cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl; |
511 | #else | |
512 | continue; | |
513 | #endif | |
514 | } | |
515 | } | |
0797d9d3 | 516 | #ifdef OCCT_DEBUG |
7fd59977 | 517 | else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl; |
518 | #endif | |
519 | ||
520 | // get and check filename of the current extern ref | |
521 | const Standard_CString filename = ExtRefs.FileName(i); | |
522 | ||
0797d9d3 | 523 | #ifdef OCCT_DEBUG |
aefdc31b | 524 | cout<<"filename="<<filename<<endl; |
83a86948 | 525 | #endif |
7fd59977 | 526 | |
527 | if ( ! filename || ! filename[0] ) { | |
0797d9d3 | 528 | #ifdef OCCT_DEBUG |
7fd59977 | 529 | cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl; |
530 | #endif | |
531 | continue; // not a valid extern ref | |
532 | } | |
533 | ||
534 | // compute true path to the extern file | |
535 | TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename ); | |
536 | if ( fullname.Length() <= 0 ) fullname = filename; | |
537 | ||
538 | /* | |
539 | char fullname[1024]; | |
540 | char *mainfile = reader.WS()->LoadedFile(); | |
541 | if ( ! mainfile ) mainfile = ""; | |
542 | Standard_Integer slash = 0; | |
543 | for ( Standard_Integer k=0; mainfile[k]; k++ ) | |
544 | if ( mainfile[k] == '/' ) slash = k; | |
545 | strncpy ( fullname, mainfile, slash ); | |
546 | sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename ); | |
547 | */ | |
548 | ||
549 | // get and check PD associated with the current extern ref | |
550 | Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i); | |
551 | if ( PD.IsNull() ) continue; // not a valid extern ref | |
552 | if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer | |
553 | ||
554 | // read extern file (or use existing data) and record its data | |
555 | Handle(STEPCAFControl_ExternFile) EF = | |
556 | ReadExternFile ( filename, fullname.ToCString(), doc ); | |
557 | PDFileMap.Bind ( PD, EF ); | |
558 | } | |
559 | ||
560 | // and insert them to the document | |
561 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() ); | |
562 | if ( STool.IsNull() ) return Standard_False; | |
563 | XCAFDoc_DataMapOfShapeLabel map; | |
564 | if ( asOne ) | |
565 | Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) ); | |
566 | else { | |
567 | for ( i=1; i <= num; i++ ) { | |
568 | Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) ); | |
569 | } | |
570 | } | |
571 | ||
572 | // read colors | |
573 | if ( GetColorMode() ) | |
574 | ReadColors ( reader.WS(), doc, PDFileMap, map ); | |
575 | ||
576 | // read names | |
577 | if ( GetNameMode() ) | |
578 | ReadNames ( reader.WS(), doc, PDFileMap, map ); | |
579 | ||
580 | // read validation props | |
581 | if ( GetPropsMode() ) | |
582 | ReadValProps ( reader.WS(), doc, PDFileMap, map ); | |
583 | ||
584 | // read layers | |
585 | if ( GetLayerMode() ) | |
586 | ReadLayers ( reader.WS(), doc ); | |
587 | ||
588 | // read SHUO entities from STEP model | |
589 | if ( GetSHUOMode() ) | |
590 | ReadSHUOs ( reader.WS(), doc, PDFileMap, map ); | |
591 | ||
592 | // read GDT entities from STEP model | |
593 | if(GetGDTMode()) | |
594 | ReadGDTs(reader.WS(),doc); | |
595 | ||
596 | // read Material entities from STEP model | |
597 | if(GetMatMode()) | |
598 | ReadMaterials(reader.WS(),doc,SeqPDS); | |
599 | ||
02a0b964 | 600 | // Expand resulting CAF structure for sub-shapes (optionally with their |
601 | // names) if requested | |
602 | ExpandSubShapes(STool, map, ShapePDMap); | |
603 | ||
7fd59977 | 604 | return Standard_True; |
605 | } | |
606 | ||
607 | //======================================================================= | |
608 | //function : AddShape | |
609 | //purpose : | |
610 | //======================================================================= | |
611 | ||
612 | TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S, | |
613 | const Handle(XCAFDoc_ShapeTool) &STool, | |
614 | const TopTools_MapOfShape &NewShapesMap, | |
615 | const STEPCAFControl_DataMapOfShapePD &ShapePDMap, | |
616 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
617 | XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
618 | { | |
619 | // if shape has already been mapped, just return corresponding label | |
620 | if ( ShapeLabelMap.IsBound ( S ) ) { | |
621 | return ShapeLabelMap.Find ( S ); | |
622 | } | |
623 | ||
624 | // if shape is located, create instance | |
625 | if ( ! S.Location().IsIdentity() ) { | |
626 | TopoDS_Shape S0 = S; | |
627 | TopLoc_Location loc; | |
628 | S0.Location ( loc ); | |
629 | AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap ); | |
630 | TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference | |
631 | ShapeLabelMap.Bind ( S, L ); | |
632 | return L; | |
633 | } | |
634 | ||
635 | // if shape is not compound, simple add it | |
636 | if ( S.ShapeType() != TopAbs_COMPOUND ) { | |
637 | TDF_Label L = STool->AddShape ( S, Standard_False ); | |
638 | ShapeLabelMap.Bind ( S, L ); | |
639 | return L; | |
640 | } | |
641 | ||
642 | // for compounds, compute number of subshapes and check whether this is assembly | |
643 | Standard_Boolean isAssembly = Standard_False; | |
644 | Standard_Integer nbComponents = 0; | |
645 | TopoDS_Iterator it; | |
646 | for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) { | |
647 | TopoDS_Shape Sub0 = it.Value(); | |
648 | TopLoc_Location loc; | |
649 | Sub0.Location ( loc ); | |
650 | if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True; | |
651 | } | |
652 | ||
653 | // if(nbComponents>0) isAssembly = Standard_True; | |
654 | ||
655 | // check whether it has associated external ref | |
656 | TColStd_SequenceOfHAsciiString SHAS; | |
657 | if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) { | |
658 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) ); | |
659 | if ( ! EF.IsNull() ) { | |
660 | // (store information on extern refs in the document) | |
661 | SHAS.Append(EF->GetName()); | |
662 | // if yes, just return corresponding label | |
663 | if ( ! EF->GetLabel().IsNull() ) { | |
664 | // but if components >0, ignore extern ref! | |
665 | if ( nbComponents <=0 ) { | |
666 | ShapeLabelMap.Bind ( S, EF->GetLabel() ); | |
667 | STool->SetExternRefs(EF->GetLabel(),SHAS); | |
668 | return EF->GetLabel(); | |
669 | } | |
670 | } | |
0797d9d3 | 671 | #ifdef OCCT_DEBUG |
7fd59977 | 672 | if ( ! EF->GetLabel().IsNull() ) |
673 | cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl; | |
674 | else if ( nbComponents <=0 ) | |
675 | cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl; | |
676 | #endif | |
677 | } | |
678 | } | |
679 | ||
680 | // add compound either as a whole, | |
681 | if ( ! isAssembly ) { | |
682 | TDF_Label L = STool->AddShape ( S, Standard_False ); | |
683 | if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS); | |
684 | ShapeLabelMap.Bind ( S, L ); | |
685 | return L; | |
686 | } | |
687 | ||
688 | // or as assembly, component-by-component | |
689 | TDF_Label L = STool->NewShape(); | |
690 | for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) { | |
691 | TopoDS_Shape Sub0 = it.Value(); | |
692 | TopLoc_Location loc; | |
693 | Sub0.Location ( loc ); | |
694 | TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap ); | |
695 | if ( ! subL.IsNull() ) { | |
696 | STool->AddComponent ( L, subL, it.Value().Location() ); | |
697 | } | |
698 | } | |
699 | if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS); | |
700 | ShapeLabelMap.Bind ( S, L ); | |
701 | //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941 | |
702 | ||
703 | return L; | |
704 | } | |
705 | ||
706 | //======================================================================= | |
707 | //function : ReadExternFile | |
708 | //purpose : | |
709 | //======================================================================= | |
710 | ||
711 | Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file, | |
712 | const Standard_CString fullname, | |
713 | Handle(TDocStd_Document)& doc) | |
714 | { | |
715 | // if the file is already read, associate it with SDR | |
716 | if ( myFiles->HasItem ( file, Standard_True ) ) { | |
717 | return myFiles->Item ( file ); | |
718 | } | |
719 | ||
0797d9d3 | 720 | #ifdef OCCT_DEBUG |
7fd59977 | 721 | cout << "Reading extern file: " << fullname << endl; |
722 | #endif | |
723 | ||
724 | // create new WorkSession and Reader | |
725 | Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession; | |
726 | newWS->SelectNorm ( "STEP" ); | |
727 | STEPControl_Reader sr ( newWS, Standard_False ); | |
728 | ||
729 | // start to fill the resulting ExternFile structure | |
730 | Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile; | |
731 | EF->SetWS ( newWS ); | |
732 | EF->SetName ( new TCollection_HAsciiString ( file ) ); | |
733 | ||
734 | // read file | |
735 | EF->SetLoadStatus ( sr.ReadFile ( fullname ) ); | |
736 | ||
737 | // transfer in single-result mode | |
738 | if ( EF->GetLoadStatus() == IFSelect_RetDone ) { | |
739 | TDF_LabelSequence labels; | |
740 | EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) ); | |
741 | if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) ); | |
742 | } | |
743 | ||
744 | // add read file to dictionary | |
745 | myFiles->SetItem ( file, EF ); | |
746 | ||
747 | return EF; | |
748 | } | |
749 | ||
750 | ||
751 | //======================================================================= | |
752 | //function : SetColorToSubshape | |
753 | //purpose : auxilary | |
754 | //======================================================================= | |
755 | static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool, | |
756 | const TopoDS_Shape & S, | |
757 | const Quantity_Color& col, | |
758 | const XCAFDoc_ColorType type) | |
759 | { | |
760 | for (TopoDS_Iterator it(S); it.More(); it.Next()) | |
761 | if (! CTool->SetColor( it.Value(), col, type)) break; | |
762 | } | |
763 | ||
764 | ||
765 | //======================================================================= | |
766 | //function : findStyledSR | |
767 | //purpose : auxilary | |
768 | //======================================================================= | |
769 | static void findStyledSR (const Handle(StepVisual_StyledItem) &style, | |
770 | Handle(StepShape_ShapeRepresentation)& aSR) | |
771 | { | |
772 | // search Shape Represenatation for component styled item | |
773 | for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) { | |
774 | Handle(StepVisual_PresentationStyleByContext) PSA = | |
775 | Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j )); | |
776 | if ( PSA.IsNull() ) | |
777 | continue; | |
778 | StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext(); | |
779 | Handle(StepShape_ShapeRepresentation) aCurrentSR = | |
780 | Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation()); | |
781 | if ( aCurrentSR.IsNull() ) | |
782 | continue; | |
783 | aSR = aCurrentSR; | |
784 | break; | |
785 | } | |
786 | } | |
787 | ||
788 | ||
789 | //======================================================================= | |
790 | //function : ReadColors | |
791 | //purpose : | |
792 | //======================================================================= | |
793 | ||
794 | Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS, | |
795 | Handle(TDocStd_Document)& Doc, | |
796 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
797 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
798 | { | |
799 | STEPConstruct_Styles Styles ( WS ); | |
800 | if ( ! Styles.LoadStyles() ) { | |
0797d9d3 | 801 | #ifdef OCCT_DEBUG |
7fd59977 | 802 | cout << "Warning: no styles are found in the model" << endl; |
803 | #endif | |
804 | return Standard_False; | |
805 | } | |
806 | // searching for invisible items in the model | |
807 | Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient; | |
808 | Styles.LoadInvisStyles( aHSeqOfInvisStyle ); | |
809 | ||
810 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() ); | |
811 | if ( CTool.IsNull() ) return Standard_False; | |
812 | ||
813 | // parse and search for color attributes | |
814 | Standard_Integer nb = Styles.NbStyles(); | |
815 | for ( Standard_Integer i=1; i <= nb; i++ ) { | |
816 | Handle(StepVisual_StyledItem) style = Styles.Style ( i ); | |
817 | if ( style.IsNull() ) continue; | |
818 | ||
819 | Standard_Boolean IsVisible = Standard_True; | |
820 | // check the visibility of styled item. | |
821 | for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) { | |
822 | if ( style != aHSeqOfInvisStyle->Value( si ) ) | |
823 | continue; | |
824 | // found that current style is invisible. | |
7fd59977 | 825 | IsVisible = Standard_False; |
826 | break; | |
827 | } | |
828 | ||
829 | Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol; | |
830 | // check if it is component style | |
831 | Standard_Boolean IsComponent = Standard_False; | |
832 | if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible ) | |
833 | continue; | |
834 | ||
835 | // find shape | |
836 | TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() ); | |
837 | Standard_Boolean isSkipSHUOstyle = Standard_False; | |
838 | // take shape with real location. | |
839 | while ( IsComponent ) { | |
840 | // take SR of NAUO | |
841 | Handle(StepShape_ShapeRepresentation) aSR; | |
842 | findStyledSR( style, aSR ); | |
843 | // search for SR along model | |
844 | if (aSR.IsNull()) | |
845 | break; | |
846 | // Handle(Interface_InterfaceModel) Model = WS->Model(); | |
847 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
848 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
849 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR ); | |
850 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; | |
851 | for (subs.Start(); subs.More(); subs.Next()) { | |
852 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
853 | if ( aSDR.IsNull() ) | |
854 | continue; | |
855 | StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition(); | |
856 | Handle(StepRepr_ProductDefinitionShape) PDS = | |
857 | Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition()); | |
858 | if ( PDS.IsNull() ) | |
859 | continue; | |
860 | StepRepr_CharacterizedDefinition aCharDef = PDS->Definition(); | |
861 | ||
862 | Handle(StepRepr_AssemblyComponentUsage) ACU = | |
863 | Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship()); | |
864 | // PTV 10.02.2003 skip styled item that refer to SHUO | |
865 | if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) { | |
866 | isSkipSHUOstyle = Standard_True; | |
867 | break; | |
868 | } | |
869 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = | |
870 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU); | |
871 | if ( NAUO.IsNull() ) | |
872 | continue; | |
873 | ||
874 | TopoDS_Shape aSh; | |
875 | // PTV 10.02.2003 to find component of assembly CORRECTLY | |
876 | STEPConstruct_Tool Tool( WS ); | |
877 | TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap ); | |
878 | aSh = CTool->ShapeTool()->GetShape(aShLab); | |
879 | // Handle(Transfer_Binder) binder = TP->Find(NAUO); | |
880 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
881 | // continue; | |
882 | // aSh = TransferBRep::ShapeResult ( TP, binder ); | |
883 | if (!aSh.IsNull()) { | |
884 | S = aSh; | |
885 | break; | |
886 | } | |
887 | } | |
888 | break; | |
889 | } | |
890 | if (isSkipSHUOstyle) | |
891 | continue; // skip styled item which refer to SHUO | |
892 | ||
36f35343 | 893 | if ( S.IsNull() ) |
7fd59977 | 894 | continue; |
7fd59977 | 895 | |
896 | if ( ! SurfCol.IsNull() ) { | |
897 | Quantity_Color col; | |
898 | Styles.DecodeColor ( SurfCol, col ); | |
899 | if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf )) | |
900 | SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf ); | |
901 | } | |
902 | if ( ! BoundCol.IsNull() ) { | |
903 | Quantity_Color col; | |
904 | Styles.DecodeColor ( BoundCol, col ); | |
905 | if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv )) | |
906 | SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv ); | |
907 | } | |
908 | if ( ! CurveCol.IsNull() ) { | |
909 | Quantity_Color col; | |
910 | Styles.DecodeColor ( CurveCol, col ); | |
911 | if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv )) | |
912 | SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv ); | |
913 | } | |
914 | if ( !IsVisible ) { | |
915 | // sets the invisibility for shape. | |
916 | TDF_Label aInvL; | |
917 | if ( CTool->ShapeTool()->Search( S, aInvL ) ) | |
918 | CTool->SetVisibility( aInvL, Standard_False ); | |
919 | } | |
920 | } | |
921 | CTool->ReverseChainsOfTreeNodes(); | |
922 | return Standard_True; | |
923 | } | |
924 | ||
925 | //======================================================================= | |
926 | //function : GetLabelFromPD | |
927 | //purpose : | |
928 | //======================================================================= | |
929 | ||
930 | static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD, | |
931 | const Handle(XCAFDoc_ShapeTool) &STool, | |
932 | const Handle(Transfer_TransientProcess) &TP, | |
933 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
934 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
935 | { | |
936 | TDF_Label L; | |
937 | if ( PDFileMap.IsBound ( PD ) ) { | |
938 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD ); | |
939 | if ( ! EF.IsNull() ) { | |
940 | L = EF->GetLabel(); | |
941 | if ( ! L.IsNull() ) return L; | |
942 | } | |
943 | } | |
944 | ||
945 | TopoDS_Shape S; | |
946 | Handle(Transfer_Binder) binder = TP->Find(PD); | |
947 | if ( binder.IsNull() || ! binder->HasResult() ) return L; | |
948 | S = TransferBRep::ShapeResult ( TP, binder ); | |
949 | if ( S.IsNull() ) return L; | |
950 | ||
951 | if ( S.IsNull() ) return L; | |
952 | if ( ShapeLabelMap.IsBound ( S ) ) | |
953 | L = ShapeLabelMap.Find ( S ); | |
954 | if ( L.IsNull() ) | |
955 | STool->Search ( S, L, Standard_True, Standard_True, Standard_False ); | |
956 | return L; | |
957 | } | |
958 | ||
959 | //======================================================================= | |
960 | //function : FindInstance | |
961 | //purpose : | |
962 | //======================================================================= | |
963 | ||
964 | TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO, | |
965 | const Handle(XCAFDoc_ShapeTool) &STool, | |
966 | const STEPConstruct_Tool &Tool, | |
967 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
968 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
969 | { | |
970 | TDF_Label L; | |
971 | ||
972 | // get shape resulting from CDSR (in fact, only location is interesting) | |
973 | Handle(Transfer_TransientProcess) TP = Tool.TransientProcess(); | |
974 | Handle(Transfer_Binder) binder = TP->Find(NAUO); | |
975 | if ( binder.IsNull() || ! binder->HasResult() ) { | |
0797d9d3 | 976 | #ifdef OCCT_DEBUG |
7fd59977 | 977 | cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl; |
978 | #endif | |
979 | return L; | |
980 | } | |
981 | ||
982 | TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder ); | |
983 | if ( S.IsNull() ) { | |
0797d9d3 | 984 | #ifdef OCCT_DEBUG |
7fd59977 | 985 | cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl; |
986 | #endif | |
987 | return L; | |
988 | } | |
989 | ||
990 | // find component`s original label | |
991 | Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition(); | |
992 | if ( PD.IsNull() ) return L; | |
993 | TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap ); | |
994 | if ( Lref.IsNull() ) return L; | |
995 | ||
996 | // find main shape (assembly) label | |
997 | PD.Nullify(); | |
998 | PD = NAUO->RelatingProductDefinition(); | |
999 | if ( PD.IsNull() ) return L; | |
1000 | TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap ); | |
1001 | if ( L0.IsNull() ) return L; | |
1002 | ||
1003 | // if CDSR and NAUO are reversed, swap labels | |
1004 | Handle(StepShape_ContextDependentShapeRepresentation) CDSR; | |
1005 | Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO); | |
1006 | for (subs1.Start(); subs1.More(); subs1.Next()) { | |
1007 | Handle(StepRepr_ProductDefinitionShape) PDS = | |
1008 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value()); | |
1009 | if(PDS.IsNull()) continue; | |
1010 | Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS); | |
1011 | for (subs2.Start(); subs2.More(); subs2.Next()) { | |
1012 | Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp = | |
1013 | Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value()); | |
1014 | if (CDSRtmp.IsNull()) continue; | |
1015 | CDSR = CDSRtmp; | |
1016 | } | |
1017 | } | |
1018 | if (CDSR.IsNull()) return L; | |
1019 | // if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) { | |
1020 | // TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw; | |
1021 | // } | |
1022 | ||
1023 | // iterate on components to find proper one | |
1024 | TDF_LabelSequence seq; | |
1025 | XCAFDoc_ShapeTool::GetComponents ( L0, seq ); | |
1026 | for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) { | |
1027 | TDF_Label Lcomp = seq(k), Lref2; | |
1028 | if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) && | |
1029 | Lref2 == Lref && | |
1030 | S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) ) | |
1031 | L = Lcomp; | |
1032 | } | |
1033 | ||
1034 | return L; | |
1035 | } | |
1036 | ||
1037 | //======================================================================= | |
1038 | //function : ReadNames | |
1039 | //purpose : | |
1040 | //======================================================================= | |
1041 | ||
1042 | Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS, | |
1043 | Handle(TDocStd_Document)& Doc, | |
1044 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1045 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
1046 | { | |
1047 | // get starting data | |
1048 | Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1049 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1050 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1051 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() ); | |
1052 | if ( STool.IsNull() ) return Standard_False; | |
1053 | STEPConstruct_Tool Tool ( WS ); | |
1054 | ||
1055 | // iterate on model to find all SDRs and CDSRs | |
1056 | Standard_Integer nb = Model->NbEntities(); | |
1057 | Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence); | |
1058 | Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition); | |
1059 | Handle(TCollection_HAsciiString) name; | |
1060 | TDF_Label L; | |
1061 | for (Standard_Integer i = 1; i <= nb; i++) { | |
1062 | Handle(Standard_Transient) enti = Model->Value(i); | |
1063 | ||
1064 | // get description of NAUO | |
1065 | if ( enti->DynamicType() == tNAUO ) { | |
1066 | L.Nullify(); | |
1067 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = | |
1068 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti); | |
1069 | if(NAUO.IsNull()) continue; | |
1070 | Interface_EntityIterator subs = WS->Graph().Sharings(NAUO); | |
1071 | for (subs.Start(); subs.More(); subs.Next()) { | |
1072 | Handle(StepRepr_ProductDefinitionShape) PDS = | |
1073 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value()); | |
1074 | if(PDS.IsNull()) continue; | |
1075 | Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship(); | |
1076 | if ( PDR.IsNull() ) continue; | |
1077 | if ( PDR->HasDescription() && | |
1078 | PDR->Description()->Length() >0 ) name = PDR->Description(); | |
ab4a5554 | 1079 | else if ( !PDR->Name().IsNull() && PDR->Name()->Length() >0 ) name = PDR->Name(); |
1080 | else if ( !PDR->Id().IsNull()) name = PDR->Id(); | |
1081 | else name = new TCollection_HAsciiString; | |
7fd59977 | 1082 | } |
1083 | // find proper label | |
1084 | L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap ); | |
1085 | if ( L.IsNull() ) continue; | |
1086 | TCollection_ExtendedString str ( name->String() ); | |
1087 | TDataStd_Name::Set ( L, str ); | |
1088 | } | |
1089 | ||
1090 | // for PD get name of associated product | |
1091 | if ( enti->DynamicType() == tPD ) { | |
1092 | L.Nullify(); | |
1093 | Handle(StepBasic_ProductDefinition) PD = | |
1094 | Handle(StepBasic_ProductDefinition)::DownCast(enti); | |
1095 | if(PD.IsNull()) continue; | |
1096 | Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); | |
ab4a5554 | 1097 | if(!Prod->Name().IsNull() && Prod->Name()->UsefullLength()>0) name = Prod->Name(); |
1098 | else if (!Prod->Id().IsNull()) name = Prod->Id(); | |
1099 | else name = new TCollection_HAsciiString; | |
7fd59977 | 1100 | L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap ); |
1101 | if ( L.IsNull() ) continue; | |
1102 | TCollection_ExtendedString str ( name->String() ); | |
1103 | TDataStd_Name::Set ( L, str ); | |
1104 | } | |
1105 | // set a name to the document | |
1106 | //TCollection_ExtendedString str ( name->String() ); | |
1107 | //TDataStd_Name::Set ( L, str ); | |
1108 | } | |
1109 | ||
1110 | return Standard_True; | |
1111 | } | |
1112 | ||
1113 | //======================================================================= | |
1114 | //function : GetLabelFromPD | |
1115 | //purpose : | |
1116 | //======================================================================= | |
1117 | ||
1118 | static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD, | |
1119 | const Handle(XCAFDoc_ShapeTool) &STool, | |
1120 | const STEPConstruct_ValidationProps &Props, | |
1121 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1122 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
1123 | { | |
1124 | TDF_Label L; | |
1125 | if ( PDFileMap.IsBound ( PD ) ) { | |
1126 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD ); | |
1127 | if ( ! EF.IsNull() ) { | |
1128 | L = EF->GetLabel(); | |
1129 | if ( ! L.IsNull() ) return L; | |
1130 | } | |
1131 | } | |
1132 | TopoDS_Shape S = Props.GetPropShape ( PD ); | |
1133 | if ( S.IsNull() ) return L; | |
1134 | if ( ShapeLabelMap.IsBound ( S ) ) | |
1135 | L = ShapeLabelMap.Find ( S ); | |
1136 | if ( L.IsNull() ) | |
1137 | STool->Search ( S, L, Standard_True, Standard_True, Standard_False ); | |
1138 | return L; | |
1139 | } | |
1140 | ||
1141 | //======================================================================= | |
1142 | //function : ReadValProps | |
1143 | //purpose : | |
1144 | //======================================================================= | |
1145 | ||
1146 | Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS, | |
1147 | Handle(TDocStd_Document)& Doc, | |
1148 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1149 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
1150 | { | |
1151 | // get starting data | |
1152 | Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1153 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1154 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1155 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() ); | |
1156 | if ( STool.IsNull() ) return Standard_False; | |
1157 | ||
1158 | // load props from the STEP model | |
1159 | TColStd_SequenceOfTransient props; | |
1160 | STEPConstruct_ValidationProps Props ( WS ); | |
1161 | if ( ! Props.LoadProps ( props ) ) { | |
0797d9d3 | 1162 | #ifdef OCCT_DEBUG |
7fd59977 | 1163 | cout << "Warning: no validation props found in the model" << endl; |
1164 | #endif | |
1165 | return Standard_False; | |
1166 | } | |
1167 | ||
1168 | // interpret props one by one | |
1169 | for (Standard_Integer i = 1; i <= props.Length(); i ++) { | |
1170 | Handle(StepRepr_PropertyDefinitionRepresentation) PDR = | |
1171 | Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) ); | |
1172 | if ( PDR.IsNull() ) continue; | |
1173 | ||
1174 | TDF_Label L; | |
1175 | ||
1176 | Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition(); | |
1177 | Interface_EntityIterator subs = Props.Graph().Shareds(PD); | |
1178 | for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) { | |
1179 | if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) { | |
1180 | Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value()); | |
1181 | if(PDS.IsNull()) continue; | |
1182 | // find corresponding NAUO | |
1183 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO; | |
1184 | Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS); | |
1185 | for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) { | |
1186 | if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) ) | |
1187 | NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value()); | |
1188 | } | |
1189 | if ( !NAUO.IsNull() ) { | |
1190 | L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap ); | |
1191 | if ( L.IsNull() ) continue; | |
1192 | } | |
1193 | else { | |
1194 | // find corresponding ProductDefinition: | |
1195 | Handle(StepBasic_ProductDefinition) ProdDef; | |
1196 | Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS); | |
1197 | for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) { | |
1198 | if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) ) | |
1199 | ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value()); | |
1200 | } | |
1201 | if ( ProdDef.IsNull() ) continue; | |
1202 | L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap ); | |
1203 | } | |
1204 | } | |
1205 | ||
1206 | if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) { | |
1207 | Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value()); | |
1208 | if(SA.IsNull()) continue; | |
1209 | // find ShapeRepresentation | |
1210 | Handle(StepShape_ShapeRepresentation) SR; | |
1211 | Interface_EntityIterator subs1 = Props.Graph().Sharings(SA); | |
1212 | for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) { | |
1213 | Handle(StepRepr_PropertyDefinition) PropD1 = | |
1214 | Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value()); | |
1215 | if(PropD1.IsNull()) continue; | |
1216 | Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1); | |
1217 | for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) { | |
1218 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
1219 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); | |
1220 | if(SDR.IsNull()) continue; | |
1221 | SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); | |
1222 | } | |
1223 | } | |
1224 | if(SR.IsNull()) continue; | |
1225 | Handle(Transfer_Binder) binder; | |
1226 | for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) { | |
1227 | if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) { | |
1228 | Handle(StepShape_SolidModel) SM = | |
1229 | Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir)); | |
1230 | binder = TP->Find(SM); | |
1231 | } | |
1232 | else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) { | |
1233 | Handle(StepShape_ShellBasedSurfaceModel) SBSM = | |
1234 | Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir)); | |
1235 | binder = TP->Find(SBSM); | |
1236 | } | |
1237 | else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) { | |
1238 | Handle(StepShape_GeometricSet) GS = | |
1239 | Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir)); | |
1240 | binder = TP->Find(GS); | |
1241 | } | |
1242 | } | |
1243 | if ( binder.IsNull() || ! binder->HasResult() ) continue; | |
1244 | TopoDS_Shape S; | |
1245 | S = TransferBRep::ShapeResult ( TP, binder ); | |
1246 | if(S.IsNull()) continue; | |
1247 | if ( ShapeLabelMap.IsBound ( S ) ) | |
1248 | L = ShapeLabelMap.Find ( S ); | |
1249 | if ( L.IsNull() ) | |
1250 | STool->Search ( S, L, Standard_True, Standard_True, Standard_True ); | |
1251 | } | |
1252 | } | |
1253 | ||
1254 | if(L.IsNull()) continue; | |
1255 | ||
1256 | // decode validation properties | |
1257 | Handle(StepRepr_Representation) rep = PDR->UsedRepresentation(); | |
1258 | for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) { | |
1259 | Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j); | |
1260 | Standard_Boolean isArea; | |
1261 | Standard_Real val; | |
1262 | gp_Pnt pos; | |
1263 | if ( Props.GetPropReal ( ent, val, isArea ) ) { | |
1264 | if ( isArea ) XCAFDoc_Area::Set ( L, val ); | |
1265 | else XCAFDoc_Volume::Set ( L, val ); | |
1266 | } | |
1267 | else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) { | |
1268 | XCAFDoc_Centroid::Set ( L, pos ); | |
1269 | } | |
1270 | } | |
1271 | } | |
1272 | return Standard_True; | |
1273 | } | |
1274 | ||
1275 | //======================================================================= | |
1276 | //function : ReadLayers | |
1277 | //purpose : | |
1278 | //======================================================================= | |
1279 | ||
1280 | Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS, | |
1281 | Handle(TDocStd_Document)& Doc) const | |
1282 | { | |
1283 | Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1284 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1285 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1286 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() ); | |
1287 | if ( STool.IsNull() ) return Standard_False; | |
1288 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() ); | |
1289 | if ( LTool.IsNull() ) return Standard_False; | |
1290 | ||
1291 | Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment); | |
1292 | Standard_Integer nb = Model->NbEntities(); | |
1293 | Handle(TCollection_HAsciiString) name; | |
1294 | ||
1295 | for (Standard_Integer i = 1; i <= nb; i ++) { | |
1296 | Handle(Standard_Transient) enti = Model->Value(i); | |
1297 | if ( ! enti->IsKind ( tSVPLA ) ) continue; | |
1298 | Handle(StepVisual_PresentationLayerAssignment) SVPLA = | |
1299 | Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti); | |
1300 | ||
1301 | Handle(TCollection_HAsciiString) descr = SVPLA->Description(); | |
1302 | Handle(TCollection_HAsciiString) hName = SVPLA->Name(); | |
1303 | TCollection_ExtendedString aLayerName ( hName->String() ); | |
1304 | ||
1305 | // find a target shape and its label in the document | |
1306 | for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) { | |
1307 | StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j); | |
1308 | Handle(Transfer_Binder) binder = TP->Find( LI.Value() ); | |
1309 | if ( binder.IsNull() || ! binder->HasResult() ) continue; | |
1310 | ||
1311 | TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder ); | |
1312 | if ( S.IsNull() ) continue; | |
1313 | ||
1314 | TDF_Label shL; | |
1315 | if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue; | |
1316 | LTool->SetLayer ( shL, aLayerName ); | |
1317 | } | |
1318 | ||
1319 | // check invisibility | |
1320 | Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA); | |
1321 | for (subs.Start(); subs.More(); subs.Next()) { | |
1322 | if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue; | |
0797d9d3 | 1323 | #ifdef OCCT_DEBUG |
7fd59977 | 1324 | cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl; |
1325 | #endif | |
1326 | //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName); | |
1327 | TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926 | |
1328 | Handle(TDataStd_UAttribute) aUAttr; | |
1329 | aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() ); | |
1330 | } | |
1331 | } | |
1332 | return Standard_True; | |
1333 | } | |
1334 | ||
1335 | //======================================================================= | |
1336 | //function : ReadSHUOs | |
1337 | //purpose : | |
1338 | //======================================================================= | |
1339 | ||
1340 | static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS, | |
1341 | const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO, | |
1342 | const Handle(XCAFDoc_ShapeTool)& STool, | |
1343 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1344 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap, | |
1345 | TDF_LabelSequence& aLabels) | |
1346 | { | |
1347 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO); | |
1348 | Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO; | |
1349 | for (subs.Start(); subs.More(); subs.Next()) { | |
1350 | if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) { | |
1351 | subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value()); | |
1352 | break; | |
1353 | } | |
1354 | } | |
1355 | if (subSHUO.IsNull()) | |
1356 | return Standard_False; | |
1357 | ||
1358 | Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = | |
1359 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage()); | |
1360 | if (NUNAUO.IsNull()) | |
1361 | return Standard_False; | |
1362 | // Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1363 | // Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1364 | // Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1365 | // Handle(Transfer_Binder) binder = TP->Find(NUNAUO); | |
1366 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1367 | // return Standard_False; | |
1368 | // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1369 | // get label of NAUO next level | |
1370 | TDF_Label NULab; | |
1371 | STEPConstruct_Tool Tool( WS ); | |
1372 | NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap ); | |
1373 | // STool->Search(NUSh, NUlab); | |
1374 | if (NULab.IsNull()) | |
1375 | return Standard_False; | |
1376 | aLabels.Append( NULab ); | |
1377 | // and check by recurse. | |
1378 | findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels ); | |
1379 | return Standard_True; | |
1380 | } | |
1381 | ||
1382 | ||
1383 | //======================================================================= | |
1384 | //function : setSHUOintoDoc | |
1385 | //purpose : auxilary | |
1386 | //======================================================================= | |
1387 | static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS, | |
1388 | const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO, | |
1389 | const Handle(XCAFDoc_ShapeTool)& STool, | |
1390 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1391 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
1392 | { | |
1393 | TDF_Label aMainLabel; | |
1394 | // get upper usage NAUO from SHUO. | |
1395 | Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO = | |
1396 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage()); | |
1397 | Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = | |
1398 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage()); | |
1399 | if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) { | |
0797d9d3 | 1400 | #ifdef OCCT_DEBUG |
7fd59977 | 1401 | cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl; |
1402 | #endif | |
1403 | return aMainLabel; | |
1404 | } | |
1405 | // Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1406 | // Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1407 | // Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1408 | // TopoDS_Shape UUSh, NUSh; | |
1409 | // Handle(Transfer_Binder) binder = TP->Find(UUNAUO); | |
1410 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1411 | // return aMainLabel; | |
1412 | // UUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1413 | // binder = TP->Find(NUNAUO); | |
1414 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1415 | // return aMainLabel; | |
1416 | // NUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1417 | ||
1418 | // get first labels for first SHUO attribute | |
1419 | TDF_Label UULab, NULab; | |
1420 | STEPConstruct_Tool Tool( WS ); | |
1421 | UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap ); | |
1422 | NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap ); | |
1423 | ||
1424 | // STool->Search(UUSh, UULab); | |
1425 | // STool->Search(NUSh, NULab); | |
1426 | if (UULab.IsNull() || NULab.IsNull()) return aMainLabel; | |
1427 | //create sequence fo labels to set SHUO structure into the document | |
1428 | TDF_LabelSequence ShuoLabels; | |
1429 | ShuoLabels.Append( UULab ); | |
1430 | ShuoLabels.Append( NULab ); | |
1431 | // add all other labels of sub SHUO entities | |
1432 | findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels ); | |
1433 | // last accord for SHUO | |
1434 | Handle(XCAFDoc_GraphNode) anSHUOAttr; | |
1435 | if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) ) | |
1436 | aMainLabel = anSHUOAttr->Label(); | |
1437 | ||
1438 | return aMainLabel; | |
1439 | } | |
1440 | ||
1441 | ||
1442 | //======================================================================= | |
1443 | //function : ReadSHUOs | |
1444 | //purpose : | |
1445 | //======================================================================= | |
1446 | ||
1447 | Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS, | |
1448 | Handle(TDocStd_Document)& Doc, | |
1449 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1450 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
1451 | { | |
1452 | // the big part code duplication from ReadColors. | |
1453 | // It is possible to share this code functionality, just to decide how ??? | |
1454 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() ); | |
1455 | Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool(); | |
1456 | ||
1457 | STEPConstruct_Styles Styles ( WS ); | |
1458 | if ( ! Styles.LoadStyles() ) { | |
0797d9d3 | 1459 | #ifdef OCCT_DEBUG |
7fd59977 | 1460 | cout << "Warning: no styles are found in the model" << endl; |
1461 | #endif | |
1462 | return Standard_False; | |
1463 | } | |
1464 | // searching for invisible items in the model | |
1465 | Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient; | |
1466 | Styles.LoadInvisStyles( aHSeqOfInvisStyle ); | |
1467 | // parse and search for color attributes | |
1468 | Standard_Integer nb = Styles.NbStyles(); | |
1469 | for ( Standard_Integer i=1; i <= nb; i++ ) { | |
1470 | Handle(StepVisual_StyledItem) style = Styles.Style ( i ); | |
1471 | if ( style.IsNull() ) continue; | |
1472 | ||
1473 | Standard_Boolean IsVisible = Standard_True; | |
1474 | // check the visibility of styled item. | |
1475 | for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) { | |
1476 | if ( style != aHSeqOfInvisStyle->Value( si ) ) | |
1477 | continue; | |
1478 | // found that current style is invisible. | |
0797d9d3 | 1479 | #ifdef OCCT_DEBUG |
7fd59977 | 1480 | cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl; |
1481 | #endif | |
1482 | IsVisible = Standard_False; | |
1483 | break; | |
1484 | } | |
1485 | ||
1486 | Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol; | |
1487 | // check if it is component style | |
1488 | Standard_Boolean IsComponent = Standard_False; | |
1489 | if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible ) | |
1490 | continue; | |
1491 | if (!IsComponent) | |
1492 | continue; | |
1493 | Handle(StepShape_ShapeRepresentation) aSR; | |
1494 | findStyledSR( style, aSR ); | |
1495 | // search for SR along model | |
1496 | if ( aSR.IsNull() ) | |
1497 | continue; | |
1498 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR ); | |
1499 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; | |
1500 | for (subs.Start(); subs.More(); subs.Next()) { | |
1501 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
1502 | if ( aSDR.IsNull() ) | |
1503 | continue; | |
1504 | StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition(); | |
1505 | Handle(StepRepr_ProductDefinitionShape) PDS = | |
1506 | Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition()); | |
1507 | if ( PDS.IsNull() ) | |
1508 | continue; | |
1509 | StepRepr_CharacterizedDefinition aCharDef = PDS->Definition(); | |
1510 | Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO = | |
1511 | Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship()); | |
1512 | if ( SHUO.IsNull() ) | |
1513 | continue; | |
1514 | ||
1515 | // set the SHUO structure to the document | |
1516 | TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap ); | |
1517 | if ( aLabelForStyle.IsNull() ) { | |
0797d9d3 | 1518 | #ifdef OCCT_DEBUG |
7fd59977 | 1519 | cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl; |
1520 | #endif | |
1521 | continue; | |
1522 | } | |
1523 | // now set the style to the SHUO main label. | |
1524 | if ( ! SurfCol.IsNull() ) { | |
1525 | Quantity_Color col; | |
1526 | Styles.DecodeColor ( SurfCol, col ); | |
1527 | CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf ); | |
1528 | } | |
1529 | if ( ! BoundCol.IsNull() ) { | |
1530 | Quantity_Color col; | |
1531 | Styles.DecodeColor ( BoundCol, col ); | |
1532 | CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv ); | |
1533 | } | |
1534 | if ( ! CurveCol.IsNull() ) { | |
1535 | Quantity_Color col; | |
1536 | Styles.DecodeColor ( CurveCol, col ); | |
1537 | CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv ); | |
1538 | } | |
1539 | if ( !IsVisible ) | |
1540 | // sets the invisibility for shape. | |
1541 | CTool->SetVisibility( aLabelForStyle, Standard_False ); | |
1542 | ||
1543 | } // end search SHUO by SDR | |
1544 | } // end iterates on styles | |
1545 | ||
1546 | return Standard_True; | |
1547 | } | |
1548 | ||
1549 | ||
1550 | //======================================================================= | |
1551 | //function : GetLengthConversionFactor | |
1552 | //purpose : | |
1553 | //======================================================================= | |
1554 | static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU, | |
1555 | Standard_Real& afact) | |
1556 | { | |
1557 | afact=1.; | |
1558 | if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False; | |
1559 | Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU = | |
1560 | Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU); | |
1561 | Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor(); | |
1562 | afact = MWUCBU->ValueComponent(); | |
1563 | StepBasic_Unit anUnit2 = MWUCBU->UnitComponent(); | |
1564 | if(anUnit2.CaseNum(anUnit2.Value())==1) { | |
1565 | Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit(); | |
1566 | if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) { | |
1567 | Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2); | |
1568 | if(SU->Name()==StepBasic_sunMetre) { | |
1569 | if(SU->HasPrefix()) | |
1570 | afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix()); | |
1571 | // convert m to mm | |
1572 | afact *= 1000.; | |
1573 | } | |
1574 | } | |
1575 | } | |
1576 | return Standard_True; | |
1577 | } | |
1578 | ||
1579 | ||
1580 | //======================================================================= | |
1581 | //function : GetMassConversionFactor | |
1582 | //purpose : | |
1583 | //======================================================================= | |
1584 | static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU, | |
1585 | Standard_Real& afact) | |
1586 | { | |
1587 | afact=1.; | |
1588 | if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False; | |
1589 | Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU = | |
1590 | Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU); | |
1591 | Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor(); | |
1592 | afact = MWUCBU->ValueComponent(); | |
1593 | StepBasic_Unit anUnit2 = MWUCBU->UnitComponent(); | |
1594 | if(anUnit2.CaseNum(anUnit2.Value())==1) { | |
1595 | Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit(); | |
1596 | if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) { | |
1597 | Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2); | |
1598 | if(SU->Name()==StepBasic_sunGram) { | |
1599 | if(SU->HasPrefix()) | |
1600 | afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix()); | |
1601 | } | |
1602 | } | |
1603 | } | |
1604 | return Standard_True; | |
1605 | } | |
1606 | ||
1607 | ||
1608 | //======================================================================= | |
1609 | //function : ReadDatums | |
1610 | //purpose : auxilary | |
1611 | //======================================================================= | |
1612 | static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool, | |
1613 | const Handle(XCAFDoc_DimTolTool) &DGTTool, | |
1614 | const Interface_Graph &graph, | |
1615 | Handle(Transfer_TransientProcess) &TP, | |
1616 | const TDF_Label TolerL, | |
1617 | const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR) | |
1618 | { | |
1619 | if(GTWDR.IsNull()) return Standard_False; | |
1620 | Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem(); | |
1621 | if(HADR.IsNull()) return Standard_False; | |
1622 | for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) { | |
1623 | Handle(StepDimTol_DatumReference) DR = HADR->Value(idr); | |
1624 | Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum(); | |
1625 | if(aDatum.IsNull()) continue; | |
1626 | Interface_EntityIterator subs4 = graph.Sharings(aDatum); | |
1627 | for(subs4.Start(); subs4.More(); subs4.Next()) { | |
1628 | Handle(StepRepr_ShapeAspectRelationship) SAR = | |
1629 | Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value()); | |
1630 | if(SAR.IsNull()) continue; | |
1631 | Handle(StepDimTol_DatumFeature) DF = | |
1632 | Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect()); | |
1633 | if(DF.IsNull()) continue; | |
1634 | Interface_EntityIterator subs5 = graph.Sharings(DF); | |
1635 | Handle(StepRepr_PropertyDefinition) PropDef; | |
1636 | for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) { | |
1637 | PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value()); | |
1638 | } | |
1639 | if(PropDef.IsNull()) continue; | |
1640 | Handle(StepShape_AdvancedFace) AF; | |
1641 | subs5 = graph.Sharings(PropDef); | |
1642 | for(subs5.Start(); subs5.More(); subs5.Next()) { | |
1643 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
1644 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value()); | |
1645 | if(!SDR.IsNull()) { | |
1646 | Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation(); | |
1647 | if( !Repr.IsNull() && Repr->NbItems()>0 ) { | |
1648 | Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1); | |
1649 | AF = Handle(StepShape_AdvancedFace)::DownCast(RI); | |
1650 | } | |
1651 | } | |
1652 | } | |
1653 | if(AF.IsNull()) return Standard_False; | |
1654 | Standard_Integer index = TP->MapIndex(AF); | |
1655 | TopoDS_Shape aSh; | |
1656 | if(index >0) { | |
1657 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
1658 | aSh = TransferBRep::ShapeResult(binder); | |
1659 | } | |
1660 | if(aSh.IsNull()) continue; | |
1661 | TDF_Label shL; | |
1662 | if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue; | |
1663 | DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification()); | |
1664 | } | |
1665 | } | |
1666 | return Standard_True; | |
1667 | } | |
1668 | ||
1669 | ||
1670 | //======================================================================= | |
1671 | //function : ReadGDTs | |
1672 | //purpose : | |
1673 | //======================================================================= | |
1674 | ||
1675 | Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession) &WS, | |
1676 | Handle(TDocStd_Document)& Doc) const | |
1677 | { | |
1678 | Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1679 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() ); | |
1680 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1681 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1682 | Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( Doc->Main() ); | |
1683 | if ( DGTTool.IsNull() ) return Standard_False; | |
1684 | ||
1685 | Standard_Integer nb = Model->NbEntities(); | |
1686 | const Interface_Graph& graph = TP->Graph(); | |
1687 | for(Standard_Integer i=1; i<=nb; i++) { | |
1688 | Handle(Standard_Transient) ent = Model->Value(i); | |
1689 | if(ent->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) { | |
1690 | Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(ent); | |
1691 | // find RepresentationItem for current ShapeAspect | |
1692 | Handle(StepRepr_RepresentationItem) RI; | |
1693 | Handle(StepRepr_PropertyDefinition) PropD; | |
1694 | Interface_EntityIterator subs3 = graph.Sharings(SA); | |
1695 | for(subs3.Start(); subs3.More() && PropD.IsNull(); subs3.Next()) { | |
1696 | PropD = Handle(StepRepr_PropertyDefinition)::DownCast(subs3.Value()); | |
1697 | } | |
1698 | if(PropD.IsNull()) continue; | |
1699 | Interface_EntityIterator subs4 = graph.Sharings(PropD); | |
1700 | for(subs4.Start(); subs4.More(); subs4.Next()) { | |
1701 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
1702 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value()); | |
1703 | if(!SDR.IsNull()) { | |
1704 | Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation(); | |
1705 | if( !Repr.IsNull() && Repr->NbItems()>0 ) { | |
1706 | RI = Repr->ItemsValue(1); | |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | if(RI.IsNull()) continue; | |
1711 | // read DGT entities: | |
1712 | subs3 = graph.Sharings(SA); | |
1713 | for(subs3.Start(); subs3.More(); subs3.Next()) { | |
1714 | if(subs3.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { | |
1715 | // read dimensions | |
1716 | Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI); | |
1717 | if(EC.IsNull()) continue; | |
1718 | Handle(TCollection_HAsciiString) aName; | |
1719 | Handle(StepShape_DimensionalSize) DimSize = | |
1720 | Handle(StepShape_DimensionalSize)::DownCast(subs3.Value()); | |
1721 | Standard_Real dim1=-1.,dim2=-1.; | |
1722 | subs4 = graph.Sharings(DimSize); | |
1723 | for(subs4.Start(); subs4.More(); subs4.Next()) { | |
1724 | Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR = | |
1725 | Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value()); | |
1726 | if(!DimCharR.IsNull()) { | |
1727 | Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation(); | |
1728 | if(!SDimR.IsNull() && SDimR->NbItems()>0) { | |
1729 | Handle(StepRepr_RepresentationItem) RI = SDimR->ItemsValue(1); | |
1730 | Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(RI); | |
1731 | if(!VR.IsNull()) { | |
1732 | aName = VR->Name(); | |
1733 | //StepRepr_CompoundItemDefinition CID = VR->ItemElement(); | |
1734 | //if(CID.IsNull()) continue; | |
1735 | //Handle(StepRepr_CompoundItemDefinitionMember) CIDM = | |
1736 | // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value()); | |
1737 | //if(CIDM.IsNull()) continue; | |
1738 | //if(CIDM->ArrTransient().IsNull()) continue; | |
1739 | //Handle(StepRepr_HArray1OfRepresentationItem) HARI; | |
1740 | //if(CID.CaseMem(CIDM)==1) | |
1741 | // HARI = CID.ListRepresentationItem(); | |
1742 | //if(CID.CaseMem(CIDM)==2) | |
1743 | // HARI = CID.SetRepresentationItem(); | |
1744 | Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement(); | |
1745 | if(HARI.IsNull()) continue; | |
1746 | if(HARI->Length()>0) { | |
1747 | Handle(StepRepr_RepresentationItem) RI1 = | |
1748 | Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1)); | |
1749 | if(RI1.IsNull()) continue; | |
1750 | if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) { | |
1751 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU = | |
1752 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1); | |
1753 | dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent(); | |
1754 | StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent(); | |
1755 | Standard_Real afact=1.; | |
1756 | if(anUnit.IsNull()) continue; | |
1757 | if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue; | |
1758 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); | |
1759 | if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact; | |
1760 | } | |
1761 | } | |
1762 | if(HARI->Length()>1) { | |
1763 | Handle(StepRepr_RepresentationItem) RI2 = | |
1764 | Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2)); | |
1765 | if(RI2.IsNull()) continue; | |
1766 | if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) { | |
1767 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU = | |
1768 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2); | |
1769 | dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent(); | |
1770 | StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent(); | |
1771 | Standard_Real afact=1.; | |
1772 | if(anUnit.IsNull()) continue; | |
1773 | if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue; | |
1774 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); | |
1775 | if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact; | |
1776 | } | |
1777 | } | |
1778 | } | |
1779 | } | |
1780 | } | |
1781 | } | |
1782 | if(dim1<0) continue; | |
1783 | if(dim2<0) dim2=dim1; | |
1784 | //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl; | |
1785 | // now we know edge_curve and value range therefore | |
1786 | // we can create corresponding D> labels | |
1787 | Standard_Integer index = TP->MapIndex(EC); | |
1788 | TopoDS_Shape aSh; | |
1789 | if(index >0) { | |
1790 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
1791 | aSh = TransferBRep::ShapeResult(binder); | |
1792 | } | |
1793 | if(aSh.IsNull()) continue; | |
1794 | TDF_Label shL; | |
1795 | if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue; | |
1796 | Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2); | |
1797 | arr->SetValue(1,dim1); | |
1798 | arr->SetValue(2,dim2); | |
1799 | DGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name()); | |
1800 | } | |
1801 | // read tolerances and datums | |
1802 | else if(subs3.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
1803 | Handle(StepDimTol_GeometricTolerance) GT = | |
1804 | Handle(StepDimTol_GeometricTolerance)::DownCast(subs3.Value()); | |
1805 | // read common data for tolerance | |
1806 | //Standard_Real dim = GT->Magnitude()->ValueComponent(); | |
1807 | Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude(); | |
1808 | if(dim3.IsNull()) continue; | |
1809 | Standard_Real dim = dim3->ValueComponent(); | |
1810 | StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent(); | |
1811 | Standard_Real afact=1.; | |
1812 | if(anUnit.IsNull()) continue; | |
1813 | if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue; | |
1814 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); | |
1815 | if(GetLengthConversionFactor(NU,afact)) dim = dim*afact; | |
1816 | //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl; | |
1817 | Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1); | |
1818 | arr->SetValue(1,dim); | |
1819 | Handle(TCollection_HAsciiString) aName = GT->Name(); | |
1820 | Handle(TCollection_HAsciiString) aDescription = GT->Description(); | |
1821 | Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI); | |
1822 | if(AF.IsNull()) continue; | |
1823 | Standard_Integer index = TP->MapIndex(AF); | |
1824 | TopoDS_Shape aSh; | |
1825 | if(index >0) { | |
1826 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
1827 | aSh = TransferBRep::ShapeResult(binder); | |
1828 | } | |
1829 | if(aSh.IsNull()) continue; | |
1830 | TDF_Label shL; | |
1831 | if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue; | |
1832 | // read specific data for tolerance | |
1833 | if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) { | |
1834 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex = | |
1835 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(subs3.Value()); | |
1836 | Standard_Integer kind=20; | |
1837 | Handle(StepDimTol_ModifiedGeometricTolerance) MGT = | |
1838 | GTComplex->GetModifiedGeometricTolerance(); | |
1839 | if(!MGT.IsNull()) { | |
1840 | kind = kind + MGT->Modifier()+1; | |
1841 | } | |
1842 | TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription); | |
1843 | // translate datums connected with this tolerance | |
1844 | Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR = | |
1845 | GTComplex->GetGeometricToleranceWithDatumReference(); | |
1846 | if(!GTWDR.IsNull()) { | |
1847 | ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR); | |
1848 | } | |
1849 | } | |
1850 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) { | |
1851 | Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR = | |
1852 | Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(subs3.Value()); | |
1853 | if(GTWDR.IsNull()) continue; | |
1854 | Standard_Integer kind = 0; | |
1855 | if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24; | |
1856 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25; | |
1857 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26; | |
1858 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27; | |
1859 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28; | |
1860 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29; | |
1861 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30; | |
1862 | else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31; | |
1863 | //cout<<"GTWDR: kind="<<kind<<endl; | |
1864 | TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription); | |
1865 | ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR); | |
1866 | } | |
1867 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) { | |
1868 | Handle(StepDimTol_ModifiedGeometricTolerance) MGT = | |
1869 | Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(subs3.Value()); | |
1870 | Standard_Integer kind = 35 + MGT->Modifier(); | |
1871 | DGTTool->SetDimTol(shL,kind,arr,aName,aDescription); | |
1872 | } | |
1873 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) { | |
1874 | DGTTool->SetDimTol(shL,38,arr,aName,aDescription); | |
1875 | } | |
1876 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) { | |
1877 | DGTTool->SetDimTol(shL,39,arr,aName,aDescription); | |
1878 | } | |
1879 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) { | |
1880 | DGTTool->SetDimTol(shL,40,arr,aName,aDescription); | |
1881 | } | |
1882 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) { | |
1883 | DGTTool->SetDimTol(shL,41,arr,aName,aDescription); | |
1884 | } | |
1885 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) { | |
1886 | DGTTool->SetDimTol(shL,42,arr,aName,aDescription); | |
1887 | } | |
1888 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) { | |
1889 | DGTTool->SetDimTol(shL,43,arr,aName,aDescription); | |
1890 | } | |
1891 | else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) { | |
1892 | DGTTool->SetDimTol(shL,44,arr,aName,aDescription); | |
1893 | } | |
1894 | } | |
1895 | } | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | return Standard_True; | |
1900 | } | |
1901 | ||
1902 | ||
1903 | //======================================================================= | |
1904 | //function : FindSolidForPDS | |
1905 | //purpose : auxilary | |
1906 | //======================================================================= | |
1907 | ||
1908 | static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS, | |
1909 | const Interface_Graph &graph) | |
1910 | { | |
1911 | Handle(StepShape_SolidModel) SM; | |
1912 | Interface_EntityIterator subs = graph.Sharings(PDS); | |
1913 | Handle(StepShape_ShapeRepresentation) SR; | |
1914 | for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) { | |
1915 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
1916 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
1917 | if(SDR.IsNull()) continue; | |
1918 | SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); | |
1919 | if(SR.IsNull()) continue; | |
1920 | for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) { | |
1921 | SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i)); | |
1922 | } | |
1923 | if(SM.IsNull()) { | |
1924 | Interface_EntityIterator subs1 = graph.Sharings(SR); | |
1925 | for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) { | |
1926 | Handle(StepRepr_RepresentationRelationship) RR = | |
1927 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value()); | |
1928 | if(RR.IsNull()) continue; | |
1929 | Handle(StepShape_ShapeRepresentation) SR2; | |
1930 | if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); | |
1931 | else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); | |
1932 | if(SR2.IsNull()) continue; | |
1933 | for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) { | |
1934 | SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2)); | |
1935 | } | |
1936 | } | |
1937 | } | |
1938 | } | |
1939 | return SM; | |
1940 | } | |
1941 | ||
1942 | ||
1943 | //======================================================================= | |
1944 | //function : ReadMaterials | |
1945 | //purpose : | |
1946 | //======================================================================= | |
1947 | ||
1948 | Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS, | |
1949 | Handle(TDocStd_Document)& Doc, | |
1950 | const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const | |
1951 | { | |
1952 | Handle(Interface_InterfaceModel) Model = WS->Model(); | |
1953 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() ); | |
1954 | Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1955 | Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1956 | Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() ); | |
1957 | if(MatTool.IsNull()) return Standard_False; | |
1958 | ||
1959 | const Interface_Graph& graph = TP->Graph(); | |
1960 | for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) { | |
1961 | Handle(StepRepr_ProductDefinitionShape) PDS = | |
1962 | Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i)); | |
1d2b1ccb G |
1963 | if(PDS.IsNull()) |
1964 | continue; | |
1965 | Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition(); | |
1966 | if(aProdDef.IsNull()) | |
1967 | continue; | |
7fd59977 | 1968 | Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(""); |
1969 | Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString(""); | |
1970 | Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString(""); | |
1971 | Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString(""); | |
1972 | Standard_Real aDensity=0; | |
1d2b1ccb | 1973 | Interface_EntityIterator subs = graph.Sharings( aProdDef); |
7fd59977 | 1974 | for(subs.Start(); subs.More(); subs.Next()) { |
1975 | Handle(StepRepr_PropertyDefinition) PropD = | |
1976 | Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value()); | |
1977 | if(PropD.IsNull()) continue; | |
1978 | Interface_EntityIterator subs1 = graph.Sharings(PropD); | |
1979 | for(subs1.Start(); subs1.More(); subs1.Next()) { | |
1980 | Handle(StepRepr_PropertyDefinitionRepresentation) PDR = | |
1981 | Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value()); | |
1982 | if(PDR.IsNull()) continue; | |
1983 | Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation(); | |
1984 | if(Repr.IsNull()) continue; | |
1985 | Standard_Integer ir; | |
1986 | for(ir=1; ir<=Repr->NbItems(); ir++) { | |
1987 | Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir); | |
1988 | if(RI.IsNull()) continue; | |
1989 | if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) { | |
1990 | // find name and description for material | |
1991 | Handle(StepRepr_DescriptiveRepresentationItem) DRI = | |
1992 | Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI); | |
1993 | aName = DRI->Name(); | |
87073a10 | 1994 | |
7fd59977 | 1995 | aDescription = DRI->Description(); |
87073a10 | 1996 | if(aName.IsNull()) |
1997 | aName = aDescription; | |
7fd59977 | 1998 | } |
1999 | if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) { | |
2000 | // try to find density for material | |
2001 | Handle(StepRepr_MeasureRepresentationItem) MRI = | |
2002 | Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI); | |
2003 | aDensity = MRI->Measure()->ValueComponent(); | |
2004 | aDensName = MRI->Name(); | |
2005 | aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name()); | |
2006 | StepBasic_Unit aUnit = MRI->Measure()->UnitComponent(); | |
2007 | if(!aUnit.IsNull()) { | |
2008 | Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit(); | |
2009 | if(DU.IsNull()) continue; | |
2010 | for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) { | |
2011 | Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu); | |
2012 | Handle(StepBasic_NamedUnit) NU = DUE->Unit(); | |
2013 | Standard_Real afact=1.; | |
2014 | if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) { | |
2015 | if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact); | |
2016 | // transfer length value for Density from millimeter to santimeter | |
2017 | // in order to result density has dimension gram/(sm*sm*sm) | |
2018 | aDensity = aDensity*1000.; | |
2019 | } | |
2020 | if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) { | |
2021 | if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact; | |
2022 | } | |
2023 | } | |
2024 | } | |
2025 | } | |
2026 | } | |
2027 | } | |
2028 | } | |
87073a10 | 2029 | |
2030 | if( aName.IsNull() || aName->Length()==0 ) | |
2031 | continue; | |
7fd59977 | 2032 | // find shape label amd create Material link |
2033 | TopoDS_Shape aSh; | |
2034 | Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph); | |
2035 | if(!SM.IsNull()) { | |
2036 | Standard_Integer index = TP->MapIndex(SM); | |
2037 | if(index >0) { | |
2038 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
2039 | if(!binder.IsNull()) | |
2040 | aSh = TransferBRep::ShapeResult(binder); | |
2041 | } | |
2042 | } | |
2043 | if(aSh.IsNull()) continue; | |
2044 | TDF_Label shL; | |
2045 | if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue; | |
2046 | MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType); | |
2047 | } | |
2048 | ||
2049 | return Standard_True; | |
2050 | } | |
2051 | ||
02a0b964 | 2052 | //======================================================================= |
2053 | //function : SettleShapeData | |
2054 | //purpose : | |
2055 | //======================================================================= | |
2056 | ||
2057 | TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem, | |
2058 | TDF_Label& theLab, | |
2059 | const Handle(XCAFDoc_ShapeTool)& theShapeTool, | |
2060 | const Handle(Transfer_TransientProcess)& TP) const | |
2061 | { | |
2062 | TDF_Label aResult = theLab; | |
2063 | ||
2064 | Handle(TCollection_HAsciiString) hName = theItem->Name(); | |
2065 | if ( hName.IsNull() || hName->IsEmpty() ) | |
2066 | return aResult; | |
2067 | ||
2068 | Handle(Transfer_Binder) aBinder = TP->Find(theItem); | |
2069 | if ( aBinder.IsNull() ) | |
2070 | return aResult; | |
2071 | ||
2072 | TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder); | |
2073 | if ( aShape.IsNull() ) | |
2074 | return aResult; | |
2075 | ||
2076 | // Allocate sub-Label | |
2077 | aResult = AllocateSubLabel(theLab); | |
2078 | ||
2079 | TCollection_AsciiString aName = hName->String(); | |
2080 | TDataStd_Name::Set(aResult, aName); | |
2081 | theShapeTool->SetShape(aResult, aShape); | |
2082 | ||
2083 | return aResult; | |
2084 | } | |
2085 | ||
2086 | //======================================================================= | |
2087 | //function : ExpandSubShapes | |
2088 | //purpose : | |
2089 | //======================================================================= | |
2090 | ||
2091 | void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool, | |
2092 | const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap, | |
2093 | const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const | |
2094 | { | |
02a0b964 | 2095 | const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess(); |
2096 | NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap; | |
2097 | TColStd_MapOfTransient aRepItems; | |
2098 | ||
2099 | // Read translation control variables | |
2100 | Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0); | |
2101 | ||
2102 | if ( !doReadSNames ) | |
2103 | return; | |
2104 | ||
2105 | const Interface_Graph& Graph = Reader().WS()->Graph(); | |
2106 | ||
2107 | for ( STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next() ) | |
2108 | { | |
2109 | const TopoDS_Shape& aRootShape = it.Key(); | |
2110 | const Handle(StepBasic_ProductDefinition)& aPDef = it.Value(); | |
2111 | if ( aPDef.IsNull() ) | |
2112 | continue; | |
2113 | ||
2114 | // Find SDR by Product | |
2115 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; | |
2116 | Interface_EntityIterator entIt = Graph.TypedSharings( aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation) ); | |
2117 | for ( entIt.Start(); entIt.More(); entIt.Next() ) | |
2118 | { | |
2119 | const Handle(Standard_Transient)& aReferer = entIt.Value(); | |
2120 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer); | |
2121 | if ( !aSDR.IsNull() ) | |
2122 | break; | |
2123 | } | |
2124 | ||
2125 | if ( aSDR.IsNull() ) | |
2126 | continue; | |
2127 | ||
2128 | // Access shape representation | |
2129 | Handle(StepShape_ShapeRepresentation) | |
2130 | aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast( aSDR->UsedRepresentation() ); | |
2131 | ||
2132 | if ( aShapeRepr.IsNull() ) | |
2133 | continue; | |
2134 | ||
2135 | // Access representation items | |
2136 | Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aShapeRepr->Items(); | |
2137 | ||
2138 | if ( aReprItems.IsNull() ) | |
2139 | continue; | |
2140 | ||
2141 | if ( !ShapeLabelMap.IsBound(aRootShape) ) | |
2142 | continue; | |
2143 | ||
2144 | TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape); | |
2145 | ||
2146 | StepRepr_SequenceOfRepresentationItem aMSBSeq; | |
2147 | StepRepr_SequenceOfRepresentationItem aSBSMSeq; | |
2148 | ||
2149 | // Iterate over the top level representation items collecting the | |
2150 | // topological containers to expand | |
2151 | for ( Standard_Integer i = aReprItems->Lower(); i <= aReprItems->Upper(); ++i ) | |
2152 | { | |
2153 | Handle(StepRepr_RepresentationItem) aTRepr = aReprItems->Value(i); | |
2154 | if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) ) | |
2155 | aMSBSeq.Append(aTRepr); | |
2156 | else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) ) | |
2157 | aSBSMSeq.Append(aTRepr); | |
2158 | } | |
2159 | ||
2160 | // Insert intermediate OCAF Labels for SOLIDs in case there are more | |
2161 | // than one Manifold Solid BRep in the Shape Representation | |
2162 | Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1); | |
2163 | ||
2164 | // Expand Manifold Solid BReps | |
2165 | for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i ) | |
2166 | { | |
2167 | const Handle(StepRepr_RepresentationItem)& aManiRepr = aMSBSeq.Value(i); | |
2168 | ||
2169 | // Put additional Label for SOLID | |
2170 | TDF_Label aManiLab; | |
2171 | if ( doInsertSolidLab ) | |
2172 | aManiLab = SettleShapeData(aManiRepr, aRootLab, ShapeTool, TP); | |
2173 | else | |
2174 | aManiLab = aRootLab; | |
2175 | ||
2176 | ExpandManifoldSolidBrep(aManiLab, aMSBSeq.Value(i), TP, ShapeTool); | |
2177 | } | |
2178 | ||
2179 | // Expand Shell-Based Surface Models | |
2180 | for ( Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i ) | |
2181 | ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool); | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | //======================================================================= | |
2186 | //function : ExpandManifoldSolidBrep | |
2187 | //purpose : | |
2188 | //======================================================================= | |
2189 | ||
2190 | void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab, | |
2191 | const Handle(StepRepr_RepresentationItem)& Repr, | |
2192 | const Handle(Transfer_TransientProcess)& TP, | |
2193 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
2194 | { | |
2195 | // Access outer shell | |
2196 | Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr); | |
eab2c851 | 2197 | Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer(); |
02a0b964 | 2198 | |
2199 | // Expand shell contents to CAF tree | |
2200 | ExpandShell(aShell, ShapeLab, TP, ShapeTool); | |
2201 | } | |
2202 | ||
2203 | //======================================================================= | |
2204 | //function : ExpandSBSM | |
2205 | //purpose : | |
2206 | //======================================================================= | |
2207 | ||
2208 | void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab, | |
2209 | const Handle(StepRepr_RepresentationItem)& Repr, | |
2210 | const Handle(Transfer_TransientProcess)& TP, | |
2211 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
2212 | { | |
2213 | Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr); | |
2214 | ||
2215 | // Access boundary shells | |
2216 | Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary(); | |
2217 | for ( Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s ) | |
2218 | { | |
2219 | const StepShape_Shell& aShell = aShells->Value(s); | |
2220 | Handle(StepShape_ConnectedFaceSet) aCFS; | |
2221 | Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell(); | |
2222 | Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell(); | |
2223 | ||
2224 | if ( !anOpenShell.IsNull() ) | |
2225 | aCFS = anOpenShell; | |
2226 | else | |
2227 | aCFS = aClosedShell; | |
2228 | ||
2229 | ExpandShell(aCFS, ShapeLab, TP, ShapeTool); | |
2230 | } | |
2231 | } | |
2232 | ||
2233 | //======================================================================= | |
2234 | //function : ExpandShell | |
2235 | //purpose : | |
2236 | //======================================================================= | |
2237 | ||
2238 | void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell, | |
2239 | TDF_Label& RootLab, | |
2240 | const Handle(Transfer_TransientProcess)& TP, | |
2241 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
2242 | { | |
2243 | // Record CAF data | |
2244 | TDF_Label aShellLab = SettleShapeData(Shell, RootLab, ShapeTool, TP); | |
2245 | ||
2246 | // Access faces | |
2247 | Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces(); | |
2248 | for ( Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f ) | |
2249 | { | |
2250 | const Handle(StepShape_Face)& aFace = aFaces->Value(f); | |
2251 | ||
2252 | // Record CAF data | |
2253 | TDF_Label aFaceLab = SettleShapeData(aFace, aShellLab, ShapeTool, TP); | |
2254 | ||
2255 | // Access face bounds | |
2256 | Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds(); | |
2257 | for ( Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w ) | |
2258 | { | |
2259 | const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound(); | |
2260 | ||
2261 | // Record CAF data | |
2262 | TDF_Label aWireLab = SettleShapeData(aWire, aFaceLab, ShapeTool, TP); | |
2263 | ||
2264 | // Access wire edges | |
2265 | // Currently only EDGE LOOPs are considered (!) | |
2266 | if ( !aWire->IsInstance( STANDARD_TYPE(StepShape_EdgeLoop) ) ) | |
2267 | continue; | |
2268 | ||
2269 | // Access edges | |
2270 | Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire); | |
2271 | Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList(); | |
2272 | for ( Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e ) | |
2273 | { | |
2274 | Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement(); | |
2275 | ||
2276 | // Record CAF data | |
2277 | TDF_Label anEdgeLab = SettleShapeData(anEdge, aWireLab, ShapeTool, TP); | |
2278 | ||
2279 | // Access vertices | |
2280 | Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart(); | |
2281 | Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd(); | |
2282 | ||
2283 | // Record CAF data | |
2284 | SettleShapeData(aV1, anEdgeLab, ShapeTool, TP); | |
2285 | SettleShapeData(aV2, anEdgeLab, ShapeTool, TP); | |
2286 | } | |
2287 | } | |
2288 | } | |
2289 | } | |
7fd59977 | 2290 | |
2291 | //======================================================================= | |
2292 | //function : SetColorMode | |
2293 | //purpose : | |
2294 | //======================================================================= | |
2295 | ||
2296 | void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode) | |
2297 | { | |
2298 | myColorMode = colormode; | |
2299 | } | |
2300 | ||
2301 | //======================================================================= | |
2302 | //function : GetColorMode | |
2303 | //purpose : | |
2304 | //======================================================================= | |
2305 | ||
2306 | Standard_Boolean STEPCAFControl_Reader::GetColorMode () const | |
2307 | { | |
2308 | return myColorMode; | |
2309 | } | |
2310 | ||
2311 | //======================================================================= | |
2312 | //function : SetNameMode | |
2313 | //purpose : | |
2314 | //======================================================================= | |
2315 | ||
2316 | void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode) | |
2317 | { | |
2318 | myNameMode = namemode; | |
2319 | } | |
2320 | ||
2321 | //======================================================================= | |
2322 | //function : GetNameMode | |
2323 | //purpose : | |
2324 | //======================================================================= | |
2325 | ||
2326 | Standard_Boolean STEPCAFControl_Reader::GetNameMode () const | |
2327 | { | |
2328 | return myNameMode; | |
2329 | } | |
2330 | ||
2331 | //======================================================================= | |
2332 | //function : SetLayerMode | |
2333 | //purpose : | |
2334 | //======================================================================= | |
2335 | ||
2336 | void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode) | |
2337 | { | |
2338 | myLayerMode = layermode; | |
2339 | } | |
2340 | ||
2341 | //======================================================================= | |
2342 | //function : GetLayerMode | |
2343 | //purpose : | |
2344 | //======================================================================= | |
2345 | ||
2346 | Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const | |
2347 | { | |
2348 | return myLayerMode; | |
2349 | } | |
2350 | ||
2351 | //======================================================================= | |
2352 | //function : SetPropsMode | |
2353 | //purpose : | |
2354 | //======================================================================= | |
2355 | ||
2356 | void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode) | |
2357 | { | |
2358 | myPropsMode = propsmode; | |
2359 | } | |
2360 | ||
2361 | //======================================================================= | |
2362 | //function : GetPropsMode | |
2363 | //purpose : | |
2364 | //======================================================================= | |
2365 | ||
2366 | Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const | |
2367 | { | |
2368 | return myPropsMode; | |
2369 | } | |
2370 | ||
2371 | //======================================================================= | |
2372 | //function : SetSHUOMode | |
2373 | //purpose : | |
2374 | //======================================================================= | |
2375 | ||
2376 | void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode) | |
2377 | { | |
2378 | mySHUOMode = mode; | |
2379 | } | |
2380 | ||
2381 | //======================================================================= | |
2382 | //function : GetSHUOMode | |
2383 | //purpose : | |
2384 | //======================================================================= | |
2385 | ||
2386 | Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const | |
2387 | { | |
2388 | return mySHUOMode; | |
2389 | } | |
2390 | ||
2391 | //======================================================================= | |
2392 | //function : SetGDTMode | |
2393 | //purpose : | |
2394 | //======================================================================= | |
2395 | ||
2396 | void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode) | |
2397 | { | |
2398 | myGDTMode = gdtmode; | |
2399 | } | |
2400 | ||
2401 | //======================================================================= | |
2402 | //function : GetGDTMode | |
2403 | //purpose : | |
2404 | //======================================================================= | |
2405 | ||
2406 | Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const | |
2407 | { | |
2408 | return myGDTMode; | |
2409 | } | |
2410 | ||
2411 | ||
2412 | //======================================================================= | |
2413 | //function : SetMatMode | |
2414 | //purpose : | |
2415 | //======================================================================= | |
2416 | ||
2417 | void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode) | |
2418 | { | |
2419 | myMatMode = matmode; | |
2420 | } | |
2421 | ||
2422 | //======================================================================= | |
2423 | //function : GetMatMode | |
2424 | //purpose : | |
2425 | //======================================================================= | |
2426 | ||
2427 | Standard_Boolean STEPCAFControl_Reader::GetMatMode () const | |
2428 | { | |
2429 | return myMatMode; | |
2430 | } |