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;
}
{
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);
+ }
}
// 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()
{
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)
{
}
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
{
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;
}
#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;
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:
private:
- XCAFDoc_AssemblyItemId myItemId;
+ XCAFDoc_AssemblyItemId myItemId;
+ Standard_Integer myExtraRef;
+ TCollection_AsciiString myExtraId;
};
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();
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,
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,
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AssemblyItemRefDriver, XmlMDF_ADriver)
IMPLEMENT_DOMSTRING(Path, "path")
+IMPLEMENT_DOMSTRING(AttrGUID, "guid")
+IMPLEMENT_DOMSTRING(SubshapeIndex, "subshape_index")
//=======================================================================
//function :
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;
}
{
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);
+ }
+
}