]> OCCT Git - occt-copy.git/commitdiff
0030919: ACIS Import - Improving translation of string attributes into XDE CR30919_730
authoranv <anv@opencascade.com>
Wed, 28 Aug 2019 13:31:12 +0000 (16:31 +0300)
committerapn <apn@opencascade.com>
Thu, 26 Sep 2019 12:58:11 +0000 (15:58 +0300)
- 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
src/XCAFDoc/XCAFDoc_ShapeTool.hxx
src/XDEDRAW/XDEDRAW_Shapes.cxx

index 29edcfbdaea2a0273e3cfcb186d7171a537530b1..3fc73c8fc30727bf9778b9a26e6b191951eb7032 100644 (file)
@@ -2043,3 +2043,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;
+}
index a8638fd7f59e11a328d96e85a5f5948cbe04b9e5..23695951a8e1121e33518cd33c31a9465837a624 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
 #include <Standard_Boolean.hxx>
+#include <TDataStd_NamedData.hxx>
 #include <TDF_Attribute.hxx>
 #include <TDF_LabelSequence.hxx>
 #include <Standard_Integer.hxx>
@@ -405,12 +406,22 @@ 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);
 
-    //! 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)
 
index 82f6dfbaa60af4d7f1b2c6c8d4847555473d1ab2..8842b449c8891e01001c65f265944be3392218d4 100644 (file)
@@ -20,6 +20,7 @@
 #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>
@@ -840,6 +841,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  : 
@@ -943,4 +1002,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);
 }