/
ManipulatorManager.cpp
66 lines (50 loc) · 1.74 KB
/
ManipulatorManager.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
#include "imanipulator.h"
#include <map>
#include "module/StaticModule.h"
#include "string/convert.h"
namespace selection
{
class ManipulatorManager :
public IManipulatorManager
{
private:
using ManipulatorsByType = std::map<IManipulator::Type, std::function<IManipulator::Ptr()>>;
std::map<IManipulator::Context, ManipulatorsByType> _manipulatorsByContext;
public:
IManipulator::Ptr createManipulator(IManipulator::Context context, IManipulator::Type type) override
{
if (_manipulatorsByContext.count(context) == 0)
{
throw std::runtime_error("Manipulator context not known: " + string::to_string(static_cast<int>(context)));
}
auto existing = _manipulatorsByContext[context].find(type);
if (existing == _manipulatorsByContext[context].end())
{
throw std::runtime_error("Manipulator type not known: " + string::to_string(static_cast<int>(type)));
}
return existing->second();
}
const std::string& getName() const
{
static std::string _name(MODULE_MANIPULATORMANAGER);
return _name;
}
const StringSet& getDependencies() const
{
static StringSet _dependencies;
return _dependencies;
}
void initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
_manipulatorsByContext.emplace(IManipulator::Context::Scene, ManipulatorsByType());
_manipulatorsByContext.emplace(IManipulator::Context::TextureTool, ManipulatorsByType());
// TODO
}
void shutdownModule()
{
_manipulatorsByContext.clear();
}
};
module::StaticModule<ManipulatorManager> _manipulatorManagerInstance;
}