- Added possibility to get (or create if absent) a properties attribute via ShapeTool;
- Added Draw command to print properties attached to a Label.
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;
+}
#include <XCAFDoc_DataMapOfShapeLabel.hxx>
#include <Standard_Boolean.hxx>
+#include <TDataStd_NamedData.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_LabelSequence.hxx>
#include <Standard_Integer.hxx>
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);
- //! Make subshape for Part from Shape
+ //! Make subshape for Part from Shape
Standard_EXPORT void makeSubShape (const TDF_Label& thePart, const TopoDS_Shape& theShape, const TopLoc_Location& theLoc) ;
+ //! 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)
#include <Draw.hxx>
#include <gp_Trsf.hxx>
#include <TCollection_AsciiString.hxx>
+#include <TDataStd_NamedData.hxx>
#include <TDF_AttributeSequence.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelSequence.hxx>
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 :
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);
}