024d6f77 |
1 | // Created on: 2017-02-13 |
2 | // Created by: Eugeny NIKONOV |
3 | // Copyright (c) 2005-2017 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <BinObjMgt_Persistent.hxx> |
83ae3591 |
17 | #include <Message_Messenger.hxx> |
024d6f77 |
18 | #include <Standard_Type.hxx> |
024d6f77 |
19 | #include <TCollection_AsciiString.hxx> |
20 | #include <TCollection_ExtendedString.hxx> |
21 | #include <BinMXCAFDoc_NoteBinDataDriver.hxx> |
22 | #include <XCAFDoc_NoteBinData.hxx> |
23 | |
24 | IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver) |
25 | |
26 | //======================================================================= |
27 | //function : |
28 | //purpose : |
29 | //======================================================================= |
83ae3591 |
30 | BinMXCAFDoc_NoteBinDataDriver::BinMXCAFDoc_NoteBinDataDriver(const Handle(Message_Messenger)& theMsgDriver) |
024d6f77 |
31 | : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name()) |
32 | { |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : |
37 | //purpose : |
38 | //======================================================================= |
39 | Handle(TDF_Attribute) BinMXCAFDoc_NoteBinDataDriver::NewEmpty() const |
40 | { |
41 | return new XCAFDoc_NoteBinData(); |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : |
46 | //purpose : |
47 | //======================================================================= |
48 | Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent& theSource, |
49 | const Handle(TDF_Attribute)& theTarget, |
50 | BinObjMgt_RRelocationTable& theRelocTable) const |
51 | { |
52 | if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable)) |
53 | return Standard_False; |
54 | |
55 | Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget); |
56 | if (aNote.IsNull()) |
57 | return Standard_False; |
58 | |
59 | TCollection_ExtendedString aTitle; |
60 | TCollection_AsciiString aMIMEtype; |
61 | Standard_Integer nbSize; |
62 | if (!(theSource >> aTitle >> aMIMEtype >> nbSize)) |
63 | return Standard_False; |
64 | |
65 | Handle(TColStd_HArray1OfByte) aData; |
66 | if (nbSize > 0) |
67 | { |
68 | aData.reset(new TColStd_HArray1OfByte(1, nbSize)); |
69 | theSource.GetByteArray(&aData->ChangeFirst(), nbSize); |
70 | } |
71 | |
72 | aNote->Set(aTitle, aMIMEtype, aData); |
73 | |
74 | return Standard_True; |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : |
79 | //purpose : |
80 | //======================================================================= |
81 | void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource, |
83ae3591 |
82 | BinObjMgt_Persistent& theTarget, |
83 | BinObjMgt_SRelocationTable& theRelocTable) const |
024d6f77 |
84 | { |
85 | BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable); |
86 | |
87 | Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource); |
88 | if (!aNote.IsNull()) |
89 | { |
90 | theTarget << aNote->Title() << aNote->MIMEtype() << aNote->Size(); |
91 | if (aNote->Size() > 0) |
92 | theTarget.PutByteArray(&aNote->Data()->ChangeFirst(), aNote->Size()); |
93 | } |
94 | } |