Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-08-15 |
2 | // Created by: Andrey BETENEV | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
7fd59977 | 16 | |
42cf5bc1 | 17 | #include <BRep_Builder.hxx> |
400af1bc | 18 | #include <Geom_Axis2Placement.hxx> |
0c63f2f8 | 19 | #include <Geom_CartesianPoint.hxx> |
20 | #include <Geom_Plane.hxx> | |
42cf5bc1 | 21 | #include <Interface_EntityIterator.hxx> |
7fd59977 | 22 | #include <Interface_InterfaceModel.hxx> |
1c9d3225 | 23 | #include <StepData_StepModel.hxx> |
24 | #include <HeaderSection_FileSchema.hxx> | |
42cf5bc1 | 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> | |
1c9d3225 | 31 | #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx> |
42cf5bc1 | 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> | |
7fd59977 | 38 | #include <StepBasic_Product.hxx> |
39 | #include <StepBasic_ProductDefinition.hxx> | |
7fd59977 | 40 | #include <StepBasic_ProductDefinitionFormation.hxx> |
42cf5bc1 | 41 | #include <StepBasic_ProductDefinitionRelationship.hxx> |
42 | #include <StepBasic_SiUnit.hxx> | |
fe0d928d | 43 | #include <StepBasic_SiUnitAndLengthUnit.hxx> |
42cf5bc1 | 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> | |
42cf5bc1 | 50 | #include <STEPCAFControl_ExternFile.hxx> |
51 | #include <STEPCAFControl_Reader.hxx> | |
7fd59977 | 52 | #include <STEPConstruct.hxx> |
42cf5bc1 | 53 | #include <STEPConstruct_Assembly.hxx> |
7fd59977 | 54 | #include <STEPConstruct_ExternRefs.hxx> |
42cf5bc1 | 55 | #include <STEPConstruct_Styles.hxx> |
56 | #include <STEPConstruct_Tool.hxx> | |
7fd59977 | 57 | #include <STEPConstruct_UnitContext.hxx> |
7fd59977 | 58 | #include <STEPConstruct_ValidationProps.hxx> |
477000eb | 59 | #include <STEPControl_ActorRead.hxx> |
42cf5bc1 | 60 | #include <STEPControl_Reader.hxx> |
1c9d3225 | 61 | #include <StepGeom_GeometricRepresentationItem.hxx> |
62 | #include <StepGeom_Axis2Placement3d.hxx> | |
63 | #include <StepGeom_Direction.hxx> | |
42cf5bc1 | 64 | #include <StepDimTol_AngularityTolerance.hxx> |
65 | #include <StepDimTol_CircularRunoutTolerance.hxx> | |
66 | #include <StepDimTol_CoaxialityTolerance.hxx> | |
67 | #include <StepDimTol_ConcentricityTolerance.hxx> | |
68 | #include <StepDimTol_CylindricityTolerance.hxx> | |
69 | #include <StepDimTol_Datum.hxx> | |
70 | #include <StepDimTol_DatumFeature.hxx> | |
71 | #include <StepDimTol_DatumReference.hxx> | |
1c9d3225 | 72 | #include <StepDimTol_DatumReferenceElement.hxx> |
73 | #include <StepDimTol_DatumReferenceCompartment.hxx> | |
74 | #include <StepDimTol_DatumSystem.hxx> | |
42cf5bc1 | 75 | #include <StepDimTol_FlatnessTolerance.hxx> |
76 | #include <StepDimTol_GeometricTolerance.hxx> | |
77 | #include <StepDimTol_GeometricToleranceWithDatumReference.hxx> | |
78 | #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx> | |
1c9d3225 | 79 | #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx> |
6595eee7 | 80 | #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx> |
81 | #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx> | |
82 | #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx> | |
42cf5bc1 | 83 | #include <StepDimTol_HArray1OfDatumReference.hxx> |
84 | #include <StepDimTol_LineProfileTolerance.hxx> | |
85 | #include <StepDimTol_ModifiedGeometricTolerance.hxx> | |
86 | #include <StepDimTol_ParallelismTolerance.hxx> | |
87 | #include <StepDimTol_PerpendicularityTolerance.hxx> | |
88 | #include <StepDimTol_PositionTolerance.hxx> | |
1c9d3225 | 89 | #include <StepDimTol_ProjectedZoneDefinition.hxx> |
42cf5bc1 | 90 | #include <StepDimTol_RoundnessTolerance.hxx> |
1c9d3225 | 91 | #include <StepDimTol_RunoutZoneDefinition.hxx> |
42cf5bc1 | 92 | #include <StepDimTol_StraightnessTolerance.hxx> |
93 | #include <StepDimTol_SurfaceProfileTolerance.hxx> | |
94 | #include <StepDimTol_SymmetryTolerance.hxx> | |
1c9d3225 | 95 | #include <StepDimTol_ToleranceZone.hxx> |
96 | #include <StepDimTol_ToleranceZoneForm.hxx> | |
42cf5bc1 | 97 | #include <StepDimTol_TotalRunoutTolerance.hxx> |
1c9d3225 | 98 | #include <StepDimTol_GeometricToleranceWithModifiers.hxx> |
99 | #include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx> | |
100 | #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx> | |
101 | #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx> | |
102 | #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx> | |
5df609e7 | 103 | #include <StepGeom_Axis2Placement3d.hxx> |
fe0d928d | 104 | #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx> |
105 | #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx> | |
5df609e7 | 106 | #include <StepGeom_Plane.hxx> |
107 | #include <StepGeom_Polyline.hxx> | |
1c9d3225 | 108 | #include <StepDimTol_PlacedDatumTargetFeature.hxx> |
42cf5bc1 | 109 | #include <StepRepr_AssemblyComponentUsage.hxx> |
110 | #include <StepRepr_CharacterizedDefinition.hxx> | |
1c9d3225 | 111 | #include <StepRepr_CompoundRepresentationItem.hxx> |
b7b2f85a | 112 | #include <StepRepr_DerivedShapeAspect.hxx> |
42cf5bc1 | 113 | #include <StepRepr_DescriptiveRepresentationItem.hxx> |
114 | #include <StepRepr_HArray1OfRepresentationItem.hxx> | |
0c63f2f8 | 115 | #include <StepRepr_MappedItem.hxx> |
42cf5bc1 | 116 | #include <StepRepr_MeasureRepresentationItem.hxx> |
117 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> | |
118 | #include <StepRepr_ProductDefinitionShape.hxx> | |
119 | #include <StepRepr_PropertyDefinition.hxx> | |
120 | #include <StepRepr_PropertyDefinitionRepresentation.hxx> | |
7fd59977 | 121 | #include <StepRepr_Representation.hxx> |
42cf5bc1 | 122 | #include <StepRepr_RepresentationItem.hxx> |
1c9d3225 | 123 | #include <StepRepr_HArray1OfRepresentationItem.hxx> |
0c63f2f8 | 124 | #include <StepRepr_RepresentationMap.hxx> |
42cf5bc1 | 125 | #include <StepRepr_RepresentationRelationship.hxx> |
126 | #include <StepRepr_RepresentedDefinition.hxx> | |
127 | #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx> | |
5b7f8e0a | 128 | #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx> |
1c9d3225 | 129 | #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx> |
5b7f8e0a | 130 | #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx> |
42cf5bc1 | 131 | #include <StepRepr_SequenceOfRepresentationItem.hxx> |
132 | #include <StepRepr_ShapeAspect.hxx> | |
b7b2f85a | 133 | #include <StepRepr_ShapeAspectDerivingRelationship.hxx> |
1c9d3225 | 134 | #include <StepRepr_CompositeShapeAspect.hxx> |
135 | #include <StepRepr_AllAroundShapeAspect.hxx> | |
136 | #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx> | |
42cf5bc1 | 137 | #include <StepRepr_ShapeAspectRelationship.hxx> |
7fd59977 | 138 | #include <StepRepr_ShapeRepresentationRelationship.hxx> |
42cf5bc1 | 139 | #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx> |
140 | #include <StepRepr_ValueRange.hxx> | |
1c9d3225 | 141 | #include <StepRepr_FeatureForDatumTargetRelationship.hxx> |
42cf5bc1 | 142 | #include <StepShape_AdvancedFace.hxx> |
1c9d3225 | 143 | #include <StepShape_AdvancedBrepShapeRepresentation.hxx> |
144 | #include <StepShape_AngleRelator.hxx> | |
145 | #include <StepShape_AngularSize.hxx> | |
146 | #include <StepShape_AngularLocation.hxx> | |
42cf5bc1 | 147 | #include <StepShape_ClosedShell.hxx> |
148 | #include <StepShape_ConnectedFaceSet.hxx> | |
149 | #include <StepShape_ContextDependentShapeRepresentation.hxx> | |
1c9d3225 | 150 | #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx> |
151 | #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx> | |
42cf5bc1 | 152 | #include <StepShape_DimensionalCharacteristicRepresentation.hxx> |
1c9d3225 | 153 | #include <StepShape_DimensionalSizeWithPath.hxx> |
154 | #include <StepShape_DimensionalLocationWithPath.hxx> | |
155 | #include <StepShape_ShapeDimensionRepresentationItem.hxx> | |
156 | #include <StepShape_ShapeRepresentationWithParameters.hxx> | |
157 | #include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx> | |
42cf5bc1 | 158 | #include <StepShape_DimensionalSize.hxx> |
1c9d3225 | 159 | #include <StepShape_DimensionalLocation.hxx> |
42cf5bc1 | 160 | #include <StepShape_EdgeCurve.hxx> |
161 | #include <StepShape_EdgeLoop.hxx> | |
5df609e7 | 162 | #include <StepShape_GeometricCurveSet.hxx> |
42cf5bc1 | 163 | #include <StepShape_GeometricSet.hxx> |
164 | #include <StepShape_HArray1OfFace.hxx> | |
165 | #include <StepShape_HArray1OfFaceBound.hxx> | |
166 | #include <StepShape_HArray1OfOrientedEdge.hxx> | |
167 | #include <StepShape_HArray1OfShell.hxx> | |
1c9d3225 | 168 | #include <StepShape_LimitsAndFits.hxx> |
42cf5bc1 | 169 | #include <StepShape_Loop.hxx> |
170 | #include <StepShape_ManifoldSolidBrep.hxx> | |
1c9d3225 | 171 | #include <StepShape_PlusMinusTolerance.hxx> |
172 | #include <StepShape_QualifiedRepresentationItem.hxx> | |
42cf5bc1 | 173 | #include <StepShape_OpenShell.hxx> |
174 | #include <StepShape_ShapeDefinitionRepresentation.hxx> | |
175 | #include <StepShape_ShapeDimensionRepresentation.hxx> | |
176 | #include <StepShape_ShapeRepresentation.hxx> | |
177 | #include <StepShape_ShellBasedSurfaceModel.hxx> | |
178 | #include <StepShape_SolidModel.hxx> | |
1c9d3225 | 179 | #include <StepShape_ToleranceMethodDefinition.hxx> |
180 | #include <StepShape_ToleranceValue.hxx> | |
181 | #include <StepShape_ValueFormatTypeQualifier.hxx> | |
42cf5bc1 | 182 | #include <StepShape_Vertex.hxx> |
400af1bc | 183 | #include <StepToGeom.hxx> |
5df609e7 | 184 | #include <StepVisual_AnnotationCurveOccurrence.hxx> |
1209c1b9 | 185 | #include <StepVisual_AnnotationFillArea.hxx> |
5df609e7 | 186 | #include <StepVisual_AnnotationPlane.hxx> |
0c63f2f8 | 187 | #include <StepVisual_CameraModelD3.hxx> |
188 | #include <StepVisual_CameraModelD3MultiClipping.hxx> | |
189 | #include <StepVisual_CameraModelD3MultiClippingIntersection.hxx> | |
190 | #include <StepVisual_CameraModelD3MultiClippingUnion.hxx> | |
191 | #include <StepVisual_CoordinatesList.hxx> | |
192 | #include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx> | |
193 | #include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx> | |
5df609e7 | 194 | #include <StepVisual_DraughtingCallout.hxx> |
195 | #include <StepVisual_DraughtingCalloutElement.hxx> | |
fe0d928d | 196 | #include <StepVisual_DraughtingModel.hxx> |
7fd59977 | 197 | #include <StepVisual_Invisibility.hxx> |
42cf5bc1 | 198 | #include <StepVisual_LayeredItem.hxx> |
5df609e7 | 199 | #include <StepVisual_PlanarBox.hxx> |
42cf5bc1 | 200 | #include <StepVisual_PresentationLayerAssignment.hxx> |
201 | #include <StepVisual_PresentationStyleByContext.hxx> | |
202 | #include <StepVisual_StyleContextSelect.hxx> | |
203 | #include <StepVisual_StyledItem.hxx> | |
0c63f2f8 | 204 | #include <StepVisual_ViewVolume.hxx> |
1c9d3225 | 205 | #include <StepShape_TypeQualifier.hxx> |
42cf5bc1 | 206 | #include <TCollection_AsciiString.hxx> |
207 | #include <TCollection_HAsciiString.hxx> | |
208 | #include <TColStd_HArray1OfReal.hxx> | |
209 | #include <TColStd_HArray1OfTransient.hxx> | |
210 | #include <TColStd_HSequenceOfTransient.hxx> | |
211 | #include <TColStd_IndexedDataMapOfTransientTransient.hxx> | |
212 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> | |
213 | #include <TColStd_MapOfTransient.hxx> | |
7fd59977 | 214 | #include <TColStd_SequenceOfHAsciiString.hxx> |
42cf5bc1 | 215 | #include <TDataStd_Name.hxx> |
7fd59977 | 216 | #include <TDataStd_TreeNode.hxx> |
42cf5bc1 | 217 | #include <TDataStd_UAttribute.hxx> |
218 | #include <TDF_Label.hxx> | |
219 | #include <TDF_Tool.hxx> | |
220 | #include <TDocStd_Document.hxx> | |
7fd59977 | 221 | #include <TNaming_NamedShape.hxx> |
5df609e7 | 222 | #include <TopExp_Explorer.hxx> |
1c9d3225 | 223 | #include <TopoDS.hxx> |
42cf5bc1 | 224 | #include <TopoDS_Compound.hxx> |
225 | #include <TopoDS_Iterator.hxx> | |
226 | #include <TopoDS_Shape.hxx> | |
227 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
228 | #include <TopTools_ListOfShape.hxx> | |
229 | #include <TopTools_MapOfShape.hxx> | |
230 | #include <Transfer_Binder.hxx> | |
231 | #include <Transfer_TransientProcess.hxx> | |
232 | #include <TransferBRep.hxx> | |
477000eb | 233 | #include <UnitsMethods.hxx> |
42cf5bc1 | 234 | #include <XCAFDoc.hxx> |
235 | #include <XCAFDoc_Area.hxx> | |
236 | #include <XCAFDoc_Centroid.hxx> | |
0c63f2f8 | 237 | #include <XCAFDoc_ClippingPlaneTool.hxx> |
42cf5bc1 | 238 | #include <XCAFDoc_ColorTool.hxx> |
239 | #include <XCAFDoc_DataMapOfShapeLabel.hxx> | |
240 | #include <XCAFDoc_DimTolTool.hxx> | |
1c9d3225 | 241 | #include <XCAFDoc_Dimension.hxx> |
242 | #include <XCAFDoc_Datum.hxx> | |
243 | #include <XCAFDoc_GeomTolerance.hxx> | |
42cf5bc1 | 244 | #include <XCAFDoc_DocumentTool.hxx> |
7fd59977 | 245 | #include <XCAFDoc_GraphNode.hxx> |
42cf5bc1 | 246 | #include <XCAFDoc_LayerTool.hxx> |
247 | #include <XCAFDoc_MaterialTool.hxx> | |
248 | #include <XCAFDoc_ShapeTool.hxx> | |
0c63f2f8 | 249 | #include <XCAFDoc_View.hxx> |
250 | #include <XCAFDoc_ViewTool.hxx> | |
42cf5bc1 | 251 | #include <XCAFDoc_Volume.hxx> |
1c9d3225 | 252 | #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx> |
253 | #include <XCAFDimTolObjects_GeomToleranceType.hxx> | |
254 | #include <XCAFDimTolObjects_DimensionObject.hxx> | |
255 | #include <XCAFDimTolObjects_GeomToleranceObject.hxx> | |
256 | #include <XCAFDimTolObjects_DatumObject.hxx> | |
0c63f2f8 | 257 | #include <XCAFView_Object.hxx> |
477000eb | 258 | #include <XSAlgo.hxx> |
259 | #include <XSAlgo_AlgoContainer.hxx> | |
42cf5bc1 | 260 | #include <XSControl_TransferReader.hxx> |
261 | #include <XSControl_WorkSession.hxx> | |
5df609e7 | 262 | #include <StepAP242_DraughtingModelItemAssociation.hxx> |
1c9d3225 | 263 | #include <StepAP242_GeometricItemSpecificUsage.hxx> |
264 | #include <StepGeom_CartesianPoint.hxx> | |
727b5ad9 | 265 | #include <STEPCAFControl_GDTProperty.hxx> |
5df609e7 | 266 | #include <StepVisual_TessellatedAnnotationOccurrence.hxx> |
267 | #include <StepVisual_TessellatedAnnotationOccurrence.hxx> | |
268 | #include <StepVisual_TessellatedItem.hxx> | |
269 | #include <StepVisual_TessellatedGeometricSet.hxx> | |
270 | #include <StepVisual_TessellatedCurveSet.hxx> | |
271 | #include <StepVisual_CoordinatesList.hxx> | |
272 | #include <NCollection_Vector.hxx> | |
273 | ||
274 | #include <TColgp_HArray1OfXYZ.hxx> | |
275 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
276 | #include <BRepTools.hxx> | |
277 | #include <Transfer_ActorOfTransientProcess.hxx> | |
278 | #include <Bnd_Box.hxx> | |
279 | #include <BRepBndLib.hxx> | |
e3249d8e | 280 | #include <Resource_Unicode.hxx> |
5df609e7 | 281 | |
7fd59977 | 282 | // skl 21.08.2003 for reading G&DT |
7fd59977 | 283 | //#include <StepRepr_CompoundItemDefinition.hxx> |
284 | //#include <StepRepr_CompoundItemDefinitionMember.hxx> | |
7fd59977 | 285 | //#include <StepBasic_ConversionBasedUnit.hxx> |
7fd59977 | 286 | //#include <TDataStd_Real.hxx> |
287 | //#include <TDataStd_Constraint.hxx> | |
288 | //#include <TDataStd_ConstraintEnum.hxx> | |
289 | //#include <TNaming_Tool.hxx> | |
290 | //#include <AIS_InteractiveObject.hxx> | |
291 | //#include <TPrsStd_ConstraintTools.hxx> | |
292 | //#include <AIS_DiameterDimension.hxx> | |
293 | //#include <TPrsStd_Position.hxx> | |
294 | //#include <TPrsStd_AISPresentation.hxx> | |
295 | //#include <TNaming_Builder.hxx> | |
0797d9d3 | 296 | #ifdef OCCT_DEBUG |
02a0b964 | 297 | //! Converts address of the passed shape (TShape) to string. |
298 | //! \param theShape [in] Shape to dump. | |
299 | //! \return corresponding string. | |
300 | TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape) | |
301 | { | |
302 | std::string anAddrStr; | |
303 | std::ostringstream ost; | |
1c29294e | 304 | ost << theShape.TShape().get(); |
02a0b964 | 305 | anAddrStr = ost.str(); |
306 | ||
307 | TCollection_AsciiString aStr = | |
cf152970 | 308 | TCollection_AsciiString("[").Cat(anAddrStr.c_str()).Cat("]"); |
02a0b964 | 309 | |
310 | return aStr; | |
311 | } | |
312 | #endif | |
313 | ||
7fd59977 | 314 | //======================================================================= |
315 | //function : STEPCAFControl_Reader | |
316 | //purpose : | |
317 | //======================================================================= | |
318 | ||
e3249d8e | 319 | STEPCAFControl_Reader::STEPCAFControl_Reader() |
320 | : mySourceCodePage (Resource_FormatType_UTF8), | |
cf152970 | 321 | myColorMode(Standard_True), |
322 | myNameMode(Standard_True), | |
323 | myLayerMode(Standard_True), | |
324 | myPropsMode(Standard_True), | |
325 | mySHUOMode(Standard_False), | |
326 | myGDTMode(Standard_True), | |
327 | myMatMode(Standard_True), | |
328 | myViewMode(Standard_True) | |
7fd59977 | 329 | { |
330 | STEPCAFControl_Controller::Init(); | |
e3249d8e | 331 | mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage"); |
7fd59977 | 332 | } |
333 | ||
334 | ||
335 | //======================================================================= | |
336 | //function : STEPCAFControl_Reader | |
337 | //purpose : | |
338 | //======================================================================= | |
339 | ||
cf152970 | 340 | STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS, |
e3249d8e | 341 | const Standard_Boolean scratch) |
342 | : mySourceCodePage (Resource_FormatType_UTF8), | |
cf152970 | 343 | myColorMode(Standard_True), |
344 | myNameMode(Standard_True), | |
345 | myLayerMode(Standard_True), | |
346 | myPropsMode(Standard_True), | |
347 | mySHUOMode(Standard_False), | |
348 | myGDTMode(Standard_True), | |
349 | myMatMode(Standard_True), | |
350 | myViewMode(Standard_True) | |
7fd59977 | 351 | { |
352 | STEPCAFControl_Controller::Init(); | |
e3249d8e | 353 | mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage"); |
cf152970 | 354 | Init(WS, scratch); |
7fd59977 | 355 | } |
356 | ||
357 | ||
358 | //======================================================================= | |
359 | //function : Init | |
360 | //purpose : | |
361 | //======================================================================= | |
362 | ||
cf152970 | 363 | void STEPCAFControl_Reader::Init(const Handle(XSControl_WorkSession)& WS, |
364 | const Standard_Boolean scratch) | |
7fd59977 | 365 | { |
cf152970 | 366 | // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" ); |
367 | myReader.SetWS(WS, scratch); | |
997e128f | 368 | myFiles.Clear(); |
7fd59977 | 369 | } |
370 | ||
e3249d8e | 371 | //======================================================================= |
372 | //function : convertName | |
373 | //purpose : | |
374 | //======================================================================= | |
375 | TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection_AsciiString& theName) const | |
376 | { | |
377 | TCollection_ExtendedString aName; | |
378 | Resource_Unicode::ConvertFormatToUnicode (mySourceCodePage, theName.ToCString(), aName); | |
379 | return aName; | |
380 | } | |
7fd59977 | 381 | |
382 | //======================================================================= | |
383 | //function : ReadFile | |
384 | //purpose : | |
385 | //======================================================================= | |
386 | ||
cf152970 | 387 | IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile(const Standard_CString filename) |
7fd59977 | 388 | { |
cf152970 | 389 | return myReader.ReadFile(filename); |
7fd59977 | 390 | } |
391 | ||
392 | ||
393 | //======================================================================= | |
394 | //function : NbRootsForTransfer | |
395 | //purpose : | |
396 | //======================================================================= | |
397 | ||
cf152970 | 398 | Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer() |
7fd59977 | 399 | { |
400 | return myReader.NbRootsForTransfer(); | |
401 | } | |
402 | ||
403 | ||
404 | //======================================================================= | |
405 | //function : TransferOneRoot | |
406 | //purpose : | |
407 | //======================================================================= | |
408 | ||
cf152970 | 409 | Standard_Boolean STEPCAFControl_Reader::TransferOneRoot(const Standard_Integer num, |
410 | Handle(TDocStd_Document) &doc) | |
7fd59977 | 411 | { |
412 | TDF_LabelSequence Lseq; | |
cf152970 | 413 | return Transfer(myReader, num, doc, Lseq); |
7fd59977 | 414 | } |
415 | ||
416 | ||
417 | //======================================================================= | |
418 | //function : Transfer | |
419 | //purpose : | |
420 | //======================================================================= | |
421 | ||
cf152970 | 422 | Standard_Boolean STEPCAFControl_Reader::Transfer(Handle(TDocStd_Document) &doc) |
7fd59977 | 423 | { |
424 | TDF_LabelSequence Lseq; | |
cf152970 | 425 | return Transfer(myReader, 0, doc, Lseq); |
7fd59977 | 426 | } |
427 | ||
428 | ||
429 | //======================================================================= | |
430 | //function : Perform | |
431 | //purpose : | |
432 | //======================================================================= | |
433 | ||
cf152970 | 434 | Standard_Boolean STEPCAFControl_Reader::Perform(const Standard_CString filename, |
435 | Handle(TDocStd_Document) &doc) | |
7fd59977 | 436 | { |
cf152970 | 437 | if (ReadFile(filename) != IFSelect_RetDone) return Standard_False; |
438 | return Transfer(doc); | |
7fd59977 | 439 | } |
cf152970 | 440 | |
7fd59977 | 441 | |
442 | //======================================================================= | |
443 | //function : Perform | |
444 | //purpose : | |
445 | //======================================================================= | |
446 | ||
cf152970 | 447 | Standard_Boolean STEPCAFControl_Reader::Perform(const TCollection_AsciiString &filename, |
448 | Handle(TDocStd_Document) &doc) | |
7fd59977 | 449 | { |
cf152970 | 450 | if (ReadFile(filename.ToCString()) != IFSelect_RetDone) return Standard_False; |
451 | return Transfer(doc); | |
7fd59977 | 452 | } |
cf152970 | 453 | |
7fd59977 | 454 | |
455 | //======================================================================= | |
456 | //function : ExternFiles | |
457 | //purpose : | |
458 | //======================================================================= | |
459 | ||
cf152970 | 460 | const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles() const |
7fd59977 | 461 | { |
462 | return myFiles; | |
463 | } | |
cf152970 | 464 | |
7fd59977 | 465 | |
466 | //======================================================================= | |
467 | //function : ExternFile | |
468 | //purpose : | |
469 | //======================================================================= | |
470 | ||
cf152970 | 471 | Standard_Boolean STEPCAFControl_Reader::ExternFile(const Standard_CString name, |
472 | Handle(STEPCAFControl_ExternFile) &ef) const | |
7fd59977 | 473 | { |
474 | ef.Nullify(); | |
cf152970 | 475 | if (myFiles.IsEmpty() || !myFiles.IsBound(name)) |
7fd59977 | 476 | return Standard_False; |
cf152970 | 477 | ef = myFiles.Find(name); |
7fd59977 | 478 | return Standard_True; |
479 | } | |
480 | ||
481 | ||
482 | //======================================================================= | |
483 | //function : Reader | |
484 | //purpose : | |
485 | //======================================================================= | |
486 | ||
cf152970 | 487 | STEPControl_Reader &STEPCAFControl_Reader::ChangeReader() |
7fd59977 | 488 | { |
489 | return myReader; | |
490 | } | |
cf152970 | 491 | |
7fd59977 | 492 | |
493 | //======================================================================= | |
494 | //function : Reader | |
495 | //purpose : | |
496 | //======================================================================= | |
497 | ||
cf152970 | 498 | const STEPControl_Reader &STEPCAFControl_Reader::Reader() const |
7fd59977 | 499 | { |
500 | return myReader; | |
501 | } | |
cf152970 | 502 | |
7fd59977 | 503 | |
504 | //======================================================================= | |
505 | //function : FillShapesMap | |
506 | //purpose : auxiliary: fill a map by all compounds and their components | |
507 | //======================================================================= | |
508 | ||
cf152970 | 509 | static void FillShapesMap(const TopoDS_Shape &S, TopTools_MapOfShape &map) |
7fd59977 | 510 | { |
511 | TopoDS_Shape S0 = S; | |
512 | TopLoc_Location loc; | |
cf152970 | 513 | S0.Location(loc); |
514 | map.Add(S0); | |
515 | if (S.ShapeType() != TopAbs_COMPOUND) return; | |
516 | for (TopoDS_Iterator it(S); it.More(); it.Next()) | |
517 | FillShapesMap(it.Value(), map); | |
7fd59977 | 518 | } |
519 | ||
520 | ||
521 | //======================================================================= | |
522 | //function : Transfer | |
523 | //purpose : basic working method | |
524 | //======================================================================= | |
525 | ||
cf152970 | 526 | Standard_Boolean STEPCAFControl_Reader::Transfer(STEPControl_Reader &reader, |
527 | const Standard_Integer nroot, | |
528 | Handle(TDocStd_Document) &doc, | |
529 | TDF_LabelSequence &Lseq, | |
530 | const Standard_Boolean asOne) | |
7fd59977 | 531 | { |
532 | reader.ClearShapes(); | |
533 | Standard_Integer i; | |
cf152970 | 534 | |
7fd59977 | 535 | // Read all shapes |
536 | Standard_Integer num = reader.NbRootsForTransfer(); | |
cf152970 | 537 | if (num <= 0) return Standard_False; |
538 | if (nroot) { | |
539 | if (nroot > num) return Standard_False; | |
540 | reader.TransferOneRoot(nroot); | |
7fd59977 | 541 | } |
542 | else { | |
cf152970 | 543 | for (i = 1; i <= num; i++) reader.TransferOneRoot(i); |
7fd59977 | 544 | } |
545 | num = reader.NbShapes(); | |
cf152970 | 546 | if (num <= 0) return Standard_False; |
7fd59977 | 547 | |
548 | // Fill a map of (top-level) shapes resulting from that transfer | |
549 | // Only these shapes will be considered further | |
550 | TopTools_MapOfShape ShapesMap, NewShapesMap; | |
cf152970 | 551 | for (i = 1; i <= num; i++) FillShapesMap(reader.Shape(i), ShapesMap); |
552 | ||
7fd59977 | 553 | // Collect information on shapes originating from SDRs |
554 | // this will be used to distinguish compounds representing assemblies | |
555 | // from the ones representing hybrid models and shape sets | |
556 | STEPCAFControl_DataMapOfShapePD ShapePDMap; | |
557 | STEPCAFControl_DataMapOfPDExternFile PDFileMap; | |
558 | Handle(Interface_InterfaceModel) Model = reader.Model(); | |
7f56eba8 | 559 | const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess(); |
7fd59977 | 560 | Standard_Integer nb = Model->NbEntities(); |
561 | ||
562 | Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient; | |
563 | ||
cf152970 | 564 | for (i = 1; i <= nb; i++) { |
7fd59977 | 565 | Handle(Standard_Transient) enti = Model->Value(i); |
cf152970 | 566 | if (enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) { |
7fd59977 | 567 | // sequence for acceleration ReadMaterials |
568 | SeqPDS->Append(enti); | |
569 | } | |
cf152970 | 570 | if (enti->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) { |
571 | Handle(StepBasic_ProductDefinition) PD = | |
7fd59977 | 572 | Handle(StepBasic_ProductDefinition)::DownCast(enti); |
573 | Standard_Integer index = TP->MapIndex(PD); | |
cf152970 | 574 | if (index > 0) { |
575 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
7fd59977 | 576 | TopoDS_Shape S = TransferBRep::ShapeResult(binder); |
cf152970 | 577 | if (!S.IsNull() && ShapesMap.Contains(S)) { |
7fd59977 | 578 | NewShapesMap.Add(S); |
cf152970 | 579 | ShapePDMap.Bind(S, PD); |
7fd59977 | 580 | Handle(STEPCAFControl_ExternFile) EF; |
cf152970 | 581 | PDFileMap.Bind(PD, EF); |
7fd59977 | 582 | } |
583 | } | |
584 | } | |
cf152970 | 585 | if (enti->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) { |
7fd59977 | 586 | Standard_Integer index = TP->MapIndex(enti); |
cf152970 | 587 | if (index > 0) { |
588 | Handle(Transfer_Binder) binder = TP->MapItem(index); | |
7fd59977 | 589 | TopoDS_Shape S = TransferBRep::ShapeResult(binder); |
cf152970 | 590 | if (!S.IsNull() && ShapesMap.Contains(S)) |
7fd59977 | 591 | NewShapesMap.Add(S); |
592 | } | |
593 | } | |
594 | } | |
595 | ||
596 | // get directory name of the main file | |
cf152970 | 597 | OSD_Path mainfile(reader.WS()->LoadedFile()); |
598 | mainfile.SetName(""); | |
599 | mainfile.SetExtension(""); | |
7fd59977 | 600 | TCollection_AsciiString dpath; |
cf152970 | 601 | mainfile.SystemName(dpath); |
7fd59977 | 602 | |
603 | // Load external references (only for relevant SDRs) | |
604 | // and fill map SDR -> extern file | |
cf152970 | 605 | STEPConstruct_ExternRefs ExtRefs(reader.WS()); |
7fd59977 | 606 | ExtRefs.LoadExternRefs(); |
cf152970 | 607 | for (i = 1; i <= ExtRefs.NbExternRefs(); i++) { |
7fd59977 | 608 | // check extern ref format |
609 | Handle(TCollection_HAsciiString) format = ExtRefs.Format(i); | |
cf152970 | 610 | if (!format.IsNull()) { |
611 | static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString("STEP AP203"); | |
612 | static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString("STEP AP214"); | |
613 | if (!format->IsSameString(ap203, Standard_False) && | |
614 | !format->IsSameString(ap214, Standard_False)) { | |
0797d9d3 | 615 | #ifdef OCCT_DEBUG |
cf152970 | 616 | cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl; |
7fd59977 | 617 | #else |
cf152970 | 618 | continue; |
7fd59977 | 619 | #endif |
620 | } | |
621 | } | |
0797d9d3 | 622 | #ifdef OCCT_DEBUG |
7fd59977 | 623 | else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl; |
624 | #endif | |
cf152970 | 625 | |
7fd59977 | 626 | // get and check filename of the current extern ref |
627 | const Standard_CString filename = ExtRefs.FileName(i); | |
628 | ||
0797d9d3 | 629 | #ifdef OCCT_DEBUG |
cf152970 | 630 | cout << "filename=" << filename << endl; |
83a86948 | 631 | #endif |
7fd59977 | 632 | |
cf152970 | 633 | if (!filename || !filename[0]) { |
0797d9d3 | 634 | #ifdef OCCT_DEBUG |
7fd59977 | 635 | cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl; |
636 | #endif | |
637 | continue; // not a valid extern ref | |
638 | } | |
639 | ||
640 | // compute true path to the extern file | |
cf152970 | 641 | TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, filename); |
642 | if (fullname.Length() <= 0) fullname = filename; | |
643 | ||
644 | /* | |
645 | char fullname[1024]; | |
646 | char *mainfile = reader.WS()->LoadedFile(); | |
647 | if ( ! mainfile ) mainfile = ""; | |
648 | Standard_Integer slash = 0; | |
649 | for ( Standard_Integer k=0; mainfile[k]; k++ ) | |
650 | if ( mainfile[k] == '/' ) slash = k; | |
651 | strncpy ( fullname, mainfile, slash ); | |
652 | sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename ); | |
653 | */ | |
654 | ||
7fd59977 | 655 | // get and check PD associated with the current extern ref |
656 | Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i); | |
cf152970 | 657 | if (PD.IsNull()) continue; // not a valid extern ref |
658 | if (!PDFileMap.IsBound(PD)) continue; // this PD is not concerned by current transfer | |
659 | ||
7fd59977 | 660 | // read extern file (or use existing data) and record its data |
cf152970 | 661 | Handle(STEPCAFControl_ExternFile) EF = |
662 | ReadExternFile(filename, fullname.ToCString(), doc); | |
663 | PDFileMap.Bind(PD, EF); | |
7fd59977 | 664 | } |
cf152970 | 665 | |
7fd59977 | 666 | // and insert them to the document |
cf152970 | 667 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(doc->Main()); |
668 | if (STool.IsNull()) return Standard_False; | |
7fd59977 | 669 | XCAFDoc_DataMapOfShapeLabel map; |
cf152970 | 670 | if (asOne) |
671 | Lseq.Append(AddShape(reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map)); | |
7fd59977 | 672 | else { |
cf152970 | 673 | for (i = 1; i <= num; i++) { |
674 | Lseq.Append(AddShape(reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map)); | |
7fd59977 | 675 | } |
676 | } | |
cf152970 | 677 | |
7fd59977 | 678 | // read colors |
cf152970 | 679 | if (GetColorMode()) |
680 | ReadColors(reader.WS(), doc, map); | |
681 | ||
7fd59977 | 682 | // read names |
cf152970 | 683 | if (GetNameMode()) |
684 | ReadNames(reader.WS(), doc, PDFileMap, map); | |
7fd59977 | 685 | |
686 | // read validation props | |
cf152970 | 687 | if (GetPropsMode()) |
688 | ReadValProps(reader.WS(), doc, PDFileMap, map); | |
7fd59977 | 689 | |
690 | // read layers | |
cf152970 | 691 | if (GetLayerMode()) |
692 | ReadLayers(reader.WS(), doc); | |
693 | ||
7fd59977 | 694 | // read SHUO entities from STEP model |
cf152970 | 695 | if (GetSHUOMode()) |
696 | ReadSHUOs(reader.WS(), doc, PDFileMap, map); | |
7fd59977 | 697 | |
698 | // read GDT entities from STEP model | |
cf152970 | 699 | if (GetGDTMode()) |
700 | ReadGDTs(reader.WS(), doc); | |
7fd59977 | 701 | |
702 | // read Material entities from STEP model | |
cf152970 | 703 | if (GetMatMode()) |
704 | ReadMaterials(reader.WS(), doc, SeqPDS); | |
7fd59977 | 705 | |
0c63f2f8 | 706 | // read View entities from STEP model |
707 | if (GetViewMode()) | |
708 | ReadViews(reader.WS(), doc); | |
709 | ||
02a0b964 | 710 | // Expand resulting CAF structure for sub-shapes (optionally with their |
711 | // names) if requested | |
712 | ExpandSubShapes(STool, map, ShapePDMap); | |
713 | ||
acc909a8 | 714 | // Update assembly compounds |
715 | STool->UpdateAssemblies(); | |
716 | ||
7fd59977 | 717 | return Standard_True; |
718 | } | |
719 | ||
720 | //======================================================================= | |
721 | //function : AddShape | |
722 | //purpose : | |
723 | //======================================================================= | |
724 | ||
cf152970 | 725 | TDF_Label STEPCAFControl_Reader::AddShape(const TopoDS_Shape &S, |
726 | const Handle(XCAFDoc_ShapeTool) &STool, | |
727 | const TopTools_MapOfShape &NewShapesMap, | |
728 | const STEPCAFControl_DataMapOfShapePD &ShapePDMap, | |
729 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
730 | XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
7fd59977 | 731 | { |
732 | // if shape has already been mapped, just return corresponding label | |
cf152970 | 733 | if (ShapeLabelMap.IsBound(S)) { |
734 | return ShapeLabelMap.Find(S); | |
7fd59977 | 735 | } |
cf152970 | 736 | |
7fd59977 | 737 | // if shape is located, create instance |
cf152970 | 738 | if (!S.Location().IsIdentity()) { |
7fd59977 | 739 | TopoDS_Shape S0 = S; |
740 | TopLoc_Location loc; | |
cf152970 | 741 | S0.Location(loc); |
742 | AddShape(S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap); | |
743 | TDF_Label L = STool->AddShape(S, Standard_False); // should create reference | |
744 | ShapeLabelMap.Bind(S, L); | |
7fd59977 | 745 | return L; |
746 | } | |
cf152970 | 747 | |
7fd59977 | 748 | // if shape is not compound, simple add it |
cf152970 | 749 | if (S.ShapeType() != TopAbs_COMPOUND) { |
750 | TDF_Label L = STool->AddShape(S, Standard_False); | |
751 | ShapeLabelMap.Bind(S, L); | |
7fd59977 | 752 | return L; |
753 | } | |
cf152970 | 754 | |
7fd59977 | 755 | // for compounds, compute number of subshapes and check whether this is assembly |
756 | Standard_Boolean isAssembly = Standard_False; | |
757 | Standard_Integer nbComponents = 0; | |
758 | TopoDS_Iterator it; | |
cf152970 | 759 | for (it.Initialize(S); it.More() && !isAssembly; it.Next(), nbComponents++) { |
7fd59977 | 760 | TopoDS_Shape Sub0 = it.Value(); |
761 | TopLoc_Location loc; | |
cf152970 | 762 | Sub0.Location(loc); |
763 | if (NewShapesMap.Contains(Sub0)) isAssembly = Standard_True; | |
7fd59977 | 764 | } |
765 | ||
cf152970 | 766 | // if(nbComponents>0) isAssembly = Standard_True; |
767 | ||
768 | // check whether it has associated external ref | |
7fd59977 | 769 | TColStd_SequenceOfHAsciiString SHAS; |
cf152970 | 770 | if (ShapePDMap.IsBound(S) && PDFileMap.IsBound(ShapePDMap.Find(S))) { |
771 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(ShapePDMap.Find(S)); | |
772 | if (!EF.IsNull()) { | |
7fd59977 | 773 | // (store information on extern refs in the document) |
774 | SHAS.Append(EF->GetName()); | |
775 | // if yes, just return corresponding label | |
cf152970 | 776 | if (!EF->GetLabel().IsNull()) { |
777 | // but if components >0, ignore extern ref! | |
778 | if (nbComponents <= 0) { | |
779 | ShapeLabelMap.Bind(S, EF->GetLabel()); | |
780 | STool->SetExternRefs(EF->GetLabel(), SHAS); | |
781 | return EF->GetLabel(); | |
782 | } | |
7fd59977 | 783 | } |
0797d9d3 | 784 | #ifdef OCCT_DEBUG |
cf152970 | 785 | if (!EF->GetLabel().IsNull()) |
7fd59977 | 786 | cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl; |
cf152970 | 787 | else if (nbComponents <= 0) |
788 | cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl; | |
7fd59977 | 789 | #endif |
790 | } | |
791 | } | |
cf152970 | 792 | |
7fd59977 | 793 | // add compound either as a whole, |
cf152970 | 794 | if (!isAssembly) { |
795 | TDF_Label L = STool->AddShape(S, Standard_False); | |
796 | if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS); | |
797 | ShapeLabelMap.Bind(S, L); | |
7fd59977 | 798 | return L; |
799 | } | |
cf152970 | 800 | |
7fd59977 | 801 | // or as assembly, component-by-component |
802 | TDF_Label L = STool->NewShape(); | |
63cdf48e | 803 | nbComponents = 0; |
cf152970 | 804 | for (it.Initialize(S); it.More(); it.Next(), nbComponents++) { |
7fd59977 | 805 | TopoDS_Shape Sub0 = it.Value(); |
806 | TopLoc_Location loc; | |
cf152970 | 807 | Sub0.Location(loc); |
808 | TDF_Label subL = AddShape(Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap); | |
809 | if (!subL.IsNull()) { | |
810 | TDF_Label instL = STool->AddComponent(L, subL, it.Value().Location()); | |
63cdf48e | 811 | ShapeLabelMap.Bind(it.Value(), instL); |
7fd59977 | 812 | } |
813 | } | |
cf152970 | 814 | if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS); |
815 | ShapeLabelMap.Bind(S, L); | |
7fd59977 | 816 | //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941 |
817 | ||
818 | return L; | |
819 | } | |
820 | ||
821 | //======================================================================= | |
822 | //function : ReadExternFile | |
823 | //purpose : | |
824 | //======================================================================= | |
825 | ||
cf152970 | 826 | Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile(const Standard_CString file, |
827 | const Standard_CString fullname, | |
828 | Handle(TDocStd_Document)& doc) | |
7fd59977 | 829 | { |
830 | // if the file is already read, associate it with SDR | |
cf152970 | 831 | if (myFiles.IsBound(file)) { |
832 | return myFiles.ChangeFind(file); | |
7fd59977 | 833 | } |
834 | ||
0797d9d3 | 835 | #ifdef OCCT_DEBUG |
7fd59977 | 836 | cout << "Reading extern file: " << fullname << endl; |
837 | #endif | |
cf152970 | 838 | |
7fd59977 | 839 | // create new WorkSession and Reader |
840 | Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession; | |
cf152970 | 841 | newWS->SelectNorm("STEP"); |
842 | STEPControl_Reader sr(newWS, Standard_False); | |
843 | ||
7fd59977 | 844 | // start to fill the resulting ExternFile structure |
845 | Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile; | |
cf152970 | 846 | EF->SetWS(newWS); |
847 | EF->SetName(new TCollection_HAsciiString(file)); | |
848 | ||
7fd59977 | 849 | // read file |
cf152970 | 850 | EF->SetLoadStatus(sr.ReadFile(fullname)); |
851 | ||
7fd59977 | 852 | // transfer in single-result mode |
cf152970 | 853 | if (EF->GetLoadStatus() == IFSelect_RetDone) { |
7fd59977 | 854 | TDF_LabelSequence labels; |
cf152970 | 855 | EF->SetTransferStatus(Transfer(sr, 0, doc, labels, Standard_True)); |
856 | if (labels.Length() > 0) EF->SetLabel(labels.Value(1)); | |
7fd59977 | 857 | } |
cf152970 | 858 | |
7fd59977 | 859 | // add read file to dictionary |
cf152970 | 860 | myFiles.Bind(file, EF); |
861 | ||
7fd59977 | 862 | return EF; |
863 | } | |
864 | ||
7fd59977 | 865 | //======================================================================= |
866 | //function : findStyledSR | |
867 | //purpose : auxilary | |
868 | //======================================================================= | |
cf152970 | 869 | static void findStyledSR(const Handle(StepVisual_StyledItem) &style, |
870 | Handle(StepShape_ShapeRepresentation)& aSR) | |
7fd59977 | 871 | { |
872 | // search Shape Represenatation for component styled item | |
cf152970 | 873 | for (Standard_Integer j = 1; j <= style->NbStyles(); j++) { |
874 | Handle(StepVisual_PresentationStyleByContext) PSA = | |
875 | Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue(j)); | |
876 | if (PSA.IsNull()) | |
7fd59977 | 877 | continue; |
878 | StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext(); | |
cf152970 | 879 | Handle(StepShape_ShapeRepresentation) aCurrentSR = |
7fd59977 | 880 | Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation()); |
cf152970 | 881 | if (aCurrentSR.IsNull()) |
7fd59977 | 882 | continue; |
883 | aSR = aCurrentSR; | |
cf152970 | 884 | break; |
7fd59977 | 885 | } |
886 | } | |
887 | ||
888 | ||
889 | //======================================================================= | |
890 | //function : ReadColors | |
891 | //purpose : | |
892 | //======================================================================= | |
893 | ||
cf152970 | 894 | Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSession) &WS, |
895 | Handle(TDocStd_Document)& Doc, | |
896 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
7fd59977 | 897 | { |
cf152970 | 898 | STEPConstruct_Styles Styles(WS); |
899 | if (!Styles.LoadStyles()) { | |
0797d9d3 | 900 | #ifdef OCCT_DEBUG |
7fd59977 | 901 | cout << "Warning: no styles are found in the model" << endl; |
902 | #endif | |
903 | return Standard_False; | |
904 | } | |
905 | // searching for invisible items in the model | |
906 | Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient; | |
cf152970 | 907 | Styles.LoadInvisStyles(aHSeqOfInvisStyle); |
908 | ||
909 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
910 | if (CTool.IsNull()) return Standard_False; | |
63cdf48e | 911 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
912 | if (STool.IsNull()) return Standard_False; | |
7fd59977 | 913 | |
914 | // parse and search for color attributes | |
915 | Standard_Integer nb = Styles.NbStyles(); | |
cf152970 | 916 | for (Standard_Integer i = 1; i <= nb; i++) { |
917 | Handle(StepVisual_StyledItem) style = Styles.Style(i); | |
918 | if (style.IsNull()) continue; | |
919 | ||
7fd59977 | 920 | Standard_Boolean IsVisible = Standard_True; |
921 | // check the visibility of styled item. | |
cf152970 | 922 | for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) { |
923 | if (style != aHSeqOfInvisStyle->Value(si)) | |
7fd59977 | 924 | continue; |
925 | // found that current style is invisible. | |
7fd59977 | 926 | IsVisible = Standard_False; |
927 | break; | |
928 | } | |
929 | ||
930 | Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol; | |
931 | // check if it is component style | |
932 | Standard_Boolean IsComponent = Standard_False; | |
cf152970 | 933 | if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, IsComponent) && IsVisible) |
7fd59977 | 934 | continue; |
cf152970 | 935 | |
7fd59977 | 936 | // find shape |
25e59720 | 937 | NCollection_Vector<Handle(Standard_Transient)> anItems; |
d658f275 | 938 | if (!style->Item().IsNull()) { |
939 | anItems.Append(style->Item()); | |
940 | } | |
cf152970 | 941 | else if (!style->ItemAP242().Representation().IsNull()) { |
d658f275 | 942 | //special case for AP242: item can be Reprsentation |
943 | Handle(StepRepr_Representation) aRepr = style->ItemAP242().Representation(); | |
7856b126 | 944 | for (Standard_Integer j = 1; j <= aRepr->Items()->Length(); j++) |
945 | anItems.Append(aRepr->Items()->Value(j)); | |
d658f275 | 946 | } |
947 | for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) { | |
cf152970 | 948 | TopoDS_Shape S = STEPConstruct::FindShape(Styles.TransientProcess(), |
949 | Handle(StepRepr_RepresentationItem)::DownCast(anItems.Value(itemIt))); | |
d658f275 | 950 | Standard_Boolean isSkipSHUOstyle = Standard_False; |
951 | // take shape with real location. | |
cf152970 | 952 | while (IsComponent) { |
d658f275 | 953 | // take SR of NAUO |
954 | Handle(StepShape_ShapeRepresentation) aSR; | |
cf152970 | 955 | findStyledSR(style, aSR); |
d658f275 | 956 | // search for SR along model |
957 | if (aSR.IsNull()) | |
7fd59977 | 958 | break; |
cf152970 | 959 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR); |
d658f275 | 960 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; |
961 | for (subs.Start(); subs.More(); subs.Next()) { | |
962 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
cf152970 | 963 | if (aSDR.IsNull()) |
d658f275 | 964 | continue; |
965 | StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition(); | |
cf152970 | 966 | Handle(StepRepr_ProductDefinitionShape) PDS = |
d658f275 | 967 | Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition()); |
cf152970 | 968 | if (PDS.IsNull()) |
d658f275 | 969 | continue; |
970 | StepRepr_CharacterizedDefinition aCharDef = PDS->Definition(); | |
cf152970 | 971 | |
972 | Handle(StepRepr_AssemblyComponentUsage) ACU = | |
d658f275 | 973 | Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship()); |
aff18753 | 974 | if (ACU.IsNull()) |
975 | continue; | |
d658f275 | 976 | // PTV 10.02.2003 skip styled item that refer to SHUO |
977 | if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) { | |
978 | isSkipSHUOstyle = Standard_True; | |
979 | break; | |
980 | } | |
981 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = | |
982 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU); | |
cf152970 | 983 | if (NAUO.IsNull()) |
d658f275 | 984 | continue; |
cf152970 | 985 | |
d658f275 | 986 | TopoDS_Shape aSh; |
987 | // PTV 10.02.2003 to find component of assembly CORRECTLY | |
cf152970 | 988 | STEPConstruct_Tool Tool(WS); |
989 | TDF_Label aShLab = FindInstance(NAUO, CTool->ShapeTool(), Tool, ShapeLabelMap); | |
d658f275 | 990 | aSh = CTool->ShapeTool()->GetShape(aShLab); |
991 | if (!aSh.IsNull()) { | |
992 | S = aSh; | |
993 | break; | |
994 | } | |
7fd59977 | 995 | } |
d658f275 | 996 | break; |
997 | } | |
998 | if (isSkipSHUOstyle) | |
999 | continue; // skip styled item which refer to SHUO | |
cf152970 | 1000 | |
1001 | if (S.IsNull()) | |
d658f275 | 1002 | continue; |
cf152970 | 1003 | |
63cdf48e | 1004 | if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !IsVisible) |
1005 | { | |
1006 | TDF_Label aL; | |
1007 | Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True); | |
1008 | if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull()) | |
1009 | { | |
1010 | Quantity_Color aSCol, aBCol, aCCol; | |
1011 | if (!SurfCol.IsNull()) | |
1012 | Styles.DecodeColor(SurfCol, aSCol); | |
1013 | if (!BoundCol.IsNull()) | |
1014 | Styles.DecodeColor(BoundCol, aBCol); | |
1015 | if (!CurveCol.IsNull()) | |
1016 | Styles.DecodeColor(CurveCol, aCCol); | |
1017 | if (isFound) | |
1018 | { | |
1019 | if (!SurfCol.IsNull()) | |
1020 | CTool->SetColor(aL, aSCol, XCAFDoc_ColorSurf); | |
1021 | if (!BoundCol.IsNull()) | |
1022 | CTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv); | |
1023 | if (!CurveCol.IsNull()) | |
1024 | CTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv); | |
1025 | } | |
1026 | else | |
1027 | { | |
1028 | for (TopoDS_Iterator it(S); it.More(); it.Next()) | |
1029 | { | |
1030 | TDF_Label aL1; | |
1031 | if (STool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True)) | |
1032 | { | |
1033 | if (!SurfCol.IsNull()) | |
1034 | CTool->SetColor(aL1, aSCol, XCAFDoc_ColorSurf); | |
1035 | if (!BoundCol.IsNull()) | |
1036 | CTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv); | |
1037 | if (!CurveCol.IsNull()) | |
1038 | CTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv); | |
1039 | } | |
1040 | } | |
1041 | } | |
1042 | } | |
1043 | if (!IsVisible) | |
1044 | { | |
1045 | // sets the invisibility for shape. | |
1046 | if (isFound) | |
1047 | CTool->SetVisibility(aL, Standard_False); | |
1048 | } | |
7fd59977 | 1049 | } |
7fd59977 | 1050 | } |
1051 | } | |
1052 | CTool->ReverseChainsOfTreeNodes(); | |
1053 | return Standard_True; | |
1054 | } | |
1055 | ||
1056 | //======================================================================= | |
1057 | //function : GetLabelFromPD | |
1058 | //purpose : | |
1059 | //======================================================================= | |
1060 | ||
cf152970 | 1061 | static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD, |
1062 | const Handle(XCAFDoc_ShapeTool) &STool, | |
1063 | const Handle(Transfer_TransientProcess) &TP, | |
1064 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1065 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
7fd59977 | 1066 | { |
1067 | TDF_Label L; | |
cf152970 | 1068 | if (PDFileMap.IsBound(PD)) { |
1069 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD); | |
1070 | if (!EF.IsNull()) { | |
7fd59977 | 1071 | L = EF->GetLabel(); |
cf152970 | 1072 | if (!L.IsNull()) return L; |
7fd59977 | 1073 | } |
1074 | } | |
1075 | ||
1076 | TopoDS_Shape S; | |
1077 | Handle(Transfer_Binder) binder = TP->Find(PD); | |
cf152970 | 1078 | if (binder.IsNull() || !binder->HasResult()) return L; |
1079 | S = TransferBRep::ShapeResult(TP, binder); | |
1080 | if (S.IsNull()) return L; | |
1081 | ||
1082 | if (ShapeLabelMap.IsBound(S)) | |
1083 | L = ShapeLabelMap.Find(S); | |
1084 | if (L.IsNull()) | |
1085 | STool->Search(S, L, Standard_True, Standard_True, Standard_False); | |
7fd59977 | 1086 | return L; |
1087 | } | |
1088 | ||
1089 | //======================================================================= | |
1090 | //function : FindInstance | |
1091 | //purpose : | |
1092 | //======================================================================= | |
1093 | ||
cf152970 | 1094 | TDF_Label STEPCAFControl_Reader::FindInstance(const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO, |
1095 | const Handle(XCAFDoc_ShapeTool) &STool, | |
1096 | const STEPConstruct_Tool &Tool, | |
1097 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
7fd59977 | 1098 | { |
1099 | TDF_Label L; | |
cf152970 | 1100 | |
7fd59977 | 1101 | // get shape resulting from CDSR (in fact, only location is interesting) |
1102 | Handle(Transfer_TransientProcess) TP = Tool.TransientProcess(); | |
1103 | Handle(Transfer_Binder) binder = TP->Find(NAUO); | |
cf152970 | 1104 | if (binder.IsNull() || !binder->HasResult()) { |
0797d9d3 | 1105 | #ifdef OCCT_DEBUG |
7fd59977 | 1106 | cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl; |
1107 | #endif | |
1108 | return L; | |
1109 | } | |
cf152970 | 1110 | |
1111 | TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder); | |
1112 | if (S.IsNull()) { | |
0797d9d3 | 1113 | #ifdef OCCT_DEBUG |
7fd59977 | 1114 | cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl; |
1115 | #endif | |
1116 | return L; | |
1117 | } | |
1118 | ||
63cdf48e | 1119 | if (ShapeLabelMap.IsBound(S)) |
1120 | L = ShapeLabelMap(S); | |
1121 | else | |
1122 | STool->Search(S, L, Standard_True, Standard_True, Standard_False); | |
1123 | ||
7fd59977 | 1124 | return L; |
1125 | } | |
1126 | ||
1127 | //======================================================================= | |
1128 | //function : ReadNames | |
1129 | //purpose : | |
1130 | //======================================================================= | |
1131 | ||
cf152970 | 1132 | Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS, |
1133 | Handle(TDocStd_Document)& Doc, | |
1134 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1135 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
7fd59977 | 1136 | { |
1137 | // get starting data | |
7f56eba8 | 1138 | const Handle(Interface_InterfaceModel) &Model = WS->Model(); |
1139 | const Handle(XSControl_TransferReader) &TR = WS->TransferReader(); | |
1140 | const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess(); | |
cf152970 | 1141 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
1142 | if (STool.IsNull()) return Standard_False; | |
1143 | STEPConstruct_Tool Tool(WS); | |
7fd59977 | 1144 | |
1145 | // iterate on model to find all SDRs and CDSRs | |
1146 | Standard_Integer nb = Model->NbEntities(); | |
1147 | Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence); | |
cf152970 | 1148 | Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition); |
7fd59977 | 1149 | Handle(TCollection_HAsciiString) name; |
1150 | TDF_Label L; | |
1151 | for (Standard_Integer i = 1; i <= nb; i++) { | |
1152 | Handle(Standard_Transient) enti = Model->Value(i); | |
1153 | ||
1154 | // get description of NAUO | |
cf152970 | 1155 | if (enti->DynamicType() == tNAUO) { |
7fd59977 | 1156 | L.Nullify(); |
cf152970 | 1157 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
9c3cce7a | 1158 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti); |
cf152970 | 1159 | if (NAUO.IsNull()) continue; |
7fd59977 | 1160 | Interface_EntityIterator subs = WS->Graph().Sharings(NAUO); |
1161 | for (subs.Start(); subs.More(); subs.Next()) { | |
cf152970 | 1162 | Handle(StepRepr_ProductDefinitionShape) PDS = |
7fd59977 | 1163 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value()); |
cf152970 | 1164 | if (PDS.IsNull()) continue; |
7fd59977 | 1165 | Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship(); |
cf152970 | 1166 | if (PDR.IsNull()) continue; |
1167 | if (PDR->HasDescription() && | |
1168 | PDR->Description()->UsefullLength() > 0) name = PDR->Description(); | |
1169 | else if (!PDR->Name().IsNull() && PDR->Name()->UsefullLength() > 0) name = PDR->Name(); | |
1170 | else if (!PDR->Id().IsNull()) name = PDR->Id(); | |
ab4a5554 | 1171 | else name = new TCollection_HAsciiString; |
7fd59977 | 1172 | } |
1173 | // find proper label | |
cf152970 | 1174 | L = FindInstance(NAUO, STool, Tool, ShapeLabelMap); |
1175 | if (L.IsNull()) continue; | |
e3249d8e | 1176 | |
1177 | TCollection_ExtendedString str = convertName (name->String()); | |
cf152970 | 1178 | TDataStd_Name::Set(L, str); |
7fd59977 | 1179 | } |
1180 | ||
1181 | // for PD get name of associated product | |
cf152970 | 1182 | if (enti->DynamicType() == tPD) { |
7fd59977 | 1183 | L.Nullify(); |
cf152970 | 1184 | Handle(StepBasic_ProductDefinition) PD = |
9c3cce7a | 1185 | Handle(StepBasic_ProductDefinition)::DownCast(enti); |
cf152970 | 1186 | if (PD.IsNull()) continue; |
9c3cce7a | 1187 | Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL); |
1188 | if (Prod.IsNull()) | |
1189 | name = new TCollection_HAsciiString; | |
cf152970 | 1190 | else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0) |
9c3cce7a | 1191 | name = Prod->Name(); |
cf152970 | 1192 | else if (!Prod->Id().IsNull()) |
9c3cce7a | 1193 | name = Prod->Id(); |
cf152970 | 1194 | else |
9c3cce7a | 1195 | name = new TCollection_HAsciiString; |
cf152970 | 1196 | L = GetLabelFromPD(PD, STool, TP, PDFileMap, ShapeLabelMap); |
1197 | if (L.IsNull()) continue; | |
e3249d8e | 1198 | TCollection_ExtendedString str = convertName (name->String()); |
cf152970 | 1199 | TDataStd_Name::Set(L, str); |
7fd59977 | 1200 | } |
1201 | // set a name to the document | |
e3249d8e | 1202 | //TCollection_ExtendedString str = convertName (name->String()); |
7fd59977 | 1203 | //TDataStd_Name::Set ( L, str ); |
1204 | } | |
1205 | ||
1206 | return Standard_True; | |
1207 | } | |
1208 | ||
1209 | //======================================================================= | |
1210 | //function : GetLabelFromPD | |
1211 | //purpose : | |
1212 | //======================================================================= | |
1213 | ||
cf152970 | 1214 | static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD, |
1215 | const Handle(XCAFDoc_ShapeTool) &STool, | |
1216 | const STEPConstruct_ValidationProps &Props, | |
1217 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1218 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
7fd59977 | 1219 | { |
1220 | TDF_Label L; | |
cf152970 | 1221 | if (PDFileMap.IsBound(PD)) { |
1222 | Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD); | |
1223 | if (!EF.IsNull()) { | |
7fd59977 | 1224 | L = EF->GetLabel(); |
cf152970 | 1225 | if (!L.IsNull()) return L; |
7fd59977 | 1226 | } |
1227 | } | |
cf152970 | 1228 | TopoDS_Shape S = Props.GetPropShape(PD); |
1229 | if (S.IsNull()) return L; | |
1230 | if (ShapeLabelMap.IsBound(S)) | |
1231 | L = ShapeLabelMap.Find(S); | |
1232 | if (L.IsNull()) | |
1233 | STool->Search(S, L, Standard_True, Standard_True, Standard_False); | |
7fd59977 | 1234 | return L; |
1235 | } | |
1236 | ||
1237 | //======================================================================= | |
1238 | //function : ReadValProps | |
1239 | //purpose : | |
1240 | //======================================================================= | |
1241 | ||
cf152970 | 1242 | Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_WorkSession) &WS, |
1243 | Handle(TDocStd_Document)& Doc, | |
1244 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1245 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
7fd59977 | 1246 | { |
1247 | // get starting data | |
7f56eba8 | 1248 | const Handle(XSControl_TransferReader) &TR = WS->TransferReader(); |
1249 | const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess(); | |
cf152970 | 1250 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
1251 | if (STool.IsNull()) return Standard_False; | |
7fd59977 | 1252 | |
1253 | // load props from the STEP model | |
1254 | TColStd_SequenceOfTransient props; | |
cf152970 | 1255 | STEPConstruct_ValidationProps Props(WS); |
1256 | if (!Props.LoadProps(props)) { | |
0797d9d3 | 1257 | #ifdef OCCT_DEBUG |
7fd59977 | 1258 | cout << "Warning: no validation props found in the model" << endl; |
1259 | #endif | |
1260 | return Standard_False; | |
1261 | } | |
1262 | ||
1263 | // interpret props one by one | |
cf152970 | 1264 | for (Standard_Integer i = 1; i <= props.Length(); i++) { |
1265 | Handle(StepRepr_PropertyDefinitionRepresentation) PDR = | |
1266 | Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(props.Value(i)); | |
1267 | if (PDR.IsNull()) continue; | |
7fd59977 | 1268 | |
1269 | TDF_Label L; | |
1270 | ||
1271 | Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition(); | |
1272 | Interface_EntityIterator subs = Props.Graph().Shareds(PD); | |
1273 | for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) { | |
cf152970 | 1274 | if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) { |
7fd59977 | 1275 | Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value()); |
cf152970 | 1276 | if (PDS.IsNull()) continue; |
7fd59977 | 1277 | // find corresponding NAUO |
1278 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO; | |
1279 | Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS); | |
1280 | for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) { | |
cf152970 | 1281 | if (subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) |
7fd59977 | 1282 | NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value()); |
1283 | } | |
cf152970 | 1284 | if (!NAUO.IsNull()) { |
1285 | L = FindInstance(NAUO, STool, WS, ShapeLabelMap); | |
1286 | if (L.IsNull()) continue; | |
7fd59977 | 1287 | } |
1288 | else { | |
1289 | // find corresponding ProductDefinition: | |
1290 | Handle(StepBasic_ProductDefinition) ProdDef; | |
1291 | Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS); | |
1292 | for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) { | |
cf152970 | 1293 | if (subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) |
7fd59977 | 1294 | ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value()); |
1295 | } | |
cf152970 | 1296 | if (ProdDef.IsNull()) continue; |
1297 | L = GetLabelFromPD(ProdDef, STool, Props, PDFileMap, ShapeLabelMap); | |
7fd59977 | 1298 | } |
1299 | } | |
1300 | ||
cf152970 | 1301 | if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) { |
7fd59977 | 1302 | Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value()); |
cf152970 | 1303 | if (SA.IsNull()) continue; |
7fd59977 | 1304 | // find ShapeRepresentation |
1305 | Handle(StepShape_ShapeRepresentation) SR; | |
1306 | Interface_EntityIterator subs1 = Props.Graph().Sharings(SA); | |
cf152970 | 1307 | for (subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) { |
1308 | Handle(StepRepr_PropertyDefinition) PropD1 = | |
7fd59977 | 1309 | Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value()); |
cf152970 | 1310 | if (PropD1.IsNull()) continue; |
7fd59977 | 1311 | Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1); |
cf152970 | 1312 | for (subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) { |
7fd59977 | 1313 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
1314 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); | |
cf152970 | 1315 | if (SDR.IsNull()) continue; |
7fd59977 | 1316 | SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); |
1317 | } | |
1318 | } | |
cf152970 | 1319 | if (SR.IsNull()) continue; |
7fd59977 | 1320 | Handle(Transfer_Binder) binder; |
cf152970 | 1321 | for (Standard_Integer ir = 1; ir <= SR->NbItems() && binder.IsNull(); ir++) { |
1322 | if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) { | |
1323 | Handle(StepShape_SolidModel) SM = | |
7fd59977 | 1324 | Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir)); |
1325 | binder = TP->Find(SM); | |
1326 | } | |
cf152970 | 1327 | else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) { |
7fd59977 | 1328 | Handle(StepShape_ShellBasedSurfaceModel) SBSM = |
1329 | Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir)); | |
1330 | binder = TP->Find(SBSM); | |
1331 | } | |
cf152970 | 1332 | else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) { |
7fd59977 | 1333 | Handle(StepShape_GeometricSet) GS = |
1334 | Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir)); | |
1335 | binder = TP->Find(GS); | |
1336 | } | |
1337 | } | |
cf152970 | 1338 | if (binder.IsNull() || !binder->HasResult()) continue; |
7fd59977 | 1339 | TopoDS_Shape S; |
cf152970 | 1340 | S = TransferBRep::ShapeResult(TP, binder); |
1341 | if (S.IsNull()) continue; | |
1342 | if (ShapeLabelMap.IsBound(S)) | |
1343 | L = ShapeLabelMap.Find(S); | |
1344 | if (L.IsNull()) | |
1345 | STool->Search(S, L, Standard_True, Standard_True, Standard_True); | |
7fd59977 | 1346 | } |
1347 | } | |
1348 | ||
cf152970 | 1349 | if (L.IsNull()) continue; |
1350 | ||
7fd59977 | 1351 | // decode validation properties |
1352 | Handle(StepRepr_Representation) rep = PDR->UsedRepresentation(); | |
cf152970 | 1353 | for (Standard_Integer j = 1; j <= rep->NbItems(); j++) { |
7fd59977 | 1354 | Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j); |
1355 | Standard_Boolean isArea; | |
1356 | Standard_Real val; | |
1357 | gp_Pnt pos; | |
cf152970 | 1358 | if (Props.GetPropReal(ent, val, isArea)) { |
1359 | if (isArea) XCAFDoc_Area::Set(L, val); | |
1360 | else XCAFDoc_Volume::Set(L, val); | |
7fd59977 | 1361 | } |
cf152970 | 1362 | else if (Props.GetPropPnt(ent, rep->ContextOfItems(), pos)) { |
1363 | XCAFDoc_Centroid::Set(L, pos); | |
7fd59977 | 1364 | } |
1365 | } | |
1366 | } | |
1367 | return Standard_True; | |
1368 | } | |
1369 | ||
1370 | //======================================================================= | |
1371 | //function : ReadLayers | |
1372 | //purpose : | |
1373 | //======================================================================= | |
1374 | ||
cf152970 | 1375 | Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSession) &WS, |
1376 | Handle(TDocStd_Document)& Doc) const | |
7fd59977 | 1377 | { |
7f56eba8 | 1378 | const Handle(Interface_InterfaceModel) &Model = WS->Model(); |
1379 | const Handle(XSControl_TransferReader) &TR = WS->TransferReader(); | |
1380 | const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess(); | |
cf152970 | 1381 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
1382 | if (STool.IsNull()) return Standard_False; | |
1383 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); | |
1384 | if (LTool.IsNull()) return Standard_False; | |
1385 | ||
7fd59977 | 1386 | Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment); |
1387 | Standard_Integer nb = Model->NbEntities(); | |
1388 | Handle(TCollection_HAsciiString) name; | |
cf152970 | 1389 | |
1390 | for (Standard_Integer i = 1; i <= nb; i++) { | |
7fd59977 | 1391 | Handle(Standard_Transient) enti = Model->Value(i); |
cf152970 | 1392 | if (!enti->IsKind(tSVPLA)) continue; |
1393 | Handle(StepVisual_PresentationLayerAssignment) SVPLA = | |
7fd59977 | 1394 | Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti); |
1209c1b9 | 1395 | if (SVPLA->AssignedItems().IsNull()) |
1396 | continue; | |
cf152970 | 1397 | |
7fd59977 | 1398 | Handle(TCollection_HAsciiString) descr = SVPLA->Description(); |
1399 | Handle(TCollection_HAsciiString) hName = SVPLA->Name(); | |
cf152970 | 1400 | TCollection_ExtendedString aLayerName(hName->String()); |
1401 | ||
7fd59977 | 1402 | // find a target shape and its label in the document |
cf152970 | 1403 | for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++) { |
7fd59977 | 1404 | StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j); |
cf152970 | 1405 | Handle(Transfer_Binder) binder = TP->Find(LI.Value()); |
1406 | if (binder.IsNull() || !binder->HasResult()) continue; | |
1407 | ||
1408 | TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder); | |
1409 | if (S.IsNull()) continue; | |
1410 | ||
7fd59977 | 1411 | TDF_Label shL; |
cf152970 | 1412 | if (!STool->Search(S, shL, Standard_True, Standard_True, Standard_True)) continue; |
1413 | LTool->SetLayer(shL, aLayerName); | |
7fd59977 | 1414 | } |
cf152970 | 1415 | |
7fd59977 | 1416 | // check invisibility |
1417 | Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA); | |
1418 | for (subs.Start(); subs.More(); subs.Next()) { | |
cf152970 | 1419 | if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue; |
0797d9d3 | 1420 | #ifdef OCCT_DEBUG |
cf152970 | 1421 | cout << "\tLayer \"" << aLayerName << "\" is invisible" << endl; |
7fd59977 | 1422 | #endif |
1423 | //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName); | |
1424 | TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926 | |
ad67e367 | 1425 | TDataStd_UAttribute::Set (InvLayerLab, XCAFDoc::InvisibleGUID()); |
7fd59977 | 1426 | } |
1427 | } | |
1428 | return Standard_True; | |
1429 | } | |
1430 | ||
1431 | //======================================================================= | |
1432 | //function : ReadSHUOs | |
1433 | //purpose : | |
1434 | //======================================================================= | |
1435 | ||
cf152970 | 1436 | static Standard_Boolean findNextSHUOlevel(const Handle(XSControl_WorkSession) &WS, |
1437 | const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO, | |
1438 | const Handle(XCAFDoc_ShapeTool)& STool, | |
1439 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1440 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap, | |
1441 | TDF_LabelSequence& aLabels) | |
7fd59977 | 1442 | { |
1443 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO); | |
1444 | Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO; | |
1445 | for (subs.Start(); subs.More(); subs.Next()) { | |
1446 | if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) { | |
1447 | subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value()); | |
1448 | break; | |
1449 | } | |
1450 | } | |
1451 | if (subSHUO.IsNull()) | |
1452 | return Standard_False; | |
cf152970 | 1453 | |
a9dde4a3 | 1454 | Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage(); |
7fd59977 | 1455 | if (NUNAUO.IsNull()) |
1456 | return Standard_False; | |
cf152970 | 1457 | // Handle(Interface_InterfaceModel) Model = WS->Model(); |
1458 | // Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1459 | // Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1460 | // Handle(Transfer_Binder) binder = TP->Find(NUNAUO); | |
1461 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1462 | // return Standard_False; | |
1463 | // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1464 | // get label of NAUO next level | |
7fd59977 | 1465 | TDF_Label NULab; |
cf152970 | 1466 | STEPConstruct_Tool Tool(WS); |
1467 | NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap); | |
1468 | // STool->Search(NUSh, NUlab); | |
7fd59977 | 1469 | if (NULab.IsNull()) |
1470 | return Standard_False; | |
cf152970 | 1471 | aLabels.Append(NULab); |
7fd59977 | 1472 | // and check by recurse. |
cf152970 | 1473 | findNextSHUOlevel(WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels); |
7fd59977 | 1474 | return Standard_True; |
1475 | } | |
1476 | ||
1477 | ||
1478 | //======================================================================= | |
1479 | //function : setSHUOintoDoc | |
1480 | //purpose : auxilary | |
1481 | //======================================================================= | |
cf152970 | 1482 | static TDF_Label setSHUOintoDoc(const Handle(XSControl_WorkSession) &WS, |
1483 | const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO, | |
1484 | const Handle(XCAFDoc_ShapeTool)& STool, | |
1485 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1486 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) | |
7fd59977 | 1487 | { |
1488 | TDF_Label aMainLabel; | |
1489 | // get upper usage NAUO from SHUO. | |
1490 | Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO = | |
1491 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage()); | |
a9dde4a3 | 1492 | Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage(); |
cf152970 | 1493 | if (UUNAUO.IsNull() || NUNAUO.IsNull()) { |
0797d9d3 | 1494 | #ifdef OCCT_DEBUG |
cf152970 | 1495 | cout << "Warning: " << __FILE__ << ": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl; |
7fd59977 | 1496 | #endif |
1497 | return aMainLabel; | |
1498 | } | |
cf152970 | 1499 | // Handle(Interface_InterfaceModel) Model = WS->Model(); |
1500 | // Handle(XSControl_TransferReader) TR = WS->TransferReader(); | |
1501 | // Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); | |
1502 | // TopoDS_Shape UUSh, NUSh; | |
1503 | // Handle(Transfer_Binder) binder = TP->Find(UUNAUO); | |
1504 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1505 | // return aMainLabel; | |
1506 | // UUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1507 | // binder = TP->Find(NUNAUO); | |
1508 | // if ( binder.IsNull() || ! binder->HasResult() ) | |
1509 | // return aMainLabel; | |
1510 | // NUSh = TransferBRep::ShapeResult ( TP, binder ); | |
1511 | ||
1512 | // get first labels for first SHUO attribute | |
7fd59977 | 1513 | TDF_Label UULab, NULab; |
cf152970 | 1514 | STEPConstruct_Tool Tool(WS); |
1515 | UULab = STEPCAFControl_Reader::FindInstance(UUNAUO, STool, Tool, ShapeLabelMap); | |
1516 | NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap); | |
1517 | ||
1518 | // STool->Search(UUSh, UULab); | |
1519 | // STool->Search(NUSh, NULab); | |
7fd59977 | 1520 | if (UULab.IsNull() || NULab.IsNull()) return aMainLabel; |
1521 | //create sequence fo labels to set SHUO structure into the document | |
1522 | TDF_LabelSequence ShuoLabels; | |
cf152970 | 1523 | ShuoLabels.Append(UULab); |
1524 | ShuoLabels.Append(NULab); | |
7fd59977 | 1525 | // add all other labels of sub SHUO entities |
cf152970 | 1526 | findNextSHUOlevel(WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels); |
7fd59977 | 1527 | // last accord for SHUO |
1528 | Handle(XCAFDoc_GraphNode) anSHUOAttr; | |
cf152970 | 1529 | if (STool->SetSHUO(ShuoLabels, anSHUOAttr)) |
7fd59977 | 1530 | aMainLabel = anSHUOAttr->Label(); |
cf152970 | 1531 | |
7fd59977 | 1532 | return aMainLabel; |
1533 | } | |
1534 | ||
1535 | ||
1536 | //======================================================================= | |
1537 | //function : ReadSHUOs | |
1538 | //purpose : | |
1539 | //======================================================================= | |
1540 | ||
cf152970 | 1541 | Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(const Handle(XSControl_WorkSession) &WS, |
1542 | Handle(TDocStd_Document)& Doc, | |
1543 | const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, | |
1544 | const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const | |
7fd59977 | 1545 | { |
1546 | // the big part code duplication from ReadColors. | |
1547 | // It is possible to share this code functionality, just to decide how ??? | |
cf152970 | 1548 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); |
7fd59977 | 1549 | Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool(); |
cf152970 | 1550 | |
1551 | STEPConstruct_Styles Styles(WS); | |
1552 | if (!Styles.LoadStyles()) { | |
0797d9d3 | 1553 | #ifdef OCCT_DEBUG |
7fd59977 | 1554 | cout << "Warning: no styles are found in the model" << endl; |
1555 | #endif | |
1556 | return Standard_False; | |
1557 | } | |
1558 | // searching for invisible items in the model | |
1559 | Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient; | |
cf152970 | 1560 | Styles.LoadInvisStyles(aHSeqOfInvisStyle); |
7fd59977 | 1561 | // parse and search for color attributes |
1562 | Standard_Integer nb = Styles.NbStyles(); | |
cf152970 | 1563 | for (Standard_Integer i = 1; i <= nb; i++) { |
1564 | Handle(StepVisual_StyledItem) style = Styles.Style(i); | |
1565 | if (style.IsNull()) continue; | |
1566 | ||
7fd59977 | 1567 | Standard_Boolean IsVisible = Standard_True; |
1568 | // check the visibility of styled item. | |
cf152970 | 1569 | for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) { |
1570 | if (style != aHSeqOfInvisStyle->Value(si)) | |
7fd59977 | 1571 | continue; |
1572 | // found that current style is invisible. | |
0797d9d3 | 1573 | #ifdef OCCT_DEBUG |
7fd59977 | 1574 | cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl; |
1575 | #endif | |
1576 | IsVisible = Standard_False; | |
1577 | break; | |
1578 | } | |
1579 | ||
1580 | Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol; | |
1581 | // check if it is component style | |
1582 | Standard_Boolean IsComponent = Standard_False; | |
cf152970 | 1583 | if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, IsComponent) && IsVisible) |
7fd59977 | 1584 | continue; |
1585 | if (!IsComponent) | |
1586 | continue; | |
1587 | Handle(StepShape_ShapeRepresentation) aSR; | |
cf152970 | 1588 | findStyledSR(style, aSR); |
7fd59977 | 1589 | // search for SR along model |
cf152970 | 1590 | if (aSR.IsNull()) |
7fd59977 | 1591 | continue; |
cf152970 | 1592 | Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR); |
7fd59977 | 1593 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; |
1594 | for (subs.Start(); subs.More(); subs.Next()) { | |
1595 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
cf152970 | 1596 | if (aSDR.IsNull()) |
7fd59977 | 1597 | continue; |
1598 | StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition(); | |
cf152970 | 1599 | Handle(StepRepr_ProductDefinitionShape) PDS = |
7fd59977 | 1600 | Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition()); |
cf152970 | 1601 | if (PDS.IsNull()) |
7fd59977 | 1602 | continue; |
1603 | StepRepr_CharacterizedDefinition aCharDef = PDS->Definition(); | |
1604 | Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO = | |
1605 | Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship()); | |
cf152970 | 1606 | if (SHUO.IsNull()) |
7fd59977 | 1607 | continue; |
cf152970 | 1608 | |
7fd59977 | 1609 | // set the SHUO structure to the document |
cf152970 | 1610 | TDF_Label aLabelForStyle = setSHUOintoDoc(WS, SHUO, STool, PDFileMap, ShapeLabelMap); |
1611 | if (aLabelForStyle.IsNull()) { | |
0797d9d3 | 1612 | #ifdef OCCT_DEBUG |
cf152970 | 1613 | cout << "Warning: " << __FILE__ << ": coudnot create SHUO structure in the document" << endl; |
7fd59977 | 1614 | #endif |
1615 | continue; | |
1616 | } | |
1617 | // now set the style to the SHUO main label. | |
cf152970 | 1618 | if (!SurfCol.IsNull()) { |
7fd59977 | 1619 | Quantity_Color col; |
cf152970 | 1620 | Styles.DecodeColor(SurfCol, col); |
1621 | CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorSurf); | |
7fd59977 | 1622 | } |
cf152970 | 1623 | if (!BoundCol.IsNull()) { |
7fd59977 | 1624 | Quantity_Color col; |
cf152970 | 1625 | Styles.DecodeColor(BoundCol, col); |
1626 | CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv); | |
7fd59977 | 1627 | } |
cf152970 | 1628 | if (!CurveCol.IsNull()) { |
7fd59977 | 1629 | Quantity_Color col; |
cf152970 | 1630 | Styles.DecodeColor(CurveCol, col); |
1631 | CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv); | |
7fd59977 | 1632 | } |
cf152970 | 1633 | if (!IsVisible) |
7fd59977 | 1634 | // sets the invisibility for shape. |
cf152970 | 1635 | CTool->SetVisibility(aLabelForStyle, Standard_False); |
1636 | ||
7fd59977 | 1637 | } // end search SHUO by SDR |
1638 | } // end iterates on styles | |
cf152970 | 1639 | |
7fd59977 | 1640 | return Standard_True; |
1641 | } | |
1642 | ||
7fd59977 | 1643 | //======================================================================= |
1644 | //function : GetMassConversionFactor | |
1645 | //purpose : | |
1646 | //======================================================================= | |
1647 | static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU, | |
cf152970 | 1648 | Standard_Real& afact) |
7fd59977 | 1649 | { |
cf152970 | 1650 | afact = 1.; |
1651 | if (!NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) return Standard_False; | |
7fd59977 | 1652 | Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU = |
1653 | Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU); | |
1654 | Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor(); | |
1655 | afact = MWUCBU->ValueComponent(); | |
1656 | StepBasic_Unit anUnit2 = MWUCBU->UnitComponent(); | |
cf152970 | 1657 | if (anUnit2.CaseNum(anUnit2.Value()) == 1) { |
7fd59977 | 1658 | Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit(); |
cf152970 | 1659 | if (NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) { |
7fd59977 | 1660 | Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2); |
cf152970 | 1661 | if (SU->Name() == StepBasic_sunGram) { |
1662 | if (SU->HasPrefix()) | |
1663 | afact *= STEPConstruct_UnitContext::ConvertSiPrefix(SU->Prefix()); | |
7fd59977 | 1664 | } |
1665 | } | |
1666 | } | |
1667 | return Standard_True; | |
1668 | } | |
1209c1b9 | 1669 | |
5df609e7 | 1670 | //======================================================================= |
0b622d67 | 1671 | //function : readPMIPresentation |
1672 | //purpose : read polyline or tessellated presentation for | |
1673 | // (Annotation_Curve_Occurrence or Draughting_Callout) | |
5df609e7 | 1674 | //======================================================================= |
0b622d67 | 1675 | Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity, |
cf152970 | 1676 | const Handle(XSControl_TransferReader)& theTR, |
1677 | const Standard_Real theFact, | |
1678 | TopoDS_Shape& thePresentation, | |
1679 | Handle(TCollection_HAsciiString)& thePresentName, | |
1680 | Bnd_Box& theBox) | |
5df609e7 | 1681 | { |
aff18753 | 1682 | if (thePresentEntity.IsNull()) |
1683 | return Standard_False; | |
5df609e7 | 1684 | Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess(); |
1209c1b9 | 1685 | Handle(StepVisual_AnnotationOccurrence) anAO; |
5df609e7 | 1686 | NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations; |
1209c1b9 | 1687 | if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence))) |
5df609e7 | 1688 | { |
1209c1b9 | 1689 | anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity); |
1690 | if (!anAO.IsNull()) { | |
1691 | thePresentName = anAO->Name(); | |
1692 | anAnnotations.Append(anAO); | |
1693 | } | |
5df609e7 | 1694 | } |
0b622d67 | 1695 | else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) |
5df609e7 | 1696 | { |
1697 | Handle(StepVisual_DraughtingCallout) aDCallout = | |
0b622d67 | 1698 | Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity); |
1699 | thePresentName = aDCallout->Name(); | |
1209c1b9 | 1700 | for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) { |
1701 | anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value()); | |
1702 | if (!anAO.IsNull()) | |
5df609e7 | 1703 | { |
1209c1b9 | 1704 | anAnnotations.Append(anAO); |
5df609e7 | 1705 | continue; |
1706 | } | |
0b622d67 | 1707 | Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation = |
5df609e7 | 1708 | aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence(); |
0b622d67 | 1709 | if (!aTesselation.IsNull()) |
5df609e7 | 1710 | anAnnotations.Append(aTesselation); |
1711 | } | |
1712 | } | |
1713 | ||
1714 | if (!anAnnotations.Length()) | |
0b622d67 | 1715 | return Standard_False; |
5df609e7 | 1716 | |
1717 | ||
1718 | BRep_Builder aB; | |
0b622d67 | 1719 | TopoDS_Compound aResAnnotation; |
5df609e7 | 1720 | aB.MakeCompound(aResAnnotation); |
1721 | ||
0b622d67 | 1722 | Standard_Integer i = 0; |
5df609e7 | 1723 | Bnd_Box aBox; |
0b622d67 | 1724 | Standard_Integer nbShapes = 0; |
1725 | for (; i < anAnnotations.Length(); i++) | |
5df609e7 | 1726 | { |
1727 | Handle(StepVisual_StyledItem) anItem = anAnnotations(i); | |
1209c1b9 | 1728 | anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem); |
5df609e7 | 1729 | TopoDS_Shape anAnnotationShape; |
1209c1b9 | 1730 | if (!anAO.IsNull()) |
5df609e7 | 1731 | { |
1209c1b9 | 1732 | Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item(); |
0b622d67 | 1733 | anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem); |
1734 | if (anAnnotationShape.IsNull()) | |
5df609e7 | 1735 | { |
1736 | Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP); | |
0b622d67 | 1737 | if (!binder.IsNull() && binder->HasResult()) { |
1738 | anAnnotationShape = TransferBRep::ShapeResult(aTP, binder); | |
5df609e7 | 1739 | } |
1740 | } | |
1741 | } | |
fe0d928d | 1742 | //case of tessellated entities |
5df609e7 | 1743 | else |
1744 | { | |
1745 | Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item(); | |
0b622d67 | 1746 | if (aTessItem.IsNull()) |
5df609e7 | 1747 | continue; |
1748 | Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem); | |
0b622d67 | 1749 | if (aTessSet.IsNull()) |
5df609e7 | 1750 | continue; |
b0cef606 | 1751 | NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items(); |
5df609e7 | 1752 | Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length(); |
1753 | Handle(StepVisual_TessellatedCurveSet) aTessCurve; | |
1754 | for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++) | |
1755 | { | |
1756 | aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n)); | |
1757 | } | |
0b622d67 | 1758 | if (aTessCurve.IsNull()) |
5df609e7 | 1759 | continue; |
1760 | Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList(); | |
0b622d67 | 1761 | if (aCoordList.IsNull()) |
5df609e7 | 1762 | continue; |
1763 | Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points(); | |
1764 | ||
1765 | if (aPoints.IsNull() || aPoints->Length() == 0) | |
1766 | continue; | |
1767 | NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves(); | |
1768 | Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length()); | |
1769 | TopoDS_Compound aComp; | |
1770 | aB.MakeCompound(aComp); | |
0b622d67 | 1771 | |
5df609e7 | 1772 | Standard_Integer k = 0; |
0b622d67 | 1773 | for (; k < aNbC; k++) |
5df609e7 | 1774 | { |
1775 | Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k); | |
1776 | TopoDS_Wire aCurW; | |
1777 | aB.MakeWire(aCurW); | |
1778 | ||
0b622d67 | 1779 | for (Standard_Integer n = 1; n < anIndexes->Length(); n++) |
5df609e7 | 1780 | { |
1781 | Standard_Integer ind = anIndexes->Value(n); | |
1782 | Standard_Integer indnext = anIndexes->Value(n + 1); | |
0b622d67 | 1783 | if (ind > aPoints->Length() || indnext > aPoints->Length()) |
5df609e7 | 1784 | continue; |
0b622d67 | 1785 | gp_Pnt aP1(aPoints->Value(ind) * theFact); |
1786 | gp_Pnt aP2(aPoints->Value(indnext) * theFact); | |
5df609e7 | 1787 | BRepBuilderAPI_MakeEdge aMaker(aP1, aP2); |
0b622d67 | 1788 | if (aMaker.IsDone()) |
5df609e7 | 1789 | { |
1790 | TopoDS_Edge aCurE = aMaker.Edge(); | |
1791 | aB.Add(aCurW, aCurE); | |
1792 | } | |
1793 | } | |
1794 | aB.Add(aComp, aCurW); | |
1795 | } | |
1796 | anAnnotationShape = aComp; | |
1797 | } | |
0b622d67 | 1798 | if (!anAnnotationShape.IsNull()) |
5df609e7 | 1799 | { |
1800 | nbShapes++; | |
1801 | aB.Add(aResAnnotation, anAnnotationShape); | |
0b622d67 | 1802 | if (i == anAnnotations.Length() - 1) |
5df609e7 | 1803 | BRepBndLib::AddClose(anAnnotationShape, aBox); |
1804 | } | |
1805 | } | |
0b622d67 | 1806 | |
1807 | thePresentation = aResAnnotation; | |
1808 | theBox = aBox; | |
1809 | return (nbShapes > 0); | |
1810 | } | |
1811 | ||
1812 | //======================================================================= | |
1813 | //function : readAnnotationPlane | |
1814 | //purpose : read annotation plane | |
1815 | //======================================================================= | |
1816 | Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane, | |
cf152970 | 1817 | gp_Ax2& thePlane) |
0b622d67 | 1818 | { |
1819 | if (theAnnotationPlane.IsNull()) | |
1820 | return Standard_False; | |
0b622d67 | 1821 | Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item(); |
aff18753 | 1822 | if (aPlaneItem.IsNull()) |
1823 | return Standard_False; | |
0b622d67 | 1824 | Handle(StepGeom_Axis2Placement3d) aA2P3D; |
1825 | //retrieve axes from AnnotationPlane | |
1826 | if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) { | |
1827 | Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem); | |
1828 | aA2P3D = aPlane->Position(); | |
1829 | } | |
1830 | else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) { | |
1831 | Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem); | |
1832 | aA2P3D = aBox->Placement().Axis2Placement3d(); | |
1833 | } | |
1834 | if (aA2P3D.IsNull()) | |
1835 | return Standard_False; | |
1836 | ||
ea6e5378 | 1837 | Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D); |
477000eb | 1838 | thePlane = anAxis->Ax2(); |
0b622d67 | 1839 | return Standard_True; |
1840 | } | |
1841 | ||
1842 | //======================================================================= | |
1843 | //function : readAnnotation | |
1844 | //purpose : read annotation plane and position for given GDT | |
1845 | // (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature) | |
1846 | //======================================================================= | |
cf152970 | 1847 | void readAnnotation(const Handle(XSControl_TransferReader)& theTR, |
400af1bc | 1848 | const Handle(Standard_Transient)& theGDT, |
0b622d67 | 1849 | const Handle(Standard_Transient)& theDimObject) |
1850 | { | |
aff18753 | 1851 | if (theGDT.IsNull() || theDimObject.IsNull()) |
1852 | return; | |
0b622d67 | 1853 | Handle(TCollection_HAsciiString) aPresentName; |
1854 | TopoDS_Compound aResAnnotation; | |
1855 | Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess(); | |
1856 | const Interface_Graph& aGraph = aTP->Graph(); | |
1857 | // find the proper DraughtingModelItemAssociation | |
1858 | Interface_EntityIterator subs = aGraph.Sharings(theGDT); | |
1859 | Handle(StepAP242_DraughtingModelItemAssociation) aDMIA; | |
1860 | for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) { | |
1861 | if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation))) | |
1862 | continue; | |
1863 | aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value()); | |
1864 | Handle(TCollection_HAsciiString) aName = aDMIA->Name(); | |
1865 | aName->LowerCase(); | |
1866 | if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) { | |
1867 | aDMIA = NULL; | |
1868 | } | |
1869 | } | |
1870 | if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0) | |
1871 | return; | |
1872 | ||
1873 | // calculate units | |
cf152970 | 1874 | Handle(StepVisual_DraughtingModel) aDModel = |
0b622d67 | 1875 | Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation()); |
477000eb | 1876 | XSAlgo::AlgoContainer()->PrepareForTransfer(); |
1877 | STEPControl_ActorRead anActor; | |
1878 | anActor.PrepareUnits(aDModel, aTP); | |
1879 | Standard_Real aFact = UnitsMethods::LengthFactor(); | |
0b622d67 | 1880 | |
1881 | // retrieve AnnotationPlane | |
1882 | Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1); | |
1883 | if (aDMIAE.IsNull()) | |
1884 | return; | |
1885 | gp_Ax2 aPlaneAxes; | |
1886 | subs = aGraph.Sharings(aDMIAE); | |
1887 | Handle(StepVisual_AnnotationPlane) anAnPlane; | |
1888 | for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) { | |
1889 | anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value()); | |
1890 | } | |
477000eb | 1891 | Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aPlaneAxes); |
0b622d67 | 1892 | |
1893 | // set plane axes to XCAF | |
1894 | if (isHasPlane) { | |
1895 | if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) { | |
cf152970 | 1896 | Handle(XCAFDimTolObjects_DimensionObject) anObj = |
0b622d67 | 1897 | Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject); |
1898 | Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1); | |
1899 | anObj->SetPlane(aPlaneAxes); | |
1900 | } | |
1901 | else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) { | |
1902 | Handle(XCAFDimTolObjects_DatumObject) anObj = | |
1903 | Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject); | |
1904 | anObj->SetPlane(aPlaneAxes); | |
1905 | } | |
1906 | else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) { | |
1907 | Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = | |
1908 | Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject); | |
1909 | anObj->SetPlane(aPlaneAxes); | |
1910 | } | |
1911 | } | |
1912 | ||
1913 | // Retrieve presentation | |
1914 | Bnd_Box aBox; | |
1915 | if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox)) | |
5df609e7 | 1916 | return; |
1917 | gp_Pnt aPtext(0., 0., 0.); | |
f0bf70e8 | 1918 | // if Annotation plane location inside bounding box set it to text position |
cf152970 | 1919 | // else set the center of bounding box to text position 0027372 |
0b622d67 | 1920 | if (!aBox.IsVoid()) |
5df609e7 | 1921 | { |
0b622d67 | 1922 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; |
1923 | aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); | |
f0bf70e8 | 1924 | if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) { |
1925 | aPtext = aPlaneAxes.Location(); | |
1926 | } | |
1927 | else { | |
1928 | aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5); | |
1929 | } | |
1930 | } | |
1931 | else { | |
1932 | aPtext = aPlaneAxes.Location(); | |
5df609e7 | 1933 | } |
1934 | ||
1935 | // set point to XCAF | |
1936 | if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) { | |
cf152970 | 1937 | Handle(XCAFDimTolObjects_DimensionObject) anObj = |
5df609e7 | 1938 | Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject); |
1939 | anObj->SetPointTextAttach(aPtext); | |
1940 | anObj->SetPresentation(aResAnnotation, aPresentName); | |
1941 | } | |
1942 | else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) { | |
1943 | Handle(XCAFDimTolObjects_DatumObject) anObj = | |
1944 | Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject); | |
cf152970 | 1945 | anObj->SetPointTextAttach(aPtext); |
1946 | anObj->SetPresentation(aResAnnotation, aPresentName); | |
5df609e7 | 1947 | } |
1948 | else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) { | |
1949 | Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = | |
1950 | Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject); | |
1951 | anObj->SetPointTextAttach(aPtext); | |
1952 | anObj->SetPresentation(aResAnnotation, aPresentName); | |
1953 | } | |
1954 | return; | |
1955 | } | |
7fd59977 | 1956 | |
b7b2f85a | 1957 | //======================================================================= |
1958 | //function : readConnectionPoints | |
1959 | //purpose : read connection points for given dimension | |
1960 | //======================================================================= | |
cf152970 | 1961 | void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR, |
b7b2f85a | 1962 | const Handle(Standard_Transient) theGDT, |
1963 | const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject) | |
1964 | { | |
aff18753 | 1965 | if (theGDT.IsNull() || theDimObject.IsNull()) |
1966 | return; | |
b7b2f85a | 1967 | Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess(); |
1968 | const Interface_Graph& aGraph = aTP->Graph(); | |
fe0d928d | 1969 | |
cf152970 | 1970 | |
1971 | Standard_Real aFact = 1.; | |
1972 | ||
fe0d928d | 1973 | Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL; |
1974 | for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) { | |
cf152970 | 1975 | Handle(Standard_Transient) anEnt = anIt.Value(); |
1976 | Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = | |
1977 | Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anEnt); | |
1978 | if (!aDCR.IsNull()) | |
1979 | aSDR = !aDCR.IsNull() ? aDCR->Representation() : Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anEnt); | |
fe0d928d | 1980 | } |
cf152970 | 1981 | if (!aSDR.IsNull()) |
1982 | { | |
1983 | XSAlgo::AlgoContainer()->PrepareForTransfer(); | |
1984 | STEPControl_ActorRead anActor; | |
1985 | anActor.PrepareUnits(aSDR, aTP); | |
1986 | aFact = UnitsMethods::LengthFactor(); | |
1987 | } | |
1988 | ||
b7b2f85a | 1989 | if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { |
1990 | // retrieve derived geometry | |
1991 | Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT); | |
1992 | Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo()); | |
1993 | if (aDSA.IsNull()) | |
1994 | return; | |
1995 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL; | |
1996 | for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) { | |
1997 | aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); | |
1998 | } | |
1999 | if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0) | |
2000 | return; | |
2001 | Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1)); | |
2002 | if (aPoint.IsNull()) { | |
2003 | // try Axis2Placement3d.location instead of CartesianPoint | |
2004 | Handle(StepGeom_Axis2Placement3d) anA2P3D = | |
2005 | Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1)); | |
2006 | if (anA2P3D.IsNull()) | |
2007 | return; | |
2008 | aPoint = anA2P3D->Location(); | |
2009 | } | |
cf152970 | 2010 | |
b7b2f85a | 2011 | // set connection point to object |
fe0d928d | 2012 | gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); |
b7b2f85a | 2013 | theDimObject->SetPoint(aPnt); |
2014 | } | |
2015 | else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { | |
2016 | // retrieve derived geometry | |
2017 | Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT); | |
2018 | Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect()); | |
2019 | Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect()); | |
2020 | if (aDSA1.IsNull() && aDSA2.IsNull()) | |
2021 | return; | |
2022 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL; | |
2023 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL; | |
2024 | if (!aDSA1.IsNull()) { | |
2025 | for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) { | |
2026 | aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); | |
2027 | } | |
2028 | } | |
2029 | if (!aDSA2.IsNull()) { | |
2030 | for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) { | |
2031 | aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); | |
2032 | } | |
2033 | } | |
2034 | // first point | |
2035 | if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) { | |
2036 | Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1)); | |
2037 | if (aPoint.IsNull()) { | |
2038 | // try Axis2Placement3d.location instead of CartesianPoint | |
2039 | Handle(StepGeom_Axis2Placement3d) anA2P3D = | |
2040 | Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1)); | |
2041 | if (!anA2P3D.IsNull()) | |
2042 | aPoint = anA2P3D->Location(); | |
2043 | } | |
2044 | if (!aPoint.IsNull()) { | |
2045 | // set connection point to object | |
fe0d928d | 2046 | gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); |
b7b2f85a | 2047 | theDimObject->SetPoint(aPnt); |
2048 | } | |
2049 | } | |
2050 | // second point | |
2051 | if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) { | |
2052 | Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1)); | |
2053 | if (aPoint.IsNull()) { | |
2054 | // try Axis2Placement3d.location instead of CartesianPoint | |
2055 | Handle(StepGeom_Axis2Placement3d) anA2P3D = | |
2056 | Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1)); | |
2057 | if (!anA2P3D.IsNull()) | |
2058 | aPoint = anA2P3D->Location(); | |
2059 | } | |
2060 | if (!aPoint.IsNull()) { | |
2061 | // set connection point to object | |
fe0d928d | 2062 | gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); |
b7b2f85a | 2063 | theDimObject->SetPoint2(aPnt); |
2064 | } | |
2065 | } | |
2066 | } | |
2067 | } | |
2068 | ||
7fd59977 | 2069 | //======================================================================= |
2070 | //function : ReadDatums | |
2071 | //purpose : auxilary | |
2072 | //======================================================================= | |
2073 | static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool, | |
cf152970 | 2074 | const Handle(XCAFDoc_DimTolTool) &DGTTool, |
2075 | const Interface_Graph &graph, | |
2076 | const Handle(Transfer_TransientProcess) &TP, | |
2077 | const TDF_Label TolerL, | |
2078 | const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR) | |
7fd59977 | 2079 | { |
cf152970 | 2080 | if (GTWDR.IsNull()) return Standard_False; |
7fd59977 | 2081 | Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem(); |
cf152970 | 2082 | if (HADR.IsNull()) return Standard_False; |
2083 | for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) { | |
7fd59977 | 2084 | Handle(StepDimTol_DatumReference) DR = HADR->Value(idr); |
2085 | Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum(); | |
cf152970 | 2086 | if (aDatum.IsNull()) continue; |
7fd59977 | 2087 | Interface_EntityIterator subs4 = graph.Sharings(aDatum); |
cf152970 | 2088 | for (subs4.Start(); subs4.More(); subs4.Next()) { |
2089 | Handle(StepRepr_ShapeAspectRelationship) SAR = | |
7fd59977 | 2090 | Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value()); |
cf152970 | 2091 | if (SAR.IsNull()) continue; |
2092 | Handle(StepDimTol_DatumFeature) DF = | |
7fd59977 | 2093 | Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect()); |
cf152970 | 2094 | if (DF.IsNull()) continue; |
7fd59977 | 2095 | Interface_EntityIterator subs5 = graph.Sharings(DF); |
2096 | Handle(StepRepr_PropertyDefinition) PropDef; | |
cf152970 | 2097 | for (subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) { |
7fd59977 | 2098 | PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value()); |
2099 | } | |
cf152970 | 2100 | if (PropDef.IsNull()) continue; |
7fd59977 | 2101 | Handle(StepShape_AdvancedFace) AF; |
2102 | subs5 = graph.Sharings(PropDef); | |
cf152970 | 2103 | for (subs5.Start(); subs5.More(); subs5.Next()) { |
2104 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
7fd59977 | 2105 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value()); |
cf152970 | 2106 | if (!SDR.IsNull()) { |
7fd59977 | 2107 | Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation(); |
cf152970 | 2108 | if (!Repr.IsNull() && Repr->NbItems() > 0) { |
7fd59977 | 2109 | Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1); |
2110 | AF = Handle(StepShape_AdvancedFace)::DownCast(RI); | |
2111 | } | |
2112 | } | |
2113 | } | |
cf152970 | 2114 | if (AF.IsNull()) return Standard_False; |
7fd59977 | 2115 | Standard_Integer index = TP->MapIndex(AF); |
2116 | TopoDS_Shape aSh; | |
cf152970 | 2117 | if (index > 0) { |
7fd59977 | 2118 | Handle(Transfer_Binder) binder = TP->MapItem(index); |
2119 | aSh = TransferBRep::ShapeResult(binder); | |
2120 | } | |
cf152970 | 2121 | if (aSh.IsNull()) continue; |
7fd59977 | 2122 | TDF_Label shL; |
cf152970 | 2123 | if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue; |
2124 | DGTTool->SetDatum(shL, TolerL, PropDef->Name(), PropDef->Description(), aDatum->Identification()); | |
7fd59977 | 2125 | } |
2126 | } | |
2127 | return Standard_True; | |
2128 | } | |
2129 | ||
43d3f6d8 | 2130 | //======================================================================= |
2131 | //function : FindShapeIndexForDGT | |
2132 | //purpose : auxiliary find shape index in map og imported shapes | |
2133 | //======================================================================= | |
2134 | static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt, | |
2135 | const Handle(XSControl_WorkSession)& theWS) | |
2136 | { | |
2137 | const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess(); | |
2138 | // try to find index of given entity | |
2139 | Standard_Integer anIndex = aTP->MapIndex(theEnt); | |
2140 | if (anIndex > 0) | |
2141 | return anIndex; | |
2142 | // if theEnt is a geometry item try to find its topological item | |
2143 | const Interface_Graph& aGraph = aTP->Graph(); | |
2144 | Interface_EntityIterator anIter = aGraph.Sharings(theEnt); | |
2145 | for (anIter.Start(); anIter.More(); anIter.Next()) { | |
2146 | if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem))) | |
2147 | { | |
2148 | anIndex = aTP->MapIndex(anIter.Value()); | |
2149 | if (anIndex > 0) | |
2150 | return anIndex; | |
2151 | } | |
2152 | } | |
2153 | return 0; | |
2154 | } | |
7fd59977 | 2155 | |
400af1bc | 2156 | //======================================================================= |
2157 | //function : collectShapeAspect | |
2158 | //purpose : | |
2159 | //======================================================================= | |
2160 | static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA, | |
cf152970 | 2161 | const Handle(XSControl_WorkSession)& theWS, |
2162 | NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs) | |
400af1bc | 2163 | { |
2164 | if (theSA.IsNull()) | |
2165 | return; | |
2166 | Handle(XSControl_TransferReader) aTR = theWS->TransferReader(); | |
2167 | Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess(); | |
2168 | const Interface_Graph& aGraph = aTP->Graph(); | |
2169 | // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect | |
2170 | if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) { | |
2171 | Interface_EntityIterator anIter = aGraph.Sharings(theSA); | |
2172 | Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL; | |
2173 | for (; aSADR.IsNull() && anIter.More(); anIter.Next()) { | |
2174 | aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value()); | |
2175 | } | |
2176 | if (!aSADR.IsNull()) | |
2177 | collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs); | |
2178 | } | |
2179 | else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) || | |
2180 | theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) { | |
2181 | theSAs.Append(theSA); | |
2182 | return; | |
2183 | } | |
2184 | else { | |
2185 | // Find all children Shape_Aspect | |
2186 | Standard_Boolean isSimple = Standard_True; | |
2187 | Interface_EntityIterator anIter = aGraph.Sharings(theSA); | |
2188 | for (; anIter.More(); anIter.Next()) { | |
2189 | if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) && | |
cf152970 | 2190 | !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { |
400af1bc | 2191 | Handle(StepRepr_ShapeAspectRelationship) aSAR = |
2192 | Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value()); | |
2193 | if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull() | |
cf152970 | 2194 | && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) { |
400af1bc | 2195 | collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs); |
2196 | isSimple = Standard_False; | |
2197 | } | |
2198 | } | |
2199 | } | |
2200 | // If not Composite_Shape_Aspect (or subtype) append to sequence. | |
2201 | if (isSimple) | |
2202 | theSAs.Append(theSA); | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | //======================================================================= | |
2207 | //function : getShapeLabel | |
2208 | //purpose : | |
2209 | //======================================================================= | |
2210 | ||
2211 | static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem, | |
cf152970 | 2212 | const Handle(XSControl_WorkSession)& theWS, |
2213 | const Handle(XCAFDoc_ShapeTool)& theShapeTool) | |
400af1bc | 2214 | { |
2215 | TDF_Label aShapeL; | |
2216 | const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess(); | |
2217 | Standard_Integer index = FindShapeIndexForDGT(theItem, theWS); | |
2218 | TopoDS_Shape aShape; | |
2219 | if (index > 0) { | |
2220 | Handle(Transfer_Binder) aBinder = aTP->MapItem(index); | |
2221 | aShape = TransferBRep::ShapeResult(aBinder); | |
2222 | } | |
2223 | if (aShape.IsNull()) | |
2224 | return aShapeL; | |
2225 | theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True); | |
2226 | return aShapeL; | |
2227 | } | |
2228 | ||
7fd59977 | 2229 | //======================================================================= |
1c9d3225 | 2230 | //function : setDatumToXCAF |
7fd59977 | 2231 | //purpose : |
2232 | //======================================================================= | |
400af1bc | 2233 | |
0c63f2f8 | 2234 | Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, |
cf152970 | 2235 | const TDF_Label theGDTL, |
2236 | const Standard_Integer thePositionCounter, | |
2237 | const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers, | |
2238 | const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal, | |
2239 | const Standard_Real theModifValue, | |
2240 | const Handle(TDocStd_Document)& theDoc, | |
2241 | const Handle(XSControl_WorkSession)& theWS) | |
7fd59977 | 2242 | { |
400af1bc | 2243 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); |
2244 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
7f56eba8 | 2245 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); |
2246 | const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); | |
1c9d3225 | 2247 | const Interface_Graph& aGraph = aTP->Graph(); |
2248 | Handle(XCAFDoc_Datum) aDat; | |
400af1bc | 2249 | TDF_LabelSequence aShapeLabels; |
2250 | Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject(); | |
2251 | ||
2252 | // Collect all links to shapes | |
2253 | NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs; | |
1c9d3225 | 2254 | Interface_EntityIterator anIterD = aGraph.Sharings(theDat); |
400af1bc | 2255 | for (anIterD.Start(); anIterD.More(); anIterD.Next()) { |
2256 | Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value()); | |
2257 | if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull()) | |
2258 | continue; | |
2259 | collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs); | |
2260 | Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect()); | |
2261 | if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) | |
2262 | readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj); | |
2263 | } | |
2264 | ||
2265 | // Collect shape labels | |
2266 | for (Standard_Integer i = 1; i <= aSAs.Length(); i++) { | |
2267 | Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i); | |
2268 | if (aSA.IsNull()) | |
2269 | continue; | |
2270 | // Skip datum targets | |
2271 | if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) | |
2272 | continue; | |
2273 | ||
2274 | // Process all connected GISU | |
2275 | Interface_EntityIterator anIter = aGraph.Sharings(aSA); | |
2276 | for (; anIter.More(); anIter.Next()) { | |
2277 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value()); | |
2278 | if (aGISU.IsNull()) | |
2279 | continue; | |
1209c1b9 | 2280 | for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) { |
2281 | TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool); | |
400af1bc | 2282 | if (!aShapeL.IsNull()) |
2283 | aShapeLabels.Append(aShapeL); | |
7fd59977 | 2284 | } |
1c9d3225 | 2285 | } |
400af1bc | 2286 | } |
2287 | ||
2288 | // Process datum targets and create objects for them | |
2289 | Standard_Boolean isExistDatumTarget = Standard_False; | |
2290 | for (Standard_Integer i = 1; i <= aSAs.Length(); i++) { | |
2291 | Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i)); | |
2292 | if (aDT.IsNull()) | |
2293 | continue; | |
1209c1b9 | 2294 | Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject(); |
400af1bc | 2295 | XCAFDimTolObjects_DatumTargetType aType; |
2296 | if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType)) | |
2297 | continue; | |
1209c1b9 | 2298 | aDatTargetObj->SetDatumTargetType(aType); |
400af1bc | 2299 | Standard_Boolean isValidDT = Standard_False; |
2300 | ||
2301 | // Feature for datum target | |
2302 | TDF_LabelSequence aDTShapeLabels; | |
1209c1b9 | 2303 | Interface_EntityIterator aDTIter = aGraph.Sharings(aDT); |
400af1bc | 2304 | Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship; |
1209c1b9 | 2305 | for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) { |
2306 | aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value()); | |
6595eee7 | 2307 | } |
400af1bc | 2308 | if (!aRelationship.IsNull()) { |
2309 | Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect(); | |
2310 | Interface_EntityIterator aSAIter = aGraph.Sharings(aSA); | |
2311 | for (; aSAIter.More(); aSAIter.Next()) { | |
2312 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value()); | |
2313 | if (aGISU.IsNull()) | |
2314 | continue; | |
1209c1b9 | 2315 | for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) { |
2316 | TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool); | |
400af1bc | 2317 | if (!aShapeL.IsNull()) { |
2318 | aDTShapeLabels.Append(aShapeL); | |
2319 | isValidDT = Standard_True; | |
2320 | } | |
7fd59977 | 2321 | } |
2322 | } | |
1c9d3225 | 2323 | } |
400af1bc | 2324 | |
2325 | if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) { | |
2326 | // Try another way of feature connection | |
1209c1b9 | 2327 | for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) { |
2328 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value()); | |
400af1bc | 2329 | if (aGISU.IsNull()) |
2330 | continue; | |
1209c1b9 | 2331 | for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) { |
2332 | TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool); | |
400af1bc | 2333 | if (!aShapeL.IsNull()) { |
2334 | aDTShapeLabels.Append(aShapeL); | |
2335 | isValidDT = Standard_True; | |
2336 | } | |
2337 | } | |
2338 | } | |
1c9d3225 | 2339 | } |
400af1bc | 2340 | |
2341 | if (aType == XCAFDimTolObjects_DatumTargetType_Area) { | |
2342 | // Area datum target | |
2343 | Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT); | |
2344 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU; | |
2345 | for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) { | |
2346 | aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value()); | |
2347 | } | |
2348 | Handle(StepRepr_RepresentationItem) anItem; | |
2349 | if (aGISU->NbIdentifiedItem() > 0) | |
2350 | anItem = aGISU->IdentifiedItemValue(1); | |
2351 | if (anItem.IsNull()) | |
2352 | continue; | |
2353 | Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS); | |
2354 | if (anItemIndex > 0) { | |
2355 | Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex); | |
2356 | TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder); | |
1209c1b9 | 2357 | aDatTargetObj->SetDatumTarget(anItemShape); |
400af1bc | 2358 | isValidDT = Standard_True; |
2359 | } | |
1c9d3225 | 2360 | } |
400af1bc | 2361 | else { |
2362 | // Point/line/rectangle/circle datum targets | |
2363 | Interface_EntityIterator anIter = aGraph.Sharings(aDT); | |
2364 | Handle(StepRepr_PropertyDefinition) aPD; | |
2365 | for (; anIter.More() && aPD.IsNull(); anIter.Next()) { | |
2366 | aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value()); | |
2367 | } | |
2368 | if (!aPD.IsNull()) { | |
2369 | anIter = aGraph.Sharings(aPD); | |
2370 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; | |
2371 | for (; anIter.More() && aSDR.IsNull(); anIter.Next()) { | |
2372 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value()); | |
2373 | } | |
2374 | if (!aSDR.IsNull()) { | |
2375 | Handle(StepShape_ShapeRepresentationWithParameters) aSRWP | |
2376 | = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation()); | |
2377 | if (!aSRWP.IsNull()) { | |
2378 | isValidDT = Standard_True; | |
2379 | // Collect parameters of datum target | |
1209c1b9 | 2380 | for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++) |
400af1bc | 2381 | { |
1209c1b9 | 2382 | if (aSRWP->ItemsValue(j).IsNull()) |
400af1bc | 2383 | continue; |
1209c1b9 | 2384 | if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) |
1c9d3225 | 2385 | { |
400af1bc | 2386 | Handle(StepGeom_Axis2Placement3d) anAx |
1209c1b9 | 2387 | = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j)); |
477000eb | 2388 | XSAlgo::AlgoContainer()->PrepareForTransfer(); |
2389 | STEPControl_ActorRead anActor; | |
2390 | anActor.PrepareUnits(aSRWP, aTP); | |
400af1bc | 2391 | Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx); |
1209c1b9 | 2392 | aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2()); |
1c9d3225 | 2393 | } |
1209c1b9 | 2394 | else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) |
1c9d3225 | 2395 | { |
400af1bc | 2396 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM = |
1209c1b9 | 2397 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j)); |
400af1bc | 2398 | Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent(); |
2399 | StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent(); | |
400af1bc | 2400 | if (anUnit.IsNull()) |
2401 | continue; | |
2402 | Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit(); | |
2403 | if (aNU.IsNull()) | |
2404 | continue; | |
477000eb | 2405 | STEPConstruct_UnitContext anUnitCtx; |
2406 | anUnitCtx.ComputeFactors(aNU); | |
2407 | aVal = aVal * anUnitCtx.LengthFactor(); | |
400af1bc | 2408 | if (aM->Name()->String().IsEqual("target length") || |
2409 | aM->Name()->String().IsEqual("target diameter")) | |
1209c1b9 | 2410 | aDatTargetObj->SetDatumTargetLength(aVal); |
400af1bc | 2411 | else |
1209c1b9 | 2412 | aDatTargetObj->SetDatumTargetWidth(aVal); |
1c9d3225 | 2413 | } |
2414 | } | |
2415 | } | |
2416 | } | |
2417 | } | |
2418 | } | |
400af1bc | 2419 | |
2420 | // Create datum target object | |
2421 | if (isValidDT) { | |
1c9d3225 | 2422 | TDF_Label aDatL = aDGTTool->AddDatum(); |
0c63f2f8 | 2423 | myGDTMap.Bind(aDT, aDatL); |
2424 | aDGTTool->Lock(aDatL); | |
1c9d3225 | 2425 | aDat = XCAFDoc_Datum::Set(aDatL); |
400af1bc | 2426 | aDGTTool->SetDatum(aDTShapeLabels, aDatL); |
1209c1b9 | 2427 | aDatTargetObj->SetName(theDat->Identification()); |
2428 | aDatTargetObj->SetPosition(thePositionCounter); | |
400af1bc | 2429 | if (!theXCAFModifiers.IsEmpty()) |
1209c1b9 | 2430 | aDatTargetObj->SetModifiers(theXCAFModifiers); |
400af1bc | 2431 | if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None) |
1209c1b9 | 2432 | aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue); |
1c9d3225 | 2433 | aDGTTool->SetDatumToGeomTol(aDatL, theGDTL); |
1209c1b9 | 2434 | aDatTargetObj->IsDatumTarget(Standard_True); |
2435 | aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue()); | |
2436 | readAnnotation(aTR, aDT, aDatTargetObj); | |
2437 | aDat->SetObject(aDatTargetObj); | |
400af1bc | 2438 | isExistDatumTarget = Standard_True; |
5df609e7 | 2439 | } |
1c9d3225 | 2440 | } |
400af1bc | 2441 | |
2442 | if (aShapeLabels.Length() > 0 || !isExistDatumTarget) { | |
2443 | // Create object for datum | |
2444 | TDF_Label aDatL = aDGTTool->AddDatum(); | |
0c63f2f8 | 2445 | myGDTMap.Bind(theDat, aDatL); |
c4fa1c2c | 2446 | // bind datum label with all reference datum_feature entities |
2447 | for (Standard_Integer i = 1; i <= aSAs.Length(); i++) { | |
2448 | Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i); | |
2449 | if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) | |
2450 | continue; | |
2451 | myGDTMap.Bind(aSA, aDatL); | |
2452 | } | |
0c63f2f8 | 2453 | aDGTTool->Lock(aDatL); |
400af1bc | 2454 | aDat = XCAFDoc_Datum::Set(aDatL); |
2455 | aDGTTool->SetDatum(aShapeLabels, aDatL); | |
2456 | aDatObj->SetName(theDat->Identification()); | |
2457 | aDatObj->SetPosition(thePositionCounter); | |
2458 | if (!theXCAFModifiers.IsEmpty()) | |
2459 | aDatObj->SetModifiers(theXCAFModifiers); | |
2460 | if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None) | |
2461 | aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue); | |
2462 | aDGTTool->SetDatumToGeomTol(aDatL, theGDTL); | |
2463 | if (aDatObj->GetPresentation().IsNull()) { | |
2464 | // Try find annotation connected to datum entity (not right case, according recommended practices) | |
2465 | readAnnotation(aTR, theDat, aDatObj); | |
2466 | } | |
2467 | aDat->SetObject(aDatObj); | |
2468 | } | |
2469 | ||
2470 | return Standard_True; | |
1c9d3225 | 2471 | } |
2472 | ||
2473 | ||
2474 | //======================================================================= | |
2475 | //function : ReadDatums | |
2476 | //purpose : auxilary | |
2477 | //======================================================================= | |
0c63f2f8 | 2478 | Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt, |
cf152970 | 2479 | const TDF_Label theGDTL, |
2480 | const Handle(TDocStd_Document)& theDoc, | |
2481 | const Handle(XSControl_WorkSession)& theWS) | |
1c9d3225 | 2482 | { |
7f56eba8 | 2483 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); |
2484 | const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); | |
1c9d3225 | 2485 | const Interface_Graph& aGraph = aTP->Graph(); |
2486 | ||
2487 | Interface_EntityIterator anIter = aGraph.Shareds(theEnt); | |
cf152970 | 2488 | for (anIter.Start(); anIter.More(); anIter.Next()) { |
1c9d3225 | 2489 | Handle(Standard_Transient) anAtr = anIter.Value(); |
cf152970 | 2490 | if (anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem))) |
1c9d3225 | 2491 | { |
2492 | Standard_Integer aPositionCounter = 0;//position on frame | |
2493 | Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr); | |
2494 | Interface_EntityIterator anIterDS = aGraph.Sharings(aDS); | |
cf152970 | 2495 | for (anIterDS.Start(); anIterDS.More(); anIterDS.Next()) { |
1c9d3225 | 2496 | Handle(Standard_Transient) anAtrDS = anIterDS.Value(); |
cf152970 | 2497 | if (anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage))) |
1c9d3225 | 2498 | { |
2499 | //get axis | |
2500 | Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI | |
2501 | = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS); | |
2502 | if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) | |
2503 | { | |
2504 | Handle(StepGeom_Axis2Placement3d) anAx | |
2505 | = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1)); | |
2506 | Handle(XCAFDoc_GeomTolerance) aTol; | |
cf152970 | 2507 | if (theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol)) |
1c9d3225 | 2508 | { |
2509 | Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject(); | |
2510 | Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios(); | |
2511 | Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios(); | |
2512 | Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates(); | |
2513 | gp_Dir aDir; | |
2514 | gp_Dir aDirR; | |
2515 | gp_Pnt aPnt; | |
cf152970 | 2516 | if (!aDirArr.IsNull() && aDirArr->Length() > 2 && |
2517 | !aDirRArr.IsNull() && aDirRArr->Length() > 2 && | |
1c9d3225 | 2518 | !aLocArr.IsNull() && aLocArr->Length() > 2) |
2519 | { | |
cf152970 | 2520 | aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2); |
2521 | aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower() + 1, aDirRArr->Lower() + 2); | |
2522 | aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower() + 1, aLocArr->Lower() + 2); | |
1c9d3225 | 2523 | gp_Ax2 anA(aPnt, aDir, aDirR); |
2524 | anObj->SetAxis(anA); | |
2525 | aTol->SetObject(anObj); | |
2526 | } | |
2527 | } | |
2528 | } | |
2529 | } | |
2530 | } | |
2531 | if (aDS->NbConstituents() > 0) | |
2532 | { | |
2533 | //get datum feature and datum target from datum system | |
2534 | Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents(); | |
cf152970 | 2535 | if (!aDRCA.IsNull()) |
1c9d3225 | 2536 | { |
cf152970 | 2537 | for (Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++) |
1c9d3225 | 2538 | { |
a9dde4a3 | 2539 | Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i); |
1c9d3225 | 2540 | //gete modifiers |
2541 | Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers(); | |
2542 | XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers; | |
2543 | XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None; | |
2544 | Standard_Real aModifValue = 0; | |
cf152970 | 2545 | if (!aModif.IsNull()) |
1c9d3225 | 2546 | { |
cf152970 | 2547 | for (Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++) |
1c9d3225 | 2548 | { |
cf152970 | 2549 | if (aModif->Value(m).CaseNumber() == 2) |
1c9d3225 | 2550 | aXCAFModifiers.Append( |
2551 | (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m). | |
cf152970 | 2552 | SimpleDatumReferenceModifierMember()->Value()); |
1c9d3225 | 2553 | else if (aModif->Value(m).CaseNumber() == 1) |
2554 | { | |
2555 | aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1); | |
2556 | Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent(); | |
2557 | StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent(); | |
cf152970 | 2558 | if (anUnit.IsNull()) continue; |
2559 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 2560 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 2561 | STEPConstruct_UnitContext anUnitCtx; |
2562 | anUnitCtx.ComputeFactors(NU); | |
2563 | aModifValue = aVal * anUnitCtx.LengthFactor(); | |
1c9d3225 | 2564 | } |
2565 | } | |
2566 | } | |
2567 | aPositionCounter++; | |
2568 | Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC); | |
cf152970 | 2569 | for (anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) { |
2570 | ||
2571 | if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) | |
1c9d3225 | 2572 | { |
2573 | Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value()); | |
cf152970 | 2574 | setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS); |
1c9d3225 | 2575 | } |
cf152970 | 2576 | else if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement))) |
1c9d3225 | 2577 | { |
cf152970 | 2578 | Handle(StepDimTol_DatumReferenceElement) aDRE |
1c9d3225 | 2579 | = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value()); |
2580 | //get modifiers from group of datums | |
2581 | Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers(); | |
cf152970 | 2582 | if (!aModifE.IsNull()) |
1c9d3225 | 2583 | { |
cf152970 | 2584 | for (Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++) |
1c9d3225 | 2585 | { |
cf152970 | 2586 | if (aModifE->Value(k).CaseNumber() == 2) |
1c9d3225 | 2587 | aXCAFModifiers.Append( |
2588 | (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k). | |
cf152970 | 2589 | SimpleDatumReferenceModifierMember()->Value()); |
f3ec3b37 | 2590 | else if (aModifE->Value(k).CaseNumber() == 1) |
1c9d3225 | 2591 | { |
2592 | aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1); | |
2593 | Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent(); | |
2594 | StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent(); | |
cf152970 | 2595 | if (anUnit.IsNull()) continue; |
2596 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
7fd59977 | 2597 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 2598 | STEPConstruct_UnitContext anUnitCtx; |
2599 | anUnitCtx.ComputeFactors(NU); | |
2600 | aModifValue = aVal * anUnitCtx.LengthFactor(); | |
7fd59977 | 2601 | } |
2602 | } | |
2603 | } | |
1c9d3225 | 2604 | Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE); |
cf152970 | 2605 | for (anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) { |
2606 | if (anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) | |
1c9d3225 | 2607 | { |
2608 | Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value()); | |
cf152970 | 2609 | setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS); |
1c9d3225 | 2610 | } |
2611 | } | |
7fd59977 | 2612 | } |
2613 | } | |
2614 | } | |
1c9d3225 | 2615 | } |
2616 | } | |
2617 | } | |
2618 | } | |
2619 | return Standard_True; | |
2620 | } | |
2621 | ||
b7b2f85a | 2622 | //======================================================================= |
2623 | //function : createGeomTolObjectInXCAF | |
1c9d3225 | 2624 | //purpose : |
2625 | //======================================================================= | |
0c63f2f8 | 2626 | TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, |
cf152970 | 2627 | const Handle(TDocStd_Document)& theDoc, |
2628 | const Handle(XSControl_WorkSession)& theWS) | |
1c9d3225 | 2629 | { |
2630 | TDF_Label aGDTL; | |
cf152970 | 2631 | if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) && |
2632 | !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) && | |
2633 | !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) | |
1c9d3225 | 2634 | { |
2635 | return aGDTL; | |
2636 | } | |
eacdb38f | 2637 | |
2638 | Handle(TCollection_HAsciiString) aSemanticName; | |
2639 | ||
f3ec3b37 | 2640 | // protection against invalid input |
2641 | if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
2642 | Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt); | |
2643 | if (aGeomTol->TolerancedShapeAspect().IsNull()) | |
2644 | return aGDTL; | |
eacdb38f | 2645 | aSemanticName = aGeomTol->Name(); |
f3ec3b37 | 2646 | } |
2647 | if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { | |
2648 | Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt); | |
2649 | if (aDim->AppliesTo().IsNull()) | |
2650 | return aGDTL; | |
eacdb38f | 2651 | aSemanticName = aDim->Name(); |
f3ec3b37 | 2652 | } |
2653 | if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { | |
2654 | Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt); | |
2655 | if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull()) | |
2656 | return aGDTL; | |
eacdb38f | 2657 | aSemanticName = aDim->Name(); |
f3ec3b37 | 2658 | } |
1c9d3225 | 2659 | |
cf152970 | 2660 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); |
2661 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
7f56eba8 | 2662 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); |
2663 | const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); | |
1c9d3225 | 2664 | const Interface_Graph& aGraph = aTP->Graph(); |
2665 | Standard_Boolean isAllAround = Standard_False; | |
2666 | Standard_Boolean isAllOver = Standard_False; | |
cf152970 | 2667 | |
1c9d3225 | 2668 | // find RepresentationItem for current Ent |
2669 | NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2; | |
2670 | ||
b7b2f85a | 2671 | // Collect all Shape_Aspect entities |
1c9d3225 | 2672 | Interface_EntityIterator anIter = aGraph.Shareds(theEnt); |
cf152970 | 2673 | for (anIter.Start(); anIter.More(); anIter.Next()) { |
1c9d3225 | 2674 | Handle(Standard_Transient) anAtr = anIter.Value(); |
2675 | NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs; | |
cf152970 | 2676 | if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) |
1c9d3225 | 2677 | { |
2678 | //if associating tolerances with part (All-Over) | |
2679 | Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr); | |
cf152970 | 2680 | for (anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next()) |
1c9d3225 | 2681 | { |
2682 | Handle(Standard_Transient) anAtrSDR = anIterSDR.Value(); | |
cf152970 | 2683 | if (anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) |
1c9d3225 | 2684 | { |
2685 | isAllOver = Standard_True; | |
2686 | Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR); | |
cf152970 | 2687 | for (anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next()) |
1c9d3225 | 2688 | { |
2689 | Handle(Standard_Transient) anAtrABSR = anIterABSR.Value(); | |
cf152970 | 2690 | if (anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation))) |
1c9d3225 | 2691 | { |
2692 | aSeqRI1.Append(anAtrABSR); | |
2693 | } | |
7fd59977 | 2694 | } |
7fd59977 | 2695 | } |
1c9d3225 | 2696 | } |
2697 | } | |
cf152970 | 2698 | else if (anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) || |
1c9d3225 | 2699 | anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) |
2700 | { | |
2701 | //if tolerance attached to dimension | |
2702 | Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr); | |
cf152970 | 2703 | for (anIterDim.Start(); anIterDim.More(); anIterDim.Next()) |
1c9d3225 | 2704 | { |
b7b2f85a | 2705 | Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value()); |
cf152970 | 2706 | if (!aSA.IsNull()) { |
b7b2f85a | 2707 | collectShapeAspect(aSA, theWS, aSAs); |
1c9d3225 | 2708 | } |
2709 | } | |
2710 | } | |
cf152970 | 2711 | else if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) |
1c9d3225 | 2712 | { |
cf152970 | 2713 | if (anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect))) |
1c9d3225 | 2714 | { |
2715 | // if applyed AllAround Modifier | |
2716 | isAllAround = Standard_True; | |
1c9d3225 | 2717 | } |
b7b2f85a | 2718 | // dimensions and default tolerances |
2719 | Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr); | |
cf152970 | 2720 | if (!aSA.IsNull()) { |
b7b2f85a | 2721 | collectShapeAspect(aSA, theWS, aSAs); |
1c9d3225 | 2722 | } |
2723 | } | |
b7b2f85a | 2724 | |
2725 | // Collect all representation items | |
cf152970 | 2726 | if (!aSAs.IsEmpty()) |
1c9d3225 | 2727 | { |
2728 | //get representation items | |
2729 | NCollection_Sequence<Handle(Standard_Transient)> aSeqRI; | |
cf152970 | 2730 | for (Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++) |
1c9d3225 | 2731 | { |
2732 | Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i)); | |
2733 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU; | |
2734 | Handle(StepRepr_PropertyDefinition) PropD; | |
cf152970 | 2735 | for (anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) { |
1c9d3225 | 2736 | aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value()); |
2737 | PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value()); | |
2738 | } | |
cf152970 | 2739 | if (!PropD.IsNull())//for old version |
1c9d3225 | 2740 | { |
2741 | Handle(StepRepr_RepresentationItem) RI; | |
2742 | Interface_EntityIterator subs4 = aGraph.Sharings(PropD); | |
cf152970 | 2743 | for (subs4.Start(); subs4.More(); subs4.Next()) { |
2744 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = | |
1c9d3225 | 2745 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value()); |
cf152970 | 2746 | if (!SDR.IsNull()) { |
1c9d3225 | 2747 | Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation(); |
cf152970 | 2748 | if (!Repr.IsNull() && Repr->NbItems() > 0) { |
1c9d3225 | 2749 | RI = Repr->ItemsValue(1); |
2750 | } | |
2751 | } | |
7fd59977 | 2752 | } |
cf152970 | 2753 | if (RI.IsNull()) continue; |
1c9d3225 | 2754 | |
cf152970 | 2755 | if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { |
1c9d3225 | 2756 | // read dimensions |
2757 | Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI); | |
cf152970 | 2758 | if (EC.IsNull()) continue; |
1c9d3225 | 2759 | Handle(TCollection_HAsciiString) aName; |
cf152970 | 2760 | Handle(StepShape_DimensionalSize) DimSize = |
1c9d3225 | 2761 | Handle(StepShape_DimensionalSize)::DownCast(theEnt); |
cf152970 | 2762 | Standard_Real dim1 = -1., dim2 = -1.; |
1c9d3225 | 2763 | subs4 = aGraph.Sharings(DimSize); |
cf152970 | 2764 | for (subs4.Start(); subs4.More(); subs4.Next()) { |
2765 | Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR = | |
1c9d3225 | 2766 | Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value()); |
cf152970 | 2767 | if (!DimCharR.IsNull()) { |
1c9d3225 | 2768 | Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation(); |
cf152970 | 2769 | if (!SDimR.IsNull() && SDimR->NbItems() > 0) { |
f2139a7f | 2770 | Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1); |
2771 | Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem); | |
cf152970 | 2772 | if (!VR.IsNull()) { |
1c9d3225 | 2773 | aName = VR->Name(); |
2774 | //StepRepr_CompoundItemDefinition CID = VR->ItemElement(); | |
2775 | //if(CID.IsNull()) continue; | |
2776 | //Handle(StepRepr_CompoundItemDefinitionMember) CIDM = | |
2777 | // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value()); | |
2778 | //if(CIDM.IsNull()) continue; | |
2779 | //if(CIDM->ArrTransient().IsNull()) continue; | |
2780 | //Handle(StepRepr_HArray1OfRepresentationItem) HARI; | |
2781 | //if(CID.CaseMem(CIDM)==1) | |
2782 | // HARI = CID.ListRepresentationItem(); | |
2783 | //if(CID.CaseMem(CIDM)==2) | |
2784 | // HARI = CID.SetRepresentationItem(); | |
2785 | Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement(); | |
cf152970 | 2786 | if (HARI.IsNull()) continue; |
2787 | if (HARI->Length() > 0) { | |
a9dde4a3 | 2788 | Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1); |
cf152970 | 2789 | if (RI1.IsNull()) continue; |
2790 | if (RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) { | |
1c9d3225 | 2791 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU = |
2792 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1); | |
2793 | dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent(); | |
2794 | StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent(); | |
cf152970 | 2795 | if (anUnit.IsNull()) continue; |
2796 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 2797 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 2798 | STEPConstruct_UnitContext anUnitCtx; |
2799 | anUnitCtx.ComputeFactors(NU); | |
2800 | dim1 = dim1 * anUnitCtx.LengthFactor(); | |
1c9d3225 | 2801 | } |
2802 | } | |
cf152970 | 2803 | if (HARI->Length() > 1) { |
a9dde4a3 | 2804 | Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2); |
cf152970 | 2805 | if (RI2.IsNull()) continue; |
2806 | if (RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) { | |
1c9d3225 | 2807 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU = |
2808 | Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2); | |
2809 | dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent(); | |
2810 | StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent(); | |
cf152970 | 2811 | if (anUnit.IsNull()) continue; |
2812 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 2813 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 2814 | STEPConstruct_UnitContext anUnitCtx; |
2815 | anUnitCtx.ComputeFactors(NU); | |
2816 | dim2 = dim2 * anUnitCtx.LengthFactor(); | |
1c9d3225 | 2817 | } |
2818 | } | |
2819 | } | |
2820 | } | |
2821 | } | |
2822 | } | |
cf152970 | 2823 | if (dim1 < 0) continue; |
2824 | if (dim2 < 0) dim2 = dim1; | |
1c9d3225 | 2825 | //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl; |
2826 | // now we know edge_curve and value range therefore | |
2827 | // we can create corresponding D> labels | |
2828 | Standard_Integer index = aTP->MapIndex(EC); | |
2829 | TopoDS_Shape aSh; | |
cf152970 | 2830 | if (index > 0) { |
1c9d3225 | 2831 | Handle(Transfer_Binder) binder = aTP->MapItem(index); |
2832 | aSh = TransferBRep::ShapeResult(binder); | |
2833 | } | |
cf152970 | 2834 | if (aSh.IsNull()) continue; |
1c9d3225 | 2835 | TDF_Label shL; |
cf152970 | 2836 | if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue; |
2837 | Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 2); | |
2838 | arr->SetValue(1, dim1); | |
2839 | arr->SetValue(2, dim2); | |
2840 | aDGTTool->SetDimTol(shL, 1, arr, aName, DimSize->Name()); | |
7fd59977 | 2841 | } |
1c9d3225 | 2842 | // read tolerances and datums |
cf152970 | 2843 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { |
1c9d3225 | 2844 | Handle(StepDimTol_GeometricTolerance) GT = |
2845 | Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt); | |
2846 | // read common data for tolerance | |
2847 | //Standard_Real dim = GT->Magnitude()->ValueComponent(); | |
cf152970 | 2848 | Handle(StepBasic_MeasureWithUnit) dim3 = GT->Magnitude(); |
2849 | if (dim3.IsNull()) continue; | |
1c9d3225 | 2850 | Standard_Real dim = dim3->ValueComponent(); |
2851 | StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent(); | |
cf152970 | 2852 | if (anUnit.IsNull()) continue; |
2853 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 2854 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 2855 | STEPConstruct_UnitContext anUnitCtx; |
2856 | anUnitCtx.ComputeFactors(NU); | |
2857 | dim = dim * anUnitCtx.LengthFactor(); | |
1c9d3225 | 2858 | //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl; |
cf152970 | 2859 | Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 1); |
2860 | arr->SetValue(1, dim); | |
1c9d3225 | 2861 | Handle(TCollection_HAsciiString) aName = GT->Name(); |
2862 | Handle(TCollection_HAsciiString) aDescription = GT->Description(); | |
2863 | Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI); | |
cf152970 | 2864 | if (AF.IsNull()) continue; |
1c9d3225 | 2865 | Standard_Integer index = aTP->MapIndex(AF); |
2866 | TopoDS_Shape aSh; | |
cf152970 | 2867 | if (index > 0) { |
1c9d3225 | 2868 | Handle(Transfer_Binder) binder = aTP->MapItem(index); |
2869 | aSh = TransferBRep::ShapeResult(binder); | |
2870 | } | |
cf152970 | 2871 | if (aSh.IsNull()) continue; |
1c9d3225 | 2872 | TDF_Label shL; |
cf152970 | 2873 | if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue; |
1c9d3225 | 2874 | // read specific data for tolerance |
cf152970 | 2875 | if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) { |
1c9d3225 | 2876 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex = |
2877 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt); | |
cf152970 | 2878 | Standard_Integer kind = 20; |
2879 | Handle(StepDimTol_ModifiedGeometricTolerance) MGT = | |
1c9d3225 | 2880 | GTComplex->GetModifiedGeometricTolerance(); |
cf152970 | 2881 | if (!MGT.IsNull()) { |
2882 | kind = kind + MGT->Modifier() + 1; | |
1c9d3225 | 2883 | } |
cf152970 | 2884 | TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription); |
1c9d3225 | 2885 | // translate datums connected with this tolerance |
2886 | Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR = | |
2887 | GTComplex->GetGeometricToleranceWithDatumReference(); | |
cf152970 | 2888 | if (!GTWDR.IsNull()) { |
2889 | ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR); | |
1c9d3225 | 2890 | } |
2891 | } | |
cf152970 | 2892 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) { |
1c9d3225 | 2893 | Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR = |
2894 | Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt); | |
cf152970 | 2895 | if (GTWDR.IsNull()) continue; |
1c9d3225 | 2896 | Standard_Integer kind = 0; |
cf152970 | 2897 | if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24; |
2898 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25; | |
2899 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26; | |
2900 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27; | |
2901 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28; | |
2902 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29; | |
2903 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30; | |
2904 | else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31; | |
1c9d3225 | 2905 | //cout<<"GTWDR: kind="<<kind<<endl; |
cf152970 | 2906 | TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription); |
2907 | ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR); | |
1c9d3225 | 2908 | } |
cf152970 | 2909 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) { |
1c9d3225 | 2910 | Handle(StepDimTol_ModifiedGeometricTolerance) MGT = |
2911 | Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt); | |
2912 | Standard_Integer kind = 35 + MGT->Modifier(); | |
cf152970 | 2913 | aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription); |
1c9d3225 | 2914 | } |
cf152970 | 2915 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) { |
2916 | aDGTTool->SetDimTol(shL, 38, arr, aName, aDescription); | |
1c9d3225 | 2917 | } |
cf152970 | 2918 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) { |
2919 | aDGTTool->SetDimTol(shL, 39, arr, aName, aDescription); | |
1c9d3225 | 2920 | } |
cf152970 | 2921 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) { |
2922 | aDGTTool->SetDimTol(shL, 40, arr, aName, aDescription); | |
1c9d3225 | 2923 | } |
cf152970 | 2924 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) { |
2925 | aDGTTool->SetDimTol(shL, 41, arr, aName, aDescription); | |
1c9d3225 | 2926 | } |
cf152970 | 2927 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) { |
2928 | aDGTTool->SetDimTol(shL, 42, arr, aName, aDescription); | |
1c9d3225 | 2929 | } |
cf152970 | 2930 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) { |
2931 | aDGTTool->SetDimTol(shL, 43, arr, aName, aDescription); | |
1c9d3225 | 2932 | } |
cf152970 | 2933 | else if (GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) { |
2934 | aDGTTool->SetDimTol(shL, 44, arr, aName, aDescription); | |
1c9d3225 | 2935 | } |
7fd59977 | 2936 | } |
1c9d3225 | 2937 | } |
2938 | else | |
2939 | { | |
cf152970 | 2940 | if (aGISU.IsNull()) continue; |
2941 | Standard_Integer j = 1; | |
2942 | for (; j <= aGISU->NbIdentifiedItem(); j++) { | |
0911d065 | 2943 | aSeqRI.Append(aGISU->IdentifiedItemValue(j)); |
7fd59977 | 2944 | } |
1c9d3225 | 2945 | } |
2946 | } | |
cf152970 | 2947 | if (!aSeqRI.IsEmpty()) |
1c9d3225 | 2948 | { |
cf152970 | 2949 | if (aSeqRI1.IsEmpty()) |
1c9d3225 | 2950 | aSeqRI1 = aSeqRI; |
cf152970 | 2951 | else |
1c9d3225 | 2952 | aSeqRI2 = aSeqRI; |
2953 | } | |
2954 | } | |
2955 | } | |
cf152970 | 2956 | if (aSeqRI1.IsEmpty()) |
935069d2 | 2957 | return aGDTL; |
1c9d3225 | 2958 | |
2959 | TDF_LabelSequence aShLS1, aShLS2; | |
2960 | ||
b7b2f85a | 2961 | // Collect shapes |
cf152970 | 2962 | for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper();i++) |
1c9d3225 | 2963 | { |
43d3f6d8 | 2964 | Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS); |
1c9d3225 | 2965 | TopoDS_Shape aSh; |
cf152970 | 2966 | if (anIndex > 0) { |
1c9d3225 | 2967 | Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); |
2968 | aSh = TransferBRep::ShapeResult(aBinder); | |
2969 | } | |
cf152970 | 2970 | if (!aSh.IsNull()) |
1c9d3225 | 2971 | { |
2972 | TDF_Label aShL; | |
2973 | aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True); | |
5b7f8e0a | 2974 | if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE) |
2975 | { | |
2976 | TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE); | |
2977 | while (ex.More()) | |
2978 | { | |
2979 | TDF_Label edgeL; | |
2980 | aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True); | |
2981 | if (!edgeL.IsNull()) | |
2982 | aShLS1.Append(edgeL); | |
2983 | ex.Next(); | |
2984 | } | |
2985 | } | |
2986 | if (!aShL.IsNull()) | |
2987 | aShLS1.Append(aShL); | |
1c9d3225 | 2988 | } |
2989 | } | |
2990 | if (!aSeqRI2.IsEmpty()) | |
2991 | { | |
2992 | //for dimensional location | |
cf152970 | 2993 | for (Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper();i++) |
1c9d3225 | 2994 | { |
43d3f6d8 | 2995 | Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS); |
1c9d3225 | 2996 | TopoDS_Shape aSh; |
cf152970 | 2997 | if (anIndex > 0) { |
1c9d3225 | 2998 | Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); |
2999 | aSh = TransferBRep::ShapeResult(aBinder); | |
3000 | } | |
cf152970 | 3001 | if (!aSh.IsNull()) |
1c9d3225 | 3002 | { |
3003 | TDF_Label aShL; | |
3004 | aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True); | |
5b7f8e0a | 3005 | if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE) |
3006 | { | |
3007 | TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE); | |
3008 | while (ex.More()) | |
3009 | { | |
3010 | TDF_Label edgeL; | |
3011 | aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True); | |
3012 | if (!edgeL.IsNull()) | |
3013 | aShLS2.Append(edgeL); | |
3014 | ex.Next(); | |
3015 | } | |
3016 | } | |
3017 | if (!aShL.IsNull()) | |
3018 | aShLS2.Append(aShL); | |
1c9d3225 | 3019 | } |
3020 | } | |
3021 | } | |
3022 | ||
cf152970 | 3023 | if (!aShLS1.IsEmpty()) |
1c9d3225 | 3024 | { |
3025 | // add to XCAF | |
cf152970 | 3026 | if (!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) |
1c9d3225 | 3027 | { |
3028 | aGDTL = aDGTTool->AddDimension(); | |
0c63f2f8 | 3029 | myGDTMap.Bind(theEnt, aGDTL); |
3030 | aDGTTool->Lock(aGDTL); | |
1c9d3225 | 3031 | Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL); |
3032 | TCollection_AsciiString aStr("DGT:Dimensional_"); | |
cf152970 | 3033 | if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) |
1c9d3225 | 3034 | { |
3035 | aStr.AssignCat("Size"); | |
3036 | } | |
cf152970 | 3037 | else if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) |
1c9d3225 | 3038 | { |
3039 | aStr.AssignCat("Location"); | |
3040 | } | |
3041 | TDataStd_Name::Set(aGDTL, aStr); | |
3042 | ||
cf152970 | 3043 | if (!aShLS2.IsEmpty()) |
1c9d3225 | 3044 | { |
3045 | aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL); | |
3046 | } | |
3047 | else | |
3048 | { | |
3049 | TDF_LabelSequence aEmptySeq; | |
3050 | aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL); | |
3051 | } | |
3052 | } | |
3053 | else | |
3054 | { | |
3055 | aGDTL = aDGTTool->AddGeomTolerance(); | |
0c63f2f8 | 3056 | myGDTMap.Bind(theEnt, aGDTL); |
3057 | aDGTTool->Lock(aGDTL); | |
1c9d3225 | 3058 | Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL); |
3059 | TCollection_AsciiString aStr("DGT:GeomTolerance"); | |
3060 | TDataStd_Name::Set(aGDTL, aStr); | |
3061 | aDGTTool->SetGeomTolerance(aShLS1, aGDTL); | |
3062 | Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject(); | |
cf152970 | 3063 | if (isAllAround) |
1c9d3225 | 3064 | anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around); |
cf152970 | 3065 | else if (isAllOver) |
1c9d3225 | 3066 | anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over); |
3067 | aGTol->SetObject(anObj); | |
3068 | } | |
eacdb38f | 3069 | |
3070 | if (aSemanticName) | |
3071 | { | |
3072 | TCollection_ExtendedString str(aSemanticName->String()); | |
3073 | TDataStd_Name::Set(aGDTL, str); | |
3074 | } | |
3075 | ||
1c9d3225 | 3076 | readDatumsAP242(theEnt, aGDTL, theDoc, theWS); |
3077 | } | |
3078 | return aGDTL; | |
3079 | } | |
3080 | ||
477000eb | 3081 | //======================================================================= |
3082 | //function : convertAngleValue | |
3083 | //purpose : auxilary | |
3084 | //======================================================================= | |
3085 | void convertAngleValue( | |
3086 | const STEPConstruct_UnitContext& anUnitCtx, | |
3087 | Standard_Real& aVal) | |
3088 | { | |
3089 | // convert radian to deg | |
3090 | Standard_Real aFact = anUnitCtx.PlaneAngleFactor() * 180 / M_PI; | |
3091 | // in order to avoid inaccuracy of calculation perform conversion | |
3092 | // only if aFact not eqaul 1 with some precision | |
3093 | if (fabs(1. - aFact) > Precision::Confusion()) | |
3094 | { | |
3095 | aVal = aVal * aFact; | |
3096 | } | |
3097 | } | |
3098 | ||
3099 | ||
1c9d3225 | 3100 | //======================================================================= |
3101 | //function : setDimObjectToXCAF | |
3102 | //purpose : | |
3103 | //======================================================================= | |
3104 | static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt, | |
cf152970 | 3105 | const TDF_Label& aDimL, |
3106 | const Handle(TDocStd_Document)& theDoc, | |
3107 | const Handle(XSControl_WorkSession)& theWS) | |
1c9d3225 | 3108 | { |
cf152970 | 3109 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); |
3110 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
7f56eba8 | 3111 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); |
3112 | const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); | |
1c9d3225 | 3113 | const Interface_Graph& aGraph = aTP->Graph(); |
3114 | Handle(XCAFDimTolObjects_DimensionObject) aDimObj; | |
cf152970 | 3115 | if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) && |
3116 | !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) | |
1c9d3225 | 3117 | return; |
3118 | ||
cf152970 | 3119 | Handle(StepShape_DimensionalSize) aDimSize = |
1c9d3225 | 3120 | Handle(StepShape_DimensionalSize)::DownCast(theEnt); |
cf152970 | 3121 | Handle(StepShape_DimensionalLocation) aDimLocation = |
1c9d3225 | 3122 | Handle(StepShape_DimensionalLocation)::DownCast(theEnt); |
3123 | ||
7644c7f4 | 3124 | aDimObj = new XCAFDimTolObjects_DimensionObject(); |
cf152970 | 3125 | Standard_Real aDim1 = -1., aDim2 = -1., aDim3 = -1.; |
5b7f8e0a | 3126 | Standard_Boolean isPlusMinusTolerance = Standard_False; |
1c9d3225 | 3127 | Handle(StepShape_TypeQualifier) aTQ; |
3128 | Handle(StepShape_ValueFormatTypeQualifier) aVFTQ; | |
3129 | Handle(StepShape_ToleranceValue) aTV; | |
3130 | Handle(StepShape_LimitsAndFits) aLAF; | |
3131 | Handle(StepRepr_CompoundRepresentationItem) aCRI; | |
3132 | Handle(StepGeom_Axis2Placement3d) anAP; | |
3133 | ||
3134 | Interface_EntityIterator anIterDim; | |
cf152970 | 3135 | if (!aDimSize.IsNull()) |
1c9d3225 | 3136 | { |
3137 | anIterDim = aGraph.Sharings(aDimSize); | |
3138 | } | |
3139 | else | |
3140 | { | |
3141 | anIterDim = aGraph.Sharings(aDimLocation); | |
3142 | } | |
cf152970 | 3143 | for (anIterDim.Start(); anIterDim.More(); anIterDim.Next()) { |
3144 | Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = | |
1c9d3225 | 3145 | Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value()); |
cf152970 | 3146 | Handle(StepShape_PlusMinusTolerance) aPMT = |
1c9d3225 | 3147 | Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value()); |
cf152970 | 3148 | if (!aDCR.IsNull()) { |
1c9d3225 | 3149 | Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation(); |
cf152970 | 3150 | if (!aSDR.IsNull()) { |
1c9d3225 | 3151 | Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items(); |
3152 | ||
cf152970 | 3153 | if (!aHARI.IsNull()) |
1c9d3225 | 3154 | { |
cf152970 | 3155 | for (Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++) |
1c9d3225 | 3156 | { |
a9dde4a3 | 3157 | Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr); |
cf152970 | 3158 | if (aDRI.IsNull()) continue; |
1c9d3225 | 3159 | |
5b7f8e0a | 3160 | if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) { |
3161 | // simple value / range | |
3162 | Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU = | |
3163 | Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI); | |
3164 | Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent(); | |
3165 | StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent(); | |
cf152970 | 3166 | if (anUnit.IsNull()) |
5b7f8e0a | 3167 | continue; |
cf152970 | 3168 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) |
5b7f8e0a | 3169 | continue; |
1c9d3225 | 3170 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3171 | STEPConstruct_UnitContext anUnitCtx; |
3172 | anUnitCtx.ComputeFactors(NU); | |
5b7f8e0a | 3173 | if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) { |
477000eb | 3174 | aVal = aVal * anUnitCtx.LengthFactor(); |
cf152970 | 3175 | |
1c9d3225 | 3176 | } |
3177 | else | |
5b7f8e0a | 3178 | if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) { |
477000eb | 3179 | convertAngleValue(anUnitCtx, aVal); |
5b7f8e0a | 3180 | } |
3181 | Handle(TCollection_HAsciiString) aName = aMWU->Name(); | |
3182 | if (aName->Search("upper") > 0) // upper limit | |
3183 | aDim2 = aVal; | |
3184 | else // lower limit or simple nominal value | |
1c9d3225 | 3185 | aDim1 = aVal; |
3186 | } | |
5b7f8e0a | 3187 | else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) { |
3188 | // value with qualifier (minimum/maximum/average) | |
3189 | Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU = | |
3190 | Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI); | |
3191 | Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent(); | |
3192 | StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent(); | |
cf152970 | 3193 | if (anUnit.IsNull()) |
5b7f8e0a | 3194 | continue; |
cf152970 | 3195 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) |
5b7f8e0a | 3196 | continue; |
1c9d3225 | 3197 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3198 | STEPConstruct_UnitContext anUnitCtx; |
3199 | anUnitCtx.ComputeFactors(NU); | |
5b7f8e0a | 3200 | if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) { |
477000eb | 3201 | aVal = aVal * anUnitCtx.LengthFactor(); |
1c9d3225 | 3202 | } |
3203 | else | |
5b7f8e0a | 3204 | if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) { |
477000eb | 3205 | convertAngleValue(anUnitCtx, aVal); |
5b7f8e0a | 3206 | } |
3207 | Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem(); | |
3208 | if (aQRI->Qualifiers()->Length() == 0) { | |
1c9d3225 | 3209 | aDim1 = aVal; |
5b7f8e0a | 3210 | continue; |
3211 | } | |
3212 | Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier(); | |
3213 | if (aValueType->Name()->String().IsEqual("minimum")) | |
3214 | aDim2 = aVal; | |
3215 | else if (aValueType->Name()->String().IsEqual("maximum")) | |
3216 | aDim3 = aVal; | |
3217 | else aDim1 = aVal; | |
1c9d3225 | 3218 | } |
cf152970 | 3219 | else if (aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) { |
1c9d3225 | 3220 | //get qualifier |
3221 | Handle(StepShape_QualifiedRepresentationItem) aQRI = | |
3222 | Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI); | |
cf152970 | 3223 | for (Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++) |
1c9d3225 | 3224 | { |
3225 | aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier(); | |
3226 | aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier(); | |
3227 | } | |
3228 | } | |
7644c7f4 | 3229 | else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) { |
3230 | Handle(StepRepr_DescriptiveRepresentationItem) aDescription = | |
3231 | Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI); | |
3232 | aDimObj->AddDescription(aDescription->Description(), aDescription->Name()); | |
3233 | } | |
cf152970 | 3234 | else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) { |
1c9d3225 | 3235 | aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI); |
3236 | } | |
cf152970 | 3237 | else if (aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) |
1c9d3225 | 3238 | { |
3239 | anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI); | |
3240 | } | |
7fd59977 | 3241 | } |
1c9d3225 | 3242 | } |
3243 | } | |
3244 | } | |
3245 | else if (!aPMT.IsNull()) | |
3246 | { | |
5b7f8e0a | 3247 | isPlusMinusTolerance = Standard_True; |
1c9d3225 | 3248 | StepShape_ToleranceMethodDefinition aTMD = aPMT->Range(); |
cf152970 | 3249 | if (aPMT.IsNull()) continue; |
3250 | if (aTMD.CaseNumber() == 1) | |
1c9d3225 | 3251 | //! 1 -> ToleranceValue from StepShape |
3252 | //! 2 -> LimitsAndFits from StepShape | |
3253 | { | |
3254 | //plus minus tolerance | |
3255 | aTV = aTMD.ToleranceValue(); | |
3256 | if (aTV.IsNull()) continue; | |
3257 | ||
33defc71 | 3258 | Handle(Standard_Transient) aUpperBound = aTV->UpperBound(); |
3259 | if(aUpperBound.IsNull()) | |
3260 | continue; | |
3261 | Handle(StepBasic_MeasureWithUnit) aMWU; | |
3262 | if(aUpperBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) ) | |
3263 | aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aUpperBound); | |
3264 | else if(aUpperBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) ) | |
3265 | { | |
3266 | Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem = | |
3267 | Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUpperBound); | |
3268 | aMWU = aReprMeasureItem->GetMeasureWithUnit(); | |
3269 | ||
3270 | } | |
3271 | if(aMWU.IsNull()) | |
3272 | continue; | |
3273 | Standard_Real aVal = aMWU->ValueComponent(); | |
3274 | StepBasic_Unit anUnit = aMWU->UnitComponent(); | |
cf152970 | 3275 | if (anUnit.IsNull()) continue; |
3276 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 3277 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3278 | STEPConstruct_UnitContext anUnitCtx; |
3279 | anUnitCtx.ComputeFactors(NU); | |
3280 | if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) || | |
3281 | aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) | |
3282 | { | |
3283 | aVal = aVal * anUnitCtx.LengthFactor(); | |
3284 | } | |
3285 | else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) || | |
3286 | aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) | |
3287 | { | |
3288 | convertAngleValue(anUnitCtx, aVal); | |
3289 | } | |
1c9d3225 | 3290 | aDim3 = aVal; |
3291 | ||
33defc71 | 3292 | |
3293 | Handle(Standard_Transient) aLowerBound = aTV->LowerBound(); | |
3294 | if(aLowerBound.IsNull()) | |
3295 | continue; | |
3296 | ||
3297 | if(aLowerBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) ) | |
3298 | aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aLowerBound); | |
3299 | else if(aLowerBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) ) | |
3300 | { | |
3301 | Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem = | |
3302 | Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aLowerBound); | |
3303 | aMWU = aReprMeasureItem->GetMeasureWithUnit(); | |
3304 | ||
3305 | } | |
3306 | if(aMWU.IsNull()) | |
3307 | continue; | |
3308 | ||
3309 | aVal = aMWU->ValueComponent(); | |
3310 | anUnit = aMWU->UnitComponent(); | |
cf152970 | 3311 | if (anUnit.IsNull()) continue; |
3312 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 3313 | NU = anUnit.NamedUnit(); |
477000eb | 3314 | anUnitCtx.ComputeFactors(NU); |
3315 | if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) || | |
3316 | aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) | |
3317 | { | |
3318 | aVal = aVal * anUnitCtx.LengthFactor(); | |
3319 | } | |
3320 | else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) || | |
3321 | aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) | |
3322 | { | |
3323 | convertAngleValue(anUnitCtx, aVal); | |
3324 | } | |
1c9d3225 | 3325 | aDim2 = Abs(aVal); |
3326 | } | |
3327 | else | |
3328 | { | |
b7b2f85a | 3329 | // class of tolerance |
1c9d3225 | 3330 | aLAF = aTMD.LimitsAndFits(); |
3331 | } | |
3332 | } | |
3333 | } | |
3334 | ||
cf152970 | 3335 | if (aDim1 < 0) return; |
1c9d3225 | 3336 | |
cf152970 | 3337 | if (aDim2 < 0) |
1c9d3225 | 3338 | aDimObj->SetValue(aDim1); |
3339 | else if (aDim3 < 0) | |
3340 | { | |
cf152970 | 3341 | Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 2); |
3342 | anArr->SetValue(1, aDim1); | |
3343 | anArr->SetValue(2, aDim2); | |
1c9d3225 | 3344 | aDimObj->SetValues(anArr); |
3345 | } | |
3346 | else | |
3347 | { | |
cf152970 | 3348 | Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 3); |
5b7f8e0a | 3349 | if (!isPlusMinusTolerance) |
3350 | { | |
3351 | aDim2 = aDim1 - aDim2; | |
3352 | aDim3 = aDim3 - aDim1; | |
3353 | } | |
cf152970 | 3354 | anArr->SetValue(1, aDim1); |
3355 | anArr->SetValue(2, aDim2); | |
3356 | anArr->SetValue(3, aDim3); | |
1c9d3225 | 3357 | aDimObj->SetValues(anArr); |
3358 | } | |
cf152970 | 3359 | if (!aTQ.IsNull()) |
1c9d3225 | 3360 | { |
3361 | XCAFDimTolObjects_DimensionQualifier aQ; | |
727b5ad9 | 3362 | if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ)) |
1c9d3225 | 3363 | { |
cf152970 | 3364 | aDimObj->SetQualifier(aQ); |
1c9d3225 | 3365 | } |
3366 | } | |
3367 | ||
3368 | if (!aVFTQ.IsNull()) | |
3369 | { | |
d94fa32e | 3370 | //A typical value would be 'NR2 2.2' |
1c9d3225 | 3371 | TCollection_HAsciiString aFormat = aVFTQ->FormatType(); |
cf152970 | 3372 | Standard_Integer i = aFormat.Location(1, ' ', 1, aFormat.Length()); |
3373 | aFormat.SubString(i + 1, i + 1)->IntegerValue(); | |
3374 | aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i + 1, i + 1)->IntegerValue(), | |
3375 | aFormat.SubString(i + 3, i + 3)->IntegerValue()); | |
1c9d3225 | 3376 | } |
3377 | ||
3378 | if (!aLAF.IsNull()) | |
cf152970 | 3379 | { |
1c9d3225 | 3380 | //get class of tolerance |
3381 | Standard_Boolean aHolle = Standard_False; | |
3382 | XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None; | |
3383 | XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01; | |
727b5ad9 | 3384 | STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG); |
1c9d3225 | 3385 | aDimObj->SetClassOfTolerance(aHolle, aFV, aG); |
3386 | } | |
3387 | ||
f0bef121 | 3388 | if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0) |
1c9d3225 | 3389 | { |
3390 | //get modifiers | |
3391 | XCAFDimTolObjects_DimensionModifiersSequence aModifiers; | |
727b5ad9 | 3392 | STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers); |
cf152970 | 3393 | if (aModifiers.Length() > 0) |
1c9d3225 | 3394 | aDimObj->SetModifiers(aModifiers); |
3395 | } | |
3396 | ||
3397 | Handle(TCollection_HAsciiString) aName; | |
cf152970 | 3398 | if (!aDimSize.IsNull()) |
1c9d3225 | 3399 | { |
3400 | aName = aDimSize->Name(); | |
3401 | } | |
3402 | else | |
3403 | { | |
3404 | aName = aDimLocation->Name(); | |
3405 | } | |
3406 | XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None; | |
727b5ad9 | 3407 | if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType)) |
1c9d3225 | 3408 | { |
cf152970 | 3409 | if (!aDimSize.IsNull()) |
1c9d3225 | 3410 | { |
cf152970 | 3411 | Handle(StepShape_AngularSize) anAngSize = |
1c9d3225 | 3412 | Handle(StepShape_AngularSize)::DownCast(aDimSize); |
cf152970 | 3413 | if (!anAngSize.IsNull()) |
1c9d3225 | 3414 | { |
3415 | //get qualifier for angular value | |
3416 | aType = XCAFDimTolObjects_DimensionType_Size_Angular; | |
cf152970 | 3417 | if (anAngSize->AngleSelection() == StepShape_Equal) |
1c9d3225 | 3418 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg); |
3419 | else if (anAngSize->AngleSelection() == StepShape_Large) | |
3420 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max); | |
3421 | else if (anAngSize->AngleSelection() == StepShape_Small) | |
3422 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min); | |
3423 | } | |
3424 | } | |
3425 | else | |
3426 | { | |
cf152970 | 3427 | Handle(StepShape_AngularLocation) anAngLoc = |
1c9d3225 | 3428 | Handle(StepShape_AngularLocation)::DownCast(aDimLocation); |
cf152970 | 3429 | if (!anAngLoc.IsNull()) |
1c9d3225 | 3430 | { |
3431 | //get qualifier for angular value | |
3432 | aType = XCAFDimTolObjects_DimensionType_Location_Angular; | |
cf152970 | 3433 | if (anAngLoc->AngleSelection() == StepShape_Equal) |
1c9d3225 | 3434 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg); |
3435 | else if (anAngLoc->AngleSelection() == StepShape_Large) | |
3436 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max); | |
3437 | else if (anAngLoc->AngleSelection() == StepShape_Small) | |
3438 | aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min); | |
3439 | } | |
3440 | } | |
cf152970 | 3441 | if (aType == XCAFDimTolObjects_DimensionType_Location_None) |
1c9d3225 | 3442 | { |
3443 | Handle(StepRepr_ShapeAspect) aPSA; | |
cf152970 | 3444 | if (!aDimSize.IsNull()) |
1c9d3225 | 3445 | { |
cf152970 | 3446 | Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath = |
1c9d3225 | 3447 | Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize); |
3448 | if (!aDimSizeWithPath.IsNull()) | |
3449 | { | |
3450 | aType = XCAFDimTolObjects_DimensionType_Size_WithPath; | |
3451 | aPSA = aDimSizeWithPath->Path(); | |
3452 | } | |
3453 | } | |
3454 | else | |
3455 | { | |
cf152970 | 3456 | Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath = |
1c9d3225 | 3457 | Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation); |
3458 | if (!aDimLocWithPath.IsNull()) | |
3459 | { | |
3460 | aType = XCAFDimTolObjects_DimensionType_Location_WithPath; | |
3461 | aPSA = aDimLocWithPath->Path(); | |
3462 | } | |
3463 | } | |
3464 | ||
cf152970 | 3465 | if (!aPSA.IsNull()) |
1c9d3225 | 3466 | { |
3467 | //for DimensionalLocationWithPath | |
3468 | Handle(StepGeom_GeometricRepresentationItem) aGRI; | |
3469 | Handle(StepAP242_GeometricItemSpecificUsage) aPGISU; | |
3470 | Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA); | |
cf152970 | 3471 | for (anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) { |
1c9d3225 | 3472 | aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value()); |
3473 | } | |
cf152970 | 3474 | if (aPGISU.IsNull()) return; |
3475 | if (aPGISU->NbIdentifiedItem() > 0) { | |
1c9d3225 | 3476 | aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1)); |
3477 | } | |
cf152970 | 3478 | if (aGRI.IsNull()) return; |
1c9d3225 | 3479 | Handle(StepRepr_RepresentationItem) aPRI; |
3480 | Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI); | |
cf152970 | 3481 | for (anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) { |
1c9d3225 | 3482 | aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value()); |
3483 | } | |
43d3f6d8 | 3484 | Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS); |
1c9d3225 | 3485 | TopoDS_Edge aSh; |
cf152970 | 3486 | if (anIndex > 0) { |
1c9d3225 | 3487 | Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); |
3488 | aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder)); | |
3489 | } | |
cf152970 | 3490 | if (aSh.IsNull()) return; |
1c9d3225 | 3491 | aDimObj->SetPath(aSh); |
3492 | } | |
cf152970 | 3493 | else if (!anAP.IsNull()) |
1c9d3225 | 3494 | { |
cf152970 | 3495 | if (anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull()) |
1c9d3225 | 3496 | { |
3497 | //for Oriented Dimensional Location | |
3498 | Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios(); | |
3499 | gp_Dir aDir; | |
cf152970 | 3500 | if (!aDirArr.IsNull() && aDirArr->Length() > 2) |
1c9d3225 | 3501 | { |
cf152970 | 3502 | aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2); |
1c9d3225 | 3503 | aDimObj->SetDirection(aDir); |
7fd59977 | 3504 | } |
cf152970 | 3505 | else if (aDirArr->Length() > 1) |
1c9d3225 | 3506 | { |
cf152970 | 3507 | aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, 0); |
1c9d3225 | 3508 | aDimObj->SetDirection(aDir); |
7fd59977 | 3509 | } |
1c9d3225 | 3510 | } |
3511 | } | |
3512 | } | |
3513 | } | |
3514 | aDimObj->SetType(aType); | |
3515 | ||
cf152970 | 3516 | |
3517 | if (!aDimObj.IsNull()) | |
1c9d3225 | 3518 | { |
5df609e7 | 3519 | |
1c9d3225 | 3520 | Handle(XCAFDoc_Dimension) aDim; |
5df609e7 | 3521 | |
cf152970 | 3522 | if (aDimL.FindAttribute(XCAFDoc_Dimension::GetID(), aDim)) |
1c9d3225 | 3523 | { |
5df609e7 | 3524 | readAnnotation(aTR, theEnt, aDimObj); |
b7b2f85a | 3525 | readConnectionPoints(aTR, theEnt, aDimObj); |
1c9d3225 | 3526 | aDim->SetObject(aDimObj); |
3527 | } | |
3528 | } | |
3529 | } | |
3530 | ||
3531 | //======================================================================= | |
3532 | //function : getTolType | |
3533 | //purpose : | |
3534 | //======================================================================= | |
3535 | static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt, | |
cf152970 | 3536 | XCAFDimTolObjects_GeomToleranceType& theType) |
1c9d3225 | 3537 | { |
cf152970 | 3538 | if (theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) |
1c9d3225 | 3539 | return Standard_False; |
3540 | theType = XCAFDimTolObjects_GeomToleranceType_None; | |
3541 | if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef))) | |
3542 | { | |
3543 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt); | |
727b5ad9 | 3544 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
6595eee7 | 3545 | } |
3546 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol))) | |
3547 | { | |
cf152970 | 3548 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE = |
6595eee7 | 3549 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt); |
727b5ad9 | 3550 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
6595eee7 | 3551 | } |
3552 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod))) | |
3553 | { | |
cf152970 | 3554 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE = |
6595eee7 | 3555 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt); |
727b5ad9 | 3556 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
6595eee7 | 3557 | } |
3558 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol))) | |
3559 | { | |
cf152970 | 3560 | Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE = |
6595eee7 | 3561 | Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt); |
727b5ad9 | 3562 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
6595eee7 | 3563 | } |
3564 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod))) | |
3565 | { | |
cf152970 | 3566 | Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE = |
6595eee7 | 3567 | Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt); |
727b5ad9 | 3568 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
6595eee7 | 3569 | } |
3570 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol))) | |
3571 | { | |
cf152970 | 3572 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE = |
6595eee7 | 3573 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt); |
727b5ad9 | 3574 | theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType()); |
1c9d3225 | 3575 | } |
cf152970 | 3576 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) |
1c9d3225 | 3577 | { |
3578 | theType = XCAFDimTolObjects_GeomToleranceType_Angularity; | |
3579 | } | |
cf152970 | 3580 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) |
1c9d3225 | 3581 | { |
3582 | theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout; | |
3583 | } | |
cf152970 | 3584 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) |
1c9d3225 | 3585 | { |
3586 | theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness; | |
3587 | } | |
cf152970 | 3588 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) |
1c9d3225 | 3589 | { |
3590 | theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality; | |
3591 | } | |
cf152970 | 3592 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) |
1c9d3225 | 3593 | { |
3594 | theType = XCAFDimTolObjects_GeomToleranceType_Concentricity; | |
3595 | } | |
cf152970 | 3596 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) |
1c9d3225 | 3597 | { |
3598 | theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity; | |
3599 | } | |
cf152970 | 3600 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) |
1c9d3225 | 3601 | { |
3602 | theType = XCAFDimTolObjects_GeomToleranceType_Flatness; | |
3603 | } | |
cf152970 | 3604 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) |
1c9d3225 | 3605 | { |
3606 | theType = XCAFDimTolObjects_GeomToleranceType_Parallelism; | |
3607 | } | |
cf152970 | 3608 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) |
1c9d3225 | 3609 | { |
3610 | theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity; | |
3611 | } | |
cf152970 | 3612 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) || |
3613 | theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) | |
1c9d3225 | 3614 | { |
3615 | theType = XCAFDimTolObjects_GeomToleranceType_Position; | |
3616 | } | |
cf152970 | 3617 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) |
1c9d3225 | 3618 | { |
3619 | theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine; | |
3620 | } | |
cf152970 | 3621 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) |
1c9d3225 | 3622 | { |
3623 | theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface; | |
3624 | } | |
cf152970 | 3625 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) |
1c9d3225 | 3626 | { |
3627 | theType = XCAFDimTolObjects_GeomToleranceType_Straightness; | |
3628 | } | |
cf152970 | 3629 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) |
1c9d3225 | 3630 | { |
3631 | theType = XCAFDimTolObjects_GeomToleranceType_Symmetry; | |
3632 | } | |
cf152970 | 3633 | else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) |
1c9d3225 | 3634 | { |
3635 | theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout; | |
3636 | } | |
3637 | return Standard_True; | |
3638 | } | |
3639 | //======================================================================= | |
3640 | //function : setGeomTolObjectToXCAF | |
3641 | //purpose : | |
3642 | //======================================================================= | |
3643 | static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt, | |
cf152970 | 3644 | const TDF_Label& theTolL, |
3645 | const Handle(TDocStd_Document)& theDoc, | |
3646 | const Handle(XSControl_WorkSession)& theWS) | |
1c9d3225 | 3647 | { |
cf152970 | 3648 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); |
3649 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
7f56eba8 | 3650 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); |
3651 | const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); | |
1c9d3225 | 3652 | const Interface_Graph& aGraph = aTP->Graph(); |
3653 | Handle(XCAFDoc_GeomTolerance) aGTol; | |
cf152970 | 3654 | if (!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol)) |
1c9d3225 | 3655 | { |
3656 | return; | |
3657 | } | |
3658 | Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject(); | |
3659 | Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt); | |
3660 | ||
3661 | XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None; | |
3662 | getTolType(theEnt, aType); | |
3663 | aTolObj->SetType(aType); | |
cf152970 | 3664 | if (!aTolEnt->Magnitude().IsNull()) { |
1c9d3225 | 3665 | //get value |
3666 | Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent(); | |
3667 | StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent(); | |
cf152970 | 3668 | if (anUnit.IsNull()) return; |
3669 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return; | |
1c9d3225 | 3670 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3671 | STEPConstruct_UnitContext anUnitCtx; |
3672 | anUnitCtx.ComputeFactors(NU); | |
3673 | aVal = aVal * anUnitCtx.LengthFactor(); | |
1c9d3225 | 3674 | aTolObj->SetValue(aVal); |
3675 | } | |
3676 | //get modifiers | |
3677 | XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None; | |
3678 | Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt); | |
cf152970 | 3679 | for (anIter.Start(); anIter.More(); anIter.Next()) { |
3680 | if (anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))) { | |
3681 | Handle(StepDimTol_ToleranceZoneForm) aForm | |
3682 | = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form(); | |
727b5ad9 | 3683 | STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV); |
1c9d3225 | 3684 | Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value()); |
cf152970 | 3685 | for (anIt.Start(); anIt.More(); anIt.Next()) { |
3686 | if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))) { | |
1c9d3225 | 3687 | Handle(StepDimTol_ProjectedZoneDefinition) aPZone |
cf152970 | 3688 | = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value()); |
3689 | if (!aPZone->ProjectionLength().IsNull()) | |
1c9d3225 | 3690 | { |
3691 | Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent(); | |
3692 | StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent(); | |
cf152970 | 3693 | if (anUnit.IsNull()) return; |
3694 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return; | |
1c9d3225 | 3695 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3696 | STEPConstruct_UnitContext anUnitCtx; |
3697 | anUnitCtx.ComputeFactors(NU); | |
3698 | aVal = aVal * anUnitCtx.LengthFactor(); | |
1c9d3225 | 3699 | aTolObj->SetValueOfZoneModifier(aVal); |
6595eee7 | 3700 | aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected); |
7fd59977 | 3701 | } |
1c9d3225 | 3702 | } |
3703 | else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition))) | |
3704 | { | |
3705 | Handle(StepDimTol_RunoutZoneDefinition) aRZone | |
cf152970 | 3706 | = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value()); |
3707 | if (!aRZone->Orientation().IsNull()) | |
1c9d3225 | 3708 | { |
3709 | Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent(); | |
3710 | StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent(); | |
cf152970 | 3711 | if (anUnit.IsNull()) continue; |
3712 | if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue; | |
1c9d3225 | 3713 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3714 | STEPConstruct_UnitContext anUnitCtx; |
3715 | anUnitCtx.ComputeFactors(NU); | |
3716 | convertAngleValue(anUnitCtx, aVal); | |
1c9d3225 | 3717 | aTolObj->SetValueOfZoneModifier(aVal); |
6595eee7 | 3718 | aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout); |
7fd59977 | 3719 | } |
3720 | } | |
3721 | } | |
1c9d3225 | 3722 | aTolObj->SetTypeOfValue(aTypeV); |
3723 | } | |
3724 | } | |
3725 | Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers; | |
3726 | if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers))) | |
3727 | { | |
3728 | aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers(); | |
3729 | } | |
3730 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod))) | |
3731 | { | |
3732 | aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) | |
cf152970 | 3733 | ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers(); |
1c9d3225 | 3734 | } |
3735 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod))) | |
3736 | { | |
3737 | aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod) | |
cf152970 | 3738 | ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers(); |
1c9d3225 | 3739 | } |
6595eee7 | 3740 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol))) |
3741 | { | |
3742 | aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) | |
cf152970 | 3743 | ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers(); |
6595eee7 | 3744 | } |
3745 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol))) | |
3746 | { | |
3747 | aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) | |
cf152970 | 3748 | ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers(); |
6595eee7 | 3749 | } |
cf152970 | 3750 | if (!aModifiers.IsNull()) |
1c9d3225 | 3751 | { |
cf152970 | 3752 | for (Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++) |
1c9d3225 | 3753 | { |
cf152970 | 3754 | if (aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement) |
1c9d3225 | 3755 | aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L); |
3756 | else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement) | |
3757 | aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M); | |
3758 | else | |
3759 | aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i)); | |
7fd59977 | 3760 | } |
3761 | } | |
6595eee7 | 3762 | Standard_Real aVal = 0; |
3763 | StepBasic_Unit anUnit; | |
1c9d3225 | 3764 | if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance))) |
3765 | { | |
3766 | Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt); | |
6595eee7 | 3767 | aVal = aMax->MaximumUpperTolerance()->ValueComponent(); |
3768 | anUnit = aMax->MaximumUpperTolerance()->UnitComponent(); | |
3769 | } | |
3770 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol))) | |
3771 | { | |
cf152970 | 3772 | Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax = |
6595eee7 | 3773 | Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt); |
3774 | aVal = aMax->GetMaxTolerance()->ValueComponent(); | |
3775 | anUnit = aMax->GetMaxTolerance()->UnitComponent(); | |
3776 | } | |
3777 | else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol))) | |
3778 | { | |
cf152970 | 3779 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax = |
6595eee7 | 3780 | Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt); |
3781 | aVal = aMax->GetMaxTolerance()->ValueComponent(); | |
3782 | anUnit = aMax->GetMaxTolerance()->UnitComponent(); | |
3783 | } | |
3784 | if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1)) | |
3785 | { | |
1c9d3225 | 3786 | Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit(); |
477000eb | 3787 | STEPConstruct_UnitContext anUnitCtx; |
3788 | anUnitCtx.ComputeFactors(NU); | |
3789 | convertAngleValue(anUnitCtx, aVal); | |
1c9d3225 | 3790 | aTolObj->SetMaxValueModifier(aVal); |
3791 | } | |
cf152970 | 3792 | |
5df609e7 | 3793 | readAnnotation(aTR, theEnt, aTolObj); |
1c9d3225 | 3794 | aGTol->SetObject(aTolObj); |
3795 | } | |
3796 | ||
3797 | //======================================================================= | |
3798 | //function : ReadGDTs | |
3799 | //purpose : | |
3800 | //======================================================================= | |
7fd59977 | 3801 | |
1c9d3225 | 3802 | Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS, |
cf152970 | 3803 | Handle(TDocStd_Document)& theDoc) |
1c9d3225 | 3804 | { |
7f56eba8 | 3805 | const Handle(Interface_InterfaceModel) &aModel = theWS->Model(); |
0b622d67 | 3806 | const Interface_Graph& aGraph = theWS->Graph(); |
3807 | const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); | |
1c9d3225 | 3808 | Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel); |
3809 | Interface_EntityIterator anI = aSM->Header(); | |
3810 | Handle(HeaderSection_FileSchema) aH; | |
cf152970 | 3811 | for (anI.Start(); anI.More() && aH.IsNull();anI.Next()) |
1c9d3225 | 3812 | aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value()); |
cf152970 | 3813 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); |
3814 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
3815 | if (aDGTTool.IsNull()) return Standard_False; | |
1c9d3225 | 3816 | |
3817 | Standard_Integer nb = aModel->NbEntities(); | |
cf152970 | 3818 | for (Standard_Integer i = 1; i <= nb; i++) { |
1c9d3225 | 3819 | Handle(Standard_Transient) anEnt = aModel->Value(i); |
cf152970 | 3820 | if (anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) || |
3821 | anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) || | |
3822 | anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
3823 | TDF_Label aGDTL = createGDTObjectInXCAF(anEnt, theDoc, theWS); | |
3824 | if (!aGDTL.IsNull()) { | |
3825 | if (anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
3826 | setGeomTolObjectToXCAF(anEnt, aGDTL, theDoc, theWS); | |
1c9d3225 | 3827 | } |
3828 | else { | |
cf152970 | 3829 | setDimObjectToXCAF(anEnt, aGDTL, theDoc, theWS); |
1c9d3225 | 3830 | } |
3831 | } | |
3832 | } | |
0b622d67 | 3833 | else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) || |
1209c1b9 | 3834 | anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence))) |
0b622d67 | 3835 | { |
1209c1b9 | 3836 | // Protection against import presentation twice |
3837 | Handle(StepVisual_DraughtingCallout) aDC; | |
3838 | for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) { | |
3839 | aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value()); | |
0b622d67 | 3840 | } |
1209c1b9 | 3841 | if (!aDC.IsNull()) |
0b622d67 | 3842 | continue; |
1209c1b9 | 3843 | // Read presentations for PMIs without semantic data. |
3844 | Handle(StepAP242_DraughtingModelItemAssociation) aDMIA; | |
3845 | TDF_LabelSequence aShapesL; | |
3846 | for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) { | |
3847 | aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value()); | |
3848 | } | |
3849 | if (!aDMIA.IsNull()) { | |
3850 | // Check entity, skip all, attached to GDTs | |
3851 | Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect(); | |
3852 | if (!aDefinition.IsNull()) { | |
3853 | Standard_Boolean isConnectedToGDT = Standard_False; | |
3854 | // Skip if definition is a datum | |
3855 | if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) || | |
3856 | aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) || | |
3857 | aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) || | |
3858 | aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) { | |
3859 | isConnectedToGDT = Standard_True; | |
3860 | } | |
3861 | // Skip if any GDT is applied to definition | |
3862 | for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) { | |
3863 | if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) || | |
3864 | anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) || | |
3865 | anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
3866 | isConnectedToGDT = Standard_True; | |
3867 | continue; | |
3868 | } | |
3869 | Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value()); | |
3870 | if (!aSAR.IsNull()) { | |
3871 | Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect(); | |
3872 | if (!aSA.IsNull()) { | |
3873 | if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) || | |
3874 | aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) || | |
3875 | aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) || | |
3876 | aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) { | |
3877 | isConnectedToGDT = Standard_True; | |
3878 | } | |
3879 | for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) { | |
3880 | if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) || | |
3881 | aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) || | |
3882 | aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) { | |
3883 | isConnectedToGDT = Standard_True; | |
3884 | continue; | |
3885 | } | |
3886 | } | |
3887 | } | |
3888 | } | |
3889 | } | |
3890 | if (isConnectedToGDT) | |
3891 | continue; | |
3892 | } | |
3893 | else if (aDMIA->Definition().PropertyDefinition().IsNull()) | |
3894 | continue; | |
3895 | ||
3896 | // Get shapes | |
3897 | NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs; | |
3898 | collectShapeAspect(aDefinition, theWS, aSAs); | |
3899 | for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) { | |
3900 | Handle(StepAP242_GeometricItemSpecificUsage) aGISU; | |
3901 | for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next()) | |
3902 | aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value()); | |
3903 | if (aGISU.IsNull()) | |
3904 | continue; | |
3905 | for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) { | |
3906 | TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main())); | |
3907 | if (!aLabel.IsNull()) | |
3908 | aShapesL.Append(aLabel); | |
3909 | } | |
0b622d67 | 3910 | } |
0b622d67 | 3911 | } |
1209c1b9 | 3912 | Standard_Boolean isCommonLabel = (aShapesL.Length() == 0); |
3913 | ||
3914 | // Calculate unit | |
3915 | Standard_Real aFact = 1.0; | |
477000eb | 3916 | if (!aDMIA.IsNull()) |
3917 | { | |
3918 | XSAlgo::AlgoContainer()->PrepareForTransfer(); | |
3919 | STEPControl_ActorRead anActor; | |
3920 | Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess(); | |
3921 | anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP); | |
3922 | aFact = UnitsMethods::LengthFactor(); | |
3923 | } | |
1209c1b9 | 3924 | |
3925 | // Presentation | |
0b622d67 | 3926 | TopoDS_Shape aPresentation; |
3927 | Handle(TCollection_HAsciiString) aPresentName; | |
3928 | Bnd_Box aBox; | |
1209c1b9 | 3929 | if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox)) |
3930 | continue; | |
3931 | // Annotation plane | |
3932 | Handle(StepVisual_AnnotationPlane) anAnPlane; | |
3933 | for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next()) | |
3934 | anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value()); | |
cf152970 | 3935 | |
1209c1b9 | 3936 | // Set object to XCAF |
3937 | TDF_Label aGDTL = aDGTTool->AddDimension(); | |
0c63f2f8 | 3938 | myGDTMap.Bind(anEnt, aGDTL); |
3939 | aDGTTool->Lock(aGDTL); | |
1209c1b9 | 3940 | Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject(); |
3941 | Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL); | |
3942 | TCollection_AsciiString aStr("DGT:"); | |
3943 | if (isCommonLabel) { | |
3944 | aStr.AssignCat("Common_label"); | |
3945 | aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel); | |
3946 | } | |
3947 | else { | |
3948 | aStr.AssignCat("Dimension"); | |
3949 | aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation); | |
3950 | } | |
3951 | TDataStd_Name::Set(aGDTL, aStr); | |
3952 | TDF_LabelSequence anEmptySeq2; | |
3953 | aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL); | |
3954 | gp_Ax2 aPlaneAxes; | |
3955 | if (!anAnPlane.IsNull()) { | |
477000eb | 3956 | if (readAnnotationPlane(anAnPlane, aPlaneAxes)) |
1209c1b9 | 3957 | aDimObj->SetPlane(aPlaneAxes); |
3958 | } | |
0b622d67 | 3959 | aDimObj->SetPresentation(aPresentation, aPresentName); |
3960 | aDim->SetObject(aDimObj); | |
3961 | } | |
1c9d3225 | 3962 | } |
7fd59977 | 3963 | return Standard_True; |
3964 | } | |
3965 | ||
3966 | ||
3967 | //======================================================================= | |
3968 | //function : FindSolidForPDS | |
3969 | //purpose : auxilary | |
3970 | //======================================================================= | |
3971 | ||
3972 | static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS, | |
cf152970 | 3973 | const Interface_Graph &graph) |
7fd59977 | 3974 | { |
3975 | Handle(StepShape_SolidModel) SM; | |
3976 | Interface_EntityIterator subs = graph.Sharings(PDS); | |
3977 | Handle(StepShape_ShapeRepresentation) SR; | |
cf152970 | 3978 | for (subs.Start(); subs.More() && SM.IsNull(); subs.Next()) { |
7fd59977 | 3979 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
3980 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); | |
cf152970 | 3981 | if (SDR.IsNull()) continue; |
7fd59977 | 3982 | SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); |
cf152970 | 3983 | if (SR.IsNull()) continue; |
3984 | for (Standard_Integer i = 1; i <= SR->NbItems() && SM.IsNull(); i++) { | |
7fd59977 | 3985 | SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i)); |
3986 | } | |
cf152970 | 3987 | if (SM.IsNull()) { |
7fd59977 | 3988 | Interface_EntityIterator subs1 = graph.Sharings(SR); |
cf152970 | 3989 | for (subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) { |
7fd59977 | 3990 | Handle(StepRepr_RepresentationRelationship) RR = |
3991 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value()); | |
cf152970 | 3992 | if (RR.IsNull()) continue; |
7fd59977 | 3993 | Handle(StepShape_ShapeRepresentation) SR2; |
cf152970 | 3994 | if (RR->Rep1() == SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); |
7fd59977 | 3995 | else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); |
cf152970 | 3996 | if (SR2.IsNull()) continue; |
3997 | for (Standard_Integer i2 = 1; i2 <= SR2->NbItems() && SM.IsNull(); i2++) { | |
7fd59977 | 3998 | SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2)); |
3999 | } | |
4000 | } | |
4001 | } | |
4002 | } | |
4003 | return SM; | |
4004 | } | |
4005 | ||
4006 | ||
4007 | //======================================================================= | |
4008 | //function : ReadMaterials | |
4009 | //purpose : | |
4010 | //======================================================================= | |
4011 | ||
4012 | Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS, | |
cf152970 | 4013 | Handle(TDocStd_Document)& Doc, |
4014 | const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const | |
7fd59977 | 4015 | { |
7f56eba8 | 4016 | const Handle(XSControl_TransferReader) &TR = WS->TransferReader(); |
4017 | const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess(); | |
cf152970 | 4018 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
4019 | Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool(Doc->Main()); | |
4020 | if (MatTool.IsNull()) return Standard_False; | |
4021 | ||
7fd59977 | 4022 | const Interface_Graph& graph = TP->Graph(); |
cf152970 | 4023 | for (Standard_Integer i = 1; i <= SeqPDS->Length(); i++) { |
7fd59977 | 4024 | Handle(StepRepr_ProductDefinitionShape) PDS = |
4025 | Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i)); | |
cf152970 | 4026 | if (PDS.IsNull()) |
1d2b1ccb G |
4027 | continue; |
4028 | Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition(); | |
cf152970 | 4029 | if (aProdDef.IsNull()) |
1d2b1ccb | 4030 | continue; |
7fd59977 | 4031 | Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(""); |
4032 | Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString(""); | |
4033 | Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString(""); | |
4034 | Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString(""); | |
cf152970 | 4035 | Standard_Real aDensity = 0; |
4036 | Interface_EntityIterator subs = graph.Sharings(aProdDef); | |
4037 | for (subs.Start(); subs.More(); subs.Next()) { | |
7fd59977 | 4038 | Handle(StepRepr_PropertyDefinition) PropD = |
4039 | Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value()); | |
cf152970 | 4040 | if (PropD.IsNull()) continue; |
7fd59977 | 4041 | Interface_EntityIterator subs1 = graph.Sharings(PropD); |
cf152970 | 4042 | for (subs1.Start(); subs1.More(); subs1.Next()) { |
7fd59977 | 4043 | Handle(StepRepr_PropertyDefinitionRepresentation) PDR = |
4044 | Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value()); | |
cf152970 | 4045 | if (PDR.IsNull()) continue; |
7fd59977 | 4046 | Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation(); |
cf152970 | 4047 | if (Repr.IsNull()) continue; |
7fd59977 | 4048 | Standard_Integer ir; |
cf152970 | 4049 | for (ir = 1; ir <= Repr->NbItems(); ir++) { |
7fd59977 | 4050 | Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir); |
cf152970 | 4051 | if (RI.IsNull()) continue; |
4052 | if (RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) { | |
7fd59977 | 4053 | // find name and description for material |
4054 | Handle(StepRepr_DescriptiveRepresentationItem) DRI = | |
4055 | Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI); | |
4056 | aName = DRI->Name(); | |
cf152970 | 4057 | |
7fd59977 | 4058 | aDescription = DRI->Description(); |
cf152970 | 4059 | if (aName.IsNull()) |
87073a10 | 4060 | aName = aDescription; |
7fd59977 | 4061 | } |
cf152970 | 4062 | if (RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) { |
7fd59977 | 4063 | // try to find density for material |
4064 | Handle(StepRepr_MeasureRepresentationItem) MRI = | |
4065 | Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI); | |
4066 | aDensity = MRI->Measure()->ValueComponent(); | |
4067 | aDensName = MRI->Name(); | |
4068 | aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name()); | |
4069 | StepBasic_Unit aUnit = MRI->Measure()->UnitComponent(); | |
cf152970 | 4070 | if (!aUnit.IsNull()) { |
7fd59977 | 4071 | Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit(); |
cf152970 | 4072 | if (DU.IsNull()) continue; |
4073 | for (Standard_Integer idu = 1; idu <= DU->NbElements(); idu++) { | |
7fd59977 | 4074 | Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu); |
4075 | Handle(StepBasic_NamedUnit) NU = DUE->Unit(); | |
cf152970 | 4076 | if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) || |
4077 | NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) | |
477000eb | 4078 | { |
4079 | STEPConstruct_UnitContext anUnitCtx; | |
4080 | anUnitCtx.ComputeFactors(NU); | |
4081 | aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()); | |
7fd59977 | 4082 | // transfer length value for Density from millimeter to santimeter |
4083 | // in order to result density has dimension gram/(sm*sm*sm) | |
477000eb | 4084 | aDensity = aDensity*1000. / (UnitsMethods::GetCasCadeLengthUnit() |
4085 | * UnitsMethods::GetCasCadeLengthUnit() * UnitsMethods::GetCasCadeLengthUnit()); | |
7fd59977 | 4086 | } |
cf152970 | 4087 | if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) { |
477000eb | 4088 | Standard_Real afact = 1.; |
4089 | if (GetMassConversionFactor(NU, afact)) | |
4090 | { | |
4091 | aDensity = aDensity*afact; | |
4092 | } | |
7fd59977 | 4093 | } |
4094 | } | |
4095 | } | |
4096 | } | |
4097 | } | |
4098 | } | |
4099 | } | |
cf152970 | 4100 | |
4101 | if (aName.IsNull() || aName->Length() == 0) | |
87073a10 | 4102 | continue; |
7fd59977 | 4103 | // find shape label amd create Material link |
4104 | TopoDS_Shape aSh; | |
cf152970 | 4105 | Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS, graph); |
4106 | if (!SM.IsNull()) { | |
7fd59977 | 4107 | Standard_Integer index = TP->MapIndex(SM); |
cf152970 | 4108 | if (index > 0) { |
7fd59977 | 4109 | Handle(Transfer_Binder) binder = TP->MapItem(index); |
cf152970 | 4110 | if (!binder.IsNull()) |
7fd59977 | 4111 | aSh = TransferBRep::ShapeResult(binder); |
4112 | } | |
4113 | } | |
cf152970 | 4114 | if (aSh.IsNull()) continue; |
7fd59977 | 4115 | TDF_Label shL; |
cf152970 | 4116 | if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue; |
4117 | MatTool->SetMaterial(shL, aName, aDescription, aDensity, aDensName, aDensValType); | |
7fd59977 | 4118 | } |
4119 | ||
4120 | return Standard_True; | |
4121 | } | |
4122 | ||
0c63f2f8 | 4123 | //======================================================================= |
4124 | //function : collectViewShapes | |
4125 | //purpose : collect all labels of representations in given representation | |
4126 | //======================================================================= | |
4127 | ||
4128 | void collectViewShapes(const Handle(XSControl_WorkSession)& theWS, | |
4129 | const Handle(TDocStd_Document)& theDoc, | |
4130 | const Handle(StepRepr_Representation) theRepr, | |
4131 | TDF_LabelSequence& theShapes) | |
4132 | { | |
4133 | Handle(XSControl_TransferReader) aTR = theWS->TransferReader(); | |
4134 | Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess(); | |
4135 | const Interface_Graph& aGraph = aTP->Graph(); | |
4136 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); | |
4137 | Standard_Integer anIndex = aTP->MapIndex(theRepr); | |
4138 | TopoDS_Shape aSh; | |
4139 | if (anIndex > 0) { | |
4140 | Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); | |
4141 | aSh = TransferBRep::ShapeResult(aBinder); | |
4142 | } | |
4143 | if (!aSh.IsNull()) { | |
4144 | TDF_Label aShL; | |
4145 | aSTool->FindShape(aSh, aShL); | |
4146 | if (!aShL.IsNull()) | |
4147 | theShapes.Append(aShL); | |
4148 | } | |
4149 | Interface_EntityIterator anIter = aGraph.Sharings(theRepr); | |
4150 | for (; anIter.More(); anIter.Next()) { | |
4151 | if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship))) | |
4152 | continue; | |
4153 | Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value()); | |
33defc71 | 4154 | if (!aReprRelationship->Rep1().IsNull() && aReprRelationship->Rep1() != theRepr) |
0c63f2f8 | 4155 | collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes); |
4156 | } | |
4157 | } | |
4158 | ||
4159 | //======================================================================= | |
4160 | //function : buildClippingPlanes | |
4161 | //purpose : | |
4162 | //======================================================================= | |
4163 | Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel, | |
4164 | TDF_LabelSequence& theClippingPlanes, | |
4165 | const Handle(XCAFDoc_ClippingPlaneTool) theTool) | |
4166 | { | |
4167 | Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString(); | |
4168 | NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes; | |
4169 | Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*"); | |
4170 | ||
4171 | // Store operands | |
4172 | if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) { | |
4173 | Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel = | |
4174 | Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel); | |
100be67a | 4175 | |
4176 | if (aCameraModel->ShapeClipping().IsNull()) | |
4177 | return anExpression; | |
4178 | ||
0c63f2f8 | 4179 | // Root of clipping planes tree |
4180 | if (aCameraModel->ShapeClipping()->Length() == 1) { | |
4181 | Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion = | |
4182 | aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion(); | |
4183 | if (!aCameraModelUnion.IsNull()) | |
4184 | return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool); | |
4185 | } | |
4186 | for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) { | |
4187 | aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value())); | |
4188 | } | |
4189 | } | |
4190 | else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) { | |
4191 | Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel = | |
4192 | Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel); | |
4193 | anOperation = new TCollection_HAsciiString("+"); | |
4194 | for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) { | |
4195 | aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value())); | |
4196 | } | |
4197 | } | |
4198 | else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) { | |
4199 | Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel = | |
4200 | Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel); | |
4201 | for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) { | |
4202 | aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value())); | |
4203 | } | |
4204 | } | |
4205 | // Build expression | |
4206 | anExpression->AssignCat("("); | |
4207 | for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) { | |
4208 | Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i)); | |
4209 | if (!aPlaneEnt.IsNull()) { | |
4210 | Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt); | |
4211 | if (!aPlane.IsNull()) { | |
4212 | TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name()); | |
4213 | theClippingPlanes.Append(aPlaneL); | |
4214 | TCollection_AsciiString anEntry; | |
4215 | TDF_Tool::Entry(aPlaneL, anEntry); | |
4216 | anExpression->AssignCat(new TCollection_HAsciiString(anEntry)); | |
4217 | } | |
4218 | } | |
4219 | else { | |
4220 | anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool)); | |
4221 | } | |
4222 | anExpression->AssignCat(anOperation); | |
4223 | } | |
4224 | // Insert brace instead of operation after last operand. | |
4225 | anExpression->SetValue(anExpression->Length(), ')'); | |
4226 | return anExpression; | |
4227 | } | |
4228 | ||
4229 | ||
4230 | //======================================================================= | |
4231 | //function : ReadViews | |
4232 | //purpose : | |
4233 | //======================================================================= | |
4234 | Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const | |
4235 | { | |
4236 | const Handle(Interface_InterfaceModel) &aModel = theWS->Model(); | |
4237 | Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); | |
4238 | Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); | |
4239 | Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main()); | |
4240 | if (aDGTTool.IsNull()) return Standard_False; | |
4241 | ||
4242 | Standard_Integer nb = aModel->NbEntities(); | |
4243 | for (Standard_Integer i = 1; i <= nb; i++) { | |
4244 | Handle(Standard_Transient) anEnt = aModel->Value(i); | |
4245 | if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3))) | |
4246 | continue; | |
4247 | Handle(XCAFView_Object) anObj = new XCAFView_Object(); | |
4248 | // Import attributes of view | |
4249 | Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt); | |
477000eb | 4250 | |
4251 | const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader(); | |
4252 | Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess(); | |
4253 | const Interface_Graph& aGraph = aTP->Graph(); | |
4254 | // find the proper DraughtingModel | |
4255 | Interface_EntityIterator subs = aGraph.Sharings(aCameraModel); | |
4256 | Handle(StepVisual_DraughtingModel) aDModel; | |
4257 | for (subs.Start(); subs.More() && aDModel.IsNull(); subs.Next()) | |
4258 | { | |
4259 | if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel))) | |
4260 | { | |
4261 | continue; | |
4262 | } | |
4263 | aDModel = Handle(StepVisual_DraughtingModel)::DownCast(subs.Value()); | |
4264 | } | |
4265 | if (!aDModel.IsNull()) | |
4266 | { | |
4267 | XSAlgo::AlgoContainer()->PrepareForTransfer(); | |
4268 | STEPControl_ActorRead anActor; | |
4269 | anActor.PrepareUnits(aDModel, aTP); | |
4270 | } | |
4271 | ||
0c63f2f8 | 4272 | anObj->SetName(aCameraModel->Name()); |
4273 | Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem()); | |
4274 | anObj->SetViewDirection(anAxis->Direction()); | |
4275 | anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection()); | |
4276 | Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume(); | |
4277 | XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera; | |
4278 | if (aViewVolume->ProjectionType() == StepVisual_copCentral) | |
4279 | aType = XCAFView_ProjectionType_Central; | |
4280 | else if (aViewVolume->ProjectionType() == StepVisual_copParallel) | |
4281 | aType = XCAFView_ProjectionType_Parallel; | |
4282 | anObj->SetType(aType); | |
4283 | Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint()); | |
4284 | anObj->SetProjectionPoint(aPoint->Pnt()); | |
4285 | anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance()); | |
4286 | anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX()); | |
4287 | anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY()); | |
4288 | if (aViewVolume->FrontPlaneClipping()) | |
4289 | anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance()); | |
4290 | if (aViewVolume->BackPlaneClipping()) | |
4291 | anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance()); | |
4292 | anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping()); | |
4293 | // Clipping plane | |
4294 | Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel = | |
4295 | Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel); | |
4296 | TDF_LabelSequence aClippingPlanes; | |
4297 | if (!aClippingCameraModel.IsNull()) { | |
4298 | Handle(TCollection_HAsciiString) aClippingExpression; | |
4299 | Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main()); | |
4300 | aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool); | |
4301 | anObj->SetClippingExpression(aClippingExpression); | |
4302 | } | |
477000eb | 4303 | |
0c63f2f8 | 4304 | // Collect shapes and GDTs |
0c63f2f8 | 4305 | if (aDModel.IsNull()) |
4306 | return Standard_False; | |
477000eb | 4307 | TDF_LabelSequence aShapes, aGDTs; |
4308 | Interface_EntityIterator anIter = aGraph.Shareds(aDModel); | |
0c63f2f8 | 4309 | for (; anIter.More(); anIter.Next()) { |
4310 | if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) { | |
4311 | Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value()); | |
4312 | Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation(); | |
4313 | collectViewShapes(theWS, theDoc, aRepr, aShapes); | |
4314 | } | |
4315 | else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) || | |
4316 | anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) { | |
4317 | Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value()); | |
4318 | for (; aDMIAIter.More(); aDMIAIter.Next()) { | |
4319 | if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation))) | |
4320 | continue; | |
4321 | Handle(StepAP242_DraughtingModelItemAssociation) aDMIA = | |
4322 | Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value()); | |
4323 | TDF_Label aGDTL; | |
4324 | Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL); | |
c4fa1c2c | 4325 | if (!isFind) { |
4326 | isFind = myGDTMap.Find(anIter.Value(), aGDTL); | |
4327 | } | |
0c63f2f8 | 4328 | if (isFind) |
4329 | aGDTs.Append(aGDTL); | |
4330 | } | |
4331 | } | |
4332 | else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) { | |
4333 | Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value()); | |
4cf17e1c | 4334 | for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) { |
0c63f2f8 | 4335 | Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value()); |
4336 | for (; aDMIAIter.More(); aDMIAIter.Next()) { | |
4337 | if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation))) | |
4338 | continue; | |
4339 | Handle(StepAP242_DraughtingModelItemAssociation) aDMIA = | |
4340 | Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value()); | |
4341 | TDF_Label aGDTL; | |
4342 | Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL); | |
4343 | if (isFind) | |
4344 | aGDTs.Append(aGDTL); | |
4345 | } | |
4346 | } | |
4347 | } | |
4348 | } | |
4349 | TDF_Label aViewL = aViewTool->AddView(); | |
4350 | Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL); | |
4351 | aView->SetObject(anObj); | |
4352 | aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL); | |
4353 | aViewTool->Lock(aViewL); | |
4354 | } | |
4355 | return Standard_True; | |
4356 | } | |
4357 | ||
02a0b964 | 4358 | //======================================================================= |
4359 | //function : SettleShapeData | |
4360 | //purpose : | |
4361 | //======================================================================= | |
4362 | ||
4363 | TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem, | |
cf152970 | 4364 | const TDF_Label& theLab, |
4365 | const Handle(XCAFDoc_ShapeTool)& theShapeTool, | |
4366 | const Handle(Transfer_TransientProcess)& TP) const | |
02a0b964 | 4367 | { |
4368 | TDF_Label aResult = theLab; | |
4369 | ||
4370 | Handle(TCollection_HAsciiString) hName = theItem->Name(); | |
cf152970 | 4371 | if (hName.IsNull() || hName->IsEmpty()) |
02a0b964 | 4372 | return aResult; |
4373 | ||
4374 | Handle(Transfer_Binder) aBinder = TP->Find(theItem); | |
cf152970 | 4375 | if (aBinder.IsNull()) |
02a0b964 | 4376 | return aResult; |
4377 | ||
4378 | TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder); | |
cf152970 | 4379 | if (aShape.IsNull()) |
02a0b964 | 4380 | return aResult; |
4381 | ||
4382 | // Allocate sub-Label | |
44f29823 | 4383 | aResult = theShapeTool->AddSubShape(theLab, aShape); |
4384 | if (aResult.IsNull()) | |
4385 | return aResult; | |
02a0b964 | 4386 | |
4387 | TCollection_AsciiString aName = hName->String(); | |
4388 | TDataStd_Name::Set(aResult, aName); | |
4389 | theShapeTool->SetShape(aResult, aShape); | |
4390 | ||
4391 | return aResult; | |
4392 | } | |
4393 | ||
44f29823 | 4394 | //======================================================================= |
4395 | //function : collectRepresentationItems | |
4396 | //purpose : recursive collection of representation items for given representation | |
4397 | // with all representations, related to it. | |
4398 | //======================================================================= | |
4399 | ||
4400 | void collectRepresentationItems(const Interface_Graph& theGraph, | |
cf152970 | 4401 | const Handle(StepShape_ShapeRepresentation)& theRepresentation, |
4402 | NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems) | |
44f29823 | 4403 | { |
4404 | Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items(); | |
4405 | for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++) | |
4406 | theItems.Append(aReprItems->Value(itemIt)); | |
4407 | ||
4408 | Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship)); | |
4409 | for (entIt.Start(); entIt.More(); entIt.Next()) | |
4410 | { | |
4411 | Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value()); | |
4412 | if (aRelationship->Rep1() == theRepresentation) | |
4413 | { | |
4414 | Handle(StepShape_ShapeRepresentation) | |
4415 | aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2()); | |
4416 | if (!aRepr.IsNull()) | |
4417 | collectRepresentationItems(theGraph, aRepr, theItems); | |
4418 | } | |
4419 | } | |
4420 | } | |
4421 | ||
02a0b964 | 4422 | //======================================================================= |
4423 | //function : ExpandSubShapes | |
4424 | //purpose : | |
4425 | //======================================================================= | |
4426 | ||
4427 | void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool, | |
cf152970 | 4428 | const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap, |
4429 | const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const | |
02a0b964 | 4430 | { |
02a0b964 | 4431 | const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess(); |
4432 | NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap; | |
4433 | TColStd_MapOfTransient aRepItems; | |
4434 | ||
4435 | // Read translation control variables | |
4436 | Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0); | |
4437 | ||
cf152970 | 4438 | if (!doReadSNames) |
02a0b964 | 4439 | return; |
4440 | ||
4441 | const Interface_Graph& Graph = Reader().WS()->Graph(); | |
4442 | ||
cf152970 | 4443 | for (STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next()) |
02a0b964 | 4444 | { |
4445 | const TopoDS_Shape& aRootShape = it.Key(); | |
4446 | const Handle(StepBasic_ProductDefinition)& aPDef = it.Value(); | |
cf152970 | 4447 | if (aPDef.IsNull()) |
02a0b964 | 4448 | continue; |
4449 | ||
4450 | // Find SDR by Product | |
4451 | Handle(StepShape_ShapeDefinitionRepresentation) aSDR; | |
cf152970 | 4452 | Interface_EntityIterator entIt = Graph.TypedSharings(aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)); |
4453 | for (entIt.Start(); entIt.More(); entIt.Next()) | |
02a0b964 | 4454 | { |
4455 | const Handle(Standard_Transient)& aReferer = entIt.Value(); | |
4456 | aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer); | |
cf152970 | 4457 | if (!aSDR.IsNull()) |
02a0b964 | 4458 | break; |
4459 | } | |
4460 | ||
cf152970 | 4461 | if (aSDR.IsNull()) |
02a0b964 | 4462 | continue; |
4463 | ||
4464 | // Access shape representation | |
4465 | Handle(StepShape_ShapeRepresentation) | |
cf152970 | 4466 | aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation()); |
02a0b964 | 4467 | |
cf152970 | 4468 | if (aShapeRepr.IsNull()) |
02a0b964 | 4469 | continue; |
4470 | ||
4471 | // Access representation items | |
44f29823 | 4472 | NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems; |
4473 | collectRepresentationItems(Graph, aShapeRepr, aReprItems); | |
02a0b964 | 4474 | |
44f29823 | 4475 | if (aReprItems.Length() == 0) |
02a0b964 | 4476 | continue; |
4477 | ||
cf152970 | 4478 | if (!ShapeLabelMap.IsBound(aRootShape)) |
02a0b964 | 4479 | continue; |
4480 | ||
4481 | TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape); | |
44f29823 | 4482 | // Do not add subshapes to assembly, |
4483 | // they will be processed with corresponding Shape_Product_Definition of necessary part. | |
4484 | if (ShapeTool->IsAssembly(aRootLab)) | |
4485 | continue; | |
02a0b964 | 4486 | |
4487 | StepRepr_SequenceOfRepresentationItem aMSBSeq; | |
4488 | StepRepr_SequenceOfRepresentationItem aSBSMSeq; | |
4489 | ||
4490 | // Iterate over the top level representation items collecting the | |
4491 | // topological containers to expand | |
44f29823 | 4492 | for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i) |
02a0b964 | 4493 | { |
44f29823 | 4494 | Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i); |
cf152970 | 4495 | if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) |
02a0b964 | 4496 | aMSBSeq.Append(aTRepr); |
cf152970 | 4497 | else if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) |
02a0b964 | 4498 | aSBSMSeq.Append(aTRepr); |
4499 | } | |
4500 | ||
4501 | // Insert intermediate OCAF Labels for SOLIDs in case there are more | |
4502 | // than one Manifold Solid BRep in the Shape Representation | |
4503 | Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1); | |
4504 | ||
4505 | // Expand Manifold Solid BReps | |
cf152970 | 4506 | for (Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i) |
02a0b964 | 4507 | { |
02a0b964 | 4508 | // Put additional Label for SOLID |
44f29823 | 4509 | if (doInsertSolidLab) |
4510 | SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP); | |
02a0b964 | 4511 | |
44f29823 | 4512 | ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool); |
02a0b964 | 4513 | } |
4514 | ||
4515 | // Expand Shell-Based Surface Models | |
cf152970 | 4516 | for (Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i) |
02a0b964 | 4517 | ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool); |
4518 | } | |
4519 | } | |
4520 | ||
4521 | //======================================================================= | |
4522 | //function : ExpandManifoldSolidBrep | |
4523 | //purpose : | |
4524 | //======================================================================= | |
4525 | ||
4526 | void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab, | |
cf152970 | 4527 | const Handle(StepRepr_RepresentationItem)& Repr, |
4528 | const Handle(Transfer_TransientProcess)& TP, | |
4529 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
02a0b964 | 4530 | { |
4531 | // Access outer shell | |
4532 | Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr); | |
eab2c851 | 4533 | Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer(); |
02a0b964 | 4534 | |
4535 | // Expand shell contents to CAF tree | |
4536 | ExpandShell(aShell, ShapeLab, TP, ShapeTool); | |
4537 | } | |
4538 | ||
4539 | //======================================================================= | |
4540 | //function : ExpandSBSM | |
4541 | //purpose : | |
4542 | //======================================================================= | |
4543 | ||
4544 | void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab, | |
cf152970 | 4545 | const Handle(StepRepr_RepresentationItem)& Repr, |
4546 | const Handle(Transfer_TransientProcess)& TP, | |
4547 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
02a0b964 | 4548 | { |
4549 | Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr); | |
4550 | ||
4551 | // Access boundary shells | |
4552 | Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary(); | |
cf152970 | 4553 | for (Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s) |
02a0b964 | 4554 | { |
4555 | const StepShape_Shell& aShell = aShells->Value(s); | |
4556 | Handle(StepShape_ConnectedFaceSet) aCFS; | |
4557 | Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell(); | |
4558 | Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell(); | |
4559 | ||
cf152970 | 4560 | if (!anOpenShell.IsNull()) |
02a0b964 | 4561 | aCFS = anOpenShell; |
4562 | else | |
4563 | aCFS = aClosedShell; | |
4564 | ||
4565 | ExpandShell(aCFS, ShapeLab, TP, ShapeTool); | |
4566 | } | |
4567 | } | |
4568 | ||
4569 | //======================================================================= | |
4570 | //function : ExpandShell | |
4571 | //purpose : | |
4572 | //======================================================================= | |
4573 | ||
4574 | void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell, | |
cf152970 | 4575 | TDF_Label& RootLab, |
4576 | const Handle(Transfer_TransientProcess)& TP, | |
4577 | const Handle(XCAFDoc_ShapeTool)& ShapeTool) const | |
02a0b964 | 4578 | { |
4579 | // Record CAF data | |
44f29823 | 4580 | SettleShapeData(Shell, RootLab, ShapeTool, TP); |
02a0b964 | 4581 | |
4582 | // Access faces | |
4583 | Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces(); | |
cf152970 | 4584 | for (Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f) |
02a0b964 | 4585 | { |
4586 | const Handle(StepShape_Face)& aFace = aFaces->Value(f); | |
ea7ffc28 | 4587 | if (aFace.IsNull()) |
4588 | continue; | |
02a0b964 | 4589 | |
4590 | // Record CAF data | |
44f29823 | 4591 | SettleShapeData(aFace, RootLab, ShapeTool, TP); |
02a0b964 | 4592 | |
4593 | // Access face bounds | |
4594 | Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds(); | |
7b93ae3c | 4595 | if (aWires.IsNull()) |
4596 | continue; | |
cf152970 | 4597 | for (Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w) |
02a0b964 | 4598 | { |
4599 | const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound(); | |
4600 | ||
4601 | // Record CAF data | |
44f29823 | 4602 | SettleShapeData(aWire, RootLab, ShapeTool, TP); |
02a0b964 | 4603 | |
4604 | // Access wire edges | |
4605 | // Currently only EDGE LOOPs are considered (!) | |
cf152970 | 4606 | if (!aWire->IsInstance(STANDARD_TYPE(StepShape_EdgeLoop))) |
02a0b964 | 4607 | continue; |
4608 | ||
4609 | // Access edges | |
4610 | Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire); | |
4611 | Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList(); | |
cf152970 | 4612 | for (Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e) |
02a0b964 | 4613 | { |
7b93ae3c | 4614 | Handle(StepShape_OrientedEdge) anOrientedEdge = anEdges->Value(e); |
4615 | if (anOrientedEdge.IsNull()) | |
4616 | continue; | |
4617 | Handle(StepShape_Edge) anEdge = anOrientedEdge->EdgeElement(); | |
4618 | if (anEdge.IsNull()) | |
4619 | continue; | |
02a0b964 | 4620 | |
4621 | // Record CAF data | |
44f29823 | 4622 | SettleShapeData(anEdge, RootLab, ShapeTool, TP); |
02a0b964 | 4623 | |
4624 | // Access vertices | |
4625 | Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart(); | |
4626 | Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd(); | |
4627 | ||
4628 | // Record CAF data | |
44f29823 | 4629 | SettleShapeData(aV1, RootLab, ShapeTool, TP); |
4630 | SettleShapeData(aV2, RootLab, ShapeTool, TP); | |
02a0b964 | 4631 | } |
4632 | } | |
4633 | } | |
4634 | } | |
7fd59977 | 4635 | |
4636 | //======================================================================= | |
4637 | //function : SetColorMode | |
4638 | //purpose : | |
4639 | //======================================================================= | |
4640 | ||
cf152970 | 4641 | void STEPCAFControl_Reader::SetColorMode(const Standard_Boolean colormode) |
7fd59977 | 4642 | { |
4643 | myColorMode = colormode; | |
4644 | } | |
4645 | ||
4646 | //======================================================================= | |
4647 | //function : GetColorMode | |
4648 | //purpose : | |
4649 | //======================================================================= | |
4650 | ||
cf152970 | 4651 | Standard_Boolean STEPCAFControl_Reader::GetColorMode() const |
7fd59977 | 4652 | { |
4653 | return myColorMode; | |
4654 | } | |
4655 | ||
4656 | //======================================================================= | |
4657 | //function : SetNameMode | |
4658 | //purpose : | |
4659 | //======================================================================= | |
4660 | ||
cf152970 | 4661 | void STEPCAFControl_Reader::SetNameMode(const Standard_Boolean namemode) |
7fd59977 | 4662 | { |
4663 | myNameMode = namemode; | |
4664 | } | |
4665 | ||
4666 | //======================================================================= | |
4667 | //function : GetNameMode | |
4668 | //purpose : | |
4669 | //======================================================================= | |
4670 | ||
cf152970 | 4671 | Standard_Boolean STEPCAFControl_Reader::GetNameMode() const |
7fd59977 | 4672 | { |
4673 | return myNameMode; | |
4674 | } | |
4675 | ||
4676 | //======================================================================= | |
4677 | //function : SetLayerMode | |
4678 | //purpose : | |
4679 | //======================================================================= | |
4680 | ||
cf152970 | 4681 | void STEPCAFControl_Reader::SetLayerMode(const Standard_Boolean layermode) |
7fd59977 | 4682 | { |
4683 | myLayerMode = layermode; | |
4684 | } | |
4685 | ||
4686 | //======================================================================= | |
4687 | //function : GetLayerMode | |
4688 | //purpose : | |
4689 | //======================================================================= | |
4690 | ||
cf152970 | 4691 | Standard_Boolean STEPCAFControl_Reader::GetLayerMode() const |
7fd59977 | 4692 | { |
4693 | return myLayerMode; | |
4694 | } | |
4695 | ||
4696 | //======================================================================= | |
4697 | //function : SetPropsMode | |
4698 | //purpose : | |
4699 | //======================================================================= | |
4700 | ||
cf152970 | 4701 | void STEPCAFControl_Reader::SetPropsMode(const Standard_Boolean propsmode) |
7fd59977 | 4702 | { |
4703 | myPropsMode = propsmode; | |
4704 | } | |
4705 | ||
4706 | //======================================================================= | |
4707 | //function : GetPropsMode | |
4708 | //purpose : | |
4709 | //======================================================================= | |
4710 | ||
cf152970 | 4711 | Standard_Boolean STEPCAFControl_Reader::GetPropsMode() const |
7fd59977 | 4712 | { |
4713 | return myPropsMode; | |
4714 | } | |
4715 | ||
4716 | //======================================================================= | |
4717 | //function : SetSHUOMode | |
4718 | //purpose : | |
4719 | //======================================================================= | |
4720 | ||
cf152970 | 4721 | void STEPCAFControl_Reader::SetSHUOMode(const Standard_Boolean mode) |
7fd59977 | 4722 | { |
4723 | mySHUOMode = mode; | |
4724 | } | |
4725 | ||
4726 | //======================================================================= | |
4727 | //function : GetSHUOMode | |
4728 | //purpose : | |
4729 | //======================================================================= | |
4730 | ||
cf152970 | 4731 | Standard_Boolean STEPCAFControl_Reader::GetSHUOMode() const |
7fd59977 | 4732 | { |
4733 | return mySHUOMode; | |
4734 | } | |
4735 | ||
4736 | //======================================================================= | |
4737 | //function : SetGDTMode | |
4738 | //purpose : | |
4739 | //======================================================================= | |
4740 | ||
cf152970 | 4741 | void STEPCAFControl_Reader::SetGDTMode(const Standard_Boolean gdtmode) |
7fd59977 | 4742 | { |
4743 | myGDTMode = gdtmode; | |
4744 | } | |
4745 | ||
4746 | //======================================================================= | |
4747 | //function : GetGDTMode | |
4748 | //purpose : | |
4749 | //======================================================================= | |
4750 | ||
cf152970 | 4751 | Standard_Boolean STEPCAFControl_Reader::GetGDTMode() const |
7fd59977 | 4752 | { |
4753 | return myGDTMode; | |
4754 | } | |
4755 | ||
4756 | ||
4757 | //======================================================================= | |
4758 | //function : SetMatMode | |
4759 | //purpose : | |
4760 | //======================================================================= | |
4761 | ||
cf152970 | 4762 | void STEPCAFControl_Reader::SetMatMode(const Standard_Boolean matmode) |
7fd59977 | 4763 | { |
4764 | myMatMode = matmode; | |
4765 | } | |
4766 | ||
4767 | //======================================================================= | |
4768 | //function : GetMatMode | |
4769 | //purpose : | |
4770 | //======================================================================= | |
4771 | ||
cf152970 | 4772 | Standard_Boolean STEPCAFControl_Reader::GetMatMode() const |
7fd59977 | 4773 | { |
4774 | return myMatMode; | |
4775 | } | |
0c63f2f8 | 4776 | |
4777 | //======================================================================= | |
4778 | //function : SetViewMode | |
4779 | //purpose : | |
4780 | //======================================================================= | |
4781 | ||
4782 | void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode) | |
4783 | { | |
4784 | myViewMode = viewmode; | |
4785 | } | |
4786 | ||
4787 | //======================================================================= | |
4788 | //function : GetViewMode | |
4789 | //purpose : | |
4790 | //======================================================================= | |
4791 | ||
4792 | Standard_Boolean STEPCAFControl_Reader::GetViewMode() const | |
4793 | { | |
4794 | return myViewMode; | |
4795 | } |