From 07f206461727bd6962e31ad0db131f3358cba3c1 Mon Sep 17 00:00:00 2001 From: anv Date: Wed, 28 Aug 2019 16:31:12 +0300 Subject: [PATCH] 0030919: ACIS Import - Improving translation of string attributes into XDE - Added possibility to get (or create if absent) a properties attribute via ShapeTool; - Added Draw command to print properties attached to a Label. --- src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 35 +++++++++++++++++ src/XCAFDoc/XCAFDoc_ShapeTool.hxx | 14 ++++++- src/XDEDRAW/XDEDRAW_Shapes.cxx | 62 +++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 5cee04bdad..6142603e3a 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -2108,3 +2108,38 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe return isModified; } + +//======================================================================= +//function : GetNamedProperties +//purpose : +//======================================================================= + +Handle(TDataStd_NamedData) XCAFDoc_ShapeTool::GetNamedProperties (const TDF_Label& theLabel, + const Standard_Boolean theToCreate) const +{ + Handle(TDataStd_NamedData) aNamedProperty; + if (!theLabel.FindAttribute(TDataStd_NamedData::GetID(), aNamedProperty) && theToCreate) + { + aNamedProperty = TDataStd_NamedData::Set(theLabel); + } + + return aNamedProperty; +} + +//======================================================================= +//function : GetNamedProperties +//purpose : +//======================================================================= + +Handle(TDataStd_NamedData) XCAFDoc_ShapeTool::GetNamedProperties (const TopoDS_Shape& theShape, + const Standard_Boolean theToCreate) const +{ + Handle(TDataStd_NamedData) aNamedProperty; + TDF_Label aLabel; + if (!Search (theShape, aLabel)) + return aNamedProperty; + + aNamedProperty = GetNamedProperties (aLabel, theToCreate); + + return aNamedProperty; +} diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx index d927b52baf..2cc83e0b6d 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.hxx @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -410,8 +411,19 @@ public: Standard_EXPORT static Standard_Boolean FindSHUO (const TDF_LabelSequence& Labels, Handle(XCAFDoc_GraphNode)& theSHUOAttr); //! Convert Shape (compound/compsolid/shell/wire) to assembly - Standard_EXPORT Standard_Boolean Expand (const TDF_Label& Shape) ; + Standard_EXPORT Standard_Boolean Expand (const TDF_Label& Shape); + //! Method to get NamedData attribute assigned to the given shape label. + //! @param theLabel [in] the shape Label + //! @param theToCreate [in] create and assign attribute if it doesn't exist + //! @return Handle to the NamedData attribute or Null if there is none + Standard_EXPORT Handle(TDataStd_NamedData) GetNamedProperties (const TDF_Label& theLabel, const Standard_Boolean theToCreate = Standard_False) const; + + //! Method to get NamedData attribute assigned to a label of the given shape. + //! @param theShape [in] input shape + //! @param theToCreate [in] create and assign attribute if it doesn't exist + //! @return Handle to the NamedData attribute or Null if there is none + Standard_EXPORT Handle(TDataStd_NamedData) GetNamedProperties(const TopoDS_Shape& theShape, const Standard_Boolean theToCreate = Standard_False) const; DEFINE_STANDARD_RTTIEXT(XCAFDoc_ShapeTool,TDF_Attribute) diff --git a/src/XDEDRAW/XDEDRAW_Shapes.cxx b/src/XDEDRAW/XDEDRAW_Shapes.cxx index a79a3a6961..95421055b0 100644 --- a/src/XDEDRAW/XDEDRAW_Shapes.cxx +++ b/src/XDEDRAW/XDEDRAW_Shapes.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -927,6 +928,64 @@ static Standard_Integer updateAssemblies(Draw_Interpretor& di, Standard_Integer return 0; } +static Standard_Integer XGetProperties(Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc != 3) + { + std::cout << "Syntax error: wrong number of arguments\nUse: " << argv[0] << " Doc Label\n"; + return 1; + } + + Handle(TDocStd_Document) aDoc; + DDocStd::GetDocument(argv[1], aDoc); + if (aDoc.IsNull()) + { + std::cout << "Syntax error: " << argv[1] << " is not a document\n"; + return 1; + } + + TDF_Label aLabel; + TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel); + + // Get XDE shape tool + Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); + + Handle(TDataStd_NamedData) aNamedData = aShapeTool->GetNamedProperties(aLabel); + + if (aNamedData.IsNull()) + { + di << argv[2] << " has no properties\n"; + return 0; + } + + if (aNamedData->HasIntegers()) + { + TColStd_DataMapOfStringInteger anIntProperties = aNamedData->GetIntegersContainer(); + for (TColStd_DataMapIteratorOfDataMapOfStringInteger anIter(anIntProperties); anIter.More(); anIter.Next()) + { + di << anIter.Key() << " : " << anIter.Value() << "\n"; + } + } + if (aNamedData->HasReals()) + { + TDataStd_DataMapOfStringReal aRealProperties = aNamedData->GetRealsContainer(); + for (TDataStd_DataMapIteratorOfDataMapOfStringReal anIter(aRealProperties); anIter.More(); anIter.Next()) + { + di << anIter.Key() << " : " << anIter.Value() << "\n"; + } + } + if (aNamedData->HasStrings()) + { + TDataStd_DataMapOfStringString aStringProperties = aNamedData->GetStringsContainer(); + for (TDataStd_DataMapIteratorOfDataMapOfStringString anIter(aStringProperties); anIter.More(); anIter.Next()) + { + di << anIter.Key() << " : " << anIter.Value() << "\n"; + } + } + + return 0; +} + //======================================================================= //function : InitCommands //purpose : @@ -1039,4 +1098,7 @@ void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di) di.Add ("XUpdateAssemblies","Doc \t: updates assembly compounds", __FILE__, updateAssemblies, g); + + di.Add("XGetProperties", "Doc Label \t: prints named properties assigned to the Label", + __FILE__, XGetProperties, g); }