]> OCCT Git - occt-copy.git/commitdiff
XCAF: assembly item ref extended to point on attributes and sub-shape indices
authorsnn <snn@opencascade.com>
Tue, 28 Feb 2017 07:16:38 +0000 (10:16 +0300)
committersnn <snn@opencascade.com>
Tue, 28 Feb 2017 07:16:38 +0000 (10:16 +0300)
src/BinMXCAFDoc/BinMXCAFDoc_AssemblyItemRefDriver.cxx
src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx
src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx
src/XCAFDoc/XCAFDoc_NotesTool.cxx
src/XCAFDoc/XCAFDoc_NotesTool.hxx
src/XmlMXCAFDoc/XmlMXCAFDoc_AssemblyItemRefDriver.cxx

index b48806e41f7935031ceb89c55b167b952b7e8194..7d362ec27c1bf75820f237d580b231e4b4c18af7 100644 (file)
@@ -53,11 +53,32 @@ Standard_Boolean BinMXCAFDoc_AssemblyItemRefDriver::Paste(const BinObjMgt_Persis
   if (aThis.IsNull())
     return Standard_False;
   
-  TCollection_AsciiString aStr;
-  if (!(theSource >> aStr))
+  TCollection_AsciiString aPathStr;
+  if (!(theSource >> aPathStr))
     return Standard_False;
 
-  aThis->Set(aStr);
+  aThis->SetItem(aPathStr);
+
+  Standard_Integer anExtraRef = 0;
+  if (!(theSource >> anExtraRef))
+    return Standard_False;
+
+  if (anExtraRef == 1)
+  {
+    Standard_GUID aGUID;
+    if (!(theSource >> aGUID))
+      return Standard_False;
+
+    aThis->SetGUID(aGUID);
+  }
+  else if (anExtraRef == 2)
+  {
+    Standard_Integer aSubshapeIndex;
+    if (!(theSource >> aSubshapeIndex))
+      return Standard_False;
+
+    aThis->SetSubshapeIndex(aSubshapeIndex);
+  }
 
   return Standard_True;
 }
@@ -72,5 +93,19 @@ void BinMXCAFDoc_AssemblyItemRefDriver::Paste(const Handle(TDF_Attribute)& theSo
 {
   Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theSource);
   if (!aThis.IsNull())
-    theTarget << aThis->Get().ToString();
+  {
+    theTarget << aThis->GetItem().ToString();
+    if (aThis->IsGUID())
+    {
+      theTarget << Standard_Integer(1);
+      theTarget << aThis->GetGUID();
+    }
+    else if (aThis->IsSubshapeIndex())
+    {
+      theTarget << Standard_Integer(2);
+      theTarget << aThis->GetSubshapeIndex();
+    }
+    else
+      theTarget << Standard_Integer(0);
+  }
 }
index 52709afb76268dd2f6dd00e02b33e140ae12b175..2e100a975d77b24d9f32f96494d12b7300a91a87 100644 (file)
 // commercial license or contractual agreement.
 
 #include <Standard_GUID.hxx>
+#include <TDF_Data.hxx>
 #include <TDF_Label.hxx>
+#include <TDF_Tool.hxx>
 #include <TDF_RelocationTable.hxx>
+#include <TDocStd_Owner.hxx>
+#include <TDocStd_Document.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopExp.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 #include <XCAFDoc_AssemblyItemRef.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_AssemblyItemRef, TDF_Attribute)
 
