From a7a1acb14bf6c2cd10ebe4f48b1ff5898a4adcd1 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 13 Mar 2018 16:22:28 +0300 Subject: [PATCH] new methods GetGDTPresentations(.) and GetGDTPresentations(.) for Dimension Tool --- src/XCAFDoc/XCAFDoc_DimTolTool.cxx | 91 ++++++++++++++++++++++++++++++ src/XCAFDoc/XCAFDoc_DimTolTool.hxx | 11 ++++ 2 files changed, 102 insertions(+) diff --git a/src/XCAFDoc/XCAFDoc_DimTolTool.cxx b/src/XCAFDoc/XCAFDoc_DimTolTool.cxx index 69f28e87df..d10123ea7f 100644 --- a/src/XCAFDoc/XCAFDoc_DimTolTool.cxx +++ b/src/XCAFDoc/XCAFDoc_DimTolTool.cxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -991,3 +993,92 @@ void XCAFDoc_DimTolTool::Paste(const Handle(TDF_Attribute)& /*into*/, { } +void XCAFDoc_DimTolTool::GetGDTPresentations(NCollection_IndexedDataMap& theGDTLabelToShape) const +{ + TDF_LabelSequence aGDTs; + GetDimensionLabels(aGDTs); + for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) { + Handle(XCAFDoc_Dimension) aDimAttr; + const TDF_Label& aCL = aGDTs.Value(i); + if (!aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr)) + continue; + Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject(); + if (anObject.IsNull()) + continue; + TopoDS_Shape aShape = anObject->GetPresentation(); + if (!aShape.IsNull()) + theGDTLabelToShape.Add(aCL, aShape); + } + + aGDTs.Clear(); + GetGeomToleranceLabels(aGDTs); + for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) { + Handle(XCAFDoc_GeomTolerance) aGTAttr; + const TDF_Label& aCL = aGDTs.Value(i); + if (!aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aGTAttr)) + continue; + Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject(); + if (anObject.IsNull()) + continue; + TopoDS_Shape aShape = anObject->GetPresentation(); + if (!aShape.IsNull()) + theGDTLabelToShape.Add(aCL, aShape); + } + + aGDTs.Clear(); + GetDatumLabels(aGDTs); + for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) { + Handle(XCAFDoc_Datum) aGTAttr; + const TDF_Label& aCL = aGDTs.Value(i); + if (!aCL.FindAttribute(XCAFDoc_Datum::GetID(),aGTAttr)) + continue; + Handle(XCAFDimTolObjects_DatumObject) anObject = aGTAttr->GetObject(); + if (anObject.IsNull()) + continue; + TopoDS_Shape aShape = anObject->GetPresentation(); + if (!aShape.IsNull()) + theGDTLabelToShape.Add(aCL, aShape); + } +} + +void XCAFDoc_DimTolTool::SetGDTPresentations(NCollection_IndexedDataMap& theGDTLabelToPrs) +{ + for (Standard_Integer i = 1; i <= theGDTLabelToPrs.Extent(); i++) + { + const TDF_Label& aCL = theGDTLabelToPrs.FindKey(i); + Handle(XCAFDoc_Dimension) aDimAttrDim; + if (aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttrDim)) + { + Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttrDim->GetObject(); + if (anObject.IsNull()) + continue; + const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i); + anObject->SetPresentation(aPrs, anObject->GetPresentationName()); + aDimAttrDim->SetObject(anObject); + continue; + } + Handle(XCAFDoc_GeomTolerance) aDimAttrG; + if (aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimAttrG)) + { + Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aDimAttrG->GetObject(); + if (anObject.IsNull()) + continue; + const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i); + anObject->SetPresentation(aPrs, anObject->GetPresentationName()); + aDimAttrG->SetObject(anObject); + continue; + } + Handle(XCAFDoc_Datum) aDimAttrD; + if (aCL.FindAttribute(XCAFDoc_Datum::GetID(),aDimAttrD)) + { + Handle(XCAFDimTolObjects_DatumObject) anObject = aDimAttrD->GetObject(); + if (anObject.IsNull()) + continue; + const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i); + anObject->SetPresentation(aPrs, anObject->GetPresentationName()); + aDimAttrD->SetObject(anObject); + continue; + } + } +} \ No newline at end of file diff --git a/src/XCAFDoc/XCAFDoc_DimTolTool.hxx b/src/XCAFDoc/XCAFDoc_DimTolTool.hxx index 1c6253ca0a..870b1a581b 100644 --- a/src/XCAFDoc/XCAFDoc_DimTolTool.hxx +++ b/src/XCAFDoc/XCAFDoc_DimTolTool.hxx @@ -25,6 +25,8 @@ #include #include #include +#include +#include class XCAFDoc_ShapeTool; class TDF_Label; @@ -236,6 +238,15 @@ public: //! Mark the given GDT as locked. Standard_EXPORT void Lock(const TDF_Label& theViewL) const; + //! fill the map GDT label -> shape presentation + Standard_EXPORT void GetGDTPresentations(NCollection_IndexedDataMap& theGDTLabelToShape) const; + + //! Set shape presentation for GDT labels according to given map (theGDTLabelToPrs) + //! theGDTLabelToPrsName map is an additional argument, can be used to set presentation names. + //! If label is not in the theGDTLabelToPrsName map, the presentation name will be empty + Standard_EXPORT void SetGDTPresentations(NCollection_IndexedDataMap& theGDTLabelToPrs); + //! Unlock the given GDT. Standard_EXPORT void Unlock(const TDF_Label& theViewL) const; -- 2.39.5