0030754: Coding - the array of weights should begin with Lower, not the constant...
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.cxx
CommitLineData
b311480e 1// Created on: 2000-08-15
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BRep_Builder.hxx>
400af1bc 18#include <Geom_Axis2Placement.hxx>
0c63f2f8 19#include <Geom_CartesianPoint.hxx>
20#include <Geom_Plane.hxx>
42cf5bc1 21#include <Interface_EntityIterator.hxx>
7fd59977 22#include <Interface_InterfaceModel.hxx>
1c9d3225 23#include <StepData_StepModel.hxx>
24#include <HeaderSection_FileSchema.hxx>
42cf5bc1 25#include <Interface_Static.hxx>
26#include <NCollection_DataMap.hxx>
27#include <OSD_Path.hxx>
28#include <Quantity_Color.hxx>
29#include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
30#include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
1c9d3225 31#include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
42cf5bc1 32#include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
33#include <StepBasic_DerivedUnit.hxx>
34#include <StepBasic_DerivedUnitElement.hxx>
35#include <StepBasic_MeasureValueMember.hxx>
36#include <StepBasic_MeasureWithUnit.hxx>
37#include <StepBasic_NamedUnit.hxx>
7fd59977 38#include <StepBasic_Product.hxx>
39#include <StepBasic_ProductDefinition.hxx>
7fd59977 40#include <StepBasic_ProductDefinitionFormation.hxx>
42cf5bc1 41#include <StepBasic_ProductDefinitionRelationship.hxx>
42#include <StepBasic_SiUnit.hxx>
fe0d928d 43#include <StepBasic_SiUnitAndLengthUnit.hxx>
42cf5bc1 44#include <StepBasic_Unit.hxx>
45#include <STEPCAFControl_Controller.hxx>
46#include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
47#include <STEPCAFControl_DataMapOfPDExternFile.hxx>
48#include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
49#include <STEPCAFControl_DataMapOfShapePD.hxx>
42cf5bc1 50#include <STEPCAFControl_ExternFile.hxx>
51#include <STEPCAFControl_Reader.hxx>
7fd59977 52#include <STEPConstruct.hxx>
42cf5bc1 53#include <STEPConstruct_Assembly.hxx>
7fd59977 54#include <STEPConstruct_ExternRefs.hxx>
42cf5bc1 55#include <STEPConstruct_Styles.hxx>
56#include <STEPConstruct_Tool.hxx>
7fd59977 57#include <STEPConstruct_UnitContext.hxx>
7fd59977 58#include <STEPConstruct_ValidationProps.hxx>
477000eb 59#include <STEPControl_ActorRead.hxx>
42cf5bc1 60#include <STEPControl_Reader.hxx>
1c9d3225 61#include <StepGeom_GeometricRepresentationItem.hxx>
62#include <StepGeom_Axis2Placement3d.hxx>
63#include <StepGeom_Direction.hxx>
42cf5bc1 64#include <StepDimTol_AngularityTolerance.hxx>
65#include <StepDimTol_CircularRunoutTolerance.hxx>
66#include <StepDimTol_CoaxialityTolerance.hxx>
67#include <StepDimTol_ConcentricityTolerance.hxx>
68#include <StepDimTol_CylindricityTolerance.hxx>
69#include <StepDimTol_Datum.hxx>
70#include <StepDimTol_DatumFeature.hxx>
71#include <StepDimTol_DatumReference.hxx>
1c9d3225 72#include <StepDimTol_DatumReferenceElement.hxx>
73#include <StepDimTol_DatumReferenceCompartment.hxx>
74#include <StepDimTol_DatumSystem.hxx>
42cf5bc1 75#include <StepDimTol_FlatnessTolerance.hxx>
76#include <StepDimTol_GeometricTolerance.hxx>
77#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
78#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
1c9d3225 79#include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
6595eee7 80#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
81#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
82#include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
42cf5bc1 83#include <StepDimTol_HArray1OfDatumReference.hxx>
84#include <StepDimTol_LineProfileTolerance.hxx>
85#include <StepDimTol_ModifiedGeometricTolerance.hxx>
86#include <StepDimTol_ParallelismTolerance.hxx>
87#include <StepDimTol_PerpendicularityTolerance.hxx>
88#include <StepDimTol_PositionTolerance.hxx>
1c9d3225 89#include <StepDimTol_ProjectedZoneDefinition.hxx>
42cf5bc1 90#include <StepDimTol_RoundnessTolerance.hxx>
1c9d3225 91#include <StepDimTol_RunoutZoneDefinition.hxx>
42cf5bc1 92#include <StepDimTol_StraightnessTolerance.hxx>
93#include <StepDimTol_SurfaceProfileTolerance.hxx>
94#include <StepDimTol_SymmetryTolerance.hxx>
1c9d3225 95#include <StepDimTol_ToleranceZone.hxx>
96#include <StepDimTol_ToleranceZoneForm.hxx>
42cf5bc1 97#include <StepDimTol_TotalRunoutTolerance.hxx>
1c9d3225 98#include <StepDimTol_GeometricToleranceWithModifiers.hxx>
99#include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
100#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
101#include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
102#include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
5df609e7 103#include <StepGeom_Axis2Placement3d.hxx>
fe0d928d 104#include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
105#include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
5df609e7 106#include <StepGeom_Plane.hxx>
107#include <StepGeom_Polyline.hxx>
1c9d3225 108#include <StepDimTol_PlacedDatumTargetFeature.hxx>
42cf5bc1 109#include <StepRepr_AssemblyComponentUsage.hxx>
110#include <StepRepr_CharacterizedDefinition.hxx>
1c9d3225 111#include <StepRepr_CompoundRepresentationItem.hxx>
b7b2f85a 112#include <StepRepr_DerivedShapeAspect.hxx>
42cf5bc1 113#include <StepRepr_DescriptiveRepresentationItem.hxx>
114#include <StepRepr_HArray1OfRepresentationItem.hxx>
0c63f2f8 115#include <StepRepr_MappedItem.hxx>
42cf5bc1 116#include <StepRepr_MeasureRepresentationItem.hxx>
117#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
118#include <StepRepr_ProductDefinitionShape.hxx>
119#include <StepRepr_PropertyDefinition.hxx>
120#include <StepRepr_PropertyDefinitionRepresentation.hxx>
7fd59977 121#include <StepRepr_Representation.hxx>
42cf5bc1 122#include <StepRepr_RepresentationItem.hxx>
1c9d3225 123#include <StepRepr_HArray1OfRepresentationItem.hxx>
0c63f2f8 124#include <StepRepr_RepresentationMap.hxx>
42cf5bc1 125#include <StepRepr_RepresentationRelationship.hxx>
126#include <StepRepr_RepresentedDefinition.hxx>
127#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
5b7f8e0a 128#include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
1c9d3225 129#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
5b7f8e0a 130#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
42cf5bc1 131#include <StepRepr_SequenceOfRepresentationItem.hxx>
132#include <StepRepr_ShapeAspect.hxx>
b7b2f85a 133#include <StepRepr_ShapeAspectDerivingRelationship.hxx>
1c9d3225 134#include <StepRepr_CompositeShapeAspect.hxx>
135#include <StepRepr_AllAroundShapeAspect.hxx>
136#include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
42cf5bc1 137#include <StepRepr_ShapeAspectRelationship.hxx>
7fd59977 138#include <StepRepr_ShapeRepresentationRelationship.hxx>
42cf5bc1 139#include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
140#include <StepRepr_ValueRange.hxx>
1c9d3225 141#include <StepRepr_FeatureForDatumTargetRelationship.hxx>
42cf5bc1 142#include <StepShape_AdvancedFace.hxx>
1c9d3225 143#include <StepShape_AdvancedBrepShapeRepresentation.hxx>
144#include <StepShape_AngleRelator.hxx>
145#include <StepShape_AngularSize.hxx>
146#include <StepShape_AngularLocation.hxx>
42cf5bc1 147#include <StepShape_ClosedShell.hxx>
148#include <StepShape_ConnectedFaceSet.hxx>
149#include <StepShape_ContextDependentShapeRepresentation.hxx>
1c9d3225 150#include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
151#include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
42cf5bc1 152#include <StepShape_DimensionalCharacteristicRepresentation.hxx>
1c9d3225 153#include <StepShape_DimensionalSizeWithPath.hxx>
154#include <StepShape_DimensionalLocationWithPath.hxx>
155#include <StepShape_ShapeDimensionRepresentationItem.hxx>
156#include <StepShape_ShapeRepresentationWithParameters.hxx>
157#include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
42cf5bc1 158#include <StepShape_DimensionalSize.hxx>
1c9d3225 159#include <StepShape_DimensionalLocation.hxx>
42cf5bc1 160#include <StepShape_EdgeCurve.hxx>
161#include <StepShape_EdgeLoop.hxx>
5df609e7 162#include <StepShape_GeometricCurveSet.hxx>
42cf5bc1 163#include <StepShape_GeometricSet.hxx>
164#include <StepShape_HArray1OfFace.hxx>
165#include <StepShape_HArray1OfFaceBound.hxx>
166#include <StepShape_HArray1OfOrientedEdge.hxx>
167#include <StepShape_HArray1OfShell.hxx>
1c9d3225 168#include <StepShape_LimitsAndFits.hxx>
42cf5bc1 169#include <StepShape_Loop.hxx>
170#include <StepShape_ManifoldSolidBrep.hxx>
1c9d3225 171#include <StepShape_PlusMinusTolerance.hxx>
172#include <StepShape_QualifiedRepresentationItem.hxx>
42cf5bc1 173#include <StepShape_OpenShell.hxx>
174#include <StepShape_ShapeDefinitionRepresentation.hxx>
175#include <StepShape_ShapeDimensionRepresentation.hxx>
176#include <StepShape_ShapeRepresentation.hxx>
177#include <StepShape_ShellBasedSurfaceModel.hxx>
178#include <StepShape_SolidModel.hxx>
1c9d3225 179#include <StepShape_ToleranceMethodDefinition.hxx>
180#include <StepShape_ToleranceValue.hxx>
181#include <StepShape_ValueFormatTypeQualifier.hxx>
42cf5bc1 182#include <StepShape_Vertex.hxx>
400af1bc 183#include <StepToGeom.hxx>
5df609e7 184#include <StepVisual_AnnotationCurveOccurrence.hxx>
1209c1b9 185#include <StepVisual_AnnotationFillArea.hxx>
5df609e7 186#include <StepVisual_AnnotationPlane.hxx>
0c63f2f8 187#include <StepVisual_CameraModelD3.hxx>
188#include <StepVisual_CameraModelD3MultiClipping.hxx>
189#include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
190#include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
191#include <StepVisual_CoordinatesList.hxx>
192#include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
193#include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
5df609e7 194#include <StepVisual_DraughtingCallout.hxx>
195#include <StepVisual_DraughtingCalloutElement.hxx>
fe0d928d 196#include <StepVisual_DraughtingModel.hxx>
7fd59977 197#include <StepVisual_Invisibility.hxx>
42cf5bc1 198#include <StepVisual_LayeredItem.hxx>
5df609e7 199#include <StepVisual_PlanarBox.hxx>
42cf5bc1 200#include <StepVisual_PresentationLayerAssignment.hxx>
201#include <StepVisual_PresentationStyleByContext.hxx>
202#include <StepVisual_StyleContextSelect.hxx>
203#include <StepVisual_StyledItem.hxx>
0c63f2f8 204#include <StepVisual_ViewVolume.hxx>
1c9d3225 205#include <StepShape_TypeQualifier.hxx>
42cf5bc1 206#include <TCollection_AsciiString.hxx>
207#include <TCollection_HAsciiString.hxx>
208#include <TColStd_HArray1OfReal.hxx>
209#include <TColStd_HArray1OfTransient.hxx>
210#include <TColStd_HSequenceOfTransient.hxx>
211#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
212#include <TColStd_MapIteratorOfMapOfTransient.hxx>
213#include <TColStd_MapOfTransient.hxx>
7fd59977 214#include <TColStd_SequenceOfHAsciiString.hxx>
42cf5bc1 215#include <TDataStd_Name.hxx>
7fd59977 216#include <TDataStd_TreeNode.hxx>
42cf5bc1 217#include <TDataStd_UAttribute.hxx>
218#include <TDF_Label.hxx>
219#include <TDF_Tool.hxx>
220#include <TDocStd_Document.hxx>
7fd59977 221#include <TNaming_NamedShape.hxx>
5df609e7 222#include <TopExp_Explorer.hxx>
1c9d3225 223#include <TopoDS.hxx>
42cf5bc1 224#include <TopoDS_Compound.hxx>
225#include <TopoDS_Iterator.hxx>
226#include <TopoDS_Shape.hxx>
227#include <TopTools_ListIteratorOfListOfShape.hxx>
228#include <TopTools_ListOfShape.hxx>
229#include <TopTools_MapOfShape.hxx>
230#include <Transfer_Binder.hxx>
231#include <Transfer_TransientProcess.hxx>
232#include <TransferBRep.hxx>
477000eb 233#include <UnitsMethods.hxx>
42cf5bc1 234#include <XCAFDoc.hxx>
235#include <XCAFDoc_Area.hxx>
236#include <XCAFDoc_Centroid.hxx>
0c63f2f8 237#include <XCAFDoc_ClippingPlaneTool.hxx>
42cf5bc1 238#include <XCAFDoc_ColorTool.hxx>
239#include <XCAFDoc_DataMapOfShapeLabel.hxx>
240#include <XCAFDoc_DimTolTool.hxx>
1c9d3225 241#include <XCAFDoc_Dimension.hxx>
242#include <XCAFDoc_Datum.hxx>
243#include <XCAFDoc_GeomTolerance.hxx>
42cf5bc1 244#include <XCAFDoc_DocumentTool.hxx>
7fd59977 245#include <XCAFDoc_GraphNode.hxx>
42cf5bc1 246#include <XCAFDoc_LayerTool.hxx>
247#include <XCAFDoc_MaterialTool.hxx>
248#include <XCAFDoc_ShapeTool.hxx>
0c63f2f8 249#include <XCAFDoc_View.hxx>
250#include <XCAFDoc_ViewTool.hxx>
42cf5bc1 251#include <XCAFDoc_Volume.hxx>
1c9d3225 252#include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
253#include <XCAFDimTolObjects_GeomToleranceType.hxx>
254#include <XCAFDimTolObjects_DimensionObject.hxx>
255#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
256#include <XCAFDimTolObjects_DatumObject.hxx>
0c63f2f8 257#include <XCAFView_Object.hxx>
477000eb 258#include <XSAlgo.hxx>
259#include <XSAlgo_AlgoContainer.hxx>
42cf5bc1 260#include <XSControl_TransferReader.hxx>
261#include <XSControl_WorkSession.hxx>
5df609e7 262#include <StepAP242_DraughtingModelItemAssociation.hxx>
1c9d3225 263#include <StepAP242_GeometricItemSpecificUsage.hxx>
264#include <StepGeom_CartesianPoint.hxx>
727b5ad9 265#include <STEPCAFControl_GDTProperty.hxx>
5df609e7 266#include <StepVisual_TessellatedAnnotationOccurrence.hxx>
267#include <StepVisual_TessellatedAnnotationOccurrence.hxx>
268#include <StepVisual_TessellatedItem.hxx>
269#include <StepVisual_TessellatedGeometricSet.hxx>
270#include <StepVisual_TessellatedCurveSet.hxx>
271#include <StepVisual_CoordinatesList.hxx>
272#include <NCollection_Vector.hxx>
273
274#include <TColgp_HArray1OfXYZ.hxx>
275#include <BRepBuilderAPI_MakeEdge.hxx>
276#include <BRepTools.hxx>
277#include <Transfer_ActorOfTransientProcess.hxx>
278#include <Bnd_Box.hxx>
279#include <BRepBndLib.hxx>
e3249d8e 280#include <Resource_Unicode.hxx>
5df609e7 281
7fd59977 282// skl 21.08.2003 for reading G&DT
7fd59977 283//#include <StepRepr_CompoundItemDefinition.hxx>
284//#include <StepRepr_CompoundItemDefinitionMember.hxx>
7fd59977 285//#include <StepBasic_ConversionBasedUnit.hxx>
7fd59977 286//#include <TDataStd_Real.hxx>
287//#include <TDataStd_Constraint.hxx>
288//#include <TDataStd_ConstraintEnum.hxx>
289//#include <TNaming_Tool.hxx>
290//#include <AIS_InteractiveObject.hxx>
291//#include <TPrsStd_ConstraintTools.hxx>
292//#include <AIS_DiameterDimension.hxx>
293//#include <TPrsStd_Position.hxx>
294//#include <TPrsStd_AISPresentation.hxx>
295//#include <TNaming_Builder.hxx>
0797d9d3 296#ifdef OCCT_DEBUG
02a0b964 297//! Converts address of the passed shape (TShape) to string.
298//! \param theShape [in] Shape to dump.
299//! \return corresponding string.
300TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
301{
302 std::string anAddrStr;
303 std::ostringstream ost;
1c29294e 304 ost << theShape.TShape().get();
02a0b964 305 anAddrStr = ost.str();
306
307 TCollection_AsciiString aStr =
cf152970 308 TCollection_AsciiString("[").Cat(anAddrStr.c_str()).Cat("]");
02a0b964 309
310 return aStr;
311}
312#endif
313
314//=======================================================================
7fd59977 315//function : STEPCAFControl_Reader
316//purpose :
317//=======================================================================
318
e3249d8e 319STEPCAFControl_Reader::STEPCAFControl_Reader()
320: mySourceCodePage (Resource_FormatType_UTF8),
cf152970 321 myColorMode(Standard_True),
322 myNameMode(Standard_True),
323 myLayerMode(Standard_True),
324 myPropsMode(Standard_True),
325 mySHUOMode(Standard_False),
326 myGDTMode(Standard_True),
327 myMatMode(Standard_True),
328 myViewMode(Standard_True)
7fd59977 329{
330 STEPCAFControl_Controller::Init();
e3249d8e 331 mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
7fd59977 332}
333
334
335//=======================================================================
336//function : STEPCAFControl_Reader
337//purpose :
338//=======================================================================
339
cf152970 340STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS,
e3249d8e 341 const Standard_Boolean scratch)
342: mySourceCodePage (Resource_FormatType_UTF8),
cf152970 343 myColorMode(Standard_True),
344 myNameMode(Standard_True),
345 myLayerMode(Standard_True),
346 myPropsMode(Standard_True),
347 mySHUOMode(Standard_False),
348 myGDTMode(Standard_True),
349 myMatMode(Standard_True),
350 myViewMode(Standard_True)
7fd59977 351{
352 STEPCAFControl_Controller::Init();
e3249d8e 353 mySourceCodePage = (Resource_FormatType )Interface_Static::IVal ("read.stepcaf.codepage");
cf152970 354 Init(WS, scratch);
7fd59977 355}
356
357
358//=======================================================================
359//function : Init
360//purpose :
361//=======================================================================
362
cf152970 363void STEPCAFControl_Reader::Init(const Handle(XSControl_WorkSession)& WS,
364 const Standard_Boolean scratch)
7fd59977 365{
cf152970 366 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
367 myReader.SetWS(WS, scratch);
997e128f 368 myFiles.Clear();
7fd59977 369}
370
e3249d8e 371//=======================================================================
372//function : convertName
373//purpose :
374//=======================================================================
375TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection_AsciiString& theName) const
376{
377 TCollection_ExtendedString aName;
378 Resource_Unicode::ConvertFormatToUnicode (mySourceCodePage, theName.ToCString(), aName);
379 return aName;
380}
7fd59977 381
382//=======================================================================
383//function : ReadFile
384//purpose :
385//=======================================================================
386
cf152970 387IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile(const Standard_CString filename)
7fd59977 388{
cf152970 389 return myReader.ReadFile(filename);
7fd59977 390}
391
392
393//=======================================================================
394//function : NbRootsForTransfer
395//purpose :
396//=======================================================================
397
cf152970 398Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer()
7fd59977 399{
400 return myReader.NbRootsForTransfer();
401}
402
403
404//=======================================================================
405//function : TransferOneRoot
406//purpose :
407//=======================================================================
408
cf152970 409Standard_Boolean STEPCAFControl_Reader::TransferOneRoot(const Standard_Integer num,
410 Handle(TDocStd_Document) &doc)
7fd59977 411{
412 TDF_LabelSequence Lseq;
cf152970 413 return Transfer(myReader, num, doc, Lseq);
7fd59977 414}
415
416
417//=======================================================================
418//function : Transfer
419//purpose :
420//=======================================================================
421
cf152970 422Standard_Boolean STEPCAFControl_Reader::Transfer(Handle(TDocStd_Document) &doc)
7fd59977 423{
424 TDF_LabelSequence Lseq;
cf152970 425 return Transfer(myReader, 0, doc, Lseq);
7fd59977 426}
427
428
429//=======================================================================
430//function : Perform
431//purpose :
432//=======================================================================
433
cf152970 434Standard_Boolean STEPCAFControl_Reader::Perform(const Standard_CString filename,
435 Handle(TDocStd_Document) &doc)
7fd59977 436{
cf152970 437 if (ReadFile(filename) != IFSelect_RetDone) return Standard_False;
438 return Transfer(doc);
7fd59977 439}
cf152970 440
7fd59977 441
442//=======================================================================
443//function : Perform
444//purpose :
445//=======================================================================
446
cf152970 447Standard_Boolean STEPCAFControl_Reader::Perform(const TCollection_AsciiString &filename,
448 Handle(TDocStd_Document) &doc)
7fd59977 449{
cf152970 450 if (ReadFile(filename.ToCString()) != IFSelect_RetDone) return Standard_False;
451 return Transfer(doc);
7fd59977 452}
cf152970 453
7fd59977 454
455//=======================================================================
456//function : ExternFiles
457//purpose :
458//=======================================================================
459
cf152970 460const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles() const
7fd59977 461{
462 return myFiles;
463}
cf152970 464
7fd59977 465
466//=======================================================================
467//function : ExternFile
468//purpose :
469//=======================================================================
470
cf152970 471Standard_Boolean STEPCAFControl_Reader::ExternFile(const Standard_CString name,
472 Handle(STEPCAFControl_ExternFile) &ef) const
7fd59977 473{
474 ef.Nullify();
cf152970 475 if (myFiles.IsEmpty() || !myFiles.IsBound(name))
7fd59977 476 return Standard_False;
cf152970 477 ef = myFiles.Find(name);
7fd59977 478 return Standard_True;
479}
480
481
482//=======================================================================
483//function : Reader
484//purpose :
485//=======================================================================
486
cf152970 487STEPControl_Reader &STEPCAFControl_Reader::ChangeReader()
7fd59977 488{
489 return myReader;
490}
cf152970 491
7fd59977 492
493//=======================================================================
494//function : Reader
495//purpose :
496//=======================================================================
497
cf152970 498const STEPControl_Reader &STEPCAFControl_Reader::Reader() const
7fd59977 499{
500 return myReader;
501}
cf152970 502
7fd59977 503
504//=======================================================================
505//function : FillShapesMap
506//purpose : auxiliary: fill a map by all compounds and their components
507//=======================================================================
508
cf152970 509static void FillShapesMap(const TopoDS_Shape &S, TopTools_MapOfShape &map)
7fd59977 510{
511 TopoDS_Shape S0 = S;
512 TopLoc_Location loc;
cf152970 513 S0.Location(loc);
514 map.Add(S0);
515 if (S.ShapeType() != TopAbs_COMPOUND) return;
516 for (TopoDS_Iterator it(S); it.More(); it.Next())
517 FillShapesMap(it.Value(), map);
7fd59977 518}
519
520
521//=======================================================================
522//function : Transfer
523//purpose : basic working method
524//=======================================================================
525
cf152970 526Standard_Boolean STEPCAFControl_Reader::Transfer(STEPControl_Reader &reader,
527 const Standard_Integer nroot,
528 Handle(TDocStd_Document) &doc,
529 TDF_LabelSequence &Lseq,
530 const Standard_Boolean asOne)
7fd59977 531{
532 reader.ClearShapes();
533 Standard_Integer i;
cf152970 534
7fd59977 535 // Read all shapes
536 Standard_Integer num = reader.NbRootsForTransfer();
cf152970 537 if (num <= 0) return Standard_False;
538 if (nroot) {
539 if (nroot > num) return Standard_False;
540 reader.TransferOneRoot(nroot);
7fd59977 541 }
542 else {
cf152970 543 for (i = 1; i <= num; i++) reader.TransferOneRoot(i);
7fd59977 544 }
545 num = reader.NbShapes();
cf152970 546 if (num <= 0) return Standard_False;
7fd59977 547
548 // Fill a map of (top-level) shapes resulting from that transfer
549 // Only these shapes will be considered further
550 TopTools_MapOfShape ShapesMap, NewShapesMap;
cf152970 551 for (i = 1; i <= num; i++) FillShapesMap(reader.Shape(i), ShapesMap);
552
7fd59977 553 // Collect information on shapes originating from SDRs
554 // this will be used to distinguish compounds representing assemblies
555 // from the ones representing hybrid models and shape sets
556 STEPCAFControl_DataMapOfShapePD ShapePDMap;
557 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
558 Handle(Interface_InterfaceModel) Model = reader.Model();
7f56eba8 559 const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
7fd59977 560 Standard_Integer nb = Model->NbEntities();
561
562 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
563
cf152970 564 for (i = 1; i <= nb; i++) {
7fd59977 565 Handle(Standard_Transient) enti = Model->Value(i);
cf152970 566 if (enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
7fd59977 567 // sequence for acceleration ReadMaterials
568 SeqPDS->Append(enti);
569 }
cf152970 570 if (enti->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
571 Handle(StepBasic_ProductDefinition) PD =
7fd59977 572 Handle(StepBasic_ProductDefinition)::DownCast(enti);
573 Standard_Integer index = TP->MapIndex(PD);
cf152970 574 if (index > 0) {
575 Handle(Transfer_Binder) binder = TP->MapItem(index);
7fd59977 576 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
cf152970 577 if (!S.IsNull() && ShapesMap.Contains(S)) {
7fd59977 578 NewShapesMap.Add(S);
cf152970 579 ShapePDMap.Bind(S, PD);
7fd59977 580 Handle(STEPCAFControl_ExternFile) EF;
cf152970 581 PDFileMap.Bind(PD, EF);
7fd59977 582 }
583 }
584 }
cf152970 585 if (enti->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
7fd59977 586 Standard_Integer index = TP->MapIndex(enti);
cf152970 587 if (index > 0) {
588 Handle(Transfer_Binder) binder = TP->MapItem(index);
7fd59977 589 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
cf152970 590 if (!S.IsNull() && ShapesMap.Contains(S))
7fd59977 591 NewShapesMap.Add(S);
592 }
593 }
594 }
595
596 // get directory name of the main file
cf152970 597 OSD_Path mainfile(reader.WS()->LoadedFile());
598 mainfile.SetName("");
599 mainfile.SetExtension("");
7fd59977 600 TCollection_AsciiString dpath;
cf152970 601 mainfile.SystemName(dpath);
7fd59977 602
603 // Load external references (only for relevant SDRs)
604 // and fill map SDR -> extern file
cf152970 605 STEPConstruct_ExternRefs ExtRefs(reader.WS());
7fd59977 606 ExtRefs.LoadExternRefs();
cf152970 607 for (i = 1; i <= ExtRefs.NbExternRefs(); i++) {
7fd59977 608 // check extern ref format
609 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
cf152970 610 if (!format.IsNull()) {
611 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString("STEP AP203");
612 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString("STEP AP214");
613 if (!format->IsSameString(ap203, Standard_False) &&
614 !format->IsSameString(ap214, Standard_False)) {
0797d9d3 615#ifdef OCCT_DEBUG
cf152970 616 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
7fd59977 617#else
cf152970 618 continue;
7fd59977 619#endif
620 }
621 }
0797d9d3 622#ifdef OCCT_DEBUG
7fd59977 623 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
624#endif
cf152970 625
7fd59977 626 // get and check filename of the current extern ref
627 const Standard_CString filename = ExtRefs.FileName(i);
628
0797d9d3 629#ifdef OCCT_DEBUG
cf152970 630 cout << "filename=" << filename << endl;
83a86948 631#endif
7fd59977 632
cf152970 633 if (!filename || !filename[0]) {
0797d9d3 634#ifdef OCCT_DEBUG
7fd59977 635 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
636#endif
637 continue; // not a valid extern ref
638 }
639
640 // compute true path to the extern file
cf152970 641 TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, filename);
642 if (fullname.Length() <= 0) fullname = filename;
643
644 /*
645 char fullname[1024];
646 char *mainfile = reader.WS()->LoadedFile();
647 if ( ! mainfile ) mainfile = "";
648 Standard_Integer slash = 0;
649 for ( Standard_Integer k=0; mainfile[k]; k++ )
650 if ( mainfile[k] == '/' ) slash = k;
651 strncpy ( fullname, mainfile, slash );
652 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
653 */
654
7fd59977 655 // get and check PD associated with the current extern ref
656 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
cf152970 657 if (PD.IsNull()) continue; // not a valid extern ref
658 if (!PDFileMap.IsBound(PD)) continue; // this PD is not concerned by current transfer
659
7fd59977 660 // read extern file (or use existing data) and record its data
cf152970 661 Handle(STEPCAFControl_ExternFile) EF =
662 ReadExternFile(filename, fullname.ToCString(), doc);
663 PDFileMap.Bind(PD, EF);
7fd59977 664 }
cf152970 665
7fd59977 666 // and insert them to the document
cf152970 667 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
668 if (STool.IsNull()) return Standard_False;
7fd59977 669 XCAFDoc_DataMapOfShapeLabel map;
cf152970 670 if (asOne)
671 Lseq.Append(AddShape(reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map));
7fd59977 672 else {
cf152970 673 for (i = 1; i <= num; i++) {
674 Lseq.Append(AddShape(reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map));
7fd59977 675 }
676 }
cf152970 677
7fd59977 678 // read colors
cf152970 679 if (GetColorMode())
680 ReadColors(reader.WS(), doc, map);
681
7fd59977 682 // read names
cf152970 683 if (GetNameMode())
684 ReadNames(reader.WS(), doc, PDFileMap, map);
7fd59977 685
686 // read validation props
cf152970 687 if (GetPropsMode())
688 ReadValProps(reader.WS(), doc, PDFileMap, map);
7fd59977 689
690 // read layers
cf152970 691 if (GetLayerMode())
692 ReadLayers(reader.WS(), doc);
693
7fd59977 694 // read SHUO entities from STEP model
cf152970 695 if (GetSHUOMode())
696 ReadSHUOs(reader.WS(), doc, PDFileMap, map);
7fd59977 697
698 // read GDT entities from STEP model
cf152970 699 if (GetGDTMode())
700 ReadGDTs(reader.WS(), doc);
7fd59977 701
702 // read Material entities from STEP model
cf152970 703 if (GetMatMode())
704 ReadMaterials(reader.WS(), doc, SeqPDS);
7fd59977 705
0c63f2f8 706 // read View entities from STEP model
707 if (GetViewMode())
708 ReadViews(reader.WS(), doc);
709
02a0b964 710 // Expand resulting CAF structure for sub-shapes (optionally with their
711 // names) if requested
712 ExpandSubShapes(STool, map, ShapePDMap);
713
acc909a8 714 // Update assembly compounds
715 STool->UpdateAssemblies();
716
7fd59977 717 return Standard_True;
718}
719
720//=======================================================================
721//function : AddShape
722//purpose :
723//=======================================================================
724
cf152970 725TDF_Label STEPCAFControl_Reader::AddShape(const TopoDS_Shape &S,
726 const Handle(XCAFDoc_ShapeTool) &STool,
727 const TopTools_MapOfShape &NewShapesMap,
728 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
729 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
730 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 731{
732 // if shape has already been mapped, just return corresponding label
cf152970 733 if (ShapeLabelMap.IsBound(S)) {
734 return ShapeLabelMap.Find(S);
7fd59977 735 }
cf152970 736
7fd59977 737 // if shape is located, create instance
cf152970 738 if (!S.Location().IsIdentity()) {
7fd59977 739 TopoDS_Shape S0 = S;
740 TopLoc_Location loc;
cf152970 741 S0.Location(loc);
742 AddShape(S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap);
743 TDF_Label L = STool->AddShape(S, Standard_False); // should create reference
744 ShapeLabelMap.Bind(S, L);
7fd59977 745 return L;
746 }
cf152970 747
7fd59977 748 // if shape is not compound, simple add it
cf152970 749 if (S.ShapeType() != TopAbs_COMPOUND) {
750 TDF_Label L = STool->AddShape(S, Standard_False);
751 ShapeLabelMap.Bind(S, L);
7fd59977 752 return L;
753 }
cf152970 754
7fd59977 755 // for compounds, compute number of subshapes and check whether this is assembly
756 Standard_Boolean isAssembly = Standard_False;
757 Standard_Integer nbComponents = 0;
758 TopoDS_Iterator it;
cf152970 759 for (it.Initialize(S); it.More() && !isAssembly; it.Next(), nbComponents++) {
7fd59977 760 TopoDS_Shape Sub0 = it.Value();
761 TopLoc_Location loc;
cf152970 762 Sub0.Location(loc);
763 if (NewShapesMap.Contains(Sub0)) isAssembly = Standard_True;
7fd59977 764 }
765
cf152970 766 // if(nbComponents>0) isAssembly = Standard_True;
767
768 // check whether it has associated external ref
7fd59977 769 TColStd_SequenceOfHAsciiString SHAS;
cf152970 770 if (ShapePDMap.IsBound(S) && PDFileMap.IsBound(ShapePDMap.Find(S))) {
771 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(ShapePDMap.Find(S));
772 if (!EF.IsNull()) {
7fd59977 773 // (store information on extern refs in the document)
774 SHAS.Append(EF->GetName());
775 // if yes, just return corresponding label
cf152970 776 if (!EF->GetLabel().IsNull()) {
777 // but if components >0, ignore extern ref!
778 if (nbComponents <= 0) {
779 ShapeLabelMap.Bind(S, EF->GetLabel());
780 STool->SetExternRefs(EF->GetLabel(), SHAS);
781 return EF->GetLabel();
782 }
7fd59977 783 }
0797d9d3 784#ifdef OCCT_DEBUG
cf152970 785 if (!EF->GetLabel().IsNull())
7fd59977 786 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
cf152970 787 else if (nbComponents <= 0)
788 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
7fd59977 789#endif
790 }
791 }
cf152970 792
7fd59977 793 // add compound either as a whole,
cf152970 794 if (!isAssembly) {
795 TDF_Label L = STool->AddShape(S, Standard_False);
796 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
797 ShapeLabelMap.Bind(S, L);
7fd59977 798 return L;
799 }
cf152970 800
7fd59977 801 // or as assembly, component-by-component
802 TDF_Label L = STool->NewShape();
63cdf48e 803 nbComponents = 0;
cf152970 804 for (it.Initialize(S); it.More(); it.Next(), nbComponents++) {
7fd59977 805 TopoDS_Shape Sub0 = it.Value();
806 TopLoc_Location loc;
cf152970 807 Sub0.Location(loc);
808 TDF_Label subL = AddShape(Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap);
809 if (!subL.IsNull()) {
810 TDF_Label instL = STool->AddComponent(L, subL, it.Value().Location());
63cdf48e 811 ShapeLabelMap.Bind(it.Value(), instL);
7fd59977 812 }
813 }
cf152970 814 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
815 ShapeLabelMap.Bind(S, L);
7fd59977 816 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
817
818 return L;
819}
820
821//=======================================================================
822//function : ReadExternFile
823//purpose :
824//=======================================================================
825
cf152970 826Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile(const Standard_CString file,
827 const Standard_CString fullname,
828 Handle(TDocStd_Document)& doc)
7fd59977 829{
830 // if the file is already read, associate it with SDR
cf152970 831 if (myFiles.IsBound(file)) {
832 return myFiles.ChangeFind(file);
7fd59977 833 }
834
0797d9d3 835#ifdef OCCT_DEBUG
7fd59977 836 cout << "Reading extern file: " << fullname << endl;
837#endif
cf152970 838
7fd59977 839 // create new WorkSession and Reader
840 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
cf152970 841 newWS->SelectNorm("STEP");
842 STEPControl_Reader sr(newWS, Standard_False);
843
7fd59977 844 // start to fill the resulting ExternFile structure
845 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
cf152970 846 EF->SetWS(newWS);
847 EF->SetName(new TCollection_HAsciiString(file));
848
7fd59977 849 // read file
cf152970 850 EF->SetLoadStatus(sr.ReadFile(fullname));
851
7fd59977 852 // transfer in single-result mode
cf152970 853 if (EF->GetLoadStatus() == IFSelect_RetDone) {
7fd59977 854 TDF_LabelSequence labels;
cf152970 855 EF->SetTransferStatus(Transfer(sr, 0, doc, labels, Standard_True));
856 if (labels.Length() > 0) EF->SetLabel(labels.Value(1));
7fd59977 857 }
cf152970 858
7fd59977 859 // add read file to dictionary
cf152970 860 myFiles.Bind(file, EF);
861
7fd59977 862 return EF;
863}
864
7fd59977 865//=======================================================================
866//function : findStyledSR
867//purpose : auxilary
868//=======================================================================
cf152970 869static void findStyledSR(const Handle(StepVisual_StyledItem) &style,
870 Handle(StepShape_ShapeRepresentation)& aSR)
7fd59977 871{
872 // search Shape Represenatation for component styled item
cf152970 873 for (Standard_Integer j = 1; j <= style->NbStyles(); j++) {
874 Handle(StepVisual_PresentationStyleByContext) PSA =
875 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue(j));
876 if (PSA.IsNull())
7fd59977 877 continue;
878 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
cf152970 879 Handle(StepShape_ShapeRepresentation) aCurrentSR =
7fd59977 880 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
cf152970 881 if (aCurrentSR.IsNull())
7fd59977 882 continue;
883 aSR = aCurrentSR;
cf152970 884 break;
7fd59977 885 }
886}
887
888
889//=======================================================================
890//function : ReadColors
891//purpose :
892//=======================================================================
893
cf152970 894Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSession) &WS,
895 Handle(TDocStd_Document)& Doc,
896 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 897{
cf152970 898 STEPConstruct_Styles Styles(WS);
899 if (!Styles.LoadStyles()) {
0797d9d3 900#ifdef OCCT_DEBUG
7fd59977 901 cout << "Warning: no styles are found in the model" << endl;
902#endif
903 return Standard_False;
904 }
905 // searching for invisible items in the model
906 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
cf152970 907 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
908
909 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
910 if (CTool.IsNull()) return Standard_False;
63cdf48e 911 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
912 if (STool.IsNull()) return Standard_False;
7fd59977 913
914 // parse and search for color attributes
915 Standard_Integer nb = Styles.NbStyles();
cf152970 916 for (Standard_Integer i = 1; i <= nb; i++) {
917 Handle(StepVisual_StyledItem) style = Styles.Style(i);
918 if (style.IsNull()) continue;
919
7fd59977 920 Standard_Boolean IsVisible = Standard_True;
921 // check the visibility of styled item.
cf152970 922 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
923 if (style != aHSeqOfInvisStyle->Value(si))
7fd59977 924 continue;
925 // found that current style is invisible.
7fd59977 926 IsVisible = Standard_False;
927 break;
928 }
929
930 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
931 // check if it is component style
932 Standard_Boolean IsComponent = Standard_False;
cf152970 933 if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, IsComponent) && IsVisible)
7fd59977 934 continue;
cf152970 935
7fd59977 936 // find shape
25e59720 937 NCollection_Vector<Handle(Standard_Transient)> anItems;
d658f275 938 if (!style->Item().IsNull()) {
939 anItems.Append(style->Item());
940 }
cf152970 941 else if (!style->ItemAP242().Representation().IsNull()) {
d658f275 942 //special case for AP242: item can be Reprsentation
943 Handle(StepRepr_Representation) aRepr = style->ItemAP242().Representation();
7856b126 944 for (Standard_Integer j = 1; j <= aRepr->Items()->Length(); j++)
945 anItems.Append(aRepr->Items()->Value(j));
d658f275 946 }
947 for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
cf152970 948 TopoDS_Shape S = STEPConstruct::FindShape(Styles.TransientProcess(),
949 Handle(StepRepr_RepresentationItem)::DownCast(anItems.Value(itemIt)));
d658f275 950 Standard_Boolean isSkipSHUOstyle = Standard_False;
951 // take shape with real location.
cf152970 952 while (IsComponent) {
d658f275 953 // take SR of NAUO
954 Handle(StepShape_ShapeRepresentation) aSR;
cf152970 955 findStyledSR(style, aSR);
d658f275 956 // search for SR along model
957 if (aSR.IsNull())
7fd59977 958 break;
cf152970 959 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
d658f275 960 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
961 for (subs.Start(); subs.More(); subs.Next()) {
962 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
cf152970 963 if (aSDR.IsNull())
d658f275 964 continue;
965 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
cf152970 966 Handle(StepRepr_ProductDefinitionShape) PDS =
d658f275 967 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
cf152970 968 if (PDS.IsNull())
d658f275 969 continue;
970 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
cf152970 971
972 Handle(StepRepr_AssemblyComponentUsage) ACU =
d658f275 973 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
aff18753 974 if (ACU.IsNull())
975 continue;
d658f275 976 // PTV 10.02.2003 skip styled item that refer to SHUO
977 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
978 isSkipSHUOstyle = Standard_True;
979 break;
980 }
981 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
982 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
cf152970 983 if (NAUO.IsNull())
d658f275 984 continue;
cf152970 985
d658f275 986 TopoDS_Shape aSh;
987 // PTV 10.02.2003 to find component of assembly CORRECTLY
cf152970 988 STEPConstruct_Tool Tool(WS);
989 TDF_Label aShLab = FindInstance(NAUO, CTool->ShapeTool(), Tool, ShapeLabelMap);
d658f275 990 aSh = CTool->ShapeTool()->GetShape(aShLab);
991 if (!aSh.IsNull()) {
992 S = aSh;
993 break;
994 }
7fd59977 995 }
d658f275 996 break;
997 }
998 if (isSkipSHUOstyle)
999 continue; // skip styled item which refer to SHUO
cf152970 1000
1001 if (S.IsNull())
d658f275 1002 continue;
cf152970 1003
63cdf48e 1004 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !IsVisible)
1005 {
1006 TDF_Label aL;
1007 Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True);
1008 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull())
1009 {
1010 Quantity_Color aSCol, aBCol, aCCol;
1011 if (!SurfCol.IsNull())
1012 Styles.DecodeColor(SurfCol, aSCol);
1013 if (!BoundCol.IsNull())
1014 Styles.DecodeColor(BoundCol, aBCol);
1015 if (!CurveCol.IsNull())
1016 Styles.DecodeColor(CurveCol, aCCol);
1017 if (isFound)
1018 {
1019 if (!SurfCol.IsNull())
1020 CTool->SetColor(aL, aSCol, XCAFDoc_ColorSurf);
1021 if (!BoundCol.IsNull())
1022 CTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
1023 if (!CurveCol.IsNull())
1024 CTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
1025 }
1026 else
1027 {
1028 for (TopoDS_Iterator it(S); it.More(); it.Next())
1029 {
1030 TDF_Label aL1;
1031 if (STool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
1032 {
1033 if (!SurfCol.IsNull())
1034 CTool->SetColor(aL1, aSCol, XCAFDoc_ColorSurf);
1035 if (!BoundCol.IsNull())
1036 CTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
1037 if (!CurveCol.IsNull())
1038 CTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
1039 }
1040 }
1041 }
1042 }
1043 if (!IsVisible)
1044 {
1045 // sets the invisibility for shape.
1046 if (isFound)
1047 CTool->SetVisibility(aL, Standard_False);
1048 }
7fd59977 1049 }
7fd59977 1050 }
1051 }
1052 CTool->ReverseChainsOfTreeNodes();
1053 return Standard_True;
1054}
1055
1056//=======================================================================
1057//function : GetLabelFromPD
1058//purpose :
1059//=======================================================================
1060
cf152970 1061static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1062 const Handle(XCAFDoc_ShapeTool) &STool,
1063 const Handle(Transfer_TransientProcess) &TP,
1064 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1065 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
7fd59977 1066{
1067 TDF_Label L;
cf152970 1068 if (PDFileMap.IsBound(PD)) {
1069 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1070 if (!EF.IsNull()) {
7fd59977 1071 L = EF->GetLabel();
cf152970 1072 if (!L.IsNull()) return L;
7fd59977 1073 }
1074 }
1075
1076 TopoDS_Shape S;
1077 Handle(Transfer_Binder) binder = TP->Find(PD);
cf152970 1078 if (binder.IsNull() || !binder->HasResult()) return L;
1079 S = TransferBRep::ShapeResult(TP, binder);
1080 if (S.IsNull()) return L;
1081
1082 if (ShapeLabelMap.IsBound(S))
1083 L = ShapeLabelMap.Find(S);
1084 if (L.IsNull())
1085 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
7fd59977 1086 return L;
1087}
1088
1089//=======================================================================
1090//function : FindInstance
1091//purpose :
1092//=======================================================================
1093
cf152970 1094TDF_Label STEPCAFControl_Reader::FindInstance(const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1095 const Handle(XCAFDoc_ShapeTool) &STool,
1096 const STEPConstruct_Tool &Tool,
1097 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
7fd59977 1098{
1099 TDF_Label L;
cf152970 1100
7fd59977 1101 // get shape resulting from CDSR (in fact, only location is interesting)
1102 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1103 Handle(Transfer_Binder) binder = TP->Find(NAUO);
cf152970 1104 if (binder.IsNull() || !binder->HasResult()) {
0797d9d3 1105#ifdef OCCT_DEBUG
7fd59977 1106 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1107#endif
1108 return L;
1109 }
cf152970 1110
1111 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1112 if (S.IsNull()) {
0797d9d3 1113#ifdef OCCT_DEBUG
7fd59977 1114 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1115#endif
1116 return L;
1117 }
1118
63cdf48e 1119 if (ShapeLabelMap.IsBound(S))
1120 L = ShapeLabelMap(S);
1121 else
1122 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1123
7fd59977 1124 return L;
1125}
1126
1127//=======================================================================
1128//function : ReadNames
1129//purpose :
1130//=======================================================================
1131
cf152970 1132Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS,
1133 Handle(TDocStd_Document)& Doc,
1134 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1135 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 1136{
1137 // get starting data
7f56eba8 1138 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1139 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1140 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
cf152970 1141 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1142 if (STool.IsNull()) return Standard_False;
1143 STEPConstruct_Tool Tool(WS);
7fd59977 1144
1145 // iterate on model to find all SDRs and CDSRs
1146 Standard_Integer nb = Model->NbEntities();
1147 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
cf152970 1148 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
7fd59977 1149 Handle(TCollection_HAsciiString) name;
1150 TDF_Label L;
1151 for (Standard_Integer i = 1; i <= nb; i++) {
1152 Handle(Standard_Transient) enti = Model->Value(i);
1153
1154 // get description of NAUO
cf152970 1155 if (enti->DynamicType() == tNAUO) {
7fd59977 1156 L.Nullify();
cf152970 1157 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
9c3cce7a 1158 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
cf152970 1159 if (NAUO.IsNull()) continue;
7fd59977 1160 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1161 for (subs.Start(); subs.More(); subs.Next()) {
cf152970 1162 Handle(StepRepr_ProductDefinitionShape) PDS =
7fd59977 1163 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
cf152970 1164 if (PDS.IsNull()) continue;
7fd59977 1165 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
cf152970 1166 if (PDR.IsNull()) continue;
1167 if (PDR->HasDescription() &&
1168 PDR->Description()->UsefullLength() > 0) name = PDR->Description();
1169 else if (!PDR->Name().IsNull() && PDR->Name()->UsefullLength() > 0) name = PDR->Name();
1170 else if (!PDR->Id().IsNull()) name = PDR->Id();
ab4a5554 1171 else name = new TCollection_HAsciiString;
7fd59977 1172 }
1173 // find proper label
cf152970 1174 L = FindInstance(NAUO, STool, Tool, ShapeLabelMap);
1175 if (L.IsNull()) continue;
e3249d8e 1176
1177 TCollection_ExtendedString str = convertName (name->String());
cf152970 1178 TDataStd_Name::Set(L, str);
7fd59977 1179 }
1180
1181 // for PD get name of associated product
cf152970 1182 if (enti->DynamicType() == tPD) {
7fd59977 1183 L.Nullify();
cf152970 1184 Handle(StepBasic_ProductDefinition) PD =
9c3cce7a 1185 Handle(StepBasic_ProductDefinition)::DownCast(enti);
cf152970 1186 if (PD.IsNull()) continue;
9c3cce7a 1187 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1188 if (Prod.IsNull())
1189 name = new TCollection_HAsciiString;
cf152970 1190 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
9c3cce7a 1191 name = Prod->Name();
cf152970 1192 else if (!Prod->Id().IsNull())
9c3cce7a 1193 name = Prod->Id();
cf152970 1194 else
9c3cce7a 1195 name = new TCollection_HAsciiString;
cf152970 1196 L = GetLabelFromPD(PD, STool, TP, PDFileMap, ShapeLabelMap);
1197 if (L.IsNull()) continue;
e3249d8e 1198 TCollection_ExtendedString str = convertName (name->String());
cf152970 1199 TDataStd_Name::Set(L, str);
7fd59977 1200 }
1201 // set a name to the document
e3249d8e 1202 //TCollection_ExtendedString str = convertName (name->String());
7fd59977 1203 //TDataStd_Name::Set ( L, str );
1204 }
1205
1206 return Standard_True;
1207}
1208
1209//=======================================================================
1210//function : GetLabelFromPD
1211//purpose :
1212//=======================================================================
1213
cf152970 1214static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1215 const Handle(XCAFDoc_ShapeTool) &STool,
1216 const STEPConstruct_ValidationProps &Props,
1217 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1218 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
7fd59977 1219{
1220 TDF_Label L;
cf152970 1221 if (PDFileMap.IsBound(PD)) {
1222 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1223 if (!EF.IsNull()) {
7fd59977 1224 L = EF->GetLabel();
cf152970 1225 if (!L.IsNull()) return L;
7fd59977 1226 }
1227 }
cf152970 1228 TopoDS_Shape S = Props.GetPropShape(PD);
1229 if (S.IsNull()) return L;
1230 if (ShapeLabelMap.IsBound(S))
1231 L = ShapeLabelMap.Find(S);
1232 if (L.IsNull())
1233 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
7fd59977 1234 return L;
1235}
1236
1237//=======================================================================
1238//function : ReadValProps
1239//purpose :
1240//=======================================================================
1241
cf152970 1242Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_WorkSession) &WS,
1243 Handle(TDocStd_Document)& Doc,
1244 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1245 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 1246{
1247 // get starting data
7f56eba8 1248 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1249 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
cf152970 1250 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1251 if (STool.IsNull()) return Standard_False;
7fd59977 1252
1253 // load props from the STEP model
1254 TColStd_SequenceOfTransient props;
cf152970 1255 STEPConstruct_ValidationProps Props(WS);
1256 if (!Props.LoadProps(props)) {
0797d9d3 1257#ifdef OCCT_DEBUG
7fd59977 1258 cout << "Warning: no validation props found in the model" << endl;
1259#endif
1260 return Standard_False;
1261 }
1262
1263 // interpret props one by one
cf152970 1264 for (Standard_Integer i = 1; i <= props.Length(); i++) {
1265 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1266 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(props.Value(i));
1267 if (PDR.IsNull()) continue;
7fd59977 1268
1269 TDF_Label L;
1270
1271 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1272 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1273 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
cf152970 1274 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
7fd59977 1275 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
cf152970 1276 if (PDS.IsNull()) continue;
7fd59977 1277 // find corresponding NAUO
1278 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1279 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1280 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
cf152970 1281 if (subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
7fd59977 1282 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1283 }
cf152970 1284 if (!NAUO.IsNull()) {
1285 L = FindInstance(NAUO, STool, WS, ShapeLabelMap);
1286 if (L.IsNull()) continue;
7fd59977 1287 }
1288 else {
1289 // find corresponding ProductDefinition:
1290 Handle(StepBasic_ProductDefinition) ProdDef;
1291 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1292 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
cf152970 1293 if (subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)))
7fd59977 1294 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1295 }
cf152970 1296 if (ProdDef.IsNull()) continue;
1297 L = GetLabelFromPD(ProdDef, STool, Props, PDFileMap, ShapeLabelMap);
7fd59977 1298 }
1299 }
1300
cf152970 1301 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
7fd59977 1302 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
cf152970 1303 if (SA.IsNull()) continue;
7fd59977 1304 // find ShapeRepresentation
1305 Handle(StepShape_ShapeRepresentation) SR;
1306 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
cf152970 1307 for (subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1308 Handle(StepRepr_PropertyDefinition) PropD1 =
7fd59977 1309 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
cf152970 1310 if (PropD1.IsNull()) continue;
7fd59977 1311 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
cf152970 1312 for (subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
7fd59977 1313 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1314 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
cf152970 1315 if (SDR.IsNull()) continue;
7fd59977 1316 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1317 }
1318 }
cf152970 1319 if (SR.IsNull()) continue;
7fd59977 1320 Handle(Transfer_Binder) binder;
cf152970 1321 for (Standard_Integer ir = 1; ir <= SR->NbItems() && binder.IsNull(); ir++) {
1322 if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1323 Handle(StepShape_SolidModel) SM =
7fd59977 1324 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1325 binder = TP->Find(SM);
1326 }
cf152970 1327 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
7fd59977 1328 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1329 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1330 binder = TP->Find(SBSM);
1331 }
cf152970 1332 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
7fd59977 1333 Handle(StepShape_GeometricSet) GS =
1334 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1335 binder = TP->Find(GS);
1336 }
1337 }
cf152970 1338 if (binder.IsNull() || !binder->HasResult()) continue;
7fd59977 1339 TopoDS_Shape S;
cf152970 1340 S = TransferBRep::ShapeResult(TP, binder);
1341 if (S.IsNull()) continue;
1342 if (ShapeLabelMap.IsBound(S))
1343 L = ShapeLabelMap.Find(S);
1344 if (L.IsNull())
1345 STool->Search(S, L, Standard_True, Standard_True, Standard_True);
7fd59977 1346 }
1347 }
1348
cf152970 1349 if (L.IsNull()) continue;
1350
7fd59977 1351 // decode validation properties
1352 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
cf152970 1353 for (Standard_Integer j = 1; j <= rep->NbItems(); j++) {
7fd59977 1354 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1355 Standard_Boolean isArea;
1356 Standard_Real val;
1357 gp_Pnt pos;
cf152970 1358 if (Props.GetPropReal(ent, val, isArea)) {
1359 if (isArea) XCAFDoc_Area::Set(L, val);
1360 else XCAFDoc_Volume::Set(L, val);
7fd59977 1361 }
cf152970 1362 else if (Props.GetPropPnt(ent, rep->ContextOfItems(), pos)) {
1363 XCAFDoc_Centroid::Set(L, pos);
7fd59977 1364 }
1365 }
1366 }
1367 return Standard_True;
1368}
1369
1370//=======================================================================
1371//function : ReadLayers
1372//purpose :
1373//=======================================================================
1374
cf152970 1375Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSession) &WS,
1376 Handle(TDocStd_Document)& Doc) const
7fd59977 1377{
7f56eba8 1378 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1379 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1380 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
cf152970 1381 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1382 if (STool.IsNull()) return Standard_False;
1383 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
1384 if (LTool.IsNull()) return Standard_False;
1385
7fd59977 1386 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1387 Standard_Integer nb = Model->NbEntities();
1388 Handle(TCollection_HAsciiString) name;
cf152970 1389
1390 for (Standard_Integer i = 1; i <= nb; i++) {
7fd59977 1391 Handle(Standard_Transient) enti = Model->Value(i);
cf152970 1392 if (!enti->IsKind(tSVPLA)) continue;
1393 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
7fd59977 1394 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1209c1b9 1395 if (SVPLA->AssignedItems().IsNull())
1396 continue;
cf152970 1397
7fd59977 1398 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1399 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
cf152970 1400 TCollection_ExtendedString aLayerName(hName->String());
1401
7fd59977 1402 // find a target shape and its label in the document
cf152970 1403 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++) {
7fd59977 1404 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
cf152970 1405 Handle(Transfer_Binder) binder = TP->Find(LI.Value());
1406 if (binder.IsNull() || !binder->HasResult()) continue;
1407
1408 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1409 if (S.IsNull()) continue;
1410
7fd59977 1411 TDF_Label shL;
cf152970 1412 if (!STool->Search(S, shL, Standard_True, Standard_True, Standard_True)) continue;
1413 LTool->SetLayer(shL, aLayerName);
7fd59977 1414 }
cf152970 1415
7fd59977 1416 // check invisibility
1417 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1418 for (subs.Start(); subs.More(); subs.Next()) {
cf152970 1419 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue;
0797d9d3 1420#ifdef OCCT_DEBUG
cf152970 1421 cout << "\tLayer \"" << aLayerName << "\" is invisible" << endl;
7fd59977 1422#endif
1423 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1424 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
ad67e367 1425 TDataStd_UAttribute::Set (InvLayerLab, XCAFDoc::InvisibleGUID());
7fd59977 1426 }
1427 }
1428 return Standard_True;
1429}
1430
1431//=======================================================================
1432//function : ReadSHUOs
1433//purpose :
1434//=======================================================================
1435
cf152970 1436static Standard_Boolean findNextSHUOlevel(const Handle(XSControl_WorkSession) &WS,
1437 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1438 const Handle(XCAFDoc_ShapeTool)& STool,
1439 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1440 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1441 TDF_LabelSequence& aLabels)
7fd59977 1442{
1443 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1444 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1445 for (subs.Start(); subs.More(); subs.Next()) {
1446 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1447 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1448 break;
1449 }
1450 }
1451 if (subSHUO.IsNull())
1452 return Standard_False;
cf152970 1453
a9dde4a3 1454 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
7fd59977 1455 if (NUNAUO.IsNull())
1456 return Standard_False;
cf152970 1457 // Handle(Interface_InterfaceModel) Model = WS->Model();
1458 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1459 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1460 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1461 // if ( binder.IsNull() || ! binder->HasResult() )
1462 // return Standard_False;
1463 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1464 // get label of NAUO next level
7fd59977 1465 TDF_Label NULab;
cf152970 1466 STEPConstruct_Tool Tool(WS);
1467 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1468 // STool->Search(NUSh, NUlab);
7fd59977 1469 if (NULab.IsNull())
1470 return Standard_False;
cf152970 1471 aLabels.Append(NULab);
7fd59977 1472 // and check by recurse.
cf152970 1473 findNextSHUOlevel(WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels);
7fd59977 1474 return Standard_True;
1475}
1476
1477
1478//=======================================================================
1479//function : setSHUOintoDoc
1480//purpose : auxilary
1481//=======================================================================
cf152970 1482static TDF_Label setSHUOintoDoc(const Handle(XSControl_WorkSession) &WS,
1483 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1484 const Handle(XCAFDoc_ShapeTool)& STool,
1485 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1486 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
7fd59977 1487{
1488 TDF_Label aMainLabel;
1489 // get upper usage NAUO from SHUO.
1490 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1491 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
a9dde4a3 1492 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
cf152970 1493 if (UUNAUO.IsNull() || NUNAUO.IsNull()) {
0797d9d3 1494#ifdef OCCT_DEBUG
cf152970 1495 cout << "Warning: " << __FILE__ << ": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
7fd59977 1496#endif
1497 return aMainLabel;
1498 }
cf152970 1499 // Handle(Interface_InterfaceModel) Model = WS->Model();
1500 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1501 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1502 // TopoDS_Shape UUSh, NUSh;
1503 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1504 // if ( binder.IsNull() || ! binder->HasResult() )
1505 // return aMainLabel;
1506 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1507 // binder = TP->Find(NUNAUO);
1508 // if ( binder.IsNull() || ! binder->HasResult() )
1509 // return aMainLabel;
1510 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1511
1512 // get first labels for first SHUO attribute
7fd59977 1513 TDF_Label UULab, NULab;
cf152970 1514 STEPConstruct_Tool Tool(WS);
1515 UULab = STEPCAFControl_Reader::FindInstance(UUNAUO, STool, Tool, ShapeLabelMap);
1516 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1517
1518 // STool->Search(UUSh, UULab);
1519 // STool->Search(NUSh, NULab);
7fd59977 1520 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1521 //create sequence fo labels to set SHUO structure into the document
1522 TDF_LabelSequence ShuoLabels;
cf152970 1523 ShuoLabels.Append(UULab);
1524 ShuoLabels.Append(NULab);
7fd59977 1525 // add all other labels of sub SHUO entities
cf152970 1526 findNextSHUOlevel(WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels);
7fd59977 1527 // last accord for SHUO
1528 Handle(XCAFDoc_GraphNode) anSHUOAttr;
cf152970 1529 if (STool->SetSHUO(ShuoLabels, anSHUOAttr))
7fd59977 1530 aMainLabel = anSHUOAttr->Label();
cf152970 1531
7fd59977 1532 return aMainLabel;
1533}
1534
1535
1536//=======================================================================
1537//function : ReadSHUOs
1538//purpose :
1539//=======================================================================
1540
cf152970 1541Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(const Handle(XSControl_WorkSession) &WS,
1542 Handle(TDocStd_Document)& Doc,
1543 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1544 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 1545{
1546 // the big part code duplication from ReadColors.
1547 // It is possible to share this code functionality, just to decide how ???
cf152970 1548 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
7fd59977 1549 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
cf152970 1550
1551 STEPConstruct_Styles Styles(WS);
1552 if (!Styles.LoadStyles()) {
0797d9d3 1553#ifdef OCCT_DEBUG
7fd59977 1554 cout << "Warning: no styles are found in the model" << endl;
1555#endif
1556 return Standard_False;
1557 }
1558 // searching for invisible items in the model
1559 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
cf152970 1560 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
7fd59977 1561 // parse and search for color attributes
1562 Standard_Integer nb = Styles.NbStyles();
cf152970 1563 for (Standard_Integer i = 1; i <= nb; i++) {
1564 Handle(StepVisual_StyledItem) style = Styles.Style(i);
1565 if (style.IsNull()) continue;
1566
7fd59977 1567 Standard_Boolean IsVisible = Standard_True;
1568 // check the visibility of styled item.
cf152970 1569 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
1570 if (style != aHSeqOfInvisStyle->Value(si))
7fd59977 1571 continue;
1572 // found that current style is invisible.
0797d9d3 1573#ifdef OCCT_DEBUG
7fd59977 1574 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1575#endif
1576 IsVisible = Standard_False;
1577 break;
1578 }
1579
1580 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1581 // check if it is component style
1582 Standard_Boolean IsComponent = Standard_False;
cf152970 1583 if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, IsComponent) && IsVisible)
7fd59977 1584 continue;
1585 if (!IsComponent)
1586 continue;
1587 Handle(StepShape_ShapeRepresentation) aSR;
cf152970 1588 findStyledSR(style, aSR);
7fd59977 1589 // search for SR along model
cf152970 1590 if (aSR.IsNull())
7fd59977 1591 continue;
cf152970 1592 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
7fd59977 1593 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1594 for (subs.Start(); subs.More(); subs.Next()) {
1595 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
cf152970 1596 if (aSDR.IsNull())
7fd59977 1597 continue;
1598 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
cf152970 1599 Handle(StepRepr_ProductDefinitionShape) PDS =
7fd59977 1600 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
cf152970 1601 if (PDS.IsNull())
7fd59977 1602 continue;
1603 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1604 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1605 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
cf152970 1606 if (SHUO.IsNull())
7fd59977 1607 continue;
cf152970 1608
7fd59977 1609 // set the SHUO structure to the document
cf152970 1610 TDF_Label aLabelForStyle = setSHUOintoDoc(WS, SHUO, STool, PDFileMap, ShapeLabelMap);
1611 if (aLabelForStyle.IsNull()) {
0797d9d3 1612#ifdef OCCT_DEBUG
cf152970 1613 cout << "Warning: " << __FILE__ << ": coudnot create SHUO structure in the document" << endl;
7fd59977 1614#endif
1615 continue;
1616 }
1617 // now set the style to the SHUO main label.
cf152970 1618 if (!SurfCol.IsNull()) {
7fd59977 1619 Quantity_Color col;
cf152970 1620 Styles.DecodeColor(SurfCol, col);
1621 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorSurf);
7fd59977 1622 }
cf152970 1623 if (!BoundCol.IsNull()) {
7fd59977 1624 Quantity_Color col;
cf152970 1625 Styles.DecodeColor(BoundCol, col);
1626 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
7fd59977 1627 }
cf152970 1628 if (!CurveCol.IsNull()) {
7fd59977 1629 Quantity_Color col;
cf152970 1630 Styles.DecodeColor(CurveCol, col);
1631 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
7fd59977 1632 }
cf152970 1633 if (!IsVisible)
7fd59977 1634 // sets the invisibility for shape.
cf152970 1635 CTool->SetVisibility(aLabelForStyle, Standard_False);
1636
7fd59977 1637 } // end search SHUO by SDR
1638 } // end iterates on styles
cf152970 1639
7fd59977 1640 return Standard_True;
1641}
1642
1c9d3225 1643//=======================================================================
7fd59977 1644//function : GetMassConversionFactor
1645//purpose :
1646//=======================================================================
1647static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
cf152970 1648 Standard_Real& afact)
7fd59977 1649{
cf152970 1650 afact = 1.;
1651 if (!NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) return Standard_False;
7fd59977 1652 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1653 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1654 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1655 afact = MWUCBU->ValueComponent();
1656 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
cf152970 1657 if (anUnit2.CaseNum(anUnit2.Value()) == 1) {
7fd59977 1658 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
cf152970 1659 if (NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
7fd59977 1660 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
cf152970 1661 if (SU->Name() == StepBasic_sunGram) {
1662 if (SU->HasPrefix())
1663 afact *= STEPConstruct_UnitContext::ConvertSiPrefix(SU->Prefix());
7fd59977 1664 }
1665 }
1666 }
1667 return Standard_True;
1668}
1209c1b9 1669
5df609e7 1670//=======================================================================
0b622d67 1671//function : readPMIPresentation
1672//purpose : read polyline or tessellated presentation for
1673// (Annotation_Curve_Occurrence or Draughting_Callout)
5df609e7 1674//=======================================================================
0b622d67 1675Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
cf152970 1676 const Handle(XSControl_TransferReader)& theTR,
1677 const Standard_Real theFact,
1678 TopoDS_Shape& thePresentation,
1679 Handle(TCollection_HAsciiString)& thePresentName,
1680 Bnd_Box& theBox)
5df609e7 1681{
aff18753 1682 if (thePresentEntity.IsNull())
1683 return Standard_False;
5df609e7 1684 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1209c1b9 1685 Handle(StepVisual_AnnotationOccurrence) anAO;
5df609e7 1686 NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
1209c1b9 1687 if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
5df609e7 1688 {
1209c1b9 1689 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
1690 if (!anAO.IsNull()) {
1691 thePresentName = anAO->Name();
1692 anAnnotations.Append(anAO);
1693 }
5df609e7 1694 }
0b622d67 1695 else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
5df609e7 1696 {
1697 Handle(StepVisual_DraughtingCallout) aDCallout =
0b622d67 1698 Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
1699 thePresentName = aDCallout->Name();
1209c1b9 1700 for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
1701 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
1702 if (!anAO.IsNull())
5df609e7 1703 {
1209c1b9 1704 anAnnotations.Append(anAO);
5df609e7 1705 continue;
1706 }
0b622d67 1707 Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
5df609e7 1708 aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
0b622d67 1709 if (!aTesselation.IsNull())
5df609e7 1710 anAnnotations.Append(aTesselation);
1711 }
1712 }
1713
1714 if (!anAnnotations.Length())
0b622d67 1715 return Standard_False;
5df609e7 1716
1717
1718 BRep_Builder aB;
0b622d67 1719 TopoDS_Compound aResAnnotation;
5df609e7 1720 aB.MakeCompound(aResAnnotation);
1721
0b622d67 1722 Standard_Integer i = 0;
5df609e7 1723 Bnd_Box aBox;
0b622d67 1724 Standard_Integer nbShapes = 0;
1725 for (; i < anAnnotations.Length(); i++)
5df609e7 1726 {
1727 Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
1209c1b9 1728 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
5df609e7 1729 TopoDS_Shape anAnnotationShape;
1209c1b9 1730 if (!anAO.IsNull())
5df609e7 1731 {
1209c1b9 1732 Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
0b622d67 1733 anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
1734 if (anAnnotationShape.IsNull())
5df609e7 1735 {
1736 Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
0b622d67 1737 if (!binder.IsNull() && binder->HasResult()) {
1738 anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
5df609e7 1739 }
1740 }
1741 }
fe0d928d 1742 //case of tessellated entities
5df609e7 1743 else
1744 {
1745 Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
0b622d67 1746 if (aTessItem.IsNull())
5df609e7 1747 continue;
1748 Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
0b622d67 1749 if (aTessSet.IsNull())
5df609e7 1750 continue;
b0cef606 1751 NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
5df609e7 1752 Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
1753 Handle(StepVisual_TessellatedCurveSet) aTessCurve;
1754 for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++)
1755 {
1756 aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
1757 }
0b622d67 1758 if (aTessCurve.IsNull())
5df609e7 1759 continue;
1760 Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
0b622d67 1761 if (aCoordList.IsNull())
5df609e7 1762 continue;
1763 Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
1764
1765 if (aPoints.IsNull() || aPoints->Length() == 0)
1766 continue;
1767 NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves();
1768 Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
1769 TopoDS_Compound aComp;
1770 aB.MakeCompound(aComp);
0b622d67 1771
5df609e7 1772 Standard_Integer k = 0;
0b622d67 1773 for (; k < aNbC; k++)
5df609e7 1774 {
1775 Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
1776 TopoDS_Wire aCurW;
1777 aB.MakeWire(aCurW);
1778
0b622d67 1779 for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
5df609e7 1780 {
1781 Standard_Integer ind = anIndexes->Value(n);
1782 Standard_Integer indnext = anIndexes->Value(n + 1);
0b622d67 1783 if (ind > aPoints->Length() || indnext > aPoints->Length())
5df609e7 1784 continue;
0b622d67 1785 gp_Pnt aP1(aPoints->Value(ind) * theFact);
1786 gp_Pnt aP2(aPoints->Value(indnext) * theFact);
5df609e7 1787 BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
0b622d67 1788 if (aMaker.IsDone())
5df609e7 1789 {
1790 TopoDS_Edge aCurE = aMaker.Edge();
1791 aB.Add(aCurW, aCurE);
1792 }
1793 }
1794 aB.Add(aComp, aCurW);
1795 }
1796 anAnnotationShape = aComp;
1797 }
0b622d67 1798 if (!anAnnotationShape.IsNull())
5df609e7 1799 {
1800 nbShapes++;
1801 aB.Add(aResAnnotation, anAnnotationShape);
0b622d67 1802 if (i == anAnnotations.Length() - 1)
5df609e7 1803 BRepBndLib::AddClose(anAnnotationShape, aBox);
1804 }
1805 }
0b622d67 1806
1807 thePresentation = aResAnnotation;
1808 theBox = aBox;
1809 return (nbShapes > 0);
1810}
1811
1812//=======================================================================
1813//function : readAnnotationPlane
1814//purpose : read annotation plane
1815//=======================================================================
1816Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
cf152970 1817 gp_Ax2& thePlane)
0b622d67 1818{
1819 if (theAnnotationPlane.IsNull())
1820 return Standard_False;
0b622d67 1821 Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
aff18753 1822 if (aPlaneItem.IsNull())
1823 return Standard_False;
0b622d67 1824 Handle(StepGeom_Axis2Placement3d) aA2P3D;
1825 //retrieve axes from AnnotationPlane
1826 if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
1827 Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
1828 aA2P3D = aPlane->Position();
1829 }
1830 else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
1831 Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
1832 aA2P3D = aBox->Placement().Axis2Placement3d();
1833 }
1834 if (aA2P3D.IsNull())
1835 return Standard_False;
1836
ea6e5378 1837 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
477000eb 1838 thePlane = anAxis->Ax2();
0b622d67 1839 return Standard_True;
1840}
1841
1842//=======================================================================
1843//function : readAnnotation
1844//purpose : read annotation plane and position for given GDT
1845// (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
1846//=======================================================================
cf152970 1847void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
400af1bc 1848 const Handle(Standard_Transient)& theGDT,
0b622d67 1849 const Handle(Standard_Transient)& theDimObject)
1850{
aff18753 1851 if (theGDT.IsNull() || theDimObject.IsNull())
1852 return;
0b622d67 1853 Handle(TCollection_HAsciiString) aPresentName;
1854 TopoDS_Compound aResAnnotation;
1855 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1856 const Interface_Graph& aGraph = aTP->Graph();
1857 // find the proper DraughtingModelItemAssociation
1858 Interface_EntityIterator subs = aGraph.Sharings(theGDT);
1859 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
1860 for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
1861 if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
1862 continue;
1863 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
1864 Handle(TCollection_HAsciiString) aName = aDMIA->Name();
1865 aName->LowerCase();
1866 if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
1867 aDMIA = NULL;
1868 }
1869 }
1870 if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
1871 return;
1872
1873 // calculate units
cf152970 1874 Handle(StepVisual_DraughtingModel) aDModel =
0b622d67 1875 Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
477000eb 1876 XSAlgo::AlgoContainer()->PrepareForTransfer();
1877 STEPControl_ActorRead anActor;
1878 anActor.PrepareUnits(aDModel, aTP);
1879 Standard_Real aFact = UnitsMethods::LengthFactor();
0b622d67 1880
1881 // retrieve AnnotationPlane
1882 Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
1883 if (aDMIAE.IsNull())
1884 return;
1885 gp_Ax2 aPlaneAxes;
1886 subs = aGraph.Sharings(aDMIAE);
1887 Handle(StepVisual_AnnotationPlane) anAnPlane;
1888 for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
1889 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
1890 }
477000eb 1891 Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aPlaneAxes);
0b622d67 1892
1893 // set plane axes to XCAF
1894 if (isHasPlane) {
1895 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
cf152970 1896 Handle(XCAFDimTolObjects_DimensionObject) anObj =
0b622d67 1897 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
1898 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1);
1899 anObj->SetPlane(aPlaneAxes);
1900 }
1901 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
1902 Handle(XCAFDimTolObjects_DatumObject) anObj =
1903 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
1904 anObj->SetPlane(aPlaneAxes);
1905 }
1906 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
1907 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
1908 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
1909 anObj->SetPlane(aPlaneAxes);
1910 }
1911 }
1912
1913 // Retrieve presentation
1914 Bnd_Box aBox;
1915 if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
5df609e7 1916 return;
1917 gp_Pnt aPtext(0., 0., 0.);
f0bf70e8 1918 // if Annotation plane location inside bounding box set it to text position
cf152970 1919 // else set the center of bounding box to text position 0027372
0b622d67 1920 if (!aBox.IsVoid())
5df609e7 1921 {
0b622d67 1922 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1923 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
f0bf70e8 1924 if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
1925 aPtext = aPlaneAxes.Location();
1926 }
1927 else {
1928 aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
1929 }
1930 }
1931 else {
1932 aPtext = aPlaneAxes.Location();
5df609e7 1933 }
1934
1935 // set point to XCAF
1936 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
cf152970 1937 Handle(XCAFDimTolObjects_DimensionObject) anObj =
5df609e7 1938 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
1939 anObj->SetPointTextAttach(aPtext);
1940 anObj->SetPresentation(aResAnnotation, aPresentName);
1941 }
1942 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
1943 Handle(XCAFDimTolObjects_DatumObject) anObj =
1944 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
cf152970 1945 anObj->SetPointTextAttach(aPtext);
1946 anObj->SetPresentation(aResAnnotation, aPresentName);
5df609e7 1947 }
1948 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
1949 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
1950 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
1951 anObj->SetPointTextAttach(aPtext);
1952 anObj->SetPresentation(aResAnnotation, aPresentName);
1953 }
1954 return;
1955}
7fd59977 1956
1957//=======================================================================
b7b2f85a 1958//function : readConnectionPoints
1959//purpose : read connection points for given dimension
1960//=======================================================================
cf152970 1961void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
b7b2f85a 1962 const Handle(Standard_Transient) theGDT,
1963 const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
1964{
aff18753 1965 if (theGDT.IsNull() || theDimObject.IsNull())
1966 return;
b7b2f85a 1967 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1968 const Interface_Graph& aGraph = aTP->Graph();
fe0d928d 1969
cf152970 1970
1971 Standard_Real aFact = 1.;
1972
fe0d928d 1973 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
1974 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
cf152970 1975 Handle(Standard_Transient) anEnt = anIt.Value();
1976 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
1977 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anEnt);
1978 if (!aDCR.IsNull())
1979 aSDR = !aDCR.IsNull() ? aDCR->Representation() : Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anEnt);
fe0d928d 1980 }
cf152970 1981 if (!aSDR.IsNull())
1982 {
1983 XSAlgo::AlgoContainer()->PrepareForTransfer();
1984 STEPControl_ActorRead anActor;
1985 anActor.PrepareUnits(aSDR, aTP);
1986 aFact = UnitsMethods::LengthFactor();
1987 }
1988
b7b2f85a 1989 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1990 // retrieve derived geometry
1991 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
1992 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
1993 if (aDSA.IsNull())
1994 return;
1995 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
1996 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
1997 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
1998 }
1999 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
2000 return;
2001 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
2002 if (aPoint.IsNull()) {
2003 // try Axis2Placement3d.location instead of CartesianPoint
2004 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2005 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
2006 if (anA2P3D.IsNull())
2007 return;
2008 aPoint = anA2P3D->Location();
2009 }
cf152970 2010
b7b2f85a 2011 // set connection point to object
fe0d928d 2012 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
b7b2f85a 2013 theDimObject->SetPoint(aPnt);
2014 }
2015 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2016 // retrieve derived geometry
2017 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
2018 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
2019 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
2020 if (aDSA1.IsNull() && aDSA2.IsNull())
2021 return;
2022 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
2023 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2024 if (!aDSA1.IsNull()) {
2025 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2026 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2027 }
2028 }
2029 if (!aDSA2.IsNull()) {
2030 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2031 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2032 }
2033 }
2034 // first point
2035 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2036 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2037 if (aPoint.IsNull()) {
2038 // try Axis2Placement3d.location instead of CartesianPoint
2039 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2040 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2041 if (!anA2P3D.IsNull())
2042 aPoint = anA2P3D->Location();
2043 }
2044 if (!aPoint.IsNull()) {
2045 // set connection point to object
fe0d928d 2046 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
b7b2f85a 2047 theDimObject->SetPoint(aPnt);
2048 }
2049 }
2050 // second point
2051 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2052 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2053 if (aPoint.IsNull()) {
2054 // try Axis2Placement3d.location instead of CartesianPoint
2055 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2056 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2057 if (!anA2P3D.IsNull())
2058 aPoint = anA2P3D->Location();
2059 }
2060 if (!aPoint.IsNull()) {
2061 // set connection point to object
fe0d928d 2062 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
b7b2f85a 2063 theDimObject->SetPoint2(aPnt);
2064 }
2065 }
2066 }
2067}
2068
2069//=======================================================================
7fd59977 2070//function : ReadDatums
2071//purpose : auxilary
2072//=======================================================================
2073static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
cf152970 2074 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2075 const Interface_Graph &graph,
2076 const Handle(Transfer_TransientProcess) &TP,
2077 const TDF_Label TolerL,
2078 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
7fd59977 2079{
cf152970 2080 if (GTWDR.IsNull()) return Standard_False;
7fd59977 2081 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
cf152970 2082 if (HADR.IsNull()) return Standard_False;
2083 for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) {
7fd59977 2084 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2085 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
cf152970 2086 if (aDatum.IsNull()) continue;
7fd59977 2087 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
cf152970 2088 for (subs4.Start(); subs4.More(); subs4.Next()) {
2089 Handle(StepRepr_ShapeAspectRelationship) SAR =
7fd59977 2090 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
cf152970 2091 if (SAR.IsNull()) continue;
2092 Handle(StepDimTol_DatumFeature) DF =
7fd59977 2093 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
cf152970 2094 if (DF.IsNull()) continue;
7fd59977 2095 Interface_EntityIterator subs5 = graph.Sharings(DF);
2096 Handle(StepRepr_PropertyDefinition) PropDef;
cf152970 2097 for (subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
7fd59977 2098 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2099 }
cf152970 2100 if (PropDef.IsNull()) continue;
7fd59977 2101 Handle(StepShape_AdvancedFace) AF;
2102 subs5 = graph.Sharings(PropDef);
cf152970 2103 for (subs5.Start(); subs5.More(); subs5.Next()) {
2104 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
7fd59977 2105 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
cf152970 2106 if (!SDR.IsNull()) {
7fd59977 2107 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
cf152970 2108 if (!Repr.IsNull() && Repr->NbItems() > 0) {
7fd59977 2109 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2110 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2111 }
2112 }
2113 }
cf152970 2114 if (AF.IsNull()) return Standard_False;
7fd59977 2115 Standard_Integer index = TP->MapIndex(AF);
2116 TopoDS_Shape aSh;
cf152970 2117 if (index > 0) {
7fd59977 2118 Handle(Transfer_Binder) binder = TP->MapItem(index);
2119 aSh = TransferBRep::ShapeResult(binder);
2120 }
cf152970 2121 if (aSh.IsNull()) continue;
7fd59977 2122 TDF_Label shL;
cf152970 2123 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2124 DGTTool->SetDatum(shL, TolerL, PropDef->Name(), PropDef->Description(), aDatum->Identification());
7fd59977 2125 }
2126 }
2127 return Standard_True;
2128}
2129
43d3f6d8 2130//=======================================================================
2131//function : FindShapeIndexForDGT
2132//purpose : auxiliary find shape index in map og imported shapes
2133//=======================================================================
2134static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2135 const Handle(XSControl_WorkSession)& theWS)
2136{
2137 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2138 // try to find index of given entity
2139 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2140 if (anIndex > 0)
2141 return anIndex;
2142 // if theEnt is a geometry item try to find its topological item
2143 const Interface_Graph& aGraph = aTP->Graph();
2144 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2145 for (anIter.Start(); anIter.More(); anIter.Next()) {
2146 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2147 {
2148 anIndex = aTP->MapIndex(anIter.Value());
2149 if (anIndex > 0)
2150 return anIndex;
2151 }
2152 }
2153 return 0;
2154}
7fd59977 2155
2156//=======================================================================
400af1bc 2157//function : collectShapeAspect
2158//purpose :
2159//=======================================================================
2160static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
cf152970 2161 const Handle(XSControl_WorkSession)& theWS,
2162 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
400af1bc 2163{
2164 if (theSA.IsNull())
2165 return;
2166 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2167 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2168 const Interface_Graph& aGraph = aTP->Graph();
2169 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2170 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2171 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2172 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2173 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2174 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2175 }
2176 if (!aSADR.IsNull())
2177 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2178 }
2179 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2180 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2181 theSAs.Append(theSA);
2182 return;
2183 }
2184 else {
2185 // Find all children Shape_Aspect
2186 Standard_Boolean isSimple = Standard_True;
2187 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2188 for (; anIter.More(); anIter.Next()) {
2189 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
cf152970 2190 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
400af1bc 2191 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2192 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2193 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
cf152970 2194 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
400af1bc 2195 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2196 isSimple = Standard_False;
2197 }
2198 }
2199 }
2200 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2201 if (isSimple)
2202 theSAs.Append(theSA);
2203 }
2204}
2205
2206//=======================================================================
2207//function : getShapeLabel
2208//purpose :
2209//=======================================================================
2210
2211static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
cf152970 2212 const Handle(XSControl_WorkSession)& theWS,
2213 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
400af1bc 2214{
2215 TDF_Label aShapeL;
2216 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2217 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2218 TopoDS_Shape aShape;
2219 if (index > 0) {
2220 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2221 aShape = TransferBRep::ShapeResult(aBinder);
2222 }
2223 if (aShape.IsNull())
2224 return aShapeL;
2225 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2226 return aShapeL;
2227}
2228
2229//=======================================================================
1c9d3225 2230//function : setDatumToXCAF
7fd59977 2231//purpose :
2232//=======================================================================
400af1bc 2233
0c63f2f8 2234Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
cf152970 2235 const TDF_Label theGDTL,
2236 const Standard_Integer thePositionCounter,
2237 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2238 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2239 const Standard_Real theModifValue,
2240 const Handle(TDocStd_Document)& theDoc,
2241 const Handle(XSControl_WorkSession)& theWS)
7fd59977 2242{
400af1bc 2243 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2244 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
7f56eba8 2245 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2246 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
1c9d3225 2247 const Interface_Graph& aGraph = aTP->Graph();
2248 Handle(XCAFDoc_Datum) aDat;
400af1bc 2249 TDF_LabelSequence aShapeLabels;
2250 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2251
2252 // Collect all links to shapes
2253 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
1c9d3225 2254 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
400af1bc 2255 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2256 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2257 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2258 continue;
2259 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2260 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2261 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2262 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2263 }
2264
2265 // Collect shape labels
2266 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2267 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2268 if (aSA.IsNull())
2269 continue;
2270 // Skip datum targets
2271 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2272 continue;
2273
2274 // Process all connected GISU
2275 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2276 for (; anIter.More(); anIter.Next()) {
2277 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2278 if (aGISU.IsNull())
2279 continue;
1209c1b9 2280 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2281 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
400af1bc 2282 if (!aShapeL.IsNull())
2283 aShapeLabels.Append(aShapeL);
7fd59977 2284 }
1c9d3225 2285 }
400af1bc 2286 }
2287
2288 // Process datum targets and create objects for them
2289 Standard_Boolean isExistDatumTarget = Standard_False;
2290 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2291 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2292 if (aDT.IsNull())
2293 continue;
1209c1b9 2294 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
400af1bc 2295 XCAFDimTolObjects_DatumTargetType aType;
2296 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2297 continue;
1209c1b9 2298 aDatTargetObj->SetDatumTargetType(aType);
400af1bc 2299 Standard_Boolean isValidDT = Standard_False;
2300
2301 // Feature for datum target
2302 TDF_LabelSequence aDTShapeLabels;
1209c1b9 2303 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
400af1bc 2304 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
1209c1b9 2305 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2306 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
6595eee7 2307 }
400af1bc 2308 if (!aRelationship.IsNull()) {
2309 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2310 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2311 for (; aSAIter.More(); aSAIter.Next()) {
2312 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2313 if (aGISU.IsNull())
2314 continue;
1209c1b9 2315 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2316 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
400af1bc 2317 if (!aShapeL.IsNull()) {
2318 aDTShapeLabels.Append(aShapeL);
2319 isValidDT = Standard_True;
2320 }
7fd59977 2321 }
2322 }
1c9d3225 2323 }
400af1bc 2324
2325 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2326 // Try another way of feature connection
1209c1b9 2327 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2328 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
400af1bc 2329 if (aGISU.IsNull())
2330 continue;
1209c1b9 2331 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2332 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
400af1bc 2333 if (!aShapeL.IsNull()) {
2334 aDTShapeLabels.Append(aShapeL);
2335 isValidDT = Standard_True;
2336 }
2337 }
2338 }
1c9d3225 2339 }
400af1bc 2340
2341 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2342 // Area datum target
2343 Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
2344 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2345 for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
2346 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
2347 }
2348 Handle(StepRepr_RepresentationItem) anItem;
2349 if (aGISU->NbIdentifiedItem() > 0)
2350 anItem = aGISU->IdentifiedItemValue(1);
2351 if (anItem.IsNull())
2352 continue;
2353 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2354 if (anItemIndex > 0) {
2355 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2356 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
1209c1b9 2357 aDatTargetObj->SetDatumTarget(anItemShape);
400af1bc 2358 isValidDT = Standard_True;
2359 }
1c9d3225 2360 }
400af1bc 2361 else {
2362 // Point/line/rectangle/circle datum targets
2363 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2364 Handle(StepRepr_PropertyDefinition) aPD;
2365 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2366 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2367 }
2368 if (!aPD.IsNull()) {
2369 anIter = aGraph.Sharings(aPD);
2370 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2371 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2372 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2373 }
2374 if (!aSDR.IsNull()) {
2375 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2376 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2377 if (!aSRWP.IsNull()) {
2378 isValidDT = Standard_True;
2379 // Collect parameters of datum target
1209c1b9 2380 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
400af1bc 2381 {
1209c1b9 2382 if (aSRWP->ItemsValue(j).IsNull())
400af1bc 2383 continue;
1209c1b9 2384 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
1c9d3225 2385 {
400af1bc 2386 Handle(StepGeom_Axis2Placement3d) anAx
1209c1b9 2387 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
477000eb 2388 XSAlgo::AlgoContainer()->PrepareForTransfer();
2389 STEPControl_ActorRead anActor;
2390 anActor.PrepareUnits(aSRWP, aTP);
400af1bc 2391 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
1209c1b9 2392 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
1c9d3225 2393 }
1209c1b9 2394 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
1c9d3225 2395 {
400af1bc 2396 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
1209c1b9 2397 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
400af1bc 2398 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2399 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
400af1bc 2400 if (anUnit.IsNull())
2401 continue;
2402 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2403 if (aNU.IsNull())
2404 continue;
477000eb 2405 STEPConstruct_UnitContext anUnitCtx;
2406 anUnitCtx.ComputeFactors(aNU);
2407 aVal = aVal * anUnitCtx.LengthFactor();
400af1bc 2408 if (aM->Name()->String().IsEqual("target length") ||
2409 aM->Name()->String().IsEqual("target diameter"))
1209c1b9 2410 aDatTargetObj->SetDatumTargetLength(aVal);
400af1bc 2411 else
1209c1b9 2412 aDatTargetObj->SetDatumTargetWidth(aVal);
1c9d3225 2413 }
2414 }
2415 }
2416 }
2417 }
2418 }
400af1bc 2419
2420 // Create datum target object
2421 if (isValidDT) {
1c9d3225 2422 TDF_Label aDatL = aDGTTool->AddDatum();
0c63f2f8 2423 myGDTMap.Bind(aDT, aDatL);
2424 aDGTTool->Lock(aDatL);
1c9d3225 2425 aDat = XCAFDoc_Datum::Set(aDatL);
400af1bc 2426 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
1209c1b9 2427 aDatTargetObj->SetName(theDat->Identification());
2428 aDatTargetObj->SetPosition(thePositionCounter);
400af1bc 2429 if (!theXCAFModifiers.IsEmpty())
1209c1b9 2430 aDatTargetObj->SetModifiers(theXCAFModifiers);
400af1bc 2431 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
1209c1b9 2432 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
1c9d3225 2433 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
1209c1b9 2434 aDatTargetObj->IsDatumTarget(Standard_True);
2435 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2436 readAnnotation(aTR, aDT, aDatTargetObj);
2437 aDat->SetObject(aDatTargetObj);
400af1bc 2438 isExistDatumTarget = Standard_True;
5df609e7 2439 }
1c9d3225 2440 }
400af1bc 2441
2442 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2443 // Create object for datum
2444 TDF_Label aDatL = aDGTTool->AddDatum();
0c63f2f8 2445 myGDTMap.Bind(theDat, aDatL);
c4fa1c2c 2446 // bind datum label with all reference datum_feature entities
2447 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2448 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2449 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2450 continue;
2451 myGDTMap.Bind(aSA, aDatL);
2452 }
0c63f2f8 2453 aDGTTool->Lock(aDatL);
400af1bc 2454 aDat = XCAFDoc_Datum::Set(aDatL);
2455 aDGTTool->SetDatum(aShapeLabels, aDatL);
2456 aDatObj->SetName(theDat->Identification());
2457 aDatObj->SetPosition(thePositionCounter);
2458 if (!theXCAFModifiers.IsEmpty())
2459 aDatObj->SetModifiers(theXCAFModifiers);
2460 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2461 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2462 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2463 if (aDatObj->GetPresentation().IsNull()) {
2464 // Try find annotation connected to datum entity (not right case, according recommended practices)
2465 readAnnotation(aTR, theDat, aDatObj);
2466 }
2467 aDat->SetObject(aDatObj);
2468 }
2469
2470 return Standard_True;
1c9d3225 2471}
2472
2473
2474//=======================================================================
2475//function : ReadDatums
2476//purpose : auxilary
2477//=======================================================================
0c63f2f8 2478Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
cf152970 2479 const TDF_Label theGDTL,
2480 const Handle(TDocStd_Document)& theDoc,
2481 const Handle(XSControl_WorkSession)& theWS)
1c9d3225 2482{
7f56eba8 2483 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2484 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
1c9d3225 2485 const Interface_Graph& aGraph = aTP->Graph();
2486
2487 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
cf152970 2488 for (anIter.Start(); anIter.More(); anIter.Next()) {
1c9d3225 2489 Handle(Standard_Transient) anAtr = anIter.Value();
cf152970 2490 if (anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
1c9d3225 2491 {
2492 Standard_Integer aPositionCounter = 0;//position on frame
2493 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2494 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
cf152970 2495 for (anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
1c9d3225 2496 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
cf152970 2497 if (anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
1c9d3225 2498 {
2499 //get axis
2500 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2501 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2502 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2503 {
2504 Handle(StepGeom_Axis2Placement3d) anAx
2505 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2506 Handle(XCAFDoc_GeomTolerance) aTol;
cf152970 2507 if (theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
1c9d3225 2508 {
2509 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2510 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2511 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2512 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2513 gp_Dir aDir;
2514 gp_Dir aDirR;
2515 gp_Pnt aPnt;
cf152970 2516 if (!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2517 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
1c9d3225 2518 !aLocArr.IsNull() && aLocArr->Length() > 2)
2519 {
cf152970 2520 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
2521 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower() + 1, aDirRArr->Lower() + 2);
2522 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower() + 1, aLocArr->Lower() + 2);
1c9d3225 2523 gp_Ax2 anA(aPnt, aDir, aDirR);
2524 anObj->SetAxis(anA);
2525 aTol->SetObject(anObj);
2526 }
2527 }
2528 }
2529 }
2530 }
2531 if (aDS->NbConstituents() > 0)
2532 {
2533 //get datum feature and datum target from datum system
2534 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
cf152970 2535 if (!aDRCA.IsNull())
1c9d3225 2536 {
cf152970 2537 for (Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
1c9d3225 2538 {
a9dde4a3 2539 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
1c9d3225 2540 //gete modifiers
2541 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2542 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2543 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2544 Standard_Real aModifValue = 0;
cf152970 2545 if (!aModif.IsNull())
1c9d3225 2546 {
cf152970 2547 for (Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
1c9d3225 2548 {
cf152970 2549 if (aModif->Value(m).CaseNumber() == 2)
1c9d3225 2550 aXCAFModifiers.Append(
2551 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
cf152970 2552 SimpleDatumReferenceModifierMember()->Value());
1c9d3225 2553 else if (aModif->Value(m).CaseNumber() == 1)
2554 {
2555 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2556 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2557 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
cf152970 2558 if (anUnit.IsNull()) continue;
2559 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
1c9d3225 2560 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
477000eb 2561 STEPConstruct_UnitContext anUnitCtx;
2562 anUnitCtx.ComputeFactors(NU);
2563 aModifValue = aVal * anUnitCtx.LengthFactor();
1c9d3225 2564 }
2565 }
2566 }
2567 aPositionCounter++;
2568 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
cf152970 2569 for (anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2570
2571 if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
1c9d3225 2572 {
2573 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
cf152970 2574 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
1c9d3225 2575 }
cf152970 2576 else if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
1c9d3225 2577 {
cf152970 2578 Handle(StepDimTol_DatumReferenceElement) aDRE
1c9d3225 2579 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2580 //get modifiers from group of datums
2581 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
cf152970 2582 if (!aModifE.IsNull())
1c9d3225 2583 {
cf152970 2584 for (Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
1c9d3225 2585 {
cf152970 2586 if (aModifE->Value(k).CaseNumber() == 2)
1c9d3225 2587 aXCAFModifiers.Append(
2588 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
cf152970 2589 SimpleDatumReferenceModifierMember()->Value());
f3ec3b37 2590 else if (aModifE->Value(k).CaseNumber() == 1)
1c9d3225 2591 {
2592 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2593 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2594 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
cf152970 2595 if (anUnit.IsNull()) continue;
2596 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
7fd59977 2597 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
477000eb 2598 STEPConstruct_UnitContext anUnitCtx;
2599 anUnitCtx.ComputeFactors(NU);
2600 aModifValue = aVal * anUnitCtx.LengthFactor();
7fd59977 2601 }
2602 }
2603 }
1c9d3225 2604 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
cf152970 2605 for (anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2606 if (anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
1c9d3225 2607 {
2608 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
cf152970 2609 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
1c9d3225 2610 }
2611 }
7fd59977 2612 }
2613 }
2614 }
1c9d3225 2615 }
2616 }
2617 }
2618 }
2619 return Standard_True;
2620}
2621
2622//=======================================================================
b7b2f85a 2623//function : createGeomTolObjectInXCAF
1c9d3225 2624//purpose :
2625//=======================================================================
0c63f2f8 2626TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
cf152970 2627 const Handle(TDocStd_Document)& theDoc,
2628 const Handle(XSControl_WorkSession)& theWS)
1c9d3225 2629{
2630 TDF_Label aGDTL;
cf152970 2631 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2632 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2633 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
1c9d3225 2634 {
2635 return aGDTL;
2636 }
eacdb38f 2637
2638 Handle(TCollection_HAsciiString) aSemanticName;
2639
f3ec3b37 2640 // protection against invalid input
2641 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2642 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2643 if (aGeomTol->TolerancedShapeAspect().IsNull())
2644 return aGDTL;
eacdb38f 2645 aSemanticName = aGeomTol->Name();
f3ec3b37 2646 }
2647 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2648 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2649 if (aDim->AppliesTo().IsNull())
2650 return aGDTL;
eacdb38f 2651 aSemanticName = aDim->Name();
f3ec3b37 2652 }
2653 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2654 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2655 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2656 return aGDTL;
eacdb38f 2657 aSemanticName = aDim->Name();
f3ec3b37 2658 }
1c9d3225 2659
cf152970 2660 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2661 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
7f56eba8 2662 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2663 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
1c9d3225 2664 const Interface_Graph& aGraph = aTP->Graph();
2665 Standard_Boolean isAllAround = Standard_False;
2666 Standard_Boolean isAllOver = Standard_False;
cf152970 2667
1c9d3225 2668 // find RepresentationItem for current Ent
2669 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2670
b7b2f85a 2671 // Collect all Shape_Aspect entities
1c9d3225 2672 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
cf152970 2673 for (anIter.Start(); anIter.More(); anIter.Next()) {
1c9d3225 2674 Handle(Standard_Transient) anAtr = anIter.Value();
2675 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
cf152970 2676 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
1c9d3225 2677 {
2678 //if associating tolerances with part (All-Over)
2679 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
cf152970 2680 for (anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
1c9d3225 2681 {
2682 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
cf152970 2683 if (anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
1c9d3225 2684 {
2685 isAllOver = Standard_True;
2686 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
cf152970 2687 for (anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
1c9d3225 2688 {
2689 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
cf152970 2690 if (anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
1c9d3225 2691 {
2692 aSeqRI1.Append(anAtrABSR);
2693 }
7fd59977 2694 }
7fd59977 2695 }
1c9d3225 2696 }
2697 }
cf152970 2698 else if (anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
1c9d3225 2699 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2700 {
2701 //if tolerance attached to dimension
2702 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
cf152970 2703 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next())
1c9d3225 2704 {
b7b2f85a 2705 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
cf152970 2706 if (!aSA.IsNull()) {
b7b2f85a 2707 collectShapeAspect(aSA, theWS, aSAs);
1c9d3225 2708 }
2709 }
2710 }
cf152970 2711 else if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
1c9d3225 2712 {
cf152970 2713 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
1c9d3225 2714 {
2715 // if applyed AllAround Modifier
2716 isAllAround = Standard_True;
1c9d3225 2717 }
b7b2f85a 2718 // dimensions and default tolerances
2719 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
cf152970 2720 if (!aSA.IsNull()) {
b7b2f85a 2721 collectShapeAspect(aSA, theWS, aSAs);
1c9d3225 2722 }
2723 }
b7b2f85a 2724
2725 // Collect all representation items
cf152970 2726 if (!aSAs.IsEmpty())
1c9d3225 2727 {
2728 //get representation items
2729 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
cf152970 2730 for (Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
1c9d3225 2731 {
2732 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2733 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2734 Handle(StepRepr_PropertyDefinition) PropD;
cf152970 2735 for (anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
1c9d3225 2736 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2737 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2738 }
cf152970 2739 if (!PropD.IsNull())//for old version
1c9d3225 2740 {
2741 Handle(StepRepr_RepresentationItem) RI;
2742 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
cf152970 2743 for (subs4.Start(); subs4.More(); subs4.Next()) {
2744 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1c9d3225 2745 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
cf152970 2746 if (!SDR.IsNull()) {
1c9d3225 2747 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
cf152970 2748 if (!Repr.IsNull() && Repr->NbItems() > 0) {
1c9d3225 2749 RI = Repr->ItemsValue(1);
2750 }
2751 }
7fd59977 2752 }
cf152970 2753 if (RI.IsNull()) continue;
1c9d3225 2754
cf152970 2755 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1c9d3225 2756 // read dimensions
2757 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
cf152970 2758 if (EC.IsNull()) continue;
1c9d3225 2759 Handle(TCollection_HAsciiString) aName;
cf152970 2760 Handle(StepShape_DimensionalSize) DimSize =
1c9d3225 2761 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
cf152970 2762 Standard_Real dim1 = -1., dim2 = -1.;
1c9d3225 2763 subs4 = aGraph.Sharings(DimSize);
cf152970 2764 for (subs4.Start(); subs4.More(); subs4.Next()) {
2765 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
1c9d3225 2766 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
cf152970 2767 if (!DimCharR.IsNull()) {
1c9d3225 2768 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
cf152970 2769 if (!SDimR.IsNull() && SDimR->NbItems() > 0) {
f2139a7f 2770 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2771 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
cf152970 2772 if (!VR.IsNull()) {
1c9d3225 2773 aName = VR->Name();
2774 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2775 //if(CID.IsNull()) continue;
2776 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2777 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2778 //if(CIDM.IsNull()) continue;
2779 //if(CIDM->ArrTransient().IsNull()) continue;
2780 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2781 //if(CID.CaseMem(CIDM)==1)
2782 // HARI = CID.ListRepresentationItem();
2783 //if(CID.CaseMem(CIDM)==2)
2784 // HARI = CID.SetRepresentationItem();
2785 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
cf152970 2786 if (HARI.IsNull()) continue;
2787 if (HARI->Length() > 0) {
a9dde4a3 2788 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
cf152970 2789 if (RI1.IsNull()) continue;
2790 if (RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1c9d3225 2791 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2792 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2793 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2794 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
cf152970 2795 if (anUnit.IsNull()) continue;
2796 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
1c9d3225 2797 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
477000eb 2798 STEPConstruct_UnitContext anUnitCtx;
2799 anUnitCtx.ComputeFactors(NU);
2800 dim1 = dim1 * anUnitCtx.LengthFactor();
1c9d3225 2801 }
2802 }
cf152970 2803 if (HARI->Length() > 1) {
a9dde4a3 2804 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
cf152970 2805 if (RI2.IsNull()) continue;
2806 if (RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1c9d3225 2807 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2808 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2809 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2810 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
cf152970 2811 if (anUnit.IsNull()) continue;
2812 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
1c9d3225 2813 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
477000eb 2814 STEPConstruct_UnitContext anUnitCtx;
2815 anUnitCtx.ComputeFactors(NU);
2816 dim2 = dim2 * anUnitCtx.LengthFactor();
1c9d3225 2817 }
2818 }
2819 }
2820 }
2821 }
2822 }
cf152970 2823 if (dim1 < 0) continue;
2824 if (dim2 < 0) dim2 = dim1;
1c9d3225 2825 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2826 // now we know edge_curve and value range therefore
2827 // we can create corresponding D&GT labels
2828 Standard_Integer index = aTP->MapIndex(EC);
2829 TopoDS_Shape aSh;
cf152970 2830 if (index > 0) {
1c9d3225 2831 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2832 aSh = TransferBRep::ShapeResult(binder);
2833 }
cf152970 2834 if (aSh.IsNull()) continue;
1c9d3225 2835 TDF_Label shL;
cf152970 2836 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2837 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 2);
2838 arr->SetValue(1, dim1);
2839 arr->SetValue(2, dim2);
2840 aDGTTool->SetDimTol(shL, 1, arr, aName, DimSize->Name());
7fd59977 2841 }
1c9d3225 2842 // read tolerances and datums
cf152970 2843 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
1c9d3225 2844 Handle(StepDimTol_GeometricTolerance) GT =