+enum {
+  ExtraRef_None,
+  ExtraRef_AttrGUID,
+  ExtraRef_SubshapeIndex
+};
+
 const Standard_GUID& 
 XCAFDoc_AssemblyItemRef::GetID()
 {
@@ -43,25 +57,46 @@ XCAFDoc_AssemblyItemRef::Set(const TDF_Label&              theLabel,
   if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
   {
     aThis = new XCAFDoc_AssemblyItemRef();
-    aThis->Set(theItemId);
+    aThis->SetItem(theItemId);
     theLabel.AddAttribute(aThis);
   }
   return aThis;
 }
 
-void 
-XCAFDoc_AssemblyItemRef::Set(const TColStd_ListOfAsciiString& thePath)
-{ 
-  myItemId.Init(thePath);
+Handle(XCAFDoc_AssemblyItemRef) 
+XCAFDoc_AssemblyItemRef::Set(const TDF_Label&              theLabel,
+                             const XCAFDoc_AssemblyItemId& theItemId,
+                             const Standard_GUID&          theAttrGUID)
+{
+  Handle(XCAFDoc_AssemblyItemRef) aThis;
+  if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
+  {
+    aThis = new XCAFDoc_AssemblyItemRef();
+    aThis->SetItem(theItemId);
+    aThis->SetGUID(theAttrGUID);
+    theLabel.AddAttribute(aThis);
+  }
+  return aThis;
 }
 
-void 
-XCAFDoc_AssemblyItemRef::Set(const TCollection_AsciiString& theString)
+Handle(XCAFDoc_AssemblyItemRef) 
+XCAFDoc_AssemblyItemRef::Set(const TDF_Label&              theLabel,
+                             const XCAFDoc_AssemblyItemId& theItemId,
+                             const Standard_Integer        theShapeIndex)
 {
-  myItemId.Init(theString);
+  Handle(XCAFDoc_AssemblyItemRef) aThis;
+  if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
+  {
+    aThis = new XCAFDoc_AssemblyItemRef();
+    aThis->SetItem(theItemId);
+    aThis->SetSubshapeIndex(theShapeIndex);
+    theLabel.AddAttribute(aThis);
+  }
+  return aThis;
 }
 
 XCAFDoc_AssemblyItemRef::XCAFDoc_AssemblyItemRef()
+  : myExtraRef(ExtraRef_None)
 {
 
 }
@@ -69,23 +104,145 @@ XCAFDoc_AssemblyItemRef::XCAFDoc_AssemblyItemRef()
 Standard_Boolean 
 XCAFDoc_AssemblyItemRef::IsOrphan() const
 {
-  // TODO...
+  if (myItemId.IsNull())
+    return Standard_True;
+
+  TDF_Label aRoot = Label().Root();
+
+  Handle(TDocStd_Owner) anOwner;
+  if (!aRoot.FindAttribute(TDocStd_Owner::GetID(), anOwner))
+    return Standard_True;
+
+  Handle(TDocStd_Document) aDoc = anOwner->GetDocument();
+  if (aDoc.IsNull())
+    return Standard_True;
+
+  Handle(TDF_Data) aData = aDoc->GetData();
+  if (aData.IsNull())
+    return Standard_True;
+
+  TDF_Label aLabel;
+  TDF_Tool::Label(aData, myItemId.GetPath().Last(), aLabel);
+  if (aLabel.IsNull())
+    return Standard_True;
+
+  if (HasExtraRef())
+  {
+    if (IsGUID())
+    {
+      Handle(TDF_Attribute) anAttr;
+      if (!aLabel.FindAttribute(GetGUID(), anAttr))
+        return Standard_True;
+    }
+    else if (IsSubshapeIndex())
+    {
+      Handle(TNaming_NamedShape) aNamedShape;
+      if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape))
+        return Standard_True;
+
+      TopoDS_Shape aShape = aNamedShape->Get();
+      TopTools_IndexedMapOfShape aMap;
+      TopExp::MapShapes(aShape, aMap);
+      Standard_Integer aSubshapeIndex = GetSubshapeIndex();
+      if (aSubshapeIndex < 1 || aMap.Size() < aSubshapeIndex)
+        return Standard_True;
+    }
+  }
+
   return Standard_False;
 }
 
+Standard_Boolean 
+XCAFDoc_AssemblyItemRef::HasExtraRef() const
+{
+  return (myExtraRef != ExtraRef_None);
+}
+
+Standard_Boolean 
+XCAFDoc_AssemblyItemRef::IsGUID() const
+{
+  return (myExtraRef == ExtraRef_AttrGUID && Standard_GUID::CheckGUIDFormat(myExtraId.ToCString()));
+}
+
+Standard_Boolean 
+XCAFDoc_AssemblyItemRef::IsSubshapeIndex() const
+{
+  return (myExtraRef == ExtraRef_SubshapeIndex && myExtraId.IsIntegerValue());
+}
+
 const XCAFDoc_AssemblyItemId& 
-XCAFDoc_AssemblyItemRef::Get() const
+XCAFDoc_AssemblyItemRef::GetItem() const
 {
   return myItemId;
 }
 
