#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>
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;
}
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());
}
}
#include <OSD_File.hxx>
#include <Standard_GUID.hxx>
-#include <TCollection_HAsciiString.hxx>
#include <TDF_Label.hxx>
#include <XCAFDoc_NoteBinData.hxx>
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;
{
}
-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();
return myTitle;
}
-const TCollection_AsciiString& XCAFDoc_NoteBinData::Data() const
+const TCollection_AsciiString& XCAFDoc_NoteBinData::MIMEtype() const
{
- return myData;
+ return myMIMEtype;
}
-const TCollection_AsciiString& XCAFDoc_NoteBinData::MIMEtype() const
+Standard_Integer XCAFDoc_NoteBinData::Size() const
{
- return myMIMEtype;
+ return (!myData.IsNull() ? myData->Length() : 0);
+}
+
+const Handle(TColStd_HArray1OfByte)& XCAFDoc_NoteBinData::Data() const
+{
+ return myData;
}
const Standard_GUID& XCAFDoc_NoteBinData::ID() const
Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr);
if (!aMine.IsNull())
{
- myData = aMine->myData;
myTitle = aMine->myTitle;
myMIMEtype = aMine->myMIMEtype;
+ myData = aMine->myData;
}
}
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
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;
}
#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)
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;
protected:
- TCollection_ExtendedString myTitle;
- TCollection_AsciiString myData;
- TCollection_AsciiString myMIMEtype;
+ TCollection_ExtendedString myTitle;
+ TCollection_AsciiString myMIMEtype;
+ Handle(TColStd_HArray1OfByte) myData;
};
#endif // _XCAFDoc_NoteBinData_HeaderFile
// 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>
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
class Standard_GUID;
class TCollection_AsciiString;
class TCollection_ExtendedString;
+class TColStd_HArray1OfByte;
class TDF_RelocationTable;
class XCAFDoc_Note;
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;
#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 :
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;
}
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;
+ }
}