Debian Codegraph @

include/iselection.h

raw
1 #pragma once
2
3 #include <cstddef>
4 #include "imodule.h"
5 #include <memory>
6 #include <sigc++/signal.h>
7 #include "imanipulator.h"
8
9 class RenderableCollector;
10
11 class ISelectable;
12 class SelectionTest;
13
14 namespace scene
15 {
16 class INode;
17 typedef std::shared_ptr<INode> INodePtr;
18 }
19
20 template<typename Element> class BasicVector2;
21 typedef BasicVector2<double> Vector2;
22 template<typename Element> class BasicVector3;
23 typedef BasicVector3<double> Vector3;
24 template<typename Element> class BasicVector4;
25 typedef BasicVector4<double> Vector4;
26 class Matrix4;
27 class Quaternion;
28
29 typedef sigc::signal<void, const ISelectable&> SelectionChangedSignal;
30 typedef std::function<void(const ISelectable&)> SelectionChangedSlot;
31
32 class SelectionInfo;
33 class Face;
34 class IFace;
35 class Brush;
36 class IPatch;
37
38 namespace selection
39 {
40 struct WorkZone;
41
42 // The possible modes when in "component manipulation mode"
43 // Used by the SelectionSystem as well as the Texture Tool
44 enum class ComponentSelectionMode
45 {
46 Default,
47 Vertex,
48 Edge,
49 Face,
50 };
51
52 // The selection strategy determining the scene objects chosen for selection tests
53 enum class SelectionMode
54 {
55 Entity, // Entities only
56 Primitive, // Primitives (no components), entities take precedence
57 GroupPart, // Child Primitives of non-worldspawn entities
58 Component, // Components
59 MergeAction, // Merge Action nodes only
60 };
61 }
62
63 namespace selection
64 {
65
66 class SelectionSystem :
67 public RegisterableModule
68 {
69 public:
70 enum EModifier {
71 eManipulator, // greebo: This is the standard case (drag, click without modifiers)
72 eToggle, // This is for Shift-Clicks to toggle the selection of an instance
73 eReplace, // This is active if the mouse is moved to a NEW location and Alt-Shift is held
74 eCycle, // This is active if the mouse STAYS at the same position and Alt-Shift is held
75 };
76
77 /** greebo: An SelectionSystem::Observer gets notified
78 * as soon as the selection is changed.
79 */
80 class Observer
81 {
82 public:
83 virtual ~Observer() {}
84 /** greebo: This gets called upon selection change.
85 *
86 * @instance: The instance that got affected (this may also be the parent brush of a FaceInstance).
87 * @isComponent: is TRUE if the changed selectable is a component (like a FaceInstance, VertexInstance).
88 */
89 virtual void selectionChanged(const scene::INodePtr& node, bool isComponent) = 0;
90 };
91
92 virtual void addObserver(Observer* observer) = 0;
93 virtual void removeObserver(Observer* observer) = 0;
94
95 // Returns the ID of the registered manipulator
96 virtual std::size_t registerManipulator(const ISceneManipulator::Ptr& manipulator) = 0;
97 virtual void unregisterManipulator(const ISceneManipulator::Ptr& manipulator) = 0;
98
99 virtual IManipulator::Type getActiveManipulatorType() = 0;
100
101 // Returns the currently active Manipulator, which is always non-null
102 virtual const ISceneManipulator::Ptr& getActiveManipulator() = 0;
103 virtual void setActiveManipulator(std::size_t manipulatorId) = 0;
104 virtual void setActiveManipulator(IManipulator::Type manipulatorType) = 0;
105
106 virtual sigc::signal<void, IManipulator::Type>& signal_activeManipulatorChanged() = 0;
107
108 virtual const SelectionInfo& getSelectionInfo() = 0;
109
110 virtual void setSelectionMode(SelectionMode mode) = 0;
111 virtual SelectionMode getSelectionMode() const = 0;
112
113 virtual void SetComponentMode(ComponentSelectionMode mode) = 0;
114 virtual ComponentSelectionMode ComponentMode() const = 0;
115
116 virtual sigc::signal<void, SelectionMode>& signal_selectionModeChanged() = 0;
117 virtual sigc::signal<void, ComponentSelectionMode>& signal_componentModeChanged() = 0;
118
119 virtual std::size_t countSelected() const = 0;
120 virtual std::size_t countSelectedComponents() const = 0;
121 virtual void onSelectedChanged(const scene::INodePtr& node, const ISelectable& selectable) = 0;
122 virtual void onComponentSelection(const scene::INodePtr& node, const ISelectable& selectable) = 0;
123
124 virtual scene::INodePtr ultimateSelected() = 0;
125 virtual scene::INodePtr penultimateSelected() = 0;
126
127 /**
128 * \brief
129 * Set the selection status of all objects in the scene.
130 *
131 * \param selected
132 * true to select all objects, false to deselect all objects.
133 */
134 virtual void setSelectedAll(bool selected) = 0;
135
136 virtual void setSelectedAllComponents(bool selected) = 0;
137
138 /**
139 * @brief Visitor interface for the selection system.
140 *
141 * This defines the Visitor interface which is used in the foreachSelected()
142 * and foreachSelectedComponent() visit methods.
143 */
144 class Visitor
145 {
146 public:
147 virtual ~Visitor() {}
148
149 /// Called by the selection system for each visited node.
150 virtual void visit(const scene::INodePtr& node) const = 0;
151 };
152
153 /// Use the provided Visitor object to enumerate each selected node.
154 void foreachSelected(const Visitor& visitor)
155 {
156 foreachSelected([&visitor](const scene::INodePtr& p)
157 { visitor.visit(p); });
158 }
159
160 /**
161 * @brief
162 * Use the provided Visitor object to enumerate each selected component.
163 */
164 virtual void foreachSelectedComponent(const Visitor& visitor) = 0;
165
166 /// Call the given functor to enumerate each selected node.
167 virtual void foreachSelected(const std::function<void(const scene::INodePtr&)>& functor) = 0;
168
169 /**
170 * @brief
171 * Use the provided functor to enumerate each selected component.
172 */
173 virtual void foreachSelectedComponent(const std::function<void(const scene::INodePtr&)>& functor) = 0;
174
175 /**
176 * Call the given functor for each selected brush. Selected group nodes like func_statics
177 * are traversed recursively, invoking the functor for each visible brush in question.
178 */
179 virtual void foreachBrush(const std::function<void(Brush&)>& functor) = 0;
180
181 /**
182 * Call the given functor for each selected face. Selected group nodes like func_statics
183 * are traversed recursively, invoking the functor for each visible face in question.
184 * Singly selected faces (those which have been selected in component mode) are
185 * considered as well by this method.
186 */
187 virtual void foreachFace(const std::function<void(IFace&)>& functor) = 0;
188
189 /**
190 * Call the given functor for each selected patch. Selected group nodes like func_statics
191 * are traversed recursively, invoking the functor for each visible patch in question.
192 */
193 virtual void foreachPatch(const std::function<void(IPatch&)>& functor) = 0;
194
195 // Returns the number of currently selected faces
196 virtual std::size_t getSelectedFaceCount() = 0;
197
198 // Returns the reference to the singly selected face
199 // Calling this will cause an cmd::ExecutionFailure if getSelectedFaceCount() != 1
200 virtual IFace& getSingleSelectedFace() = 0;
201
202 /// Signal emitted when the selection is changed
203 virtual SelectionChangedSignal signal_selectionChanged() const = 0;
204
205 virtual const Matrix4& getPivot2World() = 0;
206 virtual void pivotChanged() = 0;
207
208 // Feedback events invoked by the ManipulationMouseTool
209 virtual void onManipulationStart() = 0;
210 virtual void onManipulationChanged() = 0;
211 virtual void onManipulationEnd() = 0;
212 virtual void onManipulationCancelled() = 0;
213
214 virtual void selectPoint(SelectionTest& test, EModifier modifier, bool face) = 0;
215 virtual void selectArea(SelectionTest& test, EModifier modifier, bool face) = 0;
216
217 /**
218 * Returns the current "work zone", which is defined by the
219 * currently selected elements. Each time a scene node is selected,
220 * the workzone is adjusted to surround the current selection.
221 * Deselecting nodes doesn't change the workzone.
222 *
223 * The result is used to determine the "third" component of operations
224 * performed in the 2D views, like placing an entity.
225 *
226 * Note: the struct is defined in selectionlib.h.
227 */
228 virtual const WorkZone& getWorkZone() = 0;
229
230 // Returns the center point of the current selection
231 virtual Vector3 getCurrentSelectionCenter() = 0;
232
233 // Toggles selection focus mode (only possible with a non-empty selection)
234 // After activating, only items that are part of the set can be selected and manipulated.
235 // Throws cmd::ExecutionNotPossible when trying to activate with an empty selection
236 virtual void toggleSelectionFocus() = 0;
237
238 // Returns true when focus mode is active
239 // In focus mode only certain elements in the map can be selected.
240 // It's also possible to select single parts of selection groups
241 // without disbanding the group.
242 virtual bool selectionFocusIsActive() = 0;
243
244 // Returns the volume the focus items are occupying
245 virtual AABB getSelectionFocusBounds() = 0;
246 };
247
248 }
249
250 constexpr const char* const MODULE_SELECTIONSYSTEM("SelectionSystem");
251
252 inline selection::SelectionSystem& GlobalSelectionSystem()
253 {
254 static module::InstanceReference<selection::SelectionSystem> _reference(MODULE_SELECTIONSYSTEM);
255 return _reference;
256 }