0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / BinMXCAFDoc / BinMXCAFDoc_NoteBinDataDriver.cxx
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>
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>
25
26 IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_NoteBinDataDriver, BinMXCAFDoc_NoteDriver)
27
28 //=======================================================================
29 //function :
30 //purpose  : 
31 //=======================================================================
32 BinMXCAFDoc_NoteBinDataDriver::BinMXCAFDoc_NoteBinDataDriver(const Handle(Message_Messenger)& theMsgDriver)
33   : BinMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name())
34 {
35 }
36
37 //=======================================================================
38 //function :
39 //purpose  : 
40 //=======================================================================
41 Handle(TDF_Attribute) BinMXCAFDoc_NoteBinDataDriver::NewEmpty() const
42 {
43   return new XCAFDoc_NoteBinData();
44 }
45
46 //=======================================================================
47 //function :
48 //purpose  : 
49 //=======================================================================
50 Standard_Boolean BinMXCAFDoc_NoteBinDataDriver::Paste(const BinObjMgt_Persistent&  theSource,
51                                                       const Handle(TDF_Attribute)& theTarget,
52                                                       BinObjMgt_RRelocationTable&  theRelocTable) const
53 {
54   if (!BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable))
55     return Standard_False;
56
57   Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget);
58   if (aNote.IsNull())
59     return Standard_False;
60
61   TCollection_ExtendedString aTitle;
62   TCollection_AsciiString aMIMEtype;
63   Standard_Integer nbSize;
64   if (!(theSource >> aTitle >> aMIMEtype >> nbSize))
65     return Standard_False;
66
67   Handle(TColStd_HArray1OfByte) aData;
68   if (nbSize > 0)
69   {
70     aData.reset(new TColStd_HArray1OfByte(1, nbSize));
71     theSource.GetByteArray(&aData->ChangeFirst(), nbSize);
72   }
73
74   aNote->Set(aTitle, aMIMEtype, aData);
75
76   return Standard_True;
77 }
78
79 //=======================================================================
80 //function :
81 //purpose  : 
82 //=======================================================================
83 void BinMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
84                                                        BinObjMgt_Persistent&        theTarget,
85                                                        BinObjMgt_SRelocationTable&  theRelocTable) const
86 {
87   BinMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable);
88
89   Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource);
90   if (!aNote.IsNull())
91   {
92     theTarget << aNote->Title() << aNote->MIMEtype() << aNote->Size();
93     if (aNote->Size() > 0)
94       theTarget.PutByteArray(&aNote->Data()->ChangeFirst(), aNote->Size());
95   }
96 }