1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <Geom_Axis2Placement.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Interface_EntityIterator.hxx>
22 #include <Interface_InterfaceModel.hxx>
23 #include <StepData_StepModel.hxx>
24 #include <HeaderSection_FileSchema.hxx>
25 #include <Interface_Static.hxx>
26 #include <NCollection_DataMap.hxx>
27 #include <OSD_Path.hxx>
28 #include <Quantity_Color.hxx>
29 #include <Quantity_ColorRGBA.hxx>
30 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
31 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
32 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
33 #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
34 #include <StepBasic_DerivedUnit.hxx>
35 #include <StepBasic_DerivedUnitElement.hxx>
36 #include <StepBasic_MeasureValueMember.hxx>
37 #include <StepBasic_MeasureWithUnit.hxx>
38 #include <StepBasic_NamedUnit.hxx>
39 #include <StepBasic_Product.hxx>
40 #include <StepBasic_ProductDefinition.hxx>
41 #include <StepBasic_ProductDefinitionFormation.hxx>
42 #include <StepBasic_ProductDefinitionRelationship.hxx>
43 #include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx>
44 #include <StepBasic_SiUnit.hxx>
45 #include <StepBasic_SiUnitAndLengthUnit.hxx>
46 #include <StepBasic_Unit.hxx>
47 #include <STEPCAFControl_Controller.hxx>
48 #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
49 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
50 #include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
51 #include <STEPCAFControl_DataMapOfShapePD.hxx>
52 #include <STEPCAFControl_ExternFile.hxx>
53 #include <STEPCAFControl_Reader.hxx>
54 #include <STEPConstruct.hxx>
55 #include <STEPConstruct_Assembly.hxx>
56 #include <STEPConstruct_ExternRefs.hxx>
57 #include <STEPConstruct_Styles.hxx>
58 #include <STEPConstruct_Tool.hxx>
59 #include <STEPConstruct_UnitContext.hxx>
60 #include <STEPConstruct_ValidationProps.hxx>
61 #include <STEPControl_ActorRead.hxx>
62 #include <STEPControl_Reader.hxx>
63 #include <StepGeom_GeometricRepresentationItem.hxx>
64 #include <StepGeom_Axis2Placement3d.hxx>
65 #include <StepGeom_Direction.hxx>
66 #include <StepDimTol_AngularityTolerance.hxx>
67 #include <StepDimTol_CircularRunoutTolerance.hxx>
68 #include <StepDimTol_CoaxialityTolerance.hxx>
69 #include <StepDimTol_ConcentricityTolerance.hxx>
70 #include <StepDimTol_CylindricityTolerance.hxx>
71 #include <StepDimTol_Datum.hxx>
72 #include <StepDimTol_DatumFeature.hxx>
73 #include <StepDimTol_DatumReference.hxx>
74 #include <StepDimTol_DatumReferenceElement.hxx>
75 #include <StepDimTol_DatumReferenceCompartment.hxx>
76 #include <StepDimTol_DatumSystem.hxx>
77 #include <StepDimTol_FlatnessTolerance.hxx>
78 #include <StepDimTol_GeometricTolerance.hxx>
79 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
80 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
81 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
82 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
83 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
84 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
85 #include <StepDimTol_HArray1OfDatumReference.hxx>
86 #include <StepDimTol_LineProfileTolerance.hxx>
87 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
88 #include <StepDimTol_ParallelismTolerance.hxx>
89 #include <StepDimTol_PerpendicularityTolerance.hxx>
90 #include <StepDimTol_PositionTolerance.hxx>
91 #include <StepDimTol_ProjectedZoneDefinition.hxx>
92 #include <StepDimTol_RoundnessTolerance.hxx>
93 #include <StepDimTol_RunoutZoneDefinition.hxx>
94 #include <StepDimTol_StraightnessTolerance.hxx>
95 #include <StepDimTol_SurfaceProfileTolerance.hxx>
96 #include <StepDimTol_SymmetryTolerance.hxx>
97 #include <StepDimTol_ToleranceZone.hxx>
98 #include <StepDimTol_ToleranceZoneForm.hxx>
99 #include <StepDimTol_TotalRunoutTolerance.hxx>
100 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
101 #include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
102 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
103 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
104 #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
105 #include <StepGeom_Axis2Placement3d.hxx>
106 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
107 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
108 #include <StepGeom_Plane.hxx>
109 #include <StepGeom_Polyline.hxx>
110 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
111 #include <StepRepr_AssemblyComponentUsage.hxx>
112 #include <StepRepr_CharacterizedDefinition.hxx>
113 #include <StepRepr_CompoundRepresentationItem.hxx>
114 #include <StepRepr_DerivedShapeAspect.hxx>
115 #include <StepRepr_DescriptiveRepresentationItem.hxx>
116 #include <StepRepr_HArray1OfRepresentationItem.hxx>
117 #include <StepRepr_MappedItem.hxx>
118 #include <StepRepr_MeasureRepresentationItem.hxx>
119 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
120 #include <StepRepr_ProductDefinitionShape.hxx>
121 #include <StepRepr_PropertyDefinition.hxx>
122 #include <StepRepr_PropertyDefinitionRepresentation.hxx>
123 #include <StepRepr_Representation.hxx>
124 #include <StepRepr_RepresentationItem.hxx>
125 #include <StepRepr_HArray1OfRepresentationItem.hxx>
126 #include <StepRepr_RepresentationMap.hxx>
127 #include <StepRepr_RepresentationRelationship.hxx>
128 #include <StepRepr_RepresentedDefinition.hxx>
129 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
130 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
131 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
132 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
133 #include <StepRepr_SequenceOfRepresentationItem.hxx>
134 #include <StepRepr_ShapeAspect.hxx>
135 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
136 #include <StepRepr_CompositeShapeAspect.hxx>
137 #include <StepRepr_AllAroundShapeAspect.hxx>
138 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
139 #include <StepRepr_ShapeAspectRelationship.hxx>
140 #include <StepRepr_ShapeRepresentationRelationship.hxx>
141 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
142 #include <StepRepr_ValueRange.hxx>
143 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
144 #include <StepShape_AdvancedFace.hxx>
145 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
146 #include <StepShape_AngleRelator.hxx>
147 #include <StepShape_AngularSize.hxx>
148 #include <StepShape_AngularLocation.hxx>
149 #include <StepShape_ClosedShell.hxx>
150 #include <StepShape_ConnectedFaceSet.hxx>
151 #include <StepShape_ContextDependentShapeRepresentation.hxx>
152 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
153 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
154 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
155 #include <StepShape_DimensionalSizeWithPath.hxx>
156 #include <StepShape_DimensionalLocationWithPath.hxx>
157 #include <StepShape_ShapeDimensionRepresentationItem.hxx>
158 #include <StepShape_ShapeRepresentationWithParameters.hxx>
159 #include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
160 #include <StepShape_DimensionalSize.hxx>
161 #include <StepShape_DimensionalLocation.hxx>
162 #include <StepShape_EdgeCurve.hxx>
163 #include <StepShape_EdgeLoop.hxx>
164 #include <StepShape_GeometricCurveSet.hxx>
165 #include <StepShape_GeometricSet.hxx>
166 #include <StepShape_HArray1OfFace.hxx>
167 #include <StepShape_HArray1OfFaceBound.hxx>
168 #include <StepShape_HArray1OfOrientedEdge.hxx>
169 #include <StepShape_HArray1OfShell.hxx>
170 #include <StepShape_LimitsAndFits.hxx>
171 #include <StepShape_Loop.hxx>
172 #include <StepShape_ManifoldSolidBrep.hxx>
173 #include <StepShape_PlusMinusTolerance.hxx>
174 #include <StepShape_QualifiedRepresentationItem.hxx>
175 #include <StepShape_OpenShell.hxx>
176 #include <StepShape_ShapeDefinitionRepresentation.hxx>
177 #include <StepShape_ShapeDimensionRepresentation.hxx>
178 #include <StepShape_ShapeRepresentation.hxx>
179 #include <StepShape_ShellBasedSurfaceModel.hxx>
180 #include <StepShape_SolidModel.hxx>
181 #include <StepShape_ToleranceMethodDefinition.hxx>
182 #include <StepShape_ToleranceValue.hxx>
183 #include <StepShape_ValueFormatTypeQualifier.hxx>
184 #include <StepShape_Vertex.hxx>
185 #include <StepToGeom.hxx>
186 #include <StepVisual_AnnotationCurveOccurrence.hxx>
187 #include <StepVisual_AnnotationFillArea.hxx>
188 #include <StepVisual_AnnotationPlane.hxx>
189 #include <StepVisual_CameraModelD3.hxx>
190 #include <StepVisual_CameraModelD3MultiClipping.hxx>
191 #include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
192 #include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
193 #include <StepVisual_CoordinatesList.hxx>
194 #include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
195 #include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
196 #include <StepVisual_DraughtingCallout.hxx>
197 #include <StepVisual_DraughtingCalloutElement.hxx>
198 #include <StepVisual_DraughtingModel.hxx>
199 #include <StepVisual_Invisibility.hxx>
200 #include <StepVisual_LayeredItem.hxx>
201 #include <StepVisual_PlanarBox.hxx>
202 #include <StepVisual_PresentationLayerAssignment.hxx>
203 #include <StepVisual_PresentationStyleByContext.hxx>
204 #include <StepVisual_StyleContextSelect.hxx>
205 #include <StepVisual_StyledItem.hxx>
206 #include <StepVisual_ViewVolume.hxx>
207 #include <StepShape_TypeQualifier.hxx>
208 #include <TCollection_AsciiString.hxx>
209 #include <TCollection_HAsciiString.hxx>
210 #include <TColStd_HArray1OfReal.hxx>
211 #include <TColStd_HArray1OfTransient.hxx>
212 #include <TColStd_HSequenceOfTransient.hxx>
213 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
214 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
215 #include <TColStd_MapOfTransient.hxx>
216 #include <TColStd_SequenceOfHAsciiString.hxx>
217 #include <TDataStd_Name.hxx>
218 #include <TDataStd_TreeNode.hxx>
219 #include <TDataStd_UAttribute.hxx>
220 #include <TDF_Label.hxx>
221 #include <TDF_Tool.hxx>
222 #include <TDocStd_Document.hxx>
223 #include <TNaming_NamedShape.hxx>
224 #include <TopExp_Explorer.hxx>
225 #include <TopoDS.hxx>
226 #include <TopoDS_Compound.hxx>
227 #include <TopoDS_Iterator.hxx>
228 #include <TopoDS_Shape.hxx>
229 #include <TopTools_ListIteratorOfListOfShape.hxx>
230 #include <TopTools_ListOfShape.hxx>
231 #include <TopTools_MapOfShape.hxx>
232 #include <Transfer_Binder.hxx>
233 #include <Transfer_TransientProcess.hxx>
234 #include <TransferBRep.hxx>
235 #include <UnitsMethods.hxx>
236 #include <XCAFDoc.hxx>
237 #include <XCAFDoc_Area.hxx>
238 #include <XCAFDoc_Centroid.hxx>
239 #include <XCAFDoc_ClippingPlaneTool.hxx>
240 #include <XCAFDoc_ColorTool.hxx>
241 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
242 #include <XCAFDoc_DimTolTool.hxx>
243 #include <XCAFDoc_Dimension.hxx>
244 #include <XCAFDoc_Datum.hxx>
245 #include <XCAFDoc_GeomTolerance.hxx>
246 #include <XCAFDoc_DocumentTool.hxx>
247 #include <XCAFDoc_GraphNode.hxx>
248 #include <XCAFDoc_LayerTool.hxx>
249 #include <XCAFDoc_MaterialTool.hxx>
250 #include <XCAFDoc_ShapeTool.hxx>
251 #include <XCAFDoc_View.hxx>
252 #include <XCAFDoc_ViewTool.hxx>
253 #include <XCAFDoc_Volume.hxx>
254 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
255 #include <XCAFDimTolObjects_GeomToleranceType.hxx>
256 #include <XCAFDimTolObjects_DimensionObject.hxx>
257 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
258 #include <XCAFDimTolObjects_DatumObject.hxx>
259 #include <XCAFView_Object.hxx>
260 #include <XSAlgo.hxx>
261 #include <XSAlgo_AlgoContainer.hxx>
262 #include <XSControl_TransferReader.hxx>
263 #include <XSControl_WorkSession.hxx>
264 #include <StepAP242_DraughtingModelItemAssociation.hxx>
265 #include <StepAP242_GeometricItemSpecificUsage.hxx>
266 #include <StepGeom_CartesianPoint.hxx>
267 #include <STEPCAFControl_GDTProperty.hxx>
268 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
269 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
270 #include <StepVisual_TessellatedItem.hxx>
271 #include <StepVisual_TessellatedGeometricSet.hxx>
272 #include <StepVisual_TessellatedCurveSet.hxx>
273 #include <StepVisual_CoordinatesList.hxx>
274 #include <NCollection_Vector.hxx>
276 #include <TColgp_HArray1OfXYZ.hxx>
277 #include <BRepBuilderAPI_MakeEdge.hxx>
278 #include <BRepTools.hxx>
279 #include <Transfer_ActorOfTransientProcess.hxx>
280 #include <Bnd_Box.hxx>
281 #include <BRepBndLib.hxx>
282 #include <Resource_Unicode.hxx>
284 // skl 21.08.2003 for reading G&DT
285 //#include <StepRepr_CompoundItemDefinition.hxx>
286 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
287 //#include <StepBasic_ConversionBasedUnit.hxx>
288 //#include <TDataStd_Real.hxx>
289 //#include <TDataStd_Constraint.hxx>
290 //#include <TDataStd_ConstraintEnum.hxx>
291 //#include <TNaming_Tool.hxx>
292 //#include <AIS_InteractiveObject.hxx>
293 //#include <TPrsStd_ConstraintTools.hxx>
294 //#include <AIS_DiameterDimension.hxx>
295 //#include <TPrsStd_Position.hxx>
296 //#include <TPrsStd_AISPresentation.hxx>
297 //#include <TNaming_Builder.hxx>
299 //! Converts address of the passed shape (TShape) to string.
300 //! \param theShape [in] Shape to dump.
301 //! \return corresponding string.
302 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
304 std::string anAddrStr;
305 std::ostringstream ost;
306 ost << theShape.TShape().get();
307 anAddrStr = ost.str();
309 TCollection_AsciiString aStr =
310 TCollection_AsciiString("[").Cat(anAddrStr.c_str()).Cat("]");
316 //=======================================================================
317 //function : STEPCAFControl_Reader
319 //=======================================================================
321 STEPCAFControl_Reader::STEPCAFControl_Reader()
322 : mySourceCodePage (Resource_FormatType_UTF8),
323 myColorMode(Standard_True),
324 myNameMode(Standard_True),
325 myLayerMode(Standard_True),
326 myPropsMode(Standard_True),
327 mySHUOMode(Standard_False),
328 myGDTMode(Standard_True),
329 myMatMode(Standard_True),
330 myViewMode(Standard_True)
332 STEPCAFControl_Controller::Init();
333 mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
337 //=======================================================================
338 //function : STEPCAFControl_Reader
340 //=======================================================================
342 STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS,
343 const Standard_Boolean scratch)
344 : mySourceCodePage (Resource_FormatType_UTF8),
345 myColorMode(Standard_True),
346 myNameMode(Standard_True),
347 myLayerMode(Standard_True),
348 myPropsMode(Standard_True),
349 mySHUOMode(Standard_False),
350 myGDTMode(Standard_True),
351 myMatMode(Standard_True),
352 myViewMode(Standard_True)
354 STEPCAFControl_Controller::Init();
355 mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
360 //=======================================================================
363 //=======================================================================
365 void STEPCAFControl_Reader::Init(const Handle(XSControl_WorkSession)& WS,
366 const Standard_Boolean scratch)
368 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
369 myReader.SetWS(WS, scratch);
373 //=======================================================================
374 //function : convertName
376 //=======================================================================
377 TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection_AsciiString& theName) const
379 TCollection_ExtendedString aName;
380 Resource_Unicode::ConvertFormatToUnicode (mySourceCodePage, theName.ToCString(), aName);
384 //=======================================================================
385 //function : ReadFile
387 //=======================================================================
389 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile(const Standard_CString filename)
391 return myReader.ReadFile(filename);
395 //=======================================================================
396 //function : NbRootsForTransfer
398 //=======================================================================
400 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer()
402 return myReader.NbRootsForTransfer();
406 //=======================================================================
407 //function : TransferOneRoot
409 //=======================================================================
411 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot(const Standard_Integer num,
412 Handle(TDocStd_Document) &doc)
414 TDF_LabelSequence Lseq;
415 return Transfer(myReader, num, doc, Lseq);
419 //=======================================================================
420 //function : Transfer
422 //=======================================================================
424 Standard_Boolean STEPCAFControl_Reader::Transfer(Handle(TDocStd_Document) &doc)
426 TDF_LabelSequence Lseq;
427 return Transfer(myReader, 0, doc, Lseq);
431 //=======================================================================
434 //=======================================================================
436 Standard_Boolean STEPCAFControl_Reader::Perform(const Standard_CString filename,
437 Handle(TDocStd_Document) &doc)
439 if (ReadFile(filename) != IFSelect_RetDone) return Standard_False;
440 return Transfer(doc);
444 //=======================================================================
447 //=======================================================================
449 Standard_Boolean STEPCAFControl_Reader::Perform(const TCollection_AsciiString &filename,
450 Handle(TDocStd_Document) &doc)
452 if (ReadFile(filename.ToCString()) != IFSelect_RetDone) return Standard_False;
453 return Transfer(doc);
457 //=======================================================================
458 //function : ExternFiles
460 //=======================================================================
462 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles() const
468 //=======================================================================
469 //function : ExternFile
471 //=======================================================================
473 Standard_Boolean STEPCAFControl_Reader::ExternFile(const Standard_CString name,
474 Handle(STEPCAFControl_ExternFile) &ef) const
477 if (myFiles.IsEmpty() || !myFiles.IsBound(name))
478 return Standard_False;
479 ef = myFiles.Find(name);
480 return Standard_True;
484 //=======================================================================
487 //=======================================================================
489 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader()
495 //=======================================================================
498 //=======================================================================
500 const STEPControl_Reader &STEPCAFControl_Reader::Reader() const
506 //=======================================================================
507 //function : FillShapesMap
508 //purpose : auxiliary: fill a map by all compounds and their components
509 //=======================================================================
511 static void FillShapesMap(const TopoDS_Shape &S, TopTools_MapOfShape &map)
517 if (S.ShapeType() != TopAbs_COMPOUND) return;
518 for (TopoDS_Iterator it(S); it.More(); it.Next())
519 FillShapesMap(it.Value(), map);
523 //=======================================================================
524 //function : Transfer
525 //purpose : basic working method
526 //=======================================================================
528 Standard_Boolean STEPCAFControl_Reader::Transfer(STEPControl_Reader &reader,
529 const Standard_Integer nroot,
530 Handle(TDocStd_Document) &doc,
531 TDF_LabelSequence &Lseq,
532 const Standard_Boolean asOne)
534 reader.ClearShapes();
538 Standard_Integer num = reader.NbRootsForTransfer();
539 if (num <= 0) return Standard_False;
541 if (nroot > num) return Standard_False;
542 reader.TransferOneRoot(nroot);
545 for (i = 1; i <= num; i++) reader.TransferOneRoot(i);
547 num = reader.NbShapes();
548 if (num <= 0) return Standard_False;
550 // Fill a map of (top-level) shapes resulting from that transfer
551 // Only these shapes will be considered further
552 TopTools_MapOfShape ShapesMap, NewShapesMap;
553 for (i = 1; i <= num; i++) FillShapesMap(reader.Shape(i), ShapesMap);
555 // Collect information on shapes originating from SDRs
556 // this will be used to distinguish compounds representing assemblies
557 // from the ones representing hybrid models and shape sets
558 STEPCAFControl_DataMapOfShapePD ShapePDMap;
559 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
560 Handle(Interface_InterfaceModel) Model = reader.Model();
561 const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
562 Standard_Integer nb = Model->NbEntities();
564 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
566 for (i = 1; i <= nb; i++) {
567 Handle(Standard_Transient) enti = Model->Value(i);
568 if (enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
569 // sequence for acceleration ReadMaterials
570 SeqPDS->Append(enti);
572 if (enti->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
573 Handle(StepBasic_ProductDefinition) PD =
574 Handle(StepBasic_ProductDefinition)::DownCast(enti);
575 Standard_Integer index = TP->MapIndex(PD);
577 Handle(Transfer_Binder) binder = TP->MapItem(index);
578 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
579 if (!S.IsNull() && ShapesMap.Contains(S)) {
581 ShapePDMap.Bind(S, PD);
582 Handle(STEPCAFControl_ExternFile) EF;
583 PDFileMap.Bind(PD, EF);
587 if (enti->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
588 Standard_Integer index = TP->MapIndex(enti);
590 Handle(Transfer_Binder) binder = TP->MapItem(index);
591 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
592 if (!S.IsNull() && ShapesMap.Contains(S))
598 // get directory name of the main file
599 OSD_Path mainfile(reader.WS()->LoadedFile());
600 mainfile.SetName("");
601 mainfile.SetExtension("");
602 TCollection_AsciiString dpath;
603 mainfile.SystemName(dpath);
605 // Load external references (only for relevant SDRs)
606 // and fill map SDR -> extern file
607 STEPConstruct_ExternRefs ExtRefs(reader.WS());
608 ExtRefs.LoadExternRefs();
609 for (i = 1; i <= ExtRefs.NbExternRefs(); i++) {
610 // check extern ref format
611 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
612 if (!format.IsNull()) {
613 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString("STEP AP203");
614 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString("STEP AP214");
615 if (!format->IsSameString(ap203, Standard_False) &&
616 !format->IsSameString(ap214, Standard_False)) {
618 std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << std::endl;
625 else std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << std::endl;
628 // get and check filename of the current extern ref
629 const Standard_CString filename = ExtRefs.FileName(i);
632 std::cout << "filename=" << filename << std::endl;
635 if (!filename || !filename[0]) {
637 std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << std::endl;
639 continue; // not a valid extern ref
642 // compute true path to the extern file
643 TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, filename);
644 if (fullname.Length() <= 0) fullname = filename;
648 char *mainfile = reader.WS()->LoadedFile();
649 if ( ! mainfile ) mainfile = "";
650 Standard_Integer slash = 0;
651 for ( Standard_Integer k=0; mainfile[k]; k++ )
652 if ( mainfile[k] == '/' ) slash = k;
653 strncpy ( fullname, mainfile, slash );
654 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
657 // get and check PD associated with the current extern ref
658 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
659 if (PD.IsNull()) continue; // not a valid extern ref
660 if (!PDFileMap.IsBound(PD)) continue; // this PD is not concerned by current transfer
662 // read extern file (or use existing data) and record its data
663 Handle(STEPCAFControl_ExternFile) EF =
664 ReadExternFile(filename, fullname.ToCString(), doc);
665 PDFileMap.Bind(PD, EF);
668 // and insert them to the document
669 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
670 if (STool.IsNull()) return Standard_False;
671 XCAFDoc_DataMapOfShapeLabel map;
673 Lseq.Append(AddShape(reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map));
675 for (i = 1; i <= num; i++) {
676 Lseq.Append(AddShape(reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map));
682 ReadColors(reader.WS(), doc, map);
686 ReadNames(reader.WS(), doc, PDFileMap, map);
688 // read validation props
690 ReadValProps(reader.WS(), doc, PDFileMap, map);
694 ReadLayers(reader.WS(), doc);
696 // read SHUO entities from STEP model
698 ReadSHUOs(reader.WS(), doc, PDFileMap, map);
700 // read GDT entities from STEP model
702 ReadGDTs(reader.WS(), doc);
704 // read Material entities from STEP model
706 ReadMaterials(reader.WS(), doc, SeqPDS);
708 // read View entities from STEP model
710 ReadViews(reader.WS(), doc);
712 // Expand resulting CAF structure for sub-shapes (optionally with their
713 // names) if requested
714 ExpandSubShapes(STool, map, ShapePDMap);
716 // Update assembly compounds
717 STool->UpdateAssemblies();
719 return Standard_True;
722 //=======================================================================
723 //function : AddShape
725 //=======================================================================
727 TDF_Label STEPCAFControl_Reader::AddShape(const TopoDS_Shape &S,
728 const Handle(XCAFDoc_ShapeTool) &STool,
729 const TopTools_MapOfShape &NewShapesMap,
730 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
731 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
732 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
734 // if shape has already been mapped, just return corresponding label
735 if (ShapeLabelMap.IsBound(S)) {
736 return ShapeLabelMap.Find(S);
739 // if shape is located, create instance
740 if (!S.Location().IsIdentity()) {
744 AddShape(S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap);
745 TDF_Label L = STool->AddShape(S, Standard_False); // should create reference
746 ShapeLabelMap.Bind(S, L);
750 // if shape is not compound, simple add it
751 if (S.ShapeType() != TopAbs_COMPOUND) {
752 TDF_Label L = STool->AddShape(S, Standard_False);
753 ShapeLabelMap.Bind(S, L);
757 // for compounds, compute number of subshapes and check whether this is assembly
758 Standard_Boolean isAssembly = Standard_False;
759 Standard_Integer nbComponents = 0;
761 for (it.Initialize(S); it.More() && !isAssembly; it.Next(), nbComponents++) {
762 TopoDS_Shape Sub0 = it.Value();
765 if (NewShapesMap.Contains(Sub0)) isAssembly = Standard_True;
768 // if(nbComponents>0) isAssembly = Standard_True;
770 // check whether it has associated external ref
771 TColStd_SequenceOfHAsciiString SHAS;
772 if (ShapePDMap.IsBound(S) && PDFileMap.IsBound(ShapePDMap.Find(S))) {
773 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(ShapePDMap.Find(S));
775 // (store information on extern refs in the document)
776 SHAS.Append(EF->GetName());
777 // if yes, just return corresponding label
778 if (!EF->GetLabel().IsNull()) {
779 // but if components >0, ignore extern ref!
780 if (nbComponents <= 0) {
781 ShapeLabelMap.Bind(S, EF->GetLabel());
782 STool->SetExternRefs(EF->GetLabel(), SHAS);
783 return EF->GetLabel();
787 if (!EF->GetLabel().IsNull())
788 std::cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << std::endl;
789 else if (nbComponents <= 0)
790 std::cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << std::endl;
795 // add compound either as a whole,
797 TDF_Label L = STool->AddShape(S, Standard_False);
798 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
799 ShapeLabelMap.Bind(S, L);
803 // or as assembly, component-by-component
804 TDF_Label L = STool->NewShape();
806 for (it.Initialize(S); it.More(); it.Next(), nbComponents++) {
807 TopoDS_Shape Sub0 = it.Value();
810 TDF_Label subL = AddShape(Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap);
811 if (!subL.IsNull()) {
812 TDF_Label instL = STool->AddComponent(L, subL, it.Value().Location());
813 ShapeLabelMap.Bind(it.Value(), instL);
816 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
817 ShapeLabelMap.Bind(S, L);
818 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
823 //=======================================================================
824 //function : ReadExternFile
826 //=======================================================================
828 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile(const Standard_CString file,
829 const Standard_CString fullname,
830 Handle(TDocStd_Document)& doc)
832 // if the file is already read, associate it with SDR
833 if (myFiles.IsBound(file)) {
834 return myFiles.ChangeFind(file);
838 std::cout << "Reading extern file: " << fullname << std::endl;
841 // create new WorkSession and Reader
842 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
843 newWS->SelectNorm("STEP");
844 STEPControl_Reader sr(newWS, Standard_False);
846 // start to fill the resulting ExternFile structure
847 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
849 EF->SetName(new TCollection_HAsciiString(file));
852 EF->SetLoadStatus(sr.ReadFile(fullname));
854 // transfer in single-result mode
855 if (EF->GetLoadStatus() == IFSelect_RetDone) {
856 TDF_LabelSequence labels;
857 EF->SetTransferStatus(Transfer(sr, 0, doc, labels, Standard_True));
858 if (labels.Length() > 0) EF->SetLabel(labels.Value(1));
861 // add read file to dictionary
862 myFiles.Bind(file, EF);
867 //=======================================================================
868 //function : findStyledSR
870 //=======================================================================
871 static void findStyledSR(const Handle(StepVisual_StyledItem) &style,
872 Handle(StepShape_ShapeRepresentation)& aSR)
874 // search Shape Represenatation for component styled item
875 for (Standard_Integer j = 1; j <= style->NbStyles(); j++) {
876 Handle(StepVisual_PresentationStyleByContext) PSA =
877 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue(j));
880 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
881 Handle(StepShape_ShapeRepresentation) aCurrentSR =
882 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
883 if (aCurrentSR.IsNull())
891 //=======================================================================
892 //function : propagateColorToParts
893 //purpose : auxilary, propagate color styles from assemblies to parts
894 //=======================================================================
896 static void propagateColorToParts(const Handle(XCAFDoc_ShapeTool)& theSTool,
897 const Handle(XCAFDoc_ColorTool)& theCTool,
898 const TDF_Label& theRoot)
900 // collect components to propagate
901 TDF_LabelSequence aComponents;
902 if (theRoot.IsEqual(theSTool->Label()))
903 theSTool->GetFreeShapes(aComponents);
905 theSTool->GetComponents(theRoot, aComponents);
907 // iterate each component
908 for (TDF_LabelSequence::Iterator anIt(aComponents); anIt.More(); anIt.Next())
910 // get original label
911 TDF_Label anOriginalL = anIt.Value();
912 theSTool->GetReferredShape(anOriginalL, anOriginalL);
914 // propagate to components without own colors
915 TDF_Label aColorL, aDummyColorL;
916 for (Standard_Integer aType = 1; aType <= 3; aType++)
918 if (theCTool->GetColor(theRoot, (XCAFDoc_ColorType)aType, aColorL) &&
919 !theCTool->GetColor(anOriginalL, (XCAFDoc_ColorType)aType, aDummyColorL))
920 theCTool->SetColor(anOriginalL, aColorL, (XCAFDoc_ColorType)aType);
922 if (!theCTool->IsVisible(theRoot))
923 theCTool->SetVisibility(anOriginalL, Standard_False);
925 // propagate to next level children
926 if (theSTool->IsAssembly(anOriginalL))
927 propagateColorToParts(theSTool, theCTool, anOriginalL);
930 //=======================================================================
931 //function : ReadColors
933 //=======================================================================
935 Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSession) &WS,
936 Handle(TDocStd_Document)& Doc,
937 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
939 STEPConstruct_Styles Styles(WS);
940 if (!Styles.LoadStyles()) {
942 std::cout << "Warning: no styles are found in the model" << std::endl;
944 return Standard_False;
946 // searching for invisible items in the model
947 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
948 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
950 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
951 if (CTool.IsNull()) return Standard_False;
952 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
953 if (STool.IsNull()) return Standard_False;
955 // parse and search for color attributes
956 Standard_Integer nb = Styles.NbStyles();
957 for (Standard_Integer i = 1; i <= nb; i++) {
958 Handle(StepVisual_StyledItem) style = Styles.Style(i);
959 if (style.IsNull()) continue;
961 Standard_Boolean IsVisible = Standard_True;
962 // check the visibility of styled item.
963 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
964 if (style != aHSeqOfInvisStyle->Value(si))
966 // found that current style is invisible.
967 IsVisible = Standard_False;
971 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol, RenderCol;
972 Standard_Real RenderTransp;
973 // check if it is component style
974 Standard_Boolean IsComponent = Standard_False;
975 if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, RenderCol, RenderTransp, IsComponent) && IsVisible)
978 // collect styled items
979 NCollection_Vector<StepVisual_StyledItemTarget> anItems;
980 if (!style->ItemAP242().IsNull()) {
981 anItems.Append(style->ItemAP242());
984 const Handle(Transfer_TransientProcess) &TP = WS->TransferReader()->TransientProcess();
985 for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
986 Standard_Integer index = TP->MapIndex(anItems.Value(itemIt).Value());
989 Handle(Transfer_Binder) binder = TP->MapItem(index);
990 S = TransferBRep::ShapeResult(binder);
992 Standard_Boolean isSkipSHUOstyle = Standard_False;
993 // take shape with real location.
994 while (IsComponent) {
996 Handle(StepShape_ShapeRepresentation) aSR;
997 findStyledSR(style, aSR);
998 // search for SR along model
1001 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
1002 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1003 for (subs.Start(); subs.More(); subs.Next()) {
1004 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1007 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1008 Handle(StepRepr_ProductDefinitionShape) PDS =
1009 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1012 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1014 Handle(StepRepr_AssemblyComponentUsage) ACU =
1015 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
1018 // PTV 10.02.2003 skip styled item that refer to SHUO
1019 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1020 isSkipSHUOstyle = Standard_True;
1023 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1024 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
1029 // PTV 10.02.2003 to find component of assembly CORRECTLY
1030 STEPConstruct_Tool Tool(WS);
1031 TDF_Label aShLab = FindInstance(NAUO, CTool->ShapeTool(), Tool, ShapeLabelMap);
1032 aSh = CTool->ShapeTool()->GetShape(aShLab);
1033 if (!aSh.IsNull()) {
1040 if (isSkipSHUOstyle)
1041 continue; // skip styled item which refer to SHUO
1046 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !RenderCol.IsNull() || !IsVisible)
1049 Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True);
1050 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !RenderCol.IsNull())
1052 Quantity_Color aSCol, aBCol, aCCol, aRCol;
1053 Quantity_ColorRGBA aFullSCol;
1054 if (!SurfCol.IsNull()) {
1055 Styles.DecodeColor(SurfCol, aSCol);
1056 aFullSCol = Quantity_ColorRGBA(aSCol);
1058 if (!BoundCol.IsNull())
1059 Styles.DecodeColor(BoundCol, aBCol);
1060 if (!CurveCol.IsNull())
1061 Styles.DecodeColor(CurveCol, aCCol);
1062 if (!RenderCol.IsNull()) {
1063 Styles.DecodeColor(RenderCol, aRCol);
1064 aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - RenderTransp));
1068 if (!SurfCol.IsNull() || !RenderCol.IsNull())
1069 CTool->SetColor(aL, aFullSCol, XCAFDoc_ColorSurf);
1070 if (!BoundCol.IsNull())
1071 CTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
1072 if (!CurveCol.IsNull())
1073 CTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
1077 for (TopoDS_Iterator it(S); it.More(); it.Next())
1080 if (STool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
1082 if (!SurfCol.IsNull() || !RenderCol.IsNull())
1083 CTool->SetColor(aL1, aFullSCol, XCAFDoc_ColorSurf);
1084 if (!BoundCol.IsNull())
1085 CTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
1086 if (!CurveCol.IsNull())
1087 CTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
1094 // sets the invisibility for shape.
1096 CTool->SetVisibility(aL, Standard_False);
1101 CTool->ReverseChainsOfTreeNodes();
1103 // some colors can be attached to assemblies, propagate them to components
1104 propagateColorToParts(STool, CTool, STool->Label());
1105 return Standard_True;
1108 //=======================================================================
1109 //function : GetLabelFromPD
1111 //=======================================================================
1113 static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1114 const Handle(XCAFDoc_ShapeTool) &STool,
1115 const Handle(Transfer_TransientProcess) &TP,
1116 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1117 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1120 if (PDFileMap.IsBound(PD)) {
1121 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1124 if (!L.IsNull()) return L;
1129 Handle(Transfer_Binder) binder = TP->Find(PD);
1130 if (binder.IsNull() || !binder->HasResult()) return L;
1131 S = TransferBRep::ShapeResult(TP, binder);
1132 if (S.IsNull()) return L;
1134 if (ShapeLabelMap.IsBound(S))
1135 L = ShapeLabelMap.Find(S);
1137 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1141 //=======================================================================
1142 //function : FindInstance
1144 //=======================================================================
1146 TDF_Label STEPCAFControl_Reader::FindInstance(const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1147 const Handle(XCAFDoc_ShapeTool) &STool,
1148 const STEPConstruct_Tool &Tool,
1149 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1153 // get shape resulting from CDSR (in fact, only location is interesting)
1154 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1155 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1156 if (binder.IsNull() || !binder->HasResult()) {
1158 std::cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << std::endl;
1163 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1166 std::cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << std::endl;
1171 if (ShapeLabelMap.IsBound(S))
1172 L = ShapeLabelMap(S);
1174 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1179 //=======================================================================
1180 //function : ReadNames
1182 //=======================================================================
1184 Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS,
1185 Handle(TDocStd_Document)& Doc,
1186 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1187 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1189 // get starting data
1190 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1191 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1192 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1193 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1194 if (STool.IsNull()) return Standard_False;
1195 STEPConstruct_Tool Tool(WS);
1197 // iterate on model to find all SDRs and CDSRs
1198 Standard_Integer nb = Model->NbEntities();
1199 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1200 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1201 Handle(Standard_Type) tPDWAD = STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments);
1202 Handle(TCollection_HAsciiString) name;
1204 for (Standard_Integer i = 1; i <= nb; i++) {
1205 Handle(Standard_Transient) enti = Model->Value(i);
1207 // get description of NAUO
1208 if (enti->DynamicType() == tNAUO) {
1210 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1211 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1212 if (NAUO.IsNull()) continue;
1213 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1214 for (subs.Start(); subs.More(); subs.Next()) {
1215 Handle(StepRepr_ProductDefinitionShape) PDS =
1216 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1217 if (PDS.IsNull()) continue;
1218 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1219 if (PDR.IsNull()) continue;
1220 if (PDR->HasDescription() &&
1221 PDR->Description()->UsefullLength() > 0) name = PDR->Description();
1222 else if (!PDR->Name().IsNull() && PDR->Name()->UsefullLength() > 0) name = PDR->Name();
1223 else if (!PDR->Id().IsNull()) name = PDR->Id();
1224 else name = new TCollection_HAsciiString;
1226 // find proper label
1227 L = FindInstance(NAUO, STool, Tool, ShapeLabelMap);
1228 if (L.IsNull()) continue;
1230 TCollection_ExtendedString str = convertName (name->String());
1231 TDataStd_Name::Set(L, str);
1234 // for PD get name of associated product
1235 if (enti->DynamicType() == tPD || enti->DynamicType() == tPDWAD) {
1237 Handle(StepBasic_ProductDefinition) PD =
1238 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1239 if (PD.IsNull()) continue;
1240 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1242 name = new TCollection_HAsciiString;
1243 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1244 name = Prod->Name();
1245 else if (!Prod->Id().IsNull())
1248 name = new TCollection_HAsciiString;
1249 L = GetLabelFromPD(PD, STool, TP, PDFileMap, ShapeLabelMap);
1250 if (L.IsNull()) continue;
1251 TCollection_ExtendedString str = convertName (name->String());
1252 TDataStd_Name::Set(L, str);
1254 // set a name to the document
1255 //TCollection_ExtendedString str = convertName (name->String());
1256 //TDataStd_Name::Set ( L, str );
1259 return Standard_True;
1262 //=======================================================================
1263 //function : GetLabelFromPD
1265 //=======================================================================
1267 static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1268 const Handle(XCAFDoc_ShapeTool) &STool,
1269 const STEPConstruct_ValidationProps &Props,
1270 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1271 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1274 if (PDFileMap.IsBound(PD)) {
1275 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1278 if (!L.IsNull()) return L;
1281 TopoDS_Shape S = Props.GetPropShape(PD);
1282 if (S.IsNull()) return L;
1283 if (ShapeLabelMap.IsBound(S))
1284 L = ShapeLabelMap.Find(S);
1286 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1290 //=======================================================================
1291 //function : ReadValProps
1293 //=======================================================================
1295 Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_WorkSession) &WS,
1296 Handle(TDocStd_Document)& Doc,
1297 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1298 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1300 // get starting data
1301 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1302 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1303 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1304 if (STool.IsNull()) return Standard_False;
1306 // load props from the STEP model
1307 TColStd_SequenceOfTransient props;
1308 STEPConstruct_ValidationProps Props(WS);
1309 if (!Props.LoadProps(props)) {
1311 std::cout << "Warning: no validation props found in the model" << std::endl;
1313 return Standard_False;
1316 // interpret props one by one
1317 for (Standard_Integer i = 1; i <= props.Length(); i++) {
1318 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1319 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(props.Value(i));
1320 if (PDR.IsNull()) continue;
1324 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1325 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1326 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1327 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
1328 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1329 if (PDS.IsNull()) continue;
1330 // find corresponding NAUO
1331 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1332 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1333 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1334 if (subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1335 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1337 if (!NAUO.IsNull()) {
1338 L = FindInstance(NAUO, STool, WS, ShapeLabelMap);
1339 if (L.IsNull()) continue;
1342 // find corresponding ProductDefinition:
1343 Handle(StepBasic_ProductDefinition) ProdDef;
1344 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1345 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1346 if (subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)))
1347 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1349 if (ProdDef.IsNull()) continue;
1350 L = GetLabelFromPD(ProdDef, STool, Props, PDFileMap, ShapeLabelMap);
1354 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
1355 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1356 if (SA.IsNull()) continue;
1357 // find ShapeRepresentation
1358 Handle(StepShape_ShapeRepresentation) SR;
1359 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1360 for (subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1361 Handle(StepRepr_PropertyDefinition) PropD1 =
1362 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1363 if (PropD1.IsNull()) continue;
1364 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1365 for (subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1366 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1367 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1368 if (SDR.IsNull()) continue;
1369 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1372 if (SR.IsNull()) continue;
1373 Handle(Transfer_Binder) binder;
1374 for (Standard_Integer ir = 1; ir <= SR->NbItems() && binder.IsNull(); ir++) {
1375 if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1376 Handle(StepShape_SolidModel) SM =
1377 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1378 binder = TP->Find(SM);
1380 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1381 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1382 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1383 binder = TP->Find(SBSM);
1385 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1386 Handle(StepShape_GeometricSet) GS =
1387 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1388 binder = TP->Find(GS);
1391 if (binder.IsNull() || !binder->HasResult()) continue;
1393 S = TransferBRep::ShapeResult(TP, binder);
1394 if (S.IsNull()) continue;
1395 if (ShapeLabelMap.IsBound(S))
1396 L = ShapeLabelMap.Find(S);
1398 STool->Search(S, L, Standard_True, Standard_True, Standard_True);
1402 if (L.IsNull()) continue;
1404 // decode validation properties
1405 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1406 for (Standard_Integer j = 1; j <= rep->NbItems(); j++) {
1407 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1408 Standard_Boolean isArea;
1411 if (Props.GetPropReal(ent, val, isArea)) {
1412 if (isArea) XCAFDoc_Area::Set(L, val);
1413 else XCAFDoc_Volume::Set(L, val);
1415 else if (Props.GetPropPnt(ent, rep->ContextOfItems(), pos)) {
1416 XCAFDoc_Centroid::Set(L, pos);
1420 return Standard_True;
1423 //=======================================================================
1424 //function : ReadLayers
1426 //=======================================================================
1428 Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSession) &WS,
1429 Handle(TDocStd_Document)& Doc) const
1431 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1432 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1433 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1434 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1435 if (STool.IsNull()) return Standard_False;
1436 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
1437 if (LTool.IsNull()) return Standard_False;
1439 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1440 Standard_Integer nb = Model->NbEntities();
1441 Handle(TCollection_HAsciiString) name;
1443 for (Standard_Integer i = 1; i <= nb; i++) {
1444 Handle(Standard_Transient) enti = Model->Value(i);
1445 if (!enti->IsKind(tSVPLA)) continue;
1446 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1447 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1448 if (SVPLA->AssignedItems().IsNull())
1451 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1452 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1453 TCollection_ExtendedString aLayerName(hName->String());
1455 // find a target shape and its label in the document
1456 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++) {
1457 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1458 Handle(Transfer_Binder) binder = TP->Find(LI.Value());
1459 if (binder.IsNull() || !binder->HasResult()) continue;
1461 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1462 if (S.IsNull()) continue;
1465 if (!STool->Search(S, shL, Standard_True, Standard_True, Standard_True)) continue;
1466 LTool->SetLayer(shL, aLayerName);
1469 // check invisibility
1470 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1471 for (subs.Start(); subs.More(); subs.Next()) {
1472 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue;
1474 std::cout << "\tLayer \"" << aLayerName << "\" is invisible" << std::endl;
1476 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1477 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1478 TDataStd_UAttribute::Set (InvLayerLab, XCAFDoc::InvisibleGUID());
1481 return Standard_True;
1484 //=======================================================================
1485 //function : ReadSHUOs
1487 //=======================================================================
1489 static Standard_Boolean findNextSHUOlevel(const Handle(XSControl_WorkSession) &WS,
1490 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1491 const Handle(XCAFDoc_ShapeTool)& STool,
1492 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1493 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1494 TDF_LabelSequence& aLabels)
1496 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1497 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1498 for (subs.Start(); subs.More(); subs.Next()) {
1499 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1500 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1504 if (subSHUO.IsNull())
1505 return Standard_False;
1507 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
1508 if (NUNAUO.IsNull())
1509 return Standard_False;
1510 // Handle(Interface_InterfaceModel) Model = WS->Model();
1511 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1512 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1513 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1514 // if ( binder.IsNull() || ! binder->HasResult() )
1515 // return Standard_False;
1516 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1517 // get label of NAUO next level
1519 STEPConstruct_Tool Tool(WS);
1520 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1521 // STool->Search(NUSh, NUlab);
1523 return Standard_False;
1524 aLabels.Append(NULab);
1525 // and check by recurse.
1526 findNextSHUOlevel(WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels);
1527 return Standard_True;
1531 //=======================================================================
1532 //function : setSHUOintoDoc
1533 //purpose : auxilary
1534 //=======================================================================
1535 static TDF_Label setSHUOintoDoc(const Handle(XSControl_WorkSession) &WS,
1536 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1537 const Handle(XCAFDoc_ShapeTool)& STool,
1538 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1539 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1541 TDF_Label aMainLabel;
1542 // get upper usage NAUO from SHUO.
1543 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1544 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1545 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
1546 if (UUNAUO.IsNull() || NUNAUO.IsNull()) {
1548 std::cout << "Warning: " << __FILE__ << ": Upper_usage or Next_usage of styled SHUO is null. Skip it" << std::endl;
1552 // Handle(Interface_InterfaceModel) Model = WS->Model();
1553 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1554 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1555 // TopoDS_Shape UUSh, NUSh;
1556 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1557 // if ( binder.IsNull() || ! binder->HasResult() )
1558 // return aMainLabel;
1559 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1560 // binder = TP->Find(NUNAUO);
1561 // if ( binder.IsNull() || ! binder->HasResult() )
1562 // return aMainLabel;
1563 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1565 // get first labels for first SHUO attribute
1566 TDF_Label UULab, NULab;
1567 STEPConstruct_Tool Tool(WS);
1568 UULab = STEPCAFControl_Reader::FindInstance(UUNAUO, STool, Tool, ShapeLabelMap);
1569 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1571 // STool->Search(UUSh, UULab);
1572 // STool->Search(NUSh, NULab);
1573 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1574 //create sequence fo labels to set SHUO structure into the document
1575 TDF_LabelSequence ShuoLabels;
1576 ShuoLabels.Append(UULab);
1577 ShuoLabels.Append(NULab);
1578 // add all other labels of sub SHUO entities
1579 findNextSHUOlevel(WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels);
1580 // last accord for SHUO
1581 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1582 if (STool->SetSHUO(ShuoLabels, anSHUOAttr))
1583 aMainLabel = anSHUOAttr->Label();
1589 //=======================================================================
1590 //function : ReadSHUOs
1592 //=======================================================================
1594 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(const Handle(XSControl_WorkSession) &WS,
1595 Handle(TDocStd_Document)& Doc,
1596 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1597 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1599 // the big part code duplication from ReadColors.
1600 // It is possible to share this code functionality, just to decide how ???
1601 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
1602 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1604 STEPConstruct_Styles Styles(WS);
1605 if (!Styles.LoadStyles()) {
1607 std::cout << "Warning: no styles are found in the model" << std::endl;
1609 return Standard_False;
1611 // searching for invisible items in the model
1612 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1613 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
1614 // parse and search for color attributes
1615 Standard_Integer nb = Styles.NbStyles();
1616 for (Standard_Integer i = 1; i <= nb; i++) {
1617 Handle(StepVisual_StyledItem) style = Styles.Style(i);
1618 if (style.IsNull()) continue;
1620 Standard_Boolean IsVisible = Standard_True;
1621 // check the visibility of styled item.
1622 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
1623 if (style != aHSeqOfInvisStyle->Value(si))
1625 // found that current style is invisible.
1627 std::cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << std::endl;
1629 IsVisible = Standard_False;
1633 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol, RenderCol;
1634 Standard_Real RenderTransp;
1635 // check if it is component style
1636 Standard_Boolean IsComponent = Standard_False;
1637 if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, RenderCol, RenderTransp, IsComponent) && IsVisible)
1641 Handle(StepShape_ShapeRepresentation) aSR;
1642 findStyledSR(style, aSR);
1643 // search for SR along model
1646 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
1647 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1648 for (subs.Start(); subs.More(); subs.Next()) {
1649 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1652 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1653 Handle(StepRepr_ProductDefinitionShape) PDS =
1654 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1657 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1658 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1659 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1663 // set the SHUO structure to the document
1664 TDF_Label aLabelForStyle = setSHUOintoDoc(WS, SHUO, STool, PDFileMap, ShapeLabelMap);
1665 if (aLabelForStyle.IsNull()) {
1667 std::cout << "Warning: " << __FILE__ << ": coudnot create SHUO structure in the document" << std::endl;
1671 // now set the style to the SHUO main label.
1672 if (!SurfCol.IsNull() || !RenderCol.IsNull()) {
1674 Quantity_ColorRGBA colRGBA;
1675 if (!SurfCol.IsNull()) {
1676 Styles.DecodeColor(SurfCol, col);
1677 colRGBA = Quantity_ColorRGBA(col);
1679 if (!RenderCol.IsNull()) {
1680 Styles.DecodeColor(RenderCol, col);
1681 colRGBA = Quantity_ColorRGBA(col, static_cast<float>(1.0 - RenderTransp));
1683 CTool->SetColor(aLabelForStyle, colRGBA, XCAFDoc_ColorSurf);
1685 if (!BoundCol.IsNull()) {
1687 Styles.DecodeColor(BoundCol, col);
1688 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
1690 if (!CurveCol.IsNull()) {
1692 Styles.DecodeColor(CurveCol, col);
1693 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
1696 // sets the invisibility for shape.
1697 CTool->SetVisibility(aLabelForStyle, Standard_False);
1699 } // end search SHUO by SDR
1700 } // end iterates on styles
1702 return Standard_True;
1705 //=======================================================================
1706 //function : GetMassConversionFactor
1708 //=======================================================================
1709 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1710 Standard_Real& afact)
1713 if (!NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) return Standard_False;
1714 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1715 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1716 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1717 afact = MWUCBU->ValueComponent();
1718 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1719 if (anUnit2.CaseNum(anUnit2.Value()) == 1) {
1720 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1721 if (NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1722 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1723 if (SU->Name() == StepBasic_sunGram) {
1724 if (SU->HasPrefix())
1725 afact *= STEPConstruct_UnitContext::ConvertSiPrefix(SU->Prefix());
1729 return Standard_True;
1732 //=======================================================================
1733 //function : readPMIPresentation
1734 //purpose : read polyline or tessellated presentation for
1735 // (Annotation_Curve_Occurrence or Draughting_Callout)
1736 //=======================================================================
1737 Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
1738 const Handle(XSControl_TransferReader)& theTR,
1739 const Standard_Real theFact,
1740 TopoDS_Shape& thePresentation,
1741 Handle(TCollection_HAsciiString)& thePresentName,
1744 if (thePresentEntity.IsNull())
1745 return Standard_False;
1746 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1747 Handle(StepVisual_AnnotationOccurrence) anAO;
1748 NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
1749 if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
1751 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
1752 if (!anAO.IsNull()) {
1753 thePresentName = anAO->Name();
1754 anAnnotations.Append(anAO);
1757 else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
1759 Handle(StepVisual_DraughtingCallout) aDCallout =
1760 Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
1761 thePresentName = aDCallout->Name();
1762 for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
1763 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
1766 anAnnotations.Append(anAO);
1769 Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
1770 aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
1771 if (!aTesselation.IsNull())
1772 anAnnotations.Append(aTesselation);
1776 if (!anAnnotations.Length())
1777 return Standard_False;
1781 TopoDS_Compound aResAnnotation;
1782 aB.MakeCompound(aResAnnotation);
1784 Standard_Integer i = 0;
1786 Standard_Integer nbShapes = 0;
1787 for (; i < anAnnotations.Length(); i++)
1789 Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
1790 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
1791 TopoDS_Shape anAnnotationShape;
1794 Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
1795 anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
1796 if (anAnnotationShape.IsNull())
1798 Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
1799 if (!binder.IsNull() && binder->HasResult()) {
1800 anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
1804 //case of tessellated entities
1807 Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
1808 if (aTessItem.IsNull())
1810 Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
1811 if (aTessSet.IsNull())
1813 NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
1814 Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
1815 Handle(StepVisual_TessellatedCurveSet) aTessCurve;
1816 for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++)
1818 aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
1820 if (aTessCurve.IsNull())
1822 Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
1823 if (aCoordList.IsNull())
1825 Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
1827 if (aPoints.IsNull() || aPoints->Length() == 0)
1829 NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves();
1830 Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
1831 TopoDS_Compound aComp;
1832 aB.MakeCompound(aComp);
1834 Standard_Integer k = 0;
1835 for (; k < aNbC; k++)
1837 Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
1841 for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
1843 Standard_Integer ind = anIndexes->Value(n);
1844 Standard_Integer indnext = anIndexes->Value(n + 1);
1845 if (ind > aPoints->Length() || indnext > aPoints->Length())
1847 gp_Pnt aP1(aPoints->Value(ind) * theFact);
1848 gp_Pnt aP2(aPoints->Value(indnext) * theFact);
1849 BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
1850 if (aMaker.IsDone())
1852 TopoDS_Edge aCurE = aMaker.Edge();
1853 aB.Add(aCurW, aCurE);
1856 aB.Add(aComp, aCurW);
1858 anAnnotationShape = aComp;
1860 if (!anAnnotationShape.IsNull())
1863 aB.Add(aResAnnotation, anAnnotationShape);
1864 if (i == anAnnotations.Length() - 1)
1865 BRepBndLib::AddClose(anAnnotationShape, aBox);
1869 thePresentation = aResAnnotation;
1871 return (nbShapes > 0);
1874 //=======================================================================
1875 //function : readAnnotationPlane
1876 //purpose : read annotation plane
1877 //=======================================================================
1878 Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
1881 if (theAnnotationPlane.IsNull())
1882 return Standard_False;
1883 Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
1884 if (aPlaneItem.IsNull())
1885 return Standard_False;
1886 Handle(StepGeom_Axis2Placement3d) aA2P3D;
1887 //retrieve axes from AnnotationPlane
1888 if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
1889 Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
1890 aA2P3D = aPlane->Position();
1892 else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
1893 Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
1894 aA2P3D = aBox->Placement().Axis2Placement3d();
1896 if (aA2P3D.IsNull())
1897 return Standard_False;
1899 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
1900 thePlane = anAxis->Ax2();
1901 return Standard_True;
1904 //=======================================================================
1905 //function : readAnnotation
1906 //purpose : read annotation plane and position for given GDT
1907 // (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
1908 //=======================================================================
1909 void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
1910 const Handle(Standard_Transient)& theGDT,
1911 const Handle(Standard_Transient)& theDimObject)
1913 if (theGDT.IsNull() || theDimObject.IsNull())
1915 Handle(TCollection_HAsciiString) aPresentName;
1916 TopoDS_Compound aResAnnotation;
1917 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1918 const Interface_Graph& aGraph = aTP->Graph();
1919 // find the proper DraughtingModelItemAssociation
1920 Interface_EntityIterator subs = aGraph.Sharings(theGDT);
1921 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
1922 for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
1923 if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
1925 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
1926 Handle(TCollection_HAsciiString) aName = aDMIA->Name();
1928 if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
1932 if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
1936 Handle(StepVisual_DraughtingModel) aDModel =
1937 Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
1938 XSAlgo::AlgoContainer()->PrepareForTransfer();
1939 STEPControl_ActorRead anActor;
1940 anActor.PrepareUnits(aDModel, aTP);
1941 Standard_Real aFact = UnitsMethods::LengthFactor();
1943 // retrieve AnnotationPlane
1944 Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
1945 if (aDMIAE.IsNull())
1948 subs = aGraph.Sharings(aDMIAE);
1949 Handle(StepVisual_AnnotationPlane) anAnPlane;
1950 for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
1951 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
1953 Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aPlaneAxes);
1955 // set plane axes to XCAF
1957 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
1958 Handle(XCAFDimTolObjects_DimensionObject) anObj =
1959 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
1960 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1);
1961 anObj->SetPlane(aPlaneAxes);
1963 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
1964 Handle(XCAFDimTolObjects_DatumObject) anObj =
1965 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
1966 anObj->SetPlane(aPlaneAxes);
1968 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
1969 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
1970 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
1971 anObj->SetPlane(aPlaneAxes);
1975 // Retrieve presentation
1977 if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
1979 gp_Pnt aPtext(0., 0., 0.);
1980 // if Annotation plane location inside bounding box set it to text position
1981 // else set the center of bounding box to text position 0027372
1984 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1985 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
1986 if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
1987 aPtext = aPlaneAxes.Location();
1990 aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
1994 aPtext = aPlaneAxes.Location();
1997 // set point to XCAF
1998 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
1999 Handle(XCAFDimTolObjects_DimensionObject) anObj =
2000 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
2001 anObj->SetPointTextAttach(aPtext);
2002 anObj->SetPresentation(aResAnnotation, aPresentName);
2004 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
2005 Handle(XCAFDimTolObjects_DatumObject) anObj =
2006 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
2007 anObj->SetPointTextAttach(aPtext);
2008 anObj->SetPresentation(aResAnnotation, aPresentName);
2010 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
2011 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
2012 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
2013 anObj->SetPointTextAttach(aPtext);
2014 anObj->SetPresentation(aResAnnotation, aPresentName);
2019 //=======================================================================
2020 //function : readConnectionPoints
2021 //purpose : read connection points for given dimension
2022 //=======================================================================
2023 void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
2024 const Handle(Standard_Transient) theGDT,
2025 const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
2027 if (theGDT.IsNull() || theDimObject.IsNull())
2029 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
2030 const Interface_Graph& aGraph = aTP->Graph();
2033 Standard_Real aFact = 1.;
2035 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
2036 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
2037 Handle(Standard_Transient) anEnt = anIt.Value();
2038 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
2039 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anEnt);
2041 aSDR = !aDCR.IsNull() ? aDCR->Representation() : Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anEnt);
2045 XSAlgo::AlgoContainer()->PrepareForTransfer();
2046 STEPControl_ActorRead anActor;
2047 anActor.PrepareUnits(aSDR, aTP);
2048 aFact = UnitsMethods::LengthFactor();
2051 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2052 // retrieve derived geometry
2053 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
2054 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
2057 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
2058 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
2059 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2061 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
2063 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
2064 if (aPoint.IsNull()) {
2065 // try Axis2Placement3d.location instead of CartesianPoint
2066 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2067 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
2068 if (anA2P3D.IsNull())
2070 aPoint = anA2P3D->Location();
2073 // set connection point to object
2074 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2075 theDimObject->SetPoint(aPnt);
2077 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2078 // retrieve derived geometry
2079 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
2080 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
2081 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
2082 if (aDSA1.IsNull() && aDSA2.IsNull())
2084 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
2085 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2086 if (!aDSA1.IsNull()) {
2087 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2088 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2091 if (!aDSA2.IsNull()) {
2092 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2093 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2097 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2098 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2099 if (aPoint.IsNull()) {
2100 // try Axis2Placement3d.location instead of CartesianPoint
2101 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2102 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2103 if (!anA2P3D.IsNull())
2104 aPoint = anA2P3D->Location();
2106 if (!aPoint.IsNull()) {
2107 // set connection point to object
2108 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2109 theDimObject->SetPoint(aPnt);
2113 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2114 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2115 if (aPoint.IsNull()) {
2116 // try Axis2Placement3d.location instead of CartesianPoint
2117 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2118 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2119 if (!anA2P3D.IsNull())
2120 aPoint = anA2P3D->Location();
2122 if (!aPoint.IsNull()) {
2123 // set connection point to object
2124 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2125 theDimObject->SetPoint2(aPnt);
2131 //=======================================================================
2132 //function : ReadDatums
2133 //purpose : auxilary
2134 //=======================================================================
2135 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
2136 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2137 const Interface_Graph &graph,
2138 const Handle(Transfer_TransientProcess) &TP,
2139 const TDF_Label TolerL,
2140 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
2142 if (GTWDR.IsNull()) return Standard_False;
2143 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
2144 if (HADR.IsNull()) return Standard_False;
2145 for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) {
2146 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2147 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
2148 if (aDatum.IsNull()) continue;
2149 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
2150 for (subs4.Start(); subs4.More(); subs4.Next()) {
2151 Handle(StepRepr_ShapeAspectRelationship) SAR =
2152 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
2153 if (SAR.IsNull()) continue;
2154 Handle(StepDimTol_DatumFeature) DF =
2155 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
2156 if (DF.IsNull()) continue;
2157 Interface_EntityIterator subs5 = graph.Sharings(DF);
2158 Handle(StepRepr_PropertyDefinition) PropDef;
2159 for (subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
2160 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2162 if (PropDef.IsNull()) continue;
2163 Handle(StepShape_AdvancedFace) AF;
2164 subs5 = graph.Sharings(PropDef);
2165 for (subs5.Start(); subs5.More(); subs5.Next()) {
2166 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2167 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
2168 if (!SDR.IsNull()) {
2169 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2170 if (!Repr.IsNull() && Repr->NbItems() > 0) {
2171 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2172 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2176 if (AF.IsNull()) return Standard_False;
2177 Standard_Integer index = TP->MapIndex(AF);
2180 Handle(Transfer_Binder) binder = TP->MapItem(index);
2181 aSh = TransferBRep::ShapeResult(binder);
2183 if (aSh.IsNull()) continue;
2185 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2186 DGTTool->SetDatum(shL, TolerL, PropDef->Name(), PropDef->Description(), aDatum->Identification());
2189 return Standard_True;
2192 //=======================================================================
2193 //function : FindShapeIndexForDGT
2194 //purpose : auxiliary find shape index in map og imported shapes
2195 //=======================================================================
2196 static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2197 const Handle(XSControl_WorkSession)& theWS)
2199 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2200 // try to find index of given entity
2201 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2204 // if theEnt is a geometry item try to find its topological item
2205 const Interface_Graph& aGraph = aTP->Graph();
2206 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2207 for (anIter.Start(); anIter.More(); anIter.Next()) {
2208 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2210 anIndex = aTP->MapIndex(anIter.Value());
2218 //=======================================================================
2219 //function : collectShapeAspect
2221 //=======================================================================
2222 static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
2223 const Handle(XSControl_WorkSession)& theWS,
2224 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
2228 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2229 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2230 const Interface_Graph& aGraph = aTP->Graph();
2231 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2232 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2233 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2234 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2235 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2236 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2238 if (!aSADR.IsNull())
2239 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2241 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2242 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2243 theSAs.Append(theSA);
2247 // Find all children Shape_Aspect
2248 Standard_Boolean isSimple = Standard_True;
2249 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2250 for (; anIter.More(); anIter.Next()) {
2251 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
2252 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2253 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2254 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2255 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
2256 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
2257 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2258 isSimple = Standard_False;
2262 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2264 theSAs.Append(theSA);
2268 //=======================================================================
2269 //function : getShapeLabel
2271 //=======================================================================
2273 static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
2274 const Handle(XSControl_WorkSession)& theWS,
2275 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
2278 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2279 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2280 TopoDS_Shape aShape;
2282 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2283 aShape = TransferBRep::ShapeResult(aBinder);
2285 if (aShape.IsNull())
2287 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2291 //=======================================================================
2292 //function : setDatumToXCAF
2294 //=======================================================================
2296 Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
2297 const TDF_Label theGDTL,
2298 const Standard_Integer thePositionCounter,
2299 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2300 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2301 const Standard_Real theModifValue,
2302 const Handle(TDocStd_Document)& theDoc,
2303 const Handle(XSControl_WorkSession)& theWS)
2305 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2306 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2307 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2308 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2309 const Interface_Graph& aGraph = aTP->Graph();
2310 Handle(XCAFDoc_Datum) aDat;
2311 TDF_LabelSequence aShapeLabels;
2312 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2314 // Collect all links to shapes
2315 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2316 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
2317 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2318 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2319 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2321 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2322 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2323 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2324 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2327 // Collect shape labels
2328 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2329 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2332 // Skip datum targets
2333 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2336 // Process all connected GISU
2337 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2338 for (; anIter.More(); anIter.Next()) {
2339 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2342 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2343 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2344 if (!aShapeL.IsNull())
2345 aShapeLabels.Append(aShapeL);
2350 // Process datum targets and create objects for them
2351 Standard_Boolean isExistDatumTarget = Standard_False;
2352 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2353 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2356 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
2357 XCAFDimTolObjects_DatumTargetType aType;
2358 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2360 aDatTargetObj->SetDatumTargetType(aType);
2361 Standard_Boolean isValidDT = Standard_False;
2363 // Feature for datum target
2364 TDF_LabelSequence aDTShapeLabels;
2365 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
2366 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
2367 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2368 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
2370 if (!aRelationship.IsNull()) {
2371 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2372 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2373 for (; aSAIter.More(); aSAIter.Next()) {
2374 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2377 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2378 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2379 if (!aShapeL.IsNull()) {
2380 aDTShapeLabels.Append(aShapeL);
2381 isValidDT = Standard_True;
2387 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2388 // Try another way of feature connection
2389 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2390 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
2393 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2394 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2395 if (!aShapeL.IsNull()) {
2396 aDTShapeLabels.Append(aShapeL);
2397 isValidDT = Standard_True;
2403 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2404 // Area datum target
2405 Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
2406 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2407 for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
2408 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
2410 Handle(StepRepr_RepresentationItem) anItem;
2411 if (aGISU->NbIdentifiedItem() > 0)
2412 anItem = aGISU->IdentifiedItemValue(1);
2413 if (anItem.IsNull())
2415 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2416 if (anItemIndex > 0) {
2417 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2418 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
2419 aDatTargetObj->SetDatumTarget(anItemShape);
2420 isValidDT = Standard_True;
2424 // Point/line/rectangle/circle datum targets
2425 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2426 Handle(StepRepr_PropertyDefinition) aPD;
2427 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2428 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2430 if (!aPD.IsNull()) {
2431 anIter = aGraph.Sharings(aPD);
2432 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2433 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2434 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2436 if (!aSDR.IsNull()) {
2437 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2438 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2439 if (!aSRWP.IsNull()) {
2440 isValidDT = Standard_True;
2441 // Collect parameters of datum target
2442 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
2444 if (aSRWP->ItemsValue(j).IsNull())
2446 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2448 Handle(StepGeom_Axis2Placement3d) anAx
2449 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
2450 XSAlgo::AlgoContainer()->PrepareForTransfer();
2451 STEPControl_ActorRead anActor;
2452 anActor.PrepareUnits(aSRWP, aTP);
2453 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
2454 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
2456 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
2458 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
2459 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
2460 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2461 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
2462 if (anUnit.IsNull())
2464 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2467 STEPConstruct_UnitContext anUnitCtx;
2468 anUnitCtx.ComputeFactors(aNU);
2469 aVal = aVal * anUnitCtx.LengthFactor();
2470 if (aM->Name()->String().IsEqual("target length") ||
2471 aM->Name()->String().IsEqual("target diameter"))
2472 aDatTargetObj->SetDatumTargetLength(aVal);
2474 aDatTargetObj->SetDatumTargetWidth(aVal);
2482 // Create datum target object
2484 TDF_Label aDatL = aDGTTool->AddDatum();
2485 myGDTMap.Bind(aDT, aDatL);
2486 aDGTTool->Lock(aDatL);
2487 aDat = XCAFDoc_Datum::Set(aDatL);
2488 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
2489 aDatTargetObj->SetName(theDat->Identification());
2490 aDatTargetObj->SetPosition(thePositionCounter);
2491 if (!theXCAFModifiers.IsEmpty())
2492 aDatTargetObj->SetModifiers(theXCAFModifiers);
2493 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2494 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2495 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2496 aDatTargetObj->IsDatumTarget(Standard_True);
2497 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2498 readAnnotation(aTR, aDT, aDatTargetObj);
2499 aDat->SetObject(aDatTargetObj);
2500 isExistDatumTarget = Standard_True;
2504 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2505 // Create object for datum
2506 TDF_Label aDatL = aDGTTool->AddDatum();
2507 myGDTMap.Bind(theDat, aDatL);
2508 // bind datum label with all reference datum_feature entities
2509 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2510 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2511 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2513 myGDTMap.Bind(aSA, aDatL);
2515 aDGTTool->Lock(aDatL);
2516 aDat = XCAFDoc_Datum::Set(aDatL);
2517 aDGTTool->SetDatum(aShapeLabels, aDatL);
2518 aDatObj->SetName(theDat->Identification());
2519 aDatObj->SetPosition(thePositionCounter);
2520 if (!theXCAFModifiers.IsEmpty())
2521 aDatObj->SetModifiers(theXCAFModifiers);
2522 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2523 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2524 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2525 if (aDatObj->GetPresentation().IsNull()) {
2526 // Try find annotation connected to datum entity (not right case, according recommended practices)
2527 readAnnotation(aTR, theDat, aDatObj);
2529 aDat->SetObject(aDatObj);
2532 return Standard_True;
2536 //=======================================================================
2537 //function : ReadDatums
2538 //purpose : auxilary
2539 //=======================================================================
2540 Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2541 const TDF_Label theGDTL,
2542 const Handle(TDocStd_Document)& theDoc,
2543 const Handle(XSControl_WorkSession)& theWS)
2545 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2546 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2547 const Interface_Graph& aGraph = aTP->Graph();
2549 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2550 for (anIter.Start(); anIter.More(); anIter.Next()) {
2551 Handle(Standard_Transient) anAtr = anIter.Value();
2552 if (anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2554 Standard_Integer aPositionCounter = 0;//position on frame
2555 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2556 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2557 for (anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2558 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2559 if (anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2562 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2563 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2564 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2566 Handle(StepGeom_Axis2Placement3d) anAx
2567 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2568 Handle(XCAFDoc_GeomTolerance) aTol;
2569 if (theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2571 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2572 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2573 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2574 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2578 if (!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2579 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2580 !aLocArr.IsNull() && aLocArr->Length() > 2)
2582 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
2583 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower() + 1, aDirRArr->Lower() + 2);
2584 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower() + 1, aLocArr->Lower() + 2);
2585 gp_Ax2 anA(aPnt, aDir, aDirR);
2586 anObj->SetAxis(anA);
2587 aTol->SetObject(anObj);
2593 if (aDS->NbConstituents() > 0)
2595 //get datum feature and datum target from datum system
2596 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2597 if (!aDRCA.IsNull())
2599 for (Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2601 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
2603 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2604 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2605 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2606 Standard_Real aModifValue = 0;
2607 if (!aModif.IsNull())
2609 for (Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2611 if (aModif->Value(m).CaseNumber() == 2)
2612 aXCAFModifiers.Append(
2613 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2614 SimpleDatumReferenceModifierMember()->Value());
2615 else if (aModif->Value(m).CaseNumber() == 1)
2617 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2618 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2619 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2620 if (anUnit.IsNull()) continue;
2621 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2622 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2623 STEPConstruct_UnitContext anUnitCtx;
2624 anUnitCtx.ComputeFactors(NU);
2625 aModifValue = aVal * anUnitCtx.LengthFactor();
2630 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2631 for (anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2633 if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2635 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2636 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2638 else if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2640 Handle(StepDimTol_DatumReferenceElement) aDRE
2641 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2642 //get modifiers from group of datums
2643 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2644 if (!aModifE.IsNull())
2646 for (Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2648 if (aModifE->Value(k).CaseNumber() == 2)
2649 aXCAFModifiers.Append(
2650 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2651 SimpleDatumReferenceModifierMember()->Value());
2652 else if (aModifE->Value(k).CaseNumber() == 1)
2654 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2655 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2656 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2657 if (anUnit.IsNull()) continue;
2658 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2659 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2660 STEPConstruct_UnitContext anUnitCtx;
2661 anUnitCtx.ComputeFactors(NU);
2662 aModifValue = aVal * anUnitCtx.LengthFactor();
2666 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2667 for (anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2668 if (anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2670 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2671 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2681 return Standard_True;
2684 //=======================================================================
2685 //function : createGeomTolObjectInXCAF
2687 //=======================================================================
2688 TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2689 const Handle(TDocStd_Document)& theDoc,
2690 const Handle(XSControl_WorkSession)& theWS)
2693 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2694 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2695 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2700 Handle(TCollection_HAsciiString) aSemanticName;
2702 // protection against invalid input
2703 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2704 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2705 if (aGeomTol->TolerancedShapeAspect().IsNull())
2707 aSemanticName = aGeomTol->Name();
2709 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2710 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2711 if (aDim->AppliesTo().IsNull())
2713 aSemanticName = aDim->Name();
2715 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2716 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2717 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2719 aSemanticName = aDim->Name();
2722 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2723 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2724 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2725 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2726 const Interface_Graph& aGraph = aTP->Graph();
2727 Standard_Boolean isAllAround = Standard_False;
2728 Standard_Boolean isAllOver = Standard_False;
2730 // find RepresentationItem for current Ent
2731 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2733 // Collect all Shape_Aspect entities
2734 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2735 for (anIter.Start(); anIter.More(); anIter.Next()) {
2736 Handle(Standard_Transient) anAtr = anIter.Value();
2737 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2738 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2740 //if associating tolerances with part (All-Over)
2741 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2742 for (anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2744 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2745 if (anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2747 isAllOver = Standard_True;
2748 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2749 for (anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2751 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2752 if (anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2754 aSeqRI1.Append(anAtrABSR);
2760 else if (anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2761 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2763 //if tolerance attached to dimension
2764 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2765 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2767 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
2768 if (!aSA.IsNull()) {
2769 collectShapeAspect(aSA, theWS, aSAs);
2773 else if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2775 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2777 // if applyed AllAround Modifier
2778 isAllAround = Standard_True;
2780 // dimensions and default tolerances
2781 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
2782 if (!aSA.IsNull()) {
2783 collectShapeAspect(aSA, theWS, aSAs);
2787 // Collect all representation items
2788 if (!aSAs.IsEmpty())
2790 //get representation items
2791 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2792 for (Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2794 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2795 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2796 Handle(StepRepr_PropertyDefinition) PropD;
2797 for (anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2798 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2799 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2801 if (!PropD.IsNull())//for old version
2803 Handle(StepRepr_RepresentationItem) RI;
2804 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2805 for (subs4.Start(); subs4.More(); subs4.Next()) {
2806 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2807 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2808 if (!SDR.IsNull()) {
2809 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2810 if (!Repr.IsNull() && Repr->NbItems() > 0) {
2811 RI = Repr->ItemsValue(1);
2815 if (RI.IsNull()) continue;
2817 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2819 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2820 if (EC.IsNull()) continue;
2821 Handle(TCollection_HAsciiString) aName;
2822 Handle(StepShape_DimensionalSize) DimSize =
2823 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2824 Standard_Real dim1 = -1., dim2 = -1.;
2825 subs4 = aGraph.Sharings(DimSize);
2826 for (subs4.Start(); subs4.More(); subs4.Next()) {
2827 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2828 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2829 if (!DimCharR.IsNull()) {
2830 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2831 if (!SDimR.IsNull() && SDimR->NbItems() > 0) {
2832 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2833 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
2836 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2837 //if(CID.IsNull()) continue;
2838 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2839 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2840 //if(CIDM.IsNull()) continue;
2841 //if(CIDM->ArrTransient().IsNull()) continue;
2842 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2843 //if(CID.CaseMem(CIDM)==1)
2844 // HARI = CID.ListRepresentationItem();
2845 //if(CID.CaseMem(CIDM)==2)
2846 // HARI = CID.SetRepresentationItem();
2847 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2848 if (HARI.IsNull()) continue;
2849 if (HARI->Length() > 0) {
2850 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
2851 if (RI1.IsNull()) continue;
2852 if (RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2853 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2854 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2855 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2856 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2857 if (anUnit.IsNull()) continue;
2858 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2859 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2860 STEPConstruct_UnitContext anUnitCtx;
2861 anUnitCtx.ComputeFactors(NU);
2862 dim1 = dim1 * anUnitCtx.LengthFactor();
2865 if (HARI->Length() > 1) {
2866 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
2867 if (RI2.IsNull()) continue;
2868 if (RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2869 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2870 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2871 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2872 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2873 if (anUnit.IsNull()) continue;
2874 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2875 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2876 STEPConstruct_UnitContext anUnitCtx;
2877 anUnitCtx.ComputeFactors(NU);
2878 dim2 = dim2 * anUnitCtx.LengthFactor();
2885 if (dim1 < 0) continue;
2886 if (dim2 < 0) dim2 = dim1;
2887 //std::cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<std::endl;
2888 // now we know edge_curve and value range therefore
2889 // we can create corresponding D> labels
2890 Standard_Integer index = aTP->MapIndex(EC);
2893 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2894 aSh = TransferBRep::ShapeResult(binder);
2896 if (aSh.IsNull()) continue;
2898 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2899 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 2);
2900 arr->SetValue(1, dim1);
2901 arr->SetValue(2, dim2);
2902 aDGTTool->SetDimTol(shL, 1, arr, aName, DimSize->Name());
2904 // read tolerances and datums
2905 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2906 Handle(StepDimTol_GeometricTolerance) GT =
2907 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2908 // read common data for tolerance
2909 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2910 Handle(StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2911 if (dim3.IsNull()) continue;
2912 Standard_Real dim = dim3->ValueComponent();
2913 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2914 if (anUnit.IsNull()) continue;
2915 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2916 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2917 STEPConstruct_UnitContext anUnitCtx;
2918 anUnitCtx.ComputeFactors(NU);
2919 dim = dim * anUnitCtx.LengthFactor();
2920 //std::cout<<"GeometricTolerance: Magnitude = "<<dim<<std::endl;
2921 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 1);
2922 arr->SetValue(1, dim);
2923 Handle(TCollection_HAsciiString) aName = GT->Name();
2924 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2925 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2926 if (AF.IsNull()) continue;
2927 Standard_Integer index = aTP->MapIndex(AF);
2930 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2931 aSh = TransferBRep::ShapeResult(binder);
2933 if (aSh.IsNull()) continue;
2935 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2936 // read specific data for tolerance
2937 if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2938 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2939 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2940 Standard_Integer kind = 20;
2941 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2942 GTComplex->GetModifiedGeometricTolerance();
2943 if (!MGT.IsNull()) {
2944 kind = kind + MGT->Modifier() + 1;
2946 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2947 // translate datums connected with this tolerance
2948 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2949 GTComplex->GetGeometricToleranceWithDatumReference();
2950 if (!GTWDR.IsNull()) {
2951 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
2954 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2955 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2956 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2957 if (GTWDR.IsNull()) continue;
2958 Standard_Integer kind = 0;
2959 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2960 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2961 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2962 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
2963 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
2964 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
2965 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
2966 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
2967 //std::cout<<"GTWDR: kind="<<kind<<std::endl;
2968 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2969 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
2971 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
2972 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2973 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
2974 Standard_Integer kind = 35 + MGT->Modifier();
2975 aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2977 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
2978 aDGTTool->SetDimTol(shL, 38, arr, aName, aDescription);
2980 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
2981 aDGTTool->SetDimTol(shL, 39, arr, aName, aDescription);
2983 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
2984 aDGTTool->SetDimTol(shL, 40, arr, aName, aDescription);
2986 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
2987 aDGTTool->SetDimTol(shL, 41, arr, aName, aDescription);
2989 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
2990 aDGTTool->SetDimTol(shL, 42, arr, aName, aDescription);
2992 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
2993 aDGTTool->SetDimTol(shL, 43, arr, aName, aDescription);
2995 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
2996 aDGTTool->SetDimTol(shL, 44, arr, aName, aDescription);
3002 if (aGISU.IsNull()) continue;
3003 Standard_Integer j = 1;
3004 for (; j <= aGISU->NbIdentifiedItem(); j++) {
3005 aSeqRI.Append(aGISU->IdentifiedItemValue(j));
3009 if (!aSeqRI.IsEmpty())
3011 if (aSeqRI1.IsEmpty())
3018 if (aSeqRI1.IsEmpty())
3021 TDF_LabelSequence aShLS1, aShLS2;
3024 for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper();i++)
3026 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
3029 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3030 aSh = TransferBRep::ShapeResult(aBinder);
3035 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3036 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3038 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3042 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3043 if (!edgeL.IsNull())
3044 aShLS1.Append(edgeL);
3049 aShLS1.Append(aShL);
3052 if (!aSeqRI2.IsEmpty())
3054 //for dimensional location
3055 for (Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper();i++)
3057 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
3060 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3061 aSh = TransferBRep::ShapeResult(aBinder);
3066 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3067 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3069 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3073 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3074 if (!edgeL.IsNull())
3075 aShLS2.Append(edgeL);
3080 aShLS2.Append(aShL);
3085 if (!aShLS1.IsEmpty())
3088 if (!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3090 aGDTL = aDGTTool->AddDimension();
3091 myGDTMap.Bind(theEnt, aGDTL);
3092 aDGTTool->Lock(aGDTL);
3093 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3094 TCollection_AsciiString aStr("DGT:Dimensional_");
3095 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
3097 aStr.AssignCat("Size");
3099 else if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3101 aStr.AssignCat("Location");
3103 TDataStd_Name::Set(aGDTL, aStr);
3105 if (!aShLS2.IsEmpty())
3107 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
3111 TDF_LabelSequence aEmptySeq;
3112 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
3117 aGDTL = aDGTTool->AddGeomTolerance();
3118 myGDTMap.Bind(theEnt, aGDTL);
3119 aDGTTool->Lock(aGDTL);
3120 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
3121 TCollection_AsciiString aStr("DGT:GeomTolerance");
3122 TDataStd_Name::Set(aGDTL, aStr);
3123 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
3124 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
3126 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
3128 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
3129 aGTol->SetObject(anObj);
3134 TCollection_ExtendedString str(aSemanticName->String());
3135 TDataStd_Name::Set(aGDTL, str);
3138 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
3143 //=======================================================================
3144 //function : convertAngleValue
3145 //purpose : auxilary
3146 //=======================================================================
3147 void convertAngleValue(
3148 const STEPConstruct_UnitContext& anUnitCtx,
3149 Standard_Real& aVal)
3151 // convert radian to deg
3152 Standard_Real aFact = anUnitCtx.PlaneAngleFactor() * 180 / M_PI;
3153 // in order to avoid inaccuracy of calculation perform conversion
3154 // only if aFact not eqaul 1 with some precision
3155 if (fabs(1. - aFact) > Precision::Confusion())
3157 aVal = aVal * aFact;
3162 //=======================================================================
3163 //function : setDimObjectToXCAF
3165 //=======================================================================
3166 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3167 const TDF_Label& aDimL,
3168 const Handle(TDocStd_Document)& theDoc,
3169 const Handle(XSControl_WorkSession)& theWS)
3171 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3172 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3173 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3174 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3175 const Interface_Graph& aGraph = aTP->Graph();
3176 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
3177 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
3178 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3181 Handle(StepShape_DimensionalSize) aDimSize =
3182 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3183 Handle(StepShape_DimensionalLocation) aDimLocation =
3184 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
3186 aDimObj = new XCAFDimTolObjects_DimensionObject();
3187 Standard_Real aDim1 = -1., aDim2 = -1., aDim3 = -1.;
3188 Standard_Boolean isPlusMinusTolerance = Standard_False;
3189 Handle(StepShape_TypeQualifier) aTQ;
3190 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
3191 Handle(StepShape_ToleranceValue) aTV;
3192 Handle(StepShape_LimitsAndFits) aLAF;
3193 Handle(StepRepr_CompoundRepresentationItem) aCRI;
3194 Handle(StepGeom_Axis2Placement3d) anAP;
3196 Interface_EntityIterator anIterDim;
3197 if (!aDimSize.IsNull())
3199 anIterDim = aGraph.Sharings(aDimSize);
3203 anIterDim = aGraph.Sharings(aDimLocation);
3205 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
3206 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
3207 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
3208 Handle(StepShape_PlusMinusTolerance) aPMT =
3209 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
3210 if (!aDCR.IsNull()) {
3211 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
3212 if (!aSDR.IsNull()) {
3213 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
3215 if (!aHARI.IsNull())
3217 for (Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
3219 Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
3220 if (aDRI.IsNull()) continue;
3222 if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
3223 // simple value / range
3224 Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
3225 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
3226 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3227 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3228 if (anUnit.IsNull())
3230 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3232 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3233 STEPConstruct_UnitContext anUnitCtx;
3234 anUnitCtx.ComputeFactors(NU);
3235 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3236 aVal = aVal * anUnitCtx.LengthFactor();
3240 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
3241 convertAngleValue(anUnitCtx, aVal);
3243 Handle(TCollection_HAsciiString) aName = aMWU->Name();
3244 if (aName->Search("upper") > 0) // upper limit
3246 else // lower limit or simple nominal value
3249 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
3250 // value with qualifier (minimum/maximum/average)
3251 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
3252 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
3253 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3254 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3255 if (anUnit.IsNull())
3257 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3259 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3260 STEPConstruct_UnitContext anUnitCtx;
3261 anUnitCtx.ComputeFactors(NU);
3262 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
3263 aVal = aVal * anUnitCtx.LengthFactor();
3266 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
3267 convertAngleValue(anUnitCtx, aVal);
3269 Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
3270 if (aQRI->Qualifiers()->Length() == 0) {
3274 Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
3275 if (aValueType->Name()->String().IsEqual("minimum"))
3277 else if (aValueType->Name()->String().IsEqual("maximum"))
3281 else if (aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
3283 Handle(StepShape_QualifiedRepresentationItem) aQRI =
3284 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
3285 for (Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
3287 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
3288 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
3291 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3292 Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
3293 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
3294 aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
3296 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
3297 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
3299 else if (aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
3301 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
3307 else if (!aPMT.IsNull())
3309 isPlusMinusTolerance = Standard_True;
3310 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
3311 if (aPMT.IsNull()) continue;
3312 if (aTMD.CaseNumber() == 1)
3313 //! 1 -> ToleranceValue from StepShape
3314 //! 2 -> LimitsAndFits from StepShape
3316 //plus minus tolerance
3317 aTV = aTMD.ToleranceValue();
3318 if (aTV.IsNull()) continue;
3320 Handle(Standard_Transient) aUpperBound = aTV->UpperBound();
3321 if(aUpperBound.IsNull())
3323 Handle(StepBasic_MeasureWithUnit) aMWU;
3324 if(aUpperBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
3325 aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aUpperBound);
3326 else if(aUpperBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
3328 Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem =
3329 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUpperBound);
3330 aMWU = aReprMeasureItem->GetMeasureWithUnit();
3335 Standard_Real aVal = aMWU->ValueComponent();
3336 StepBasic_Unit anUnit = aMWU->UnitComponent();
3337 if (anUnit.IsNull()) continue;
3338 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3339 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3340 STEPConstruct_UnitContext anUnitCtx;
3341 anUnitCtx.ComputeFactors(NU);
3342 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3343 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3345 aVal = aVal * anUnitCtx.LengthFactor();
3347 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3348 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3350 convertAngleValue(anUnitCtx, aVal);
3355 Handle(Standard_Transient) aLowerBound = aTV->LowerBound();
3356 if(aLowerBound.IsNull())
3359 if(aLowerBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
3360 aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aLowerBound);
3361 else if(aLowerBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
3363 Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem =
3364 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aLowerBound);
3365 aMWU = aReprMeasureItem->GetMeasureWithUnit();
3371 aVal = aMWU->ValueComponent();
3372 anUnit = aMWU->UnitComponent();
3373 if (anUnit.IsNull()) continue;
3374 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3375 NU = anUnit.NamedUnit();
3376 anUnitCtx.ComputeFactors(NU);
3377 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3378 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3380 aVal = aVal * anUnitCtx.LengthFactor();
3382 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3383 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3385 convertAngleValue(anUnitCtx, aVal);
3391 // class of tolerance
3392 aLAF = aTMD.LimitsAndFits();
3397 if (aDim1 < 0) return;
3400 aDimObj->SetValue(aDim1);
3403 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 2);
3404 anArr->SetValue(1, aDim1);
3405 anArr->SetValue(2, aDim2);
3406 aDimObj->SetValues(anArr);
3410 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 3);
3411 if (!isPlusMinusTolerance)
3413 aDim2 = aDim1 - aDim2;
3414 aDim3 = aDim3 - aDim1;
3416 anArr->SetValue(1, aDim1);
3417 anArr->SetValue(2, aDim2);
3418 anArr->SetValue(3, aDim3);
3419 aDimObj->SetValues(anArr);
3423 XCAFDimTolObjects_DimensionQualifier aQ;
3424 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
3426 aDimObj->SetQualifier(aQ);
3430 if (!aVFTQ.IsNull())
3432 //A typical value would be 'NR2 2.2'
3433 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
3434 Standard_Integer i = aFormat.Location(1, ' ', 1, aFormat.Length());
3435 aFormat.SubString(i + 1, i + 1)->IntegerValue();
3436 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i + 1, i + 1)->IntegerValue(),
3437 aFormat.SubString(i + 3, i + 3)->IntegerValue());
3442 //get class of tolerance
3443 Standard_Boolean aHolle = Standard_False;
3444 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
3445 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
3446 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
3447 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
3450 if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0)
3453 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
3454 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
3455 if (aModifiers.Length() > 0)
3456 aDimObj->SetModifiers(aModifiers);
3459 Handle(TCollection_HAsciiString) aName;
3460 if (!aDimSize.IsNull())
3462 aName = aDimSize->Name();
3466 aName = aDimLocation->Name();
3468 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
3469 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
3471 if (!aDimSize.IsNull())
3473 Handle(StepShape_AngularSize) anAngSize =
3474 Handle(StepShape_AngularSize)::DownCast(aDimSize);
3475 if (!anAngSize.IsNull())
3477 //get qualifier for angular value
3478 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
3479 if (anAngSize->AngleSelection() == StepShape_Equal)
3480 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3481 else if (anAngSize->AngleSelection() == StepShape_Large)
3482 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3483 else if (anAngSize->AngleSelection() == StepShape_Small)
3484 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3489 Handle(StepShape_AngularLocation) anAngLoc =
3490 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
3491 if (!anAngLoc.IsNull())
3493 //get qualifier for angular value
3494 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
3495 if (anAngLoc->AngleSelection() == StepShape_Equal)
3496 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3497 else if (anAngLoc->AngleSelection() == StepShape_Large)
3498 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3499 else if (anAngLoc->AngleSelection() == StepShape_Small)
3500 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3503 if (aType == XCAFDimTolObjects_DimensionType_Location_None)
3505 Handle(StepRepr_ShapeAspect) aPSA;
3506 if (!aDimSize.IsNull())
3508 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath =
3509 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
3510 if (!aDimSizeWithPath.IsNull())
3512 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
3513 aPSA = aDimSizeWithPath->Path();
3518 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath =
3519 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
3520 if (!aDimLocWithPath.IsNull())
3522 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
3523 aPSA = aDimLocWithPath->Path();
3529 //for DimensionalLocationWithPath
3530 Handle(StepGeom_GeometricRepresentationItem) aGRI;
3531 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
3532 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
3533 for (anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
3534 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
3536 if (aPGISU.IsNull()) return;
3537 if (aPGISU->NbIdentifiedItem() > 0) {
3538 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
3540 if (aGRI.IsNull()) return;
3541 Handle(StepRepr_RepresentationItem) aPRI;
3542 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
3543 for (anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
3544 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
3546 Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
3549 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3550 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
3552 if (aSh.IsNull()) return;
3553 aDimObj->SetPath(aSh);
3555 else if (!anAP.IsNull())
3557 if (anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
3559 //for Oriented Dimensional Location
3560 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
3562 if (!aDirArr.IsNull() && aDirArr->Length() > 2)
3564 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
3565 aDimObj->SetDirection(aDir);
3567 else if (aDirArr->Length() > 1)
3569 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, 0);
3570 aDimObj->SetDirection(aDir);
3576 aDimObj->SetType(aType);
3579 if (!aDimObj.IsNull())
3582 Handle(XCAFDoc_Dimension) aDim;
3584 if (aDimL.FindAttribute(XCAFDoc_Dimension::GetID(), aDim))
3586 readAnnotation(aTR, theEnt, aDimObj);
3587 readConnectionPoints(aTR, theEnt, aDimObj);
3588 aDim->SetObject(aDimObj);
3593 //=======================================================================
3594 //function : getTolType
3596 //=======================================================================
3597 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
3598 XCAFDimTolObjects_GeomToleranceType& theType)
3600 if (theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3601 return Standard_False;
3602 theType = XCAFDimTolObjects_GeomToleranceType_None;
3603 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
3605 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
3606 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3608 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3610 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
3611 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
3612 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3614 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3616 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
3617 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
3618 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3620 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3622 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
3623 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
3624 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3626 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3628 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
3629 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
3630 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3632 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3634 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3635 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3636 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3638 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3640 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3642 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3644 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3646 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3648 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3650 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3652 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3654 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3656 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3658 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3660 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3662 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3664 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3666 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3668 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3670 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3672 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3674 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3675 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3677 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3679 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3681 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3683 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3685 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3687 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3689 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3691 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3693 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3695 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3697 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3699 return Standard_True;
3701 //=======================================================================
3702 //function : setGeomTolObjectToXCAF
3704 //=======================================================================
3705 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3706 const TDF_Label& theTolL,
3707 const Handle(TDocStd_Document)& theDoc,
3708 const Handle(XSControl_WorkSession)& theWS)
3710 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3711 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3712 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3713 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3714 const Interface_Graph& aGraph = aTP->Graph();
3715 Handle(XCAFDoc_GeomTolerance) aGTol;
3716 if (!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3720 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3721 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3723 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3724 getTolType(theEnt, aType);
3725 aTolObj->SetType(aType);
3726 if (!aTolEnt->Magnitude().IsNull()) {
3728 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3729 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3730 if (anUnit.IsNull()) return;
3731 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3732 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3733 STEPConstruct_UnitContext anUnitCtx;
3734 anUnitCtx.ComputeFactors(NU);
3735 aVal = aVal * anUnitCtx.LengthFactor();
3736 aTolObj->SetValue(aVal);
3739 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3740 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3741 for (anIter.Start(); anIter.More(); anIter.Next()) {
3742 if (anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))) {
3743 Handle(StepDimTol_ToleranceZoneForm) aForm
3744 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3745 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3746 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3747 for (anIt.Start(); anIt.More(); anIt.Next()) {
3748 if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))) {
3749 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3750 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3751 if (!aPZone->ProjectionLength().IsNull())
3753 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3754 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3755 if (anUnit.IsNull()) return;
3756 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3757 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3758 STEPConstruct_UnitContext anUnitCtx;
3759 anUnitCtx.ComputeFactors(NU);
3760 aVal = aVal * anUnitCtx.LengthFactor();
3761 aTolObj->SetValueOfZoneModifier(aVal);
3762 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3765 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3767 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3768 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3769 if (!aRZone->Orientation().IsNull())
3771 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3772 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3773 if (anUnit.IsNull()) continue;
3774 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3775 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3776 STEPConstruct_UnitContext anUnitCtx;
3777 anUnitCtx.ComputeFactors(NU);
3778 convertAngleValue(anUnitCtx, aVal);
3779 aTolObj->SetValueOfZoneModifier(aVal);
3780 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
3784 aTolObj->SetTypeOfValue(aTypeV);
3787 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
3788 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
3790 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
3792 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3794 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
3795 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3797 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3799 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
3800 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3802 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3804 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
3805 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3807 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3809 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
3810 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3812 if (!aModifiers.IsNull())
3814 for (Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
3816 if (aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
3817 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
3818 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
3819 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
3821 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
3824 Standard_Real aVal = 0;
3825 StepBasic_Unit anUnit;
3826 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
3828 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
3829 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
3830 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
3832 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3834 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
3835 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3836 aVal = aMax->GetMaxTolerance()->ValueComponent();
3837 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3839 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3841 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
3842 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3843 aVal = aMax->GetMaxTolerance()->ValueComponent();
3844 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3846 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
3848 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3849 STEPConstruct_UnitContext anUnitCtx;
3850 anUnitCtx.ComputeFactors(NU);
3851 convertAngleValue(anUnitCtx, aVal);
3852 aTolObj->SetMaxValueModifier(aVal);
3855 readAnnotation(aTR, theEnt, aTolObj);
3856 aGTol->SetObject(aTolObj);
3859 //=======================================================================
3860 //function : ReadGDTs
3862 //=======================================================================
3864 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
3865 Handle(TDocStd_Document)& theDoc)
3867 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
3868 const Interface_Graph& aGraph = theWS->Graph();
3869 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3870 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
3871 Interface_EntityIterator anI = aSM->Header();
3872 Handle(HeaderSection_FileSchema) aH;
3873 for (anI.Start(); anI.More() && aH.IsNull();anI.Next())
3874 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
3875 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3876 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3877 if (aDGTTool.IsNull()) return Standard_False;
3879 Standard_Integer nb = aModel->NbEntities();
3880 for (Standard_Integer i = 1; i <= nb; i++) {
3881 Handle(Standard_Transient) anEnt = aModel->Value(i);
3882 if (anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3883 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3884 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3885 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt, theDoc, theWS);
3886 if (!aGDTL.IsNull()) {
3887 if (anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3888 setGeomTolObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
3891 setDimObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
3895 else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
3896 anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
3898 // Protection against import presentation twice
3899 Handle(StepVisual_DraughtingCallout) aDC;
3900 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
3901 aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
3905 // Read presentations for PMIs without semantic data.
3906 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
3907 TDF_LabelSequence aShapesL;
3908 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
3909 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
3911 if (!aDMIA.IsNull()) {
3912 // Check entity, skip all, attached to GDTs
3913 Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
3914 if (!aDefinition.IsNull()) {
3915 Standard_Boolean isConnectedToGDT = Standard_False;
3916 // Skip if definition is a datum
3917 if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3918 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3919 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3920 aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3921 isConnectedToGDT = Standard_True;
3923 // Skip if any GDT is applied to definition
3924 for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
3925 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3926 anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3927 anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3928 isConnectedToGDT = Standard_True;
3931 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
3932 if (!aSAR.IsNull()) {
3933 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
3934 if (!aSA.IsNull()) {
3935 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3936 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3937 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3938 aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3939 isConnectedToGDT = Standard_True;
3941 for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
3942 if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3943 aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3944 aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3945 isConnectedToGDT = Standard_True;
3952 if (isConnectedToGDT)
3955 else if (aDMIA->Definition().PropertyDefinition().IsNull())
3959 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
3960 collectShapeAspect(aDefinition, theWS, aSAs);
3961 for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
3962 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
3963 for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
3964 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
3967 for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
3968 TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
3969 if (!aLabel.IsNull())
3970 aShapesL.Append(aLabel);
3974 Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
3977 Standard_Real aFact = 1.0;
3978 if (!aDMIA.IsNull())
3980 XSAlgo::AlgoContainer()->PrepareForTransfer();
3981 STEPControl_ActorRead anActor;
3982 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
3983 anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP);
3984 aFact = UnitsMethods::LengthFactor();
3988 TopoDS_Shape aPresentation;
3989 Handle(TCollection_HAsciiString) aPresentName;
3991 if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
3994 Handle(StepVisual_AnnotationPlane) anAnPlane;
3995 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
3996 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
3998 // Set object to XCAF
3999 TDF_Label aGDTL = aDGTTool->AddDimension();
4000 myGDTMap.Bind(anEnt, aGDTL);
4001 aDGTTool->Lock(aGDTL);
4002 Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
4003 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
4004 TCollection_AsciiString aStr("DGT:");
4005 if (isCommonLabel) {
4006 aStr.AssignCat("Common_label");
4007 aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
4010 aStr.AssignCat("Dimension");
4011 aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
4013 TDataStd_Name::Set(aGDTL, aStr);
4014 TDF_LabelSequence anEmptySeq2;
4015 aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
4017 if (!anAnPlane.IsNull()) {
4018 if (readAnnotationPlane(anAnPlane, aPlaneAxes))
4019 aDimObj->SetPlane(aPlaneAxes);
4021 aDimObj->SetPresentation(aPresentation, aPresentName);
4022 aDim->SetObject(aDimObj);
4025 return Standard_True;
4029 //=======================================================================
4030 //function : FindSolidForPDS
4031 //purpose : auxilary
4032 //=======================================================================
4034 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
4035 const Interface_Graph &graph)
4037 Handle(StepShape_SolidModel) SM;
4038 Interface_EntityIterator subs = graph.Sharings(PDS);
4039 Handle(StepShape_ShapeRepresentation) SR;
4040 for (subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
4041 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
4042 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
4043 if (SDR.IsNull()) continue;
4044 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
4045 if (SR.IsNull()) continue;
4046 for (Standard_Integer i = 1; i <= SR->NbItems() && SM.IsNull(); i++) {
4047 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
4050 Interface_EntityIterator subs1 = graph.Sharings(SR);
4051 for (subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
4052 Handle(StepRepr_RepresentationRelationship) RR =
4053 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
4054 if (RR.IsNull()) continue;
4055 Handle(StepShape_ShapeRepresentation) SR2;
4056 if (RR->Rep1() == SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
4057 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
4058 if (SR2.IsNull()) continue;
4059 for (Standard_Integer i2 = 1; i2 <= SR2->NbItems() && SM.IsNull(); i2++) {
4060 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
4069 //=======================================================================
4070 //function : ReadMaterials
4072 //=======================================================================
4074 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
4075 Handle(TDocStd_Document)& Doc,
4076 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
4078 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
4079 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
4080 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
4081 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool(Doc->Main());
4082 if (MatTool.IsNull()) return Standard_False;
4084 const Interface_Graph& graph = TP->Graph();
4085 for (Standard_Integer i = 1; i <= SeqPDS->Length(); i++) {
4086 Handle(StepRepr_ProductDefinitionShape) PDS =
4087 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
4090 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
4091 if (aProdDef.IsNull())
4093 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
4094 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
4095 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
4096 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
4097 Standard_Real aDensity = 0;
4098 Interface_EntityIterator subs = graph.Sharings(aProdDef);
4099 for (subs.Start(); subs.More(); subs.Next()) {
4100 Handle(StepRepr_PropertyDefinition) PropD =
4101 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
4102 if (PropD.IsNull()) continue;
4103 Interface_EntityIterator subs1 = graph.Sharings(PropD);
4104 for (subs1.Start(); subs1.More(); subs1.Next()) {
4105 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
4106 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
4107 if (PDR.IsNull()) continue;
4108 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
4109 if (Repr.IsNull()) continue;
4110 Standard_Integer ir;
4111 for (ir = 1; ir <= Repr->NbItems(); ir++) {
4112 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
4113 if (RI.IsNull()) continue;
4114 if (RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
4115 // find name and description for material
4116 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
4117 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
4118 aName = DRI->Name();
4120 aDescription = DRI->Description();
4122 aName = aDescription;
4124 if (RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
4125 // try to find density for material
4126 Handle(StepRepr_MeasureRepresentationItem) MRI =
4127 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
4128 aDensity = MRI->Measure()->ValueComponent();
4129 aDensName = MRI->Name();
4130 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
4131 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
4132 if (!aUnit.IsNull()) {
4133 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
4134 if (DU.IsNull()) continue;
4135 for (Standard_Integer idu = 1; idu <= DU->NbElements(); idu++) {
4136 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
4137 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
4138 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ||
4139 NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)))
4141 STEPConstruct_UnitContext anUnitCtx;
4142 anUnitCtx.ComputeFactors(NU);
4143 aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor());
4144 // transfer length value for Density from millimeter to santimeter
4145 // in order to result density has dimension gram/(sm*sm*sm)
4146 aDensity = aDensity*1000. / (UnitsMethods::GetCasCadeLengthUnit()
4147 * UnitsMethods::GetCasCadeLengthUnit() * UnitsMethods::GetCasCadeLengthUnit());
4149 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
4150 Standard_Real afact = 1.;
4151 if (GetMassConversionFactor(NU, afact))
4153 aDensity = aDensity*afact;
4163 if (aName.IsNull() || aName->Length() == 0)
4165 // find shape label amd create Material link
4167 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS, graph);
4169 Standard_Integer index = TP->MapIndex(SM);
4171 Handle(Transfer_Binder) binder = TP->MapItem(index);
4172 if (!binder.IsNull())
4173 aSh = TransferBRep::ShapeResult(binder);
4176 if (aSh.IsNull()) continue;
4178 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
4179 MatTool->SetMaterial(shL, aName, aDescription, aDensity, aDensName, aDensValType);
4182 return Standard_True;
4185 //=======================================================================
4186 //function : collectViewShapes
4187 //purpose : collect all labels of representations in given representation
4188 //=======================================================================
4190 void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
4191 const Handle(TDocStd_Document)& theDoc,
4192 const Handle(StepRepr_Representation) theRepr,
4193 TDF_LabelSequence& theShapes)
4195 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4196 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4197 const Interface_Graph& aGraph = aTP->Graph();
4198 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4199 Standard_Integer anIndex = aTP->MapIndex(theRepr);
4202 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
4203 aSh = TransferBRep::ShapeResult(aBinder);
4205 if (!aSh.IsNull()) {
4207 aSTool->FindShape(aSh, aShL);
4209 theShapes.Append(aShL);
4211 Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
4212 for (; anIter.More(); anIter.Next()) {
4213 if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
4215 Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
4216 if (!aReprRelationship->Rep1().IsNull() && aReprRelationship->Rep1() != theRepr)
4217 collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
4221 //=======================================================================
4222 //function : buildClippingPlanes
4224 //=======================================================================
4225 Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
4226 TDF_LabelSequence& theClippingPlanes,
4227 const Handle(XCAFDoc_ClippingPlaneTool) theTool)
4229 Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
4230 NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
4231 Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
4234 if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
4235 Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
4236 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
4238 if (aCameraModel->ShapeClipping().IsNull())
4239 return anExpression;
4241 // Root of clipping planes tree
4242 if (aCameraModel->ShapeClipping()->Length() == 1) {
4243 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
4244 aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
4245 if (!aCameraModelUnion.IsNull())
4246 return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
4248 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4249 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4252 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
4253 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
4254 Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
4255 anOperation = new TCollection_HAsciiString("+");
4256 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4257 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4260 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
4261 Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
4262 Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
4263 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4264 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4268 anExpression->AssignCat("(");
4269 for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
4270 Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
4271 if (!aPlaneEnt.IsNull()) {
4272 Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
4273 if (!aPlane.IsNull()) {
4274 TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
4275 theClippingPlanes.Append(aPlaneL);
4276 TCollection_AsciiString anEntry;
4277 TDF_Tool::Entry(aPlaneL, anEntry);
4278 anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
4282 anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
4284 anExpression->AssignCat(anOperation);
4286 // Insert brace instead of operation after last operand.
4287 anExpression->SetValue(anExpression->Length(), ')');
4288 return anExpression;
4292 //=======================================================================
4293 //function : ReadViews
4295 //=======================================================================
4296 Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
4298 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4299 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4300 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4301 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
4302 if (aDGTTool.IsNull()) return Standard_False;
4304 Standard_Integer nb = aModel->NbEntities();
4305 for (Standard_Integer i = 1; i <= nb; i++) {
4306 Handle(Standard_Transient) anEnt = aModel->Value(i);
4307 if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
4309 Handle(XCAFView_Object) anObj = new XCAFView_Object();
4310 // Import attributes of view
4311 Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
4313 const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader();
4314 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4315 const Interface_Graph& aGraph = aTP->Graph();
4316 // find the proper DraughtingModel
4317 Interface_EntityIterator subs = aGraph.Sharings(aCameraModel);
4318 Handle(StepVisual_DraughtingModel) aDModel;
4319 for (subs.Start(); subs.More() && aDModel.IsNull(); subs.Next())
4321 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel)))
4325 aDModel = Handle(StepVisual_DraughtingModel)::DownCast(subs.Value());
4327 if (!aDModel.IsNull())
4329 XSAlgo::AlgoContainer()->PrepareForTransfer();
4330 STEPControl_ActorRead anActor;
4331 anActor.PrepareUnits(aDModel, aTP);
4334 anObj->SetName(aCameraModel->Name());
4335 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
4336 anObj->SetViewDirection(anAxis->Direction());
4337 anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
4338 Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
4339 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
4340 if (aViewVolume->ProjectionType() == StepVisual_copCentral)
4341 aType = XCAFView_ProjectionType_Central;
4342 else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
4343 aType = XCAFView_ProjectionType_Parallel;
4344 anObj->SetType(aType);
4345 Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
4346 anObj->SetProjectionPoint(aPoint->Pnt());
4347 anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
4348 anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
4349 anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
4350 if (aViewVolume->FrontPlaneClipping())
4351 anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
4352 if (aViewVolume->BackPlaneClipping())
4353 anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
4354 anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
4356 Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
4357 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
4358 TDF_LabelSequence aClippingPlanes;
4359 if (!aClippingCameraModel.IsNull()) {
4360 Handle(TCollection_HAsciiString) aClippingExpression;
4361 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
4362 aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
4363 anObj->SetClippingExpression(aClippingExpression);
4366 // Collect shapes and GDTs
4367 if (aDModel.IsNull())
4368 return Standard_False;
4369 TDF_LabelSequence aShapes, aGDTs;
4370 Interface_EntityIterator anIter = aGraph.Shareds(aDModel);
4371 for (; anIter.More(); anIter.Next()) {
4372 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
4373 Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
4374 Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
4375 collectViewShapes(theWS, theDoc, aRepr, aShapes);
4377 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
4378 anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
4379 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4380 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4381 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4383 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4384 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4386 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4388 isFind = myGDTMap.Find(anIter.Value(), aGDTL);
4391 aGDTs.Append(aGDTL);
4394 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
4395 Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4396 for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
4397 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4398 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4399 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4401 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4402 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4404 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4406 aGDTs.Append(aGDTL);
4411 TDF_Label aViewL = aViewTool->AddView();
4412 Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
4413 aView->SetObject(anObj);
4414 aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
4415 aViewTool->Lock(aViewL);
4417 return Standard_True;
4420 //=======================================================================
4421 //function : SettleShapeData
4423 //=======================================================================
4425 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
4426 const TDF_Label& theLab,
4427 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
4428 const Handle(Transfer_TransientProcess)& TP) const
4430 TDF_Label aResult = theLab;
4432 Handle(TCollection_HAsciiString) hName = theItem->Name();
4433 if (hName.IsNull() || hName->IsEmpty())
4436 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
4437 if (aBinder.IsNull())
4440 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
4441 if (aShape.IsNull())
4444 // Allocate sub-Label
4445 aResult = theShapeTool->AddSubShape(theLab, aShape);
4446 if (aResult.IsNull())
4449 TCollection_AsciiString aName = hName->String();
4450 TDataStd_Name::Set(aResult, aName);
4451 theShapeTool->SetShape(aResult, aShape);
4456 //=======================================================================
4457 //function : collectRepresentationItems
4458 //purpose : recursive collection of representation items for given representation
4459 // with all representations, related to it.
4460 //=======================================================================
4462 void collectRepresentationItems(const Interface_Graph& theGraph,
4463 const Handle(StepShape_ShapeRepresentation)& theRepresentation,
4464 NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
4466 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items();
4467 for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++)
4468 theItems.Append(aReprItems->Value(itemIt));
4470 Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
4471 for (entIt.Start(); entIt.More(); entIt.Next())
4473 Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
4474 if (aRelationship->Rep1() == theRepresentation)
4476 Handle(StepShape_ShapeRepresentation)
4477 aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
4478 if (!aRepr.IsNull())
4479 collectRepresentationItems(theGraph, aRepr, theItems);
4484 //=======================================================================
4485 //function : ExpandSubShapes
4487 //=======================================================================
4489 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
4490 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
4491 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
4493 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
4494 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
4495 TColStd_MapOfTransient aRepItems;
4497 // Read translation control variables
4498 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
4503 const Interface_Graph& Graph = Reader().WS()->Graph();
4505 for (STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next())
4507 const TopoDS_Shape& aRootShape = it.Key();
4508 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
4512 // Find SDR by Product
4513 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
4514 Interface_EntityIterator entIt = Graph.TypedSharings(aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation));
4515 for (entIt.Start(); entIt.More(); entIt.Next())
4517 const Handle(Standard_Transient)& aReferer = entIt.Value();
4518 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
4526 // Access shape representation
4527 Handle(StepShape_ShapeRepresentation)
4528 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation());
4530 if (aShapeRepr.IsNull())
4533 // Access representation items
4534 NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
4535 collectRepresentationItems(Graph, aShapeRepr, aReprItems);
4537 if (aReprItems.Length() == 0)
4540 if (!ShapeLabelMap.IsBound(aRootShape))
4543 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
4544 // Do not add subshapes to assembly,
4545 // they will be processed with corresponding Shape_Product_Definition of necessary part.
4546 if (ShapeTool->IsAssembly(aRootLab))
4549 StepRepr_SequenceOfRepresentationItem aMSBSeq;
4550 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
4552 // Iterate over the top level representation items collecting the
4553 // topological containers to expand
4554 for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
4556 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
4557 if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep)))
4558 aMSBSeq.Append(aTRepr);
4559 else if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel)))
4560 aSBSMSeq.Append(aTRepr);
4563 // Insert intermediate OCAF Labels for SOLIDs in case there are more
4564 // than one Manifold Solid BRep in the Shape Representation
4565 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
4567 // Expand Manifold Solid BReps
4568 for (Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i)
4570 // Put additional Label for SOLID
4571 if (doInsertSolidLab)
4572 SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
4574 ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
4577 // Expand Shell-Based Surface Models
4578 for (Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i)
4579 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
4583 //=======================================================================
4584 //function : ExpandManifoldSolidBrep
4586 //=======================================================================
4588 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
4589 const Handle(StepRepr_RepresentationItem)& Repr,
4590 const Handle(Transfer_TransientProcess)& TP,
4591 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4593 // Access outer shell
4594 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
4595 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
4597 // Expand shell contents to CAF tree
4598 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
4601 //=======================================================================
4602 //function : ExpandSBSM
4604 //=======================================================================
4606 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
4607 const Handle(StepRepr_RepresentationItem)& Repr,
4608 const Handle(Transfer_TransientProcess)& TP,
4609 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4611 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
4613 // Access boundary shells
4614 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
4615 for (Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s)
4617 const StepShape_Shell& aShell = aShells->Value(s);
4618 Handle(StepShape_ConnectedFaceSet) aCFS;
4619 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
4620 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
4622 if (!anOpenShell.IsNull())
4625 aCFS = aClosedShell;
4627 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
4631 //=======================================================================
4632 //function : ExpandShell
4634 //=======================================================================
4636 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
4638 const Handle(Transfer_TransientProcess)& TP,
4639 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4642 SettleShapeData(Shell, RootLab, ShapeTool, TP);
4645 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
4646 for (Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f)
4648 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
4653 SettleShapeData(aFace, RootLab, ShapeTool, TP);
4655 // Access face bounds
4656 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
4657 if (aWires.IsNull())
4659 for (Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w)
4661 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
4664 SettleShapeData(aWire, RootLab, ShapeTool, TP);
4666 // Access wire edges
4667 // Currently only EDGE LOOPs are considered (!)
4668 if (!aWire->IsInstance(STANDARD_TYPE(StepShape_EdgeLoop)))
4672 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
4673 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
4674 for (Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e)
4676 Handle(StepShape_OrientedEdge) anOrientedEdge = anEdges->Value(e);
4677 if (anOrientedEdge.IsNull())
4679 Handle(StepShape_Edge) anEdge = anOrientedEdge->EdgeElement();
4680 if (anEdge.IsNull())
4684 SettleShapeData(anEdge, RootLab, ShapeTool, TP);
4687 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
4688 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
4691 SettleShapeData(aV1, RootLab, ShapeTool, TP);
4692 SettleShapeData(aV2, RootLab, ShapeTool, TP);
4698 //=======================================================================
4699 //function : SetColorMode
4701 //=======================================================================
4703 void STEPCAFControl_Reader::SetColorMode(const Standard_Boolean colormode)
4705 myColorMode = colormode;
4708 //=======================================================================
4709 //function : GetColorMode
4711 //=======================================================================
4713 Standard_Boolean STEPCAFControl_Reader::GetColorMode() const
4718 //=======================================================================
4719 //function : SetNameMode
4721 //=======================================================================
4723 void STEPCAFControl_Reader::SetNameMode(const Standard_Boolean namemode)
4725 myNameMode = namemode;
4728 //=======================================================================
4729 //function : GetNameMode
4731 //=======================================================================
4733 Standard_Boolean STEPCAFControl_Reader::GetNameMode() const
4738 //=======================================================================
4739 //function : SetLayerMode
4741 //=======================================================================
4743 void STEPCAFControl_Reader::SetLayerMode(const Standard_Boolean layermode)
4745 myLayerMode = layermode;
4748 //=======================================================================
4749 //function : GetLayerMode
4751 //=======================================================================
4753 Standard_Boolean STEPCAFControl_Reader::GetLayerMode() const
4758 //=======================================================================
4759 //function : SetPropsMode
4761 //=======================================================================
4763 void STEPCAFControl_Reader::SetPropsMode(const Standard_Boolean propsmode)
4765 myPropsMode = propsmode;
4768 //=======================================================================
4769 //function : GetPropsMode
4771 //=======================================================================
4773 Standard_Boolean STEPCAFControl_Reader::GetPropsMode() const
4778 //=======================================================================
4779 //function : SetSHUOMode
4781 //=======================================================================
4783 void STEPCAFControl_Reader::SetSHUOMode(const Standard_Boolean mode)
4788 //=======================================================================
4789 //function : GetSHUOMode
4791 //=======================================================================
4793 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode() const
4798 //=======================================================================
4799 //function : SetGDTMode
4801 //=======================================================================
4803 void STEPCAFControl_Reader::SetGDTMode(const Standard_Boolean gdtmode)
4805 myGDTMode = gdtmode;
4808 //=======================================================================
4809 //function : GetGDTMode
4811 //=======================================================================
4813 Standard_Boolean STEPCAFControl_Reader::GetGDTMode() const
4819 //=======================================================================
4820 //function : SetMatMode
4822 //=======================================================================
4824 void STEPCAFControl_Reader::SetMatMode(const Standard_Boolean matmode)
4826 myMatMode = matmode;
4829 //=======================================================================
4830 //function : GetMatMode
4832 //=======================================================================
4834 Standard_Boolean STEPCAFControl_Reader::GetMatMode() const
4839 //=======================================================================
4840 //function : SetViewMode
4842 //=======================================================================
4844 void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
4846 myViewMode = viewmode;
4849 //=======================================================================
4850 //function : GetViewMode
4852 //=======================================================================
4854 Standard_Boolean STEPCAFControl_Reader::GetViewMode() const