-
Notifications
You must be signed in to change notification settings - Fork 1
/
score_addon_tutorial.cpp
165 lines (151 loc) · 5.6 KB
/
score_addon_tutorial.cpp
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
#include "score_addon_tutorial.hpp"
#include <score/plugins/FactorySetup.hpp>
#include <Tutorial/ApplicationPlugin/TutorialApplicationPlugin.hpp>
#include <Tutorial/DocumentPlugin/TutorialDocumentPlugin.hpp>
#include <Tutorial/Panel/TutorialPanelDelegate.hpp>
#include <Tutorial/PolymorphicEntity/Implementation/ConcretePolymorphicEntity.hpp>
#include <Tutorial/PolymorphicEntity/PolymorphicEntityFactory.hpp>
#include <Tutorial/Process/Executor/TutorialProcessExecutor.hpp>
#include <Tutorial/Process/Inspector/TutorialProcessInspector.hpp>
#include <Tutorial/Process/Layer/TutorialProcessLayerFactory.hpp>
#include <Tutorial/Process/LocalTree/TutorialProcessLocalTree.hpp>
#include <Tutorial/Process/TutorialProcessFactory.hpp>
#include <score/model/EntitySerialization.hpp>
#include <score_addon_tutorial_commands_files.hpp>
score_addon_tutorial::score_addon_tutorial() {}
score_addon_tutorial::~score_addon_tutorial() {}
/**
* @brief score_addon_tutorial::required
* @return Features that this plug-in requires.
*
* If a feature is listed here, i-score will load the
* plug-in providing this feature (through \ref
* score::Plugin_QtInterface::offered) before this one.
*/
auto score_addon_tutorial::required() const -> std::vector<score::PluginKey>
{
return {};
}
/**
* @brief score_addon_tutorial::updateSaveFile
* This function is called if someone tries to load
* a save file that was created with a previous version
* of this plug-in.
* This allows to update the JSON data in order to load
* it in the current version.
*/
void score_addon_tutorial::updateSaveFile(
rapidjson::Value& obj,
score::Version obj_version,
score::Version current_version)
{
}
/**
* @brief score_addon_tutorial::factoryFamilies
* This function allows the plug-in to provide new factory types.
* All plug-ins will be scanned for factories of the provided type.
*
* For instance, a new interface to display some elements in a toolbar.
*
* Elements registered here can then be used through an \ref
* score::ApplicationContext instance :
*
* \code
* auto& ctx = score::AppContext();
* auto& my_factories =
* ctx.interfaces<Tutorial::PolymorphicElementFactoryList>(); \endcode
*/
std::vector<std::unique_ptr<score::InterfaceListBase>>
score_addon_tutorial::factoryFamilies()
{
return make_ptr_vector<
score::InterfaceListBase,
Tutorial::PolymorphicElementFactoryList>();
}
/**
* @brief score_addon_tutorial::factories
*
* This function allows the plug-in to provide implementations for the
* factory types provided earlier.
*
* For instance, factories for the elements that will go in the toolbar.
*
* An helper function is provided : \ref instantiate_factories .
*
* The factories registered here are then accessible like this :
*
* \code
* // Get a context or use an existing one
* auto& ctx = score::AppContext();
*
* // Get the list of factories that we are looking for
* auto& my_factories = ctx.interfaces<Process::ProcessList>();
*
* // Get the key for the actual factory we want;
* // Instead of doing this, it could already be saved somewhere for instance.
* auto process_key = Metadata<ConcreteKey_k, Tutorial::ProcessFactory>::get();
*
* // Get the actual factory
* auto my_process_factory = my_factories.get(process_key);
* \endcode
*
* However, it should rarely be necessary to access a particular factory.
* The general case should be getting a factory according to an user input.
*/
std::vector<std::unique_ptr<score::InterfaceBase>>
score_addon_tutorial::factories(
const score::ApplicationContext& ctx,
const score::InterfaceKey& key) const
{
return instantiate_factories<
score::ApplicationContext,
FW<Process::ProcessModelFactory, // An abstract factory
Tutorial::ProcessFactory // followed by all the matching concrete
// factories
>,
FW<Process::LayerFactory, Tutorial::LayerFactory>,
FW<Process::InspectorWidgetDelegateFactory, Tutorial::InspectorFactory>,
FW<Execution::ProcessComponentFactory,
Tutorial::ProcessExecutorComponentFactory>,
FW<LocalTree::ProcessComponentFactory,
Tutorial::LocalTreeProcessComponentFactory>,
FW<score::DocumentPluginFactory, Tutorial::DocumentPluginFactory>,
FW<score::PanelDelegateFactory,
Tutorial::PanelDelegateFactory>,
FW<
// This abstract factory was defined inside the tutorial plug-in :
Tutorial::PolymorphicElementFactory,
Tutorial::ConcretePolymorphicElementFactory>>(ctx, key);
}
/**
* @brief score_addon_tutorial::make_applicationPlugin
*
* This function allows to instantiate an application-wide object.
* These objects are instantiated before any factory.
*/
score::GUIApplicationPlugin* score_addon_tutorial::make_guiApplicationPlugin(
const score::GUIApplicationContext& app)
{
return new Tutorial::ApplicationPlugin{app};
}
/**
* @brief score_addon_tutorial::make_commands
* This function provides the list of commands available with this
* plug-in.
*/
std::pair<const CommandGroupKey, CommandGeneratorMap>
score_addon_tutorial::make_commands()
{
using namespace Tutorial;
std::pair<const CommandGroupKey, CommandGeneratorMap> cmds{
CommandFactoryName(), CommandGeneratorMap{}};
// CMake generates the "addon_commands.hpp" and "addon_commands_file.hpp"
// by scanning the source files for \ref SCORE_COMMAND_DECL or \ref
// SCORE_COMMAND_DECL_T.
ossia::for_each_type<
#include <score_addon_tutorial_commands.hpp>
>(score::commands::FactoryInserter{cmds.second});
return cmds;
}
#include <score/plugins/PluginInstances.hpp>
SCORE_EXPORT_PLUGIN(score_addon_tutorial)