+Standard_GUID 
+XCAFDoc_AssemblyItemRef::GetGUID() const
+{
+  if (IsGUID())
+    return Standard_GUID(myExtraId.ToCString());
+  else
+    return Standard_GUID();
+}
+
+Standard_Integer 
+XCAFDoc_AssemblyItemRef::GetSubshapeIndex() const
+{
+  if (IsSubshapeIndex())
+    return myExtraId.IntegerValue();
+  else
+    return 0;
+}
+
 void 
-XCAFDoc_AssemblyItemRef::Set(const XCAFDoc_AssemblyItemId& theItemId)
+XCAFDoc_AssemblyItemRef::SetItem(const XCAFDoc_AssemblyItemId& theItemId)
 {
   Backup();
   myItemId = theItemId;
 }
 
+void
+XCAFDoc_AssemblyItemRef::SetItem(const TColStd_ListOfAsciiString& thePath)
+{
+  Backup();
+  myItemId.Init(thePath);
+}
+
+void
+XCAFDoc_AssemblyItemRef::SetItem(const TCollection_AsciiString& theString)
+{
+  Backup();
+  myItemId.Init(theString);
+}
+
+void XCAFDoc_AssemblyItemRef::SetGUID(const Standard_GUID& theAttrGUID)
+{
+  Backup();
+  myExtraRef = ExtraRef_AttrGUID;
+  Standard_Character aGUIDStr[Standard_GUID_SIZE + 1];
+  theAttrGUID.ToCString(aGUIDStr); 
+  aGUIDStr[Standard_GUID_SIZE] = '\0';
+  myExtraId.Clear();
+  myExtraId.AssignCat(aGUIDStr);
+}
+
+void 
+XCAFDoc_AssemblyItemRef::SetSubshapeIndex(Standard_Integer theSubshapeIndex)
+{
+  Backup();
+  myExtraRef = ExtraRef_SubshapeIndex;
+  myExtraId.Clear();
+  myExtraId.AssignCat(theSubshapeIndex);
+}
+
+void 
+XCAFDoc_AssemblyItemRef::ClearExtraRef()
+{
+  Backup();
+  myExtraRef = ExtraRef_None;
+  myExtraId.Clear();
+}
+
 const Standard_GUID& 
 XCAFDoc_AssemblyItemRef::ID() const
 {
@@ -101,23 +258,35 @@ XCAFDoc_AssemblyItemRef::NewEmpty() const
 void 
 XCAFDoc_AssemblyItemRef::Restore(const Handle(TDF_Attribute)& theAttrFrom)
 {
-  Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrFrom);
-  if (!aThis.IsNull())
-    myItemId = aThis->myItemId;
+  Handle(XCAFDoc_AssemblyItemRef) anOther = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrFrom);
+  if (!anOther.IsNull())
+  {
+    myItemId = anOther->myItemId;
+    myExtraRef = anOther->myExtraRef;
+    myExtraId = anOther->myExtraId;
+  }
 }
 
 void 
 XCAFDoc_AssemblyItemRef::Paste(const Handle(TDF_Attribute)&       theAttrInto,
                                const Handle(TDF_RelocationTable)& /*theRT*/) const
 {
-  Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrInto);
-  if (!aThis.IsNull())
-    aThis->myItemId = myItemId;
+  Handle(XCAFDoc_AssemblyItemRef) anOther = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrInto);
+  if (!anOther.IsNull())
+  {
+    anOther->myItemId = myItemId;
+    anOther->myExtraRef = myExtraRef;
+    anOther->myExtraId = myExtraId;
+  }
 }
 
 Standard_OStream& 
 XCAFDoc_AssemblyItemRef::Dump(Standard_OStream& theOS) const
 {
-  theOS << myItemId.ToString();
+  theOS << "Path: " << myItemId.ToString();
+  if (IsGUID())
+    theOS << "/GUID:" << myExtraId;
+  else if (IsSubshapeIndex())
+    theOS << "/Subshape: " << myExtraId;
   return theOS;
 }
index c162a5ec48e0f4552211cf1f423ee8194c026328..f404398c3429f614d076a4ae175947159fd70cbe 100644 (file)
 
 #include <Standard.hxx>
 #include <Standard_Type.hxx>
+#include <Standard_GUID.hxx>
 #include <TDF_Attribute.hxx>
 #include <XCAFDoc_AssemblyItemId.hxx>
 
-class Standard_GUID;
+class TDF_Data;
 class TDF_RelocationTable;
 
 class XCAFDoc_AssemblyItemRef;
@@ -40,16 +41,32 @@ public:
 
   Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
                                                              const XCAFDoc_AssemblyItemId& theItemId);
