1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <STEPCAFControl_Reader.ixx>
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>
25 #include <Transfer_TransientProcess.hxx>
26 #include <TransferBRep.hxx>
27 #include <Transfer_Binder.hxx>
28 #include <Interface_InterfaceModel.hxx>
29 #include <XSControl_TransferReader.hxx>
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>
43 #include <StepRepr_SequenceOfRepresentationItem.hxx>
44 #include <StepVisual_StyledItem.hxx>
45 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
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>
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>
81 #include <TDataStd_TreeNode.hxx>
82 #include <TNaming_NamedShape.hxx>
83 #include <BRep_Builder.hxx>
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>
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>
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>
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>
156 #include <StepShape_SolidModel.hxx>
157 #include <StepShape_ShellBasedSurfaceModel.hxx>
158 #include <StepShape_GeometricSet.hxx>
159 #include <StepBasic_ProductDefinition.hxx>
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>
177 //! Converts address of the passed shape (TShape) to string.
178 //! \param theShape [in] Shape to dump.
179 //! \return corresponding string.
180 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
182 std::string anAddrStr;
183 std::ostringstream ost;
184 ost << theShape.TShape().Access();
185 anAddrStr = ost.str();
187 TCollection_AsciiString aStr =
188 TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]");
194 //=======================================================================
196 //purpose : global function to check equality of topological shapes
197 //=======================================================================
199 inline Standard_Boolean IsEqual(const TopoDS_Shape& theShape1,
200 const TopoDS_Shape& theShape2)
202 return theShape1.IsEqual(theShape2);
205 //=======================================================================
206 //function : AllocateSubLabel
208 //=======================================================================
210 static TDF_Label AllocateSubLabel(TDF_Label& theRoot)
212 return TDF_TagSource::NewChild(theRoot);
215 //=======================================================================
216 //function : STEPCAFControl_Reader
218 //=======================================================================
220 STEPCAFControl_Reader::STEPCAFControl_Reader ():
221 myColorMode( Standard_True ),
222 myNameMode ( Standard_True ),
223 myLayerMode( Standard_True ),
224 myPropsMode( Standard_True ),
225 mySHUOMode ( Standard_False ),
226 myGDTMode ( Standard_True ),
227 myMatMode ( Standard_True )
229 STEPCAFControl_Controller::Init();
230 myFiles = new STEPCAFControl_DictionaryOfExternFile;
234 //=======================================================================
235 //function : STEPCAFControl_Reader
237 //=======================================================================
239 STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
240 const Standard_Boolean scratch) :
241 myColorMode( Standard_True ),
242 myNameMode ( Standard_True ),
243 myLayerMode( Standard_True ),
244 myPropsMode( Standard_True ),
245 mySHUOMode ( Standard_False ),
246 myGDTMode ( Standard_True ),
247 myMatMode ( Standard_True )
249 STEPCAFControl_Controller::Init();
250 Init ( WS, scratch );
254 //=======================================================================
257 //=======================================================================
259 void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
260 const Standard_Boolean scratch)
262 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
263 myReader.SetWS (WS,scratch);
264 myFiles = new STEPCAFControl_DictionaryOfExternFile;
268 //=======================================================================
269 //function : ReadFile
271 //=======================================================================
273 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
275 return myReader.ReadFile ( filename );
279 //=======================================================================
280 //function : NbRootsForTransfer
282 //=======================================================================
284 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
286 return myReader.NbRootsForTransfer();
290 //=======================================================================
291 //function : TransferOneRoot
293 //=======================================================================
295 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
296 Handle(TDocStd_Document) &doc)
298 TDF_LabelSequence Lseq;
299 return Transfer ( myReader, num, doc, Lseq );
303 //=======================================================================
304 //function : Transfer
306 //=======================================================================
308 Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
310 TDF_LabelSequence Lseq;
311 return Transfer ( myReader, 0, doc, Lseq );
315 //=======================================================================
318 //=======================================================================
320 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
321 Handle(TDocStd_Document) &doc)
323 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
324 return Transfer ( doc );
328 //=======================================================================
331 //=======================================================================
333 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
334 Handle(TDocStd_Document) &doc)
336 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
337 return Transfer ( doc );
341 //=======================================================================
342 //function : ExternFiles
344 //=======================================================================
346 const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
352 //=======================================================================
353 //function : ExternFile
355 //=======================================================================
357 Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
358 Handle(STEPCAFControl_ExternFile) &ef) const
361 if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
362 return Standard_False;
363 ef = myFiles->Item ( name );
364 return Standard_True;
368 //=======================================================================
371 //=======================================================================
373 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
379 //=======================================================================
382 //=======================================================================
384 const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
390 //=======================================================================
391 //function : FillShapesMap
392 //purpose : auxiliary: fill a map by all compounds and their components
393 //=======================================================================
395 static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
401 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
402 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
403 FillShapesMap ( it.Value(), map );
407 //=======================================================================
408 //function : Transfer
409 //purpose : basic working method
410 //=======================================================================
412 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
413 const Standard_Integer nroot,
414 Handle(TDocStd_Document) &doc,
415 TDF_LabelSequence &Lseq,
416 const Standard_Boolean asOne)
418 reader.ClearShapes();
422 Standard_Integer num = reader.NbRootsForTransfer();
423 if ( num <=0 ) return Standard_False;
425 if ( nroot > num ) return Standard_False;
426 reader.TransferOneRoot ( nroot );
429 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
431 num = reader.NbShapes();
432 if ( num <=0 ) return Standard_False;
434 // Fill a map of (top-level) shapes resulting from that transfer
435 // Only these shapes will be considered further
436 TopTools_MapOfShape ShapesMap, NewShapesMap;
437 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
439 // Collect information on shapes originating from SDRs
440 // this will be used to distinguish compounds representing assemblies
441 // from the ones representing hybrid models and shape sets
442 STEPCAFControl_DataMapOfShapePD ShapePDMap;
443 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
444 Handle(Interface_InterfaceModel) Model = reader.Model();
445 Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess();
446 Standard_Integer nb = Model->NbEntities();
448 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
450 for (i = 1; i <= nb; i ++) {
451 Handle(Standard_Transient) enti = Model->Value(i);
452 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
453 // sequence for acceleration ReadMaterials
454 SeqPDS->Append(enti);
456 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
457 Handle(StepBasic_ProductDefinition) PD =
458 Handle(StepBasic_ProductDefinition)::DownCast(enti);
459 Standard_Integer index = TP->MapIndex(PD);
461 Handle(Transfer_Binder) binder = TP->MapItem (index);
462 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
463 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
465 ShapePDMap.Bind ( S, PD );
466 Handle(STEPCAFControl_ExternFile) EF;
467 PDFileMap.Bind ( PD, EF );
471 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
472 Standard_Integer index = TP->MapIndex(enti);
474 Handle(Transfer_Binder) binder = TP->MapItem (index);
475 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
476 if ( ! S.IsNull() && ShapesMap.Contains(S) )
482 // get directory name of the main file
483 OSD_Path mainfile ( reader.WS()->LoadedFile() );
484 mainfile.SetName ( "" );
485 mainfile.SetExtension ( "" );
486 TCollection_AsciiString dpath;
487 mainfile.SystemName ( dpath );
489 // Load external references (only for relevant SDRs)
490 // and fill map SDR -> extern file
491 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
492 ExtRefs.LoadExternRefs();
493 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
494 // check extern ref format
495 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
496 if ( ! format.IsNull() ) {
497 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
498 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
499 if ( ! format->IsSameString ( ap203, Standard_False ) &&
500 ! format->IsSameString ( ap214, Standard_False ) ) {
502 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
509 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
512 // get and check filename of the current extern ref
513 const Standard_CString filename = ExtRefs.FileName(i);
516 cout<<"filename="<<filename<<endl;
519 if ( ! filename || ! filename[0] ) {
521 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
523 continue; // not a valid extern ref
526 // compute true path to the extern file
527 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
528 if ( fullname.Length() <= 0 ) fullname = filename;
532 char *mainfile = reader.WS()->LoadedFile();
533 if ( ! mainfile ) mainfile = "";
534 Standard_Integer slash = 0;
535 for ( Standard_Integer k=0; mainfile[k]; k++ )
536 if ( mainfile[k] == '/' ) slash = k;
537 strncpy ( fullname, mainfile, slash );
538 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
541 // get and check PD associated with the current extern ref
542 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
543 if ( PD.IsNull() ) continue; // not a valid extern ref
544 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
546 // read extern file (or use existing data) and record its data
547 Handle(STEPCAFControl_ExternFile) EF =
548 ReadExternFile ( filename, fullname.ToCString(), doc );
549 PDFileMap.Bind ( PD, EF );
552 // and insert them to the document
553 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
554 if ( STool.IsNull() ) return Standard_False;
555 XCAFDoc_DataMapOfShapeLabel map;
557 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
559 for ( i=1; i <= num; i++ ) {
560 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
565 if ( GetColorMode() )
566 ReadColors ( reader.WS(), doc, PDFileMap, map );
570 ReadNames ( reader.WS(), doc, PDFileMap, map );
572 // read validation props
573 if ( GetPropsMode() )
574 ReadValProps ( reader.WS(), doc, PDFileMap, map );
577 if ( GetLayerMode() )
578 ReadLayers ( reader.WS(), doc );
580 // read SHUO entities from STEP model
582 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
584 // read GDT entities from STEP model
586 ReadGDTs(reader.WS(),doc);
588 // read Material entities from STEP model
590 ReadMaterials(reader.WS(),doc,SeqPDS);
592 // Expand resulting CAF structure for sub-shapes (optionally with their
593 // names) if requested
594 ExpandSubShapes(STool, map, ShapePDMap);
596 return Standard_True;
599 //=======================================================================
600 //function : AddShape
602 //=======================================================================
604 TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
605 const Handle(XCAFDoc_ShapeTool) &STool,
606 const TopTools_MapOfShape &NewShapesMap,
607 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
608 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
609 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
611 // if shape has already been mapped, just return corresponding label
612 if ( ShapeLabelMap.IsBound ( S ) ) {
613 return ShapeLabelMap.Find ( S );
616 // if shape is located, create instance
617 if ( ! S.Location().IsIdentity() ) {
621 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
622 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
623 ShapeLabelMap.Bind ( S, L );
627 // if shape is not compound, simple add it
628 if ( S.ShapeType() != TopAbs_COMPOUND ) {
629 TDF_Label L = STool->AddShape ( S, Standard_False );
630 ShapeLabelMap.Bind ( S, L );
634 // for compounds, compute number of subshapes and check whether this is assembly
635 Standard_Boolean isAssembly = Standard_False;
636 Standard_Integer nbComponents = 0;
638 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
639 TopoDS_Shape Sub0 = it.Value();
641 Sub0.Location ( loc );
642 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
645 // if(nbComponents>0) isAssembly = Standard_True;
647 // check whether it has associated external ref
648 TColStd_SequenceOfHAsciiString SHAS;
649 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
650 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
651 if ( ! EF.IsNull() ) {
652 // (store information on extern refs in the document)
653 SHAS.Append(EF->GetName());
654 // if yes, just return corresponding label
655 if ( ! EF->GetLabel().IsNull() ) {
656 // but if components >0, ignore extern ref!
657 if ( nbComponents <=0 ) {
658 ShapeLabelMap.Bind ( S, EF->GetLabel() );
659 STool->SetExternRefs(EF->GetLabel(),SHAS);
660 return EF->GetLabel();
664 if ( ! EF->GetLabel().IsNull() )
665 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
666 else if ( nbComponents <=0 )
667 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
672 // add compound either as a whole,
673 if ( ! isAssembly ) {
674 TDF_Label L = STool->AddShape ( S, Standard_False );
675 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
676 ShapeLabelMap.Bind ( S, L );
680 // or as assembly, component-by-component
681 TDF_Label L = STool->NewShape();
682 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
683 TopoDS_Shape Sub0 = it.Value();
685 Sub0.Location ( loc );
686 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
687 if ( ! subL.IsNull() ) {
688 STool->AddComponent ( L, subL, it.Value().Location() );
691 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
692 ShapeLabelMap.Bind ( S, L );
693 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
698 //=======================================================================
699 //function : ReadExternFile
701 //=======================================================================
703 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
704 const Standard_CString fullname,
705 Handle(TDocStd_Document)& doc)
707 // if the file is already read, associate it with SDR
708 if ( myFiles->HasItem ( file, Standard_True ) ) {
709 return myFiles->Item ( file );
713 cout << "Reading extern file: " << fullname << endl;
716 // create new WorkSession and Reader
717 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
718 newWS->SelectNorm ( "STEP" );
719 STEPControl_Reader sr ( newWS, Standard_False );
721 // start to fill the resulting ExternFile structure
722 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
724 EF->SetName ( new TCollection_HAsciiString ( file ) );
727 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
729 // transfer in single-result mode
730 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
731 TDF_LabelSequence labels;
732 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
733 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
736 // add read file to dictionary
737 myFiles->SetItem ( file, EF );
743 //=======================================================================
744 //function : SetColorToSubshape
746 //=======================================================================
747 static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
748 const TopoDS_Shape & S,
749 const Quantity_Color& col,
750 const XCAFDoc_ColorType type)
752 for (TopoDS_Iterator it(S); it.More(); it.Next())
753 if (! CTool->SetColor( it.Value(), col, type)) break;
757 //=======================================================================
758 //function : findStyledSR
760 //=======================================================================
761 static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
762 Handle(StepShape_ShapeRepresentation)& aSR)
764 // search Shape Represenatation for component styled item
765 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
766 Handle(StepVisual_PresentationStyleByContext) PSA =
767 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
770 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
771 Handle(StepShape_ShapeRepresentation) aCurrentSR =
772 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
773 if ( aCurrentSR.IsNull() )
781 //=======================================================================
782 //function : ReadColors
784 //=======================================================================
786 Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
787 Handle(TDocStd_Document)& Doc,
788 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
789 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
791 STEPConstruct_Styles Styles ( WS );
792 if ( ! Styles.LoadStyles() ) {
794 cout << "Warning: no styles are found in the model" << endl;
796 return Standard_False;
798 // searching for invisible items in the model
799 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
800 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
802 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
803 if ( CTool.IsNull() ) return Standard_False;
805 // parse and search for color attributes
806 Standard_Integer nb = Styles.NbStyles();
807 for ( Standard_Integer i=1; i <= nb; i++ ) {
808 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
809 if ( style.IsNull() ) continue;
811 Standard_Boolean IsVisible = Standard_True;
812 // check the visibility of styled item.
813 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
814 if ( style != aHSeqOfInvisStyle->Value( si ) )
816 // found that current style is invisible.
817 IsVisible = Standard_False;
821 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
822 // check if it is component style
823 Standard_Boolean IsComponent = Standard_False;
824 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
828 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() );
829 Standard_Boolean isSkipSHUOstyle = Standard_False;
830 // take shape with real location.
831 while ( IsComponent ) {
833 Handle(StepShape_ShapeRepresentation) aSR;
834 findStyledSR( style, aSR );
835 // search for SR along model
838 // Handle(Interface_InterfaceModel) Model = WS->Model();
839 Handle(XSControl_TransferReader) TR = WS->TransferReader();
840 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
841 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
842 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
843 for (subs.Start(); subs.More(); subs.Next()) {
844 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
847 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
848 Handle(StepRepr_ProductDefinitionShape) PDS =
849 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
852 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
854 Handle(StepRepr_AssemblyComponentUsage) ACU =
855 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
856 // PTV 10.02.2003 skip styled item that refer to SHUO
857 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
858 isSkipSHUOstyle = Standard_True;
861 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
862 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
867 // PTV 10.02.2003 to find component of assembly CORRECTLY
868 STEPConstruct_Tool Tool( WS );
869 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
870 aSh = CTool->ShapeTool()->GetShape(aShLab);
871 // Handle(Transfer_Binder) binder = TP->Find(NAUO);
872 // if ( binder.IsNull() || ! binder->HasResult() )
874 // aSh = TransferBRep::ShapeResult ( TP, binder );
883 continue; // skip styled item which refer to SHUO
888 if ( ! SurfCol.IsNull() ) {
890 Styles.DecodeColor ( SurfCol, col );
891 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
892 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
894 if ( ! BoundCol.IsNull() ) {
896 Styles.DecodeColor ( BoundCol, col );
897 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
898 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
900 if ( ! CurveCol.IsNull() ) {
902 Styles.DecodeColor ( CurveCol, col );
903 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
904 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
907 // sets the invisibility for shape.
909 if ( CTool->ShapeTool()->Search( S, aInvL ) )
910 CTool->SetVisibility( aInvL, Standard_False );
913 CTool->ReverseChainsOfTreeNodes();
914 return Standard_True;
917 //=======================================================================
918 //function : GetLabelFromPD
920 //=======================================================================
922 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
923 const Handle(XCAFDoc_ShapeTool) &STool,
924 const Handle(Transfer_TransientProcess) &TP,
925 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
926 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
929 if ( PDFileMap.IsBound ( PD ) ) {
930 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
931 if ( ! EF.IsNull() ) {
933 if ( ! L.IsNull() ) return L;
938 Handle(Transfer_Binder) binder = TP->Find(PD);
939 if ( binder.IsNull() || ! binder->HasResult() ) return L;
940 S = TransferBRep::ShapeResult ( TP, binder );
941 if ( S.IsNull() ) return L;
943 if ( S.IsNull() ) return L;
944 if ( ShapeLabelMap.IsBound ( S ) )
945 L = ShapeLabelMap.Find ( S );
947 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
951 //=======================================================================
952 //function : FindInstance
954 //=======================================================================
956 TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
957 const Handle(XCAFDoc_ShapeTool) &STool,
958 const STEPConstruct_Tool &Tool,
959 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
960 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
964 // get shape resulting from CDSR (in fact, only location is interesting)
965 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
966 Handle(Transfer_Binder) binder = TP->Find(NAUO);
967 if ( binder.IsNull() || ! binder->HasResult() ) {
969 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
974 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
977 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
982 // find component`s original label
983 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
984 if ( PD.IsNull() ) return L;
985 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
986 if ( Lref.IsNull() ) return L;
988 // find main shape (assembly) label
990 PD = NAUO->RelatingProductDefinition();
991 if ( PD.IsNull() ) return L;
992 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
993 if ( L0.IsNull() ) return L;
995 // if CDSR and NAUO are reversed, swap labels
996 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
997 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
998 for (subs1.Start(); subs1.More(); subs1.Next()) {
999 Handle(StepRepr_ProductDefinitionShape) PDS =
1000 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
1001 if(PDS.IsNull()) continue;
1002 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
1003 for (subs2.Start(); subs2.More(); subs2.Next()) {
1004 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
1005 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
1006 if (CDSRtmp.IsNull()) continue;
1010 if (CDSR.IsNull()) return L;
1011 // if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
1012 // TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
1015 // iterate on components to find proper one
1016 TDF_LabelSequence seq;
1017 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
1018 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
1019 TDF_Label Lcomp = seq(k), Lref2;
1020 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
1022 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
1029 //=======================================================================
1030 //function : ReadNames
1032 //=======================================================================
1034 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
1035 Handle(TDocStd_Document)& Doc,
1036 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1037 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1039 // get starting data
1040 Handle(Interface_InterfaceModel) Model = WS->Model();
1041 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1042 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1043 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1044 if ( STool.IsNull() ) return Standard_False;
1045 STEPConstruct_Tool Tool ( WS );
1047 // iterate on model to find all SDRs and CDSRs
1048 Standard_Integer nb = Model->NbEntities();
1049 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1050 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1051 Handle(TCollection_HAsciiString) name;
1053 for (Standard_Integer i = 1; i <= nb; i++) {
1054 Handle(Standard_Transient) enti = Model->Value(i);
1056 // get description of NAUO
1057 if ( enti->DynamicType() == tNAUO ) {
1059 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1060 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1061 if(NAUO.IsNull()) continue;
1062 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1063 for (subs.Start(); subs.More(); subs.Next()) {
1064 Handle(StepRepr_ProductDefinitionShape) PDS =
1065 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1066 if(PDS.IsNull()) continue;
1067 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1068 if ( PDR.IsNull() ) continue;
1069 if ( PDR->HasDescription() &&
1070 PDR->Description()->Length() >0 ) name = PDR->Description();
1071 else if ( !PDR->Name().IsNull() && PDR->Name()->Length() >0 ) name = PDR->Name();
1072 else if ( !PDR->Id().IsNull()) name = PDR->Id();
1073 else name = new TCollection_HAsciiString;
1075 // find proper label
1076 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1077 if ( L.IsNull() ) continue;
1078 TCollection_ExtendedString str ( name->String() );
1079 TDataStd_Name::Set ( L, str );
1082 // for PD get name of associated product
1083 if ( enti->DynamicType() == tPD ) {
1085 Handle(StepBasic_ProductDefinition) PD =
1086 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1087 if(PD.IsNull()) continue;
1088 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1089 if(!Prod->Name().IsNull() && Prod->Name()->UsefullLength()>0) name = Prod->Name();
1090 else if (!Prod->Id().IsNull()) name = Prod->Id();
1091 else name = new TCollection_HAsciiString;
1092 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1093 if ( L.IsNull() ) continue;
1094 TCollection_ExtendedString str ( name->String() );
1095 TDataStd_Name::Set ( L, str );
1097 // set a name to the document
1098 //TCollection_ExtendedString str ( name->String() );
1099 //TDataStd_Name::Set ( L, str );
1102 return Standard_True;
1105 //=======================================================================
1106 //function : GetLabelFromPD
1108 //=======================================================================
1110 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1111 const Handle(XCAFDoc_ShapeTool) &STool,
1112 const STEPConstruct_ValidationProps &Props,
1113 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1114 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1117 if ( PDFileMap.IsBound ( PD ) ) {
1118 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1119 if ( ! EF.IsNull() ) {
1121 if ( ! L.IsNull() ) return L;
1124 TopoDS_Shape S = Props.GetPropShape ( PD );
1125 if ( S.IsNull() ) return L;
1126 if ( ShapeLabelMap.IsBound ( S ) )
1127 L = ShapeLabelMap.Find ( S );
1129 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1133 //=======================================================================
1134 //function : ReadValProps
1136 //=======================================================================
1138 Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1139 Handle(TDocStd_Document)& Doc,
1140 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1141 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1143 // get starting data
1144 Handle(Interface_InterfaceModel) Model = WS->Model();
1145 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1146 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1147 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1148 if ( STool.IsNull() ) return Standard_False;
1150 // load props from the STEP model
1151 TColStd_SequenceOfTransient props;
1152 STEPConstruct_ValidationProps Props ( WS );
1153 if ( ! Props.LoadProps ( props ) ) {
1155 cout << "Warning: no validation props found in the model" << endl;
1157 return Standard_False;
1160 // interpret props one by one
1161 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1162 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1163 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1164 if ( PDR.IsNull() ) continue;
1168 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1169 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1170 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1171 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1172 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1173 if(PDS.IsNull()) continue;
1174 // find corresponding NAUO
1175 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1176 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1177 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1178 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1179 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1181 if ( !NAUO.IsNull() ) {
1182 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1183 if ( L.IsNull() ) continue;
1186 // find corresponding ProductDefinition:
1187 Handle(StepBasic_ProductDefinition) ProdDef;
1188 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1189 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1190 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1191 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1193 if ( ProdDef.IsNull() ) continue;
1194 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1198 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1199 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1200 if(SA.IsNull()) continue;
1201 // find ShapeRepresentation
1202 Handle(StepShape_ShapeRepresentation) SR;
1203 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1204 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1205 Handle(StepRepr_PropertyDefinition) PropD1 =
1206 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1207 if(PropD1.IsNull()) continue;
1208 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1209 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1210 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1211 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1212 if(SDR.IsNull()) continue;
1213 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1216 if(SR.IsNull()) continue;
1217 Handle(Transfer_Binder) binder;
1218 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1219 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1220 Handle(StepShape_SolidModel) SM =
1221 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1222 binder = TP->Find(SM);
1224 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1225 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1226 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1227 binder = TP->Find(SBSM);
1229 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1230 Handle(StepShape_GeometricSet) GS =
1231 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1232 binder = TP->Find(GS);
1235 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1237 S = TransferBRep::ShapeResult ( TP, binder );
1238 if(S.IsNull()) continue;
1239 if ( ShapeLabelMap.IsBound ( S ) )
1240 L = ShapeLabelMap.Find ( S );
1242 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1246 if(L.IsNull()) continue;
1248 // decode validation properties
1249 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1250 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1251 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1252 Standard_Boolean isArea;
1255 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1256 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1257 else XCAFDoc_Volume::Set ( L, val );
1259 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1260 XCAFDoc_Centroid::Set ( L, pos );
1264 return Standard_True;
1267 //=======================================================================
1268 //function : ReadLayers
1270 //=======================================================================
1272 Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1273 Handle(TDocStd_Document)& Doc) const
1275 Handle(Interface_InterfaceModel) Model = WS->Model();
1276 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1277 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1278 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1279 if ( STool.IsNull() ) return Standard_False;
1280 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1281 if ( LTool.IsNull() ) return Standard_False;
1283 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1284 Standard_Integer nb = Model->NbEntities();
1285 Handle(TCollection_HAsciiString) name;
1287 for (Standard_Integer i = 1; i <= nb; i ++) {
1288 Handle(Standard_Transient) enti = Model->Value(i);
1289 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1290 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1291 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1293 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1294 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1295 TCollection_ExtendedString aLayerName ( hName->String() );
1297 // find a target shape and its label in the document
1298 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1299 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1300 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1301 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1303 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1304 if ( S.IsNull() ) continue;
1307 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1308 LTool->SetLayer ( shL, aLayerName );
1311 // check invisibility
1312 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1313 for (subs.Start(); subs.More(); subs.Next()) {
1314 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1316 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1318 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1319 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1320 Handle(TDataStd_UAttribute) aUAttr;
1321 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1324 return Standard_True;
1327 //=======================================================================
1328 //function : ReadSHUOs
1330 //=======================================================================
1332 static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1333 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1334 const Handle(XCAFDoc_ShapeTool)& STool,
1335 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1336 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1337 TDF_LabelSequence& aLabels)
1339 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1340 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1341 for (subs.Start(); subs.More(); subs.Next()) {
1342 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1343 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1347 if (subSHUO.IsNull())
1348 return Standard_False;
1350 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1351 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
1352 if (NUNAUO.IsNull())
1353 return Standard_False;
1354 // Handle(Interface_InterfaceModel) Model = WS->Model();
1355 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1356 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1357 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1358 // if ( binder.IsNull() || ! binder->HasResult() )
1359 // return Standard_False;
1360 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1361 // get label of NAUO next level
1363 STEPConstruct_Tool Tool( WS );
1364 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1365 // STool->Search(NUSh, NUlab);
1367 return Standard_False;
1368 aLabels.Append( NULab );
1369 // and check by recurse.
1370 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1371 return Standard_True;
1375 //=======================================================================
1376 //function : setSHUOintoDoc
1377 //purpose : auxilary
1378 //=======================================================================
1379 static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1380 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1381 const Handle(XCAFDoc_ShapeTool)& STool,
1382 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1383 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1385 TDF_Label aMainLabel;
1386 // get upper usage NAUO from SHUO.
1387 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1388 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1389 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1390 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
1391 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1393 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1397 // Handle(Interface_InterfaceModel) Model = WS->Model();
1398 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1399 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1400 // TopoDS_Shape UUSh, NUSh;
1401 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1402 // if ( binder.IsNull() || ! binder->HasResult() )
1403 // return aMainLabel;
1404 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1405 // binder = TP->Find(NUNAUO);
1406 // if ( binder.IsNull() || ! binder->HasResult() )
1407 // return aMainLabel;
1408 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1410 // get first labels for first SHUO attribute
1411 TDF_Label UULab, NULab;
1412 STEPConstruct_Tool Tool( WS );
1413 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1414 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1416 // STool->Search(UUSh, UULab);
1417 // STool->Search(NUSh, NULab);
1418 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1419 //create sequence fo labels to set SHUO structure into the document
1420 TDF_LabelSequence ShuoLabels;
1421 ShuoLabels.Append( UULab );
1422 ShuoLabels.Append( NULab );
1423 // add all other labels of sub SHUO entities
1424 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1425 // last accord for SHUO
1426 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1427 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1428 aMainLabel = anSHUOAttr->Label();
1434 //=======================================================================
1435 //function : ReadSHUOs
1437 //=======================================================================
1439 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1440 Handle(TDocStd_Document)& Doc,
1441 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1442 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1444 // the big part code duplication from ReadColors.
1445 // It is possible to share this code functionality, just to decide how ???
1446 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1447 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1449 STEPConstruct_Styles Styles ( WS );
1450 if ( ! Styles.LoadStyles() ) {
1452 cout << "Warning: no styles are found in the model" << endl;
1454 return Standard_False;
1456 // searching for invisible items in the model
1457 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1458 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1459 // parse and search for color attributes
1460 Standard_Integer nb = Styles.NbStyles();
1461 for ( Standard_Integer i=1; i <= nb; i++ ) {
1462 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1463 if ( style.IsNull() ) continue;
1465 Standard_Boolean IsVisible = Standard_True;
1466 // check the visibility of styled item.
1467 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1468 if ( style != aHSeqOfInvisStyle->Value( si ) )
1470 // found that current style is invisible.
1472 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1474 IsVisible = Standard_False;
1478 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1479 // check if it is component style
1480 Standard_Boolean IsComponent = Standard_False;
1481 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1485 Handle(StepShape_ShapeRepresentation) aSR;
1486 findStyledSR( style, aSR );
1487 // search for SR along model
1490 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1491 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1492 for (subs.Start(); subs.More(); subs.Next()) {
1493 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1494 if ( aSDR.IsNull() )
1496 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1497 Handle(StepRepr_ProductDefinitionShape) PDS =
1498 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1501 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1502 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1503 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1504 if ( SHUO.IsNull() )
1507 // set the SHUO structure to the document
1508 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1509 if ( aLabelForStyle.IsNull() ) {
1511 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1515 // now set the style to the SHUO main label.
1516 if ( ! SurfCol.IsNull() ) {
1518 Styles.DecodeColor ( SurfCol, col );
1519 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1521 if ( ! BoundCol.IsNull() ) {
1523 Styles.DecodeColor ( BoundCol, col );
1524 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1526 if ( ! CurveCol.IsNull() ) {
1528 Styles.DecodeColor ( CurveCol, col );
1529 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1532 // sets the invisibility for shape.
1533 CTool->SetVisibility( aLabelForStyle, Standard_False );
1535 } // end search SHUO by SDR
1536 } // end iterates on styles
1538 return Standard_True;
1542 //=======================================================================
1543 //function : GetLengthConversionFactor
1545 //=======================================================================
1546 static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1547 Standard_Real& afact)
1550 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1551 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1552 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1553 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1554 afact = MWUCBU->ValueComponent();
1555 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1556 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1557 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1558 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1559 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1560 if(SU->Name()==StepBasic_sunMetre) {
1562 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1568 return Standard_True;
1572 //=======================================================================
1573 //function : GetMassConversionFactor
1575 //=======================================================================
1576 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1577 Standard_Real& afact)
1580 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1581 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1582 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1583 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1584 afact = MWUCBU->ValueComponent();
1585 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1586 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1587 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1588 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1589 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1590 if(SU->Name()==StepBasic_sunGram) {
1592 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1596 return Standard_True;
1600 //=======================================================================
1601 //function : ReadDatums
1602 //purpose : auxilary
1603 //=======================================================================
1604 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
1605 const Handle(XCAFDoc_DimTolTool) &DGTTool,
1606 const Interface_Graph &graph,
1607 Handle(Transfer_TransientProcess) &TP,
1608 const TDF_Label TolerL,
1609 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
1611 if(GTWDR.IsNull()) return Standard_False;
1612 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
1613 if(HADR.IsNull()) return Standard_False;
1614 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
1615 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
1616 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
1617 if(aDatum.IsNull()) continue;
1618 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
1619 for(subs4.Start(); subs4.More(); subs4.Next()) {
1620 Handle(StepRepr_ShapeAspectRelationship) SAR =
1621 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
1622 if(SAR.IsNull()) continue;
1623 Handle(StepDimTol_DatumFeature) DF =
1624 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
1625 if(DF.IsNull()) continue;
1626 Interface_EntityIterator subs5 = graph.Sharings(DF);
1627 Handle(StepRepr_PropertyDefinition) PropDef;
1628 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
1629 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
1631 if(PropDef.IsNull()) continue;
1632 Handle(StepShape_AdvancedFace) AF;
1633 subs5 = graph.Sharings(PropDef);
1634 for(subs5.Start(); subs5.More(); subs5.Next()) {
1635 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1636 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
1638 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1639 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1640 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
1641 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1645 if(AF.IsNull()) return Standard_False;
1646 Standard_Integer index = TP->MapIndex(AF);
1649 Handle(Transfer_Binder) binder = TP->MapItem(index);
1650 aSh = TransferBRep::ShapeResult(binder);
1652 if(aSh.IsNull()) continue;
1654 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1655 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
1658 return Standard_True;
1662 //=======================================================================
1663 //function : ReadGDTs
1665 //=======================================================================
1667 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession) &WS,
1668 Handle(TDocStd_Document)& Doc) const
1670 Handle(Interface_InterfaceModel) Model = WS->Model();
1671 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1672 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1673 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1674 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( Doc->Main() );
1675 if ( DGTTool.IsNull() ) return Standard_False;
1677 Standard_Integer nb = Model->NbEntities();
1678 const Interface_Graph& graph = TP->Graph();
1679 for(Standard_Integer i=1; i<=nb; i++) {
1680 Handle(Standard_Transient) ent = Model->Value(i);
1681 if(ent->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
1682 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(ent);
1683 // find RepresentationItem for current ShapeAspect
1684 Handle(StepRepr_RepresentationItem) RI;
1685 Handle(StepRepr_PropertyDefinition) PropD;
1686 Interface_EntityIterator subs3 = graph.Sharings(SA);
1687 for(subs3.Start(); subs3.More() && PropD.IsNull(); subs3.Next()) {
1688 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(subs3.Value());
1690 if(PropD.IsNull()) continue;
1691 Interface_EntityIterator subs4 = graph.Sharings(PropD);
1692 for(subs4.Start(); subs4.More(); subs4.Next()) {
1693 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1694 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
1696 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1697 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1698 RI = Repr->ItemsValue(1);
1702 if(RI.IsNull()) continue;
1703 // read DGT entities:
1704 subs3 = graph.Sharings(SA);
1705 for(subs3.Start(); subs3.More(); subs3.Next()) {
1706 if(subs3.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1708 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
1709 if(EC.IsNull()) continue;
1710 Handle(TCollection_HAsciiString) aName;
1711 Handle(StepShape_DimensionalSize) DimSize =
1712 Handle(StepShape_DimensionalSize)::DownCast(subs3.Value());
1713 Standard_Real dim1=-1.,dim2=-1.;
1714 subs4 = graph.Sharings(DimSize);
1715 for(subs4.Start(); subs4.More(); subs4.Next()) {
1716 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
1717 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
1718 if(!DimCharR.IsNull()) {
1719 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
1720 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
1721 Handle(StepRepr_RepresentationItem) RI = SDimR->ItemsValue(1);
1722 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(RI);
1725 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
1726 //if(CID.IsNull()) continue;
1727 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
1728 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
1729 //if(CIDM.IsNull()) continue;
1730 //if(CIDM->ArrTransient().IsNull()) continue;
1731 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
1732 //if(CID.CaseMem(CIDM)==1)
1733 // HARI = CID.ListRepresentationItem();
1734 //if(CID.CaseMem(CIDM)==2)
1735 // HARI = CID.SetRepresentationItem();
1736 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
1737 if(HARI.IsNull()) continue;
1738 if(HARI->Length()>0) {
1739 Handle(StepRepr_RepresentationItem) RI1 =
1740 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
1741 if(RI1.IsNull()) continue;
1742 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1743 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1744 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
1745 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1746 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1747 Standard_Real afact=1.;
1748 if(anUnit.IsNull()) continue;
1749 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1750 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1751 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
1754 if(HARI->Length()>1) {
1755 Handle(StepRepr_RepresentationItem) RI2 =
1756 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
1757 if(RI2.IsNull()) continue;
1758 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1759 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1760 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
1761 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1762 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1763 Standard_Real afact=1.;
1764 if(anUnit.IsNull()) continue;
1765 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1766 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1767 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
1774 if(dim1<0) continue;
1775 if(dim2<0) dim2=dim1;
1776 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
1777 // now we know edge_curve and value range therefore
1778 // we can create corresponding D> labels
1779 Standard_Integer index = TP->MapIndex(EC);
1782 Handle(Transfer_Binder) binder = TP->MapItem(index);
1783 aSh = TransferBRep::ShapeResult(binder);
1785 if(aSh.IsNull()) continue;
1787 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1788 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
1789 arr->SetValue(1,dim1);
1790 arr->SetValue(2,dim2);
1791 DGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
1793 // read tolerances and datums
1794 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
1795 Handle(StepDimTol_GeometricTolerance) GT =
1796 Handle(StepDimTol_GeometricTolerance)::DownCast(subs3.Value());
1797 // read common data for tolerance
1798 //Standard_Real dim = GT->Magnitude()->ValueComponent();
1799 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
1800 if(dim3.IsNull()) continue;
1801 Standard_Real dim = dim3->ValueComponent();
1802 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
1803 Standard_Real afact=1.;
1804 if(anUnit.IsNull()) continue;
1805 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1806 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1807 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
1808 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
1809 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
1810 arr->SetValue(1,dim);
1811 Handle(TCollection_HAsciiString) aName = GT->Name();
1812 Handle(TCollection_HAsciiString) aDescription = GT->Description();
1813 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1814 if(AF.IsNull()) continue;
1815 Standard_Integer index = TP->MapIndex(AF);
1818 Handle(Transfer_Binder) binder = TP->MapItem(index);
1819 aSh = TransferBRep::ShapeResult(binder);
1821 if(aSh.IsNull()) continue;
1823 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1824 // read specific data for tolerance
1825 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
1826 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
1827 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(subs3.Value());
1828 Standard_Integer kind=20;
1829 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1830 GTComplex->GetModifiedGeometricTolerance();
1832 kind = kind + MGT->Modifier()+1;
1834 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1835 // translate datums connected with this tolerance
1836 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1837 GTComplex->GetGeometricToleranceWithDatumReference();
1838 if(!GTWDR.IsNull()) {
1839 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1842 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
1843 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1844 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(subs3.Value());
1845 if(GTWDR.IsNull()) continue;
1846 Standard_Integer kind = 0;
1847 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
1848 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
1849 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
1850 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
1851 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
1852 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
1853 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
1854 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
1855 //cout<<"GTWDR: kind="<<kind<<endl;
1856 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1857 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1859 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
1860 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1861 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(subs3.Value());
1862 Standard_Integer kind = 35 + MGT->Modifier();
1863 DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1865 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
1866 DGTTool->SetDimTol(shL,38,arr,aName,aDescription);
1868 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
1869 DGTTool->SetDimTol(shL,39,arr,aName,aDescription);
1871 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
1872 DGTTool->SetDimTol(shL,40,arr,aName,aDescription);
1874 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
1875 DGTTool->SetDimTol(shL,41,arr,aName,aDescription);
1877 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
1878 DGTTool->SetDimTol(shL,42,arr,aName,aDescription);
1880 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
1881 DGTTool->SetDimTol(shL,43,arr,aName,aDescription);
1883 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
1884 DGTTool->SetDimTol(shL,44,arr,aName,aDescription);
1891 return Standard_True;
1895 //=======================================================================
1896 //function : FindSolidForPDS
1897 //purpose : auxilary
1898 //=======================================================================
1900 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
1901 const Interface_Graph &graph)
1903 Handle(StepShape_SolidModel) SM;
1904 Interface_EntityIterator subs = graph.Sharings(PDS);
1905 Handle(StepShape_ShapeRepresentation) SR;
1906 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
1907 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1908 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1909 if(SDR.IsNull()) continue;
1910 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1911 if(SR.IsNull()) continue;
1912 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
1913 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
1916 Interface_EntityIterator subs1 = graph.Sharings(SR);
1917 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
1918 Handle(StepRepr_RepresentationRelationship) RR =
1919 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
1920 if(RR.IsNull()) continue;
1921 Handle(StepShape_ShapeRepresentation) SR2;
1922 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
1923 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
1924 if(SR2.IsNull()) continue;
1925 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
1926 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
1935 //=======================================================================
1936 //function : ReadMaterials
1938 //=======================================================================
1940 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
1941 Handle(TDocStd_Document)& Doc,
1942 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
1944 Handle(Interface_InterfaceModel) Model = WS->Model();
1945 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1946 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1947 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1948 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
1949 if(MatTool.IsNull()) return Standard_False;
1951 const Interface_Graph& graph = TP->Graph();
1952 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
1953 Handle(StepRepr_ProductDefinitionShape) PDS =
1954 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
1957 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
1958 if(aProdDef.IsNull())
1960 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
1961 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
1962 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
1963 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
1964 Standard_Real aDensity=0;
1965 Interface_EntityIterator subs = graph.Sharings( aProdDef);
1966 for(subs.Start(); subs.More(); subs.Next()) {
1967 Handle(StepRepr_PropertyDefinition) PropD =
1968 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
1969 if(PropD.IsNull()) continue;
1970 Interface_EntityIterator subs1 = graph.Sharings(PropD);
1971 for(subs1.Start(); subs1.More(); subs1.Next()) {
1972 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1973 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
1974 if(PDR.IsNull()) continue;
1975 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
1976 if(Repr.IsNull()) continue;
1977 Standard_Integer ir;
1978 for(ir=1; ir<=Repr->NbItems(); ir++) {
1979 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
1980 if(RI.IsNull()) continue;
1981 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
1982 // find name and description for material
1983 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
1984 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
1985 aName = DRI->Name();
1987 aDescription = DRI->Description();
1989 aName = aDescription;
1991 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
1992 // try to find density for material
1993 Handle(StepRepr_MeasureRepresentationItem) MRI =
1994 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
1995 aDensity = MRI->Measure()->ValueComponent();
1996 aDensName = MRI->Name();
1997 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
1998 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
1999 if(!aUnit.IsNull()) {
2000 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
2001 if(DU.IsNull()) continue;
2002 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
2003 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
2004 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
2005 Standard_Real afact=1.;
2006 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
2007 if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact);
2008 // transfer length value for Density from millimeter to santimeter
2009 // in order to result density has dimension gram/(sm*sm*sm)
2010 aDensity = aDensity*1000.;
2012 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
2013 if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact;
2022 if( aName.IsNull() || aName->Length()==0 )
2024 // find shape label amd create Material link
2026 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
2028 Standard_Integer index = TP->MapIndex(SM);
2030 Handle(Transfer_Binder) binder = TP->MapItem(index);
2031 if(!binder.IsNull())
2032 aSh = TransferBRep::ShapeResult(binder);
2035 if(aSh.IsNull()) continue;
2037 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2038 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
2041 return Standard_True;
2044 //=======================================================================
2045 //function : SettleShapeData
2047 //=======================================================================
2049 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
2051 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
2052 const Handle(Transfer_TransientProcess)& TP) const
2054 TDF_Label aResult = theLab;
2056 Handle(TCollection_HAsciiString) hName = theItem->Name();
2057 if ( hName.IsNull() || hName->IsEmpty() )
2060 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
2061 if ( aBinder.IsNull() )
2064 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
2065 if ( aShape.IsNull() )
2068 // Allocate sub-Label
2069 aResult = AllocateSubLabel(theLab);
2071 TCollection_AsciiString aName = hName->String();
2072 TDataStd_Name::Set(aResult, aName);
2073 theShapeTool->SetShape(aResult, aShape);
2078 //=======================================================================
2079 //function : ExpandSubShapes
2081 //=======================================================================
2083 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
2084 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
2085 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
2087 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
2088 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
2089 TColStd_MapOfTransient aRepItems;
2091 // Read translation control variables
2092 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
2094 if ( !doReadSNames )
2097 const Interface_Graph& Graph = Reader().WS()->Graph();
2099 for ( STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next() )
2101 const TopoDS_Shape& aRootShape = it.Key();
2102 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
2103 if ( aPDef.IsNull() )
2106 // Find SDR by Product
2107 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2108 Interface_EntityIterator entIt = Graph.TypedSharings( aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation) );
2109 for ( entIt.Start(); entIt.More(); entIt.Next() )
2111 const Handle(Standard_Transient)& aReferer = entIt.Value();
2112 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
2113 if ( !aSDR.IsNull() )
2117 if ( aSDR.IsNull() )
2120 // Access shape representation
2121 Handle(StepShape_ShapeRepresentation)
2122 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast( aSDR->UsedRepresentation() );
2124 if ( aShapeRepr.IsNull() )
2127 // Access representation items
2128 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aShapeRepr->Items();
2130 if ( aReprItems.IsNull() )
2133 if ( !ShapeLabelMap.IsBound(aRootShape) )
2136 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
2138 StepRepr_SequenceOfRepresentationItem aMSBSeq;
2139 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
2141 // Iterate over the top level representation items collecting the
2142 // topological containers to expand
2143 for ( Standard_Integer i = aReprItems->Lower(); i <= aReprItems->Upper(); ++i )
2145 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems->Value(i);
2146 if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
2147 aMSBSeq.Append(aTRepr);
2148 else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) )
2149 aSBSMSeq.Append(aTRepr);
2152 // Insert intermediate OCAF Labels for SOLIDs in case there are more
2153 // than one Manifold Solid BRep in the Shape Representation
2154 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
2156 // Expand Manifold Solid BReps
2157 for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i )
2159 const Handle(StepRepr_RepresentationItem)& aManiRepr = aMSBSeq.Value(i);
2161 // Put additional Label for SOLID
2163 if ( doInsertSolidLab )
2164 aManiLab = SettleShapeData(aManiRepr, aRootLab, ShapeTool, TP);
2166 aManiLab = aRootLab;
2168 ExpandManifoldSolidBrep(aManiLab, aMSBSeq.Value(i), TP, ShapeTool);
2171 // Expand Shell-Based Surface Models
2172 for ( Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i )
2173 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
2177 //=======================================================================
2178 //function : ExpandManifoldSolidBrep
2180 //=======================================================================
2182 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
2183 const Handle(StepRepr_RepresentationItem)& Repr,
2184 const Handle(Transfer_TransientProcess)& TP,
2185 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
2187 // Access outer shell
2188 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
2189 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
2191 // Expand shell contents to CAF tree
2192 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
2195 //=======================================================================
2196 //function : ExpandSBSM
2198 //=======================================================================
2200 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
2201 const Handle(StepRepr_RepresentationItem)& Repr,
2202 const Handle(Transfer_TransientProcess)& TP,
2203 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
2205 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
2207 // Access boundary shells
2208 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
2209 for ( Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s )
2211 const StepShape_Shell& aShell = aShells->Value(s);
2212 Handle(StepShape_ConnectedFaceSet) aCFS;
2213 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
2214 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
2216 if ( !anOpenShell.IsNull() )
2219 aCFS = aClosedShell;
2221 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
2225 //=======================================================================
2226 //function : ExpandShell
2228 //=======================================================================
2230 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
2232 const Handle(Transfer_TransientProcess)& TP,
2233 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
2236 TDF_Label aShellLab = SettleShapeData(Shell, RootLab, ShapeTool, TP);
2239 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
2240 for ( Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f )
2242 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
2245 TDF_Label aFaceLab = SettleShapeData(aFace, aShellLab, ShapeTool, TP);
2247 // Access face bounds
2248 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
2249 for ( Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w )
2251 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
2254 TDF_Label aWireLab = SettleShapeData(aWire, aFaceLab, ShapeTool, TP);
2256 // Access wire edges
2257 // Currently only EDGE LOOPs are considered (!)
2258 if ( !aWire->IsInstance( STANDARD_TYPE(StepShape_EdgeLoop) ) )
2262 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
2263 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
2264 for ( Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e )
2266 Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement();
2269 TDF_Label anEdgeLab = SettleShapeData(anEdge, aWireLab, ShapeTool, TP);
2272 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
2273 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
2276 SettleShapeData(aV1, anEdgeLab, ShapeTool, TP);
2277 SettleShapeData(aV2, anEdgeLab, ShapeTool, TP);
2283 //=======================================================================
2284 //function : SetColorMode
2286 //=======================================================================
2288 void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
2290 myColorMode = colormode;
2293 //=======================================================================
2294 //function : GetColorMode
2296 //=======================================================================
2298 Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
2303 //=======================================================================
2304 //function : SetNameMode
2306 //=======================================================================
2308 void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
2310 myNameMode = namemode;
2313 //=======================================================================
2314 //function : GetNameMode
2316 //=======================================================================
2318 Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
2323 //=======================================================================
2324 //function : SetLayerMode
2326 //=======================================================================
2328 void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
2330 myLayerMode = layermode;
2333 //=======================================================================
2334 //function : GetLayerMode
2336 //=======================================================================
2338 Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
2343 //=======================================================================
2344 //function : SetPropsMode
2346 //=======================================================================
2348 void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
2350 myPropsMode = propsmode;
2353 //=======================================================================
2354 //function : GetPropsMode
2356 //=======================================================================
2358 Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
2363 //=======================================================================
2364 //function : SetSHUOMode
2366 //=======================================================================
2368 void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
2373 //=======================================================================
2374 //function : GetSHUOMode
2376 //=======================================================================
2378 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
2383 //=======================================================================
2384 //function : SetGDTMode
2386 //=======================================================================
2388 void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
2390 myGDTMode = gdtmode;
2393 //=======================================================================
2394 //function : GetGDTMode
2396 //=======================================================================
2398 Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
2404 //=======================================================================
2405 //function : SetMatMode
2407 //=======================================================================
2409 void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
2411 myMatMode = matmode;
2414 //=======================================================================
2415 //function : GetMatMode
2417 //=======================================================================
2419 Standard_Boolean STEPCAFControl_Reader::GetMatMode () const