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.
17 #include <BRep_Builder.hxx>
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_InterfaceModel.hxx>
20 #include <StepData_StepModel.hxx>
21 #include <HeaderSection_FileSchema.hxx>
22 #include <Interface_Static.hxx>
23 #include <NCollection_DataMap.hxx>
24 #include <OSD_Path.hxx>
25 #include <Quantity_Color.hxx>
26 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
27 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
28 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
29 #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
30 #include <StepBasic_DerivedUnit.hxx>
31 #include <StepBasic_DerivedUnitElement.hxx>
32 #include <StepBasic_MeasureValueMember.hxx>
33 #include <StepBasic_MeasureWithUnit.hxx>
34 #include <StepBasic_NamedUnit.hxx>
35 #include <StepBasic_Product.hxx>
36 #include <StepBasic_ProductDefinition.hxx>
37 #include <StepBasic_ProductDefinitionFormation.hxx>
38 #include <StepBasic_ProductDefinitionRelationship.hxx>
39 #include <StepBasic_SiUnit.hxx>
40 #include <StepBasic_Unit.hxx>
41 #include <STEPCAFControl_Controller.hxx>
42 #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
43 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
44 #include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
45 #include <STEPCAFControl_DataMapOfShapePD.hxx>
46 #include <STEPCAFControl_DictionaryOfExternFile.hxx>
47 #include <STEPCAFControl_ExternFile.hxx>
48 #include <STEPCAFControl_Reader.hxx>
49 #include <STEPConstruct.hxx>
50 #include <STEPConstruct_Assembly.hxx>
51 #include <STEPConstruct_ExternRefs.hxx>
52 #include <STEPConstruct_Styles.hxx>
53 #include <STEPConstruct_Tool.hxx>
54 #include <STEPConstruct_UnitContext.hxx>
55 #include <STEPConstruct_ValidationProps.hxx>
56 #include <STEPControl_Reader.hxx>
57 #include <StepGeom_GeometricRepresentationItem.hxx>
58 #include <StepGeom_Axis2Placement3d.hxx>
59 #include <StepGeom_Direction.hxx>
60 #include <StepDimTol_AngularityTolerance.hxx>
61 #include <StepDimTol_CircularRunoutTolerance.hxx>
62 #include <StepDimTol_CoaxialityTolerance.hxx>
63 #include <StepDimTol_ConcentricityTolerance.hxx>
64 #include <StepDimTol_CylindricityTolerance.hxx>
65 #include <StepDimTol_Datum.hxx>
66 #include <StepDimTol_DatumFeature.hxx>
67 #include <StepDimTol_DatumReference.hxx>
68 #include <StepDimTol_DatumReferenceElement.hxx>
69 #include <StepDimTol_DatumReferenceCompartment.hxx>
70 #include <StepDimTol_DatumSystem.hxx>
71 #include <StepDimTol_FlatnessTolerance.hxx>
72 #include <StepDimTol_GeometricTolerance.hxx>
73 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
74 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
75 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
76 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
77 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
78 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
79 #include <StepDimTol_HArray1OfDatumReference.hxx>
80 #include <StepDimTol_LineProfileTolerance.hxx>
81 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
82 #include <StepDimTol_ParallelismTolerance.hxx>
83 #include <StepDimTol_PerpendicularityTolerance.hxx>
84 #include <StepDimTol_PositionTolerance.hxx>
85 #include <StepDimTol_ProjectedZoneDefinition.hxx>
86 #include <StepDimTol_RoundnessTolerance.hxx>
87 #include <StepDimTol_RunoutZoneDefinition.hxx>
88 #include <StepDimTol_StraightnessTolerance.hxx>
89 #include <StepDimTol_SurfaceProfileTolerance.hxx>
90 #include <StepDimTol_SymmetryTolerance.hxx>
91 #include <StepDimTol_ToleranceZone.hxx>
92 #include <StepDimTol_ToleranceZoneForm.hxx>
93 #include <StepDimTol_TotalRunoutTolerance.hxx>
94 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
95 #include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
96 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
97 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
98 #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
99 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
100 #include <StepRepr_AssemblyComponentUsage.hxx>
101 #include <StepRepr_CharacterizedDefinition.hxx>
102 #include <StepRepr_CompoundRepresentationItem.hxx>
103 #include <StepRepr_DescriptiveRepresentationItem.hxx>
104 #include <StepRepr_HArray1OfRepresentationItem.hxx>
105 #include <StepRepr_MeasureRepresentationItem.hxx>
106 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
107 #include <StepRepr_ProductDefinitionShape.hxx>
108 #include <StepRepr_PropertyDefinition.hxx>
109 #include <StepRepr_PropertyDefinitionRepresentation.hxx>
110 #include <StepRepr_Representation.hxx>
111 #include <StepRepr_RepresentationItem.hxx>
112 #include <StepRepr_HArray1OfRepresentationItem.hxx>
113 #include <StepRepr_RepresentationRelationship.hxx>
114 #include <StepRepr_RepresentedDefinition.hxx>
115 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
116 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
117 #include <StepRepr_SequenceOfRepresentationItem.hxx>
118 #include <StepRepr_ShapeAspect.hxx>
119 #include <StepRepr_CompositeShapeAspect.hxx>
120 #include <StepRepr_AllAroundShapeAspect.hxx>
121 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
122 #include <StepRepr_ShapeAspectRelationship.hxx>
123 #include <StepRepr_ShapeRepresentationRelationship.hxx>
124 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
125 #include <StepRepr_ValueRange.hxx>
126 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
127 #include <StepShape_AdvancedFace.hxx>
128 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
129 #include <StepShape_AngleRelator.hxx>
130 #include <StepShape_AngularSize.hxx>
131 #include <StepShape_AngularLocation.hxx>
132 #include <StepShape_ClosedShell.hxx>
133 #include <StepShape_ConnectedFaceSet.hxx>
134 #include <StepShape_ContextDependentShapeRepresentation.hxx>
135 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
136 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
137 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
138 #include <StepShape_DimensionalSizeWithPath.hxx>
139 #include <StepShape_DimensionalLocationWithPath.hxx>
140 #include <StepShape_ShapeDimensionRepresentationItem.hxx>
141 #include <StepShape_ShapeRepresentationWithParameters.hxx>
142 #include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
143 #include <StepShape_DimensionalSize.hxx>
144 #include <StepShape_DimensionalLocation.hxx>
145 #include <StepShape_EdgeCurve.hxx>
146 #include <StepShape_EdgeLoop.hxx>
147 #include <StepShape_GeometricSet.hxx>
148 #include <StepShape_HArray1OfFace.hxx>
149 #include <StepShape_HArray1OfFaceBound.hxx>
150 #include <StepShape_HArray1OfOrientedEdge.hxx>
151 #include <StepShape_HArray1OfShell.hxx>
152 #include <StepShape_LimitsAndFits.hxx>
153 #include <StepShape_Loop.hxx>
154 #include <StepShape_ManifoldSolidBrep.hxx>
155 #include <StepShape_PlusMinusTolerance.hxx>
156 #include <StepShape_QualifiedRepresentationItem.hxx>
157 #include <StepShape_OpenShell.hxx>
158 #include <StepShape_ShapeDefinitionRepresentation.hxx>
159 #include <StepShape_ShapeDimensionRepresentation.hxx>
160 #include <StepShape_ShapeRepresentation.hxx>
161 #include <StepShape_ShellBasedSurfaceModel.hxx>
162 #include <StepShape_SolidModel.hxx>
163 #include <StepShape_ToleranceMethodDefinition.hxx>
164 #include <StepShape_ToleranceValue.hxx>
165 #include <StepShape_ValueFormatTypeQualifier.hxx>
166 #include <StepShape_Vertex.hxx>
167 #include <StepVisual_Invisibility.hxx>
168 #include <StepVisual_LayeredItem.hxx>
169 #include <StepVisual_PresentationLayerAssignment.hxx>
170 #include <StepVisual_PresentationStyleByContext.hxx>
171 #include <StepVisual_StyleContextSelect.hxx>
172 #include <StepVisual_StyledItem.hxx>
173 #include <StepShape_TypeQualifier.hxx>
174 #include <TCollection_AsciiString.hxx>
175 #include <TCollection_HAsciiString.hxx>
176 #include <TColStd_HArray1OfReal.hxx>
177 #include <TColStd_HArray1OfTransient.hxx>
178 #include <TColStd_HSequenceOfTransient.hxx>
179 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
180 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
181 #include <TColStd_MapOfTransient.hxx>
182 #include <TColStd_SequenceOfHAsciiString.hxx>
183 #include <TDataStd_Name.hxx>
184 #include <TDataStd_TreeNode.hxx>
185 #include <TDataStd_UAttribute.hxx>
186 #include <TDF_Label.hxx>
187 #include <TDF_Tool.hxx>
188 #include <TDocStd_Document.hxx>
189 #include <TNaming_NamedShape.hxx>
190 #include <TopoDS.hxx>
191 #include <TopoDS_Compound.hxx>
192 #include <TopoDS_Iterator.hxx>
193 #include <TopoDS_Shape.hxx>
194 #include <TopTools_ListIteratorOfListOfShape.hxx>
195 #include <TopTools_ListOfShape.hxx>
196 #include <TopTools_MapOfShape.hxx>
197 #include <Transfer_Binder.hxx>
198 #include <Transfer_TransientProcess.hxx>
199 #include <TransferBRep.hxx>
200 #include <XCAFDoc.hxx>
201 #include <XCAFDoc_Area.hxx>
202 #include <XCAFDoc_Centroid.hxx>
203 #include <XCAFDoc_ColorTool.hxx>
204 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
205 #include <XCAFDoc_DimTolTool.hxx>
206 #include <XCAFDoc_Dimension.hxx>
207 #include <XCAFDoc_Datum.hxx>
208 #include <XCAFDoc_GeomTolerance.hxx>
209 #include <XCAFDoc_DocumentTool.hxx>
210 #include <XCAFDoc_GraphNode.hxx>
211 #include <XCAFDoc_LayerTool.hxx>
212 #include <XCAFDoc_MaterialTool.hxx>
213 #include <XCAFDoc_ShapeTool.hxx>
214 #include <XCAFDoc_Volume.hxx>
215 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
216 #include <XCAFDimTolObjects_GeomToleranceType.hxx>
217 #include <XCAFDimTolObjects_DimensionObject.hxx>
218 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
219 #include <XCAFDimTolObjects_DatumObject.hxx>
220 #include <XSControl_TransferReader.hxx>
221 #include <XSControl_WorkSession.hxx>
222 #include <StepAP242_GeometricItemSpecificUsage.hxx>
223 #include <StepGeom_CartesianPoint.hxx>
224 #include <STEPCAFControl_GDTProperty.hxx>
225 // skl 21.08.2003 for reading G&DT
226 //#include <StepRepr_CompoundItemDefinition.hxx>
227 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
228 //#include <StepBasic_ConversionBasedUnit.hxx>
229 //#include <TDataStd_Real.hxx>
230 //#include <TDataStd_Constraint.hxx>
231 //#include <TDataStd_ConstraintEnum.hxx>
232 //#include <TNaming_Tool.hxx>
233 //#include <AIS_InteractiveObject.hxx>
234 //#include <TPrsStd_ConstraintTools.hxx>
235 //#include <AIS_DiameterDimension.hxx>
236 //#include <TPrsStd_Position.hxx>
237 //#include <TPrsStd_AISPresentation.hxx>
238 //#include <TNaming_Builder.hxx>
240 //! Converts address of the passed shape (TShape) to string.
241 //! \param theShape [in] Shape to dump.
242 //! \return corresponding string.
243 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
245 std::string anAddrStr;
246 std::ostringstream ost;
247 ost << theShape.TShape().get();
248 anAddrStr = ost.str();
250 TCollection_AsciiString aStr =
251 TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]");
257 //=======================================================================
259 //purpose : global function to check equality of topological shapes
260 //=======================================================================
262 inline Standard_Boolean IsEqual(const TopoDS_Shape& theShape1,
263 const TopoDS_Shape& theShape2)
265 return theShape1.IsEqual(theShape2);
268 //=======================================================================
269 //function : AllocateSubLabel
271 //=======================================================================
273 static TDF_Label AllocateSubLabel(TDF_Label& theRoot)
275 return TDF_TagSource::NewChild(theRoot);
278 //=======================================================================
279 //function : STEPCAFControl_Reader
281 //=======================================================================
283 STEPCAFControl_Reader::STEPCAFControl_Reader ():
284 myColorMode( Standard_True ),
285 myNameMode ( Standard_True ),
286 myLayerMode( Standard_True ),
287 myPropsMode( Standard_True ),
288 mySHUOMode ( Standard_False ),
289 myGDTMode ( Standard_True ),
290 myMatMode ( Standard_True )
292 STEPCAFControl_Controller::Init();
293 myFiles = new STEPCAFControl_DictionaryOfExternFile;
297 //=======================================================================
298 //function : STEPCAFControl_Reader
300 //=======================================================================
302 STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
303 const Standard_Boolean scratch) :
304 myColorMode( Standard_True ),
305 myNameMode ( Standard_True ),
306 myLayerMode( Standard_True ),
307 myPropsMode( Standard_True ),
308 mySHUOMode ( Standard_False ),
309 myGDTMode ( Standard_True ),
310 myMatMode ( Standard_True )
312 STEPCAFControl_Controller::Init();
313 Init ( WS, scratch );
317 //=======================================================================
320 //=======================================================================
322 void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
323 const Standard_Boolean scratch)
325 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
326 myReader.SetWS (WS,scratch);
327 myFiles = new STEPCAFControl_DictionaryOfExternFile;
331 //=======================================================================
332 //function : ReadFile
334 //=======================================================================
336 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
338 return myReader.ReadFile ( filename );
342 //=======================================================================
343 //function : NbRootsForTransfer
345 //=======================================================================
347 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
349 return myReader.NbRootsForTransfer();
353 //=======================================================================
354 //function : TransferOneRoot
356 //=======================================================================
358 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
359 Handle(TDocStd_Document) &doc)
361 TDF_LabelSequence Lseq;
362 return Transfer ( myReader, num, doc, Lseq );
366 //=======================================================================
367 //function : Transfer
369 //=======================================================================
371 Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
373 TDF_LabelSequence Lseq;
374 return Transfer ( myReader, 0, doc, Lseq );
378 //=======================================================================
381 //=======================================================================
383 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
384 Handle(TDocStd_Document) &doc)
386 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
387 return Transfer ( doc );
391 //=======================================================================
394 //=======================================================================
396 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
397 Handle(TDocStd_Document) &doc)
399 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
400 return Transfer ( doc );
404 //=======================================================================
405 //function : ExternFiles
407 //=======================================================================
409 const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
415 //=======================================================================
416 //function : ExternFile
418 //=======================================================================
420 Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
421 Handle(STEPCAFControl_ExternFile) &ef) const
424 if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
425 return Standard_False;
426 ef = myFiles->Item ( name );
427 return Standard_True;
431 //=======================================================================
434 //=======================================================================
436 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
442 //=======================================================================
445 //=======================================================================
447 const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
453 //=======================================================================
454 //function : FillShapesMap
455 //purpose : auxiliary: fill a map by all compounds and their components
456 //=======================================================================
458 static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
464 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
465 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
466 FillShapesMap ( it.Value(), map );
470 //=======================================================================
471 //function : Transfer
472 //purpose : basic working method
473 //=======================================================================
475 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
476 const Standard_Integer nroot,
477 Handle(TDocStd_Document) &doc,
478 TDF_LabelSequence &Lseq,
479 const Standard_Boolean asOne)
481 reader.ClearShapes();
485 Standard_Integer num = reader.NbRootsForTransfer();
486 if ( num <=0 ) return Standard_False;
488 if ( nroot > num ) return Standard_False;
489 reader.TransferOneRoot ( nroot );
492 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
494 num = reader.NbShapes();
495 if ( num <=0 ) return Standard_False;
497 // Fill a map of (top-level) shapes resulting from that transfer
498 // Only these shapes will be considered further
499 TopTools_MapOfShape ShapesMap, NewShapesMap;
500 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
502 // Collect information on shapes originating from SDRs
503 // this will be used to distinguish compounds representing assemblies
504 // from the ones representing hybrid models and shape sets
505 STEPCAFControl_DataMapOfShapePD ShapePDMap;
506 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
507 Handle(Interface_InterfaceModel) Model = reader.Model();
508 Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess();
509 Standard_Integer nb = Model->NbEntities();
511 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
513 for (i = 1; i <= nb; i ++) {
514 Handle(Standard_Transient) enti = Model->Value(i);
515 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
516 // sequence for acceleration ReadMaterials
517 SeqPDS->Append(enti);
519 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
520 Handle(StepBasic_ProductDefinition) PD =
521 Handle(StepBasic_ProductDefinition)::DownCast(enti);
522 Standard_Integer index = TP->MapIndex(PD);
524 Handle(Transfer_Binder) binder = TP->MapItem (index);
525 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
526 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
528 ShapePDMap.Bind ( S, PD );
529 Handle(STEPCAFControl_ExternFile) EF;
530 PDFileMap.Bind ( PD, EF );
534 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
535 Standard_Integer index = TP->MapIndex(enti);
537 Handle(Transfer_Binder) binder = TP->MapItem (index);
538 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
539 if ( ! S.IsNull() && ShapesMap.Contains(S) )
545 // get directory name of the main file
546 OSD_Path mainfile ( reader.WS()->LoadedFile() );
547 mainfile.SetName ( "" );
548 mainfile.SetExtension ( "" );
549 TCollection_AsciiString dpath;
550 mainfile.SystemName ( dpath );
552 // Load external references (only for relevant SDRs)
553 // and fill map SDR -> extern file
554 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
555 ExtRefs.LoadExternRefs();
556 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
557 // check extern ref format
558 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
559 if ( ! format.IsNull() ) {
560 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
561 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
562 if ( ! format->IsSameString ( ap203, Standard_False ) &&
563 ! format->IsSameString ( ap214, Standard_False ) ) {
565 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
572 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
575 // get and check filename of the current extern ref
576 const Standard_CString filename = ExtRefs.FileName(i);
579 cout<<"filename="<<filename<<endl;
582 if ( ! filename || ! filename[0] ) {
584 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
586 continue; // not a valid extern ref
589 // compute true path to the extern file
590 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
591 if ( fullname.Length() <= 0 ) fullname = filename;
595 char *mainfile = reader.WS()->LoadedFile();
596 if ( ! mainfile ) mainfile = "";
597 Standard_Integer slash = 0;
598 for ( Standard_Integer k=0; mainfile[k]; k++ )
599 if ( mainfile[k] == '/' ) slash = k;
600 strncpy ( fullname, mainfile, slash );
601 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
604 // get and check PD associated with the current extern ref
605 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
606 if ( PD.IsNull() ) continue; // not a valid extern ref
607 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
609 // read extern file (or use existing data) and record its data
610 Handle(STEPCAFControl_ExternFile) EF =
611 ReadExternFile ( filename, fullname.ToCString(), doc );
612 PDFileMap.Bind ( PD, EF );
615 // and insert them to the document
616 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
617 if ( STool.IsNull() ) return Standard_False;
618 XCAFDoc_DataMapOfShapeLabel map;
620 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
622 for ( i=1; i <= num; i++ ) {
623 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
628 if ( GetColorMode() )
629 ReadColors ( reader.WS(), doc, PDFileMap, map );
633 ReadNames ( reader.WS(), doc, PDFileMap, map );
635 // read validation props
636 if ( GetPropsMode() )
637 ReadValProps ( reader.WS(), doc, PDFileMap, map );
640 if ( GetLayerMode() )
641 ReadLayers ( reader.WS(), doc );
643 // read SHUO entities from STEP model
645 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
647 // read GDT entities from STEP model
649 ReadGDTs(reader.WS(),doc);
651 // read Material entities from STEP model
653 ReadMaterials(reader.WS(),doc,SeqPDS);
655 // Expand resulting CAF structure for sub-shapes (optionally with their
656 // names) if requested
657 ExpandSubShapes(STool, map, ShapePDMap);
659 return Standard_True;
662 //=======================================================================
663 //function : AddShape
665 //=======================================================================
667 TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
668 const Handle(XCAFDoc_ShapeTool) &STool,
669 const TopTools_MapOfShape &NewShapesMap,
670 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
671 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
672 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
674 // if shape has already been mapped, just return corresponding label
675 if ( ShapeLabelMap.IsBound ( S ) ) {
676 return ShapeLabelMap.Find ( S );
679 // if shape is located, create instance
680 if ( ! S.Location().IsIdentity() ) {
684 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
685 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
686 ShapeLabelMap.Bind ( S, L );
690 // if shape is not compound, simple add it
691 if ( S.ShapeType() != TopAbs_COMPOUND ) {
692 TDF_Label L = STool->AddShape ( S, Standard_False );
693 ShapeLabelMap.Bind ( S, L );
697 // for compounds, compute number of subshapes and check whether this is assembly
698 Standard_Boolean isAssembly = Standard_False;
699 Standard_Integer nbComponents = 0;
701 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
702 TopoDS_Shape Sub0 = it.Value();
704 Sub0.Location ( loc );
705 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
708 // if(nbComponents>0) isAssembly = Standard_True;
710 // check whether it has associated external ref
711 TColStd_SequenceOfHAsciiString SHAS;
712 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
713 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
714 if ( ! EF.IsNull() ) {
715 // (store information on extern refs in the document)
716 SHAS.Append(EF->GetName());
717 // if yes, just return corresponding label
718 if ( ! EF->GetLabel().IsNull() ) {
719 // but if components >0, ignore extern ref!
720 if ( nbComponents <=0 ) {
721 ShapeLabelMap.Bind ( S, EF->GetLabel() );
722 STool->SetExternRefs(EF->GetLabel(),SHAS);
723 return EF->GetLabel();
727 if ( ! EF->GetLabel().IsNull() )
728 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
729 else if ( nbComponents <=0 )
730 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
735 // add compound either as a whole,
736 if ( ! isAssembly ) {
737 TDF_Label L = STool->AddShape ( S, Standard_False );
738 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
739 ShapeLabelMap.Bind ( S, L );
743 // or as assembly, component-by-component
744 TDF_Label L = STool->NewShape();
745 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
746 TopoDS_Shape Sub0 = it.Value();
748 Sub0.Location ( loc );
749 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
750 if ( ! subL.IsNull() ) {
751 STool->AddComponent ( L, subL, it.Value().Location() );
754 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
755 ShapeLabelMap.Bind ( S, L );
756 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
761 //=======================================================================
762 //function : ReadExternFile
764 //=======================================================================
766 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
767 const Standard_CString fullname,
768 Handle(TDocStd_Document)& doc)
770 // if the file is already read, associate it with SDR
771 if ( myFiles->HasItem ( file, Standard_True ) ) {
772 return myFiles->Item ( file );
776 cout << "Reading extern file: " << fullname << endl;
779 // create new WorkSession and Reader
780 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
781 newWS->SelectNorm ( "STEP" );
782 STEPControl_Reader sr ( newWS, Standard_False );
784 // start to fill the resulting ExternFile structure
785 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
787 EF->SetName ( new TCollection_HAsciiString ( file ) );
790 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
792 // transfer in single-result mode
793 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
794 TDF_LabelSequence labels;
795 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
796 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
799 // add read file to dictionary
800 myFiles->SetItem ( file, EF );
806 //=======================================================================
807 //function : SetColorToSubshape
809 //=======================================================================
810 static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
811 const TopoDS_Shape & S,
812 const Quantity_Color& col,
813 const XCAFDoc_ColorType type)
815 for (TopoDS_Iterator it(S); it.More(); it.Next())
816 if (! CTool->SetColor( it.Value(), col, type)) break;
820 //=======================================================================
821 //function : findStyledSR
823 //=======================================================================
824 static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
825 Handle(StepShape_ShapeRepresentation)& aSR)
827 // search Shape Represenatation for component styled item
828 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
829 Handle(StepVisual_PresentationStyleByContext) PSA =
830 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
833 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
834 Handle(StepShape_ShapeRepresentation) aCurrentSR =
835 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
836 if ( aCurrentSR.IsNull() )
844 //=======================================================================
845 //function : ReadColors
847 //=======================================================================
849 Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
850 Handle(TDocStd_Document)& Doc,
851 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
852 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
854 STEPConstruct_Styles Styles ( WS );
855 if ( ! Styles.LoadStyles() ) {
857 cout << "Warning: no styles are found in the model" << endl;
859 return Standard_False;
861 // searching for invisible items in the model
862 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
863 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
865 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
866 if ( CTool.IsNull() ) return Standard_False;
868 // parse and search for color attributes
869 Standard_Integer nb = Styles.NbStyles();
870 for ( Standard_Integer i=1; i <= nb; i++ ) {
871 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
872 if ( style.IsNull() ) continue;
874 Standard_Boolean IsVisible = Standard_True;
875 // check the visibility of styled item.
876 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
877 if ( style != aHSeqOfInvisStyle->Value( si ) )
879 // found that current style is invisible.
880 IsVisible = Standard_False;
884 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
885 // check if it is component style
886 Standard_Boolean IsComponent = Standard_False;
887 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
891 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() );
892 Standard_Boolean isSkipSHUOstyle = Standard_False;
893 // take shape with real location.
894 while ( IsComponent ) {
896 Handle(StepShape_ShapeRepresentation) aSR;
897 findStyledSR( style, aSR );
898 // search for SR along model
901 // Handle(Interface_InterfaceModel) Model = WS->Model();
902 Handle(XSControl_TransferReader) TR = WS->TransferReader();
903 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
904 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
905 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
906 for (subs.Start(); subs.More(); subs.Next()) {
907 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
910 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
911 Handle(StepRepr_ProductDefinitionShape) PDS =
912 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
915 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
917 Handle(StepRepr_AssemblyComponentUsage) ACU =
918 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
919 // PTV 10.02.2003 skip styled item that refer to SHUO
920 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
921 isSkipSHUOstyle = Standard_True;
924 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
925 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
930 // PTV 10.02.2003 to find component of assembly CORRECTLY
931 STEPConstruct_Tool Tool( WS );
932 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
933 aSh = CTool->ShapeTool()->GetShape(aShLab);
934 // Handle(Transfer_Binder) binder = TP->Find(NAUO);
935 // if ( binder.IsNull() || ! binder->HasResult() )
937 // aSh = TransferBRep::ShapeResult ( TP, binder );
946 continue; // skip styled item which refer to SHUO
951 if ( ! SurfCol.IsNull() ) {
953 Styles.DecodeColor ( SurfCol, col );
954 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
955 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
957 if ( ! BoundCol.IsNull() ) {
959 Styles.DecodeColor ( BoundCol, col );
960 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
961 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
963 if ( ! CurveCol.IsNull() ) {
965 Styles.DecodeColor ( CurveCol, col );
966 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
967 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
970 // sets the invisibility for shape.
972 if ( CTool->ShapeTool()->Search( S, aInvL ) )
973 CTool->SetVisibility( aInvL, Standard_False );
976 CTool->ReverseChainsOfTreeNodes();
977 return Standard_True;
980 //=======================================================================
981 //function : GetLabelFromPD
983 //=======================================================================
985 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
986 const Handle(XCAFDoc_ShapeTool) &STool,
987 const Handle(Transfer_TransientProcess) &TP,
988 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
989 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
992 if ( PDFileMap.IsBound ( PD ) ) {
993 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
994 if ( ! EF.IsNull() ) {
996 if ( ! L.IsNull() ) return L;
1001 Handle(Transfer_Binder) binder = TP->Find(PD);
1002 if ( binder.IsNull() || ! binder->HasResult() ) return L;
1003 S = TransferBRep::ShapeResult ( TP, binder );
1004 if ( S.IsNull() ) return L;
1006 if ( S.IsNull() ) return L;
1007 if ( ShapeLabelMap.IsBound ( S ) )
1008 L = ShapeLabelMap.Find ( S );
1010 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1014 //=======================================================================
1015 //function : FindInstance
1017 //=======================================================================
1019 TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1020 const Handle(XCAFDoc_ShapeTool) &STool,
1021 const STEPConstruct_Tool &Tool,
1022 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1023 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1027 // get shape resulting from CDSR (in fact, only location is interesting)
1028 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1029 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1030 if ( binder.IsNull() || ! binder->HasResult() ) {
1032 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1037 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1040 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1045 // find component`s original label
1046 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
1047 if ( PD.IsNull() ) return L;
1048 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1049 if ( Lref.IsNull() ) return L;
1051 // find main shape (assembly) label
1053 PD = NAUO->RelatingProductDefinition();
1054 if ( PD.IsNull() ) return L;
1055 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1056 if ( L0.IsNull() ) return L;
1058 // if CDSR and NAUO are reversed, swap labels
1059 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1060 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
1061 for (subs1.Start(); subs1.More(); subs1.Next()) {
1062 Handle(StepRepr_ProductDefinitionShape) PDS =
1063 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
1064 if(PDS.IsNull()) continue;
1065 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
1066 for (subs2.Start(); subs2.More(); subs2.Next()) {
1067 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
1068 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
1069 if (CDSRtmp.IsNull()) continue;
1073 if (CDSR.IsNull()) return L;
1074 // if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
1075 // TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
1078 // iterate on components to find proper one
1079 TDF_LabelSequence seq;
1080 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
1081 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
1082 TDF_Label Lcomp = seq(k), Lref2;
1083 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
1085 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
1092 //=======================================================================
1093 //function : ReadNames
1095 //=======================================================================
1097 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
1098 Handle(TDocStd_Document)& Doc,
1099 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1100 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1102 // get starting data
1103 Handle(Interface_InterfaceModel) Model = WS->Model();
1104 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1105 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1106 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1107 if ( STool.IsNull() ) return Standard_False;
1108 STEPConstruct_Tool Tool ( WS );
1110 // iterate on model to find all SDRs and CDSRs
1111 Standard_Integer nb = Model->NbEntities();
1112 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1113 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1114 Handle(TCollection_HAsciiString) name;
1116 for (Standard_Integer i = 1; i <= nb; i++) {
1117 Handle(Standard_Transient) enti = Model->Value(i);
1119 // get description of NAUO
1120 if ( enti->DynamicType() == tNAUO ) {
1122 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1123 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1124 if(NAUO.IsNull()) continue;
1125 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1126 for (subs.Start(); subs.More(); subs.Next()) {
1127 Handle(StepRepr_ProductDefinitionShape) PDS =
1128 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1129 if(PDS.IsNull()) continue;
1130 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1131 if ( PDR.IsNull() ) continue;
1132 if ( PDR->HasDescription() &&
1133 PDR->Description()->Length() >0 ) name = PDR->Description();
1134 else if ( !PDR->Name().IsNull() && PDR->Name()->Length() >0 ) name = PDR->Name();
1135 else if ( !PDR->Id().IsNull()) name = PDR->Id();
1136 else name = new TCollection_HAsciiString;
1138 // find proper label
1139 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1140 if ( L.IsNull() ) continue;
1141 TCollection_ExtendedString str ( name->String() );
1142 TDataStd_Name::Set ( L, str );
1145 // for PD get name of associated product
1146 if ( enti->DynamicType() == tPD ) {
1148 Handle(StepBasic_ProductDefinition) PD =
1149 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1150 if(PD.IsNull()) continue;
1151 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1153 name = new TCollection_HAsciiString;
1154 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1155 name = Prod->Name();
1156 else if (!Prod->Id().IsNull())
1159 name = new TCollection_HAsciiString;
1160 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1161 if ( L.IsNull() ) continue;
1162 TCollection_ExtendedString str ( name->String() );
1163 TDataStd_Name::Set ( L, str );
1165 // set a name to the document
1166 //TCollection_ExtendedString str ( name->String() );
1167 //TDataStd_Name::Set ( L, str );
1170 return Standard_True;
1173 //=======================================================================
1174 //function : GetLabelFromPD
1176 //=======================================================================
1178 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1179 const Handle(XCAFDoc_ShapeTool) &STool,
1180 const STEPConstruct_ValidationProps &Props,
1181 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1182 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1185 if ( PDFileMap.IsBound ( PD ) ) {
1186 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1187 if ( ! EF.IsNull() ) {
1189 if ( ! L.IsNull() ) return L;
1192 TopoDS_Shape S = Props.GetPropShape ( PD );
1193 if ( S.IsNull() ) return L;
1194 if ( ShapeLabelMap.IsBound ( S ) )
1195 L = ShapeLabelMap.Find ( S );
1197 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1201 //=======================================================================
1202 //function : ReadValProps
1204 //=======================================================================
1206 Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1207 Handle(TDocStd_Document)& Doc,
1208 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1209 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1211 // get starting data
1212 Handle(Interface_InterfaceModel) Model = WS->Model();
1213 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1214 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1215 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1216 if ( STool.IsNull() ) return Standard_False;
1218 // load props from the STEP model
1219 TColStd_SequenceOfTransient props;
1220 STEPConstruct_ValidationProps Props ( WS );
1221 if ( ! Props.LoadProps ( props ) ) {
1223 cout << "Warning: no validation props found in the model" << endl;
1225 return Standard_False;
1228 // interpret props one by one
1229 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1230 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1231 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1232 if ( PDR.IsNull() ) continue;
1236 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1237 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1238 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1239 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1240 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1241 if(PDS.IsNull()) continue;
1242 // find corresponding NAUO
1243 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1244 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1245 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1246 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1247 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1249 if ( !NAUO.IsNull() ) {
1250 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1251 if ( L.IsNull() ) continue;
1254 // find corresponding ProductDefinition:
1255 Handle(StepBasic_ProductDefinition) ProdDef;
1256 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1257 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1258 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1259 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1261 if ( ProdDef.IsNull() ) continue;
1262 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1266 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1267 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1268 if(SA.IsNull()) continue;
1269 // find ShapeRepresentation
1270 Handle(StepShape_ShapeRepresentation) SR;
1271 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1272 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1273 Handle(StepRepr_PropertyDefinition) PropD1 =
1274 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1275 if(PropD1.IsNull()) continue;
1276 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1277 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1278 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1279 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1280 if(SDR.IsNull()) continue;
1281 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1284 if(SR.IsNull()) continue;
1285 Handle(Transfer_Binder) binder;
1286 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1287 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1288 Handle(StepShape_SolidModel) SM =
1289 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1290 binder = TP->Find(SM);
1292 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1293 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1294 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1295 binder = TP->Find(SBSM);
1297 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1298 Handle(StepShape_GeometricSet) GS =
1299 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1300 binder = TP->Find(GS);
1303 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1305 S = TransferBRep::ShapeResult ( TP, binder );
1306 if(S.IsNull()) continue;
1307 if ( ShapeLabelMap.IsBound ( S ) )
1308 L = ShapeLabelMap.Find ( S );
1310 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1314 if(L.IsNull()) continue;
1316 // decode validation properties
1317 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1318 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1319 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1320 Standard_Boolean isArea;
1323 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1324 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1325 else XCAFDoc_Volume::Set ( L, val );
1327 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1328 XCAFDoc_Centroid::Set ( L, pos );
1332 return Standard_True;
1335 //=======================================================================
1336 //function : ReadLayers
1338 //=======================================================================
1340 Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1341 Handle(TDocStd_Document)& Doc) const
1343 Handle(Interface_InterfaceModel) Model = WS->Model();
1344 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1345 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1346 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1347 if ( STool.IsNull() ) return Standard_False;
1348 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1349 if ( LTool.IsNull() ) return Standard_False;
1351 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1352 Standard_Integer nb = Model->NbEntities();
1353 Handle(TCollection_HAsciiString) name;
1355 for (Standard_Integer i = 1; i <= nb; i ++) {
1356 Handle(Standard_Transient) enti = Model->Value(i);
1357 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1358 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1359 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1361 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1362 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1363 TCollection_ExtendedString aLayerName ( hName->String() );
1365 // find a target shape and its label in the document
1366 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1367 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1368 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1369 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1371 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1372 if ( S.IsNull() ) continue;
1375 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1376 LTool->SetLayer ( shL, aLayerName );
1379 // check invisibility
1380 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1381 for (subs.Start(); subs.More(); subs.Next()) {
1382 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1384 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1386 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1387 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1388 Handle(TDataStd_UAttribute) aUAttr;
1389 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1392 return Standard_True;
1395 //=======================================================================
1396 //function : ReadSHUOs
1398 //=======================================================================
1400 static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1401 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1402 const Handle(XCAFDoc_ShapeTool)& STool,
1403 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1404 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1405 TDF_LabelSequence& aLabels)
1407 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1408 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1409 for (subs.Start(); subs.More(); subs.Next()) {
1410 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1411 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1415 if (subSHUO.IsNull())
1416 return Standard_False;
1418 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1419 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
1420 if (NUNAUO.IsNull())
1421 return Standard_False;
1422 // Handle(Interface_InterfaceModel) Model = WS->Model();
1423 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1424 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1425 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1426 // if ( binder.IsNull() || ! binder->HasResult() )
1427 // return Standard_False;
1428 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1429 // get label of NAUO next level
1431 STEPConstruct_Tool Tool( WS );
1432 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1433 // STool->Search(NUSh, NUlab);
1435 return Standard_False;
1436 aLabels.Append( NULab );
1437 // and check by recurse.
1438 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1439 return Standard_True;
1443 //=======================================================================
1444 //function : setSHUOintoDoc
1445 //purpose : auxilary
1446 //=======================================================================
1447 static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1448 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1449 const Handle(XCAFDoc_ShapeTool)& STool,
1450 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1451 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1453 TDF_Label aMainLabel;
1454 // get upper usage NAUO from SHUO.
1455 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1456 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1457 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1458 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
1459 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1461 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1465 // Handle(Interface_InterfaceModel) Model = WS->Model();
1466 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1467 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1468 // TopoDS_Shape UUSh, NUSh;
1469 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1470 // if ( binder.IsNull() || ! binder->HasResult() )
1471 // return aMainLabel;
1472 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1473 // binder = TP->Find(NUNAUO);
1474 // if ( binder.IsNull() || ! binder->HasResult() )
1475 // return aMainLabel;
1476 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1478 // get first labels for first SHUO attribute
1479 TDF_Label UULab, NULab;
1480 STEPConstruct_Tool Tool( WS );
1481 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1482 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1484 // STool->Search(UUSh, UULab);
1485 // STool->Search(NUSh, NULab);
1486 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1487 //create sequence fo labels to set SHUO structure into the document
1488 TDF_LabelSequence ShuoLabels;
1489 ShuoLabels.Append( UULab );
1490 ShuoLabels.Append( NULab );
1491 // add all other labels of sub SHUO entities
1492 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1493 // last accord for SHUO
1494 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1495 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1496 aMainLabel = anSHUOAttr->Label();
1502 //=======================================================================
1503 //function : ReadSHUOs
1505 //=======================================================================
1507 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1508 Handle(TDocStd_Document)& Doc,
1509 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1510 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1512 // the big part code duplication from ReadColors.
1513 // It is possible to share this code functionality, just to decide how ???
1514 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1515 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1517 STEPConstruct_Styles Styles ( WS );
1518 if ( ! Styles.LoadStyles() ) {
1520 cout << "Warning: no styles are found in the model" << endl;
1522 return Standard_False;
1524 // searching for invisible items in the model
1525 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1526 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1527 // parse and search for color attributes
1528 Standard_Integer nb = Styles.NbStyles();
1529 for ( Standard_Integer i=1; i <= nb; i++ ) {
1530 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1531 if ( style.IsNull() ) continue;
1533 Standard_Boolean IsVisible = Standard_True;
1534 // check the visibility of styled item.
1535 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1536 if ( style != aHSeqOfInvisStyle->Value( si ) )
1538 // found that current style is invisible.
1540 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1542 IsVisible = Standard_False;
1546 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1547 // check if it is component style
1548 Standard_Boolean IsComponent = Standard_False;
1549 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1553 Handle(StepShape_ShapeRepresentation) aSR;
1554 findStyledSR( style, aSR );
1555 // search for SR along model
1558 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1559 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1560 for (subs.Start(); subs.More(); subs.Next()) {
1561 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1562 if ( aSDR.IsNull() )
1564 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1565 Handle(StepRepr_ProductDefinitionShape) PDS =
1566 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1569 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1570 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1571 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1572 if ( SHUO.IsNull() )
1575 // set the SHUO structure to the document
1576 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1577 if ( aLabelForStyle.IsNull() ) {
1579 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1583 // now set the style to the SHUO main label.
1584 if ( ! SurfCol.IsNull() ) {
1586 Styles.DecodeColor ( SurfCol, col );
1587 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1589 if ( ! BoundCol.IsNull() ) {
1591 Styles.DecodeColor ( BoundCol, col );
1592 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1594 if ( ! CurveCol.IsNull() ) {
1596 Styles.DecodeColor ( CurveCol, col );
1597 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1600 // sets the invisibility for shape.
1601 CTool->SetVisibility( aLabelForStyle, Standard_False );
1603 } // end search SHUO by SDR
1604 } // end iterates on styles
1606 return Standard_True;
1610 //=======================================================================
1611 //function : GetLengthConversionFactor
1613 //=======================================================================
1614 static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1615 Standard_Real& afact)
1618 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1619 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1620 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1621 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1622 afact = MWUCBU->ValueComponent();
1623 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1624 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1625 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1626 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1627 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1628 if(SU->Name()==StepBasic_sunMetre) {
1630 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1636 return Standard_True;
1640 //=======================================================================
1641 //function : GetAngleConversionFactor
1643 //=======================================================================
1644 static Standard_Boolean GetAngleConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1645 Standard_Real& afact)
1648 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)) ) return Standard_False;
1649 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit) CBULU =
1650 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)::DownCast(NU);
1651 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1652 afact = MWUCBU->ValueComponent();
1653 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1654 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1655 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1656 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1657 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1658 if(SU->Name()==StepBasic_sunRadian) {
1660 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1661 // convert radian to deg
1666 return Standard_True;
1669 //=======================================================================
1670 //function : GetMassConversionFactor
1672 //=======================================================================
1673 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1674 Standard_Real& afact)
1677 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1678 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1679 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1680 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1681 afact = MWUCBU->ValueComponent();
1682 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1683 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1684 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1685 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1686 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1687 if(SU->Name()==StepBasic_sunGram) {
1689 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1693 return Standard_True;
1697 //=======================================================================
1698 //function : ReadDatums
1699 //purpose : auxilary
1700 //=======================================================================
1701 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
1702 const Handle(XCAFDoc_DimTolTool) &DGTTool,
1703 const Interface_Graph &graph,
1704 Handle(Transfer_TransientProcess) &TP,
1705 const TDF_Label TolerL,
1706 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
1708 if(GTWDR.IsNull()) return Standard_False;
1709 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
1710 if(HADR.IsNull()) return Standard_False;
1711 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
1712 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
1713 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
1714 if(aDatum.IsNull()) continue;
1715 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
1716 for(subs4.Start(); subs4.More(); subs4.Next()) {
1717 Handle(StepRepr_ShapeAspectRelationship) SAR =
1718 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
1719 if(SAR.IsNull()) continue;
1720 Handle(StepDimTol_DatumFeature) DF =
1721 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
1722 if(DF.IsNull()) continue;
1723 Interface_EntityIterator subs5 = graph.Sharings(DF);
1724 Handle(StepRepr_PropertyDefinition) PropDef;
1725 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
1726 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
1728 if(PropDef.IsNull()) continue;
1729 Handle(StepShape_AdvancedFace) AF;
1730 subs5 = graph.Sharings(PropDef);
1731 for(subs5.Start(); subs5.More(); subs5.Next()) {
1732 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1733 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
1735 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1736 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1737 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
1738 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1742 if(AF.IsNull()) return Standard_False;
1743 Standard_Integer index = TP->MapIndex(AF);
1746 Handle(Transfer_Binder) binder = TP->MapItem(index);
1747 aSh = TransferBRep::ShapeResult(binder);
1749 if(aSh.IsNull()) continue;
1751 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1752 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
1755 return Standard_True;
1759 //=======================================================================
1760 //function : setDatumToXCAF
1762 //=======================================================================
1763 static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
1764 const TDF_Label theGDTL,
1765 const Standard_Integer thePositionCounter,
1766 const XCAFDimTolObjects_DatumModifiersSequence& aXCAFModifiers,
1767 const XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal,
1768 const Standard_Real aModifValue,
1769 const Handle(TDocStd_Document)& theDoc,
1770 const Handle(XSControl_WorkSession)& theWS)
1772 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
1773 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
1774 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
1775 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
1776 const Interface_Graph& aGraph = aTP->Graph();
1777 Handle(XCAFDoc_Datum) aDat;
1779 Standard_Boolean aRefShapeIsFound = Standard_False;
1780 Standard_Boolean aFirstStep = Standard_True;
1781 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
1782 for(anIterD.Start(); anIterD.More(); anIterD.Next()) {
1783 Handle(StepRepr_ShapeAspectRelationship) aSAR =
1784 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
1785 if(aSAR.IsNull()) continue;
1787 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatingShapeAspect();
1788 if (aSA.IsNull()) continue;
1789 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
1790 if(aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
1792 //processing for complex entity
1793 Interface_EntityIterator anIterC = aGraph.Sharings(aSA);
1794 for(anIterC.Start(); anIterC.More(); anIterC.Next()) {
1795 Handle(StepRepr_ShapeAspectRelationship) SAR =
1796 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterC.Value());
1797 if(SAR.IsNull()) continue;
1798 Handle(StepRepr_ShapeAspect) aS =
1799 Handle(StepRepr_ShapeAspect)::DownCast(SAR->RelatedShapeAspect());
1800 if(aS.IsNull()) continue;
1801 Interface_EntityIterator anIterSA = aGraph.Sharings(aS);
1802 for(anIterSA.Start(); anIterSA.More() && aPGISU.IsNull(); anIterSA.Next()) {
1803 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
1805 if(!aPGISU.IsNull()){
1811 else if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
1813 //processing for datum target
1814 Interface_EntityIterator anIterDTF = aGraph.Sharings(aSA);
1815 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1816 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_FeatureForDatumTargetRelationship)))
1818 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR =
1819 Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(anIterDTF.Value());
1820 Handle(StepRepr_ShapeAspect) aTmpSA = aFFDTR->RelatedShapeAspect();
1821 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aTmpSA);
1822 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
1823 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
1828 if (aSA.IsNull()) continue;
1829 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aSA);
1830 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
1831 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
1833 if(aPGISU.IsNull()) continue;
1834 // get representation item
1835 Handle(StepRepr_RepresentationItem) aRI;
1836 for(Standard_Integer i = 1 ; i <= aPGISU->NbIdentifiedItem() && aRI.IsNull(); i++)
1838 aRI = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(i));
1840 if(aRI.IsNull()) continue;
1841 Standard_Integer index = aTP->MapIndex(aRI);
1844 Handle(Transfer_Binder) binder = aTP->MapItem(index);
1845 aSh = TransferBRep::ShapeResult(binder);
1847 if(aSh.IsNull()) continue;
1848 if( !aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True) ) continue;
1849 Handle(TDataStd_TreeNode) aNode;
1850 if(aFirstStep && aShL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) && aNode->HasFirst() &&
1851 aNode->First()->Label().FindAttribute(XCAFDoc_Datum::GetID(),aDat))
1853 //if datums already attached, not need add datum target
1854 aRefShapeIsFound = Standard_True;
1856 aFirstStep = Standard_False;
1857 Handle(XCAFDimTolObjects_DatumObject) aDatObj;
1858 if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
1860 if(!aRefShapeIsFound)
1862 //if datum targers not yet added
1863 TDF_Label aDatL = aDGTTool->AddDatum();
1864 aDat = XCAFDoc_Datum::Set(aDatL);
1865 aDGTTool->SetDatum(aShL, aDatL);
1866 aDatObj = aDat->GetObject();
1867 aDatObj->SetName(theDat->Identification());
1868 aDatObj->SetPosition (thePositionCounter);
1869 if(!aXCAFModifiers.IsEmpty())
1870 aDatObj->SetModifiers(aXCAFModifiers);
1871 if (aXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
1872 aDatObj->SetModifierWithValue(aXCAFModifWithVal, aModifValue);
1873 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
1874 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSA);
1875 if (aPDTF->TargetId()->IsIntegerValue())
1876 aDatObj->SetDatumTargetNumber(aPDTF->TargetId()->IntegerValue());
1878 aDatObj->SetDatumTargetNumber(0);
1879 aDatObj->IsDatumTarget(Standard_True);
1880 XCAFDimTolObjects_DatumTargetType aType;
1881 if(STEPCAFControl_GDTProperty::GetDatumTargetType(aSA->Description(),aType))
1883 aDatObj->SetDatumTargetType(aType);
1884 if(aType == XCAFDimTolObjects_DatumTargetType_Area)
1886 Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
1887 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1888 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
1890 Handle(StepAP242_GeometricItemSpecificUsage) aGISU
1891 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
1892 Handle(StepRepr_RepresentationItem) anItem;
1893 if(aPGISU->NbIdentifiedItem() > 0) {
1894 anItem = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
1896 if(anItem.IsNull()) continue;
1897 Standard_Integer anItemIndex = aTP->MapIndex(anItem);
1898 if(anItemIndex >0) {
1899 Handle(Transfer_Binder) binder = aTP->MapItem(anItemIndex);
1900 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(binder);
1901 aDatObj->SetDatumTarget(anItemShape);
1908 Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
1909 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1910 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_PropertyDefinition)))
1912 Interface_EntityIterator anIterPD = aGraph.Shareds(anIterDTF.Value());
1913 for(anIterPD.Start(); anIterPD.More(); anIterPD.Next()) {
1914 if(anIterPD.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
1916 Interface_EntityIterator anIterSDR = aGraph.Sharings(anIterPD.Value());
1917 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next()) {
1918 if(anIterSDR.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentationWithParameters)))
1920 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
1921 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(anIterSDR.Value());
1922 for(Standard_Integer r = aSRWP->Items()->Lower(); r <= aSRWP->Items()->Upper(); r++)
1924 if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
1926 Handle(StepGeom_Axis2Placement3d) anAx
1927 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(r));
1928 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
1929 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
1930 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
1934 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
1935 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
1936 !aLocArr.IsNull() && aLocArr->Length() > 2)
1938 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
1939 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
1940 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
1941 gp_Ax2 anA(aPnt, aDir, aDirR);
1942 aDatObj->SetDatumTargetAxis(anA);
1945 else if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
1947 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
1948 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(r));
1949 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
1950 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
1951 Standard_Real aFact=1.;
1952 if(anUnit.IsNull()) continue;
1953 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1954 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1955 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
1956 if(aM->Name()->String().IsEqual("target length") ||
1957 aM->Name()->String().IsEqual("target diameter"))
1958 aDatObj->SetDatumTargetLength(aVal);
1960 aDatObj->SetDatumTargetWidth(aVal);
1975 //processing for darum feature
1976 TDF_Label aDatL = aDGTTool->AddDatum();
1977 aDat = XCAFDoc_Datum::Set(aDatL);
1978 aDGTTool->SetDatum(aShL, aDatL);
1979 aDatObj = aDat->GetObject();
1980 aDatObj->SetName(theDat->Identification());
1981 aDatObj->SetPosition (thePositionCounter);
1982 if(!aXCAFModifiers.IsEmpty())
1983 aDatObj->SetModifiers(aXCAFModifiers);
1984 if (aXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
1985 aDatObj->SetModifierWithValue(aXCAFModifWithVal, aModifValue);
1986 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
1988 if(!aDatObj.IsNull())
1989 aDat->SetObject(aDatObj);
1991 return !aDat.IsNull();
1995 //=======================================================================
1996 //function : ReadDatums
1997 //purpose : auxilary
1998 //=======================================================================
1999 static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2000 const TDF_Label theGDTL,
2001 const Handle(TDocStd_Document)& theDoc,
2002 const Handle(XSControl_WorkSession)& theWS)
2004 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2005 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2006 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2007 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2008 const Interface_Graph& aGraph = aTP->Graph();
2010 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2011 for(anIter.Start(); anIter.More(); anIter.Next()) {
2012 Handle(Standard_Transient) anAtr = anIter.Value();
2013 if(anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2015 Standard_Integer aPositionCounter = 0;//position on frame
2016 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2017 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2018 for(anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2019 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2020 if(anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2023 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2024 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2025 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2027 Handle(StepGeom_Axis2Placement3d) anAx
2028 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2029 Handle(XCAFDoc_GeomTolerance) aTol;
2030 if(theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2032 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2033 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2034 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2035 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2039 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2040 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2041 !aLocArr.IsNull() && aLocArr->Length() > 2)
2043 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
2044 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
2045 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
2046 gp_Ax2 anA(aPnt, aDir, aDirR);
2047 anObj->SetAxis(anA);
2048 aTol->SetObject(anObj);
2054 if (aDS->NbConstituents() > 0)
2056 //get datum feature and datum target from datum system
2057 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2060 for(Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2062 Handle(StepDimTol_DatumReferenceCompartment) aDRC
2063 = Handle(StepDimTol_DatumReferenceCompartment)::DownCast(aDRCA->Value(i));
2065 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2066 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2067 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2068 Standard_Real aModifValue = 0;
2069 if(!aModif.IsNull())
2071 for(Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2073 if(aModif->Value(m).CaseNumber() == 2)
2074 aXCAFModifiers.Append(
2075 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2076 SimpleDatumReferenceModifierMember()->Value());
2077 else if (aModif->Value(m).CaseNumber() == 1)
2079 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2080 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2081 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2082 Standard_Real aFact=1.;
2083 if(anUnit.IsNull()) continue;
2084 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2085 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2086 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2092 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2093 for(anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2095 if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2097 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2098 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2100 else if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2102 Handle(StepDimTol_DatumReferenceElement) aDRE
2103 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2104 //get modifiers from group of datums
2105 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2106 if(!aModifE.IsNull())
2108 for(Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2110 if(aModifE->Value(k).CaseNumber() == 1)
2111 aXCAFModifiers.Append(
2112 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2113 SimpleDatumReferenceModifierMember()->Value());
2114 else if (aModifE->Value(k).CaseNumber() == 2)
2116 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2117 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2118 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2119 Standard_Real aFact=1.;
2120 if(anUnit.IsNull()) continue;
2121 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2122 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2123 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2128 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2129 for(anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2130 if(anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2132 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2133 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2143 return Standard_True;
2146 //=======================================================================
2147 //function : craeteGeomTolObjectInXCAF
2149 //=======================================================================
2150 static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2151 const Handle(TDocStd_Document)& theDoc,
2152 const Handle(XSControl_WorkSession)& theWS)
2155 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2156 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2157 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2162 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2163 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2164 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2165 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2166 const Interface_Graph& aGraph = aTP->Graph();
2167 Standard_Boolean isAllAround = Standard_False;
2168 Standard_Boolean isAllOver = Standard_False;
2170 // find RepresentationItem for current Ent
2171 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2173 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2174 for(anIter.Start(); anIter.More(); anIter.Next()) {
2175 Handle(Standard_Transient) anAtr = anIter.Value();
2176 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2177 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2179 //if associating tolerances with part (All-Over)
2180 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2181 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2183 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2184 if(anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2186 isAllOver = Standard_True;
2187 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2188 for(anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2190 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2191 if(anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2193 aSeqRI1.Append(anAtrABSR);
2199 else if(anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2200 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2202 //if tolerance attached to dimension
2203 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2204 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2206 Handle(Standard_Transient) anAtrDim = anIterDim.Value();
2207 if(anAtrDim->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2208 anAtrDim->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
2210 Interface_EntityIterator anIterCSA = aGraph.Sharings(anAtrDim);
2211 for(anIterCSA.Start(); anIterCSA.More(); anIterCSA.Next()) {
2212 if (anIterCSA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2213 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterCSA.Value());
2214 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2215 if (anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))){
2216 aSAs.Append(Handle(StepRepr_ShapeAspect)::DownCast(anIterSAR.Value()));
2222 else if(anAtrDim->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2224 aSAs.Append( Handle(StepRepr_ShapeAspect)::DownCast(anAtrDim));
2228 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2229 anAtr->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
2231 //processing for composite entity
2232 Handle(Standard_Transient) anAtrTmp = anAtr;
2233 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2235 // if applyed AllAround Modifier
2236 isAllAround = Standard_True;
2237 Interface_EntityIterator anIterAASA = aGraph.Sharings(anAtrTmp);
2238 for(anIterAASA.Start(); anIterAASA.More(); anIterAASA.Next()) {
2239 if (anIterAASA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2240 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterAASA.Value());
2241 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2242 if ((anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2243 anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) &&
2244 anAtrTmp != anIterSAR.Value()){
2245 anAtrTmp = anIterSAR.Value();
2252 Interface_EntityIterator anIterCSA = aGraph.Sharings(anAtrTmp);
2253 for(anIterCSA.Start(); anIterCSA.More(); anIterCSA.Next()) {
2254 if (anIterCSA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2255 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterCSA.Value());
2256 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2257 if (anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))){
2258 aSAs.Append(Handle(StepRepr_ShapeAspect)::DownCast(anIterSAR.Value()));
2264 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2267 aSAs.Append( Handle(StepRepr_ShapeAspect)::DownCast(anAtr));
2271 //get representation items
2272 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2273 for(Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2275 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2276 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2277 Handle(StepRepr_PropertyDefinition) PropD;
2278 for(anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2279 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2280 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2282 if(!PropD.IsNull())//for old version
2284 Handle(StepRepr_RepresentationItem) RI;
2285 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2286 for(subs4.Start(); subs4.More(); subs4.Next()) {
2287 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2288 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2290 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2291 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2292 RI = Repr->ItemsValue(1);
2296 if(RI.IsNull()) continue;
2298 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2300 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2301 if(EC.IsNull()) continue;
2302 Handle(TCollection_HAsciiString) aName;
2303 Handle(StepShape_DimensionalSize) DimSize =
2304 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2305 Standard_Real dim1=-1.,dim2=-1.;
2306 subs4 = aGraph.Sharings(DimSize);
2307 for(subs4.Start(); subs4.More(); subs4.Next()) {
2308 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2309 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2310 if(!DimCharR.IsNull()) {
2311 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2312 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
2313 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2314 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
2317 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2318 //if(CID.IsNull()) continue;
2319 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2320 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2321 //if(CIDM.IsNull()) continue;
2322 //if(CIDM->ArrTransient().IsNull()) continue;
2323 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2324 //if(CID.CaseMem(CIDM)==1)
2325 // HARI = CID.ListRepresentationItem();
2326 //if(CID.CaseMem(CIDM)==2)
2327 // HARI = CID.SetRepresentationItem();
2328 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2329 if(HARI.IsNull()) continue;
2330 if(HARI->Length()>0) {
2331 Handle(StepRepr_RepresentationItem) RI1 =
2332 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
2333 if(RI1.IsNull()) continue;
2334 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2335 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2336 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2337 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2338 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2339 Standard_Real afact=1.;
2340 if(anUnit.IsNull()) continue;
2341 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2342 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2343 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
2346 if(HARI->Length()>1) {
2347 Handle(StepRepr_RepresentationItem) RI2 =
2348 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
2349 if(RI2.IsNull()) continue;
2350 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2351 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2352 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2353 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2354 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2355 Standard_Real afact=1.;
2356 if(anUnit.IsNull()) continue;
2357 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2358 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2359 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
2366 if(dim1<0) continue;
2367 if(dim2<0) dim2=dim1;
2368 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2369 // now we know edge_curve and value range therefore
2370 // we can create corresponding D> labels
2371 Standard_Integer index = aTP->MapIndex(EC);
2374 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2375 aSh = TransferBRep::ShapeResult(binder);
2377 if(aSh.IsNull()) continue;
2379 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2380 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
2381 arr->SetValue(1,dim1);
2382 arr->SetValue(2,dim2);
2383 aDGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
2385 // read tolerances and datums
2386 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2387 Handle(StepDimTol_GeometricTolerance) GT =
2388 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2389 // read common data for tolerance
2390 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2391 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2392 if(dim3.IsNull()) continue;
2393 Standard_Real dim = dim3->ValueComponent();
2394 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2395 Standard_Real afact=1.;
2396 if(anUnit.IsNull()) continue;
2397 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2398 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2399 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
2400 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
2401 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
2402 arr->SetValue(1,dim);
2403 Handle(TCollection_HAsciiString) aName = GT->Name();
2404 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2405 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2406 if(AF.IsNull()) continue;
2407 Standard_Integer index = aTP->MapIndex(AF);
2410 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2411 aSh = TransferBRep::ShapeResult(binder);
2413 if(aSh.IsNull()) continue;
2415 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2416 // read specific data for tolerance
2417 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2418 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2419 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2420 Standard_Integer kind=20;
2421 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2422 GTComplex->GetModifiedGeometricTolerance();
2424 kind = kind + MGT->Modifier()+1;
2426 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2427 // translate datums connected with this tolerance
2428 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2429 GTComplex->GetGeometricToleranceWithDatumReference();
2430 if(!GTWDR.IsNull()) {
2431 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2434 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2435 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2436 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2437 if(GTWDR.IsNull()) continue;
2438 Standard_Integer kind = 0;
2439 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2440 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2441 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2442 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
2443 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
2444 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
2445 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
2446 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
2447 //cout<<"GTWDR: kind="<<kind<<endl;
2448 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2449 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2451 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
2452 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2453 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
2454 Standard_Integer kind = 35 + MGT->Modifier();
2455 aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2457 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
2458 aDGTTool->SetDimTol(shL,38,arr,aName,aDescription);
2460 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
2461 aDGTTool->SetDimTol(shL,39,arr,aName,aDescription);
2463 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
2464 aDGTTool->SetDimTol(shL,40,arr,aName,aDescription);
2466 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
2467 aDGTTool->SetDimTol(shL,41,arr,aName,aDescription);
2469 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
2470 aDGTTool->SetDimTol(shL,42,arr,aName,aDescription);
2472 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
2473 aDGTTool->SetDimTol(shL,43,arr,aName,aDescription);
2475 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
2476 aDGTTool->SetDimTol(shL,44,arr,aName,aDescription);
2482 if(aGISU.IsNull()) continue;
2483 if(aGISU->NbIdentifiedItem() > 0) {
2484 aSeqRI.Append(aGISU->IdentifiedItemValue(1));
2488 if(!aSeqRI.IsEmpty())
2490 if(aSeqRI1.IsEmpty())
2497 if(aSeqRI1.IsEmpty()) return aGDTL;
2499 TDF_LabelSequence aShLS1, aShLS2;
2501 for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++)
2503 Standard_Integer anIndex = aTP->MapIndex(aSeqRI1.Value(i));
2506 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2507 aSh = TransferBRep::ShapeResult(aBinder);
2512 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2513 aShLS1.Append(aShL);
2516 if (!aSeqRI2.IsEmpty())
2518 //for dimensional location
2519 for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++)
2521 Standard_Integer anIndex = aTP->MapIndex(aSeqRI2.Value(i));
2524 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2525 aSh = TransferBRep::ShapeResult(aBinder);
2530 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2531 aShLS2.Append(aShL);
2536 if(!aShLS1.IsEmpty())
2539 if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2541 aGDTL = aDGTTool->AddDimension();
2542 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
2543 TCollection_AsciiString aStr("DGT:Dimensional_");
2544 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2546 aStr.AssignCat("Size");
2548 else if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
2550 aStr.AssignCat("Location");
2552 TDataStd_Name::Set(aGDTL, aStr);
2554 if(!aShLS2.IsEmpty())
2556 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
2560 TDF_LabelSequence aEmptySeq;
2561 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
2566 aGDTL = aDGTTool->AddGeomTolerance();
2567 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
2568 TCollection_AsciiString aStr("DGT:GeomTolerance");
2569 TDataStd_Name::Set(aGDTL, aStr);
2570 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
2571 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
2573 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
2575 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
2576 aGTol->SetObject(anObj);
2578 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
2583 //=======================================================================
2584 //function : setDimObjectToXCAF
2586 //=======================================================================
2587 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
2588 const TDF_Label& aDimL,
2589 const Handle(TDocStd_Document)& theDoc,
2590 const Handle(XSControl_WorkSession)& theWS)
2592 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2593 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2594 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2595 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2596 const Interface_Graph& aGraph = aTP->Graph();
2597 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
2598 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2599 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
2602 Handle(StepShape_DimensionalSize) aDimSize =
2603 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2604 Handle(StepShape_DimensionalLocation) aDimLocation =
2605 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2607 Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
2608 Handle(StepShape_TypeQualifier) aTQ;
2609 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
2610 Handle(StepShape_ToleranceValue) aTV;
2611 Handle(StepShape_LimitsAndFits) aLAF;
2612 Handle(StepRepr_CompoundRepresentationItem) aCRI;
2613 Handle(StepGeom_Axis2Placement3d) anAP;
2615 Interface_EntityIterator anIterDim;
2616 if(!aDimSize.IsNull())
2618 anIterDim = aGraph.Sharings(aDimSize);
2622 anIterDim = aGraph.Sharings(aDimLocation);
2624 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
2625 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
2626 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
2627 Handle(StepShape_PlusMinusTolerance) aPMT =
2628 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
2629 if(!aDCR.IsNull()) {
2630 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
2631 if(!aSDR.IsNull()) {
2632 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
2636 for(Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
2638 Handle(StepRepr_RepresentationItem) aDRI =
2639 Handle(StepRepr_RepresentationItem)::DownCast(aHARI->Value(nr));
2640 if(aDRI.IsNull()) continue;
2642 if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2644 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aRILMWU =
2645 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aDRI);
2646 Standard_Real aVal = aRILMWU->GetMeasureWithUnit()->ValueComponent();
2647 StepBasic_Unit anUnit = aRILMWU->GetMeasureWithUnit()->UnitComponent();
2648 Standard_Real aFact=1.;
2649 if(anUnit.IsNull()) continue;
2650 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2651 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2652 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2657 Standard_Real aTmp = aDim1;
2663 else if(aVal > aDim2)
2679 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
2681 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) aRIPAMWU =
2682 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit)::DownCast(aDRI);
2683 Standard_Real aVal = aRIPAMWU->GetMeasureWithUnit()->ValueComponent();
2684 StepBasic_Unit anUnit = aRIPAMWU->GetMeasureWithUnit()->UnitComponent();
2685 Standard_Real aFact=1.;
2686 if(anUnit.IsNull()) continue;
2687 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2688 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2689 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
2694 Standard_Real aTmp = aDim1;
2700 else if(aVal > aDim2)
2716 else if(aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
2718 Handle(StepShape_QualifiedRepresentationItem) aQRI =
2719 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
2720 for(Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
2722 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
2723 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
2726 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
2727 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
2729 else if(aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2731 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
2737 else if (!aPMT.IsNull())
2739 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
2740 if(aPMT.IsNull()) continue;
2741 if(aTMD.CaseNumber() == 1)
2742 //! 1 -> ToleranceValue from StepShape
2743 //! 2 -> LimitsAndFits from StepShape
2745 //plus minus tolerance
2746 aTV = aTMD.ToleranceValue();
2747 if (aTV.IsNull()) continue;
2749 Standard_Real aVal = aTV->UpperBound()->ValueComponent();
2750 StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
2751 Standard_Real aFact=1.;
2752 if(anUnit.IsNull()) continue;
2753 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2754 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2755 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2758 aVal = aTV->LowerBound()->ValueComponent();
2759 anUnit = aTV->LowerBound()->UnitComponent();
2761 if(anUnit.IsNull()) continue;
2762 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2763 NU = anUnit.NamedUnit();
2764 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2769 // calss of tolerance
2770 aLAF = aTMD.LimitsAndFits();
2777 aDimObj = new XCAFDimTolObjects_DimensionObject();
2779 aDimObj->SetValue(aDim1);
2782 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,2);
2783 anArr->SetValue(1,aDim1);
2784 anArr->SetValue(2,aDim2);
2785 aDimObj->SetValues(anArr);
2789 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,3);
2790 anArr->SetValue(1,aDim1);
2791 anArr->SetValue(2,aDim2);
2792 anArr->SetValue(3,aDim3);
2793 aDimObj->SetValues(anArr);
2797 XCAFDimTolObjects_DimensionQualifier aQ;
2798 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
2800 aDimObj->SetQualifier(aQ);
2804 if (!aVFTQ.IsNull())
2806 //A typical value would be
\91NR2 2.2
\92
2807 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
2808 Standard_Integer i = aFormat.Location(1,' ',1,aFormat.Length());
2809 aFormat.SubString(i+1,i+1)->IntegerValue();
2810 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i+1,i+1)->IntegerValue(),
2811 aFormat.SubString(i+3,i+3)->IntegerValue());
2816 //get class of tolerance
2817 Standard_Boolean aHolle = Standard_False;
2818 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
2819 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
2820 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
2821 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
2824 if (!aCRI.IsNull() && aCRI->ItemElement()->Length() > 0)
2827 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
2828 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
2829 if(aModifiers.Length() > 0)
2830 aDimObj->SetModifiers(aModifiers);
2833 Handle(TCollection_HAsciiString) aName;
2834 if(!aDimSize.IsNull())
2836 aName = aDimSize->Name();
2840 aName = aDimLocation->Name();
2842 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
2843 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
2845 if(!aDimSize.IsNull())
2847 Handle(StepShape_AngularSize) anAngSize=
2848 Handle(StepShape_AngularSize)::DownCast(aDimSize);
2849 if(!anAngSize.IsNull())
2851 //get qualifier for angular value
2852 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
2853 if(anAngSize->AngleSelection() == StepShape_Equal)
2854 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
2855 else if (anAngSize->AngleSelection() == StepShape_Large)
2856 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
2857 else if (anAngSize->AngleSelection() == StepShape_Small)
2858 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
2863 Handle(StepShape_AngularLocation) anAngLoc=
2864 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
2865 if(!anAngLoc.IsNull())
2867 //get qualifier for angular value
2868 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
2869 if(anAngLoc->AngleSelection() == StepShape_Equal)
2870 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
2871 else if (anAngLoc->AngleSelection() == StepShape_Large)
2872 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
2873 else if (anAngLoc->AngleSelection() == StepShape_Small)
2874 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
2877 if(aType == XCAFDimTolObjects_DimensionType_Location_None)
2879 Handle(StepRepr_ShapeAspect) aPSA;
2880 if(!aDimSize.IsNull())
2882 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath=
2883 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
2884 if (!aDimSizeWithPath.IsNull())
2886 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
2887 aPSA = aDimSizeWithPath->Path();
2892 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath=
2893 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
2894 if (!aDimLocWithPath.IsNull())
2896 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
2897 aPSA = aDimLocWithPath->Path();
2903 //for DimensionalLocationWithPath
2904 Handle(StepGeom_GeometricRepresentationItem) aGRI;
2905 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
2906 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
2907 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
2908 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
2910 if(aPGISU.IsNull()) return;
2911 if(aPGISU->NbIdentifiedItem() > 0) {
2912 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
2914 if(aGRI.IsNull()) return;
2915 Handle(StepRepr_RepresentationItem) aPRI;
2916 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
2917 for(anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
2918 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
2920 Standard_Integer anIndex = aTP->MapIndex(aPRI);
2923 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2924 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
2926 if(aSh.IsNull()) return;
2927 aDimObj->SetPath(aSh);
2929 else if(!anAP.IsNull())
2931 if(anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
2933 //for Oriented Dimensional Location
2934 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
2936 if(!aDirArr.IsNull() && aDirArr->Length() > 2)
2938 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
2939 aDimObj->SetDirection(aDir);
2941 else if(aDirArr->Length() > 1)
2943 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, 0);
2944 aDimObj->SetDirection(aDir);
2950 aDimObj->SetType(aType);
2952 if(!aDimObj.IsNull())
2954 Handle(XCAFDoc_Dimension) aDim;
2955 if(aDimL.FindAttribute(XCAFDoc_Dimension::GetID(),aDim))
2957 aDim->SetObject(aDimObj);
2962 //=======================================================================
2963 //function : getTolType
2965 //=======================================================================
2966 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
2967 XCAFDimTolObjects_GeomToleranceType& theType)
2969 if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2970 return Standard_False;
2971 theType = XCAFDimTolObjects_GeomToleranceType_None;
2972 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
2974 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
2975 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
2977 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
2979 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
2980 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
2981 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
2983 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
2985 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
2986 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
2987 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
2989 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
2991 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
2992 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
2993 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
2995 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
2997 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
2998 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
2999 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3001 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3003 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3004 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3005 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3007 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3009 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3011 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3013 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3015 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3017 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3019 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3021 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3023 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3025 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3027 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3029 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3031 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3033 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3035 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3037 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3039 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3041 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3043 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3044 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3046 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3048 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3050 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3052 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3054 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3056 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3058 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3060 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3062 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3064 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3066 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3068 return Standard_True;
3070 //=======================================================================
3071 //function : setGeomTolObjectToXCAF
3073 //=======================================================================
3074 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3075 const TDF_Label& theTolL,
3076 const Handle(TDocStd_Document)& theDoc,
3077 const Handle(XSControl_WorkSession)& theWS)
3079 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3080 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3081 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
3082 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
3083 const Interface_Graph& aGraph = aTP->Graph();
3084 Handle(XCAFDoc_GeomTolerance) aGTol;
3085 if(!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3089 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3090 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3092 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3093 getTolType(theEnt, aType);
3094 aTolObj->SetType(aType);
3095 if(!aTolEnt->Magnitude().IsNull()){
3097 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3098 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3099 Standard_Real aFact=1.;
3100 if(anUnit.IsNull()) return;
3101 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3102 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3103 if(GetLengthConversionFactor(NU,aFact))
3105 aTolObj->SetValue(aVal);
3108 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3109 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3110 for(anIter.Start(); anIter.More(); anIter.Next()) {
3111 if(anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))){
3112 Handle(StepDimTol_ToleranceZoneForm) aForm
3113 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3114 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3115 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3116 for(anIt.Start(); anIt.More(); anIt.Next()) {
3117 if(anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))){
3118 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3119 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3120 if(!aPZone->ProjectionLength().IsNull())
3122 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3123 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3124 Standard_Real aFact=1.;
3125 if(anUnit.IsNull()) return;
3126 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3127 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3128 if(GetLengthConversionFactor(NU,aFact))
3130 aTolObj->SetValueOfZoneModifier(aVal);
3131 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3134 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3136 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3137 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3138 if(!aRZone->Orientation().IsNull())
3140 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3141 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3142 Standard_Real aFact=1.;
3143 if(anUnit.IsNull()) continue;
3144 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3145 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3146 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
3147 aTolObj->SetValueOfZoneModifier(aVal);
3148 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
3152 aTolObj->SetTypeOfValue(aTypeV);
3155 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
3156 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
3158 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
3160 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3162 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
3163 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3165 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3167 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
3168 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3170 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3172 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
3173 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3175 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3177 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
3178 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3180 if(!aModifiers.IsNull())
3182 for(Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
3184 if(aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
3185 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
3186 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
3187 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
3189 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
3192 Standard_Real aVal = 0;
3193 StepBasic_Unit anUnit;
3194 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
3196 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
3197 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
3198 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
3200 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3202 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
3203 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3204 aVal = aMax->GetMaxTolerance()->ValueComponent();
3205 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3207 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3209 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
3210 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3211 aVal = aMax->GetMaxTolerance()->ValueComponent();
3212 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3214 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
3216 Standard_Real aFact=1.;
3217 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3218 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
3219 aTolObj->SetMaxValueModifier(aVal);
3222 aGTol->SetObject(aTolObj);
3225 //=======================================================================
3226 //function : ReadGDTs
3228 //=======================================================================
3230 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
3231 Handle(TDocStd_Document)& theDoc) const
3233 Handle(Interface_InterfaceModel) aModel = theWS->Model();
3234 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
3235 Interface_EntityIterator anI = aSM->Header();
3236 Handle(HeaderSection_FileSchema) aH;
3237 for(anI.Start(); anI.More() && aH.IsNull();anI.Next())
3238 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
3239 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3240 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
3241 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
3242 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3243 if ( aDGTTool.IsNull() ) return Standard_False;
3245 Standard_Integer nb = aModel->NbEntities();
3246 for(Standard_Integer i=1; i<=nb; i++) {
3247 Handle(Standard_Transient) anEnt = aModel->Value(i);
3248 if(anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3249 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3250 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3251 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt,theDoc,theWS);
3252 if(!aGDTL.IsNull()){
3253 if(anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))){
3254 setGeomTolObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3257 setDimObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3262 return Standard_True;
3266 //=======================================================================
3267 //function : FindSolidForPDS
3268 //purpose : auxilary
3269 //=======================================================================
3271 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
3272 const Interface_Graph &graph)
3274 Handle(StepShape_SolidModel) SM;
3275 Interface_EntityIterator subs = graph.Sharings(PDS);
3276 Handle(StepShape_ShapeRepresentation) SR;
3277 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
3278 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3279 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
3280 if(SDR.IsNull()) continue;
3281 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
3282 if(SR.IsNull()) continue;
3283 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
3284 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
3287 Interface_EntityIterator subs1 = graph.Sharings(SR);
3288 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
3289 Handle(StepRepr_RepresentationRelationship) RR =
3290 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
3291 if(RR.IsNull()) continue;
3292 Handle(StepShape_ShapeRepresentation) SR2;
3293 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
3294 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
3295 if(SR2.IsNull()) continue;
3296 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
3297 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
3306 //=======================================================================
3307 //function : ReadMaterials
3309 //=======================================================================
3311 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
3312 Handle(TDocStd_Document)& Doc,
3313 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
3315 Handle(Interface_InterfaceModel) Model = WS->Model();
3316 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
3317 Handle(XSControl_TransferReader) TR = WS->TransferReader();
3318 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
3319 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
3320 if(MatTool.IsNull()) return Standard_False;
3322 const Interface_Graph& graph = TP->Graph();
3323 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
3324 Handle(StepRepr_ProductDefinitionShape) PDS =
3325 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
3328 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
3329 if(aProdDef.IsNull())
3331 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
3332 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
3333 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
3334 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
3335 Standard_Real aDensity=0;
3336 Interface_EntityIterator subs = graph.Sharings( aProdDef);
3337 for(subs.Start(); subs.More(); subs.Next()) {
3338 Handle(StepRepr_PropertyDefinition) PropD =
3339 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
3340 if(PropD.IsNull()) continue;
3341 Interface_EntityIterator subs1 = graph.Sharings(PropD);
3342 for(subs1.Start(); subs1.More(); subs1.Next()) {
3343 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
3344 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
3345 if(PDR.IsNull()) continue;
3346 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
3347 if(Repr.IsNull()) continue;
3348 Standard_Integer ir;
3349 for(ir=1; ir<=Repr->NbItems(); ir++) {
3350 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
3351 if(RI.IsNull()) continue;
3352 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3353 // find name and description for material
3354 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
3355 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
3356 aName = DRI->Name();
3358 aDescription = DRI->Description();
3360 aName = aDescription;
3362 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
3363 // try to find density for material
3364 Handle(StepRepr_MeasureRepresentationItem) MRI =
3365 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
3366 aDensity = MRI->Measure()->ValueComponent();
3367 aDensName = MRI->Name();
3368 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
3369 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
3370 if(!aUnit.IsNull()) {
3371 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
3372 if(DU.IsNull()) continue;
3373 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
3374 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
3375 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
3376 Standard_Real afact=1.;
3377 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
3378 if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact);
3379 // transfer length value for Density from millimeter to santimeter
3380 // in order to result density has dimension gram/(sm*sm*sm)
3381 aDensity = aDensity*1000.;
3383 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
3384 if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact;
3393 if( aName.IsNull() || aName->Length()==0 )
3395 // find shape label amd create Material link
3397 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
3399 Standard_Integer index = TP->MapIndex(SM);
3401 Handle(Transfer_Binder) binder = TP->MapItem(index);
3402 if(!binder.IsNull())
3403 aSh = TransferBRep::ShapeResult(binder);
3406 if(aSh.IsNull()) continue;
3408 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
3409 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
3412 return Standard_True;
3415 //=======================================================================
3416 //function : SettleShapeData
3418 //=======================================================================
3420 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
3422 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
3423 const Handle(Transfer_TransientProcess)& TP) const
3425 TDF_Label aResult = theLab;
3427 Handle(TCollection_HAsciiString) hName = theItem->Name();
3428 if ( hName.IsNull() || hName->IsEmpty() )
3431 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
3432 if ( aBinder.IsNull() )
3435 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
3436 if ( aShape.IsNull() )
3439 // Allocate sub-Label
3440 aResult = AllocateSubLabel(theLab);
3442 TCollection_AsciiString aName = hName->String();
3443 TDataStd_Name::Set(aResult, aName);
3444 theShapeTool->SetShape(aResult, aShape);
3449 //=======================================================================
3450 //function : ExpandSubShapes
3452 //=======================================================================
3454 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
3455 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
3456 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
3458 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
3459 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
3460 TColStd_MapOfTransient aRepItems;
3462 // Read translation control variables
3463 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
3465 if ( !doReadSNames )
3468 const Interface_Graph& Graph = Reader().WS()->Graph();
3470 for ( STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next() )
3472 const TopoDS_Shape& aRootShape = it.Key();
3473 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
3474 if ( aPDef.IsNull() )
3477 // Find SDR by Product
3478 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3479 Interface_EntityIterator entIt = Graph.TypedSharings( aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation) );
3480 for ( entIt.Start(); entIt.More(); entIt.Next() )
3482 const Handle(Standard_Transient)& aReferer = entIt.Value();
3483 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
3484 if ( !aSDR.IsNull() )
3488 if ( aSDR.IsNull() )
3491 // Access shape representation
3492 Handle(StepShape_ShapeRepresentation)
3493 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast( aSDR->UsedRepresentation() );
3495 if ( aShapeRepr.IsNull() )
3498 // Access representation items
3499 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aShapeRepr->Items();
3501 if ( aReprItems.IsNull() )
3504 if ( !ShapeLabelMap.IsBound(aRootShape) )
3507 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
3509 StepRepr_SequenceOfRepresentationItem aMSBSeq;
3510 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
3512 // Iterate over the top level representation items collecting the
3513 // topological containers to expand
3514 for ( Standard_Integer i = aReprItems->Lower(); i <= aReprItems->Upper(); ++i )
3516 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems->Value(i);
3517 if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
3518 aMSBSeq.Append(aTRepr);
3519 else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) )
3520 aSBSMSeq.Append(aTRepr);
3523 // Insert intermediate OCAF Labels for SOLIDs in case there are more
3524 // than one Manifold Solid BRep in the Shape Representation
3525 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
3527 // Expand Manifold Solid BReps
3528 for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i )
3530 const Handle(StepRepr_RepresentationItem)& aManiRepr = aMSBSeq.Value(i);
3532 // Put additional Label for SOLID
3534 if ( doInsertSolidLab )
3535 aManiLab = SettleShapeData(aManiRepr, aRootLab, ShapeTool, TP);
3537 aManiLab = aRootLab;
3539 ExpandManifoldSolidBrep(aManiLab, aMSBSeq.Value(i), TP, ShapeTool);
3542 // Expand Shell-Based Surface Models
3543 for ( Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i )
3544 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
3548 //=======================================================================
3549 //function : ExpandManifoldSolidBrep
3551 //=======================================================================
3553 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
3554 const Handle(StepRepr_RepresentationItem)& Repr,
3555 const Handle(Transfer_TransientProcess)& TP,
3556 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
3558 // Access outer shell
3559 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
3560 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
3562 // Expand shell contents to CAF tree
3563 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
3566 //=======================================================================
3567 //function : ExpandSBSM
3569 //=======================================================================
3571 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
3572 const Handle(StepRepr_RepresentationItem)& Repr,
3573 const Handle(Transfer_TransientProcess)& TP,
3574 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
3576 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
3578 // Access boundary shells
3579 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
3580 for ( Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s )
3582 const StepShape_Shell& aShell = aShells->Value(s);
3583 Handle(StepShape_ConnectedFaceSet) aCFS;
3584 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
3585 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
3587 if ( !anOpenShell.IsNull() )
3590 aCFS = aClosedShell;
3592 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
3596 //=======================================================================
3597 //function : ExpandShell
3599 //=======================================================================
3601 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
3603 const Handle(Transfer_TransientProcess)& TP,
3604 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
3607 TDF_Label aShellLab = SettleShapeData(Shell, RootLab, ShapeTool, TP);
3610 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
3611 for ( Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f )
3613 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
3616 TDF_Label aFaceLab = SettleShapeData(aFace, aShellLab, ShapeTool, TP);
3618 // Access face bounds
3619 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
3620 for ( Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w )
3622 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
3625 TDF_Label aWireLab = SettleShapeData(aWire, aFaceLab, ShapeTool, TP);
3627 // Access wire edges
3628 // Currently only EDGE LOOPs are considered (!)
3629 if ( !aWire->IsInstance( STANDARD_TYPE(StepShape_EdgeLoop) ) )
3633 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
3634 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
3635 for ( Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e )
3637 Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement();
3640 TDF_Label anEdgeLab = SettleShapeData(anEdge, aWireLab, ShapeTool, TP);
3643 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
3644 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
3647 SettleShapeData(aV1, anEdgeLab, ShapeTool, TP);
3648 SettleShapeData(aV2, anEdgeLab, ShapeTool, TP);
3654 //=======================================================================
3655 //function : SetColorMode
3657 //=======================================================================
3659 void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
3661 myColorMode = colormode;
3664 //=======================================================================
3665 //function : GetColorMode
3667 //=======================================================================
3669 Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
3674 //=======================================================================
3675 //function : SetNameMode
3677 //=======================================================================
3679 void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
3681 myNameMode = namemode;
3684 //=======================================================================
3685 //function : GetNameMode
3687 //=======================================================================
3689 Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
3694 //=======================================================================
3695 //function : SetLayerMode
3697 //=======================================================================
3699 void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
3701 myLayerMode = layermode;
3704 //=======================================================================
3705 //function : GetLayerMode
3707 //=======================================================================
3709 Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
3714 //=======================================================================
3715 //function : SetPropsMode
3717 //=======================================================================
3719 void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
3721 myPropsMode = propsmode;
3724 //=======================================================================
3725 //function : GetPropsMode
3727 //=======================================================================
3729 Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
3734 //=======================================================================
3735 //function : SetSHUOMode
3737 //=======================================================================
3739 void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
3744 //=======================================================================
3745 //function : GetSHUOMode
3747 //=======================================================================
3749 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
3754 //=======================================================================
3755 //function : SetGDTMode
3757 //=======================================================================
3759 void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
3761 myGDTMode = gdtmode;
3764 //=======================================================================
3765 //function : GetGDTMode
3767 //=======================================================================
3769 Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
3775 //=======================================================================
3776 //function : SetMatMode
3778 //=======================================================================
3780 void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
3782 myMatMode = matmode;
3785 //=======================================================================
3786 //function : GetMatMode
3788 //=======================================================================
3790 Standard_Boolean STEPCAFControl_Reader::GetMatMode () const