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