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 <TDF_Attribute.hxx>
20 #include <TColStd_HArray1OfByte.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TCollection_ExtendedString.hxx>
23 #include <BinMXCAFDoc_NoteBinDataDriver.hxx>
24 #include <XCAFDoc_NoteBinData.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver)
28 //=======================================================================
31 //=======================================================================
32 BinMXCAFDoc_NoteBinDataDriver::BinMXCAFDoc_NoteBinDataDriver(const Handle(Message_Messenger)& theMsgDriver)
33 : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name())
37 //=======================================================================
40 //=======================================================================
41 Handle(TDF_Attribute) BinMXCAFDoc_NoteBinDataDriver::NewEmpty() const
43 return new XCAFDoc_NoteBinData();
46 //=======================================================================
49 //=======================================================================
50 Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent& theSource,
51 const Handle(TDF_Attribute)& theTarget,
52 BinObjMgt_RRelocationTable& theRelocTable) const
54 if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable))
55 return Standard_False;
57 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget);
59 return Standard_False;
61 TCollection_ExtendedString aTitle;
62 TCollection_AsciiString aMIMEtype;
63 Standard_Integer nbSize;
64 if (!(theSource >> aTitle >> aMIMEtype >> nbSize))
65 return Standard_False;
67 Handle(TColStd_HArray1OfByte) aData;
70 aData.reset(new TColStd_HArray1OfByte(1, nbSize));
71 theSource.GetByteArray(&aData->ChangeFirst(), nbSize);
74 aNote->Set(aTitle, aMIMEtype, aData);
79 //=======================================================================
82 //=======================================================================
83 void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
84 BinObjMgt_Persistent& theTarget,
85 BinObjMgt_SRelocationTable& theRelocTable) const
87 BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable);
89 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource);
92 theTarget << aNote->Title() << aNote->MIMEtype() << aNote->Size();
93 if (aNote->Size() > 0)
94 theTarget.PutByteArray(&aNote->Data()->ChangeFirst(), aNote->Size());