From 48c370666596e918352a502965ff332d191baf14 Mon Sep 17 00:00:00 2001 From: snn Date: Tue, 28 Feb 2017 10:16:38 +0300 Subject: [PATCH] XCAF: assembly item ref extended to point on attributes and sub-shape indices --- .../BinMXCAFDoc_AssemblyItemRefDriver.cxx | 43 +++- src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx | 205 ++++++++++++++++-- src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx | 31 ++- src/XCAFDoc/XCAFDoc_NotesTool.cxx | 24 +- src/XCAFDoc/XCAFDoc_NotesTool.hxx | 6 + .../XmlMXCAFDoc_AssemblyItemRefDriver.cxx | 43 +++- 6 files changed, 320 insertions(+), 32 deletions(-) diff --git a/src/BinMXCAFDoc/BinMXCAFDoc_AssemblyItemRefDriver.cxx b/src/BinMXCAFDoc/BinMXCAFDoc_AssemblyItemRefDriver.cxx index b48806e41f..7d362ec27c 100644 --- a/src/BinMXCAFDoc/BinMXCAFDoc_AssemblyItemRefDriver.cxx +++ b/src/BinMXCAFDoc/BinMXCAFDoc_AssemblyItemRefDriver.cxx @@ -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); + } } diff --git a/src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx b/src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx index 52709afb76..2e100a975d 100644 --- a/src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx +++ b/src/XCAFDoc/XCAFDoc_AssemblyItemRef.cxx @@ -14,12 +14,26 @@ // commercial license or contractual agreement. #include +#include #include +#include #include +#include +#include +#include +#include +#include +#include #include 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; } diff --git a/src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx b/src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx index c162a5ec48..f404398c34 100644 --- a/src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx +++ b/src/XCAFDoc/XCAFDoc_AssemblyItemRef.hxx @@ -18,10 +18,11 @@ #include #include +#include #include #include -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; }; diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.cxx b/src/XCAFDoc/XCAFDoc_NotesTool.cxx index bfdd95ea26..ca8cc80852 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.cxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.cxx @@ -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, diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.hxx b/src/XCAFDoc/XCAFDoc_NotesTool.hxx index 8c25272d6f..43b8cdce78 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.hxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.hxx @@ -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, diff --git a/src/XmlMXCAFDoc/XmlMXCAFDoc_AssemblyItemRefDriver.cxx b/src/XmlMXCAFDoc/XmlMXCAFDoc_AssemblyItemRefDriver.cxx index 23404ed1f3..f9fe9fb022 100644 --- a/src/XmlMXCAFDoc/XmlMXCAFDoc_AssemblyItemRefDriver.cxx +++ b/src/XmlMXCAFDoc/XmlMXCAFDoc_AssemblyItemRefDriver.cxx @@ -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); + } + }