+  Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
+                                                             const XCAFDoc_AssemblyItemId& theItemId,
+                                                             const Standard_GUID&          theGUID);
+  Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label&              theLabel,
+                                                             const XCAFDoc_AssemblyItemId& theItemId,
+                                                             const Standard_Integer        theShapeIndex);
 
   Standard_EXPORT XCAFDoc_AssemblyItemRef();
 
   Standard_EXPORT Standard_Boolean IsOrphan() const;
 
-  Standard_EXPORT const XCAFDoc_AssemblyItemId& Get() const;
+  Standard_EXPORT Standard_Boolean HasExtraRef() const;
+  Standard_EXPORT Standard_Boolean IsGUID() const;
+  Standard_EXPORT Standard_Boolean IsSubshapeIndex() const;
+
+  Standard_EXPORT const XCAFDoc_AssemblyItemId& GetItem() const;
+  Standard_EXPORT Standard_GUID GetGUID() const;
+  Standard_EXPORT Standard_Integer GetSubshapeIndex() const;
   
-  Standard_EXPORT void Set(const XCAFDoc_AssemblyItemId& theItemId);
-  Standard_EXPORT void Set(const TColStd_ListOfAsciiString& thePath);
-  Standard_EXPORT void Set(const TCollection_AsciiString& theString);
+  Standard_EXPORT void SetItem(const XCAFDoc_AssemblyItemId& theItemId);
+  Standard_EXPORT void SetItem(const TColStd_ListOfAsciiString& thePath);
+  Standard_EXPORT void SetItem(const TCollection_AsciiString& theString);
+  Standard_EXPORT void SetGUID(const Standard_GUID& theAttrGUID);
+  Standard_EXPORT void SetSubshapeIndex(Standard_Integer theShapeIndex);
+
+  Standard_EXPORT void ClearExtraRef();
 
 public:
 
@@ -66,7 +83,9 @@ public:
 
 private:
 
-  XCAFDoc_AssemblyItemId myItemId;
+  XCAFDoc_AssemblyItemId  myItemId;
+  Standard_Integer        myExtraRef;
+  TCollection_AsciiString myExtraId;
 
 };
 
index bfdd95ea26603d20bb7105d1cefa9e87a564c69b..ca8cc8085204b4b2390a4912a0d65044ea53a016 100644 (file)
@@ -125,7 +125,7 @@ XCAFDoc_NotesTool::FindAnnotatedItem(const XCAFDoc_AssemblyItemId& theItemId) co
   for (TDF_ChildIDIterator anIter(GetAnnotatedItemsLabel(), XCAFDoc_AssemblyItemRef::GetID()); anIter.More(); anIter.Next())
   {
     Handle(XCAFDoc_AssemblyItemRef) anItemRef = Handle(XCAFDoc_AssemblyItemRef)::DownCast(anIter.Value());
-    if (!anItemRef.IsNull() && anItemRef->Get().IsEqual(theItemId))
+    if (!anItemRef.IsNull() && anItemRef->GetItem().IsEqual(theItemId))
       return anItemRef->Label();
   }
   return TDF_Label();
@@ -237,6 +237,28 @@ XCAFDoc_NotesTool::AddNote(const TDF_Label&              theNoteLabel,
   return anItemRef;
 }
 
