1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <STEPCAFControl_Reader.ixx>
23 #include <Quantity_Color.hxx>
24 #include <TCollection_HAsciiString.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopTools_MapOfShape.hxx>
28 #include <TopoDS_Compound.hxx>
30 #include <Transfer_TransientProcess.hxx>
31 #include <TransferBRep.hxx>
32 #include <Transfer_Binder.hxx>
33 #include <Interface_InterfaceModel.hxx>
34 #include <XSControl_TransferReader.hxx>
36 #include <StepBasic_Product.hxx>
37 #include <StepBasic_ProductDefinition.hxx>
38 #include <StepBasic_ProductDefinitionRelationship.hxx>
39 #include <StepBasic_ProductDefinitionFormation.hxx>
40 #include <StepShape_ContextDependentShapeRepresentation.hxx>
41 #include <StepShape_ShapeDefinitionRepresentation.hxx>
42 #include <StepShape_ShapeDefinitionRepresentation.hxx>
43 #include <StepRepr_ProductDefinitionShape.hxx>
44 #include <StepRepr_PropertyDefinition.hxx>
45 #include <StepRepr_ShapeAspect.hxx>
46 #include <StepRepr_MeasureRepresentationItem.hxx>
47 #include <StepRepr_DescriptiveRepresentationItem.hxx>
48 #include <StepVisual_StyledItem.hxx>
49 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
51 #include <STEPConstruct.hxx>
52 #include <STEPConstruct_Styles.hxx>
53 #include <STEPConstruct_ExternRefs.hxx>
54 #include <STEPConstruct_UnitContext.hxx>
55 #include <STEPCAFControl_Controller.hxx>
56 #include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
58 #include <TDataStd_Name.hxx>
59 #include <TDF_Label.hxx>
60 #include <XCAFDoc_ColorTool.hxx>
61 #include <XCAFDoc_ShapeTool.hxx>
62 #include <XCAFDoc_DocumentTool.hxx>
63 #include <XCAFDoc_DimTolTool.hxx>
64 #include <XCAFDoc_MaterialTool.hxx>
65 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
66 #include <STEPConstruct_ValidationProps.hxx>
67 #include <StepRepr_Representation.hxx>
68 #include <XCAFDoc_Area.hxx>
69 #include <XCAFDoc_Volume.hxx>
70 #include <XCAFDoc_Centroid.hxx>
71 #include <StepVisual_PresentationLayerAssignment.hxx>
72 #include <TColStd_HSequenceOfTransient.hxx>
73 #include <StepVisual_LayeredItem.hxx>
74 #include <XCAFDoc_LayerTool.hxx>
75 #include <Interface_EntityIterator.hxx>
76 #include <StepRepr_ShapeRepresentationRelationship.hxx>
77 #include <STEPConstruct_Assembly.hxx>
78 #include <TDF_Tool.hxx>
79 #include <StepVisual_Invisibility.hxx>
80 #include <TDataStd_UAttribute.hxx>
81 #include <XCAFDoc.hxx>
82 #include <OSD_Path.hxx>
83 #include <TColStd_SequenceOfHAsciiString.hxx>
85 #include <TDataStd_TreeNode.hxx>
86 #include <TNaming_NamedShape.hxx>
87 #include <BRep_Builder.hxx>
89 #include <STEPCAFControl_DataMapOfShapePD.hxx>
90 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
91 #include <StepVisual_PresentationStyleByContext.hxx>
92 #include <StepVisual_StyleContextSelect.hxx>
93 #include <StepRepr_RepresentedDefinition.hxx>
94 #include <StepRepr_CharacterizedDefinition.hxx>
95 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
96 #include <XCAFDoc_GraphNode.hxx>
97 #include <STEPCAFControl_Reader.hxx>
99 // skl 21.08.2003 for reading G&DT
100 #include <StepShape_DimensionalSize.hxx>
101 #include <StepDimTol_GeometricTolerance.hxx>
102 #include <StepShape_EdgeCurve.hxx>
103 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
104 #include <StepShape_ShapeDimensionRepresentation.hxx>
105 #include <StepRepr_ValueRange.hxx>
106 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
107 #include <StepBasic_MeasureWithUnit.hxx>
108 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
109 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
110 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
111 //#include <StepRepr_CompoundItemDefinition.hxx>
112 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
113 #include <TColStd_HArray1OfTransient.hxx>
114 #include <StepRepr_HArray1OfRepresentationItem.hxx>
115 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
116 //#include <StepBasic_ConversionBasedUnit.hxx>
117 #include <StepBasic_Unit.hxx>
118 #include <StepBasic_NamedUnit.hxx>
119 #include <StepBasic_SiUnit.hxx>
120 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
121 #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
122 #include <StepBasic_DerivedUnit.hxx>
123 #include <StepBasic_DerivedUnitElement.hxx>
124 #include <StepBasic_MeasureValueMember.hxx>
126 //#include <TDataStd_Real.hxx>
127 //#include <TDataStd_Constraint.hxx>
128 //#include <TDataStd_ConstraintEnum.hxx>
129 //#include <TNaming_Tool.hxx>
130 //#include <AIS_InteractiveObject.hxx>
131 //#include <TPrsStd_ConstraintTools.hxx>
132 //#include <AIS_DiameterDimension.hxx>
133 //#include <TPrsStd_Position.hxx>
134 //#include <TPrsStd_AISPresentation.hxx>
135 //#include <TNaming_Builder.hxx>
136 #include <TColStd_HArray1OfReal.hxx>
137 #include <StepShape_AdvancedFace.hxx>
138 #include <StepDimTol_HArray1OfDatumReference.hxx>
139 #include <StepDimTol_DatumReference.hxx>
140 #include <StepDimTol_Datum.hxx>
141 #include <StepDimTol_DatumFeature.hxx>
142 #include <StepRepr_ShapeAspectRelationship.hxx>
144 #include <StepDimTol_AngularityTolerance.hxx>
145 #include <StepDimTol_CircularRunoutTolerance.hxx>
146 #include <StepDimTol_CoaxialityTolerance.hxx>
147 #include <StepDimTol_ConcentricityTolerance.hxx>
148 #include <StepDimTol_ParallelismTolerance.hxx>
149 #include <StepDimTol_PerpendicularityTolerance.hxx>
150 #include <StepDimTol_SymmetryTolerance.hxx>
151 #include <StepDimTol_TotalRunoutTolerance.hxx>
152 #include <StepDimTol_CylindricityTolerance.hxx>
153 #include <StepDimTol_FlatnessTolerance.hxx>
154 #include <StepDimTol_LineProfileTolerance.hxx>
155 #include <StepDimTol_PositionTolerance.hxx>
156 #include <StepDimTol_RoundnessTolerance.hxx>
157 #include <StepDimTol_StraightnessTolerance.hxx>
158 #include <StepDimTol_SurfaceProfileTolerance.hxx>
160 #include <StepShape_SolidModel.hxx>
161 #include <StepShape_ShellBasedSurfaceModel.hxx>
162 #include <StepShape_GeometricSet.hxx>
163 #include <StepBasic_ProductDefinition.hxx>
165 //#include <BRepTools.hxx>
168 //=======================================================================
169 //function : STEPCAFControl_Reader
171 //=======================================================================
173 STEPCAFControl_Reader::STEPCAFControl_Reader ():
174 myColorMode( Standard_True ),
175 myNameMode ( Standard_True ),
176 myLayerMode( Standard_True ),
177 myPropsMode( Standard_True ),
178 myGDTMode ( Standard_True ),
179 myMatMode ( Standard_True )
181 STEPCAFControl_Controller::Init();
182 myFiles = new STEPCAFControl_DictionaryOfExternFile;
186 //=======================================================================
187 //function : STEPCAFControl_Reader
189 //=======================================================================
191 STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
192 const Standard_Boolean scratch) :
193 myColorMode( Standard_True ),
194 myNameMode ( Standard_True ),
195 myLayerMode( Standard_True ),
196 myPropsMode( Standard_True ),
197 myGDTMode ( Standard_True ),
198 myMatMode ( Standard_True )
200 STEPCAFControl_Controller::Init();
201 Init ( WS, scratch );
205 //=======================================================================
208 //=======================================================================
210 void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
211 const Standard_Boolean scratch)
213 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
214 myReader.SetWS (WS,scratch);
215 myFiles = new STEPCAFControl_DictionaryOfExternFile;
219 //=======================================================================
220 //function : ReadFile
222 //=======================================================================
224 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
226 return myReader.ReadFile ( filename );
230 //=======================================================================
231 //function : NbRootsForTransfer
233 //=======================================================================
235 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
237 return myReader.NbRootsForTransfer();
241 //=======================================================================
242 //function : TransferOneRoot
244 //=======================================================================
246 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
247 Handle(TDocStd_Document) &doc)
249 TDF_LabelSequence Lseq;
250 return Transfer ( myReader, num, doc, Lseq );
254 //=======================================================================
255 //function : Transfer
257 //=======================================================================
259 Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
261 TDF_LabelSequence Lseq;
262 return Transfer ( myReader, 0, doc, Lseq );
266 //=======================================================================
269 //=======================================================================
271 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
272 Handle(TDocStd_Document) &doc)
274 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
275 return Transfer ( doc );
279 //=======================================================================
282 //=======================================================================
284 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
285 Handle(TDocStd_Document) &doc)
287 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
288 return Transfer ( doc );
292 //=======================================================================
293 //function : ExternFiles
295 //=======================================================================
297 const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
303 //=======================================================================
304 //function : ExternFile
306 //=======================================================================
308 Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
309 Handle(STEPCAFControl_ExternFile) &ef) const
312 if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
313 return Standard_False;
314 ef = myFiles->Item ( name );
315 return Standard_True;
319 //=======================================================================
322 //=======================================================================
324 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
330 //=======================================================================
333 //=======================================================================
335 const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
341 //=======================================================================
342 //function : FillShapesMap
343 //purpose : auxiliary: fill a map by all compounds and their components
344 //=======================================================================
346 static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
352 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
353 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
354 FillShapesMap ( it.Value(), map );
358 //=======================================================================
359 //function : Transfer
360 //purpose : basic working method
361 //=======================================================================
363 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
364 const Standard_Integer nroot,
365 Handle(TDocStd_Document) &doc,
366 TDF_LabelSequence &Lseq,
367 const Standard_Boolean asOne)
369 reader.ClearShapes();
373 Standard_Integer num = reader.NbRootsForTransfer();
374 if ( num <=0 ) return Standard_False;
376 if ( nroot > num ) return Standard_False;
377 reader.TransferOneRoot ( num );
380 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
382 num = reader.NbShapes();
383 if ( num <=0 ) return Standard_False;
385 // Fill a map of (top-level) shapes resulting from that transfer
386 // Only these shapes will be considered further
387 TopTools_MapOfShape ShapesMap, NewShapesMap;
388 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
390 // Collect information on shapes originating from SDRs
391 // this will be used to distinguish compounds representing assemblies
392 // from the ones representing hybrid models and shape sets
393 STEPCAFControl_DataMapOfShapePD ShapePDMap;
394 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
395 Handle(Interface_InterfaceModel) Model = reader.Model();
396 Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess();
397 Standard_Integer nb = Model->NbEntities();
399 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
401 for (i = 1; i <= nb; i ++) {
402 Handle(Standard_Transient) enti = Model->Value(i);
403 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
404 // sequence for acceleration ReadMaterials
405 SeqPDS->Append(enti);
407 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
408 Handle(StepBasic_ProductDefinition) PD =
409 Handle(StepBasic_ProductDefinition)::DownCast(enti);
410 Standard_Integer index = TP->MapIndex(PD);
412 Handle(Transfer_Binder) binder = TP->MapItem (index);
413 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
414 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
416 ShapePDMap.Bind ( S, PD );
417 Handle(STEPCAFControl_ExternFile) EF;
418 PDFileMap.Bind ( PD, EF );
422 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
423 Standard_Integer index = TP->MapIndex(enti);
425 Handle(Transfer_Binder) binder = TP->MapItem (index);
426 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
427 if ( ! S.IsNull() && ShapesMap.Contains(S) )
433 // get directory name of the main file
434 OSD_Path mainfile ( reader.WS()->LoadedFile() );
435 mainfile.SetName ( "" );
436 mainfile.SetExtension ( "" );
437 TCollection_AsciiString dpath;
438 mainfile.SystemName ( dpath );
440 // Load external references (only for relevant SDRs)
441 // and fill map SDR -> extern file
442 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
443 ExtRefs.LoadExternRefs();
444 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
445 // check extern ref format
446 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
447 if ( ! format.IsNull() ) {
448 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
449 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
450 if ( ! format->IsSameString ( ap203, Standard_False ) &&
451 ! format->IsSameString ( ap214, Standard_False ) ) {
453 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
460 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
463 // get and check filename of the current extern ref
464 const Standard_CString filename = ExtRefs.FileName(i);
466 cout<<"filename="<<filename<<endl;
468 if ( ! filename || ! filename[0] ) {
470 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
472 continue; // not a valid extern ref
475 // compute true path to the extern file
476 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
477 if ( fullname.Length() <= 0 ) fullname = filename;
481 char *mainfile = reader.WS()->LoadedFile();
482 if ( ! mainfile ) mainfile = "";
483 Standard_Integer slash = 0;
484 for ( Standard_Integer k=0; mainfile[k]; k++ )
485 if ( mainfile[k] == '/' ) slash = k;
486 strncpy ( fullname, mainfile, slash );
487 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
490 // get and check PD associated with the current extern ref
491 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
492 if ( PD.IsNull() ) continue; // not a valid extern ref
493 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
495 // read extern file (or use existing data) and record its data
496 Handle(STEPCAFControl_ExternFile) EF =
497 ReadExternFile ( filename, fullname.ToCString(), doc );
498 PDFileMap.Bind ( PD, EF );
501 // and insert them to the document
502 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
503 if ( STool.IsNull() ) return Standard_False;
504 XCAFDoc_DataMapOfShapeLabel map;
506 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
508 for ( i=1; i <= num; i++ ) {
509 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
514 if ( GetColorMode() )
515 ReadColors ( reader.WS(), doc, PDFileMap, map );
519 ReadNames ( reader.WS(), doc, PDFileMap, map );
521 // read validation props
522 if ( GetPropsMode() )
523 ReadValProps ( reader.WS(), doc, PDFileMap, map );
526 if ( GetLayerMode() )
527 ReadLayers ( reader.WS(), doc );
529 // read SHUO entities from STEP model
531 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
533 // read GDT entities from STEP model
535 ReadGDTs(reader.WS(),doc);
537 // read Material entities from STEP model
539 ReadMaterials(reader.WS(),doc,SeqPDS);
541 // cout << "Ready !!" << endl;
543 return Standard_True;
546 //=======================================================================
547 //function : AddShape
549 //=======================================================================
551 TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
552 const Handle(XCAFDoc_ShapeTool) &STool,
553 const TopTools_MapOfShape &NewShapesMap,
554 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
555 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
556 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
558 // if shape has already been mapped, just return corresponding label
559 if ( ShapeLabelMap.IsBound ( S ) ) {
560 return ShapeLabelMap.Find ( S );
563 // if shape is located, create instance
564 if ( ! S.Location().IsIdentity() ) {
568 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
569 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
570 ShapeLabelMap.Bind ( S, L );
574 // if shape is not compound, simple add it
575 if ( S.ShapeType() != TopAbs_COMPOUND ) {
576 TDF_Label L = STool->AddShape ( S, Standard_False );
577 ShapeLabelMap.Bind ( S, L );
581 // for compounds, compute number of subshapes and check whether this is assembly
582 Standard_Boolean isAssembly = Standard_False;
583 Standard_Integer nbComponents = 0;
585 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
586 TopoDS_Shape Sub0 = it.Value();
588 Sub0.Location ( loc );
589 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
592 // if(nbComponents>0) isAssembly = Standard_True;
594 // check whether it has associated external ref
595 TColStd_SequenceOfHAsciiString SHAS;
596 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
597 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
598 if ( ! EF.IsNull() ) {
599 // (store information on extern refs in the document)
600 SHAS.Append(EF->GetName());
601 // if yes, just return corresponding label
602 if ( ! EF->GetLabel().IsNull() ) {
603 // but if components >0, ignore extern ref!
604 if ( nbComponents <=0 ) {
605 ShapeLabelMap.Bind ( S, EF->GetLabel() );
606 STool->SetExternRefs(EF->GetLabel(),SHAS);
607 return EF->GetLabel();
611 if ( ! EF->GetLabel().IsNull() )
612 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
613 else if ( nbComponents <=0 )
614 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
619 // add compound either as a whole,
620 if ( ! isAssembly ) {
621 TDF_Label L = STool->AddShape ( S, Standard_False );
622 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
623 ShapeLabelMap.Bind ( S, L );
627 // or as assembly, component-by-component
628 TDF_Label L = STool->NewShape();
629 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
630 TopoDS_Shape Sub0 = it.Value();
632 Sub0.Location ( loc );
633 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
634 if ( ! subL.IsNull() ) {
635 STool->AddComponent ( L, subL, it.Value().Location() );
638 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
639 ShapeLabelMap.Bind ( S, L );
640 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
645 //=======================================================================
646 //function : ReadExternFile
648 //=======================================================================
650 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
651 const Standard_CString fullname,
652 Handle(TDocStd_Document)& doc)
654 // if the file is already read, associate it with SDR
655 if ( myFiles->HasItem ( file, Standard_True ) ) {
656 return myFiles->Item ( file );
660 cout << "Reading extern file: " << fullname << endl;
663 // create new WorkSession and Reader
664 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
665 newWS->SelectNorm ( "STEP" );
666 STEPControl_Reader sr ( newWS, Standard_False );
668 // start to fill the resulting ExternFile structure
669 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
671 EF->SetName ( new TCollection_HAsciiString ( file ) );
674 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
676 // transfer in single-result mode
677 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
678 TDF_LabelSequence labels;
679 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
680 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
683 // add read file to dictionary
684 myFiles->SetItem ( file, EF );
690 //=======================================================================
691 //function : SetColorToSubshape
693 //=======================================================================
694 static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
695 const TopoDS_Shape & S,
696 const Quantity_Color& col,
697 const XCAFDoc_ColorType type)
699 for (TopoDS_Iterator it(S); it.More(); it.Next())
700 if (! CTool->SetColor( it.Value(), col, type)) break;
704 //=======================================================================
705 //function : findStyledSR
707 //=======================================================================
708 static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
709 Handle(StepShape_ShapeRepresentation)& aSR)
711 // search Shape Represenatation for component styled item
712 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
713 Handle(StepVisual_PresentationStyleByContext) PSA =
714 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
717 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
718 Handle(StepShape_ShapeRepresentation) aCurrentSR =
719 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
720 if ( aCurrentSR.IsNull() )
728 //=======================================================================
729 //function : ReadColors
731 //=======================================================================
733 Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
734 Handle(TDocStd_Document)& Doc,
735 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
736 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
738 STEPConstruct_Styles Styles ( WS );
739 if ( ! Styles.LoadStyles() ) {
741 cout << "Warning: no styles are found in the model" << endl;
743 return Standard_False;
745 // searching for invisible items in the model
746 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
747 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
749 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
750 if ( CTool.IsNull() ) return Standard_False;
752 // parse and search for color attributes
753 Standard_Integer nb = Styles.NbStyles();
754 for ( Standard_Integer i=1; i <= nb; i++ ) {
755 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
756 if ( style.IsNull() ) continue;
758 Standard_Boolean IsVisible = Standard_True;
759 // check the visibility of styled item.
760 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
761 if ( style != aHSeqOfInvisStyle->Value( si ) )
763 // found that current style is invisible.
764 IsVisible = Standard_False;
768 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
769 // check if it is component style
770 Standard_Boolean IsComponent = Standard_False;
771 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
775 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() );
776 Standard_Boolean isSkipSHUOstyle = Standard_False;
777 // take shape with real location.
778 while ( IsComponent ) {
780 Handle(StepShape_ShapeRepresentation) aSR;
781 findStyledSR( style, aSR );
782 // search for SR along model
785 // Handle(Interface_InterfaceModel) Model = WS->Model();
786 Handle(XSControl_TransferReader) TR = WS->TransferReader();
787 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
788 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
789 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
790 for (subs.Start(); subs.More(); subs.Next()) {
791 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
794 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
795 Handle(StepRepr_ProductDefinitionShape) PDS =
796 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
799 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
801 Handle(StepRepr_AssemblyComponentUsage) ACU =
802 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
803 // PTV 10.02.2003 skip styled item that refer to SHUO
804 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
805 isSkipSHUOstyle = Standard_True;
808 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
809 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
814 // PTV 10.02.2003 to find component of assembly CORRECTLY
815 STEPConstruct_Tool Tool( WS );
816 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
817 aSh = CTool->ShapeTool()->GetShape(aShLab);
818 // Handle(Transfer_Binder) binder = TP->Find(NAUO);
819 // if ( binder.IsNull() || ! binder->HasResult() )
821 // aSh = TransferBRep::ShapeResult ( TP, binder );
830 continue; // skip styled item which refer to SHUO
835 if ( ! SurfCol.IsNull() ) {
837 Styles.DecodeColor ( SurfCol, col );
838 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
839 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
841 if ( ! BoundCol.IsNull() ) {
843 Styles.DecodeColor ( BoundCol, col );
844 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
845 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
847 if ( ! CurveCol.IsNull() ) {
849 Styles.DecodeColor ( CurveCol, col );
850 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
851 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
854 // sets the invisibility for shape.
856 if ( CTool->ShapeTool()->Search( S, aInvL ) )
857 CTool->SetVisibility( aInvL, Standard_False );
860 CTool->ReverseChainsOfTreeNodes();
861 return Standard_True;
864 //=======================================================================
865 //function : GetLabelFromPD
867 //=======================================================================
869 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
870 const Handle(XCAFDoc_ShapeTool) &STool,
871 const Handle(Transfer_TransientProcess) &TP,
872 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
873 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
876 if ( PDFileMap.IsBound ( PD ) ) {
877 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
878 if ( ! EF.IsNull() ) {
880 if ( ! L.IsNull() ) return L;
885 Handle(Transfer_Binder) binder = TP->Find(PD);
886 if ( binder.IsNull() || ! binder->HasResult() ) return L;
887 S = TransferBRep::ShapeResult ( TP, binder );
888 if ( S.IsNull() ) return L;
890 if ( S.IsNull() ) return L;
891 if ( ShapeLabelMap.IsBound ( S ) )
892 L = ShapeLabelMap.Find ( S );
894 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
898 //=======================================================================
899 //function : FindInstance
901 //=======================================================================
903 TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
904 const Handle(XCAFDoc_ShapeTool) &STool,
905 const STEPConstruct_Tool &Tool,
906 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
907 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
911 // get shape resulting from CDSR (in fact, only location is interesting)
912 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
913 Handle(Transfer_Binder) binder = TP->Find(NAUO);
914 if ( binder.IsNull() || ! binder->HasResult() ) {
916 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
921 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
924 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
929 // find component`s original label
930 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
931 if ( PD.IsNull() ) return L;
932 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
933 if ( Lref.IsNull() ) return L;
935 // find main shape (assembly) label
937 PD = NAUO->RelatingProductDefinition();
938 if ( PD.IsNull() ) return L;
939 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
940 if ( L0.IsNull() ) return L;
942 // if CDSR and NAUO are reversed, swap labels
943 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
944 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
945 for (subs1.Start(); subs1.More(); subs1.Next()) {
946 Handle(StepRepr_ProductDefinitionShape) PDS =
947 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
948 if(PDS.IsNull()) continue;
949 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
950 for (subs2.Start(); subs2.More(); subs2.Next()) {
951 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
952 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
953 if (CDSRtmp.IsNull()) continue;
957 if (CDSR.IsNull()) return L;
958 // if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
959 // TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
962 // iterate on components to find proper one
963 TDF_LabelSequence seq;
964 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
965 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
966 TDF_Label Lcomp = seq(k), Lref2;
967 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
969 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
976 //=======================================================================
977 //function : ReadNames
979 //=======================================================================
981 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
982 Handle(TDocStd_Document)& Doc,
983 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
984 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
987 Handle(Interface_InterfaceModel) Model = WS->Model();
988 Handle(XSControl_TransferReader) TR = WS->TransferReader();
989 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
990 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
991 if ( STool.IsNull() ) return Standard_False;
992 STEPConstruct_Tool Tool ( WS );
994 // iterate on model to find all SDRs and CDSRs
995 Standard_Integer nb = Model->NbEntities();
996 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
997 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
998 Handle(TCollection_HAsciiString) name;
1000 for (Standard_Integer i = 1; i <= nb; i++) {
1001 Handle(Standard_Transient) enti = Model->Value(i);
1003 // get description of NAUO
1004 if ( enti->DynamicType() == tNAUO ) {
1006 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1007 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1008 if(NAUO.IsNull()) continue;
1009 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1010 for (subs.Start(); subs.More(); subs.Next()) {
1011 Handle(StepRepr_ProductDefinitionShape) PDS =
1012 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1013 if(PDS.IsNull()) continue;
1014 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1015 if ( PDR.IsNull() ) continue;
1016 if ( PDR->HasDescription() &&
1017 PDR->Description()->Length() >0 ) name = PDR->Description();
1018 else if ( PDR->Name()->Length() >0 ) name = PDR->Name();
1019 else name = PDR->Id();
1021 // find proper label
1022 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1023 if ( L.IsNull() ) continue;
1024 TCollection_ExtendedString str ( name->String() );
1025 TDataStd_Name::Set ( L, str );
1028 // for PD get name of associated product
1029 if ( enti->DynamicType() == tPD ) {
1031 Handle(StepBasic_ProductDefinition) PD =
1032 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1033 if(PD.IsNull()) continue;
1034 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1035 if(Prod->Name()->UsefullLength()>0) name = Prod->Name();
1036 else name = Prod->Id();
1037 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1038 if ( L.IsNull() ) continue;
1039 TCollection_ExtendedString str ( name->String() );
1040 TDataStd_Name::Set ( L, str );
1042 // set a name to the document
1043 //TCollection_ExtendedString str ( name->String() );
1044 //TDataStd_Name::Set ( L, str );
1047 return Standard_True;
1050 //=======================================================================
1051 //function : GetLabelFromPD
1053 //=======================================================================
1055 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1056 const Handle(XCAFDoc_ShapeTool) &STool,
1057 const STEPConstruct_ValidationProps &Props,
1058 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1059 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1062 if ( PDFileMap.IsBound ( PD ) ) {
1063 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1064 if ( ! EF.IsNull() ) {
1066 if ( ! L.IsNull() ) return L;
1069 TopoDS_Shape S = Props.GetPropShape ( PD );
1070 if ( S.IsNull() ) return L;
1071 if ( ShapeLabelMap.IsBound ( S ) )
1072 L = ShapeLabelMap.Find ( S );
1074 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1078 //=======================================================================
1079 //function : ReadValProps
1081 //=======================================================================
1083 Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1084 Handle(TDocStd_Document)& Doc,
1085 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1086 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1088 // get starting data
1089 Handle(Interface_InterfaceModel) Model = WS->Model();
1090 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1091 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1092 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1093 if ( STool.IsNull() ) return Standard_False;
1095 // load props from the STEP model
1096 TColStd_SequenceOfTransient props;
1097 STEPConstruct_ValidationProps Props ( WS );
1098 if ( ! Props.LoadProps ( props ) ) {
1100 cout << "Warning: no validation props found in the model" << endl;
1102 return Standard_False;
1105 // interpret props one by one
1106 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1107 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1108 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1109 if ( PDR.IsNull() ) continue;
1113 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1114 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1115 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1116 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1117 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1118 if(PDS.IsNull()) continue;
1119 // find corresponding NAUO
1120 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1121 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1122 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1123 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1124 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1126 if ( !NAUO.IsNull() ) {
1127 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1128 if ( L.IsNull() ) continue;
1131 // find corresponding ProductDefinition:
1132 Handle(StepBasic_ProductDefinition) ProdDef;
1133 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1134 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1135 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1136 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1138 if ( ProdDef.IsNull() ) continue;
1139 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1143 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1144 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1145 if(SA.IsNull()) continue;
1146 // find ShapeRepresentation
1147 Handle(StepShape_ShapeRepresentation) SR;
1148 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1149 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1150 Handle(StepRepr_PropertyDefinition) PropD1 =
1151 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1152 if(PropD1.IsNull()) continue;
1153 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1154 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1155 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1156 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1157 if(SDR.IsNull()) continue;
1158 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1161 if(SR.IsNull()) continue;
1162 Handle(Transfer_Binder) binder;
1163 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1164 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1165 Handle(StepShape_SolidModel) SM =
1166 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1167 binder = TP->Find(SM);
1169 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1170 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1171 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1172 binder = TP->Find(SBSM);
1174 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1175 Handle(StepShape_GeometricSet) GS =
1176 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1177 binder = TP->Find(GS);
1180 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1182 S = TransferBRep::ShapeResult ( TP, binder );
1183 if(S.IsNull()) continue;
1184 if ( ShapeLabelMap.IsBound ( S ) )
1185 L = ShapeLabelMap.Find ( S );
1187 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1191 if(L.IsNull()) continue;
1193 // decode validation properties
1194 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1195 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1196 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1197 Standard_Boolean isArea;
1200 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1201 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1202 else XCAFDoc_Volume::Set ( L, val );
1204 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1205 XCAFDoc_Centroid::Set ( L, pos );
1209 return Standard_True;
1212 //=======================================================================
1213 //function : ReadLayers
1215 //=======================================================================
1217 Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1218 Handle(TDocStd_Document)& Doc) const
1220 Handle(Interface_InterfaceModel) Model = WS->Model();
1221 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1222 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1223 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1224 if ( STool.IsNull() ) return Standard_False;
1225 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1226 if ( LTool.IsNull() ) return Standard_False;
1228 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1229 Standard_Integer nb = Model->NbEntities();
1230 Handle(TCollection_HAsciiString) name;
1232 for (Standard_Integer i = 1; i <= nb; i ++) {
1233 Handle(Standard_Transient) enti = Model->Value(i);
1234 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1235 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1236 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1238 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1239 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1240 TCollection_ExtendedString aLayerName ( hName->String() );
1242 // find a target shape and its label in the document
1243 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1244 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1245 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1246 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1248 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1249 if ( S.IsNull() ) continue;
1252 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1253 LTool->SetLayer ( shL, aLayerName );
1256 // check invisibility
1257 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1258 for (subs.Start(); subs.More(); subs.Next()) {
1259 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1261 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1263 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1264 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1265 Handle(TDataStd_UAttribute) aUAttr;
1266 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1269 return Standard_True;
1272 //=======================================================================
1273 //function : ReadSHUOs
1275 //=======================================================================
1277 static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1278 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1279 const Handle(XCAFDoc_ShapeTool)& STool,
1280 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1281 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1282 TDF_LabelSequence& aLabels)
1284 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1285 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1286 for (subs.Start(); subs.More(); subs.Next()) {
1287 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1288 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1292 if (subSHUO.IsNull())
1293 return Standard_False;
1295 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1296 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
1297 if (NUNAUO.IsNull())
1298 return Standard_False;
1299 // Handle(Interface_InterfaceModel) Model = WS->Model();
1300 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1301 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1302 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1303 // if ( binder.IsNull() || ! binder->HasResult() )
1304 // return Standard_False;
1305 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1306 // get label of NAUO next level
1308 STEPConstruct_Tool Tool( WS );
1309 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1310 // STool->Search(NUSh, NUlab);
1312 return Standard_False;
1313 aLabels.Append( NULab );
1314 // and check by recurse.
1315 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1316 return Standard_True;
1320 //=======================================================================
1321 //function : setSHUOintoDoc
1322 //purpose : auxilary
1323 //=======================================================================
1324 static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1325 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1326 const Handle(XCAFDoc_ShapeTool)& STool,
1327 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1328 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1330 TDF_Label aMainLabel;
1331 // get upper usage NAUO from SHUO.
1332 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1333 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1334 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1335 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
1336 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1338 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1342 // Handle(Interface_InterfaceModel) Model = WS->Model();
1343 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1344 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1345 // TopoDS_Shape UUSh, NUSh;
1346 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1347 // if ( binder.IsNull() || ! binder->HasResult() )
1348 // return aMainLabel;
1349 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1350 // binder = TP->Find(NUNAUO);
1351 // if ( binder.IsNull() || ! binder->HasResult() )
1352 // return aMainLabel;
1353 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1355 // get first labels for first SHUO attribute
1356 TDF_Label UULab, NULab;
1357 STEPConstruct_Tool Tool( WS );
1358 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1359 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1361 // STool->Search(UUSh, UULab);
1362 // STool->Search(NUSh, NULab);
1363 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1364 //create sequence fo labels to set SHUO structure into the document
1365 TDF_LabelSequence ShuoLabels;
1366 ShuoLabels.Append( UULab );
1367 ShuoLabels.Append( NULab );
1368 // add all other labels of sub SHUO entities
1369 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1370 // last accord for SHUO
1371 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1372 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1373 aMainLabel = anSHUOAttr->Label();
1379 //=======================================================================
1380 //function : ReadSHUOs
1382 //=======================================================================
1384 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1385 Handle(TDocStd_Document)& Doc,
1386 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1387 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1389 // the big part code duplication from ReadColors.
1390 // It is possible to share this code functionality, just to decide how ???
1391 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1392 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1394 STEPConstruct_Styles Styles ( WS );
1395 if ( ! Styles.LoadStyles() ) {
1397 cout << "Warning: no styles are found in the model" << endl;
1399 return Standard_False;
1401 // searching for invisible items in the model
1402 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1403 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1404 // parse and search for color attributes
1405 Standard_Integer nb = Styles.NbStyles();
1406 for ( Standard_Integer i=1; i <= nb; i++ ) {
1407 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1408 if ( style.IsNull() ) continue;
1410 Standard_Boolean IsVisible = Standard_True;
1411 // check the visibility of styled item.
1412 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1413 if ( style != aHSeqOfInvisStyle->Value( si ) )
1415 // found that current style is invisible.
1417 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1419 IsVisible = Standard_False;
1423 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1424 // check if it is component style
1425 Standard_Boolean IsComponent = Standard_False;
1426 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1430 Handle(StepShape_ShapeRepresentation) aSR;
1431 findStyledSR( style, aSR );
1432 // search for SR along model
1435 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1436 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1437 for (subs.Start(); subs.More(); subs.Next()) {
1438 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1439 if ( aSDR.IsNull() )
1441 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1442 Handle(StepRepr_ProductDefinitionShape) PDS =
1443 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1446 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1447 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1448 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1449 if ( SHUO.IsNull() )
1452 // set the SHUO structure to the document
1453 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1454 if ( aLabelForStyle.IsNull() ) {
1456 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1460 // now set the style to the SHUO main label.
1461 if ( ! SurfCol.IsNull() ) {
1463 Styles.DecodeColor ( SurfCol, col );
1464 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1466 if ( ! BoundCol.IsNull() ) {
1468 Styles.DecodeColor ( BoundCol, col );
1469 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1471 if ( ! CurveCol.IsNull() ) {
1473 Styles.DecodeColor ( CurveCol, col );
1474 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1477 // sets the invisibility for shape.
1478 CTool->SetVisibility( aLabelForStyle, Standard_False );
1480 } // end search SHUO by SDR
1481 } // end iterates on styles
1483 return Standard_True;
1487 //=======================================================================
1488 //function : GetLengthConversionFactor
1490 //=======================================================================
1491 static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1492 Standard_Real& afact)
1495 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1496 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1497 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1498 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1499 afact = MWUCBU->ValueComponent();
1500 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1501 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1502 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1503 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1504 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1505 if(SU->Name()==StepBasic_sunMetre) {
1507 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1513 return Standard_True;
1517 //=======================================================================
1518 //function : GetMassConversionFactor
1520 //=======================================================================
1521 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1522 Standard_Real& afact)
1525 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1526 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1527 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1528 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1529 afact = MWUCBU->ValueComponent();
1530 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1531 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1532 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1533 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1534 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1535 if(SU->Name()==StepBasic_sunGram) {
1537 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1541 return Standard_True;
1545 //=======================================================================
1546 //function : ReadDatums
1547 //purpose : auxilary
1548 //=======================================================================
1549 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
1550 const Handle(XCAFDoc_DimTolTool) &DGTTool,
1551 const Interface_Graph &graph,
1552 Handle(Transfer_TransientProcess) &TP,
1553 const TDF_Label TolerL,
1554 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
1556 if(GTWDR.IsNull()) return Standard_False;
1557 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
1558 if(HADR.IsNull()) return Standard_False;
1559 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
1560 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
1561 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
1562 if(aDatum.IsNull()) continue;
1563 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
1564 for(subs4.Start(); subs4.More(); subs4.Next()) {
1565 Handle(StepRepr_ShapeAspectRelationship) SAR =
1566 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
1567 if(SAR.IsNull()) continue;
1568 Handle(StepDimTol_DatumFeature) DF =
1569 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
1570 if(DF.IsNull()) continue;
1571 Interface_EntityIterator subs5 = graph.Sharings(DF);
1572 Handle(StepRepr_PropertyDefinition) PropDef;
1573 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
1574 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
1576 if(PropDef.IsNull()) continue;
1577 Handle(StepShape_AdvancedFace) AF;
1578 subs5 = graph.Sharings(PropDef);
1579 for(subs5.Start(); subs5.More(); subs5.Next()) {
1580 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1581 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
1583 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1584 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1585 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
1586 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1590 if(AF.IsNull()) return Standard_False;
1591 Standard_Integer index = TP->MapIndex(AF);
1594 Handle(Transfer_Binder) binder = TP->MapItem(index);
1595 aSh = TransferBRep::ShapeResult(binder);
1597 if(aSh.IsNull()) continue;
1599 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1600 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
1603 return Standard_True;
1607 //=======================================================================
1608 //function : ReadGDTs
1610 //=======================================================================
1612 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession) &WS,
1613 Handle(TDocStd_Document)& Doc) const
1615 Handle(Interface_InterfaceModel) Model = WS->Model();
1616 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1617 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1618 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1619 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( Doc->Main() );
1620 if ( DGTTool.IsNull() ) return Standard_False;
1622 Standard_Integer nb = Model->NbEntities();
1623 const Interface_Graph& graph = TP->Graph();
1624 for(Standard_Integer i=1; i<=nb; i++) {
1625 Handle(Standard_Transient) ent = Model->Value(i);
1626 if(ent->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
1627 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(ent);
1628 // find RepresentationItem for current ShapeAspect
1629 Handle(StepRepr_RepresentationItem) RI;
1630 Handle(StepRepr_PropertyDefinition) PropD;
1631 Interface_EntityIterator subs3 = graph.Sharings(SA);
1632 for(subs3.Start(); subs3.More() && PropD.IsNull(); subs3.Next()) {
1633 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(subs3.Value());
1635 if(PropD.IsNull()) continue;
1636 Interface_EntityIterator subs4 = graph.Sharings(PropD);
1637 for(subs4.Start(); subs4.More(); subs4.Next()) {
1638 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1639 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
1641 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1642 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1643 RI = Repr->ItemsValue(1);
1647 if(RI.IsNull()) continue;
1648 // read DGT entities:
1649 subs3 = graph.Sharings(SA);
1650 for(subs3.Start(); subs3.More(); subs3.Next()) {
1651 if(subs3.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1653 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
1654 if(EC.IsNull()) continue;
1655 Handle(TCollection_HAsciiString) aName;
1656 Handle(StepShape_DimensionalSize) DimSize =
1657 Handle(StepShape_DimensionalSize)::DownCast(subs3.Value());
1658 Standard_Real dim1=-1.,dim2=-1.;
1659 subs4 = graph.Sharings(DimSize);
1660 for(subs4.Start(); subs4.More(); subs4.Next()) {
1661 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
1662 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
1663 if(!DimCharR.IsNull()) {
1664 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
1665 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
1666 Handle(StepRepr_RepresentationItem) RI = SDimR->ItemsValue(1);
1667 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(RI);
1670 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
1671 //if(CID.IsNull()) continue;
1672 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
1673 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
1674 //if(CIDM.IsNull()) continue;
1675 //if(CIDM->ArrTransient().IsNull()) continue;
1676 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
1677 //if(CID.CaseMem(CIDM)==1)
1678 // HARI = CID.ListRepresentationItem();
1679 //if(CID.CaseMem(CIDM)==2)
1680 // HARI = CID.SetRepresentationItem();
1681 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
1682 if(HARI.IsNull()) continue;
1683 if(HARI->Length()>0) {
1684 Handle(StepRepr_RepresentationItem) RI1 =
1685 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
1686 if(RI1.IsNull()) continue;
1687 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1688 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1689 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
1690 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1691 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1692 Standard_Real afact=1.;
1693 if(anUnit.IsNull()) continue;
1694 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1695 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1696 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
1699 if(HARI->Length()>1) {
1700 Handle(StepRepr_RepresentationItem) RI2 =
1701 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
1702 if(RI2.IsNull()) continue;
1703 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1704 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1705 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
1706 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1707 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1708 Standard_Real afact=1.;
1709 if(anUnit.IsNull()) continue;
1710 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1711 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1712 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
1719 if(dim1<0) continue;
1720 if(dim2<0) dim2=dim1;
1721 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
1722 // now we know edge_curve and value range therefore
1723 // we can create corresponding D> labels
1724 Standard_Integer index = TP->MapIndex(EC);
1727 Handle(Transfer_Binder) binder = TP->MapItem(index);
1728 aSh = TransferBRep::ShapeResult(binder);
1730 if(aSh.IsNull()) continue;
1732 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1733 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
1734 arr->SetValue(1,dim1);
1735 arr->SetValue(2,dim2);
1736 DGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
1738 // read tolerances and datums
1739 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
1740 Handle(StepDimTol_GeometricTolerance) GT =
1741 Handle(StepDimTol_GeometricTolerance)::DownCast(subs3.Value());
1742 // read common data for tolerance
1743 //Standard_Real dim = GT->Magnitude()->ValueComponent();
1744 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
1745 if(dim3.IsNull()) continue;
1746 Standard_Real dim = dim3->ValueComponent();
1747 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
1748 Standard_Real afact=1.;
1749 if(anUnit.IsNull()) continue;
1750 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1751 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1752 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
1753 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
1754 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
1755 arr->SetValue(1,dim);
1756 Handle(TCollection_HAsciiString) aName = GT->Name();
1757 Handle(TCollection_HAsciiString) aDescription = GT->Description();
1758 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1759 if(AF.IsNull()) continue;
1760 Standard_Integer index = TP->MapIndex(AF);
1763 Handle(Transfer_Binder) binder = TP->MapItem(index);
1764 aSh = TransferBRep::ShapeResult(binder);
1766 if(aSh.IsNull()) continue;
1768 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1769 // read specific data for tolerance
1770 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
1771 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
1772 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(subs3.Value());
1773 Standard_Integer kind=20;
1774 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1775 GTComplex->GetModifiedGeometricTolerance();
1777 kind = kind + MGT->Modifier()+1;
1779 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1780 // translate datums connected with this tolerance
1781 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1782 GTComplex->GetGeometricToleranceWithDatumReference();
1783 if(!GTWDR.IsNull()) {
1784 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1787 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
1788 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1789 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(subs3.Value());
1790 if(GTWDR.IsNull()) continue;
1791 Standard_Integer kind = 0;
1792 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
1793 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
1794 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
1795 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
1796 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
1797 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
1798 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
1799 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
1800 //cout<<"GTWDR: kind="<<kind<<endl;
1801 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1802 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1804 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
1805 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1806 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(subs3.Value());
1807 Standard_Integer kind = 35 + MGT->Modifier();
1808 DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1810 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
1811 DGTTool->SetDimTol(shL,38,arr,aName,aDescription);
1813 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
1814 DGTTool->SetDimTol(shL,39,arr,aName,aDescription);
1816 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
1817 DGTTool->SetDimTol(shL,40,arr,aName,aDescription);
1819 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
1820 DGTTool->SetDimTol(shL,41,arr,aName,aDescription);
1822 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
1823 DGTTool->SetDimTol(shL,42,arr,aName,aDescription);
1825 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
1826 DGTTool->SetDimTol(shL,43,arr,aName,aDescription);
1828 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
1829 DGTTool->SetDimTol(shL,44,arr,aName,aDescription);
1836 return Standard_True;
1840 //=======================================================================
1841 //function : FindSolidForPDS
1842 //purpose : auxilary
1843 //=======================================================================
1845 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
1846 const Interface_Graph &graph)
1848 Handle(StepShape_SolidModel) SM;
1849 Interface_EntityIterator subs = graph.Sharings(PDS);
1850 Handle(StepShape_ShapeRepresentation) SR;
1851 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
1852 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1853 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1854 if(SDR.IsNull()) continue;
1855 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1856 if(SR.IsNull()) continue;
1857 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
1858 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
1861 Interface_EntityIterator subs1 = graph.Sharings(SR);
1862 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
1863 Handle(StepRepr_RepresentationRelationship) RR =
1864 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
1865 if(RR.IsNull()) continue;
1866 Handle(StepShape_ShapeRepresentation) SR2;
1867 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
1868 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
1869 if(SR2.IsNull()) continue;
1870 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
1871 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
1880 //=======================================================================
1881 //function : ReadMaterials
1883 //=======================================================================
1885 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
1886 Handle(TDocStd_Document)& Doc,
1887 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
1889 Handle(Interface_InterfaceModel) Model = WS->Model();
1890 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1891 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1892 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1893 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
1894 if(MatTool.IsNull()) return Standard_False;
1896 const Interface_Graph& graph = TP->Graph();
1897 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
1898 Handle(StepRepr_ProductDefinitionShape) PDS =
1899 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
1902 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
1903 if(aProdDef.IsNull())
1905 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
1906 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
1907 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
1908 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
1909 Standard_Real aDensity=0;
1910 Interface_EntityIterator subs = graph.Sharings( aProdDef);
1911 for(subs.Start(); subs.More(); subs.Next()) {
1912 Handle(StepRepr_PropertyDefinition) PropD =
1913 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
1914 if(PropD.IsNull()) continue;
1915 Interface_EntityIterator subs1 = graph.Sharings(PropD);
1916 for(subs1.Start(); subs1.More(); subs1.Next()) {
1917 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1918 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
1919 if(PDR.IsNull()) continue;
1920 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
1921 if(Repr.IsNull()) continue;
1922 Standard_Integer ir;
1923 for(ir=1; ir<=Repr->NbItems(); ir++) {
1924 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
1925 if(RI.IsNull()) continue;
1926 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
1927 // find name and description for material
1928 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
1929 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
1930 aName = DRI->Name();
1932 aDescription = DRI->Description();
1934 aName = aDescription;
1936 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
1937 // try to find density for material
1938 Handle(StepRepr_MeasureRepresentationItem) MRI =
1939 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
1940 aDensity = MRI->Measure()->ValueComponent();
1941 aDensName = MRI->Name();
1942 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
1943 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
1944 if(!aUnit.IsNull()) {
1945 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
1946 if(DU.IsNull()) continue;
1947 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
1948 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
1949 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
1950 Standard_Real afact=1.;
1951 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
1952 if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact);
1953 // transfer length value for Density from millimeter to santimeter
1954 // in order to result density has dimension gram/(sm*sm*sm)
1955 aDensity = aDensity*1000.;
1957 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
1958 if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact;
1967 if( aName.IsNull() || aName->Length()==0 )
1969 // find shape label amd create Material link
1971 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
1973 Standard_Integer index = TP->MapIndex(SM);
1975 Handle(Transfer_Binder) binder = TP->MapItem(index);
1976 if(!binder.IsNull())
1977 aSh = TransferBRep::ShapeResult(binder);
1980 if(aSh.IsNull()) continue;
1982 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1983 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
1986 return Standard_True;
1990 //=======================================================================
1991 //function : SetColorMode
1993 //=======================================================================
1995 void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
1997 myColorMode = colormode;
2000 //=======================================================================
2001 //function : GetColorMode
2003 //=======================================================================
2005 Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
2010 //=======================================================================
2011 //function : SetNameMode
2013 //=======================================================================
2015 void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
2017 myNameMode = namemode;
2020 //=======================================================================
2021 //function : GetNameMode
2023 //=======================================================================
2025 Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
2030 //=======================================================================
2031 //function : SetLayerMode
2033 //=======================================================================
2035 void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
2037 myLayerMode = layermode;
2040 //=======================================================================
2041 //function : GetLayerMode
2043 //=======================================================================
2045 Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
2050 //=======================================================================
2051 //function : SetPropsMode
2053 //=======================================================================
2055 void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
2057 myPropsMode = propsmode;
2060 //=======================================================================
2061 //function : GetPropsMode
2063 //=======================================================================
2065 Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
2070 //=======================================================================
2071 //function : SetSHUOMode
2073 //=======================================================================
2075 void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
2080 //=======================================================================
2081 //function : GetSHUOMode
2083 //=======================================================================
2085 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
2090 //=======================================================================
2091 //function : SetGDTMode
2093 //=======================================================================
2095 void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
2097 myGDTMode = gdtmode;
2100 //=======================================================================
2101 //function : GetGDTMode
2103 //=======================================================================
2105 Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
2111 //=======================================================================
2112 //function : SetMatMode
2114 //=======================================================================
2116 void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
2118 myMatMode = matmode;
2121 //=======================================================================
2122 //function : GetMatMode
2124 //=======================================================================
2126 Standard_Boolean STEPCAFControl_Reader::GetMatMode () const