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