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