0029621: Application Framework - Impossible to attach existing tessellation to XCAFDo...
[occt.git] / src / XCAFDoc / XCAFDoc_NoteBinData.cxx
CommitLineData
8c7fab9b 1// Copyright (c) 2017-2018 OPEN CASCADE SAS
024d6f77 2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <OSD_File.hxx>
15#include <Standard_GUID.hxx>
16#include <TDF_Label.hxx>
17#include <XCAFDoc_NoteBinData.hxx>
18
19IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_NoteBinData, XCAFDoc_Note)
20
8c7fab9b 21// =======================================================================
22// function : GetID
23// purpose :
24// =======================================================================
25const Standard_GUID&
024d6f77 26XCAFDoc_NoteBinData::GetID()
27{
28 static Standard_GUID s_ID("E9055501-F0FC-4864-BE4B-284FDA7DDEAC");
29 return s_ID;
30}
31
8c7fab9b 32// =======================================================================
33// function : Get
34// purpose :
35// =======================================================================
024d6f77 36Handle(XCAFDoc_NoteBinData)
37XCAFDoc_NoteBinData::Get(const TDF_Label& theLabel)
38{
39 Handle(XCAFDoc_NoteBinData) aThis;
40 theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aThis);
41 return aThis;
42}
43
8c7fab9b 44// =======================================================================
45// function : Set
46// purpose :
47// =======================================================================
48Handle(XCAFDoc_NoteBinData)
024d6f77 49XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel,
50 const TCollection_ExtendedString& theUserName,
51 const TCollection_ExtendedString& theTimeStamp,
52 const TCollection_ExtendedString& theTitle,
53 const TCollection_AsciiString& theMIMEtype,
54 OSD_File& theFile)
55{
56 Handle(XCAFDoc_NoteBinData) aNoteBinData;
57 if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNoteBinData))
58 {
59 aNoteBinData = new XCAFDoc_NoteBinData();
60 aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp);
61 if (aNoteBinData->Set(theTitle, theMIMEtype, theFile))
62 theLabel.AddAttribute(aNoteBinData);
63 else
64 aNoteBinData.Nullify();
65 }
66 return aNoteBinData;
67}
68
8c7fab9b 69// =======================================================================
70// function : Set
71// purpose :
72// =======================================================================
73Handle(XCAFDoc_NoteBinData)
024d6f77 74XCAFDoc_NoteBinData::Set(const TDF_Label& theLabel,
75 const TCollection_ExtendedString& theUserName,
76 const TCollection_ExtendedString& theTimeStamp,
77 const TCollection_ExtendedString& theTitle,
78 const TCollection_AsciiString& theMIMEtype,
79 const Handle(TColStd_HArray1OfByte)& theData)
80{
81 Handle(XCAFDoc_NoteBinData) aNoteBinData;
82 if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_NoteBinData::GetID(), aNoteBinData))
83 {
84 aNoteBinData = new XCAFDoc_NoteBinData();
85 aNoteBinData->XCAFDoc_Note::Set(theUserName, theTimeStamp);
86 aNoteBinData->Set(theTitle, theMIMEtype, theData);
87 theLabel.AddAttribute(aNoteBinData);
88 }
89 return aNoteBinData;
90}
91
8c7fab9b 92// =======================================================================
93// function : XCAFDoc_NoteBinData
94// purpose :
95// =======================================================================
024d6f77 96XCAFDoc_NoteBinData::XCAFDoc_NoteBinData()
97{
98}
99
8c7fab9b 100// =======================================================================
101// function : Set
102// purpose :
103// =======================================================================
104Standard_Boolean
024d6f77 105XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
106 const TCollection_AsciiString& theMIMEtype,
107 OSD_File& theFile)
108{
109 if (!theFile.IsOpen() || !theFile.IsReadable())
110 return Standard_False;
111
112 Backup();
113
114 if (theFile.Size() > (Standard_Size)IntegerLast())
115 return Standard_False;
116
117 myData.reset(new TColStd_HArray1OfByte(1, (Standard_Integer)theFile.Size()));
118 Standard_Integer nbReadBytes = 0;
119 theFile.Read((Standard_Address)&myData->First(), myData->Length(), nbReadBytes);
120 if (nbReadBytes < myData->Length())
121 return Standard_False;
122
123 myTitle = theTitle;
124 myMIMEtype = theMIMEtype;
125
126 return Standard_True;
127}
128
8c7fab9b 129// =======================================================================
130// function : Set
131// purpose :
132// =======================================================================
133void
024d6f77 134XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
135 const TCollection_AsciiString& theMIMEtype,
136 const Handle(TColStd_HArray1OfByte)& theData)
137{
138 Backup();
139
140 myData = theData;
141 myTitle = theTitle;
142 myMIMEtype = theMIMEtype;
143}
144
8c7fab9b 145// =======================================================================
146// function : ID
147// purpose :
148// =======================================================================
149const
024d6f77 150Standard_GUID& XCAFDoc_NoteBinData::ID() const
151{
152 return GetID();
153}
154
8c7fab9b 155// =======================================================================
156// function : NewEmpty
157// purpose :
158// =======================================================================
159Handle(TDF_Attribute)
024d6f77 160XCAFDoc_NoteBinData::NewEmpty() const
161{
162 return new XCAFDoc_NoteBinData();
163}
164
8c7fab9b 165// =======================================================================
166// function : Restore
167// purpose :
168// =======================================================================
169void
024d6f77 170XCAFDoc_NoteBinData::Restore(const Handle(TDF_Attribute)& theAttr)
171{
172 XCAFDoc_Note::Restore(theAttr);
173
174 Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttr);
175 if (!aMine.IsNull())
176 {
177 myTitle = aMine->myTitle;
178 myMIMEtype = aMine->myMIMEtype;
179 myData = aMine->myData;
180 }
181}
182
8c7fab9b 183// =======================================================================
184// function : Paste
185// purpose :
186// =======================================================================
187void
024d6f77 188XCAFDoc_NoteBinData::Paste(const Handle(TDF_Attribute)& theAttrInto,
189 const Handle(TDF_RelocationTable)& theRT) const
190{
191 XCAFDoc_Note::Paste(theAttrInto, theRT);
192
193 Handle(XCAFDoc_NoteBinData) aMine = Handle(XCAFDoc_NoteBinData)::DownCast(theAttrInto);
194 if (!aMine.IsNull())
195 aMine->Set(myTitle, myMIMEtype, myData);
196}
197
8c7fab9b 198// =======================================================================
199// function : Dump
200// purpose :
201// =======================================================================
202Standard_OStream&
024d6f77 203XCAFDoc_NoteBinData::Dump(Standard_OStream& theOS) const
204{
205 XCAFDoc_Note::Dump(theOS);
206 theOS << "\n"
207 << "Title : " << (!myTitle.IsEmpty() ? myMIMEtype : "<untitled>") << "\n"
208 << "MIME type : " << (!myMIMEtype.IsEmpty() ? myMIMEtype : "<none>") << "\n"
209 << "Size : " << Size() << " bytes" << "\n"
210 ;
211 if (!myData.IsNull())
212 {
213 for (Standard_Integer i = myData->Lower(); i <= myData->Upper(); ++i)
214 theOS << myData->Value(i);
215 }
216 return theOS;
217}