copy nodes with connections
This commit is contained in:
+19
-2
@@ -44,6 +44,25 @@ class AppState{
|
||||
}
|
||||
}
|
||||
|
||||
void copyNodesAndConnections(Vec2D<float> position){
|
||||
auto copy_nodes_ids = nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n){return n.copied;}) | std::views::transform([](Node n){return n.id;}) | std::ranges::to<std::vector<int>>();
|
||||
|
||||
std::vector<Connection> copy_connections;
|
||||
std::ranges::copy_if(cm.connections, std::back_inserter(copy_connections), [copy_nodes_ids](Connection c){return std::ranges::contains(copy_nodes_ids, c.v1) && std::ranges::contains(copy_nodes_ids, c.v2);});
|
||||
|
||||
for(auto &n : copy_nodes_ids){
|
||||
int old_id = n;
|
||||
int new_id = nm.copyNode(n, position + nm.nodes[n].drag_offset);
|
||||
|
||||
for(auto &c : copy_connections){
|
||||
if(c.v1 == old_id) c.v1 = new_id;
|
||||
if(c.v2 == old_id) c.v2 = new_id;
|
||||
}
|
||||
}
|
||||
|
||||
cm.connections.insert(cm.connections.end(), copy_connections.cbegin(), copy_connections.cend());
|
||||
}
|
||||
|
||||
void removeNodes(){
|
||||
|
||||
for(auto &n : nm.nodes){
|
||||
@@ -66,8 +85,6 @@ class AppState{
|
||||
if(!nm.nodes.at(c.v2).selected) adjacent_nodes_ids.push_back(c.v2);
|
||||
}
|
||||
|
||||
// std::ranges::for_each(adjacent_nodes_ids, [this](int id){ nm.nodes.at(id).highlighted = true;} );
|
||||
|
||||
auto reroute_signals = sm.signals | std::ranges::views::filter([erase_nodes_ids](Signal s){
|
||||
return std::ranges::contains(erase_nodes_ids, s.next);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user