[Bf-blender-cvs] [ceca20b7984] functions: color exported dot clusters randomly

Jacques Lucke noreply at git.blender.org
Tue Nov 26 17:52:35 CET 2019


Commit: ceca20b7984decd04160c26a03e1535313682338
Author: Jacques Lucke
Date:   Tue Nov 26 17:52:29 2019 +0100
Branches: functions
https://developer.blender.org/rBceca20b7984decd04160c26a03e1535313682338

color exported dot clusters randomly

===================================================================

M	source/blender/blenkernel/intern/inlined_node_tree.cc
M	source/blender/blenlib/BLI_dot_export.h
M	source/blender/blenlib/intern/dot_export.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/inlined_node_tree.cc b/source/blender/blenkernel/intern/inlined_node_tree.cc
index a92ed9a22ad..5fa1253110d 100644
--- a/source/blender/blenkernel/intern/inlined_node_tree.cc
+++ b/source/blender/blenkernel/intern/inlined_node_tree.cc
@@ -384,6 +384,8 @@ std::string InlinedNodeTree::to_dot() const
 
   for (const XNode *xnode : m_node_by_id) {
     auto &dot_node = digraph.new_node("");
+    dot_node.set_attribute("bgcolor", "white");
+    dot_node.set_attribute("style", "filled");
 
     Vector<std::string> input_names;
     for (const XInputSocket *input : xnode->inputs()) {
@@ -406,6 +408,9 @@ std::string InlinedNodeTree::to_dot() const
       for (const XGroupInput *group_input : input->linked_group_inputs()) {
         if (!dot_group_inputs.contains(group_input)) {
           auto &dot_group_input_node = digraph.new_node("");
+          dot_group_input_node.set_attribute("bgcolor", "white");
+          dot_group_input_node.set_attribute("style", "filled");
+
           dot_group_inputs.add_new(group_input,
                                    BLI::DotExport::Utils::NodeWithSocketsWrapper(
                                        dot_group_input_node, "Group Input", {}, {"Value"}));
@@ -439,6 +444,7 @@ std::string InlinedNodeTree::to_dot() const
     }
   }
 
+  digraph.set_random_cluster_bgcolors();
   return digraph.to_dot_string();
 }
 
diff --git a/source/blender/blenlib/BLI_dot_export.h b/source/blender/blenlib/BLI_dot_export.h
index 146edcefc4c..d0fa5b6fe82 100644
--- a/source/blender/blenlib/BLI_dot_export.h
+++ b/source/blender/blenlib/BLI_dot_export.h
@@ -72,6 +72,8 @@ class Graph {
   {
     this->set_attribute("rankdir", Attr_rankdir::to_string(rankdir));
   }
+
+  void set_random_cluster_bgcolors();
 };
 
 class Cluster {
@@ -102,6 +104,8 @@ class Cluster {
   {
     this->set_parent_cluster(&cluster);
   }
+
+  void set_random_cluster_bgcolors();
 };
 
 class Node {
@@ -234,6 +238,8 @@ class UndirectedEdge : public Edge {
 
 namespace Utils {
 
+std::string color_attr_from_hsv(float h, float s, float v);
+
 class NodeWithSocketsWrapper {
  private:
   Node *m_node;
diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc
index be029e2e2b0..372fc8d1950 100644
--- a/source/blender/blenlib/intern/dot_export.cc
+++ b/source/blender/blenlib/intern/dot_export.cc
@@ -1,3 +1,5 @@
+#include <iomanip>
+
 #include "BLI_dot_export.h"
 
 namespace BLI {
@@ -78,6 +80,28 @@ void Node::set_parent_cluster(Cluster *cluster)
   m_cluster = cluster;
 }
 
+/* Utility methods
+ **********************************************/
+
+void Graph::set_random_cluster_bgcolors()
+{
+  for (Cluster *cluster : m_top_level_clusters) {
+    cluster->set_random_cluster_bgcolors();
+  }
+}
+
+void Cluster::set_random_cluster_bgcolors()
+{
+  float hue = rand() / (float)RAND_MAX;
+  float staturation = 0.3f;
+  float value = 0.8f;
+  this->set_attribute("bgcolor", Utils::color_attr_from_hsv(hue, staturation, value));
+
+  for (Cluster *cluster : m_children) {
+    cluster->set_random_cluster_bgcolors();
+  }
+}
+
 /* Dot Generation
  **********************************************/
 
@@ -203,6 +227,13 @@ void NodePort::to_dot_string(std::stringstream &ss) const
 
 namespace Utils {
 
+std::string color_attr_from_hsv(float h, float s, float v)
+{
+  std::stringstream ss;
+  ss << std::setprecision(4) << h << ' ' << s << ' ' << v;
+  return ss.str();
+}
+
 NodeWithSocketsWrapper::NodeWithSocketsWrapper(Node &node,
                                                StringRef name,
                                                ArrayRef<std::string> input_names,



More information about the Bf-blender-cvs mailing list