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 <Geom_Axis2Placement.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Interface_EntityIterator.hxx>
22 #include <Interface_InterfaceModel.hxx>
23 #include <StepData_StepModel.hxx>
24 #include <HeaderSection_FileSchema.hxx>
25 #include <Interface_Static.hxx>
26 #include <NCollection_DataMap.hxx>
27 #include <OSD_Path.hxx>
28 #include <Quantity_Color.hxx>
29 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
30 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
31 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
32 #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
33 #include <StepBasic_DerivedUnit.hxx>
34 #include <StepBasic_DerivedUnitElement.hxx>
35 #include <StepBasic_MeasureValueMember.hxx>
36 #include <StepBasic_MeasureWithUnit.hxx>
37 #include <StepBasic_NamedUnit.hxx>
38 #include <StepBasic_Product.hxx>
39 #include <StepBasic_ProductDefinition.hxx>
40 #include <StepBasic_ProductDefinitionFormation.hxx>
41 #include <StepBasic_ProductDefinitionRelationship.hxx>
42 #include <StepBasic_SiUnit.hxx>
43 #include <StepBasic_SiUnitAndLengthUnit.hxx>
44 #include <StepBasic_Unit.hxx>
45 #include <STEPCAFControl_Controller.hxx>
46 #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
47 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
48 #include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
49 #include <STEPCAFControl_DataMapOfShapePD.hxx>
50 #include <STEPCAFControl_ExternFile.hxx>
51 #include <STEPCAFControl_Reader.hxx>
52 #include <STEPConstruct.hxx>
53 #include <STEPConstruct_Assembly.hxx>
54 #include <STEPConstruct_ExternRefs.hxx>
55 #include <STEPConstruct_Styles.hxx>
56 #include <STEPConstruct_Tool.hxx>
57 #include <STEPConstruct_UnitContext.hxx>
58 #include <STEPConstruct_ValidationProps.hxx>
59 #include <STEPControl_Reader.hxx>
60 #include <StepGeom_GeometricRepresentationItem.hxx>
61 #include <StepGeom_Axis2Placement3d.hxx>
62 #include <StepGeom_Direction.hxx>
63 #include <StepDimTol_AngularityTolerance.hxx>
64 #include <StepDimTol_CircularRunoutTolerance.hxx>
65 #include <StepDimTol_CoaxialityTolerance.hxx>
66 #include <StepDimTol_ConcentricityTolerance.hxx>
67 #include <StepDimTol_CylindricityTolerance.hxx>
68 #include <StepDimTol_Datum.hxx>
69 #include <StepDimTol_DatumFeature.hxx>
70 #include <StepDimTol_DatumReference.hxx>
71 #include <StepDimTol_DatumReferenceElement.hxx>
72 #include <StepDimTol_DatumReferenceCompartment.hxx>
73 #include <StepDimTol_DatumSystem.hxx>
74 #include <StepDimTol_FlatnessTolerance.hxx>
75 #include <StepDimTol_GeometricTolerance.hxx>
76 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
77 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
78 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
79 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
80 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
81 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
82 #include <StepDimTol_HArray1OfDatumReference.hxx>
83 #include <StepDimTol_LineProfileTolerance.hxx>
84 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
85 #include <StepDimTol_ParallelismTolerance.hxx>
86 #include <StepDimTol_PerpendicularityTolerance.hxx>
87 #include <StepDimTol_PositionTolerance.hxx>
88 #include <StepDimTol_ProjectedZoneDefinition.hxx>
89 #include <StepDimTol_RoundnessTolerance.hxx>
90 #include <StepDimTol_RunoutZoneDefinition.hxx>
91 #include <StepDimTol_StraightnessTolerance.hxx>
92 #include <StepDimTol_SurfaceProfileTolerance.hxx>
93 #include <StepDimTol_SymmetryTolerance.hxx>
94 #include <StepDimTol_ToleranceZone.hxx>
95 #include <StepDimTol_ToleranceZoneForm.hxx>
96 #include <StepDimTol_TotalRunoutTolerance.hxx>
97 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
98 #include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
99 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
100 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
101 #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
102 #include <StepGeom_Axis2Placement3d.hxx>
103 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
104 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
105 #include <StepGeom_Plane.hxx>
106 #include <StepGeom_Polyline.hxx>
107 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
108 #include <StepRepr_AssemblyComponentUsage.hxx>
109 #include <StepRepr_CharacterizedDefinition.hxx>
110 #include <StepRepr_CompoundRepresentationItem.hxx>
111 #include <StepRepr_DerivedShapeAspect.hxx>
112 #include <StepRepr_DescriptiveRepresentationItem.hxx>
113 #include <StepRepr_HArray1OfRepresentationItem.hxx>
114 #include <StepRepr_MappedItem.hxx>
115 #include <StepRepr_MeasureRepresentationItem.hxx>
116 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
117 #include <StepRepr_ProductDefinitionShape.hxx>
118 #include <StepRepr_PropertyDefinition.hxx>
119 #include <StepRepr_PropertyDefinitionRepresentation.hxx>
120 #include <StepRepr_Representation.hxx>
121 #include <StepRepr_RepresentationItem.hxx>
122 #include <StepRepr_HArray1OfRepresentationItem.hxx>
123 #include <StepRepr_RepresentationMap.hxx>
124 #include <StepRepr_RepresentationRelationship.hxx>
125 #include <StepRepr_RepresentedDefinition.hxx>
126 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
127 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
128 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
129 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
130 #include <StepRepr_SequenceOfRepresentationItem.hxx>
131 #include <StepRepr_ShapeAspect.hxx>
132 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
133 #include <StepRepr_CompositeShapeAspect.hxx>
134 #include <StepRepr_AllAroundShapeAspect.hxx>
135 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
136 #include <StepRepr_ShapeAspectRelationship.hxx>
137 #include <StepRepr_ShapeRepresentationRelationship.hxx>
138 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
139 #include <StepRepr_ValueRange.hxx>
140 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
141 #include <StepShape_AdvancedFace.hxx>
142 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
143 #include <StepShape_AngleRelator.hxx>
144 #include <StepShape_AngularSize.hxx>
145 #include <StepShape_AngularLocation.hxx>
146 #include <StepShape_ClosedShell.hxx>
147 #include <StepShape_ConnectedFaceSet.hxx>
148 #include <StepShape_ContextDependentShapeRepresentation.hxx>
149 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
150 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
151 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
152 #include <StepShape_DimensionalSizeWithPath.hxx>
153 #include <StepShape_DimensionalLocationWithPath.hxx>
154 #include <StepShape_ShapeDimensionRepresentationItem.hxx>
155 #include <StepShape_ShapeRepresentationWithParameters.hxx>
156 #include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
157 #include <StepShape_DimensionalSize.hxx>
158 #include <StepShape_DimensionalLocation.hxx>
159 #include <StepShape_EdgeCurve.hxx>
160 #include <StepShape_EdgeLoop.hxx>
161 #include <StepShape_GeometricCurveSet.hxx>
162 #include <StepShape_GeometricSet.hxx>
163 #include <StepShape_HArray1OfFace.hxx>
164 #include <StepShape_HArray1OfFaceBound.hxx>
165 #include <StepShape_HArray1OfOrientedEdge.hxx>
166 #include <StepShape_HArray1OfShell.hxx>
167 #include <StepShape_LimitsAndFits.hxx>
168 #include <StepShape_Loop.hxx>
169 #include <StepShape_ManifoldSolidBrep.hxx>
170 #include <StepShape_PlusMinusTolerance.hxx>
171 #include <StepShape_QualifiedRepresentationItem.hxx>
172 #include <StepShape_OpenShell.hxx>
173 #include <StepShape_ShapeDefinitionRepresentation.hxx>
174 #include <StepShape_ShapeDimensionRepresentation.hxx>
175 #include <StepShape_ShapeRepresentation.hxx>
176 #include <StepShape_ShellBasedSurfaceModel.hxx>
177 #include <StepShape_SolidModel.hxx>
178 #include <StepShape_ToleranceMethodDefinition.hxx>
179 #include <StepShape_ToleranceValue.hxx>
180 #include <StepShape_ValueFormatTypeQualifier.hxx>
181 #include <StepShape_Vertex.hxx>
182 #include <StepToGeom.hxx>
183 #include <StepVisual_AnnotationCurveOccurrence.hxx>
184 #include <StepVisual_AnnotationFillArea.hxx>
185 #include <StepVisual_AnnotationPlane.hxx>
186 #include <StepVisual_CameraModelD3.hxx>
187 #include <StepVisual_CameraModelD3MultiClipping.hxx>
188 #include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
189 #include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
190 #include <StepVisual_CoordinatesList.hxx>
191 #include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
192 #include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
193 #include <StepVisual_DraughtingCallout.hxx>
194 #include <StepVisual_DraughtingCalloutElement.hxx>
195 #include <StepVisual_DraughtingModel.hxx>
196 #include <StepVisual_Invisibility.hxx>
197 #include <StepVisual_LayeredItem.hxx>
198 #include <StepVisual_PlanarBox.hxx>
199 #include <StepVisual_PresentationLayerAssignment.hxx>
200 #include <StepVisual_PresentationStyleByContext.hxx>
201 #include <StepVisual_StyleContextSelect.hxx>
202 #include <StepVisual_StyledItem.hxx>
203 #include <StepVisual_ViewVolume.hxx>
204 #include <StepShape_TypeQualifier.hxx>
205 #include <TCollection_AsciiString.hxx>
206 #include <TCollection_HAsciiString.hxx>
207 #include <TColStd_HArray1OfReal.hxx>
208 #include <TColStd_HArray1OfTransient.hxx>
209 #include <TColStd_HSequenceOfTransient.hxx>
210 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
211 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
212 #include <TColStd_MapOfTransient.hxx>
213 #include <TColStd_SequenceOfHAsciiString.hxx>
214 #include <TDataStd_Name.hxx>
215 #include <TDataStd_TreeNode.hxx>
216 #include <TDataStd_UAttribute.hxx>
217 #include <TDF_Label.hxx>
218 #include <TDF_Tool.hxx>
219 #include <TDocStd_Document.hxx>
220 #include <TNaming_NamedShape.hxx>
221 #include <TopExp_Explorer.hxx>
222 #include <TopoDS.hxx>
223 #include <TopoDS_Compound.hxx>
224 #include <TopoDS_Iterator.hxx>
225 #include <TopoDS_Shape.hxx>
226 #include <TopTools_ListIteratorOfListOfShape.hxx>
227 #include <TopTools_ListOfShape.hxx>
228 #include <TopTools_MapOfShape.hxx>
229 #include <Transfer_Binder.hxx>
230 #include <Transfer_TransientProcess.hxx>
231 #include <TransferBRep.hxx>
232 #include <XCAFDoc.hxx>
233 #include <XCAFDoc_Area.hxx>
234 #include <XCAFDoc_Centroid.hxx>
235 #include <XCAFDoc_ClippingPlaneTool.hxx>
236 #include <XCAFDoc_ColorTool.hxx>
237 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
238 #include <XCAFDoc_DimTolTool.hxx>
239 #include <XCAFDoc_Dimension.hxx>
240 #include <XCAFDoc_Datum.hxx>
241 #include <XCAFDoc_GeomTolerance.hxx>
242 #include <XCAFDoc_DocumentTool.hxx>
243 #include <XCAFDoc_GraphNode.hxx>
244 #include <XCAFDoc_LayerTool.hxx>
245 #include <XCAFDoc_MaterialTool.hxx>
246 #include <XCAFDoc_ShapeTool.hxx>
247 #include <XCAFDoc_View.hxx>
248 #include <XCAFDoc_ViewTool.hxx>
249 #include <XCAFDoc_Volume.hxx>
250 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
251 #include <XCAFDimTolObjects_GeomToleranceType.hxx>
252 #include <XCAFDimTolObjects_DimensionObject.hxx>
253 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
254 #include <XCAFDimTolObjects_DatumObject.hxx>
255 #include <XCAFView_Object.hxx>
256 #include <XSControl_TransferReader.hxx>
257 #include <XSControl_WorkSession.hxx>
258 #include <StepAP242_DraughtingModelItemAssociation.hxx>
259 #include <StepAP242_GeometricItemSpecificUsage.hxx>
260 #include <StepGeom_CartesianPoint.hxx>
261 #include <STEPCAFControl_GDTProperty.hxx>
262 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
263 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
264 #include <StepVisual_TessellatedItem.hxx>
265 #include <StepVisual_TessellatedGeometricSet.hxx>
266 #include <StepVisual_TessellatedCurveSet.hxx>
267 #include <StepVisual_CoordinatesList.hxx>
268 #include <NCollection_Vector.hxx>
270 #include <TColgp_HArray1OfXYZ.hxx>
271 #include <BRepBuilderAPI_MakeEdge.hxx>
272 #include <BRepTools.hxx>
273 #include <Transfer_ActorOfTransientProcess.hxx>
274 #include <Bnd_Box.hxx>
275 #include <BRepBndLib.hxx>
277 // skl 21.08.2003 for reading G&DT
278 //#include <StepRepr_CompoundItemDefinition.hxx>
279 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
280 //#include <StepBasic_ConversionBasedUnit.hxx>
281 //#include <TDataStd_Real.hxx>
282 //#include <TDataStd_Constraint.hxx>
283 //#include <TDataStd_ConstraintEnum.hxx>
284 //#include <TNaming_Tool.hxx>
285 //#include <AIS_InteractiveObject.hxx>
286 //#include <TPrsStd_ConstraintTools.hxx>
287 //#include <AIS_DiameterDimension.hxx>
288 //#include <TPrsStd_Position.hxx>
289 //#include <TPrsStd_AISPresentation.hxx>
290 //#include <TNaming_Builder.hxx>
292 //! Converts address of the passed shape (TShape) to string.
293 //! \param theShape [in] Shape to dump.
294 //! \return corresponding string.
295 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
297 std::string anAddrStr;
298 std::ostringstream ost;
299 ost << theShape.TShape().get();
300 anAddrStr = ost.str();
302 TCollection_AsciiString aStr =
303 TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]");
309 //=======================================================================
310 //function : STEPCAFControl_Reader
312 //=======================================================================
314 STEPCAFControl_Reader::STEPCAFControl_Reader ():
315 myColorMode( Standard_True ),
316 myNameMode ( Standard_True ),
317 myLayerMode( Standard_True ),
318 myPropsMode( Standard_True ),
319 mySHUOMode ( Standard_False ),
320 myGDTMode ( Standard_True ),
321 myMatMode(Standard_True),
322 myViewMode(Standard_True)
324 STEPCAFControl_Controller::Init();
328 //=======================================================================
329 //function : STEPCAFControl_Reader
331 //=======================================================================
333 STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
334 const Standard_Boolean scratch) :
335 myColorMode( Standard_True ),
336 myNameMode ( Standard_True ),
337 myLayerMode( Standard_True ),
338 myPropsMode( Standard_True ),
339 mySHUOMode ( Standard_False ),
340 myGDTMode ( Standard_True ),
341 myMatMode(Standard_True),
342 myViewMode(Standard_True)
344 STEPCAFControl_Controller::Init();
345 Init ( WS, scratch );
349 //=======================================================================
352 //=======================================================================
354 void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
355 const Standard_Boolean scratch)
357 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
358 myReader.SetWS (WS,scratch);
363 //=======================================================================
364 //function : ReadFile
366 //=======================================================================
368 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
370 return myReader.ReadFile ( filename );
374 //=======================================================================
375 //function : NbRootsForTransfer
377 //=======================================================================
379 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
381 return myReader.NbRootsForTransfer();
385 //=======================================================================
386 //function : TransferOneRoot
388 //=======================================================================
390 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
391 Handle(TDocStd_Document) &doc)
393 TDF_LabelSequence Lseq;
394 return Transfer ( myReader, num, doc, Lseq );
398 //=======================================================================
399 //function : Transfer
401 //=======================================================================
403 Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
405 TDF_LabelSequence Lseq;
406 return Transfer ( myReader, 0, doc, Lseq );
410 //=======================================================================
413 //=======================================================================
415 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
416 Handle(TDocStd_Document) &doc)
418 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
419 return Transfer ( doc );
423 //=======================================================================
426 //=======================================================================
428 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
429 Handle(TDocStd_Document) &doc)
431 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
432 return Transfer ( doc );
436 //=======================================================================
437 //function : ExternFiles
439 //=======================================================================
441 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles () const
447 //=======================================================================
448 //function : ExternFile
450 //=======================================================================
452 Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
453 Handle(STEPCAFControl_ExternFile) &ef) const
456 if ( myFiles.IsEmpty() || !myFiles.IsBound ( name ) )
457 return Standard_False;
458 ef = myFiles.Find ( name );
459 return Standard_True;
463 //=======================================================================
466 //=======================================================================
468 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
474 //=======================================================================
477 //=======================================================================
479 const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
485 //=======================================================================
486 //function : FillShapesMap
487 //purpose : auxiliary: fill a map by all compounds and their components
488 //=======================================================================
490 static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
496 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
497 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
498 FillShapesMap ( it.Value(), map );
502 //=======================================================================
503 //function : Transfer
504 //purpose : basic working method
505 //=======================================================================
507 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
508 const Standard_Integer nroot,
509 Handle(TDocStd_Document) &doc,
510 TDF_LabelSequence &Lseq,
511 const Standard_Boolean asOne)
513 reader.ClearShapes();
517 Standard_Integer num = reader.NbRootsForTransfer();
518 if ( num <=0 ) return Standard_False;
520 if ( nroot > num ) return Standard_False;
521 reader.TransferOneRoot ( nroot );
524 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
526 num = reader.NbShapes();
527 if ( num <=0 ) return Standard_False;
529 // Fill a map of (top-level) shapes resulting from that transfer
530 // Only these shapes will be considered further
531 TopTools_MapOfShape ShapesMap, NewShapesMap;
532 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
534 // Collect information on shapes originating from SDRs
535 // this will be used to distinguish compounds representing assemblies
536 // from the ones representing hybrid models and shape sets
537 STEPCAFControl_DataMapOfShapePD ShapePDMap;
538 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
539 Handle(Interface_InterfaceModel) Model = reader.Model();
540 const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
541 Standard_Integer nb = Model->NbEntities();
543 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
545 for (i = 1; i <= nb; i ++) {
546 Handle(Standard_Transient) enti = Model->Value(i);
547 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
548 // sequence for acceleration ReadMaterials
549 SeqPDS->Append(enti);
551 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
552 Handle(StepBasic_ProductDefinition) PD =
553 Handle(StepBasic_ProductDefinition)::DownCast(enti);
554 Standard_Integer index = TP->MapIndex(PD);
556 Handle(Transfer_Binder) binder = TP->MapItem (index);
557 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
558 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
560 ShapePDMap.Bind ( S, PD );
561 Handle(STEPCAFControl_ExternFile) EF;
562 PDFileMap.Bind ( PD, EF );
566 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
567 Standard_Integer index = TP->MapIndex(enti);
569 Handle(Transfer_Binder) binder = TP->MapItem (index);
570 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
571 if ( ! S.IsNull() && ShapesMap.Contains(S) )
577 // get directory name of the main file
578 OSD_Path mainfile ( reader.WS()->LoadedFile() );
579 mainfile.SetName ( "" );
580 mainfile.SetExtension ( "" );
581 TCollection_AsciiString dpath;
582 mainfile.SystemName ( dpath );
584 // Load external references (only for relevant SDRs)
585 // and fill map SDR -> extern file
586 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
587 ExtRefs.LoadExternRefs();
588 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
589 // check extern ref format
590 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
591 if ( ! format.IsNull() ) {
592 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
593 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
594 if ( ! format->IsSameString ( ap203, Standard_False ) &&
595 ! format->IsSameString ( ap214, Standard_False ) ) {
597 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
604 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
607 // get and check filename of the current extern ref
608 const Standard_CString filename = ExtRefs.FileName(i);
611 cout<<"filename="<<filename<<endl;
614 if ( ! filename || ! filename[0] ) {
616 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
618 continue; // not a valid extern ref
621 // compute true path to the extern file
622 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
623 if ( fullname.Length() <= 0 ) fullname = filename;
627 char *mainfile = reader.WS()->LoadedFile();
628 if ( ! mainfile ) mainfile = "";
629 Standard_Integer slash = 0;
630 for ( Standard_Integer k=0; mainfile[k]; k++ )
631 if ( mainfile[k] == '/' ) slash = k;
632 strncpy ( fullname, mainfile, slash );
633 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
636 // get and check PD associated with the current extern ref
637 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
638 if ( PD.IsNull() ) continue; // not a valid extern ref
639 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
641 // read extern file (or use existing data) and record its data
642 Handle(STEPCAFControl_ExternFile) EF =
643 ReadExternFile ( filename, fullname.ToCString(), doc );
644 PDFileMap.Bind ( PD, EF );
647 // and insert them to the document
648 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
649 if ( STool.IsNull() ) return Standard_False;
650 XCAFDoc_DataMapOfShapeLabel map;
652 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
654 for ( i=1; i <= num; i++ ) {
655 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
660 if ( GetColorMode() )
661 ReadColors ( reader.WS(), doc, PDFileMap, map );
665 ReadNames ( reader.WS(), doc, PDFileMap, map );
667 // read validation props
668 if ( GetPropsMode() )
669 ReadValProps ( reader.WS(), doc, PDFileMap, map );
672 if ( GetLayerMode() )
673 ReadLayers ( reader.WS(), doc );
675 // read SHUO entities from STEP model
677 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
679 // read GDT entities from STEP model
681 ReadGDTs(reader.WS(),doc);
683 // read Material entities from STEP model
685 ReadMaterials(reader.WS(),doc,SeqPDS);
687 // read View entities from STEP model
689 ReadViews(reader.WS(), doc);
691 // Expand resulting CAF structure for sub-shapes (optionally with their
692 // names) if requested
693 ExpandSubShapes(STool, map, ShapePDMap);
695 // Update assembly compounds
696 STool->UpdateAssemblies();
698 return Standard_True;
701 //=======================================================================
702 //function : AddShape
704 //=======================================================================
706 TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
707 const Handle(XCAFDoc_ShapeTool) &STool,
708 const TopTools_MapOfShape &NewShapesMap,
709 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
710 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
711 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
713 // if shape has already been mapped, just return corresponding label
714 if ( ShapeLabelMap.IsBound ( S ) ) {
715 return ShapeLabelMap.Find ( S );
718 // if shape is located, create instance
719 if ( ! S.Location().IsIdentity() ) {
723 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
724 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
725 ShapeLabelMap.Bind ( S, L );
729 // if shape is not compound, simple add it
730 if ( S.ShapeType() != TopAbs_COMPOUND ) {
731 TDF_Label L = STool->AddShape ( S, Standard_False );
732 ShapeLabelMap.Bind ( S, L );
736 // for compounds, compute number of subshapes and check whether this is assembly
737 Standard_Boolean isAssembly = Standard_False;
738 Standard_Integer nbComponents = 0;
740 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
741 TopoDS_Shape Sub0 = it.Value();
743 Sub0.Location ( loc );
744 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
747 // if(nbComponents>0) isAssembly = Standard_True;
749 // check whether it has associated external ref
750 TColStd_SequenceOfHAsciiString SHAS;
751 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
752 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
753 if ( ! EF.IsNull() ) {
754 // (store information on extern refs in the document)
755 SHAS.Append(EF->GetName());
756 // if yes, just return corresponding label
757 if ( ! EF->GetLabel().IsNull() ) {
758 // but if components >0, ignore extern ref!
759 if ( nbComponents <=0 ) {
760 ShapeLabelMap.Bind ( S, EF->GetLabel() );
761 STool->SetExternRefs(EF->GetLabel(),SHAS);
762 return EF->GetLabel();
766 if ( ! EF->GetLabel().IsNull() )
767 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
768 else if ( nbComponents <=0 )
769 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
774 // add compound either as a whole,
775 if ( ! isAssembly ) {
776 TDF_Label L = STool->AddShape ( S, Standard_False );
777 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
778 ShapeLabelMap.Bind ( S, L );
782 // or as assembly, component-by-component
783 TDF_Label L = STool->NewShape();
784 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
785 TopoDS_Shape Sub0 = it.Value();
787 Sub0.Location ( loc );
788 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
789 if ( ! subL.IsNull() ) {
790 STool->AddComponent ( L, subL, it.Value().Location() );
793 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
794 ShapeLabelMap.Bind ( S, L );
795 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
800 //=======================================================================
801 //function : ReadExternFile
803 //=======================================================================
805 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
806 const Standard_CString fullname,
807 Handle(TDocStd_Document)& doc)
809 // if the file is already read, associate it with SDR
810 if ( myFiles.IsBound ( file ) ) {
811 return myFiles.ChangeFind ( file );
815 cout << "Reading extern file: " << fullname << endl;
818 // create new WorkSession and Reader
819 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
820 newWS->SelectNorm ( "STEP" );
821 STEPControl_Reader sr ( newWS, Standard_False );
823 // start to fill the resulting ExternFile structure
824 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
826 EF->SetName ( new TCollection_HAsciiString ( file ) );
829 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
831 // transfer in single-result mode
832 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
833 TDF_LabelSequence labels;
834 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
835 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
838 // add read file to dictionary
839 myFiles.Bind( file, EF );
845 //=======================================================================
846 //function : SetColorToSubshape
848 //=======================================================================
849 static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
850 const TopoDS_Shape & S,
851 const Quantity_Color& col,
852 const XCAFDoc_ColorType type)
854 for (TopoDS_Iterator it(S); it.More(); it.Next())
855 if (! CTool->SetColor( it.Value(), col, type)) break;
859 //=======================================================================
860 //function : findStyledSR
862 //=======================================================================
863 static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
864 Handle(StepShape_ShapeRepresentation)& aSR)
866 // search Shape Represenatation for component styled item
867 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
868 Handle(StepVisual_PresentationStyleByContext) PSA =
869 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
872 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
873 Handle(StepShape_ShapeRepresentation) aCurrentSR =
874 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
875 if ( aCurrentSR.IsNull() )
883 //=======================================================================
884 //function : ReadColors
886 //=======================================================================
888 Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
889 Handle(TDocStd_Document)& Doc,
890 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
891 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
893 STEPConstruct_Styles Styles ( WS );
894 if ( ! Styles.LoadStyles() ) {
896 cout << "Warning: no styles are found in the model" << endl;
898 return Standard_False;
900 // searching for invisible items in the model
901 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
902 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
904 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
905 if ( CTool.IsNull() ) return Standard_False;
907 // parse and search for color attributes
908 Standard_Integer nb = Styles.NbStyles();
909 for ( Standard_Integer i=1; i <= nb; i++ ) {
910 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
911 if ( style.IsNull() ) continue;
913 Standard_Boolean IsVisible = Standard_True;
914 // check the visibility of styled item.
915 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
916 if ( style != aHSeqOfInvisStyle->Value( si ) )
918 // found that current style is invisible.
919 IsVisible = Standard_False;
923 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
924 // check if it is component style
925 Standard_Boolean IsComponent = Standard_False;
926 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
930 NCollection_Vector<Handle(Standard_Transient)> anItems;
931 if (!style->Item().IsNull()) {
932 anItems.Append(style->Item());
934 else if (!style->ItemAP242().Representation().IsNull()){
935 //special case for AP242: item can be Reprsentation
936 Handle(StepRepr_Representation) aRepr = style->ItemAP242().Representation();
937 for (Standard_Integer j = 1; j <= aRepr->Items()->Length(); j++)
938 anItems.Append(aRepr->Items()->Value(j));
940 for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
941 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(),
942 Handle(StepRepr_RepresentationItem)::DownCast(anItems.Value(itemIt)) );
943 Standard_Boolean isSkipSHUOstyle = Standard_False;
944 // take shape with real location.
945 while ( IsComponent ) {
947 Handle(StepShape_ShapeRepresentation) aSR;
948 findStyledSR( style, aSR );
949 // search for SR along model
952 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
953 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
954 for (subs.Start(); subs.More(); subs.Next()) {
955 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
958 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
959 Handle(StepRepr_ProductDefinitionShape) PDS =
960 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
963 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
965 Handle(StepRepr_AssemblyComponentUsage) ACU =
966 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
969 // PTV 10.02.2003 skip styled item that refer to SHUO
970 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
971 isSkipSHUOstyle = Standard_True;
974 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
975 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
980 // PTV 10.02.2003 to find component of assembly CORRECTLY
981 STEPConstruct_Tool Tool( WS );
982 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
983 aSh = CTool->ShapeTool()->GetShape(aShLab);
992 continue; // skip styled item which refer to SHUO
997 if ( ! SurfCol.IsNull() ) {
999 Styles.DecodeColor ( SurfCol, col );
1000 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
1001 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
1003 if ( ! BoundCol.IsNull() ) {
1005 Styles.DecodeColor ( BoundCol, col );
1006 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
1007 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
1009 if ( ! CurveCol.IsNull() ) {
1011 Styles.DecodeColor ( CurveCol, col );
1012 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
1013 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
1016 // sets the invisibility for shape.
1018 if ( CTool->ShapeTool()->Search( S, aInvL ) )
1019 CTool->SetVisibility( aInvL, Standard_False );
1023 CTool->ReverseChainsOfTreeNodes();
1024 return Standard_True;
1027 //=======================================================================
1028 //function : GetLabelFromPD
1030 //=======================================================================
1032 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1033 const Handle(XCAFDoc_ShapeTool) &STool,
1034 const Handle(Transfer_TransientProcess) &TP,
1035 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1036 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1039 if ( PDFileMap.IsBound ( PD ) ) {
1040 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1041 if ( ! EF.IsNull() ) {
1043 if ( ! L.IsNull() ) return L;
1048 Handle(Transfer_Binder) binder = TP->Find(PD);
1049 if ( binder.IsNull() || ! binder->HasResult() ) return L;
1050 S = TransferBRep::ShapeResult ( TP, binder );
1051 if ( S.IsNull() ) return L;
1053 if ( S.IsNull() ) return L;
1054 if ( ShapeLabelMap.IsBound ( S ) )
1055 L = ShapeLabelMap.Find ( S );
1057 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1061 //=======================================================================
1062 //function : FindInstance
1064 //=======================================================================
1066 TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1067 const Handle(XCAFDoc_ShapeTool) &STool,
1068 const STEPConstruct_Tool &Tool,
1069 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1070 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1074 // get shape resulting from CDSR (in fact, only location is interesting)
1075 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1076 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1077 if ( binder.IsNull() || ! binder->HasResult() ) {
1079 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1084 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1087 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1092 // find component`s original label
1093 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
1094 if ( PD.IsNull() ) return L;
1095 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1096 if ( Lref.IsNull() ) return L;
1098 // find main shape (assembly) label
1100 PD = NAUO->RelatingProductDefinition();
1101 if ( PD.IsNull() ) return L;
1102 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1103 if ( L0.IsNull() ) return L;
1105 // if CDSR and NAUO are reversed, swap labels
1106 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1107 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
1108 for (subs1.Start(); subs1.More(); subs1.Next()) {
1109 Handle(StepRepr_ProductDefinitionShape) PDS =
1110 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
1111 if(PDS.IsNull()) continue;
1112 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
1113 for (subs2.Start(); subs2.More(); subs2.Next()) {
1114 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
1115 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
1116 if (CDSRtmp.IsNull()) continue;
1120 if (CDSR.IsNull()) return L;
1121 // if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
1122 // TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
1125 // iterate on components to find proper one
1126 TDF_LabelSequence seq;
1127 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
1128 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
1129 TDF_Label Lcomp = seq(k), Lref2;
1130 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
1132 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
1139 //=======================================================================
1140 //function : ReadNames
1142 //=======================================================================
1144 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
1145 Handle(TDocStd_Document)& Doc,
1146 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1147 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1149 // get starting data
1150 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1151 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1152 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1153 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1154 if ( STool.IsNull() ) return Standard_False;
1155 STEPConstruct_Tool Tool ( WS );
1157 // iterate on model to find all SDRs and CDSRs
1158 Standard_Integer nb = Model->NbEntities();
1159 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1160 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1161 Handle(TCollection_HAsciiString) name;
1163 for (Standard_Integer i = 1; i <= nb; i++) {
1164 Handle(Standard_Transient) enti = Model->Value(i);
1166 // get description of NAUO
1167 if ( enti->DynamicType() == tNAUO ) {
1169 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1170 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1171 if(NAUO.IsNull()) continue;
1172 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1173 for (subs.Start(); subs.More(); subs.Next()) {
1174 Handle(StepRepr_ProductDefinitionShape) PDS =
1175 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1176 if(PDS.IsNull()) continue;
1177 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1178 if ( PDR.IsNull() ) continue;
1179 if ( PDR->HasDescription() &&
1180 PDR->Description()->UsefullLength() >0 ) name = PDR->Description();
1181 else if ( !PDR->Name().IsNull() && PDR->Name()->UsefullLength() >0 ) name = PDR->Name();
1182 else if ( !PDR->Id().IsNull()) name = PDR->Id();
1183 else name = new TCollection_HAsciiString;
1185 // find proper label
1186 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1187 if ( L.IsNull() ) continue;
1188 TCollection_ExtendedString str ( name->String() );
1189 TDataStd_Name::Set ( L, str );
1192 // for PD get name of associated product
1193 if ( enti->DynamicType() == tPD ) {
1195 Handle(StepBasic_ProductDefinition) PD =
1196 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1197 if(PD.IsNull()) continue;
1198 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1200 name = new TCollection_HAsciiString;
1201 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1202 name = Prod->Name();
1203 else if (!Prod->Id().IsNull())
1206 name = new TCollection_HAsciiString;
1207 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1208 if ( L.IsNull() ) continue;
1209 TCollection_ExtendedString str ( name->String() );
1210 TDataStd_Name::Set ( L, str );
1212 // set a name to the document
1213 //TCollection_ExtendedString str ( name->String() );
1214 //TDataStd_Name::Set ( L, str );
1217 return Standard_True;
1220 //=======================================================================
1221 //function : GetLabelFromPD
1223 //=======================================================================
1225 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1226 const Handle(XCAFDoc_ShapeTool) &STool,
1227 const STEPConstruct_ValidationProps &Props,
1228 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1229 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1232 if ( PDFileMap.IsBound ( PD ) ) {
1233 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1234 if ( ! EF.IsNull() ) {
1236 if ( ! L.IsNull() ) return L;
1239 TopoDS_Shape S = Props.GetPropShape ( PD );
1240 if ( S.IsNull() ) return L;
1241 if ( ShapeLabelMap.IsBound ( S ) )
1242 L = ShapeLabelMap.Find ( S );
1244 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1248 //=======================================================================
1249 //function : ReadValProps
1251 //=======================================================================
1253 Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1254 Handle(TDocStd_Document)& Doc,
1255 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1256 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1258 // get starting data
1259 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1260 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1261 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1262 if ( STool.IsNull() ) return Standard_False;
1264 // load props from the STEP model
1265 TColStd_SequenceOfTransient props;
1266 STEPConstruct_ValidationProps Props ( WS );
1267 if ( ! Props.LoadProps ( props ) ) {
1269 cout << "Warning: no validation props found in the model" << endl;
1271 return Standard_False;
1274 // interpret props one by one
1275 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1276 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1277 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1278 if ( PDR.IsNull() ) continue;
1282 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1283 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1284 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1285 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1286 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1287 if(PDS.IsNull()) continue;
1288 // find corresponding NAUO
1289 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1290 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1291 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1292 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1293 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1295 if ( !NAUO.IsNull() ) {
1296 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1297 if ( L.IsNull() ) continue;
1300 // find corresponding ProductDefinition:
1301 Handle(StepBasic_ProductDefinition) ProdDef;
1302 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1303 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1304 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1305 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1307 if ( ProdDef.IsNull() ) continue;
1308 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1312 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1313 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1314 if(SA.IsNull()) continue;
1315 // find ShapeRepresentation
1316 Handle(StepShape_ShapeRepresentation) SR;
1317 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1318 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1319 Handle(StepRepr_PropertyDefinition) PropD1 =
1320 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1321 if(PropD1.IsNull()) continue;
1322 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1323 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1324 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1325 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1326 if(SDR.IsNull()) continue;
1327 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1330 if(SR.IsNull()) continue;
1331 Handle(Transfer_Binder) binder;
1332 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1333 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1334 Handle(StepShape_SolidModel) SM =
1335 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1336 binder = TP->Find(SM);
1338 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1339 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1340 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1341 binder = TP->Find(SBSM);
1343 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1344 Handle(StepShape_GeometricSet) GS =
1345 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1346 binder = TP->Find(GS);
1349 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1351 S = TransferBRep::ShapeResult ( TP, binder );
1352 if(S.IsNull()) continue;
1353 if ( ShapeLabelMap.IsBound ( S ) )
1354 L = ShapeLabelMap.Find ( S );
1356 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1360 if(L.IsNull()) continue;
1362 // decode validation properties
1363 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1364 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1365 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1366 Standard_Boolean isArea;
1369 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1370 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1371 else XCAFDoc_Volume::Set ( L, val );
1373 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1374 XCAFDoc_Centroid::Set ( L, pos );
1378 return Standard_True;
1381 //=======================================================================
1382 //function : ReadLayers
1384 //=======================================================================
1386 Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1387 Handle(TDocStd_Document)& Doc) const
1389 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1390 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1391 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1392 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1393 if ( STool.IsNull() ) return Standard_False;
1394 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1395 if ( LTool.IsNull() ) return Standard_False;
1397 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1398 Standard_Integer nb = Model->NbEntities();
1399 Handle(TCollection_HAsciiString) name;
1401 for (Standard_Integer i = 1; i <= nb; i ++) {
1402 Handle(Standard_Transient) enti = Model->Value(i);
1403 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1404 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1405 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1406 if (SVPLA->AssignedItems().IsNull())
1409 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1410 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1411 TCollection_ExtendedString aLayerName ( hName->String() );
1413 // find a target shape and its label in the document
1414 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1415 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1416 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1417 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1419 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1420 if ( S.IsNull() ) continue;
1423 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1424 LTool->SetLayer ( shL, aLayerName );
1427 // check invisibility
1428 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1429 for (subs.Start(); subs.More(); subs.Next()) {
1430 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1432 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1434 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1435 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1436 Handle(TDataStd_UAttribute) aUAttr;
1437 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1440 return Standard_True;
1443 //=======================================================================
1444 //function : ReadSHUOs
1446 //=======================================================================
1448 static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1449 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1450 const Handle(XCAFDoc_ShapeTool)& STool,
1451 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1452 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1453 TDF_LabelSequence& aLabels)
1455 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1456 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1457 for (subs.Start(); subs.More(); subs.Next()) {
1458 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1459 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1463 if (subSHUO.IsNull())
1464 return Standard_False;
1466 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
1467 if (NUNAUO.IsNull())
1468 return Standard_False;
1469 // Handle(Interface_InterfaceModel) Model = WS->Model();
1470 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1471 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1472 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1473 // if ( binder.IsNull() || ! binder->HasResult() )
1474 // return Standard_False;
1475 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1476 // get label of NAUO next level
1478 STEPConstruct_Tool Tool( WS );
1479 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1480 // STool->Search(NUSh, NUlab);
1482 return Standard_False;
1483 aLabels.Append( NULab );
1484 // and check by recurse.
1485 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1486 return Standard_True;
1490 //=======================================================================
1491 //function : setSHUOintoDoc
1492 //purpose : auxilary
1493 //=======================================================================
1494 static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1495 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1496 const Handle(XCAFDoc_ShapeTool)& STool,
1497 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1498 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1500 TDF_Label aMainLabel;
1501 // get upper usage NAUO from SHUO.
1502 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1503 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1504 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
1505 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1507 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1511 // Handle(Interface_InterfaceModel) Model = WS->Model();
1512 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1513 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1514 // TopoDS_Shape UUSh, NUSh;
1515 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1516 // if ( binder.IsNull() || ! binder->HasResult() )
1517 // return aMainLabel;
1518 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1519 // binder = TP->Find(NUNAUO);
1520 // if ( binder.IsNull() || ! binder->HasResult() )
1521 // return aMainLabel;
1522 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1524 // get first labels for first SHUO attribute
1525 TDF_Label UULab, NULab;
1526 STEPConstruct_Tool Tool( WS );
1527 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1528 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1530 // STool->Search(UUSh, UULab);
1531 // STool->Search(NUSh, NULab);
1532 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1533 //create sequence fo labels to set SHUO structure into the document
1534 TDF_LabelSequence ShuoLabels;
1535 ShuoLabels.Append( UULab );
1536 ShuoLabels.Append( NULab );
1537 // add all other labels of sub SHUO entities
1538 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1539 // last accord for SHUO
1540 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1541 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1542 aMainLabel = anSHUOAttr->Label();
1548 //=======================================================================
1549 //function : ReadSHUOs
1551 //=======================================================================
1553 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1554 Handle(TDocStd_Document)& Doc,
1555 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1556 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1558 // the big part code duplication from ReadColors.
1559 // It is possible to share this code functionality, just to decide how ???
1560 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1561 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1563 STEPConstruct_Styles Styles ( WS );
1564 if ( ! Styles.LoadStyles() ) {
1566 cout << "Warning: no styles are found in the model" << endl;
1568 return Standard_False;
1570 // searching for invisible items in the model
1571 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1572 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1573 // parse and search for color attributes
1574 Standard_Integer nb = Styles.NbStyles();
1575 for ( Standard_Integer i=1; i <= nb; i++ ) {
1576 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1577 if ( style.IsNull() ) continue;
1579 Standard_Boolean IsVisible = Standard_True;
1580 // check the visibility of styled item.
1581 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1582 if ( style != aHSeqOfInvisStyle->Value( si ) )
1584 // found that current style is invisible.
1586 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1588 IsVisible = Standard_False;
1592 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1593 // check if it is component style
1594 Standard_Boolean IsComponent = Standard_False;
1595 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1599 Handle(StepShape_ShapeRepresentation) aSR;
1600 findStyledSR( style, aSR );
1601 // search for SR along model
1604 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1605 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1606 for (subs.Start(); subs.More(); subs.Next()) {
1607 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1608 if ( aSDR.IsNull() )
1610 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1611 Handle(StepRepr_ProductDefinitionShape) PDS =
1612 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1615 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1616 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1617 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1618 if ( SHUO.IsNull() )
1621 // set the SHUO structure to the document
1622 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1623 if ( aLabelForStyle.IsNull() ) {
1625 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1629 // now set the style to the SHUO main label.
1630 if ( ! SurfCol.IsNull() ) {
1632 Styles.DecodeColor ( SurfCol, col );
1633 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1635 if ( ! BoundCol.IsNull() ) {
1637 Styles.DecodeColor ( BoundCol, col );
1638 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1640 if ( ! CurveCol.IsNull() ) {
1642 Styles.DecodeColor ( CurveCol, col );
1643 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1646 // sets the invisibility for shape.
1647 CTool->SetVisibility( aLabelForStyle, Standard_False );
1649 } // end search SHUO by SDR
1650 } // end iterates on styles
1652 return Standard_True;
1656 //=======================================================================
1657 //function : GetLengthConversionFactor
1659 //=======================================================================
1660 static Standard_Boolean GetLengthConversionFactor(const Handle(StepBasic_NamedUnit)& NU,
1661 Standard_Real& afact)
1664 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1665 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1666 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1667 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1668 afact = MWUCBU->ValueComponent();
1669 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1670 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1671 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1672 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1673 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1674 if(SU->Name()==StepBasic_sunMetre) {
1676 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1682 return Standard_True;
1685 //=======================================================================
1686 //function : GetLengthConversionFactorFromContext
1688 //=======================================================================
1689 static Standard_Boolean GetLengthConversionFactorFromContext(const Handle(StepRepr_RepresentationContext)& theRC,
1690 Standard_Real& theFact)
1694 return Standard_False;
1695 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) aSiLU;
1696 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
1697 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
1698 if (!aCtx.IsNull()) {
1699 for (Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
1700 if (aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
1701 aSiLU = Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(aCtx->UnitsValue(j));
1706 if (aSiLU.IsNull()) {
1707 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
1708 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
1709 if (!aCtx1.IsNull()) {
1710 for (Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
1711 if (aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
1712 aSiLU = Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(aCtx1->UnitsValue(j));
1719 return Standard_False;
1720 return GetLengthConversionFactor(aSiLU, theFact);
1724 //=======================================================================
1725 //function : GetAngleConversionFactor
1727 //=======================================================================
1728 static Standard_Boolean GetAngleConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1729 Standard_Real& afact)
1732 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)) ) return Standard_False;
1733 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit) CBULU =
1734 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)::DownCast(NU);
1735 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1736 afact = MWUCBU->ValueComponent();
1737 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1738 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1739 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1740 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1741 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1742 if(SU->Name()==StepBasic_sunRadian) {
1744 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1745 // convert radian to deg
1750 return Standard_True;
1753 //=======================================================================
1754 //function : GetMassConversionFactor
1756 //=======================================================================
1757 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1758 Standard_Real& afact)
1761 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1762 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1763 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1764 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1765 afact = MWUCBU->ValueComponent();
1766 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1767 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1768 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1769 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1770 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1771 if(SU->Name()==StepBasic_sunGram) {
1773 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1777 return Standard_True;
1780 //=======================================================================
1781 //function : readPMIPresentation
1782 //purpose : read polyline or tessellated presentation for
1783 // (Annotation_Curve_Occurrence or Draughting_Callout)
1784 //=======================================================================
1785 Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
1786 const Handle(XSControl_TransferReader)& theTR,
1787 const Standard_Real theFact,
1788 TopoDS_Shape& thePresentation,
1789 Handle(TCollection_HAsciiString)& thePresentName,
1792 if (thePresentEntity.IsNull())
1793 return Standard_False;
1794 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1795 Handle(StepVisual_AnnotationOccurrence) anAO;
1796 NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
1797 if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
1799 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
1800 if (!anAO.IsNull()) {
1801 thePresentName = anAO->Name();
1802 anAnnotations.Append(anAO);
1805 else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
1807 Handle(StepVisual_DraughtingCallout) aDCallout =
1808 Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
1809 thePresentName = aDCallout->Name();
1810 for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
1811 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
1814 anAnnotations.Append(anAO);
1817 Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
1818 aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
1819 if (!aTesselation.IsNull())
1820 anAnnotations.Append(aTesselation);
1824 if (!anAnnotations.Length())
1825 return Standard_False;
1829 TopoDS_Compound aResAnnotation;
1830 aB.MakeCompound(aResAnnotation);
1832 Standard_Integer i = 0;
1834 Standard_Integer nbShapes = 0;
1835 for (; i < anAnnotations.Length(); i++)
1837 Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
1838 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
1839 TopoDS_Shape anAnnotationShape;
1842 Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
1843 anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
1844 if (anAnnotationShape.IsNull())
1846 Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
1847 if (!binder.IsNull() && binder->HasResult()) {
1848 anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
1852 //case of tessellated entities
1855 Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
1856 if (aTessItem.IsNull())
1858 Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
1859 if (aTessSet.IsNull())
1861 NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
1862 Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
1863 Handle(StepVisual_TessellatedCurveSet) aTessCurve;
1864 for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++)
1866 aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
1868 if (aTessCurve.IsNull())
1870 Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
1871 if (aCoordList.IsNull())
1873 Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
1875 if (aPoints.IsNull() || aPoints->Length() == 0)
1877 NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves();
1878 Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
1879 TopoDS_Compound aComp;
1880 aB.MakeCompound(aComp);
1882 Standard_Integer k = 0;
1883 for (; k < aNbC; k++)
1885 Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
1889 for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
1891 Standard_Integer ind = anIndexes->Value(n);
1892 Standard_Integer indnext = anIndexes->Value(n + 1);
1893 if (ind > aPoints->Length() || indnext > aPoints->Length())
1895 gp_Pnt aP1(aPoints->Value(ind) * theFact);
1896 gp_Pnt aP2(aPoints->Value(indnext) * theFact);
1897 BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
1898 if (aMaker.IsDone())
1900 TopoDS_Edge aCurE = aMaker.Edge();
1901 aB.Add(aCurW, aCurE);
1904 aB.Add(aComp, aCurW);
1906 anAnnotationShape = aComp;
1908 if (!anAnnotationShape.IsNull())
1911 aB.Add(aResAnnotation, anAnnotationShape);
1912 if (i == anAnnotations.Length() - 1)
1913 BRepBndLib::AddClose(anAnnotationShape, aBox);
1917 thePresentation = aResAnnotation;
1919 return (nbShapes > 0);
1922 //=======================================================================
1923 //function : readAnnotationPlane
1924 //purpose : read annotation plane
1925 //=======================================================================
1926 Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
1927 const Standard_Real theFact,
1930 if (theAnnotationPlane.IsNull())
1931 return Standard_False;
1932 Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
1933 if (aPlaneItem.IsNull())
1934 return Standard_False;
1935 Handle(StepGeom_Axis2Placement3d) aA2P3D;
1936 //retrieve axes from AnnotationPlane
1937 if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
1938 Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
1939 aA2P3D = aPlane->Position();
1941 else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
1942 Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
1943 aA2P3D = aBox->Placement().Axis2Placement3d();
1945 if (aA2P3D.IsNull())
1946 return Standard_False;
1949 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
1950 aPlaneAxes = anAxis->Ax2();
1951 gp_XYZ aLocPos = aPlaneAxes.Location().XYZ();
1953 aPlaneAxes.SetLocation(aLocPos);
1954 thePlane = aPlaneAxes;
1955 return Standard_True;
1958 //=======================================================================
1959 //function : readAnnotation
1960 //purpose : read annotation plane and position for given GDT
1961 // (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
1962 //=======================================================================
1963 void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
1964 const Handle(Standard_Transient)& theGDT,
1965 const Handle(Standard_Transient)& theDimObject)
1967 if (theGDT.IsNull() || theDimObject.IsNull())
1969 Handle(TCollection_HAsciiString) aPresentName;
1970 TopoDS_Compound aResAnnotation;
1971 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1972 const Interface_Graph& aGraph = aTP->Graph();
1973 // find the proper DraughtingModelItemAssociation
1974 Interface_EntityIterator subs = aGraph.Sharings(theGDT);
1975 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
1976 for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
1977 if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
1979 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
1980 Handle(TCollection_HAsciiString) aName = aDMIA->Name();
1982 if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
1986 if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
1990 Handle(StepVisual_DraughtingModel) aDModel =
1991 Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
1992 Standard_Real aFact = 1;
1993 if (!aDModel.IsNull())
1994 GetLengthConversionFactorFromContext(aDModel->ContextOfItems(), aFact);
1996 // retrieve AnnotationPlane
1997 Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
1998 if (aDMIAE.IsNull())
2001 subs = aGraph.Sharings(aDMIAE);
2002 Handle(StepVisual_AnnotationPlane) anAnPlane;
2003 for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
2004 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
2006 Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aFact, aPlaneAxes);
2008 // set plane axes to XCAF
2010 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
2011 Handle(XCAFDimTolObjects_DimensionObject) anObj =
2012 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
2013 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1);
2014 anObj->SetPlane(aPlaneAxes);
2016 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
2017 Handle(XCAFDimTolObjects_DatumObject) anObj =
2018 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
2019 anObj->SetPlane(aPlaneAxes);
2021 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
2022 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
2023 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
2024 anObj->SetPlane(aPlaneAxes);
2028 // Retrieve presentation
2030 if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
2032 gp_Pnt aPtext(0., 0., 0.);
2033 // if Annotation plane location inside bounding box set it to text position
2034 // else set the center of bounding box to text position
2037 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2038 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2039 if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
2040 aPtext = aPlaneAxes.Location();
2043 aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
2047 aPtext = aPlaneAxes.Location();
2050 // set point to XCAF
2051 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
2052 Handle(XCAFDimTolObjects_DimensionObject) anObj =
2053 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
2054 anObj->SetPointTextAttach(aPtext);
2055 anObj->SetPresentation(aResAnnotation, aPresentName);
2057 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
2058 Handle(XCAFDimTolObjects_DatumObject) anObj =
2059 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
2060 anObj->SetPointTextAttach(aPtext);
2061 anObj->SetPresentation(aResAnnotation, aPresentName);
2063 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
2064 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
2065 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
2066 anObj->SetPointTextAttach(aPtext);
2067 anObj->SetPresentation(aResAnnotation, aPresentName);
2072 //=======================================================================
2073 //function : readConnectionPoints
2074 //purpose : read connection points for given dimension
2075 //=======================================================================
2076 void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
2077 const Handle(Standard_Transient) theGDT,
2078 const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
2080 if (theGDT.IsNull() || theDimObject.IsNull())
2082 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
2083 const Interface_Graph& aGraph = aTP->Graph();
2086 Standard_Real aFact = 1;
2087 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
2088 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
2089 aSDR = Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anIt.Value());
2092 GetLengthConversionFactorFromContext(aSDR->ContextOfItems(), aFact);
2094 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2095 // retrieve derived geometry
2096 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
2097 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
2100 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
2101 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
2102 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2104 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
2106 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
2107 if (aPoint.IsNull()) {
2108 // try Axis2Placement3d.location instead of CartesianPoint
2109 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2110 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
2111 if (anA2P3D.IsNull())
2113 aPoint = anA2P3D->Location();
2116 // set connection point to object
2117 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2118 theDimObject->SetPoint(aPnt);
2120 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2121 // retrieve derived geometry
2122 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
2123 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
2124 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
2125 if (aDSA1.IsNull() && aDSA2.IsNull())
2127 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
2128 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2129 if (!aDSA1.IsNull()) {
2130 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2131 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2134 if (!aDSA2.IsNull()) {
2135 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2136 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2140 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2141 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2142 if (aPoint.IsNull()) {
2143 // try Axis2Placement3d.location instead of CartesianPoint
2144 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2145 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2146 if (!anA2P3D.IsNull())
2147 aPoint = anA2P3D->Location();
2149 if (!aPoint.IsNull()) {
2150 // set connection point to object
2151 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2152 theDimObject->SetPoint(aPnt);
2156 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2157 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2158 if (aPoint.IsNull()) {
2159 // try Axis2Placement3d.location instead of CartesianPoint
2160 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2161 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2162 if (!anA2P3D.IsNull())
2163 aPoint = anA2P3D->Location();
2165 if (!aPoint.IsNull()) {
2166 // set connection point to object
2167 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2168 theDimObject->SetPoint2(aPnt);
2174 //=======================================================================
2175 //function : ReadDatums
2176 //purpose : auxilary
2177 //=======================================================================
2178 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
2179 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2180 const Interface_Graph &graph,
2181 const Handle(Transfer_TransientProcess) &TP,
2182 const TDF_Label TolerL,
2183 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
2185 if(GTWDR.IsNull()) return Standard_False;
2186 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
2187 if(HADR.IsNull()) return Standard_False;
2188 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
2189 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2190 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
2191 if(aDatum.IsNull()) continue;
2192 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
2193 for(subs4.Start(); subs4.More(); subs4.Next()) {
2194 Handle(StepRepr_ShapeAspectRelationship) SAR =
2195 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
2196 if(SAR.IsNull()) continue;
2197 Handle(StepDimTol_DatumFeature) DF =
2198 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
2199 if(DF.IsNull()) continue;
2200 Interface_EntityIterator subs5 = graph.Sharings(DF);
2201 Handle(StepRepr_PropertyDefinition) PropDef;
2202 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
2203 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2205 if(PropDef.IsNull()) continue;
2206 Handle(StepShape_AdvancedFace) AF;
2207 subs5 = graph.Sharings(PropDef);
2208 for(subs5.Start(); subs5.More(); subs5.Next()) {
2209 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2210 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
2212 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2213 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2214 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2215 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2219 if(AF.IsNull()) return Standard_False;
2220 Standard_Integer index = TP->MapIndex(AF);
2223 Handle(Transfer_Binder) binder = TP->MapItem(index);
2224 aSh = TransferBRep::ShapeResult(binder);
2226 if(aSh.IsNull()) continue;
2228 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2229 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
2232 return Standard_True;
2235 //=======================================================================
2236 //function : FindShapeIndexForDGT
2237 //purpose : auxiliary find shape index in map og imported shapes
2238 //=======================================================================
2239 static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2240 const Handle(XSControl_WorkSession)& theWS)
2242 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2243 // try to find index of given entity
2244 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2247 // if theEnt is a geometry item try to find its topological item
2248 const Interface_Graph& aGraph = aTP->Graph();
2249 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2250 for (anIter.Start(); anIter.More(); anIter.Next()) {
2251 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2253 anIndex = aTP->MapIndex(anIter.Value());
2261 //=======================================================================
2262 //function : collectShapeAspect
2264 //=======================================================================
2265 static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
2266 const Handle(XSControl_WorkSession)& theWS,
2267 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
2271 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2272 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2273 const Interface_Graph& aGraph = aTP->Graph();
2274 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2275 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2276 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2277 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2278 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2279 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2281 if (!aSADR.IsNull())
2282 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2284 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2285 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2286 theSAs.Append(theSA);
2290 // Find all children Shape_Aspect
2291 Standard_Boolean isSimple = Standard_True;
2292 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2293 for (; anIter.More(); anIter.Next()) {
2294 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
2295 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2296 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2297 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2298 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
2299 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
2300 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2301 isSimple = Standard_False;
2305 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2307 theSAs.Append(theSA);
2311 //=======================================================================
2312 //function : getShapeLabel
2314 //=======================================================================
2316 static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
2317 const Handle(XSControl_WorkSession)& theWS,
2318 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
2321 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2322 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2323 TopoDS_Shape aShape;
2325 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2326 aShape = TransferBRep::ShapeResult(aBinder);
2328 if (aShape.IsNull())
2330 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2334 //=======================================================================
2335 //function : setDatumToXCAF
2337 //=======================================================================
2339 Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
2340 const TDF_Label theGDTL,
2341 const Standard_Integer thePositionCounter,
2342 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2343 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2344 const Standard_Real theModifValue,
2345 const Handle(TDocStd_Document)& theDoc,
2346 const Handle(XSControl_WorkSession)& theWS)
2348 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2349 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2350 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2351 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2352 const Interface_Graph& aGraph = aTP->Graph();
2353 Handle(XCAFDoc_Datum) aDat;
2354 TDF_LabelSequence aShapeLabels;
2355 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2357 // Collect all links to shapes
2358 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2359 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
2360 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2361 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2362 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2364 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2365 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2366 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2367 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2370 // Collect shape labels
2371 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2372 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2375 // Skip datum targets
2376 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2379 // Process all connected GISU
2380 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2381 for (; anIter.More(); anIter.Next()) {
2382 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2385 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2386 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2387 if (!aShapeL.IsNull())
2388 aShapeLabels.Append(aShapeL);
2393 // Process datum targets and create objects for them
2394 Standard_Boolean isExistDatumTarget = Standard_False;
2395 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2396 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2399 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
2400 XCAFDimTolObjects_DatumTargetType aType;
2401 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2403 aDatTargetObj->SetDatumTargetType(aType);
2404 Standard_Boolean isValidDT = Standard_False;
2406 // Feature for datum target
2407 TDF_LabelSequence aDTShapeLabels;
2408 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
2409 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
2410 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2411 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
2413 if (!aRelationship.IsNull()) {
2414 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2415 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2416 for (; aSAIter.More(); aSAIter.Next()) {
2417 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2420 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2421 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2422 if (!aShapeL.IsNull()) {
2423 aDTShapeLabels.Append(aShapeL);
2424 isValidDT = Standard_True;
2430 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2431 // Try another way of feature connection
2432 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2433 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
2436 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2437 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2438 if (!aShapeL.IsNull()) {
2439 aDTShapeLabels.Append(aShapeL);
2440 isValidDT = Standard_True;
2446 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2447 // Area datum target
2448 Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
2449 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2450 for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
2451 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
2453 Handle(StepRepr_RepresentationItem) anItem;
2454 if (aGISU->NbIdentifiedItem() > 0)
2455 anItem = aGISU->IdentifiedItemValue(1);
2456 if (anItem.IsNull())
2458 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2459 if (anItemIndex > 0) {
2460 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2461 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
2462 aDatTargetObj->SetDatumTarget(anItemShape);
2463 isValidDT = Standard_True;
2467 // Point/line/rectangle/circle datum targets
2468 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2469 Handle(StepRepr_PropertyDefinition) aPD;
2470 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2471 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2473 if (!aPD.IsNull()) {
2474 anIter = aGraph.Sharings(aPD);
2475 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2476 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2477 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2479 if (!aSDR.IsNull()) {
2480 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2481 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2482 if (!aSRWP.IsNull()) {
2483 isValidDT = Standard_True;
2484 // Collect parameters of datum target
2485 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
2487 if (aSRWP->ItemsValue(j).IsNull())
2489 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2491 Handle(StepGeom_Axis2Placement3d) anAx
2492 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
2493 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
2494 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
2496 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
2498 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
2499 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
2500 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2501 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
2502 Standard_Real aFact = 1.;
2503 if (anUnit.IsNull())
2505 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2508 if (GetLengthConversionFactor(aNU, aFact))
2509 aVal = aVal * aFact;
2510 if (aM->Name()->String().IsEqual("target length") ||
2511 aM->Name()->String().IsEqual("target diameter"))
2512 aDatTargetObj->SetDatumTargetLength(aVal);
2514 aDatTargetObj->SetDatumTargetWidth(aVal);
2522 // Create datum target object
2524 TDF_Label aDatL = aDGTTool->AddDatum();
2525 myGDTMap.Bind(aDT, aDatL);
2526 aDGTTool->Lock(aDatL);
2527 aDat = XCAFDoc_Datum::Set(aDatL);
2528 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
2529 aDatTargetObj->SetName(theDat->Identification());
2530 aDatTargetObj->SetPosition(thePositionCounter);
2531 if (!theXCAFModifiers.IsEmpty())
2532 aDatTargetObj->SetModifiers(theXCAFModifiers);
2533 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2534 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2535 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2536 aDatTargetObj->IsDatumTarget(Standard_True);
2537 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2538 readAnnotation(aTR, aDT, aDatTargetObj);
2539 aDat->SetObject(aDatTargetObj);
2540 isExistDatumTarget = Standard_True;
2544 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2545 // Create object for datum
2546 TDF_Label aDatL = aDGTTool->AddDatum();
2547 myGDTMap.Bind(theDat, aDatL);
2548 // bind datum label with all reference datum_feature entities
2549 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2550 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2551 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2553 myGDTMap.Bind(aSA, aDatL);
2555 aDGTTool->Lock(aDatL);
2556 aDat = XCAFDoc_Datum::Set(aDatL);
2557 aDGTTool->SetDatum(aShapeLabels, aDatL);
2558 aDatObj->SetName(theDat->Identification());
2559 aDatObj->SetPosition(thePositionCounter);
2560 if (!theXCAFModifiers.IsEmpty())
2561 aDatObj->SetModifiers(theXCAFModifiers);
2562 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2563 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2564 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2565 if (aDatObj->GetPresentation().IsNull()) {
2566 // Try find annotation connected to datum entity (not right case, according recommended practices)
2567 readAnnotation(aTR, theDat, aDatObj);
2569 aDat->SetObject(aDatObj);
2572 return Standard_True;
2576 //=======================================================================
2577 //function : ReadDatums
2578 //purpose : auxilary
2579 //=======================================================================
2580 Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2581 const TDF_Label theGDTL,
2582 const Handle(TDocStd_Document)& theDoc,
2583 const Handle(XSControl_WorkSession)& theWS)
2585 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2586 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2587 const Interface_Graph& aGraph = aTP->Graph();
2589 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2590 for(anIter.Start(); anIter.More(); anIter.Next()) {
2591 Handle(Standard_Transient) anAtr = anIter.Value();
2592 if(anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2594 Standard_Integer aPositionCounter = 0;//position on frame
2595 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2596 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2597 for(anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2598 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2599 if(anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2602 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2603 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2604 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2606 Handle(StepGeom_Axis2Placement3d) anAx
2607 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2608 Handle(XCAFDoc_GeomTolerance) aTol;
2609 if(theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2611 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2612 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2613 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2614 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2618 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2619 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2620 !aLocArr.IsNull() && aLocArr->Length() > 2)
2622 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
2623 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
2624 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
2625 gp_Ax2 anA(aPnt, aDir, aDirR);
2626 anObj->SetAxis(anA);
2627 aTol->SetObject(anObj);
2633 if (aDS->NbConstituents() > 0)
2635 //get datum feature and datum target from datum system
2636 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2639 for(Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2641 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
2643 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2644 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2645 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2646 Standard_Real aModifValue = 0;
2647 if(!aModif.IsNull())
2649 for(Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2651 if(aModif->Value(m).CaseNumber() == 2)
2652 aXCAFModifiers.Append(
2653 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2654 SimpleDatumReferenceModifierMember()->Value());
2655 else if (aModif->Value(m).CaseNumber() == 1)
2657 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2658 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2659 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2660 Standard_Real aFact=1.;
2661 if(anUnit.IsNull()) continue;
2662 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2663 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2664 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2670 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2671 for(anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2673 if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2675 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2676 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2678 else if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2680 Handle(StepDimTol_DatumReferenceElement) aDRE
2681 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2682 //get modifiers from group of datums
2683 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2684 if(!aModifE.IsNull())
2686 for(Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2688 if(aModifE->Value(k).CaseNumber() == 2)
2689 aXCAFModifiers.Append(
2690 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2691 SimpleDatumReferenceModifierMember()->Value());
2692 else if (aModifE->Value(k).CaseNumber() == 1)
2694 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2695 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2696 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2697 Standard_Real aFact=1.;
2698 if(anUnit.IsNull()) continue;
2699 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2700 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2701 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2706 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2707 for(anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2708 if(anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2710 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2711 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2721 return Standard_True;
2724 //=======================================================================
2725 //function : createGeomTolObjectInXCAF
2727 //=======================================================================
2728 TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2729 const Handle(TDocStd_Document)& theDoc,
2730 const Handle(XSControl_WorkSession)& theWS)
2733 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2734 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2735 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2740 Handle(TCollection_HAsciiString) aSemanticName;
2742 // protection against invalid input
2743 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2744 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2745 if (aGeomTol->TolerancedShapeAspect().IsNull())
2747 aSemanticName = aGeomTol->Name();
2749 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2750 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2751 if (aDim->AppliesTo().IsNull())
2753 aSemanticName = aDim->Name();
2755 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2756 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2757 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2759 aSemanticName = aDim->Name();
2762 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2763 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2764 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2765 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2766 const Interface_Graph& aGraph = aTP->Graph();
2767 Standard_Boolean isAllAround = Standard_False;
2768 Standard_Boolean isAllOver = Standard_False;
2770 // find RepresentationItem for current Ent
2771 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2773 // Collect all Shape_Aspect entities
2774 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2775 for(anIter.Start(); anIter.More(); anIter.Next()) {
2776 Handle(Standard_Transient) anAtr = anIter.Value();
2777 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2778 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2780 //if associating tolerances with part (All-Over)
2781 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2782 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2784 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2785 if(anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2787 isAllOver = Standard_True;
2788 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2789 for(anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2791 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2792 if(anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2794 aSeqRI1.Append(anAtrABSR);
2800 else if(anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2801 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2803 //if tolerance attached to dimension
2804 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2805 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2807 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
2809 collectShapeAspect(aSA, theWS, aSAs);
2813 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2815 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2817 // if applyed AllAround Modifier
2818 isAllAround = Standard_True;
2820 // dimensions and default tolerances
2821 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
2823 collectShapeAspect(aSA, theWS, aSAs);
2827 // Collect all representation items
2830 //get representation items
2831 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2832 for(Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2834 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2835 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2836 Handle(StepRepr_PropertyDefinition) PropD;
2837 for(anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2838 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2839 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2841 if(!PropD.IsNull())//for old version
2843 Handle(StepRepr_RepresentationItem) RI;
2844 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2845 for(subs4.Start(); subs4.More(); subs4.Next()) {
2846 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2847 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2849 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2850 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2851 RI = Repr->ItemsValue(1);
2855 if(RI.IsNull()) continue;
2857 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2859 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2860 if(EC.IsNull()) continue;
2861 Handle(TCollection_HAsciiString) aName;
2862 Handle(StepShape_DimensionalSize) DimSize =
2863 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2864 Standard_Real dim1=-1.,dim2=-1.;
2865 subs4 = aGraph.Sharings(DimSize);
2866 for(subs4.Start(); subs4.More(); subs4.Next()) {
2867 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2868 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2869 if(!DimCharR.IsNull()) {
2870 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2871 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
2872 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2873 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
2876 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2877 //if(CID.IsNull()) continue;
2878 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2879 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2880 //if(CIDM.IsNull()) continue;
2881 //if(CIDM->ArrTransient().IsNull()) continue;
2882 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2883 //if(CID.CaseMem(CIDM)==1)
2884 // HARI = CID.ListRepresentationItem();
2885 //if(CID.CaseMem(CIDM)==2)
2886 // HARI = CID.SetRepresentationItem();
2887 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2888 if(HARI.IsNull()) continue;
2889 if(HARI->Length()>0) {
2890 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
2891 if(RI1.IsNull()) continue;
2892 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2893 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2894 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2895 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2896 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2897 Standard_Real afact=1.;
2898 if(anUnit.IsNull()) continue;
2899 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2900 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2901 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
2904 if(HARI->Length()>1) {
2905 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
2906 if(RI2.IsNull()) continue;
2907 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2908 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2909 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2910 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2911 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2912 Standard_Real afact=1.;
2913 if(anUnit.IsNull()) continue;
2914 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2915 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2916 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
2923 if(dim1<0) continue;
2924 if(dim2<0) dim2=dim1;
2925 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2926 // now we know edge_curve and value range therefore
2927 // we can create corresponding D> labels
2928 Standard_Integer index = aTP->MapIndex(EC);
2931 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2932 aSh = TransferBRep::ShapeResult(binder);
2934 if(aSh.IsNull()) continue;
2936 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2937 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
2938 arr->SetValue(1,dim1);
2939 arr->SetValue(2,dim2);
2940 aDGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
2942 // read tolerances and datums
2943 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2944 Handle(StepDimTol_GeometricTolerance) GT =
2945 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2946 // read common data for tolerance
2947 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2948 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2949 if(dim3.IsNull()) continue;
2950 Standard_Real dim = dim3->ValueComponent();
2951 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2952 Standard_Real afact=1.;
2953 if(anUnit.IsNull()) continue;
2954 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2955 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2956 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
2957 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
2958 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
2959 arr->SetValue(1,dim);
2960 Handle(TCollection_HAsciiString) aName = GT->Name();
2961 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2962 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2963 if(AF.IsNull()) continue;
2964 Standard_Integer index = aTP->MapIndex(AF);
2967 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2968 aSh = TransferBRep::ShapeResult(binder);
2970 if(aSh.IsNull()) continue;
2972 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2973 // read specific data for tolerance
2974 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2975 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2976 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2977 Standard_Integer kind=20;
2978 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2979 GTComplex->GetModifiedGeometricTolerance();
2981 kind = kind + MGT->Modifier()+1;
2983 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2984 // translate datums connected with this tolerance
2985 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2986 GTComplex->GetGeometricToleranceWithDatumReference();
2987 if(!GTWDR.IsNull()) {
2988 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2991 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2992 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2993 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2994 if(GTWDR.IsNull()) continue;
2995 Standard_Integer kind = 0;
2996 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2997 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2998 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2999 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
3000 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
3001 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
3002 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
3003 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
3004 //cout<<"GTWDR: kind="<<kind<<endl;
3005 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
3006 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
3008 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
3009 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3010 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
3011 Standard_Integer kind = 35 + MGT->Modifier();
3012 aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
3014 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
3015 aDGTTool->SetDimTol(shL,38,arr,aName,aDescription);
3017 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
3018 aDGTTool->SetDimTol(shL,39,arr,aName,aDescription);
3020 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
3021 aDGTTool->SetDimTol(shL,40,arr,aName,aDescription);
3023 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
3024 aDGTTool->SetDimTol(shL,41,arr,aName,aDescription);
3026 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
3027 aDGTTool->SetDimTol(shL,42,arr,aName,aDescription);
3029 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
3030 aDGTTool->SetDimTol(shL,43,arr,aName,aDescription);
3032 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
3033 aDGTTool->SetDimTol(shL,44,arr,aName,aDescription);
3039 if(aGISU.IsNull()) continue;
3040 Standard_Integer j =1;
3041 for ( ; j <= aGISU->NbIdentifiedItem(); j++) {
3042 aSeqRI.Append(aGISU->IdentifiedItemValue(j));
3046 if(!aSeqRI.IsEmpty())
3048 if(aSeqRI1.IsEmpty())
3055 if(aSeqRI1.IsEmpty())
3058 TDF_LabelSequence aShLS1, aShLS2;
3061 for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++)
3063 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
3066 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3067 aSh = TransferBRep::ShapeResult(aBinder);
3072 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3073 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3075 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3079 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3080 if (!edgeL.IsNull())
3081 aShLS1.Append(edgeL);
3086 aShLS1.Append(aShL);
3089 if (!aSeqRI2.IsEmpty())
3091 //for dimensional location
3092 for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++)
3094 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
3097 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3098 aSh = TransferBRep::ShapeResult(aBinder);
3103 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3104 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3106 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3110 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3111 if (!edgeL.IsNull())
3112 aShLS2.Append(edgeL);
3117 aShLS2.Append(aShL);
3122 if(!aShLS1.IsEmpty())
3125 if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3127 aGDTL = aDGTTool->AddDimension();
3128 myGDTMap.Bind(theEnt, aGDTL);
3129 aDGTTool->Lock(aGDTL);
3130 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3131 TCollection_AsciiString aStr("DGT:Dimensional_");
3132 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
3134 aStr.AssignCat("Size");
3136 else if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3138 aStr.AssignCat("Location");
3140 TDataStd_Name::Set(aGDTL, aStr);
3142 if(!aShLS2.IsEmpty())
3144 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
3148 TDF_LabelSequence aEmptySeq;
3149 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
3154 aGDTL = aDGTTool->AddGeomTolerance();
3155 myGDTMap.Bind(theEnt, aGDTL);
3156 aDGTTool->Lock(aGDTL);
3157 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
3158 TCollection_AsciiString aStr("DGT:GeomTolerance");
3159 TDataStd_Name::Set(aGDTL, aStr);
3160 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
3161 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
3163 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
3165 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
3166 aGTol->SetObject(anObj);
3171 TCollection_ExtendedString str(aSemanticName->String());
3172 TDataStd_Name::Set(aGDTL, str);
3175 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
3180 //=======================================================================
3181 //function : setDimObjectToXCAF
3183 //=======================================================================
3184 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3185 const TDF_Label& aDimL,
3186 const Handle(TDocStd_Document)& theDoc,
3187 const Handle(XSControl_WorkSession)& theWS)
3189 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3190 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3191 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3192 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3193 const Interface_Graph& aGraph = aTP->Graph();
3194 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
3195 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
3196 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3199 Handle(StepShape_DimensionalSize) aDimSize =
3200 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3201 Handle(StepShape_DimensionalLocation) aDimLocation =
3202 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
3204 aDimObj = new XCAFDimTolObjects_DimensionObject();
3205 Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
3206 Standard_Boolean isPlusMinusTolerance = Standard_False;
3207 Handle(StepShape_TypeQualifier) aTQ;
3208 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
3209 Handle(StepShape_ToleranceValue) aTV;
3210 Handle(StepShape_LimitsAndFits) aLAF;
3211 Handle(StepRepr_CompoundRepresentationItem) aCRI;
3212 Handle(StepGeom_Axis2Placement3d) anAP;
3214 Interface_EntityIterator anIterDim;
3215 if(!aDimSize.IsNull())
3217 anIterDim = aGraph.Sharings(aDimSize);
3221 anIterDim = aGraph.Sharings(aDimLocation);
3223 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
3224 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
3225 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
3226 Handle(StepShape_PlusMinusTolerance) aPMT =
3227 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
3228 if(!aDCR.IsNull()) {
3229 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
3230 if(!aSDR.IsNull()) {
3231 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
3235 for(Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
3237 Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
3238 if(aDRI.IsNull()) continue;
3240 if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
3241 // simple value / range
3242 Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
3243 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
3244 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3245 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3246 Standard_Real aFact = 1.;
3247 if (anUnit.IsNull())
3249 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3251 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3252 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3253 if (GetLengthConversionFactor(NU, aFact))
3254 aVal = aVal * aFact;
3257 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
3258 if (GetAngleConversionFactor(NU, aFact))
3259 aVal = aVal * aFact;
3261 Handle(TCollection_HAsciiString) aName = aMWU->Name();
3262 if (aName->Search("upper") > 0) // upper limit
3264 else // lower limit or simple nominal value
3267 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
3268 // value with qualifier (minimum/maximum/average)
3269 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
3270 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
3271 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3272 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3273 Standard_Real aFact = 1.;
3276 if( !(anUnit.CaseNum(anUnit.Value()) == 1) )
3278 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3279 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
3280 if (GetLengthConversionFactor(NU, aFact))
3281 aVal = aVal * aFact;
3284 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
3285 if (GetAngleConversionFactor(NU, aFact))
3286 aVal = aVal * aFact;
3288 Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
3289 if (aQRI->Qualifiers()->Length() == 0) {
3293 Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
3294 if (aValueType->Name()->String().IsEqual("minimum"))
3296 else if (aValueType->Name()->String().IsEqual("maximum"))
3300 else if(aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
3302 Handle(StepShape_QualifiedRepresentationItem) aQRI =
3303 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
3304 for(Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
3306 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
3307 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
3310 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3311 Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
3312 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
3313 aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
3315 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
3316 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
3318 else if(aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
3320 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
3326 else if (!aPMT.IsNull())
3328 isPlusMinusTolerance = Standard_True;
3329 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
3330 if(aPMT.IsNull()) continue;
3331 if(aTMD.CaseNumber() == 1)
3332 //! 1 -> ToleranceValue from StepShape
3333 //! 2 -> LimitsAndFits from StepShape
3335 //plus minus tolerance
3336 aTV = aTMD.ToleranceValue();
3337 if (aTV.IsNull()) continue;
3339 Standard_Real aVal = aTV->UpperBound()->ValueComponent();
3340 StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
3341 Standard_Real aFact=1.;
3342 if(anUnit.IsNull()) continue;
3343 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3344 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3345 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
3348 aVal = aTV->LowerBound()->ValueComponent();
3349 anUnit = aTV->LowerBound()->UnitComponent();
3351 if(anUnit.IsNull()) continue;
3352 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3353 NU = anUnit.NamedUnit();
3354 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
3359 // class of tolerance
3360 aLAF = aTMD.LimitsAndFits();
3368 aDimObj->SetValue(aDim1);
3371 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,2);
3372 anArr->SetValue(1,aDim1);
3373 anArr->SetValue(2,aDim2);
3374 aDimObj->SetValues(anArr);
3378 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,3);
3379 if (!isPlusMinusTolerance)
3381 aDim2 = aDim1 - aDim2;
3382 aDim3 = aDim3 - aDim1;
3384 anArr->SetValue(1,aDim1);
3385 anArr->SetValue(2,aDim2);
3386 anArr->SetValue(3,aDim3);
3387 aDimObj->SetValues(anArr);
3391 XCAFDimTolObjects_DimensionQualifier aQ;
3392 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
3394 aDimObj->SetQualifier(aQ);
3398 if (!aVFTQ.IsNull())
3400 //A typical value would be 'NR2 2.2'
3401 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
3402 Standard_Integer i = aFormat.Location(1,' ',1,aFormat.Length());
3403 aFormat.SubString(i+1,i+1)->IntegerValue();
3404 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i+1,i+1)->IntegerValue(),
3405 aFormat.SubString(i+3,i+3)->IntegerValue());
3410 //get class of tolerance
3411 Standard_Boolean aHolle = Standard_False;
3412 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
3413 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
3414 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
3415 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
3418 if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0)
3421 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
3422 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
3423 if(aModifiers.Length() > 0)
3424 aDimObj->SetModifiers(aModifiers);
3427 Handle(TCollection_HAsciiString) aName;
3428 if(!aDimSize.IsNull())
3430 aName = aDimSize->Name();
3434 aName = aDimLocation->Name();
3436 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
3437 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
3439 if(!aDimSize.IsNull())
3441 Handle(StepShape_AngularSize) anAngSize=
3442 Handle(StepShape_AngularSize)::DownCast(aDimSize);
3443 if(!anAngSize.IsNull())
3445 //get qualifier for angular value
3446 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
3447 if(anAngSize->AngleSelection() == StepShape_Equal)
3448 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3449 else if (anAngSize->AngleSelection() == StepShape_Large)
3450 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3451 else if (anAngSize->AngleSelection() == StepShape_Small)
3452 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3457 Handle(StepShape_AngularLocation) anAngLoc=
3458 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
3459 if(!anAngLoc.IsNull())
3461 //get qualifier for angular value
3462 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
3463 if(anAngLoc->AngleSelection() == StepShape_Equal)
3464 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3465 else if (anAngLoc->AngleSelection() == StepShape_Large)
3466 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3467 else if (anAngLoc->AngleSelection() == StepShape_Small)
3468 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3471 if(aType == XCAFDimTolObjects_DimensionType_Location_None)
3473 Handle(StepRepr_ShapeAspect) aPSA;
3474 if(!aDimSize.IsNull())
3476 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath=
3477 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
3478 if (!aDimSizeWithPath.IsNull())
3480 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
3481 aPSA = aDimSizeWithPath->Path();
3486 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath=
3487 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
3488 if (!aDimLocWithPath.IsNull())
3490 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
3491 aPSA = aDimLocWithPath->Path();
3497 //for DimensionalLocationWithPath
3498 Handle(StepGeom_GeometricRepresentationItem) aGRI;
3499 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
3500 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
3501 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
3502 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
3504 if(aPGISU.IsNull()) return;
3505 if(aPGISU->NbIdentifiedItem() > 0) {
3506 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
3508 if(aGRI.IsNull()) return;
3509 Handle(StepRepr_RepresentationItem) aPRI;
3510 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
3511 for(anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
3512 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
3514 Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
3517 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3518 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
3520 if(aSh.IsNull()) return;
3521 aDimObj->SetPath(aSh);
3523 else if(!anAP.IsNull())
3525 if(anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
3527 //for Oriented Dimensional Location
3528 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
3530 if(!aDirArr.IsNull() && aDirArr->Length() > 2)
3532 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
3533 aDimObj->SetDirection(aDir);
3535 else if(aDirArr->Length() > 1)
3537 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, 0);
3538 aDimObj->SetDirection(aDir);
3544 aDimObj->SetType(aType);
3547 if(!aDimObj.IsNull())
3550 Handle(XCAFDoc_Dimension) aDim;
3552 if(aDimL.FindAttribute(XCAFDoc_Dimension::GetID(),aDim))
3554 readAnnotation(aTR, theEnt, aDimObj);
3555 readConnectionPoints(aTR, theEnt, aDimObj);
3556 aDim->SetObject(aDimObj);
3561 //=======================================================================
3562 //function : getTolType
3564 //=======================================================================
3565 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
3566 XCAFDimTolObjects_GeomToleranceType& theType)
3568 if(theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3569 return Standard_False;
3570 theType = XCAFDimTolObjects_GeomToleranceType_None;
3571 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
3573 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
3574 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3576 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3578 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
3579 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
3580 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3582 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3584 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
3585 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
3586 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3588 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3590 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
3591 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
3592 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3594 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3596 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
3597 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
3598 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3600 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3602 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3603 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3604 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3606 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3608 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3610 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3612 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3614 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3616 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3618 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3620 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3622 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3624 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3626 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3628 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3630 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3632 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3634 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3636 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3638 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3640 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3642 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3643 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3645 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3647 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3649 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3651 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3653 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3655 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3657 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3659 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3661 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3663 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3665 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3667 return Standard_True;
3669 //=======================================================================
3670 //function : setGeomTolObjectToXCAF
3672 //=======================================================================
3673 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3674 const TDF_Label& theTolL,
3675 const Handle(TDocStd_Document)& theDoc,
3676 const Handle(XSControl_WorkSession)& theWS)
3678 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3679 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3680 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3681 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3682 const Interface_Graph& aGraph = aTP->Graph();
3683 Handle(XCAFDoc_GeomTolerance) aGTol;
3684 if(!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3688 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3689 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3691 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3692 getTolType(theEnt, aType);
3693 aTolObj->SetType(aType);
3694 if(!aTolEnt->Magnitude().IsNull()){
3696 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3697 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3698 Standard_Real aFact=1.;
3699 if(anUnit.IsNull()) return;
3700 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3701 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3702 if(GetLengthConversionFactor(NU,aFact))
3704 aTolObj->SetValue(aVal);
3707 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3708 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3709 for(anIter.Start(); anIter.More(); anIter.Next()) {
3710 if(anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))){
3711 Handle(StepDimTol_ToleranceZoneForm) aForm
3712 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3713 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3714 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3715 for(anIt.Start(); anIt.More(); anIt.Next()) {
3716 if(anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))){
3717 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3718 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3719 if(!aPZone->ProjectionLength().IsNull())
3721 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3722 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3723 Standard_Real aFact=1.;
3724 if(anUnit.IsNull()) return;
3725 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3726 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3727 if(GetLengthConversionFactor(NU,aFact))
3729 aTolObj->SetValueOfZoneModifier(aVal);
3730 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3733 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3735 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3736 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3737 if(!aRZone->Orientation().IsNull())
3739 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3740 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3741 Standard_Real aFact=1.;
3742 if(anUnit.IsNull()) continue;
3743 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3744 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3745 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
3746 aTolObj->SetValueOfZoneModifier(aVal);
3747 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
3751 aTolObj->SetTypeOfValue(aTypeV);
3754 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
3755 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
3757 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
3759 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3761 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
3762 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3764 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3766 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
3767 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3769 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3771 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
3772 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3774 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3776 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
3777 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3779 if(!aModifiers.IsNull())
3781 for(Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
3783 if(aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
3784 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
3785 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
3786 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
3788 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
3791 Standard_Real aVal = 0;
3792 StepBasic_Unit anUnit;
3793 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
3795 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
3796 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
3797 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
3799 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3801 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
3802 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3803 aVal = aMax->GetMaxTolerance()->ValueComponent();
3804 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3806 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3808 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
3809 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3810 aVal = aMax->GetMaxTolerance()->ValueComponent();
3811 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3813 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
3815 Standard_Real aFact=1.;
3816 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3817 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
3818 aTolObj->SetMaxValueModifier(aVal);
3821 readAnnotation(aTR, theEnt, aTolObj);
3822 aGTol->SetObject(aTolObj);
3825 //=======================================================================
3826 //function : ReadGDTs
3828 //=======================================================================
3830 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
3831 Handle(TDocStd_Document)& theDoc)
3833 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
3834 const Interface_Graph& aGraph = theWS->Graph();
3835 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3836 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
3837 Interface_EntityIterator anI = aSM->Header();
3838 Handle(HeaderSection_FileSchema) aH;
3839 for(anI.Start(); anI.More() && aH.IsNull();anI.Next())
3840 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
3841 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3842 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3843 if ( aDGTTool.IsNull() ) return Standard_False;
3845 Standard_Integer nb = aModel->NbEntities();
3846 for(Standard_Integer i=1; i<=nb; i++) {
3847 Handle(Standard_Transient) anEnt = aModel->Value(i);
3848 if(anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3849 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3850 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3851 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt,theDoc,theWS);
3852 if(!aGDTL.IsNull()){
3853 if(anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))){
3854 setGeomTolObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3857 setDimObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3861 else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
3862 anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
3864 // Protection against import presentation twice
3865 Handle(StepVisual_DraughtingCallout) aDC;
3866 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
3867 aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
3871 // Read presentations for PMIs without semantic data.
3872 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
3873 TDF_LabelSequence aShapesL;
3874 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
3875 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
3877 if (!aDMIA.IsNull()) {
3878 // Check entity, skip all, attached to GDTs
3879 Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
3880 if (!aDefinition.IsNull()) {
3881 Standard_Boolean isConnectedToGDT = Standard_False;
3882 // Skip if definition is a datum
3883 if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3884 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3885 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3886 aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3887 isConnectedToGDT = Standard_True;
3889 // Skip if any GDT is applied to definition
3890 for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
3891 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3892 anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3893 anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3894 isConnectedToGDT = Standard_True;
3897 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
3898 if (!aSAR.IsNull()) {
3899 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
3900 if (!aSA.IsNull()) {
3901 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3902 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3903 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3904 aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3905 isConnectedToGDT = Standard_True;
3907 for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
3908 if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3909 aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3910 aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3911 isConnectedToGDT = Standard_True;
3918 if (isConnectedToGDT)
3921 else if (aDMIA->Definition().PropertyDefinition().IsNull())
3925 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
3926 collectShapeAspect(aDefinition, theWS, aSAs);
3927 for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
3928 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
3929 for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
3930 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
3933 for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
3934 TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
3935 if (!aLabel.IsNull())
3936 aShapesL.Append(aLabel);
3940 Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
3943 Standard_Real aFact = 1.0;
3944 if (!aDMIA.IsNull() && !aDMIA->UsedRepresentation().IsNull())
3945 GetLengthConversionFactorFromContext(aDMIA->UsedRepresentation()->ContextOfItems(), aFact);
3948 TopoDS_Shape aPresentation;
3949 Handle(TCollection_HAsciiString) aPresentName;
3951 if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
3954 Handle(StepVisual_AnnotationPlane) anAnPlane;
3955 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
3956 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
3958 // Set object to XCAF
3959 TDF_Label aGDTL = aDGTTool->AddDimension();
3960 myGDTMap.Bind(anEnt, aGDTL);
3961 aDGTTool->Lock(aGDTL);
3962 Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
3963 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3964 TCollection_AsciiString aStr("DGT:");
3965 if (isCommonLabel) {
3966 aStr.AssignCat("Common_label");
3967 aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
3970 aStr.AssignCat("Dimension");
3971 aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
3973 TDataStd_Name::Set(aGDTL, aStr);
3974 TDF_LabelSequence anEmptySeq2;
3975 aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
3977 if (!anAnPlane.IsNull()) {
3978 if (readAnnotationPlane(anAnPlane, aFact, aPlaneAxes))
3979 aDimObj->SetPlane(aPlaneAxes);
3981 aDimObj->SetPresentation(aPresentation, aPresentName);
3982 aDim->SetObject(aDimObj);
3985 return Standard_True;
3989 //=======================================================================
3990 //function : FindSolidForPDS
3991 //purpose : auxilary
3992 //=======================================================================
3994 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
3995 const Interface_Graph &graph)
3997 Handle(StepShape_SolidModel) SM;
3998 Interface_EntityIterator subs = graph.Sharings(PDS);
3999 Handle(StepShape_ShapeRepresentation) SR;
4000 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
4001 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
4002 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
4003 if(SDR.IsNull()) continue;
4004 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
4005 if(SR.IsNull()) continue;
4006 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
4007 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
4010 Interface_EntityIterator subs1 = graph.Sharings(SR);
4011 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
4012 Handle(StepRepr_RepresentationRelationship) RR =
4013 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
4014 if(RR.IsNull()) continue;
4015 Handle(StepShape_ShapeRepresentation) SR2;
4016 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
4017 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
4018 if(SR2.IsNull()) continue;
4019 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
4020 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
4029 //=======================================================================
4030 //function : ReadMaterials
4032 //=======================================================================
4034 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
4035 Handle(TDocStd_Document)& Doc,
4036 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
4038 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
4039 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
4040 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
4041 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
4042 if(MatTool.IsNull()) return Standard_False;
4044 const Interface_Graph& graph = TP->Graph();
4045 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
4046 Handle(StepRepr_ProductDefinitionShape) PDS =
4047 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
4050 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
4051 if(aProdDef.IsNull())
4053 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
4054 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
4055 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
4056 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
4057 Standard_Real aDensity=0;
4058 Interface_EntityIterator subs = graph.Sharings( aProdDef);
4059 for(subs.Start(); subs.More(); subs.Next()) {
4060 Handle(StepRepr_PropertyDefinition) PropD =
4061 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
4062 if(PropD.IsNull()) continue;
4063 Interface_EntityIterator subs1 = graph.Sharings(PropD);
4064 for(subs1.Start(); subs1.More(); subs1.Next()) {
4065 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
4066 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
4067 if(PDR.IsNull()) continue;
4068 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
4069 if(Repr.IsNull()) continue;
4070 Standard_Integer ir;
4071 for(ir=1; ir<=Repr->NbItems(); ir++) {
4072 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
4073 if(RI.IsNull()) continue;
4074 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
4075 // find name and description for material
4076 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
4077 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
4078 aName = DRI->Name();
4080 aDescription = DRI->Description();
4082 aName = aDescription;
4084 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
4085 // try to find density for material
4086 Handle(StepRepr_MeasureRepresentationItem) MRI =
4087 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
4088 aDensity = MRI->Measure()->ValueComponent();
4089 aDensName = MRI->Name();
4090 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
4091 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
4092 if(!aUnit.IsNull()) {
4093 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
4094 if(DU.IsNull()) continue;
4095 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
4096 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
4097 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
4098 Standard_Real afact=1.;
4099 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
4100 if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact);
4101 // transfer length value for Density from millimeter to santimeter
4102 // in order to result density has dimension gram/(sm*sm*sm)
4103 aDensity = aDensity*1000.;
4105 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
4106 if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact;
4115 if( aName.IsNull() || aName->Length()==0 )
4117 // find shape label amd create Material link
4119 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
4121 Standard_Integer index = TP->MapIndex(SM);
4123 Handle(Transfer_Binder) binder = TP->MapItem(index);
4124 if(!binder.IsNull())
4125 aSh = TransferBRep::ShapeResult(binder);
4128 if(aSh.IsNull()) continue;
4130 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
4131 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
4134 return Standard_True;
4137 //=======================================================================
4138 //function : collectViewShapes
4139 //purpose : collect all labels of representations in given representation
4140 //=======================================================================
4142 void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
4143 const Handle(TDocStd_Document)& theDoc,
4144 const Handle(StepRepr_Representation) theRepr,
4145 TDF_LabelSequence& theShapes)
4147 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4148 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4149 const Interface_Graph& aGraph = aTP->Graph();
4150 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4151 Standard_Integer anIndex = aTP->MapIndex(theRepr);
4154 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
4155 aSh = TransferBRep::ShapeResult(aBinder);
4157 if (!aSh.IsNull()) {
4159 aSTool->FindShape(aSh, aShL);
4161 theShapes.Append(aShL);
4163 Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
4164 for (; anIter.More(); anIter.Next()) {
4165 if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
4167 Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
4168 if (aReprRelationship->Rep1() != theRepr)
4169 collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
4173 //=======================================================================
4174 //function : buildClippingPlanes
4176 //=======================================================================
4177 Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
4178 TDF_LabelSequence& theClippingPlanes,
4179 const Handle(XCAFDoc_ClippingPlaneTool) theTool)
4181 Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
4182 NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
4183 Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
4186 if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
4187 Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
4188 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
4189 // Root of clipping planes tree
4190 if (aCameraModel->ShapeClipping()->Length() == 1) {
4191 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
4192 aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
4193 if (!aCameraModelUnion.IsNull())
4194 return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
4196 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4197 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4200 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
4201 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
4202 Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
4203 anOperation = new TCollection_HAsciiString("+");
4204 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4205 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4208 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
4209 Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
4210 Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
4211 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4212 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4216 anExpression->AssignCat("(");
4217 for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
4218 Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
4219 if (!aPlaneEnt.IsNull()) {
4220 Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
4221 if (!aPlane.IsNull()) {
4222 TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
4223 theClippingPlanes.Append(aPlaneL);
4224 TCollection_AsciiString anEntry;
4225 TDF_Tool::Entry(aPlaneL, anEntry);
4226 anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
4230 anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
4232 anExpression->AssignCat(anOperation);
4234 // Insert brace instead of operation after last operand.
4235 anExpression->SetValue(anExpression->Length(), ')');
4236 return anExpression;
4240 //=======================================================================
4241 //function : ReadViews
4243 //=======================================================================
4244 Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
4246 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4247 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4248 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4249 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
4250 if (aDGTTool.IsNull()) return Standard_False;
4252 Standard_Integer nb = aModel->NbEntities();
4253 for (Standard_Integer i = 1; i <= nb; i++) {
4254 Handle(Standard_Transient) anEnt = aModel->Value(i);
4255 if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
4257 Handle(XCAFView_Object) anObj = new XCAFView_Object();
4258 // Import attributes of view
4259 Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
4260 anObj->SetName(aCameraModel->Name());
4261 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
4262 anObj->SetViewDirection(anAxis->Direction());
4263 anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
4264 Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
4265 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
4266 if (aViewVolume->ProjectionType() == StepVisual_copCentral)
4267 aType = XCAFView_ProjectionType_Central;
4268 else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
4269 aType = XCAFView_ProjectionType_Parallel;
4270 anObj->SetType(aType);
4271 Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
4272 anObj->SetProjectionPoint(aPoint->Pnt());
4273 anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
4274 anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
4275 anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
4276 if (aViewVolume->FrontPlaneClipping())
4277 anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
4278 if (aViewVolume->BackPlaneClipping())
4279 anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
4280 anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
4282 Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
4283 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
4284 TDF_LabelSequence aClippingPlanes;
4285 if (!aClippingCameraModel.IsNull()) {
4286 Handle(TCollection_HAsciiString) aClippingExpression;
4287 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
4288 aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
4289 anObj->SetClippingExpression(aClippingExpression);
4291 // Collect shapes and GDTs
4292 TDF_LabelSequence aShapes, aGDTs;
4293 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4294 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4295 const Interface_Graph& aGraph = aTP->Graph();
4296 Handle(StepVisual_DraughtingModel) aDModel;
4297 Interface_EntityIterator anIter = aGraph.Sharings(aCameraModel);
4298 for (; anIter.More() && aDModel.IsNull(); anIter.Next()) {
4299 aDModel = Handle(StepVisual_DraughtingModel)::DownCast(anIter.Value());
4301 if (aDModel.IsNull())
4302 return Standard_False;
4304 anIter = aGraph.Shareds(aDModel);
4305 for (; anIter.More(); anIter.Next()) {
4306 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
4307 Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
4308 Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
4309 collectViewShapes(theWS, theDoc, aRepr, aShapes);
4311 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
4312 anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
4313 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4314 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4315 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4317 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4318 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4320 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4322 isFind = myGDTMap.Find(anIter.Value(), aGDTL);
4325 aGDTs.Append(aGDTL);
4328 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
4329 Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4330 for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
4331 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4332 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4333 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4335 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4336 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4338 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4340 aGDTs.Append(aGDTL);
4345 TDF_Label aViewL = aViewTool->AddView();
4346 Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
4347 aView->SetObject(anObj);
4348 aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
4349 aViewTool->Lock(aViewL);
4351 return Standard_True;
4354 //=======================================================================
4355 //function : SettleShapeData
4357 //=======================================================================
4359 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
4360 const TDF_Label& theLab,
4361 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
4362 const Handle(Transfer_TransientProcess)& TP) const
4364 TDF_Label aResult = theLab;
4366 Handle(TCollection_HAsciiString) hName = theItem->Name();
4367 if ( hName.IsNull() || hName->IsEmpty() )
4370 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
4371 if ( aBinder.IsNull() )
4374 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
4375 if ( aShape.IsNull() )
4378 // Allocate sub-Label
4379 aResult = theShapeTool->AddSubShape(theLab, aShape);
4380 if (aResult.IsNull())
4383 TCollection_AsciiString aName = hName->String();
4384 TDataStd_Name::Set(aResult, aName);
4385 theShapeTool->SetShape(aResult, aShape);
4390 //=======================================================================
4391 //function : collectRepresentationItems
4392 //purpose : recursive collection of representation items for given representation
4393 // with all representations, related to it.
4394 //=======================================================================
4396 void collectRepresentationItems(const Interface_Graph& theGraph,
4397 const Handle(StepShape_ShapeRepresentation)& theRepresentation,
4398 NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
4400 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items();
4401 for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++)
4402 theItems.Append(aReprItems->Value(itemIt));
4404 Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
4405 for (entIt.Start(); entIt.More(); entIt.Next())
4407 Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
4408 if (aRelationship->Rep1() == theRepresentation)
4410 Handle(StepShape_ShapeRepresentation)
4411 aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
4412 if (!aRepr.IsNull())
4413 collectRepresentationItems(theGraph, aRepr, theItems);
4418 //=======================================================================
4419 //function : ExpandSubShapes
4421 //=======================================================================
4423 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
4424 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
4425 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
4427 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
4428 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
4429 TColStd_MapOfTransient aRepItems;
4431 // Read translation control variables
4432 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
4434 if ( !doReadSNames )
4437 const Interface_Graph& Graph = Reader().WS()->Graph();
4439 for ( STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next() )
4441 const TopoDS_Shape& aRootShape = it.Key();
4442 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
4443 if ( aPDef.IsNull() )
4446 // Find SDR by Product
4447 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
4448 Interface_EntityIterator entIt = Graph.TypedSharings( aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation) );
4449 for ( entIt.Start(); entIt.More(); entIt.Next() )
4451 const Handle(Standard_Transient)& aReferer = entIt.Value();
4452 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
4453 if ( !aSDR.IsNull() )
4457 if ( aSDR.IsNull() )
4460 // Access shape representation
4461 Handle(StepShape_ShapeRepresentation)
4462 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast( aSDR->UsedRepresentation() );
4464 if ( aShapeRepr.IsNull() )
4467 // Access representation items
4468 NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
4469 collectRepresentationItems(Graph, aShapeRepr, aReprItems);
4471 if (aReprItems.Length() == 0)
4474 if ( !ShapeLabelMap.IsBound(aRootShape) )
4477 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
4478 // Do not add subshapes to assembly,
4479 // they will be processed with corresponding Shape_Product_Definition of necessary part.
4480 if (ShapeTool->IsAssembly(aRootLab))
4483 StepRepr_SequenceOfRepresentationItem aMSBSeq;
4484 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
4486 // Iterate over the top level representation items collecting the
4487 // topological containers to expand
4488 for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
4490 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
4491 if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
4492 aMSBSeq.Append(aTRepr);
4493 else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) )
4494 aSBSMSeq.Append(aTRepr);
4497 // Insert intermediate OCAF Labels for SOLIDs in case there are more
4498 // than one Manifold Solid BRep in the Shape Representation
4499 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
4501 // Expand Manifold Solid BReps
4502 for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i )
4504 // Put additional Label for SOLID
4505 if (doInsertSolidLab)
4506 SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
4508 ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
4511 // Expand Shell-Based Surface Models
4512 for ( Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i )
4513 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
4517 //=======================================================================
4518 //function : ExpandManifoldSolidBrep
4520 //=======================================================================
4522 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
4523 const Handle(StepRepr_RepresentationItem)& Repr,
4524 const Handle(Transfer_TransientProcess)& TP,
4525 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4527 // Access outer shell
4528 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
4529 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
4531 // Expand shell contents to CAF tree
4532 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
4535 //=======================================================================
4536 //function : ExpandSBSM
4538 //=======================================================================
4540 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
4541 const Handle(StepRepr_RepresentationItem)& Repr,
4542 const Handle(Transfer_TransientProcess)& TP,
4543 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4545 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
4547 // Access boundary shells
4548 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
4549 for ( Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s )
4551 const StepShape_Shell& aShell = aShells->Value(s);
4552 Handle(StepShape_ConnectedFaceSet) aCFS;
4553 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
4554 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
4556 if ( !anOpenShell.IsNull() )
4559 aCFS = aClosedShell;
4561 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
4565 //=======================================================================
4566 //function : ExpandShell
4568 //=======================================================================
4570 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
4572 const Handle(Transfer_TransientProcess)& TP,
4573 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4576 SettleShapeData(Shell, RootLab, ShapeTool, TP);
4579 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
4580 for ( Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f )
4582 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
4587 SettleShapeData(aFace, RootLab, ShapeTool, TP);
4589 // Access face bounds
4590 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
4591 for ( Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w )
4593 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
4596 SettleShapeData(aWire, RootLab, ShapeTool, TP);
4598 // Access wire edges
4599 // Currently only EDGE LOOPs are considered (!)
4600 if ( !aWire->IsInstance( STANDARD_TYPE(StepShape_EdgeLoop) ) )
4604 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
4605 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
4606 for ( Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e )
4608 Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement();
4611 SettleShapeData(anEdge, RootLab, ShapeTool, TP);
4614 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
4615 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
4618 SettleShapeData(aV1, RootLab, ShapeTool, TP);
4619 SettleShapeData(aV2, RootLab, ShapeTool, TP);
4625 //=======================================================================
4626 //function : SetColorMode
4628 //=======================================================================
4630 void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
4632 myColorMode = colormode;
4635 //=======================================================================
4636 //function : GetColorMode
4638 //=======================================================================
4640 Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
4645 //=======================================================================
4646 //function : SetNameMode
4648 //=======================================================================
4650 void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
4652 myNameMode = namemode;
4655 //=======================================================================
4656 //function : GetNameMode
4658 //=======================================================================
4660 Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
4665 //=======================================================================
4666 //function : SetLayerMode
4668 //=======================================================================
4670 void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
4672 myLayerMode = layermode;
4675 //=======================================================================
4676 //function : GetLayerMode
4678 //=======================================================================
4680 Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
4685 //=======================================================================
4686 //function : SetPropsMode
4688 //=======================================================================
4690 void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
4692 myPropsMode = propsmode;
4695 //=======================================================================
4696 //function : GetPropsMode
4698 //=======================================================================
4700 Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
4705 //=======================================================================
4706 //function : SetSHUOMode
4708 //=======================================================================
4710 void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
4715 //=======================================================================
4716 //function : GetSHUOMode
4718 //=======================================================================
4720 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
4725 //=======================================================================
4726 //function : SetGDTMode
4728 //=======================================================================
4730 void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
4732 myGDTMode = gdtmode;
4735 //=======================================================================
4736 //function : GetGDTMode
4738 //=======================================================================
4740 Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
4746 //=======================================================================
4747 //function : SetMatMode
4749 //=======================================================================
4751 void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
4753 myMatMode = matmode;
4756 //=======================================================================
4757 //function : GetMatMode
4759 //=======================================================================
4761 Standard_Boolean STEPCAFControl_Reader::GetMatMode () const
4766 //=======================================================================
4767 //function : SetViewMode
4769 //=======================================================================
4771 void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
4773 myViewMode = viewmode;
4776 //=======================================================================
4777 //function : GetViewMode
4779 //=======================================================================
4781 Standard_Boolean STEPCAFControl_Reader::GetViewMode() const