1 // Created on: 2017-02-13
2 // Created by: Eugeny NIKONOV
3 // Copyright (c) 2005-2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BinObjMgt_Persistent.hxx>
17 #include <Message_Messenger.hxx>
18 #include <Standard_Type.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TCollection_ExtendedString.hxx>
21 #include <BinMXCAFDoc_NoteBinDataDriver.hxx>
22 #include <XCAFDoc_NoteBinData.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver)
26 //=======================================================================
29 //=======================================================================
30 BinMXCAFDoc_NoteBinDataDriver::BinMXCAFDoc_NoteBinDataDriver(const Handle(Message_Messenger)& theMsgDriver)
31 : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name())
35 //=======================================================================
38 //=======================================================================
39 Handle(TDF_Attribute) BinMXCAFDoc_NoteBinDataDriver::NewEmpty() const
41 return new XCAFDoc_NoteBinData();
44 //=======================================================================
47 //=======================================================================
48 Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent& theSource,
49 const Handle(TDF_Attribute)& theTarget,
50 BinObjMgt_RRelocationTable& theRelocTable) const
52 if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable))
53 return Standard_False;
55 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget);
57 return Standard_False;
59 TCollection_ExtendedString aTitle;
60 TCollection_AsciiString aMIMEtype;
61 Standard_Integer nbSize;
62 if (!(theSource >> aTitle >> aMIMEtype >> nbSize))
63 return Standard_False;
65 Handle(TColStd_HArray1OfByte) aData;
68 aData.reset(new TColStd_HArray1OfByte(1, nbSize));
69 theSource.GetByteArray(&aData->ChangeFirst(), nbSize);
72 aNote->Set(aTitle, aMIMEtype, aData);
77 //=======================================================================
80 //=======================================================================
81 void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
82 BinObjMgt_Persistent& theTarget,
83 BinObjMgt_SRelocationTable& theRelocTable) const
85 BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable);
87 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource);
90 theTarget << aNote->Title() << aNote->MIMEtype() << aNote->Size();
91 if (aNote->Size() > 0)
92 theTarget.PutByteArray(&aNote->Data()->ChangeFirst(), aNote->Size());