Debian Codegraph @

include/iselectiongroup.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "iselectable.h"
5 #include <sigc++/signal.h>
6
7 // GroupSelectables are regular selectables which can be part of
8 // one or more SelectionGroups.
9 class IGroupSelectable :
10 public ISelectable
11 {
12 public:
13 typedef std::vector<std::size_t> GroupIds;
14
15 virtual ~IGroupSelectable() {}
16
17 // Adds this item to the group specified by its ID
18 virtual void addToGroup(std::size_t groupId) = 0;
19
20 // Removes this item from the group specified by its ID
21 virtual void removeFromGroup(std::size_t groupId) = 0;
22
23 // Returns true if this node is member of any group
24 virtual bool isGroupMember() = 0;
25
26 // Returns the group this node has been added to last
27 // This represents the currently "active" group ID
28 // Will throw an exception if this node is not a member of any group
29 virtual std::size_t getMostRecentGroupId() = 0;
30
31 // Returns all group assignments of this node
32 // The most recently added group is at the back of the list
33 virtual const GroupIds& getGroupIds() const = 0;
34
35 // Special overload to control whether this selectable should propagate
36 // the status change to the group it belongs to.
37 virtual void setSelected(bool select, bool changeGroupStatus) = 0;
38 };
39
40 namespace selection
41 {
42
43 // Represents a SelectionGroup which can contain 0 or more IGroupSelectable nodes.
44 class ISelectionGroup
45 {
46 public:
47 virtual ~ISelectionGroup() {}
48
49 // Returns the ID of this group
50 virtual std::size_t getId() const = 0;
51
52 // Gets the name of this group
53 virtual const std::string& getName() const = 0;
54
55 // Sets the name of this group
56 virtual void setName(const std::string& name) = 0;
57
58 // Adds the given node to this group. The node should be a IGroupSelectable
59 // which will be checked internally. If the node is not matching, nothing happens.
60 virtual void addNode(const scene::INodePtr& node) = 0;
61
62 // Remvoes the given node from this group. The node should be a IGroupSelectable
63 // which will be checked internally. If the node is not matching, nothing happens.
64 // The group will not be removed if this was the last member node
65 virtual void removeNode(const scene::INodePtr& node) = 0;
66
67 // Returns the number of nodes in this group
68 virtual std::size_t size() const = 0;
69
70 // Sets the selection status of all the nodes in this group
71 virtual void setSelected(bool selected) = 0;
72
73 // Calls the given functor for each node in this group.
74 // The functor should not change the membership of this group, this will likely lead
75 // to internal iterator corruption.
76 virtual void foreachNode(const std::function<void(const scene::INodePtr&)>& functor) = 0;
77 };
78 typedef std::shared_ptr<ISelectionGroup> ISelectionGroupPtr;
79
80 class ISelectionGroupManager
81 {
82 public:
83 typedef std::shared_ptr<ISelectionGroupManager> Ptr;
84
85 virtual ~ISelectionGroupManager() {}
86
87 // Creates a new selection group. The group is stored within the SelectionGroupManager
88 // so the returned shared_ptr can safely be let go by the client code.
89 // In the pathological case of being run out of IDs this will throw a std::runtime_error
90 virtual ISelectionGroupPtr createSelectionGroup() = 0;
91
92 // Special overload used to create a group with a specific ID. Only intended to be used
93 // by map loading modules to reconstruct persisted group data after parsing.
94 virtual ISelectionGroupPtr createSelectionGroup(std::size_t id) = 0;
95
96 // Tries to get a selection group by ID. Returns an empty ptr if the ID doesn't exist
97 virtual ISelectionGroupPtr getSelectionGroup(std::size_t id) = 0;
98
99 // Unline getSelectionGroup() this will create the group if it doesn't exist
100 virtual ISelectionGroupPtr findOrCreateSelectionGroup(std::size_t id) = 0;
101
102 // Sets the selection status of all members of the given group
103 virtual void setGroupSelected(std::size_t id, bool selected) = 0;
104
105 // Deletes all selection groups
106 virtual void deleteAllSelectionGroups() = 0;
107
108 // Deletes the group with the given ID. All nodes will be removed from this group as well.
109 virtual void deleteSelectionGroup(std::size_t id) = 0;
110
111 // Visit each group with the given functor
112 virtual void foreachSelectionGroup(const std::function<void(ISelectionGroup&)>& func) = 0;
113 };
114
115 class ISelectionGroupModule :
116 public RegisterableModule
117 {
118 public:
119 virtual ~ISelectionGroupModule() {}
120
121 virtual ISelectionGroupManager::Ptr createSelectionGroupManager() = 0;
122 };
123
124 } // namespace
125
126 const char* const MODULE_SELECTIONGROUPMODULE = "SelectionGroupModule";
127
128 inline selection::ISelectionGroupModule& GlobalSelectionGroupModule()
129 {
130 static module::InstanceReference<selection::ISelectionGroupModule> _reference(MODULE_SELECTIONGROUPMODULE);
131 return _reference;
132 }