mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-06-20 11:54:07 +03:00
XCAF: binary notes with array of bytes
This commit is contained in:
parent
e66ddc4bab
commit
bc1c59d0a0
@ -17,6 +17,7 @@
|
||||
#include <CDM_MessageDriver.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
#include <TColStd_HArray1OfByte.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <BinMXCAFDoc_NoteBinDataDriver.hxx>
|
||||
@ -58,11 +59,19 @@ Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent
|
||||
return Standard_False;
|
||||
|
||||
TCollection_ExtendedString aTitle;
|
||||
TCollection_AsciiString aData, aMIMEtype;
|
||||
if (!(theSource >> aTitle >> aData >> aMIMEtype))
|
||||
TCollection_AsciiString aMIMEtype;
|
||||
Standard_Integer nbSize;
|
||||
if (!(theSource >> aTitle >> aMIMEtype >> nbSize))
|
||||
return Standard_False;
|
||||
|
||||
aNote->Set(aTitle, aData, aMIMEtype);
|
||||
Handle(TColStd_HArray1OfByte) aData;
|
||||
if (nbSize > 0)
|
||||
{
|
||||
aData.reset(new TColStd_HArray1OfByte(1, nbSize));
|
||||
theSource.GetByteArray(&aData->ChangeFirst(), nbSize);
|
||||
}
|
||||
|
||||
aNote->Set(aTitle, aMIMEtype, aData);
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
@ -80,10 +89,8 @@ void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource
|
||||
Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource);
|
||||
if (!aNote.IsNull())
|
||||
{
|
||||
theTarget
|
||||
<< aNote->Title()
|
||||
<< aNote->MIMEtype()
|
||||
<< aNote->Data()
|
||||
;
|
||||
theTarget << aNote->Title() << aNote->MIMEtype() << aNote->Size();
|
||||
if (aNote->Size() > 0)
|
||||
theTarget.PutByteArray(&aNote->Data()->ChangeFirst(), aNote->Size());
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <OSD_File.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <XCAFDoc_NoteBinData.hxx>
|
||||
|
||||
@ -33,19 +32,41 @@ Standard_Boolean XCAFDoc_NoteBinData::IsMine(const TDF_Label& theLabel)
|
||||
return (!theLabel.IsNull() && theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), anAttr));
|
||||
}
|
||||
|
||||
Handle(XCAFDoc_NoteBinData) XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel,
|
||||
const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype)
|
||||
Handle(XCAFDoc_NoteBinData)
|
||||
XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel,
|
||||
const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile)
|
||||
{
|
||||
Handle(XCAFDoc_NoteBinData) aNoteBinData;
|
||||
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNoteBinData))
|
||||
{
|
||||
aNoteBinData = new XCAFDoc_NoteBinData();
|
||||
aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp);
|
||||
aNoteBinData->Set(theTitle, theFile, theMIMEtype);
|
||||
if (aNoteBinData->Set(theTitle, theMIMEtype, theFile))
|
||||
theLabel.AddAttribute(aNoteBinData);
|
||||
else
|
||||
aNoteBinData.Nullify();
|
||||
}
|
||||
return aNoteBinData;
|
||||
}
|
||||
|
||||
Handle(XCAFDoc_NoteBinData)
|
||||
XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel,
|
||||
const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData)
|
||||
{
|
||||
Handle(XCAFDoc_NoteBinData) aNoteBinData;
|
||||
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNoteBinData))
|
||||
{
|
||||
aNoteBinData = new XCAFDoc_NoteBinData();
|
||||
aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp);
|
||||
aNoteBinData->Set(theTitle, theMIMEtype, theData);
|
||||
theLabel.AddAttribute(aNoteBinData);
|
||||
}
|
||||
return aNoteBinData;
|
||||
@ -55,25 +76,33 @@ XCAFDoc_NoteBinData::XCAFDoc_NoteBinData()
|
||||
{
|
||||
}
|
||||
|
||||
void XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype)
|
||||
Standard_Boolean XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile)
|
||||
{
|
||||
if (!theFile.IsOpen() || !theFile.IsReadable())
|
||||
return;
|
||||
return Standard_False;
|
||||
|
||||
Backup();
|
||||
|
||||
TCollection_AsciiString myData;
|
||||
theFile.Read(myData, theFile.Size());
|
||||
if (theFile.Size() > IntegerLast())
|
||||
return Standard_False;
|
||||
|
||||
myData.reset(new TColStd_HArray1OfByte(1, theFile.Size()));
|
||||
Standard_Integer nbReadBytes = 0;
|
||||
theFile.Read((Standard_Address)&myData->First(), myData->Length(), nbReadBytes);
|
||||
if (nbReadBytes < myData->Length())
|
||||
return Standard_False;
|
||||
|
||||
myTitle = theTitle;
|
||||
myMIMEtype = theMIMEtype;
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
void XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theData,
|
||||
const TCollection_AsciiString& theMIMEtype)
|
||||
void XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData)
|
||||
{
|
||||
Backup();
|
||||
|
||||
@ -87,16 +116,21 @@ const TCollection_ExtendedString& XCAFDoc_NoteBinData::Title() const
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
const TCollection_AsciiString& XCAFDoc_NoteBinData::Data() const
|
||||
{
|
||||
return myData;
|
||||
}
|
||||
|
||||
const TCollection_AsciiString& XCAFDoc_NoteBinData::MIMEtype() const
|
||||
{
|
||||
return myMIMEtype;
|
||||
}
|
||||
|
||||
Standard_Integer XCAFDoc_NoteBinData::Size() const
|
||||
{
|
||||
return (!myData.IsNull() ? myData->Length() : 0);
|
||||
}
|
||||
|
||||
const Handle(TColStd_HArray1OfByte)& XCAFDoc_NoteBinData::Data() const
|
||||
{
|
||||
return myData;
|
||||
}
|
||||
|
||||
const Standard_GUID& XCAFDoc_NoteBinData::ID() const
|
||||
{
|
||||
return GetID();
|
||||
@ -114,9 +148,9 @@ void XCAFDoc_NoteBinData::Restore(const Handle(TDF_Attribute)& theAttr)
|
||||
Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr);
|
||||
if (!aMine.IsNull())
|
||||
{
|
||||
myData = aMine->myData;
|
||||
myTitle = aMine->myTitle;
|
||||
myMIMEtype = aMine->myMIMEtype;
|
||||
myData = aMine->myData;
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +161,7 @@ void XCAFDoc_NoteBinData::Paste(const Handle(TDF_Attribute)& theAttrInto,
|
||||
|
||||
Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttrInto);
|
||||
if (!aMine.IsNull())
|
||||
aMine->Set(myTitle, myData, myMIMEtype);
|
||||
aMine->Set(myTitle, myMIMEtype, myData);
|
||||
}
|
||||
|
||||
Standard_OStream& XCAFDoc_NoteBinData::Dump(Standard_OStream& theOS) const
|
||||
@ -136,8 +170,12 @@ Standard_OStream& XCAFDoc_NoteBinData::Dump(Standard_OStream& theOS) const
|
||||
theOS << "\n"
|
||||
<< "Title : " << (!myTitle.IsEmpty() ? myMIMEtype : "<untitled>") << "\n"
|
||||
<< "MIME type : " << (!myMIMEtype.IsEmpty() ? myMIMEtype : "<none>") << "\n"
|
||||
<< "Size : " << myData.Length() << " bytes" << "\n"
|
||||
<< myData
|
||||
<< "Size : " << Size() << " bytes" << "\n"
|
||||
;
|
||||
if (!myData.IsNull())
|
||||
{
|
||||
for (Standard_Integer i = myData->Lower(); i <= myData->Upper(); ++i)
|
||||
theOS << myData->Value(i);
|
||||
}
|
||||
return theOS;
|
||||
}
|
||||
|
@ -17,10 +17,11 @@
|
||||
#define _XCAFDoc_NoteBinData_HeaderFile
|
||||
|
||||
#include <XCAFDoc_Note.hxx>
|
||||
#include <TColStd_HArray1OfByte.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
|
||||
class OSD_File;
|
||||
class TCollection_AsciiString;
|
||||
class TCollection_ExtendedString;
|
||||
|
||||
class XCAFDoc_NoteBinData;
|
||||
DEFINE_STANDARD_HANDLE(XCAFDoc_NoteBinData, XCAFDoc_Note)
|
||||
@ -39,23 +40,33 @@ public:
|
||||
const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype);
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile);
|
||||
|
||||
Standard_EXPORT static Handle(XCAFDoc_NoteBinData) Set(const TDF_Label& theLabel,
|
||||
const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData);
|
||||
|
||||
Standard_EXPORT XCAFDoc_NoteBinData();
|
||||
|
||||
Standard_EXPORT void Set(const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype);
|
||||
Standard_EXPORT Standard_Boolean Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile);
|
||||
|
||||
Standard_EXPORT void Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theData,
|
||||
const TCollection_AsciiString& theMIMEtype);
|
||||
Standard_EXPORT void Set(const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData);
|
||||
|
||||
Standard_EXPORT const TCollection_ExtendedString& Title() const;
|
||||
Standard_EXPORT const TCollection_AsciiString& Data() const;
|
||||
Standard_EXPORT const TCollection_AsciiString& MIMEtype() const;
|
||||
|
||||
Standard_EXPORT Standard_Integer Size() const;
|
||||
|
||||
Standard_EXPORT const Handle(TColStd_HArray1OfByte)& Data() const;
|
||||
|
||||
public:
|
||||
|
||||
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
|
||||
@ -71,9 +82,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
TCollection_ExtendedString myTitle;
|
||||
TCollection_AsciiString myData;
|
||||
TCollection_AsciiString myMIMEtype;
|
||||
TCollection_ExtendedString myTitle;
|
||||
TCollection_AsciiString myMIMEtype;
|
||||
Handle(TColStd_HArray1OfByte) myData;
|
||||
};
|
||||
|
||||
#endif // _XCAFDoc_NoteBinData_HeaderFile
|
||||
|
@ -14,6 +14,7 @@
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TColStd_HArray1OfByte.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TDF_LabelSequence.hxx>
|
||||
@ -88,13 +89,26 @@ Handle(XCAFDoc_Note)
|
||||
XCAFDoc_NotesTool::AddBinData(const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype)
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile)
|
||||
{
|
||||
TDF_Label aNoteLabel;
|
||||
TDF_TagSource aTag;
|
||||
aNoteLabel = aTag.NewChild(Label());
|
||||
return XCAFDoc_NoteBinData::Set(aNoteLabel, theUserName, theTimeStamp, theTitle, theFile, theMIMEtype);
|
||||
return XCAFDoc_NoteBinData::Set(aNoteLabel, theUserName, theTimeStamp, theTitle, theMIMEtype, theFile);
|
||||
}
|
||||
|
||||
Handle(XCAFDoc_Note)
|
||||
XCAFDoc_NotesTool::AddBinData(const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData)
|
||||
{
|
||||
TDF_Label aNoteLabel;
|
||||
TDF_TagSource aTag;
|
||||
aNoteLabel = aTag.NewChild(Label());
|
||||
return XCAFDoc_NoteBinData::Set(aNoteLabel, theUserName, theTimeStamp, theTitle, theMIMEtype, theData);
|
||||
}
|
||||
|
||||
Standard_Boolean XCAFDoc_NotesTool::HasAttachedNotes(const TDF_Label& theLabel) const
|
||||
|
@ -25,6 +25,7 @@ class OSD_File;
|
||||
class Standard_GUID;
|
||||
class TCollection_AsciiString;
|
||||
class TCollection_ExtendedString;
|
||||
class TColStd_HArray1OfByte;
|
||||
class TDF_RelocationTable;
|
||||
class XCAFDoc_Note;
|
||||
|
||||
@ -54,8 +55,14 @@ public:
|
||||
Standard_EXPORT Handle(XCAFDoc_Note) AddBinData(const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
OSD_File& theFile,
|
||||
const TCollection_AsciiString& theMIMEtype);
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
OSD_File& theFile);
|
||||
|
||||
Standard_EXPORT Handle(XCAFDoc_Note) AddBinData(const TCollection_ExtendedString& theUserName,
|
||||
const TCollection_ExtendedString& theTimeStamp,
|
||||
const TCollection_ExtendedString& theTitle,
|
||||
const TCollection_AsciiString& theMIMEtype,
|
||||
const Handle(TColStd_HArray1OfByte)& theData);
|
||||
|
||||
Standard_EXPORT Standard_Boolean HasAttachedNotes(const TDF_Label& theLabel) const;
|
||||
|
||||
|
@ -17,13 +17,15 @@
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
#include <XCAFDoc_NoteBinData.hxx>
|
||||
#include <XmlObjMgt.hxx>
|
||||
#include <XmlMXCAFDoc_NoteBinDataDriver.hxx>
|
||||
#include <XmlObjMgt_Persistent.hxx>
|
||||
#include <LDOM_OSStream.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_NoteBinDataDriver, XmlMXCAFDoc_NoteDriver)
|
||||
IMPLEMENT_DOMSTRING(Title, "title")
|
||||
IMPLEMENT_DOMSTRING(MIMEtype, "mime_type")
|
||||
IMPLEMENT_DOMSTRING(Data, "data")
|
||||
IMPLEMENT_DOMSTRING(Size, "size")
|
||||
|
||||
//=======================================================================
|
||||
//function :
|
||||
@ -57,15 +59,30 @@ Standard_Boolean XmlMXCAFDoc_NoteBinDataDriver::Paste(const XmlObjMgt_Persistent
|
||||
|
||||
XmlObjMgt_DOMString aTitle = anElement.getAttribute(::Title());
|
||||
XmlObjMgt_DOMString aMIMEtype = anElement.getAttribute(::MIMEtype());
|
||||
XmlObjMgt_DOMString aData = anElement.getAttribute(::Data());
|
||||
if (aTitle == NULL || aMIMEtype == NULL || aData == NULL)
|
||||
XmlObjMgt_DOMString aSize = anElement.getAttribute(::Size());
|
||||
if (aTitle == NULL || aMIMEtype == NULL || aSize == NULL)
|
||||
return Standard_False;
|
||||
|
||||
Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget);
|
||||
if (aNote.IsNull())
|
||||
return Standard_False;
|
||||
|
||||
aNote->Set(aTitle.GetString(), aData.GetString(), aMIMEtype.GetString());
|
||||
Standard_Integer nbSize = 0;
|
||||
if (!aSize.GetInteger(nbSize))
|
||||
return Standard_False;
|
||||
|
||||
XmlObjMgt_DOMString aDataStr = XmlObjMgt::GetStringValue(theSource);
|
||||
Standard_SStream anSS(aDataStr.GetString());
|
||||
|
||||
Handle(TColStd_HArray1OfByte) aData = new TColStd_HArray1OfByte(1, nbSize);
|
||||
for (Standard_Integer i = 1; i <= nbSize; ++i)
|
||||
{
|
||||
Standard_Byte aValue;
|
||||
anSS >> aValue;
|
||||
aData->ChangeValue(i) = aValue;
|
||||
}
|
||||
|
||||
aNote->Set(aTitle.GetString(), aMIMEtype.GetString(), aData);
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
@ -84,9 +101,21 @@ void XmlMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource
|
||||
|
||||
XmlObjMgt_DOMString aTitle(TCollection_AsciiString(aNote->Title()).ToCString());
|
||||
XmlObjMgt_DOMString aMIMEtype(aNote->MIMEtype().ToCString());
|
||||
XmlObjMgt_DOMString aData(aNote->Data().ToCString());
|
||||
|
||||
theTarget.Element().setAttribute(::Title(), aTitle);
|
||||
theTarget.Element().setAttribute(::MIMEtype(), aMIMEtype);
|
||||
theTarget.Element().setAttribute(::Data(), aData);
|
||||
theTarget.Element().setAttribute(::Size(), aNote->Size());
|
||||
|
||||
if (aNote->Size() > 0)
|
||||
{
|
||||
const Handle(TColStd_HArray1OfByte)& aData = aNote->Data();
|
||||
LDOM_OSStream anOSS(aNote->Size());
|
||||
for (Standard_Integer i = aData->Lower(); i <= aData->Upper(); ++i)
|
||||
{
|
||||
anOSS << std::hex << aData->Value(i);
|
||||
}
|
||||
Standard_Character* dump = (Standard_Character*)anOSS.str(); // copying! Don't forget to delete it.
|
||||
XmlObjMgt::SetStringValue(theTarget, dump, Standard_True);
|
||||
delete[] dump;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user