Debian Codegraph @

include/itexturetoolmodel.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "inode.h"
5 #include "Bounded.h"
6 #include "iselection.h"
7 #include "iselectiontest.h"
8 #include "iselectable.h"
9 #include "imanipulator.h"
10 #include "editable.h"
11 #include <sigc++/signal.h>
12
13 class Matrix3;
14 class IFace;
15 class IPatch;
16
17 namespace textool
18 {
19
20 // Enumeration of possible texture tool selection modes
21 enum class SelectionMode
22 {
23 Surface,
24 Vertex,
25 };
26
27 /**
28 * A transformable node in the texture tool scene. This is usually
29 * implemented by Faces and Patches. They will accept a given transformation
30 * and apply it to their selected child elements.
31 * For faces, this could mean that three selected vertices (out of four)
32 * will be transformed by the given matrix. It's possible that unselected
33 * winding vertices will be affected by this transformation, due to the nature
34 * of the texture projection.
35 * Patch vertices can be transformed independently.
36 */
37 class ITransformable
38 {
39 public:
40 // Let this object save a snapshot of its current texture state to have something
41 // to base the upcoming transformation on
42 virtual void beginTransformation() = 0;
43
44 // Move the state back to the base state we saved in beginTransformation()
45 // Is called right before applyTransformationToSelected() is invoked with a new transform
46 virtual void revertTransformation() = 0;
47
48 // Applies the given transform to all selected components of this node.
49 virtual void transform(const Matrix3& transform) = 0;
50
51 // "Saves" the current transformed state as the new base state
52 virtual void commitTransformation() = 0;
53 };
54
55 // A Texture Tool node that consists of one or more selectable components
56 class IComponentSelectable
57 {
58 public:
59 using Ptr = std::shared_ptr<IComponentSelectable>;
60
61 virtual ~IComponentSelectable() {}
62
63 // True if this node has at least one selected component (e.g. a vertex)
64 virtual bool hasSelectedComponents() const = 0;
65
66 // Returns the number of selected components
67 virtual std::size_t getNumSelectedComponents() const = 0;
68
69 // Unselect all components of this node
70 virtual void clearComponentSelection() = 0;
71
72 // Perform a selection test using the given selector and test volume
73 virtual void testSelectComponents(Selector& selector, SelectionTest& test) = 0;
74
75 // Returns the bounds containing all the selected vertices
76 virtual AABB getSelectedComponentBounds() = 0;
77
78 // If this node has selected components, this selects all related items too
79 // E.g. a single winding vertex expands to the entire winding
80 virtual void expandComponentSelectionToRelated() = 0;
81 };
82
83 // A Texture Tool node that allows its components to be transformed
84 class IComponentTransformable
85 {
86 public:
87 virtual ~IComponentTransformable() {}
88
89 // Apply the given transformation matrix to all selected components
90 virtual void transformComponents(const Matrix3& transform) = 0;
91
92 // Tries to merge selected components with the given point
93 virtual void mergeComponentsWith(const Vector2& center) = 0;
94 };
95
96 // The base element of every node in the ITextureToolSceneGraph
97 class INode :
98 public ITransformable,
99 public Bounded,
100 public ISelectable,
101 public SelectionTestable,
102 public Snappable
103 {
104 public:
105 virtual ~INode() {}
106
107 using Ptr = std::shared_ptr<INode>;
108
109 // Renders this node, with all coords relative to UV space origin
110 virtual void render(SelectionMode mode) = 0;
111
112 // If this node is selected, this selects all related items too:
113 // a single face expands to all faces of the same brush
114 virtual void expandSelectionToRelated() = 0;
115 };
116
117 // Node representing a single brush face
118 class IFaceNode :
119 public virtual INode,
120 public virtual IComponentSelectable,
121 public virtual IComponentTransformable,
122 public virtual ComponentSnappable
123 {
124 public:
125 virtual ~IFaceNode() {}
126
127 using Ptr = std::shared_ptr<IFaceNode>;
128
129 virtual IFace& getFace() = 0;
130 };
131
132 // Node representing a patch
133 class IPatchNode :
134 public virtual INode,
135 public virtual IComponentSelectable,
136 public virtual IComponentTransformable,
137 public virtual ComponentSnappable
138 {
139 public:
140 virtual ~IPatchNode() {}
141
142 using Ptr = std::shared_ptr<IPatchNode>;
143
144 virtual IPatch& getPatch() = 0;
145 };
146
147 /**
148 * The scene graph of all texture tool items. From all the selected
149 * items in the regular SceneGraph the texture-editable elements
150 * are extracted and put into this graph.
151 *
152 * It can have multiple top-level elements (faces, patches) each of which
153 * can have an arbitrary number of child elements (vertices).
154 *
155 * Like in the regular scene graph, some of the elements have special
156 * properties like being renderable or transformable, which manifests
157 * in them implementing the corresponding interface.
158 */
159 class ITextureToolSceneGraph :
160 public RegisterableModule
161 {
162 public:
163 virtual ~ITextureToolSceneGraph() {}
164
165 // Returns the name of the single material that all the tex tool nodes are sharing.
166 // This is an empty string if this scene graph is empty, i.e. the map selection doesn't
167 // boil down to a single selected material.
168 virtual const std::string& getActiveMaterial() = 0;
169
170 // Iterate over every node in this graph calling the given functor
171 // Collection should not be modified during iteration
172 virtual void foreachNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;
173 };
174
175 class ITextureToolSelectionSystem :
176 public RegisterableModule
177 {
178 public:
179 // Iterate over every selected node in this graph calling the given functor
180 // Collection should not be modified during iteration
181 virtual void foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;
182
183 // Iterate over every node that has at least one component selected, visiting the given functor
184 // Collection should not be modified during iteration
185 virtual void foreachSelectedComponentNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;
186
187 virtual std::size_t countSelected() = 0;
188 virtual std::size_t countSelectedComponentNodes() = 0;
189
190 virtual sigc::signal<void>& signal_selectionChanged() = 0;
191
192 virtual void clearSelection() = 0;
193 virtual void clearComponentSelection() = 0;
194
195 virtual SelectionMode getSelectionMode() const = 0;
196 virtual void setSelectionMode(SelectionMode mode) = 0;
197
198 // Will switch to the given selection mode. If already in mode, this switches back to Default mode (Surface).
199 virtual void toggleSelectionMode(SelectionMode mode) = 0;
200
201 virtual sigc::signal<void, SelectionMode>& signal_selectionModeChanged() = 0;
202
203 virtual void selectPoint(SelectionTest& test, selection::SelectionSystem::EModifier modifier) = 0;
204 virtual void selectArea(SelectionTest& test, selection::SelectionSystem::EModifier modifier) = 0;
205
206 // Returns the ID of the registered manipulator
207 virtual std::size_t registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) = 0;
208 virtual void unregisterManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) = 0;
209
210 virtual selection::IManipulator::Type getActiveManipulatorType() = 0;
211
212 // Returns the currently active Manipulator, which is always non-null
213 virtual const selection::ITextureToolManipulator::Ptr& getActiveManipulator() = 0;
214 virtual void setActiveManipulator(std::size_t manipulatorId) = 0;
215 virtual void setActiveManipulator(selection::IManipulator::Type manipulatorType) = 0;
216
217 // Toggles the given manipulator mode. If the current mode is already set to <manipulatorType>,
218 // the system will switch back to default mode.
219 virtual void toggleManipulatorMode(selection::IManipulator::Type manipulatorType) = 0;
220
221 virtual sigc::signal<void, selection::IManipulator::Type>& signal_activeManipulatorChanged() = 0;
222
223 virtual Matrix4 getPivot2World() = 0;
224 virtual void onManipulationStart() = 0;
225 virtual void onManipulationChanged() = 0;
226 virtual void onManipulationFinished() = 0;
227 virtual void onManipulationCancelled() = 0;
228
229 // Feedback methods which are invoked by selectable nodes to report a selection status change
230 virtual void onNodeSelectionChanged(ISelectable& selectable) = 0;
231 virtual void onComponentSelectionChanged(ISelectable& selectable) = 0;
232 };
233
234 constexpr const char* const RKEY_GRID_STATE = "user/ui/textures/texTool/gridActive";
235
236 }
237
238 constexpr const char* const MODULE_TEXTOOL_SCENEGRAPH("TextureToolSceneGraph");
239 constexpr const char* const MODULE_TEXTOOL_SELECTIONSYSTEM("TextureToolSelectionSystem");
240
241 inline textool::ITextureToolSceneGraph& GlobalTextureToolSceneGraph()
242 {
243 static module::InstanceReference<textool::ITextureToolSceneGraph> _reference(MODULE_TEXTOOL_SCENEGRAPH);
244 return _reference;
245 }
246
247 inline textool::ITextureToolSelectionSystem& GlobalTextureToolSelectionSystem()
248 {
249 static module::InstanceReference<textool::ITextureToolSelectionSystem> _reference(MODULE_TEXTOOL_SELECTIONSYSTEM);
250 return _reference;
251 }
252