/
iselectiongroup.h
137 lines (103 loc) · 4.63 KB
/
iselectiongroup.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
#pragma once
#include "imodule.h"
#include "iselectable.h"
#include <sigc++/signal.h>
// GroupSelectables are regular selectables which can be part of
// one or more SelectionGroups.
class IGroupSelectable :
public ISelectable
{
public:
typedef std::vector<std::size_t> GroupIds;
virtual ~IGroupSelectable() {}
// Adds this item to the group specified by its ID
virtual void addToGroup(std::size_t groupId) = 0;
// Removes this item from the group specified by its ID
virtual void removeFromGroup(std::size_t groupId) = 0;
// Returns true if this node is member of any group
virtual bool isGroupMember() = 0;
// Returns the group this node has been added to last
// This represents the currently "active" group ID
// Will throw an exception if this node is not a member of any group
virtual std::size_t getMostRecentGroupId() = 0;
// Returns all group assignments of this node
// The most recently added group is at the back of the list
virtual const GroupIds& getGroupIds() const = 0;
// Special overload to control whether this selectable should propagate
// the status change to the group it belongs to.
virtual void setSelected(bool select, bool changeGroupStatus) = 0;
};
namespace selection
{
// Represents a SelectionGroup which can contain 0 or more IGroupSelectable nodes.
class ISelectionGroup
{
public:
virtual ~ISelectionGroup() {}
// Returns the ID of this group
virtual std::size_t getId() const = 0;
// Gets the name of this group
virtual const std::string& getName() const = 0;
// Sets the name of this group
virtual void setName(const std::string& name) = 0;
// Adds the given node to this group. The node should be a IGroupSelectable
// which will be checked internally. If the node is not matching, nothing happens.
virtual void addNode(const scene::INodePtr& node) = 0;
// Remvoes the given node from this group. The node should be a IGroupSelectable
// which will be checked internally. If the node is not matching, nothing happens.
// The group will not be removed if this was the last member node
virtual void removeNode(const scene::INodePtr& node) = 0;
// Returns the number of nodes in this group
virtual std::size_t size() const = 0;
// Sets the selection status of all the nodes in this group
virtual void setSelected(bool selected) = 0;
// Calls the given functor for each node in this group.
// The functor should not change the membership of this group, this will likely lead
// to internal iterator corruption.
virtual void foreachNode(const std::function<void(const scene::INodePtr&)>& functor) = 0;
};
typedef std::shared_ptr<ISelectionGroup> ISelectionGroupPtr;
class ISelectionGroupManager
{
public:
typedef std::shared_ptr<ISelectionGroupManager> Ptr;
virtual ~ISelectionGroupManager() {}
// Creates a new selection group. The group is stored within the SelectionGroupManager
// so the returned shared_ptr can safely be let go by the client code.
// In the pathological case of being run out of IDs this will throw a std::runtime_error
virtual ISelectionGroupPtr createSelectionGroup() = 0;
// Special overload used to create a group with a specific ID. Only intended to be used
// by map loading modules to reconstruct persisted group data after parsing.
virtual ISelectionGroupPtr createSelectionGroup(std::size_t id) = 0;
// Tries to get a selection group by ID. Returns an empty ptr if the ID doesn't exist
virtual ISelectionGroupPtr getSelectionGroup(std::size_t id) = 0;
// Unline getSelectionGroup() this will create the group if it doesn't exist
virtual ISelectionGroupPtr findOrCreateSelectionGroup(std::size_t id) = 0;
// Sets the selection status of all members of the given group
virtual void setGroupSelected(std::size_t id, bool selected) = 0;
// Deletes all selection groups
virtual void deleteAllSelectionGroups() = 0;
// Deletes the group with the given ID. All nodes will be removed from this group as well.
virtual void deleteSelectionGroup(std::size_t id) = 0;
// Visit each group with the given functor
virtual void foreachSelectionGroup(const std::function<void(ISelectionGroup&)>& func) = 0;
};
class ISelectionGroupModule :
public RegisterableModule
{
public:
virtual ~ISelectionGroupModule() {}
virtual ISelectionGroupManager::Ptr createSelectionGroupManager() = 0;
};
} // namespace
const char* const MODULE_SELECTIONGROUPMODULE = "SelectionGroupModule";
inline selection::ISelectionGroupModule& GlobalSelectionGroupModule()
{
// Cache the reference locally
static selection::ISelectionGroupModule& _module(
*std::static_pointer_cast<selection::ISelectionGroupModule>(
module::GlobalModuleRegistry().getModule(MODULE_SELECTIONGROUPMODULE)
)
);
return _module;
}