1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-01 10:26:12 +03:00

XCAF: assembly item ref extended to point on attributes and sub-shape indices

This commit is contained in:
snn 2017-02-28 10:16:38 +03:00
parent ac5eea5d0e
commit 48c3706665
6 changed files with 320 additions and 32 deletions

View File

@ -53,11 +53,32 @@ Standard_Boolean BinMXCAFDoc_AssemblyItemRefDriver::Paste(const BinObjMgt_Persis
if (aThis.IsNull()) if (aThis.IsNull())
return Standard_False; return Standard_False;
TCollection_AsciiString aStr; TCollection_AsciiString aPathStr;
if (!(theSource >> aStr)) if (!(theSource >> aPathStr))
return Standard_False; 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; 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); Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theSource);
if (!aThis.IsNull()) 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);
}
} }

View File

@ -14,12 +14,26 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <Standard_GUID.hxx> #include <Standard_GUID.hxx>
#include <TDF_Data.hxx>
#include <TDF_Label.hxx> #include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <TDF_RelocationTable.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> #include <XCAFDoc_AssemblyItemRef.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_AssemblyItemRef, TDF_Attribute) IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_AssemblyItemRef, TDF_Attribute)
enum {
ExtraRef_None,
ExtraRef_AttrGUID,
ExtraRef_SubshapeIndex
};
const Standard_GUID& const Standard_GUID&
XCAFDoc_AssemblyItemRef::GetID() XCAFDoc_AssemblyItemRef::GetID()
{ {
@ -43,25 +57,46 @@ XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis)) if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
{ {
aThis = new XCAFDoc_AssemblyItemRef(); aThis = new XCAFDoc_AssemblyItemRef();
aThis->Set(theItemId); aThis->SetItem(theItemId);
theLabel.AddAttribute(aThis); theLabel.AddAttribute(aThis);
} }
return aThis; return aThis;
} }
void Handle(XCAFDoc_AssemblyItemRef)
XCAFDoc_AssemblyItemRef::Set(const TColStd_ListOfAsciiString& thePath) XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
const XCAFDoc_AssemblyItemId& theItemId,
const Standard_GUID& theAttrGUID)
{ {
myItemId.Init(thePath); 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 Handle(XCAFDoc_AssemblyItemRef)
XCAFDoc_AssemblyItemRef::Set(const TCollection_AsciiString& theString) 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() XCAFDoc_AssemblyItemRef::XCAFDoc_AssemblyItemRef()
: myExtraRef(ExtraRef_None)
{ {
} }
@ -69,23 +104,145 @@ XCAFDoc_AssemblyItemRef::XCAFDoc_AssemblyItemRef()
Standard_Boolean Standard_Boolean
XCAFDoc_AssemblyItemRef::IsOrphan() const 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; 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& const XCAFDoc_AssemblyItemId&
XCAFDoc_AssemblyItemRef::Get() const XCAFDoc_AssemblyItemRef::GetItem() const
{ {
return myItemId; 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 void
XCAFDoc_AssemblyItemRef::Set(const XCAFDoc_AssemblyItemId& theItemId) XCAFDoc_AssemblyItemRef::SetItem(const XCAFDoc_AssemblyItemId& theItemId)
{ {
Backup(); Backup();
myItemId = theItemId; 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& const Standard_GUID&
XCAFDoc_AssemblyItemRef::ID() const XCAFDoc_AssemblyItemRef::ID() const
{ {
@ -101,23 +258,35 @@ XCAFDoc_AssemblyItemRef::NewEmpty() const
void void
XCAFDoc_AssemblyItemRef::Restore(const Handle(TDF_Attribute)& theAttrFrom) XCAFDoc_AssemblyItemRef::Restore(const Handle(TDF_Attribute)& theAttrFrom)
{ {
Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrFrom); Handle(XCAFDoc_AssemblyItemRef) anOther = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrFrom);
if (!aThis.IsNull()) if (!anOther.IsNull())
myItemId = aThis->myItemId; {
myItemId = anOther->myItemId;
myExtraRef = anOther->myExtraRef;
myExtraId = anOther->myExtraId;
}
} }
void void
XCAFDoc_AssemblyItemRef::Paste(const Handle(TDF_Attribute)& theAttrInto, XCAFDoc_AssemblyItemRef::Paste(const Handle(TDF_Attribute)& theAttrInto,
const Handle(TDF_RelocationTable)& /*theRT*/) const const Handle(TDF_RelocationTable)& /*theRT*/) const
{ {
Handle(XCAFDoc_AssemblyItemRef) aThis = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrInto); Handle(XCAFDoc_AssemblyItemRef) anOther = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrInto);
if (!aThis.IsNull()) if (!anOther.IsNull())
aThis->myItemId = myItemId; {
anOther->myItemId = myItemId;
anOther->myExtraRef = myExtraRef;
anOther->myExtraId = myExtraId;
}
} }
Standard_OStream& Standard_OStream&
XCAFDoc_AssemblyItemRef::Dump(Standard_OStream& theOS) const 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; return theOS;
} }

View File

@ -18,10 +18,11 @@
#include <Standard.hxx> #include <Standard.hxx>
#include <Standard_Type.hxx> #include <Standard_Type.hxx>
#include <Standard_GUID.hxx>
#include <TDF_Attribute.hxx> #include <TDF_Attribute.hxx>
#include <XCAFDoc_AssemblyItemId.hxx> #include <XCAFDoc_AssemblyItemId.hxx>
class Standard_GUID; class TDF_Data;
class TDF_RelocationTable; class TDF_RelocationTable;
class XCAFDoc_AssemblyItemRef; class XCAFDoc_AssemblyItemRef;
@ -40,16 +41,32 @@ public:
Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label& theLabel, Standard_EXPORT static Handle(XCAFDoc_AssemblyItemRef) Set(const TDF_Label& theLabel,
const XCAFDoc_AssemblyItemId& theItemId); 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 XCAFDoc_AssemblyItemRef();
Standard_EXPORT Standard_Boolean IsOrphan() const; 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 void Set(const XCAFDoc_AssemblyItemId& theItemId); Standard_EXPORT const XCAFDoc_AssemblyItemId& GetItem() const;
Standard_EXPORT void Set(const TColStd_ListOfAsciiString& thePath); Standard_EXPORT Standard_GUID GetGUID() const;
Standard_EXPORT void Set(const TCollection_AsciiString& theString); Standard_EXPORT Standard_Integer GetSubshapeIndex() const;
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: public:
@ -67,6 +84,8 @@ public:
private: private:
XCAFDoc_AssemblyItemId myItemId; XCAFDoc_AssemblyItemId myItemId;
Standard_Integer myExtraRef;
TCollection_AsciiString myExtraId;
}; };

