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