/
DragManipulator.cpp
177 lines (142 loc) · 5.37 KB
/
DragManipulator.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
166
167
168
169
170
171
172
173
174
175
176
177
#include "DragManipulator.h"
#include "selection/SelectionPool.h"
#include "selection/SelectionTestWalkers.h"
#include "selection/algorithm/Planes.h"
#include "selection/SingleItemSelector.h"
#include "selection/BestSelector.h"
#include "registry/registry.h"
namespace selection
{
const std::string RKEY_TRANSIENT_COMPONENT_SELECTION = "user/ui/transientComponentSelection";
DragManipulator::DragManipulator(ManipulationPivot& pivot, SelectionSystem& selectionSystem, ISceneSelectionTesterFactory& factory) :
_pivot(pivot),
_selectionSystem(selectionSystem),
_testerFactory(factory),
_freeResizeComponent(_resizeTranslatable),
_resizeModeActive(false),
_freeDragComponent(_dragTranslatable),
_dragTranslatable(SelectionTranslator::TranslationCallback())
{}
DragManipulator::Type DragManipulator::getType() const
{
return Drag;
}
DragManipulator::Component* DragManipulator::getActiveComponent()
{
return _dragSelectable.isSelected() ? &_freeDragComponent : &_freeResizeComponent;
}
void DragManipulator::testSelect(SelectionTest& test, const Matrix4& pivot2world)
{
_resizeModeActive = false;
// No drag manipulation in merge mode
if (_selectionSystem.getSelectionMode() == SelectionMode::MergeAction) return;
SelectionPool selector;
switch (_selectionSystem.getSelectionMode())
{
case SelectionMode::Primitive:
testSelectPrimitiveMode(test.getVolume(), test, selector);
break;
case SelectionMode::GroupPart:
testSelectGroupPartMode(test.getVolume(), test, selector);
break;
case SelectionMode::Entity:
testSelectEntityMode(test.getVolume(), test, selector);
break;
case SelectionMode::Component:
testSelectComponentMode(test.getVolume(), test, selector);
break;
};
for (SelectionPool::const_iterator i = selector.begin(); i != selector.end(); ++i)
{
i->second->setSelected(true);
}
}
void DragManipulator::testSelectPrimitiveMode(const VolumeTest& view, SelectionTest& test, SelectionPool& selector)
{
SingleItemSelector itemSelector;
// First try to select entities (including func_* groups)
EntitySelector selectionTester(itemSelector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, selectionTester);
if (itemSelector.hasValidSelectable())
{
// Found a selectable entity
selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
return;
}
// Find all worldspawn primitives
PrimitiveSelector primitiveTester(itemSelector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, primitiveTester);
if (itemSelector.hasValidSelectable())
{
// Found a selectable primitive
selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
return;
}
// Entities and worldspawn primitives failed, so check for group children too
// Find all group child primitives that are selectable
GroupChildPrimitiveSelector childPrimitiveTester(itemSelector, test);
GlobalSceneGraph().foreachVisibleNodeInVolume(view, childPrimitiveTester);
if (itemSelector.hasValidSelectable())
{
// Found a selectable group child primitive
selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
return;
}
// all direct hits failed, check for drag-selectable faces
_resizeModeActive = algorithm::testSelectPlanes(selector, test);
}
void DragManipulator::testSelectGroupPartMode(const VolumeTest& view, SelectionTest& test, SelectionPool& selector)
{
// Find all primitives that are selectable
SingleItemSelector itemSelector;
auto tester = _testerFactory.createSceneSelectionTester(SelectionMode::GroupPart);
tester->testSelectScene(view, test, itemSelector);
if (itemSelector.hasValidSelectable())
{
// Found a selectable primitive
selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
return;
}
// Check for selectable faces
_resizeModeActive = algorithm::testSelectPlanes(selector, test);
}
void DragManipulator::testSelectEntityMode(const VolumeTest& view, SelectionTest& test, SelectionPool& selector)
{
// Create a boolean selection pool (can have exactly one selectable or none)
SingleItemSelector itemSelector;
auto tester = _testerFactory.createSceneSelectionTester(SelectionMode::Entity);
tester->testSelectScene(view, test, itemSelector);
// Check, if an entity could be found
if (itemSelector.hasValidSelectable())
{
selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
}
}
void DragManipulator::testSelectComponentMode(const VolumeTest& view, SelectionTest& test, SelectionPool& selector)
{
BestSelector bestSelector;
auto tester = _testerFactory.createSceneSelectionTester(SelectionMode::Component);
tester->testSelectScene(view, test, bestSelector);
bool transientComponentSelection = registry::getValue<bool>(RKEY_TRANSIENT_COMPONENT_SELECTION);
for (ISelectable* selectable : bestSelector.getBestSelectables())
{
// greebo: For transient component selection, clicking an unselected
// component will deselect all previously selected components beforehand
if (transientComponentSelection && !selectable->isSelected())
{
_selectionSystem.setSelectedAllComponents(false);
}
selector.addSelectable(SelectionIntersection(0, 0), selectable);
_dragSelectable.setSelected(true);
}
}
void DragManipulator::setSelected(bool select)
{
_resizeModeActive = select;
_dragSelectable.setSelected(select);
}
bool DragManipulator::isSelected() const
{
return _resizeModeActive || _dragSelectable.isSelected();
}
}