forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppInstance.h
504 lines (365 loc) · 15.4 KB
/
AppInstance.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/* ***** 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 APPINSTANCE_H
#define APPINSTANCE_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 <vector>
#include <list>
#include <string>
#include <utility>
#include <climits> // for INT_MAX, INT_MIN
#include <cstddef> // for NULL
#include <QtCore/QtGlobal> // for Q_UNUSED
#include <QtCore/QObject> // for Q_OBJECT, Q_SIGNALS, Q_SLOTS
#include <QtCore/QMutex>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/scoped_ptr.hpp>
#endif
#include "Global/GlobalDefines.h"
#include "Engine/RectD.h"
#include "Engine/TimeLineKeyFrames.h"
#include "Engine/EngineFwd.h"
NATRON_NAMESPACE_ENTER
struct AppInstancePrivate;
class FlagSetter
{
bool* p;
QMutex* lock;
public:
FlagSetter(bool initialValue,
bool* p);
FlagSetter(bool initialValue,
bool* p,
QMutex* mutex);
~FlagSetter();
};
class FlagIncrementer
{
int* p;
QMutex* lock;
public:
FlagIncrementer(int* p);
FlagIncrementer(int* p,
QMutex* mutex);
~FlagIncrementer();
};
class AppInstance
: public QObject
, public boost::noncopyable
, public boost::enable_shared_from_this<AppInstance>
, public TimeLineKeyFrames
{
GCC_DIAG_SUGGEST_OVERRIDE_OFF
Q_OBJECT
GCC_DIAG_SUGGEST_OVERRIDE_ON
public:
// TODO: enable_shared_from_this
// constructors should be privatized in any class that derives from boost::enable_shared_from_this<>
AppInstance(int appID);
public:
virtual ~AppInstance();
virtual void aboutToQuit();
virtual bool isBackground() const { return true; }
struct RenderWork
{
OutputEffectInstance* writer;
int firstFrame;
int lastFrame;
int frameStep;
bool useRenderStats;
bool isRestart;
RenderWork()
: writer(0)
, firstFrame(0)
, lastFrame(0)
, frameStep(0)
, useRenderStats(false)
, isRestart(false)
{
}
RenderWork(OutputEffectInstance* writer,
int firstFrame,
int lastFrame,
int frameStep,
bool useRenderStats)
: writer(writer)
, firstFrame(firstFrame)
, lastFrame(lastFrame)
, frameStep(frameStep)
, useRenderStats(useRenderStats)
, isRestart(false)
{
}
};
void load(const CLArgs& cl, bool makeEmptyInstance);
protected:
virtual void loadInternal(const CLArgs& cl, bool makeEmptyInstance);
void executeCommandLinePythonCommands(const CLArgs& args);
public:
int getAppID() const;
void exportDocs(const QString path);
/** @brief Create a new node in the node graph.
**/
NodePtr createNode(CreateNodeArgs & args);
NodePtr createReader(const std::string& filename,
CreateNodeArgs& args);
NodePtr createWriter(const std::string& filename,
CreateNodeArgs& args,
int firstFrame = INT_MIN, int lastFrame = INT_MAX);
NodePtr getNodeByFullySpecifiedName(const std::string & name) const;
ProjectPtr getProject() const;
TimeLinePtr getTimeLine() const;
/*true if the user is NOT scrubbing the timeline*/
virtual bool shouldRefreshPreview() const
{
return false;
}
virtual void connectViewersToViewerCache()
{
}
virtual void disconnectViewersFromViewerCache()
{
}
virtual void errorDialog(const std::string & title, const std::string & message, bool useHtml) const;
virtual void errorDialog(const std::string & title, const std::string & message, bool* stopAsking, bool useHtml) const;
virtual void warningDialog(const std::string & title, const std::string & message, bool useHtml) const;
virtual void warningDialog(const std::string & title, const std::string & message, bool* stopAsking, bool useHtml) const;
virtual void informationDialog(const std::string & title, const std::string & message, bool useHtml) const;
virtual void informationDialog(const std::string & title, const std::string & message, bool* stopAsking, bool useHtml) const;
virtual StandardButtonEnum questionDialog(const std::string & title,
const std::string & message,
bool useHtml,
StandardButtons buttons =
StandardButtons(eStandardButtonYes | eStandardButtonNo),
StandardButtonEnum defaultButton = eStandardButtonNoButton) const WARN_UNUSED_RETURN;
/**
* @brief Asks a question to the user and returns the reply.
* @param stopAsking Set to true if the user do not want Natron to ask the question again.
**/
virtual StandardButtonEnum questionDialog(const std::string & /*title*/,
const std::string & /*message*/,
bool /*useHtml*/,
StandardButtons /*buttons*/,
StandardButtonEnum /*defaultButton*/,
bool* /*stopAsking*/)
{
return eStandardButtonYes;
}
virtual void loadProjectGui(bool /*isAutosave*/, boost::archive::xml_iarchive & /*archive*/) const
{
}
virtual void saveProjectGui(boost::archive::xml_oarchive & /*archive*/)
{
}
virtual void setupViewersForViews(const std::vector<std::string>& /*viewNames*/)
{
}
virtual void notifyRenderStarted(const QString & /*sequenceName*/,
int /*firstFrame*/,
int /*lastFrame*/,
int /*frameStep*/,
bool /*canPause*/,
OutputEffectInstance* /*writer*/,
const ProcessHandlerPtr & /*process*/)
{
}
virtual void notifyRenderRestarted( OutputEffectInstance* /*writer*/,
const ProcessHandlerPtr & /*process*/)
{
}
virtual bool isShowingDialog() const
{
return false;
}
virtual bool isGuiFrozen() const { return false; }
virtual void progressStart(const NodePtr& node,
const std::string &message,
const std::string &messageid,
bool canCancel = true)
{
Q_UNUSED(node);
Q_UNUSED(message);
Q_UNUSED(messageid);
Q_UNUSED(canCancel);
}
virtual void progressEnd(const NodePtr& /*node*/)
{
}
virtual bool progressUpdate(const NodePtr& /*node*/,
double /*t*/)
{
return true;
}
/**
* @brief Checks for a new version of Natron
**/
void checkForNewVersion() const;
virtual void onMaxPanelsOpenedChanged(int /*maxPanels*/)
{
}
virtual void onRenderQueuingChanged(bool /*queueingEnabled*/)
{
}
ViewerColorSpaceEnum getDefaultColorSpaceForBitDepth(ImageBitDepthEnum bitdepth) const;
double getProjectFrameRate() const;
virtual std::string openImageFileDialog() { return std::string(); }
virtual std::string saveImageFileDialog() { return std::string(); }
void onOCIOConfigPathChanged(const std::string& path);
/**
* @brief Given writer names, start rendering the given RenderRequest. If empty all Writers in the project
* will be rendered using the frame ranges.
**/
void startWritersRenderingFromNames(bool enableRenderStats,
bool doBlockingRender,
const std::list<std::string>& writers,
const std::list<std::pair<int, std::pair<int, int> > >& frameRanges);
void startWritersRendering(bool doBlockingRender, const std::list<RenderWork>& writers);
public:
void addInvalidExpressionKnob(const KnobIPtr& knob);
void removeInvalidExpressionKnob(const KnobI* knob);
void recheckInvalidExpressions();
virtual void clearViewersLastRenderedTexture() {}
virtual void toggleAutoHideGraphInputs() {}
/**
* @brief In Natron v1.0.0 plug-in IDs were lower case only due to a bug in OpenFX host support.
* To be able to load projects created in Natron v1.0.0 we must identity that the project was created in this version
* and try to load plug-ins with their lower case ID instead.
**/
void setProjectWasCreatedWithLowerCaseIDs(bool b);
bool wasProjectCreatedWithLowerCaseIDs() const;
bool isCreatingPythonGroup() const;
bool isCreatingNodeTree() const;
void setIsCreatingNodeTree(bool b);
virtual void appendToScriptEditor(const std::string& str);
virtual void printAutoDeclaredVariable(const std::string& str);
void getFrameRange(double* first, double* last) const;
virtual void setLastViewerUsingTimeline(const NodePtr& /*node*/) {}
virtual ViewerInstance* getLastViewerUsingTimeline() const { return 0; }
bool loadPythonScript(const QFileInfo& file);
virtual void queueRedrawForAllViewers() {}
virtual void renderAllViewers(bool /* canAbort*/) {}
virtual void abortAllViewers() {}
virtual void refreshAllPreviews() {}
virtual void declareCurrentAppVariable_Python();
void execOnProjectCreatedCallback();
virtual void createLoadProjectSplashScreen(const QString& /*projectFile*/) {}
virtual void updateProjectLoadStatus(const QString& /*str*/) {}
virtual void closeLoadPRojectSplashScreen() {}
std::string getAppIDString() const;
const std::list<NodePtr>& getNodesBeingCreated() const;
virtual bool isDraftRenderEnabled() const { return false; }
virtual void setDraftRenderEnabled(bool /*b*/) {}
virtual void setUserIsPainting(const NodePtr& /*rotopaintNode*/,
const RotoStrokeItemPtr& /*stroke*/,
bool /*isPainting*/) {}
virtual void getActiveRotoDrawingStroke(NodePtr* /*node*/,
RotoStrokeItemPtr* /*stroke*/,
bool* /*isPainting*/) const { }
virtual bool isRenderStatsActionChecked() const { return false; }
bool saveTemp(const std::string& filename);
virtual bool save(const std::string& filename);
virtual bool saveAs(const std::string& filename);
virtual AppInstancePtr loadProject(const std::string& filename);
///Close the current project but keep the window
virtual bool resetProject();
///Reset + close window, quit if last window
virtual bool closeProject();
///Opens a new window
virtual AppInstancePtr newProject();
virtual void* getOfxHostOSHandle() const { return NULL; }
virtual void updateLastPaintStrokeData(int /*newAge*/,
const std::list<std::pair<Point, double> >& /*points*/,
const RectD& /*lastPointsBbox*/,
int /*strokeIndex*/) {}
virtual void getLastPaintStrokePoints(std::list<std::list<std::pair<Point, double> > >* /*strokes*/,
int* /*strokeIndex*/) const {}
virtual int getStrokeLastIndex() const { return -1; }
virtual void getStrokeAndMultiStrokeIndex(RotoStrokeItemPtr* /*stroke*/,
int* /*strokeIndex*/) const {}
virtual void getRenderStrokeData(RectD* /*lastStrokeMovementBbox*/,
std::list<std::pair<Point, double> >* /*lastStrokeMovementPoints*/,
double */*distNextIn*/,
ImagePtr* /*strokeImage*/) const {}
virtual void updateStrokeImage(const ImagePtr& /*image*/,
double /*distNextOut*/,
bool /*setDistNextOut*/) {}
virtual RectD getLastPaintStrokeBbox() const { return RectD(); }
virtual RectD getPaintStrokeWholeBbox() const { return RectD(); }
void removeRenderFromQueue(OutputEffectInstance* writer);
virtual void reloadScriptEditorFonts() {}
const ProjectBeingLoadedInfo& getProjectBeingLoadedInfo() const;
void setProjectBeingLoadedInfo(const ProjectBeingLoadedInfo& info);
public Q_SLOTS:
void quit();
void quitNow();
virtual void redrawAllViewers() {}
void triggerAutoSave();
void clearOpenFXPluginsCaches();
void clearAllLastRenderedImages();
void newVersionCheckDownloaded();
void newVersionCheckError();
void onBackgroundRenderProcessFinished();
void onQueuedRenderFinished(int retCode);
Q_SIGNALS:
void pluginsPopulated();
protected:
virtual void onGroupCreationFinished(const NodePtr& node, const NodeSerializationPtr& serialization, bool autoConnect);
virtual void createNodeGui(const NodePtr& /*node*/,
const NodePtr& /*parentmultiinstance*/,
const CreateNodeArgs& /*args*/)
{
}
private:
void startNextQueuedRender(OutputEffectInstance* finishedWriter);
void getWritersWorkForCL(const CLArgs& cl, std::list<AppInstance::RenderWork>& requests);
NodePtr createNodeInternal(CreateNodeArgs& args);
void setGroupLabelIDAndVersion(const NodePtr& node,
const QString& pythonModulePath,
const QString &pythonModule);
NodePtr createNodeFromPythonModule(Plugin* plugin,
const CreateNodeArgs& args);
boost::scoped_ptr<AppInstancePrivate> _imp;
};
class CreatingNodeTreeFlag_RAII
{
AppInstanceWPtr _app;
public:
CreatingNodeTreeFlag_RAII(const AppInstancePtr& app)
: _app(app)
{
app->setIsCreatingNodeTree(true);
}
~CreatingNodeTreeFlag_RAII()
{
AppInstancePtr a = _app.lock();
if (a) {
a->setIsCreatingNodeTree(false);
}
}
};
NATRON_NAMESPACE_EXIT
#endif // APPINSTANCE_H