Running again after weak_ptr refactoring. No connecting of nodes atm. Copy/Paste might not work, too.
This commit is contained in:
+43
-19
@@ -38,14 +38,12 @@ namespace VISEQ::GRAPH {
|
||||
NODES::VEC_SPTR_Node nodes;
|
||||
EDGES::VEC_SPTR_Edge edges;
|
||||
|
||||
std::map<WPTR_Node, VEC_WPTR_Edge> connections;
|
||||
|
||||
EDGES::VEC_WPTR_Edge remove_edges;
|
||||
EDGES::VEC_WPTR_Edge split_edges;
|
||||
|
||||
VEC_WPTR_Node selected_nodes;
|
||||
VEC_SPTR_Node selected_nodes;
|
||||
|
||||
std::map<NODES::WPTR_Node, int> counter;
|
||||
std::map<NODES::SPTR_Node, int> counter;
|
||||
|
||||
std::shared_ptr<APP::State> state = APP::State::get();
|
||||
|
||||
@@ -56,10 +54,20 @@ namespace VISEQ::GRAPH {
|
||||
std::shared_ptr<GraphManager> getPtr(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
|
||||
int getNodesSize(){
|
||||
return nodes.size();
|
||||
}
|
||||
|
||||
void addMidiNode(Vec2Df position){
|
||||
nodes.emplace_back(std::make_shared<MidiNode>(position));
|
||||
}
|
||||
|
||||
void setMidiPortForAll(int number, bool _state){
|
||||
for(auto n : nodes){
|
||||
if(n->getNodeType() == NodeType::MIDINODE) std::dynamic_pointer_cast<MidiNode>(n)->setMidiPort(number, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void addNode(SPTR_Node node){
|
||||
nodes.insert(nodes.end(), node);
|
||||
@@ -70,8 +78,8 @@ namespace VISEQ::GRAPH {
|
||||
edges.emplace_back(std::make_shared<Edge>());
|
||||
edges.back()->start = from;
|
||||
edges.back()->end = to;
|
||||
edges.back()->start_conn = from.lock()->connectors.back();
|
||||
edges.back()->end_conn = to.lock()->connectors.back();
|
||||
// edges.back()->start_conn = from.lock()->connectors.back(); // TODO: crashes on start
|
||||
// edges.back()->end_conn = to.lock()->connectors.back();
|
||||
from.lock()->connections.push_back(edges.back());
|
||||
to.lock()->connections.push_back(edges.back());
|
||||
}
|
||||
@@ -88,12 +96,12 @@ namespace VISEQ::GRAPH {
|
||||
void deselect(){
|
||||
std::cout << "deselect" << std::endl;
|
||||
for(auto s : selected_nodes){
|
||||
s.lock()->selected = false;
|
||||
s->selected = false;
|
||||
}
|
||||
selected_nodes.clear();
|
||||
}
|
||||
|
||||
VEC_WPTR_Node getSelection(){
|
||||
VEC_SPTR_Node getSelection(){
|
||||
return selected_nodes;
|
||||
}
|
||||
|
||||
@@ -112,7 +120,17 @@ namespace VISEQ::GRAPH {
|
||||
nodes.back()->selected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VEC_SPTR_Node getCopiesOfSelectedNodes(){
|
||||
VEC_SPTR_Node copied_nodes;
|
||||
for(auto n : selected_nodes){
|
||||
// if(n->getNodeType() == NodeType::MIDINODE) copied_nodes.insert(copied_nodes.end(), std::make_shared<MidiNode>(*n));
|
||||
copied_nodes.insert(copied_nodes.end(), std::make_shared<Node>(*n));
|
||||
copied_nodes.back()->deselect();
|
||||
}
|
||||
return copied_nodes;
|
||||
}
|
||||
|
||||
SPTR_Node copyNode(SPTR_Node n, Vec2Df position){
|
||||
std::cout << "copy basenode" << std::endl;
|
||||
nodes.insert(nodes.end(), std::make_shared<Node>(*n));
|
||||
@@ -197,11 +215,11 @@ namespace VISEQ::GRAPH {
|
||||
}
|
||||
|
||||
if(current.lock()->distributionMode == Distribution::ROUNDROBIN){
|
||||
if(counter.find(current) == counter.end()) {
|
||||
counter[current] = 0;
|
||||
if(counter.find(current.lock()) == counter.end()) {
|
||||
counter[current.lock()] = 0;
|
||||
} else {
|
||||
counter[current] = (counter[current] + 1) % possible_connections.size();
|
||||
return_path = counter[current];
|
||||
counter[current.lock()] = (counter[current.lock()] + 1) % possible_connections.size();
|
||||
return_path = counter[current.lock()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,13 +449,19 @@ namespace VISEQ::GRAPH {
|
||||
}
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const GraphManager& G){
|
||||
j = json{{"nodes", G.nodes}, {"edges", G.edges}};
|
||||
void drawNodeUI(){
|
||||
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, GraphManager& G){
|
||||
j.at("nodes").template get_to<VEC_SPTR_Node>(G.nodes);
|
||||
}
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges)
|
||||
|
||||
/*inline void to_json(json& j, const GraphManager& G){*/
|
||||
/* j = json{{"nodes", G.nodes}, {"edges", G.edges}};*/
|
||||
/*}*/
|
||||
/**/
|
||||
/*inline void from_json(const json& j, GraphManager& G){*/
|
||||
/* j.at("nodes").template get_to<VEC_SPTR_Node>(G.nodes);*/
|
||||
/*}*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user