+Handle(XCAFDoc_AssemblyItemRef) 
+XCAFDoc_NotesTool::AddNoteToAttr(const TDF_Label&              theNoteLabel,
+              const XCAFDoc_AssemblyItemId& theItemId,
+              const Standard_GUID&          theGUID)
+{
+  Handle(XCAFDoc_AssemblyItemRef) anItemRef = AddNote(theNoteLabel, theItemId);
+  if (!anItemRef.IsNull())
+    anItemRef->SetGUID(theGUID);
+  return anItemRef;
+}
+
+Handle(XCAFDoc_AssemblyItemRef) 
+XCAFDoc_NotesTool::AddNoteToSubshape(const TDF_Label&              theNoteLabel,
+                  const XCAFDoc_AssemblyItemId& theItemId,
+                  Standard_Integer              theSubshapeIndex)
+{
+  Handle(XCAFDoc_AssemblyItemRef) anItemRef = AddNote(theNoteLabel, theItemId);
+  if (!anItemRef.IsNull())
+    anItemRef->SetSubshapeIndex(theSubshapeIndex);
+  return anItemRef;
+}
+
 Standard_Boolean 
 XCAFDoc_NotesTool::RemoveNote(const TDF_Label&              theNoteLabel,
                               const XCAFDoc_AssemblyItemId& theItemId,
index 8c25272d6f832adeda200cd5b33459e01ab0752a..43b8cdce78fdf520bc2a583448e9bbd5475a151e 100644 (file)
@@ -79,6 +79,12 @@ public:
 
   Standard_EXPORT Handle(XCAFDoc_AssemblyItemRef) AddNote(const TDF_Label&              theNoteLabel,
                                                           const XCAFDoc_AssemblyItemId& theItemId);
+  Standard_EXPORT Handle(XCAFDoc_AssemblyItemRef) AddNoteToAttr(const TDF_Label&              theNoteLabel,
+                                                                const XCAFDoc_AssemblyItemId& theItemId,
+                                                                const Standard_GUID&          theGUID);
+  Standard_EXPORT Handle(XCAFDoc_AssemblyItemRef) AddNoteToSubshape(const TDF_Label&              theNoteLabel,
+                                                                    const XCAFDoc_AssemblyItemId& theItemId,
+                                                                    Standard_Integer              theSubshapeIndex);
 
   Standard_EXPORT Standard_Boolean RemoveNote(const TDF_Label&              theNoteLabel,
                                               const XCAFDoc_AssemblyItemId& theItemId,
index 23404ed1f3fed2dd25289f7045154758259d6cac..f9fe9fb022b147f3f0b6ee89c47ae3f97b909c54 100644 (file)
@@ -22,6 +22,8 @@
 
 IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AssemblyItemRefDriver, XmlMDF_ADriver)
 IMPLEMENT_DOMSTRING(Path, "path")
+IMPLEMENT_DOMSTRING(AttrGUID, "guid")
+IMPLEMENT_DOMSTRING(SubshapeIndex, "subshape_index")
 
 //=======================================================================
 //function :
@@ -59,7 +61,26 @@ Standard_Boolean XmlMXCAFDoc_AssemblyItemRefDriver::Paste(const XmlObjMgt_Persis
   if (aThis.IsNull())
     return Standard_False;
 
-  aThis->Set(aPath.GetString());
+  aThis->SetItem(aPath.GetString());
+
+  XmlObjMgt_DOMString anAttrGUID = anElement.getAttribute(::AttrGUID());
+  if (anAttrGUID != NULL)
+  {
+    Standard_GUID aGUID(anAttrGUID.GetString());
+    aThis->SetGUID(aGUID);
+    return Standard_True;
+  }
+
+  XmlObjMgt_DOMString aSubshapeIndex = anElement.getAttribute(::SubshapeIndex());
+  if (aSubshapeIndex != NULL)
+  {
+    Standard_Integer anIndex;
+    if (!aSubshapeIndex.GetInteger(anIndex))
+      return Standard_False;
+
+    aThis->SetSubshapeIndex(anIndex);
+    return Standard_True;
+  }
 
   return Standard_True;
 }
@@ -74,7 +95,23 @@ void XmlMXCAFDoc_AssemblyItemRefDriver::Paste(const Handle(TDF_Attribute)& theSo
 {
   Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theSource);
 
-  XmlObjMgt_DOMString aPath(aThis->Get().ToString().ToCString());
-
+  XmlObjMgt_DOMString aPath(aThis->GetItem().ToString().ToCString());
   theTarget.Element().setAttribute(::Path(), aPath);
+
+  if (aThis->IsGUID())
+  {
+    Standard_GUID aGUID = aThis->GetGUID();
+    Standard_Character aGUIDStr[Standard_GUID_SIZE + 1];
+    aGUID.ToCString(aGUIDStr);
+    aGUIDStr[Standard_GUID_SIZE] = '\0';
+    XmlObjMgt_DOMString anAttrGUID(aGUIDStr);
+    theTarget.Element().setAttribute(::AttrGUID(), anAttrGUID);
+  }
+  else if (aThis->IsSubshapeIndex())
+  {
+    TCollection_AsciiString aSubshapeIndexStr(aThis->GetSubshapeIndex());
+    XmlObjMgt_DOMString aSubshapeIndex(aSubshapeIndexStr.ToCString());
+    theTarget.Element().setAttribute(::SubshapeIndex(), aSubshapeIndex);
+  }
+
 }