diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-05 16:30:22 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-05 16:30:22 +0300 |
commit | 40ad9890599ed17bccb2be98e48322271c2c407e (patch) | |
tree | 54dcaf57c80c3f0a0e1b69e78d8b1281f002a6eb /source/blender/blenlib/intern | |
parent | 754a663f6812e504585b07831e7dbc5a7505eced (diff) |
BLI: improve dot exporter interface
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/dot_export.cc | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc index 48b6dc826d0..8e4aafa4bb8 100644 --- a/source/blender/blenlib/intern/dot_export.cc +++ b/source/blender/blenlib/intern/dot_export.cc @@ -28,7 +28,7 @@ Node &Graph::new_node(StringRef label) Node *node = new Node(*this); nodes_.append(std::unique_ptr<Node>(node)); top_level_nodes_.add_new(node); - node->set_attribute("label", label); + node->attributes.set("label", label); return *node; } @@ -37,7 +37,7 @@ Cluster &Graph::new_cluster(StringRef label) Cluster *cluster = new Cluster(*this); clusters_.append(std::unique_ptr<Cluster>(cluster)); top_level_clusters_.add_new(cluster); - cluster->set_attribute("label", label); + cluster->attributes.set("label", label); return *cluster; } @@ -110,13 +110,25 @@ void Cluster::set_random_cluster_bgcolors() float hue = rand() / (float)RAND_MAX; float staturation = 0.3f; float value = 0.8f; - this->set_attribute("bgcolor", color_attr_from_hsv(hue, staturation, value)); + this->attributes.set("bgcolor", color_attr_from_hsv(hue, staturation, value)); for (Cluster *cluster : children_) { cluster->set_random_cluster_bgcolors(); } } +bool Cluster::contains(Node &node) const +{ + Cluster *current = node.parent_cluster(); + while (current != nullptr) { + if (current == this) { + return true; + } + current = current->parent_; + } + return false; +} + /* Dot Generation **********************************************/ @@ -155,7 +167,7 @@ std::string UndirectedGraph::to_dot_string() const void Graph::export__declare_nodes_and_clusters(std::stringstream &ss) const { ss << "graph "; - attributes_.export__as_bracket_list(ss); + attributes.export__as_bracket_list(ss); ss << "\n\n"; for (Node *node : top_level_nodes_) { @@ -169,10 +181,10 @@ void Graph::export__declare_nodes_and_clusters(std::stringstream &ss) const void Cluster::export__declare_nodes_and_clusters(std::stringstream &ss) const { - ss << "subgraph cluster_" << (uintptr_t)this << " {\n"; + ss << "subgraph " << this->name() << " {\n"; ss << "graph "; - attributes_.export__as_bracket_list(ss); + attributes.export__as_bracket_list(ss); ss << "\n\n"; for (Node *node : nodes_) { @@ -192,7 +204,7 @@ void DirectedEdge::export__as_edge_statement(std::stringstream &ss) const ss << " -> "; b_.to_dot_string(ss); ss << " "; - attributes_.export__as_bracket_list(ss); + attributes.export__as_bracket_list(ss); } void UndirectedEdge::export__as_edge_statement(std::stringstream &ss) const @@ -201,10 +213,10 @@ void UndirectedEdge::export__as_edge_statement(std::stringstream &ss) const ss << " -- "; b_.to_dot_string(ss); ss << " "; - attributes_.export__as_bracket_list(ss); + attributes.export__as_bracket_list(ss); } -void AttributeList::export__as_bracket_list(std::stringstream &ss) const +void Attributes::export__as_bracket_list(std::stringstream &ss) const { ss << "["; attributes_.foreach_item([&](StringRef key, StringRef value) { @@ -228,7 +240,7 @@ void Node::export__as_declaration(std::stringstream &ss) const { this->export__as_id(ss); ss << " "; - attributes_.export__as_bracket_list(ss); + attributes.export__as_bracket_list(ss); ss << "\n"; } @@ -296,7 +308,7 @@ NodeWithSocketsRef::NodeWithSocketsRef(Node &node, ss << "</table>>"; - node_->set_attribute("label", ss.str()); + node_->attributes.set("label", ss.str()); node_->set_shape(Attr_shape::Rectangle); } |