Unravel Engine C++ Reference
Loading...
Searching...
No Matches
selection_action.cpp
Go to the documentation of this file.
1#include "selection_action.h"
3
4namespace unravel
5{
6namespace
7{
8 auto convert_to_stable(const std::vector<entt::meta_any>& selection) -> std::vector<entt::meta_any>
9 {
10 std::vector<entt::meta_any> stable_selection;
11 for(const auto& sel : selection)
12 {
13 if(sel.type() == entt::resolve<entt::handle>())
14 {
15 auto handle = sel.cast<entt::handle>();
16 if(handle)
17 {
18 stable_selection.emplace_back(entt::make_uhandle(handle));
19 }
20 }
21 else
22 {
23 stable_selection.emplace_back(sel);
24 }
25 }
26 return stable_selection;
27 }
28
29 auto resolve_stable(const std::vector<entt::meta_any>& selection) -> std::vector<entt::meta_any>
30 {
31 std::vector<entt::meta_any> resolved_selection;
32 for(const auto& sel : selection)
33 {
34 if(sel.type() == entt::resolve<entt::uhandle>())
35 {
36 auto uhandle = sel.cast<entt::uhandle>();
37 auto resolved = uhandle.resolve();
38 if(resolved)
39 {
40 resolved_selection.emplace_back(resolved);
41 }
42 }
43 else
44 {
45 resolved_selection.emplace_back(sel);
46 }
47 }
48 return resolved_selection;
49 }
50}
51
53 const std::vector<entt::meta_any>& old_sel,
54 const std::vector<entt::meta_any>& new_sel, bool is_select)
55 : manager(mgr), old_selection(convert_to_stable(old_sel)), new_selection(convert_to_stable(new_sel)), is_select(is_select)
56{
57 name = is_select ? "Select" : "Unselect";
58 undoable = true;
59
60}
61
63{
64 if (!manager)
65 {
66 return;
67 }
68
69 // Restore the new selection state using the internal method
71}
72
74{
75 if (!manager)
76 {
77 return;
78 }
79
80 // Restore the old selection state using the internal method
82}
83
84auto selection_action_t::is_mergeable(const editing_action_t& previous) const -> bool
85{
86 const auto& selection_action = static_cast<const selection_action_t&>(previous);
87 if(selection_action.is_select != is_select)
88 {
89 return false;
90 }
91
92 // For sequential selection actions (like area picking), merge if:
93 // The current action's old_selection matches the previous action's new_selection
94 // This means the current action is continuing from where the previous one left off
95
96 // Handle empty selections
97 if(old_selection.empty() && selection_action.new_selection.empty())
98 {
99 return true;
100 }
101
102 if(old_selection.size() != selection_action.new_selection.size())
103 {
104 return false;
105 }
106
107 // Check if old_selection matches previous new_selection (order-independent comparison)
108 // This handles the case where entities are selected in different orders
109 for(const auto& old_item : old_selection)
110 {
111 bool found = false;
112 for(const auto& prev_new_item : selection_action.new_selection)
113 {
114 if(old_item == prev_new_item)
115 {
116 found = true;
117 break;
118 }
119 }
120 if(!found)
121 {
122 return false;
123 }
124 }
125
126 return true;
127}
128
130{
131 // When merging, keep the old_selection from the previous action
132 // and use the new_selection from the current action (which is the latest state)
133 const auto& selection_action = static_cast<const selection_action_t&>(previous);
134 old_selection = selection_action.old_selection;
135 // new_selection stays as is (it's the latest state)
136}
137
139{
140 return manager != nullptr;
141}
142
143} // namespace unravel
144
std::string name
Definition hub.cpp:33
auto make_uhandle(entt::handle handle) -> uhandle
Definition scene.h:229
auto resolve() const -> entt::handle
Definition scene.cpp:486
void restore_selection_impl(const std::vector< entt::meta_any > &selection_snapshot)
void merge_with(const editing_action_t &previous) override
auto is_valid() const -> bool override
std::vector< entt::meta_any > old_selection
selection_action_t(editing_manager *mgr, const std::vector< entt::meta_any > &old_sel, const std::vector< entt::meta_any > &new_sel, bool is_select)
auto is_mergeable(const editing_action_t &previous) const -> bool override
std::vector< entt::meta_any > new_selection
gfx::uniform_handle handle
Definition uniform.cpp:9