Node interactions working again, graph editing functions not complete yet

This commit is contained in:
Sebastian
2024-11-30 02:54:40 +01:00
parent 635c94e3cf
commit fcc5d74e18
12 changed files with 343 additions and 441 deletions
+45 -41
View File
@@ -2,7 +2,6 @@
#include "datatypes.h"
#include "draggable.h"
#include "state.h"
#include "vmath.h"
#include "raylib.h"
@@ -34,14 +33,19 @@ using namespace VISEQ::GRAPH::EDGES;
namespace VISEQ::GRAPH {
class GraphManager{
class GraphManager : public std::enable_shared_from_this<GraphManager>{
public:
GraphManager() {}
std::shared_ptr<GraphManager> getPtr(){
return shared_from_this();
}
NODES::VEC_SPTR_Node nodes;
EDGES::VEC_SPTR_Edge edges;
std::map<SPTR_Node, VEC_SPTR_Edge> connections;
EDGES::VEC_SPTR_Edge remove_edges;
EDGES::VEC_SPTR_Edge split_edges;
@@ -51,17 +55,25 @@ namespace VISEQ::GRAPH {
std::map<NODES::SPTR_Node, int> counter;
std::shared_ptr<APP::State> state = APP::State::get();
SPTR_Node addMidiNode(Vec2Df position){
nodes.emplace_back(std::make_shared<MidiNode>(position));
return nodes.back();
}
NODES::SPTR_Node getRandomNode(){
VEC_SPTR_GraphItem o;
std::ranges::sample(nodes, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::NODES::Node>(o.front());
void addNode(SPTR_Node node){
nodes.insert(nodes.end(), node);
nodes.back()->init();
}
EDGES::SPTR_Edge getRandomEdge(){
VEC_SPTR_GraphItem o;
std::ranges::sample(edges, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
void addConnection(SPTR_Node from, SPTR_Node to){
if(from != to) {
edges.emplace_back(std::make_shared<Edge>());
edges.back()->start = from;
edges.back()->end = to;
from->connections.push_back(edges.back());
to->connections.push_back(edges.back());
}
}
void select(){
@@ -84,12 +96,7 @@ namespace VISEQ::GRAPH {
return selected_nodes;
//return nodes | RANGE_FILTER([](SPTR_Node n){return n->selected;}) | std::ranges::to<VEC_SPTR_Node>();
}
void addNode(SPTR_Node node){
nodes.insert(nodes.end(), node);
nodes.back()->init();
}
void copyNodes(VEC_SPTR_Node _nodes, Vec2Df position){
for(auto n: _nodes){
nodes.insert(nodes.end(), std::make_shared<Node>(*n));
@@ -119,12 +126,7 @@ namespace VISEQ::GRAPH {
nodes.back()->setPosition(position);
return nodes.back();
}
SPTR_Node addMidiNode(Vec2Df position){
nodes.emplace_back(std::make_shared<MidiNode>(position));
return nodes.back();
}
void setNodeMode(int mode){
for(auto n: nodes){
n->SMode(mode);
@@ -135,10 +137,28 @@ namespace VISEQ::GRAPH {
counter.clear();
}
SPTR_Node next_node(SPTR_Node current, SPTR_Node last){
std::vector<std::shared_ptr<Connector>> active_connectors;
NODES::SPTR_Node getRandomNode(){
VEC_SPTR_GraphItem o;
std::ranges::sample(nodes, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::NODES::Node>(o.front());
}
EDGES::SPTR_Edge getRandomEdge(){
VEC_SPTR_GraphItem o;
std::ranges::sample(edges, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
}
SPTR_Node getClosestNode(Vec2Df position){
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->picked_up;}) | std::ranges::to<VEC_SPTR_Node>();
std::sort(neighbors.begin(), neighbors.end(), [position](SPTR_Node na, SPTR_Node nb){ return na->position.dist(position) < nb->position.dist(position);});
return neighbors.front();
}
/*SPTR_Node next_node(SPTR_Node current, SPTR_Node last){*/
/* std::vector<std::shared_ptr<Connector>> active_connectors;*/
/**/
/*}*/
SPTR_Node next(SPTR_Node current, SPTR_Node last){
VEC_SPTR_Edge possible_connections = current->connections | RANGE_FILTER([current](SPTR_Edge c){
@@ -180,22 +200,6 @@ namespace VISEQ::GRAPH {
return possible_connections.at(return_path)->getNextNode(current);
}
SPTR_Node getClosestNode(Vec2Df position){
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->picked_up;}) | std::ranges::to<VEC_SPTR_Node>();
std::sort(neighbors.begin(), neighbors.end(), [position](SPTR_Node na, SPTR_Node nb){ return na->position.dist(position) < nb->position.dist(position);});
return neighbors.front();
}
void addConnection(SPTR_Node from, SPTR_Node to){
if(from != to) {
edges.emplace_back(std::make_shared<Edge>());
edges.back()->start = from;
edges.back()->end = to;
from->connections.push_back(edges.back());
to->connections.push_back(edges.back());
}
}
void splitEdge(SPTR_Edge edge){
split_edges.push_back(edge);
}