/
TextureToolSelectionSystem.cpp
146 lines (116 loc) · 3.64 KB
/
TextureToolSelectionSystem.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
#include "TextureToolSelectionSystem.h"
#include "itextstream.h"
#include "module/StaticModule.h"
#include "../manipulators/TextureToolRotateManipulator.h"
namespace textool
{
const std::string& TextureToolSelectionSystem::getName() const
{
static std::string _name(MODULE_TEXTOOL_SELECTIONSYSTEM);
return _name;
}
const StringSet& TextureToolSelectionSystem::getDependencies() const
{
static StringSet _dependencies{ MODULE_TEXTOOL_SCENEGRAPH };
return _dependencies;
}
void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
registerManipulator(std::make_shared<selection::TextureToolRotateManipulator>());
_defaultManipulatorType = selection::IManipulator::Rotate;
setActiveManipulator(_defaultManipulatorType);
}
void TextureToolSelectionSystem::shutdownModule()
{
_sigActiveManipulatorChanged.clear();
_manipulators.clear();
}
void TextureToolSelectionSystem::foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor)
{
GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
if (node->isSelected())
{
return functor(node);
}
return true;
});
}
std::size_t TextureToolSelectionSystem::registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator)
{
std::size_t newId = 1;
while (_manipulators.count(newId) > 0)
{
++newId;
if (newId == std::numeric_limits<std::size_t>::max())
{
throw std::runtime_error("Out of manipulator IDs");
}
}
_manipulators.emplace(newId, manipulator);
manipulator->setId(newId);
if (!_activeManipulator)
{
_activeManipulator = manipulator;
}
return newId;
}
void TextureToolSelectionSystem::unregisterManipulator(const selection::ITextureToolManipulator::Ptr& manipulator)
{
for (auto i = _manipulators.begin(); i != _manipulators.end(); ++i)
{
if (i->second == manipulator)
{
i->second->setId(0);
_manipulators.erase(i);
return;
}
}
}
selection::IManipulator::Type TextureToolSelectionSystem::getActiveManipulatorType()
{
return _activeManipulator->getType();
}
const selection::ITextureToolManipulator::Ptr& TextureToolSelectionSystem::getActiveManipulator()
{
return _activeManipulator;
}
void TextureToolSelectionSystem::setActiveManipulator(std::size_t manipulatorId)
{
auto found = _manipulators.find(manipulatorId);
if (found == _manipulators.end())
{
rError() << "Cannot activate non-existent manipulator ID " << manipulatorId << std::endl;
return;
}
_activeManipulator = found->second;
#if 0
// Release the user lock when switching manipulators
_pivot.setUserLocked(false);
pivotChanged();
#endif
}
void TextureToolSelectionSystem::setActiveManipulator(selection::IManipulator::Type manipulatorType)
{
for (const auto& pair : _manipulators)
{
if (pair.second->getType() == manipulatorType)
{
_activeManipulator = pair.second;
#if 0
// Release the user lock when switching manipulators
_pivot.setUserLocked(false);
pivotChanged();
#endif
return;
}
}
rError() << "Cannot activate non-existent manipulator by type " << manipulatorType << std::endl;
}
sigc::signal<void, selection::IManipulator::Type>& TextureToolSelectionSystem::signal_activeManipulatorChanged()
{
return _sigActiveManipulatorChanged;
}
module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;
}