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