split edge: check, copy paste: check with a little bug
This commit is contained in:
+28
-8
@@ -49,22 +49,38 @@ class AppState{
|
||||
|
||||
VEC_SPTR_Edge copy_connections;
|
||||
for(auto n : nodes){
|
||||
std::ranges::copy_if(n->connections.begin(), n->connections.end(), std::back_inserter(copy_connections), [nodes](SPTR_Edge e){ return std::ranges::contains(nodes, e->start) && std::ranges::contains(nodes, e->end);});
|
||||
for(auto c : n->connections){
|
||||
if(std::ranges::contains(nodes, c->start) && std::ranges::contains(nodes, c->end)) {
|
||||
copy_connections.push_back(std::make_shared<Edge>(*c));
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << copy_connections.size() << std::endl;
|
||||
|
||||
for(auto old_node : nodes){
|
||||
SPTR_Node new_node;
|
||||
|
||||
if(old_node->getNodeType() == NodeType::MIDINODE) {
|
||||
new_node = gm.copyNode(std::dynamic_pointer_cast<MidiNode>(old_node), position + old_node->drag_offset);
|
||||
} else {
|
||||
new_node = gm.copyNode(old_node, position + old_node->drag_offset);
|
||||
}
|
||||
|
||||
for(auto n : nodes){
|
||||
SPTR_Node old_node = n;
|
||||
SPTR_Node new_node = gm.copyNode(n, position + n->drag_offset);
|
||||
new_node->copied = false;
|
||||
new_node->selected = false;
|
||||
|
||||
for(auto c : copy_connections){
|
||||
if(c->start == old_node) c->start = new_node;
|
||||
if(c->end == old_node) c->end = new_node;
|
||||
if(c->start == old_node) {
|
||||
c->start = new_node;
|
||||
c->start->connections.push_back(c);
|
||||
}
|
||||
if(c->end == old_node) {
|
||||
c->end = new_node;
|
||||
c->end->connections.push_back(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gm.edges.insert(gm.edges.end(), copy_connections.cbegin(), copy_connections.cend());
|
||||
std::ranges::copy(copy_connections.begin(), copy_connections.end(), std::back_inserter(gm.edges));
|
||||
}
|
||||
|
||||
void removeNodes(VEC_SPTR_Node nodes){
|
||||
@@ -103,6 +119,10 @@ class AppState{
|
||||
s->start = s->next;
|
||||
}
|
||||
|
||||
for(auto n : adjacent_nodes){
|
||||
std::erase_if(n->connections, [n, nodes](SPTR_Edge c){ return std::ranges::contains(nodes, c->start) || std::ranges::contains(nodes, c->end);});
|
||||
}
|
||||
|
||||
for(auto n : nodes){
|
||||
std::erase_if(gm.edges, [n](SPTR_Edge c){ return c->start == n || c->end == n;});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user