forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectSerialization.h
307 lines (264 loc) · 11.3 KB
/
ProjectSerialization.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
#ifndef PROJECTSERIALIZATION_H
#define PROJECTSERIALIZATION_H
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include "Global/Macros.h"
#include <stdexcept>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_OFF
GCC_DIAG_OFF(unused-parameter)
// /opt/local/include/boost/serialization/smart_cast.hpp:254:25: warning: unused parameter 'u' [-Wunused-parameter]
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/map.hpp>
// /usr/local/include/boost/serialization/shared_ptr.hpp:112:5: warning: unused typedef 'boost_static_assert_typedef_112' [-Wunused-local-typedef]
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/scoped_ptr.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
GCC_DIAG_ON(unused-parameter)
#endif
#include "Global/GitVersion.h"
#include "Global/GlobalDefines.h"
#include "Engine/AppInstance.h"
#include "Engine/KnobSerialization.h"
#include "Engine/MemoryInfo.h" // isApplication32Bits
#include "Engine/Node.h"
#include "Engine/NodeSerialization.h"
#include "Engine/NodeGroupSerialization.h"
#include "Engine/ProjectPrivate.h"
#include "Engine/Project.h"
#include "Engine/TimeLine.h"
#include "Engine/EngineFwd.h"
#define PROJECT_SERIALIZATION_INTRODUCES_NATRON_VERSION 2
#define PROJECT_SERIALIZATION_REMOVES_NODE_COUNTERS 3
#define PROJECT_SERIALIZATION_REMOVES_TIMELINE_BOUNDS 4
#define PROJECT_SERIALIZATION_INTRODUCES_GROUPS 5
#define PROJECT_SERIALIZATION_CHANGE_VERSION_SERIALIZATION 6
#define PROJECT_SERIALIZATION_VERSION PROJECT_SERIALIZATION_CHANGE_VERSION_SERIALIZATION
NATRON_NAMESPACE_ENTER
class ProjectBeingLoadedInfo
{
public:
int vMajor,vMinor,vRev;
std::string gitBranch,gitCommit;
std::string osStr;
int bits;
ProjectBeingLoadedInfo()
: vMajor(-1)
, vMinor(-1)
, vRev(-1)
, gitBranch()
, gitCommit()
, osStr()
, bits(-1)
{
}
};
class ProjectSerialization
{
NodeCollectionSerialization _nodes;
std::list<Format> _additionalFormats;
std::list<KnobSerializationPtr> _projectKnobs;
SequenceTime _timelineCurrent;
qint64 _creationDate;
AppInstanceWPtr _app;
unsigned int _version;
ProjectBeingLoadedInfo _projectLoadedInfo;
public:
ProjectSerialization(const AppInstancePtr& app)
: _timelineCurrent(0)
, _creationDate(0)
, _app(app)
, _version(0)
{
}
~ProjectSerialization()
{
}
unsigned int getVersion() const
{
return _version;
}
const ProjectBeingLoadedInfo& getProjectBeingLoadedInfo() const
{
return _projectLoadedInfo;
}
void initialize(const Project* project);
SequenceTime getCurrentTime() const
{
return _timelineCurrent;
}
const std::list<KnobSerializationPtr > & getProjectKnobsValues() const
{
return _projectKnobs;
}
const std::list<Format> & getAdditionalFormats() const
{
return _additionalFormats;
}
const NodeCollectionSerialization & getNodesSerialization() const
{
return _nodes;
}
qint64 getCreationDate() const
{
return _creationDate;
}
friend class ::boost::serialization::access;
template<class Archive>
void save(Archive & ar,
const unsigned int /*version*/) const
{
/*std::string natronVersion(NATRON_APPLICATION_NAME);
natronVersion.append(" v" NATRON_VERSION_STRING);
natronVersion.append(" from git branch " GIT_BRANCH);
natronVersion.append(" commit " GIT_COMMIT);
natronVersion.append(" for ");
#ifdef __NATRON_WIN32__
natronVersion.append(" Windows ");
#elif defined(__NATRON_OSX__)
natronVersion.append(" MacOSX ");
#elif defined(__NATRON_LINUX__)
natronVersion.append(" Linux ");
#endif
natronVersion.append(isApplication32Bits() ? "32bit" : "64bit");
ar & ::boost::serialization::make_nvp("NatronVersion", natronVersion);*/
int vMajor = NATRON_VERSION_MAJOR;
int vMinor = NATRON_VERSION_MINOR;
int vRev = NATRON_VERSION_REVISION;
ar & ::boost::serialization::make_nvp("VersionMajor", vMajor);
ar & ::boost::serialization::make_nvp("VersionMinor", vMinor);
ar & ::boost::serialization::make_nvp("VersionRev", vRev);
std::string gitBranchStr(GIT_BRANCH);
ar & ::boost::serialization::make_nvp("GitBranch", gitBranchStr);
std::string gitCommitStr(GIT_COMMIT);
ar & ::boost::serialization::make_nvp("GitCommit", gitCommitStr);
std::string osString;
#ifdef __NATRON_WIN32__
osString.append("Windows");
#elif defined(__NATRON_OSX__)
osString.append("MacOSX");
#elif defined(__NATRON_LINUX__)
osString.append("Linux");
#endif
ar & ::boost::serialization::make_nvp("OS", osString);
int bits = isApplication32Bits() ? 32 : 64;
ar & ::boost::serialization::make_nvp("Bits", bits);
ar & ::boost::serialization::make_nvp("NodesCollection", _nodes);
int knobsCount = _projectKnobs.size();
ar & ::boost::serialization::make_nvp("ProjectKnobsCount", knobsCount);
for (std::list<KnobSerializationPtr>::const_iterator it = _projectKnobs.begin();
it != _projectKnobs.end();
++it) {
ar & ::boost::serialization::make_nvp( "item", *(*it) );
}
ar & ::boost::serialization::make_nvp("AdditionalFormats", _additionalFormats);
ar & ::boost::serialization::make_nvp("Timeline_current_time", _timelineCurrent);
ar & ::boost::serialization::make_nvp("CreationDate", _creationDate);
}
template<class Archive>
void load(Archive & ar,
const unsigned int version)
{
_version = version;
if (version >= PROJECT_SERIALIZATION_INTRODUCES_NATRON_VERSION && version < PROJECT_SERIALIZATION_CHANGE_VERSION_SERIALIZATION) {
std::string natronVersion;
ar & ::boost::serialization::make_nvp("NatronVersion", natronVersion);
std::string toFind(NATRON_APPLICATION_NAME " v");
std::size_t foundV = natronVersion.find(toFind);
if (foundV != std::string::npos) {
foundV += toFind.size();
toFind = " from git branch";
std::size_t foundFrom = natronVersion.find(toFind);
if (foundFrom != std::string::npos) {
std::string vStr;
for (std::size_t i = foundV; i < foundFrom; ++i) {
vStr.push_back(natronVersion[i]);
}
QStringList splits = QString::fromUtf8( vStr.c_str() ).split( QLatin1Char('.') );
if (splits.size() == 3) {
_projectLoadedInfo.vMajor = splits[0].toInt();
_projectLoadedInfo.vMinor = splits[1].toInt();
_projectLoadedInfo.vRev = splits[2].toInt();
AppInstancePtr app = _app.lock();
assert(app);
app->setProjectBeingLoadedInfo(_projectLoadedInfo);
if (NATRON_VERSION_ENCODE(_projectLoadedInfo.vMajor, _projectLoadedInfo.vMinor, _projectLoadedInfo.vRev) > NATRON_VERSION_ENCODED) {
throw std::invalid_argument("The given project was produced with a more recent and incompatible version of Natron.");
}
}
}
}
}
if (version >= PROJECT_SERIALIZATION_CHANGE_VERSION_SERIALIZATION) {
ar & ::boost::serialization::make_nvp("VersionMajor", _projectLoadedInfo.vMajor);
ar & ::boost::serialization::make_nvp("VersionMinor", _projectLoadedInfo.vMinor);
ar & ::boost::serialization::make_nvp("VersionRev", _projectLoadedInfo.vRev);
ar & ::boost::serialization::make_nvp("GitBranch", _projectLoadedInfo.gitBranch);
ar & ::boost::serialization::make_nvp("GitCommit", _projectLoadedInfo.gitCommit);
ar & ::boost::serialization::make_nvp("OS", _projectLoadedInfo.osStr);
ar & ::boost::serialization::make_nvp("Bits", _projectLoadedInfo.bits);
AppInstancePtr app = _app.lock();
assert(app);
app->setProjectBeingLoadedInfo(_projectLoadedInfo);
}
if (version < PROJECT_SERIALIZATION_INTRODUCES_GROUPS) {
int nodesCount;
ar & ::boost::serialization::make_nvp("NodesCount", nodesCount);
for (int i = 0; i < nodesCount; ++i) {
NodeSerializationPtr ns = boost::make_shared<NodeSerialization>();
ar & ::boost::serialization::make_nvp("item", *ns);
_nodes.addNodeSerialization(ns);
}
} else {
ar & ::boost::serialization::make_nvp("NodesCollection", _nodes);
}
int knobsCount;
ar & ::boost::serialization::make_nvp("ProjectKnobsCount", knobsCount);
for (int i = 0; i < knobsCount; ++i) {
KnobSerializationPtr ks = boost::make_shared<KnobSerialization>();
ar & ::boost::serialization::make_nvp("item", *ks);
_projectKnobs.push_back(ks);
}
ar & ::boost::serialization::make_nvp("AdditionalFormats", _additionalFormats);
ar & ::boost::serialization::make_nvp("Timeline_current_time", _timelineCurrent);
if (version < PROJECT_SERIALIZATION_REMOVES_TIMELINE_BOUNDS) {
SequenceTime left, right;
ar & ::boost::serialization::make_nvp("Timeline_left_bound", left);
ar & ::boost::serialization::make_nvp("Timeline_right_bound", right);
}
if (version < PROJECT_SERIALIZATION_REMOVES_NODE_COUNTERS) {
std::map<std::string, int> _nodeCounters;
ar & ::boost::serialization::make_nvp("NodeCounters", _nodeCounters);
}
ar & ::boost::serialization::make_nvp("CreationDate", _creationDate);
} // load
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
NATRON_NAMESPACE_EXIT
BOOST_CLASS_VERSION(NATRON_NAMESPACE::ProjectSerialization, PROJECT_SERIALIZATION_VERSION)
#endif // PROJECTSERIALIZATION_H