/
iselection.h
321 lines (263 loc) · 10.2 KB
/
iselection.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
#pragma once
#include <cstddef>
#include "imodule.h"
#include "ivolumetest.h"
#include <memory>
#include <sigc++/signal.h>
class RenderableCollector;
class ISelectable;
class SelectionTest;
namespace scene
{
class INode;
typedef std::shared_ptr<INode> INodePtr;
}
template<typename Element> class BasicVector2;
typedef BasicVector2<double> Vector2;
template<typename Element> class BasicVector3;
typedef BasicVector3<double> Vector3;
template<typename Element> class BasicVector4;
typedef BasicVector4<double> Vector4;
class Matrix4;
class Quaternion;
typedef sigc::signal<void, const ISelectable&> SelectionChangedSignal;
typedef sigc::slot<void, const ISelectable&> SelectionChangedSlot;
class SelectionInfo;
class Face;
class IFace;
class Brush;
class IPatch;
namespace selection
{
struct WorkZone;
/**
* A Manipulator is a renderable object which contains one or more
* ManipulatorComponents, each of which can be manipulated by the user. For
* example, the rotation Manipulator draws several circles which cause rotations
* around specific axes.
*/
class Manipulator
{
public:
// Manipulator type enum, user-defined manipulators should return "Custom"
enum Type
{
Drag,
Translate,
Rotate,
Scale,
Clip,
ModelScale,
Custom
};
/**
* Part of a Manipulator which can be operated upon by the user.
*
* \see Manipulator
*/
class Component
{
public:
virtual ~Component() {}
/**
* Called when the user successfully activates this component. The calling code provides
* information about the view we're operating in, the starting device coords and the
* location of the current selection pivot.
*/
virtual void beginTransformation(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint) = 0;
struct Constraint
{
enum Flags
{
Unconstrained = 0, // no keyboard modifier held
Type1 = 1 << 0, // usually: shift held down
Grid = 1 << 1, // usually: ctrl NOT held down
Type3 = 1 << 2, // usually: alt held down
};
};
/**
* Called during mouse movement, the component is asked to calculate the deltas and distances
* it needs to perform the translation/rotation/scale/whatever the operator does on the selected objects.
* The pivot2world transform relates to the original pivot location at the time the transformation started.
* If the constrained flags are not 0, they indicate the user is holding down a key during movement,
* usually the SHIFT or CTRL key. It's up to the component to decide how to handle the constraint.
*/
virtual void transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int flags) = 0;
};
virtual ~Manipulator() {}
// ID and Type management
virtual std::size_t getId() const = 0;
virtual void setId(std::size_t id) = 0;
virtual Type getType() const = 0;
/**
* Get the currently-active ManipulatorComponent. This is determined by the
* most recent selection test.
*/
virtual Component* getActiveComponent() = 0;
virtual void testSelect(SelectionTest& test, const Matrix4& pivot2world) {}
// Renders the manipulator's visual representation to the scene
virtual void render(RenderableCollector& collector, const VolumeTest& volume) = 0;
virtual void setSelected(bool select) = 0;
virtual bool isSelected() const = 0;
// Manipulators should indicate whether component editing is supported or not
virtual bool supportsComponentManipulation() const = 0;
};
typedef std::shared_ptr<Manipulator> ManipulatorPtr;
}
class SelectionSystem :
public RegisterableModule
{
public:
enum EModifier {
eManipulator, // greebo: This is the standard case (drag, click without modifiers)
eToggle, // This is for Shift-Clicks to toggle the selection of an instance
eReplace, // This is active if the mouse is moved to a NEW location and Alt-Shift is held
eCycle, // This is active if the mouse STAYS at the same position and Alt-Shift is held
};
enum EMode
{
eEntity,
ePrimitive,
eGroupPart,
eComponent,
eMergeAction,
};
// The possible modes when in "component manipulation mode"
enum EComponentMode {
eDefault,
eVertex,
eEdge,
eFace,
};
/** greebo: An SelectionSystem::Observer gets notified
* as soon as the selection is changed.
*/
class Observer
{
public:
virtual ~Observer() {}
/** greebo: This gets called upon selection change.
*
* @instance: The instance that got affected (this may also be the parent brush of a FaceInstance).
* @isComponent: is TRUE if the changed selectable is a component (like a FaceInstance, VertexInstance).
*/
virtual void selectionChanged(const scene::INodePtr& node, bool isComponent) = 0;
};
virtual void addObserver(Observer* observer) = 0;
virtual void removeObserver(Observer* observer) = 0;
// Returns the ID of the registered manipulator
virtual std::size_t registerManipulator(const selection::ManipulatorPtr& manipulator) = 0;
virtual void unregisterManipulator(const selection::ManipulatorPtr& manipulator) = 0;
virtual selection::Manipulator::Type getActiveManipulatorType() = 0;
// Returns the currently active Manipulator, which is always non-null
virtual const selection::ManipulatorPtr& getActiveManipulator() = 0;
virtual void setActiveManipulator(std::size_t manipulatorId) = 0;
virtual void setActiveManipulator(selection::Manipulator::Type manipulatorType) = 0;
virtual sigc::signal<void, selection::Manipulator::Type>& signal_activeManipulatorChanged() = 0;
virtual const SelectionInfo& getSelectionInfo() = 0;
virtual void SetMode(EMode mode) = 0;
virtual EMode Mode() const = 0;
virtual void SetComponentMode(EComponentMode mode) = 0;
virtual EComponentMode ComponentMode() const = 0;
virtual sigc::signal<void, EMode>& signal_selectionModeChanged() = 0;
virtual sigc::signal<void, EComponentMode>& signal_componentModeChanged() = 0;
virtual std::size_t countSelected() const = 0;
virtual std::size_t countSelectedComponents() const = 0;
virtual void onSelectedChanged(const scene::INodePtr& node, const ISelectable& selectable) = 0;
virtual void onComponentSelection(const scene::INodePtr& node, const ISelectable& selectable) = 0;
virtual scene::INodePtr ultimateSelected() = 0;
virtual scene::INodePtr penultimateSelected() = 0;
/**
* \brief
* Set the selection status of all objects in the scene.
*
* \param selected
* true to select all objects, false to deselect all objects.
*/
virtual void setSelectedAll(bool selected) = 0;
virtual void setSelectedAllComponents(bool selected) = 0;
/**
* @brief Visitor interface for the selection system.
*
* This defines the Visitor interface which is used in the foreachSelected()
* and foreachSelectedComponent() visit methods.
*/
class Visitor
{
public:
virtual ~Visitor() {}
/// Called by the selection system for each visited node.
virtual void visit(const scene::INodePtr& node) const = 0;
};
/// Use the provided Visitor object to enumerate each selected node.
void foreachSelected(const Visitor& visitor)
{
foreachSelected([&visitor](const scene::INodePtr& p)
{ visitor.visit(p); });
}
/**
* @brief
* Use the provided Visitor object to enumerate each selected component.
*/
virtual void foreachSelectedComponent(const Visitor& visitor) = 0;
/// Call the given functor to enumerate each selected node.
virtual void foreachSelected(const std::function<void(const scene::INodePtr&)>& functor) = 0;
/**
* @brief
* Use the provided functor to enumerate each selected component.
*/
virtual void foreachSelectedComponent(const std::function<void(const scene::INodePtr&)>& functor) = 0;
/**
* Call the given functor for each selected brush. Selected group nodes like func_statics
* are traversed recursively, invoking the functor for each visible brush in question.
*/
virtual void foreachBrush(const std::function<void(Brush&)>& functor) = 0;
/**
* Call the given functor for each selected face. Selected group nodes like func_statics
* are traversed recursively, invoking the functor for each visible face in question.
* Singly selected faces (those which have been selected in component mode) are
* considered as well by this method.
*/
virtual void foreachFace(const std::function<void(IFace&)>& functor) = 0;
/**
* Call the given functor for each selected patch. Selected group nodes like func_statics
* are traversed recursively, invoking the functor for each visible patch in question.
*/
virtual void foreachPatch(const std::function<void(IPatch&)>& functor) = 0;
// Returns the number of currently selected faces
virtual std::size_t getSelectedFaceCount() = 0;
// Returns the reference to the singly selected face
// Calling this will cause an cmd::ExecutionFailure if getSelectedFaceCount() != 1
virtual IFace& getSingleSelectedFace() = 0;
/// Signal emitted when the selection is changed
virtual SelectionChangedSignal signal_selectionChanged() const = 0;
virtual const Matrix4& getPivot2World() = 0;
virtual void pivotChanged() = 0;
// Feedback events invoked by the ManipulationMouseTool
virtual void onManipulationStart() = 0;
virtual void onManipulationChanged() = 0;
virtual void onManipulationEnd() = 0;
virtual void onManipulationCancelled() = 0;
virtual void selectPoint(SelectionTest& test, EModifier modifier, bool face) = 0;
virtual void selectArea(SelectionTest& test, EModifier modifier, bool face) = 0;
/**
* Returns the current "work zone", which is defined by the
* currently selected elements. Each time a scene node is selected,
* the workzone is adjusted to surround the current selection.
* Deselecting nodes doesn't change the workzone.
*
* The result is used to determine the "third" component of operations
* performed in the 2D views, like placing an entity.
*
* Note: the struct is defined in selectionlib.h.
*/
virtual const selection::WorkZone& getWorkZone() = 0;
// Returns the center point of the current selection
virtual Vector3 getCurrentSelectionCenter() = 0;
};
const char* const MODULE_SELECTIONSYSTEM("SelectionSystem");
inline SelectionSystem& GlobalSelectionSystem()
{
static module::InstanceReference<SelectionSystem> _reference(MODULE_SELECTIONSYSTEM);
return _reference;
}