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