View 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()) for (TDF_ChildIDIterator anIter(GetAnnotatedItemsLabel(), XCAFDoc_AssemblyItemRef::GetID()); anIter.More(); anIter.Next())
{ {
Handle(XCAFDoc_AssemblyItemRef) anItemRef = Handle(XCAFDoc_AssemblyItemRef)::DownCast(anIter.Value()); 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 anItemRef->Label();
} }
return TDF_Label(); return TDF_Label();
@ -237,6 +237,28 @@ XCAFDoc_NotesTool::AddNote(const TDF_Label& theNoteLabel,
return anItemRef; 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 Standard_Boolean
XCAFDoc_NotesTool::RemoveNote(const TDF_Label& theNoteLabel, XCAFDoc_NotesTool::RemoveNote(const TDF_Label& theNoteLabel,
const XCAFDoc_AssemblyItemId& theItemId, const XCAFDoc_AssemblyItemId& theItemId,

View File

@ -79,6 +79,12 @@ public:
Standard_EXPORT Handle(XCAFDoc_AssemblyItemRef) AddNote(const TDF_Label& theNoteLabel, Standard_EXPORT Handle(XCAFDoc_AssemblyItemRef) AddNote(const TDF_Label& theNoteLabel,
const XCAFDoc_AssemblyItemId& theItemId); 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, Standard_EXPORT Standard_Boolean RemoveNote(const TDF_Label& theNoteLabel,
const XCAFDoc_AssemblyItemId& theItemId, const XCAFDoc_AssemblyItemId& theItemId,

View File

@ -22,6 +22,8 @@
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AssemblyItemRefDriver, XmlMDF_ADriver) IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AssemblyItemRefDriver, XmlMDF_ADriver)
IMPLEMENT_DOMSTRING(Path, "path") IMPLEMENT_DOMSTRING(Path, "path")
IMPLEMENT_DOMSTRING(AttrGUID, "guid")
IMPLEMENT_DOMSTRING(SubshapeIndex, "subshape_index")
//======================================================================= //=======================================================================
//function : //function :
@ -59,7 +61,26 @@ Standard_Boolean XmlMXCAFDoc_AssemblyItemRefDriver::Paste(const XmlObjMgt_Persis
if (aThis.IsNull()) if (aThis.IsNull())
return Standard_False; 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; 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); 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); 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);
}
} }