From b8a8da98e4065bf7cb7bab7dfc9a37af7afd0d64 Mon Sep 17 00:00:00 2001 From: ika Date: Tue, 14 May 2024 15:17:32 +0100 Subject: [PATCH] 0033206: Data Exchange, Step - Supplemental geometry support Updated import methods to add supplemental geometry as a reference to the PMI Updated export methods to handle supplemental geometry as a special type. Created new GUID for supplemental geometry container - compound contains all sup. geom. shapes. Created new GUID for supplemental geometry label - supplemental geometry shape. Created new GUID for supplemental geometry reference - relation for depends on. Supplemental geometry: surfaces and curves. --- src/STEPCAFControl/STEPCAFControl_Reader.cxx | 379 ++++++++++++------- src/STEPCAFControl/STEPCAFControl_Reader.hxx | 12 + src/STEPCAFControl/STEPCAFControl_Writer.cxx | 232 +++++++++++- src/XCAFDoc/XCAFDoc.cxx | 30 ++ src/XCAFDoc/XCAFDoc.hxx | 9 + 5 files changed, 514 insertions(+), 148 deletions(-) diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index ac50c771bb..e9b4975d82 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -16,8 +16,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -53,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -174,6 +178,7 @@ #include #include #include +#include #include #include #include @@ -187,6 +192,7 @@ #include #include #include +#include #include #include #include @@ -2422,6 +2428,46 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR, return; } +//======================================================================= +//function : computePMIReferensePosition +//purpose : compute position of shape contains in the shapeAspect +//======================================================================= +Standard_Boolean computePMIReferensePosition(const Handle(StepRepr_ShapeAspect)& theReference, + const Interface_Graph& theGraph, + gp_Pnt& thePosition) +{ + if (theReference.IsNull()) + return Standard_False; + Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL; + for (Interface_EntityIterator anIt = theGraph.Sharings(theReference); aGISU.IsNull() && anIt.More(); anIt.Next()) + { + aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); + } + if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0) + return Standard_False; + const Handle(StepRepr_RepresentationItem)& anItem = aGISU->IdentifiedItem()->Value(1); + if (anItem->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint))) + { + Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(anItem); + thePosition.SetX(aPoint->CoordinatesValue(1)); + thePosition.SetY(aPoint->CoordinatesValue(2)); + thePosition.SetZ(aPoint->CoordinatesValue(3)); + return Standard_True; + } + else if (anItem->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) + { + Handle(StepGeom_Axis2Placement3d) anA2P3D = Handle(StepGeom_Axis2Placement3d)::DownCast(anItem); + if (!anA2P3D->Location().IsNull()) + { + thePosition.SetX(anA2P3D->Location()->CoordinatesValue(1)); + thePosition.SetY(anA2P3D->Location()->CoordinatesValue(2)); + thePosition.SetZ(anA2P3D->Location()->CoordinatesValue(3)); + return Standard_True; + } + } + return Standard_False; +} + //======================================================================= //function : readConnectionPoints //purpose : read connection points for given dimension @@ -2436,7 +2482,7 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR, Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess(); const Interface_Graph& aGraph = aTP->Graph(); - + Standard_Real aFact = 1.; Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL; @@ -2455,83 +2501,33 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR, anActor.PrepareUnits(aSDR, aTP, aLocalFactors); aFact = aLocalFactors.LengthFactor(); } - + if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) { // retrieve derived geometry Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT); - Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo()); - if (aDSA.IsNull()) - return; - Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL; - for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) { - aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); + gp_Pnt aPnt; + if (computePMIReferensePosition(aDim->AppliesTo(), aGraph, aPnt)) + { + // set connection point to object + aPnt.SetXYZ(aPnt.XYZ() * aFact); + theDimObject->SetPoint(aPnt); } - if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0) - return; - Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1)); - if (anA2P3D.IsNull()) - return; - aPoint = anA2P3D->Location(); - } - - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint(aPnt); } else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) { // retrieve derived geometry Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT); - Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect()); - Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect()); - if (aDSA1.IsNull() && aDSA2.IsNull()) - return; - Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL; - Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL; - if (!aDSA1.IsNull()) { - for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) { - aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); - } + gp_Pnt aPnt; + if (computePMIReferensePosition(aDim->RelatingShapeAspect(), aGraph, aPnt)) + { + // set connection point to object + aPnt.SetXYZ(aPnt.XYZ() * aFact); + theDimObject->SetPoint(aPnt); } - if (!aDSA2.IsNull()) { - for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) { - aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value()); - } - } - // first point - if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) { - Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1)); - if (!anA2P3D.IsNull()) - aPoint = anA2P3D->Location(); - } - if (!aPoint.IsNull()) { - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint(aPnt); - } - } - // second point - if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) { - Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1)); - if (aPoint.IsNull()) { - // try Axis2Placement3d.location instead of CartesianPoint - Handle(StepGeom_Axis2Placement3d) anA2P3D = - Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1)); - if (!anA2P3D.IsNull()) - aPoint = anA2P3D->Location(); - } - if (!aPoint.IsNull()) { - // set connection point to object - gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact); - theDimObject->SetPoint2(aPnt); - } + if (computePMIReferensePosition(aDim->RelatedShapeAspect(), aGraph, aPnt)) + { + // set connection point to object + aPnt.SetXYZ(aPnt.XYZ() * aFact); + theDimObject->SetPoint2(aPnt); } } } @@ -3164,8 +3160,8 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main()); - const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader(); - const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess(); + const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader(); + const Handle(Transfer_TransientProcess)& aTP = aTR->TransientProcess(); const Interface_Graph& aGraph = aTP->Graph(); Standard_Boolean isAllAround = Standard_False; Standard_Boolean isAllOver = Standard_False; @@ -3464,65 +3460,15 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra TDF_LabelSequence aShLS1, aShLS2; // Collect shapes - for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper();i++) + for (NCollection_Sequence::Iterator anIter1(aSeqRI1); + anIter1.More(); anIter1.Next()) { - Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS); - TopoDS_Shape aSh; - if (anIndex > 0) { - Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); - aSh = TransferBRep::ShapeResult(aBinder); - } - if (!aSh.IsNull()) - { - TDF_Label aShL; - aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True); - if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE) - { - TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE); - while (ex.More()) - { - TDF_Label edgeL; - aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True); - if (!edgeL.IsNull()) - aShLS1.Append(edgeL); - ex.Next(); - } - } - if (!aShL.IsNull()) - aShLS1.Append(aShL); - } + findReferenceGeometry(anIter1.Value(), aSTool, aShLS1, theLocalFactors); } - if (!aSeqRI2.IsEmpty()) + for (NCollection_Sequence::Iterator anIter2(aSeqRI2); + anIter2.More(); anIter2.Next()) { - //for dimensional location - for (Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper();i++) - { - Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS); - TopoDS_Shape aSh; - if (anIndex > 0) { - Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); - aSh = TransferBRep::ShapeResult(aBinder); - } - if (!aSh.IsNull()) - { - TDF_Label aShL; - aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True); - if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE) - { - TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE); - while (ex.More()) - { - TDF_Label edgeL; - aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True); - if (!edgeL.IsNull()) - aShLS2.Append(edgeL); - ex.Next(); - } - } - if (!aShL.IsNull()) - aShLS2.Append(aShL); - } - } + findReferenceGeometry(anIter2.Value(), aSTool, aShLS2, theLocalFactors); } if (!aShLS1.IsEmpty()) @@ -3583,6 +3529,185 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra return aGDTL; } +//======================================================================= +//function : findReferenceGeometry +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Reader::findReferenceGeometry(const Handle(Standard_Transient)& theShapeStart, + const Handle(XCAFDoc_ShapeTool)& theShTool, + TDF_LabelSequence& theShLabelSeq, + const StepData_Factors& theLocalFactors) +{ + const Handle(XSControl_TransferReader)& aTR = myReader.WS()->TransferReader(); + const Handle(Transfer_TransientProcess)& aTP = aTR->TransientProcess(); + TopoDS_Shape aSh = TransferBRep::ShapeResult(aTP, theShapeStart); + if (!aSh.IsNull()) + { + TDF_Label aShL; + theShTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True); + if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE) + { + for (TopExp_Explorer anExp(aSh, TopAbs_EDGE, TopAbs_SHAPE); + anExp.More(); anExp.Next()) + { + TDF_Label anEdgeL; + theShTool->Search(anExp.Current(), anEdgeL, Standard_True, Standard_True, Standard_True); + if (!anEdgeL.IsNull()) + { + theShLabelSeq.Append(anEdgeL); + } + } + } + if (!aShL.IsNull()) + { + theShLabelSeq.Append(aShL); + return Standard_True; + } + } + + TDF_Label aFindResultL; + if (myGDTMap.Find(theShapeStart, aFindResultL)) + { + theShLabelSeq.Append(aFindResultL); + return Standard_True; + } + const Handle(StepGeom_GeometricRepresentationItem)& aGeomItem = + Handle(StepGeom_GeometricRepresentationItem)::DownCast(theShapeStart); + if (aGeomItem.IsNull()) + { + return Standard_False; + } + if (theShapeStart->IsKind(STANDARD_TYPE(StepGeom_Curve))) + { + const Handle(StepGeom_Curve)& aStepCurve = Handle(StepGeom_Curve)::DownCast(theShapeStart); + Handle(Geom_Curve) aCurve = StepToGeom::MakeCurve(aStepCurve, theLocalFactors); + if (aCurve.IsNull()) + { + return Standard_False; + } + BRepBuilderAPI_MakeEdge aMaker; + if (aCurve->IsKind(STANDARD_TYPE(Geom_Line))) + { + const Standard_Real aScale = theLocalFactors.LengthFactor(); + aMaker.Init(aCurve, 0, 1. * aScale); + } + else + { + aMaker.Init(aCurve); + } + if (aMaker.IsDone()) + { + aSh = aMaker.Shape(); + } + } + else if (theShapeStart->IsKind(STANDARD_TYPE(StepGeom_Surface))) + { + const Handle(StepGeom_Surface)& aStepSurface = Handle(StepGeom_Surface)::DownCast(theShapeStart); + Handle(Geom_Surface) aSurface = StepToGeom::MakeSurface(aStepSurface, theLocalFactors); + if (aSurface.IsNull()) + { + return Standard_False; + } + BRepBuilderAPI_MakeFace aMaker; + if (aSurface->IsKind(STANDARD_TYPE(Geom_Plane))) + { + const Standard_Real aScale = theLocalFactors.LengthFactor(); + aMaker.Init(aSurface, 0., 1. * aScale, 0., 1. * aScale, Precision::Confusion()); + } + else + { + aMaker.Init(aSurface, Standard_True, Precision::Confusion()); + } + if (aMaker.IsDone()) + { + aSh = aMaker.Shape(); + } + } + if (aSh.IsNull()) + { + return Standard_False; + } + if (mySupplementalLabel.IsNull()) + { + mySupplementalLabel = theShTool->NewShape(); + TDataStd_Name::Set(mySupplementalLabel, "Supplemental Geometry"); + TDataStd_UAttribute::Set(mySupplementalLabel, XCAFDoc::SupplementalContainerGUID()); + TDataStd_UAttribute::Set(mySupplementalLabel, XCAFDoc::InvisibleGUID()); + } + TDF_Label aSupGeomLabel = theShTool->AddComponent(mySupplementalLabel, aSh); + if (aSupGeomLabel.IsNull()) + { + return Standard_False; + } + TDataStd_UAttribute::Set(aSupGeomLabel, XCAFDoc::SupplementalGeometryGUID()); + + if (!aGeomItem->Name().IsNull()) + { + TDataStd_Name::Set(aSupGeomLabel, aGeomItem->Name()->String()); + TDF_Label aReferredShapeL; + theShTool->GetReferredShape(aSupGeomLabel, aReferredShapeL); + TDataStd_Name::Set(aReferredShapeL, aGeomItem->Name()->String()); + TDataStd_UAttribute::Set(aReferredShapeL, XCAFDoc::SupplementalGeometryGUID()); + } + TDF_Label aRefL; + const Interface_Graph& aGraph = aTP->Graph(); + for (Interface_EntityIterator anIter(aGraph.Sharings(theShapeStart)); + anIter.More() && aRefL.IsNull(); anIter.Next()) + { + Handle(StepAP242_GeometricItemSpecificUsage) aPGISU = + Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value()); + if (aPGISU.IsNull()) + { + continue; + } + Handle(StepRepr_ShapeAspect) aShAspect = aPGISU->Definition().ShapeAspect(); + if (aShAspect.IsNull()) + { + continue; + } + Handle(StepRepr_ProductDefinitionShape) aRefPDS = aShAspect->OfShape(); + if (aRefPDS.IsNull()) + { + continue; + } + TopoDS_Shape aRefSh = TransferBRep::ShapeResult(aTP, aRefPDS->Definition().Value()); + theShTool->Search(aRefSh, aRefL, Standard_True, Standard_True, Standard_False); + } + + if (aRefL.IsNull()) + { + TDF_LabelSequence aFreeShapes; + theShTool->GetFreeShapes(aFreeShapes); + for(TDF_LabelSequence::Iterator anIter(aFreeShapes); anIter.More() && aRefL.IsNull(); anIter.Next()) + { + const TDF_Label aLabel = anIter.Value(); + Handle(TDataStd_UAttribute) aSupGeomAttr; + if (aLabel.FindAttribute(XCAFDoc::SupplementalContainerGUID(), aSupGeomAttr)) + { + continue; + } + TopoDS_Shape aTmpShape = theShTool->GetShape(aLabel); + if (!aTmpShape.IsNull()) + { + aRefL = aLabel; + } + } + } + if (aRefL.IsNull()) + { + return Standard_False; + } + + // set reference + Handle(TDataStd_TreeNode) aMainNode = TDataStd_TreeNode::Set(aRefL, XCAFDoc::SupplementalRefGUID()); + Handle(TDataStd_TreeNode) aRefNode = TDataStd_TreeNode::Set(aSupGeomLabel, XCAFDoc::SupplementalRefGUID()); + aRefNode->Remove(); // abv: fix against bug in TreeNode::Append() + aMainNode->Append(aRefNode); + myGDTMap.Bind(theShapeStart, aSupGeomLabel); + theShLabelSeq.Append(aSupGeomLabel); + return Standard_True; +} + //======================================================================= //function : convertAngleValue //purpose : auxiliary diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.hxx b/src/STEPCAFControl/STEPCAFControl_Reader.hxx index 5fb211931b..d6a41bfd6b 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.hxx @@ -323,6 +323,17 @@ private: const Handle(XSControl_WorkSession)& theWS, const StepData_Factors& theLocalFactors); + //! Finds reference geometry or create supplemental geometry label + //! @param[in] theShapeStart step entity to get reference + //! @param[in] theShTool tool to work with shape labels + //! @param[out] theShLabelSeq container to put reference label + //! @param[in] theLocalFactors structure to calculate units. + //! @return TRUE if a reference is found or supplemental geometry is added + Standard_Boolean findReferenceGeometry(const Handle(Standard_Transient)& theShapeStart, + const Handle(XCAFDoc_ShapeTool)& theShTool, + TDF_LabelSequence& theShLabelSeq, + const StepData_Factors& theLocalFactors); + //! Internal method. Read Dimension or GeomTolerance. TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, const Handle(TDocStd_Document)& theDoc, @@ -339,6 +350,7 @@ private: STEPControl_Reader myReader; NCollection_DataMap myFiles; XCAFDoc_DataMapOfShapeLabel myMap; + TDF_Label mySupplementalLabel; Standard_Boolean myColorMode; Standard_Boolean myNameMode; Standard_Boolean myLayerMode; diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index d9a716269b..9b8993a40a 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -93,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -175,6 +178,7 @@ #include #include #include +#include #include #include #include @@ -595,6 +599,12 @@ Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer& theWriter, if (myLabels.IsBound(aCurL)) continue; // already processed + Handle(TDataStd_UAttribute) aSupGeomAttr; + if (aCurL.FindAttribute(XCAFDoc::SupplementalContainerGUID(), aSupGeomAttr)) + { + continue; + } + TopoDS_Shape aCurShape = XCAFDoc_ShapeTool::GetShape(aCurL); if (aCurShape.IsNull()) continue; @@ -2520,6 +2530,111 @@ Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::writeShapeAspect(const Handl return aSA; } +//======================================================================= +//function : WriteSupplementalGeometry +//purpose : +//======================================================================= +Handle(StepRepr_ShapeAspect) WriteSupplementalGeometry(const Handle(XSControl_WorkSession)& WS, + const Handle(StepRepr_ConstructiveGeometryRepresentation)& theCGRepr, + const TDF_Label& theLabel, + const TopoDS_Shape& theShape, + Handle(StepRepr_RepresentationContext)& theRC, + Handle(StepAP242_GeometricItemSpecificUsage)& theGISU, + NCollection_Vector& theGeomItems, + const StepData_Factors& theLocalFactors) +{ + Handle(StepRepr_ShapeAspect) aResSA; + // Get working data + const Handle(Interface_InterfaceModel)& aModel = WS->Model(); + const Handle(XSControl_TransferWriter)& aTW = WS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + const Handle(Interface_HGraph) aHGraph = WS->HGraph(); + if (aHGraph.IsNull()) + { + return aResSA; + } + Interface_Graph aGraph = aHGraph->Graph(); + + // Shape_Aspect + Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(); + Handle(TDataStd_Name) aNameAttr; + if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) + { + aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get())); + } + Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString(); + + Handle(TDataStd_TreeNode) aRefNode; + if (!theLabel.FindAttribute(XCAFDoc::SupplementalRefGUID(), aRefNode) + || aRefNode->Father().IsNull() || aRefNode->Father()->Label().IsNull()) + { + return aResSA; + } + TopoDS_Shape aMainShape = XCAFDoc_ShapeTool::GetShape(aRefNode->Father()->Label()); + TopLoc_Location aLoc; + TColStd_SequenceOfTransient aSeqRI; + FindEntities(aFP, aMainShape, aLoc, aSeqRI); + if (aSeqRI.Length() <= 0) + { + aFP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << aMainShape.TShape()->DynamicType()->Name() << std::endl; + return aResSA; + } + + Handle(StepRepr_ProductDefinitionShape) aPDS; + Handle(StepRepr_RepresentationContext) aRC; + Handle(Standard_Transient) anEnt = aSeqRI.Value(1); + aPDS = FindPDS(aGraph, anEnt, aRC); + if (aPDS.IsNull()) + return aResSA; + + theRC = aRC; + + Handle(StepGeom_GeometricRepresentationItem) anIdentifiedItem; + if (theShape.ShapeType() == TopAbs_FACE) + { + const TopoDS_Face& aFace = TopoDS::Face(theShape); + const Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + GeomToStep_MakeSurface aMaker(aSurf, theLocalFactors); + if (aMaker.IsDone()) + { + anIdentifiedItem = aMaker.Value(); + } + } + else if (theShape.ShapeType() == TopAbs_EDGE) + { + const TopoDS_Edge& anEdge = TopoDS::Edge(theShape); + Standard_Real aTmpFirst, aTmpLast; + const Handle(Geom_Curve) aCurv = BRep_Tool::Curve(anEdge, aTmpFirst, aTmpLast); + GeomToStep_MakeCurve aMaker(aCurv, theLocalFactors); + if (aMaker.IsDone()) + { + anIdentifiedItem = aMaker.Value(); + } + } + if (anIdentifiedItem.IsNull()) + { + return aResSA; + } + aResSA = new StepRepr_ShapeAspect(); + aResSA->Init(aName, aDescription, aPDS, StepData_LTrue); + // Geometric_Item_Specific_Usage + Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage(); + StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition; + aDefinition.SetValue(aResSA); + Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1); + + anIdentifiedItem->SetName(aName); + theGISU = aGISU; + anReprItems->SetValue(1, anIdentifiedItem); + theGeomItems.Append(anIdentifiedItem); + + // Set entities to model + aGISU->Init(aName, aDescription, aDefinition, theCGRepr, anReprItems); + aModel->AddWithRefs(aResSA); + aModel->AddWithRefs(aGISU); + return aResSA; +} + //======================================================================= //function : writePresentation //purpose : auxiliary (write annotation plane and presentation) @@ -3106,7 +3221,7 @@ static void WriteDerivedGeometry(const Handle(XSControl_WorkSession)& theWS, const Handle(StepRepr_ConstructiveGeometryRepresentation)& theRepr, Handle(StepRepr_ShapeAspect)& theFirstSA, Handle(StepRepr_ShapeAspect)& theSecondSA, - NCollection_Vector& thePnts, + NCollection_Vector& theGeoms, const StepData_Factors& theLocalFactors) { const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); @@ -3115,7 +3230,7 @@ static void WriteDerivedGeometry(const Handle(XSControl_WorkSession)& theWS, { GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint(), theLocalFactors.LengthFactor()); Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value(); - thePnts.Append(aPoint); + theGeoms.Append(aPoint); Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect(); aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse); Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage(); @@ -3136,7 +3251,7 @@ static void WriteDerivedGeometry(const Handle(XSControl_WorkSession)& theWS, { GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2(), theLocalFactors.LengthFactor()); Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value(); - thePnts.Append(aPoint); + theGeoms.Append(aPoint); Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect(); aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse); Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage(); @@ -3439,14 +3554,30 @@ void STEPCAFControl_Writer::writeGeomTolerance(const Handle(XSControl_WorkSessio aLMWU->Init(aValueMember, aUnit); aModel->AddWithRefs(aLMWU); + // Auxiliary entities for derived geometry + Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr = + new StepRepr_ConstructiveGeometryRepresentation(); + Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel = + new StepRepr_ConstructiveGeometryRepresentationRelationship(); + NCollection_Vector aConnectionGeometry; + // Geometric_Tolerance target Handle(StepRepr_ShapeAspect) aMainSA; Handle(StepRepr_RepresentationContext) dummyRC; Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU; if (theShapeSeqL.Length() == 1) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1)); - aMainSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = theShapeSeqL.Value(1); + Handle(TDataStd_UAttribute) aSupAttr; + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aMainSA = WriteSupplementalGeometry(theWS, aCGRepr, aShLabel, aShape, dummyRC, dummyGISU, aConnectionGeometry, theLocalFactors); + } + else + { + aMainSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); + } aModel->AddWithRefs(aMainSA); } else @@ -3455,8 +3586,18 @@ void STEPCAFControl_Writer::writeGeomTolerance(const Handle(XSControl_WorkSessio for (TDF_LabelSequence::Iterator aShIter(theShapeSeqL); aShIter.More(); aShIter.Next()) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShIter.Value()); - Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = aShIter.Value(); + Handle(TDataStd_UAttribute) aSupAttr; + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + Handle(StepRepr_ShapeAspect) aSA; + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aSA = WriteSupplementalGeometry(theWS, aCGRepr, aShLabel, aShape, dummyRC, dummyGISU, aConnectionGeometry, theLocalFactors); + } + else + { + aSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); + } if (aSA.IsNull()) continue; if (aCSA.IsNull()) @@ -3471,6 +3612,17 @@ void STEPCAFControl_Writer::writeGeomTolerance(const Handle(XSControl_WorkSessio } aMainSA = aCSA; } + + // Write Derived geometry + if (aConnectionGeometry.Length() > 0) + { + Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionGeometry.Length()); + for (Standard_Integer i = 0; i < aConnectionGeometry.Length(); i++) + anItems->SetValue(i + 1, aConnectionGeometry(i)); + aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC); + aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr); + aModel->AddWithRefs(aCGReprRel); + } StepDimTol_GeometricToleranceTarget aGTTarget; aGTTarget.SetValue(aMainSA); @@ -4078,7 +4230,7 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo new StepRepr_ConstructiveGeometryRepresentation(); Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel = new StepRepr_ConstructiveGeometryRepresentationRelationship(); - NCollection_Vector aConnectionPnts; + NCollection_Vector aConnectionGeometry; Handle(StepRepr_RepresentationContext) dummyRC; Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU; for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); @@ -4108,8 +4260,17 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA; if (aFirstShapeL.Length() == 1) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1)); - aFirstSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = aFirstShapeL.Value(1); + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + Handle(TDataStd_UAttribute) aSupAttr; + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aFirstSA = WriteSupplementalGeometry(theWS,aCGRepr, aShLabel, aShape, dummyRC, dummyGISU,aConnectionGeometry, theLocalFactors); + } + else + { + aFirstSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + } if (aRC.IsNull() && !dummyRC.IsNull()) aRC = dummyRC; } @@ -4118,8 +4279,18 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo Handle(StepRepr_CompositeShapeAspect) aCSA; for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt)); - Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = aFirstShapeL.Value(shIt); + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + Handle(TDataStd_UAttribute) aSupAttr; + Handle(StepRepr_ShapeAspect) aSA; + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aSA = WriteSupplementalGeometry(theWS, aCGRepr, aShLabel, aShape, dummyRC, dummyGISU, aConnectionGeometry, theLocalFactors); + } + else + { + aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + } if (aSA.IsNull()) continue; if (aCSA.IsNull()) @@ -4138,8 +4309,17 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo } if (aSecondShapeL.Length() == 1) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1)); - aSecondSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = aSecondShapeL.Value(1); + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + Handle(TDataStd_UAttribute) aSupAttr; + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aSecondSA = WriteSupplementalGeometry(theWS, aCGRepr, aShLabel, aShape, dummyRC, dummyGISU, aConnectionGeometry, theLocalFactors); + } + else + { + aSecondSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + } if (aRC.IsNull() && !dummyRC.IsNull()) aRC = dummyRC; } @@ -4148,8 +4328,18 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo Handle(StepRepr_CompositeShapeAspect) aCSA; for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt)); - Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + const TDF_Label& aShLabel = aSecondShapeL.Value(shIt); + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + Handle(TDataStd_UAttribute) aSupAttr; + Handle(StepRepr_ShapeAspect) aSA; + if (aShLabel.FindAttribute(XCAFDoc::SupplementalGeometryGUID(), aSupAttr)) + { + aSA = WriteSupplementalGeometry(theWS, aCGRepr, aShLabel, aShape, dummyRC, dummyGISU, aConnectionGeometry, theLocalFactors); + } + else + { + aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); + } if (aCSA.IsNull() && !aSA.IsNull()) { aCSA = new StepRepr_CompositeShapeAspect(); @@ -4177,7 +4367,7 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo // Write dimensions StepShape_DimensionalCharacteristic aDimension; if (anObject->HasPoint() || anObject->HasPoint2()) - WriteDerivedGeometry(theWS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts, theLocalFactors); + WriteDerivedGeometry(theWS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionGeometry, theLocalFactors); XCAFDimTolObjects_DimensionType aDimType = anObject->GetType(); if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) { @@ -4257,11 +4447,11 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value(), theLocalFactors); } // Write Derived geometry - if (aConnectionPnts.Length() > 0) + if (aConnectionGeometry.Length() > 0) { - Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length()); - for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++) - anItems->SetValue(i + 1, aConnectionPnts(i)); + Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionGeometry.Length()); + for (Standard_Integer i = 0; i < aConnectionGeometry.Length(); i++) + anItems->SetValue(i + 1, aConnectionGeometry(i)); aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC); aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr); aModel->AddWithRefs(aCGReprRel); diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index 9faf73353c..dbf25bacdf 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -311,6 +311,36 @@ const Standard_GUID& XCAFDoc::ViewRefAnnotationGUID() return ID; } +//======================================================================= +//function : SupplementalContainerGUID +//purpose : +//======================================================================= +const Standard_GUID& XCAFDoc::SupplementalContainerGUID() +{ + static const Standard_GUID ID("da071945-9557-41b4-9e44-19e649f98b54"); + return ID; +} + +//======================================================================= +//function : SupplementalRefGUID +//purpose : +//======================================================================= +const Standard_GUID& XCAFDoc::SupplementalRefGUID() +{ + static const Standard_GUID ID("85a1b8d7-0936-4e8b-a953-a8bd7731411a"); + return ID; +} + +//======================================================================= +//function : SupplementalGeometryGUID +//purpose : +//======================================================================= +const Standard_GUID& XCAFDoc::SupplementalGeometryGUID() +{ + static const Standard_GUID ID("e17cce33-1aa2-4b7f-9060-6e469a7954a9"); + return ID; +} + //======================================================================= //function : LockGUID //purpose : diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index 442c060ac0..e8cd2e4175 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -110,6 +110,15 @@ public: //! Return GUIDs for GraphNode representing specified types of View Standard_EXPORT static const Standard_GUID& ViewRefNoteGUID(); Standard_EXPORT static const Standard_GUID& ViewRefAnnotationGUID(); + + //! Returns GUID for TreeNode representing compound of supplemental geometry + Standard_EXPORT static const Standard_GUID & SupplementalContainerGUID(); + + //! Returns GUID for TreeNode representing reference for supplemental geometry + Standard_EXPORT static const Standard_GUID & SupplementalRefGUID(); + + //! Returns GUID for TreeNode representing supplemental geometry + Standard_EXPORT static const Standard_GUID & SupplementalGeometryGUID(); //! Returns GUID for UAttribute identifying lock flag Standard_EXPORT static const Standard_GUID& LockGUID();