[Bf-blender-cvs] [95fb3dc5ca4] master: Depsgraph: refactor dot exporter to use utility library from blenlib
Jacques Lucke
noreply at git.blender.org
Thu Aug 6 12:40:48 CEST 2020
Commit: 95fb3dc5ca4a0522a82a92fc103e2937d3fa541f
Author: Jacques Lucke
Date: Thu Aug 6 12:40:37 2020 +0200
Branches: master
https://developer.blender.org/rB95fb3dc5ca4a0522a82a92fc103e2937d3fa541f
Depsgraph: refactor dot exporter to use utility library from blenlib
Reviewers: sybren, sergey
Differential Revision: https://developer.blender.org/D8473
===================================================================
M source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
===================================================================
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
index 458baf4fb1e..d0356f44022 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
@@ -25,6 +25,7 @@
#include <cstdarg>
+#include "BLI_dot_export.hh"
#include "BLI_utildefines.h"
#include "DNA_listBase.h"
@@ -41,6 +42,7 @@
#include "intern/node/deg_node_time.h"
namespace deg = blender::deg;
+namespace dot = blender::dot;
/* ****************** */
/* Graphviz Debugging */
@@ -48,8 +50,6 @@ namespace deg = blender::deg;
namespace blender {
namespace deg {
-#define NL "\r\n"
-
/* Only one should be enabled, defines whether graphviz nodes
* get colored by individual types or classes.
*/
@@ -158,47 +158,43 @@ static int deg_debug_node_color_index(const Node *node)
#endif
}
-struct DebugContext {
- FILE *file;
+struct DotExportContext {
bool show_tags;
+ dot::DirectedGraph &digraph;
+ Map<const Node *, dot::Node *> nodes_map;
+ Map<const Node *, dot::Cluster *> clusters_map;
};
-static void deg_debug_fprintf(const DebugContext &ctx, const char *fmt, ...)
- ATTR_PRINTF_FORMAT(2, 3);
-static void deg_debug_fprintf(const DebugContext &ctx, const char *fmt, ...)
+static void deg_debug_graphviz_legend_color(const char *name,
+ const char *color,
+ std::stringstream &ss)
{
- va_list args;
- va_start(args, fmt);
- vfprintf(ctx.file, fmt, args);
- va_end(args);
-}
-static void deg_debug_graphviz_legend_color(const DebugContext &ctx,
- const char *name,
- const char *color)
-{
- deg_debug_fprintf(ctx, "<TR>");
- deg_debug_fprintf(ctx, "<TD>%s</TD>", name);
- deg_debug_fprintf(ctx, "<TD BGCOLOR=\"%s\"></TD>", color);
- deg_debug_fprintf(ctx, "</TR>" NL);
+ ss << "<TR>";
+ ss << "<TD>" << name << "</TD>";
+ ss << "<TD BGCOLOR=\"" << color << "\"></TD>";
+ ss << "</TR>";
}
-static void deg_debug_graphviz_legend(const DebugContext &ctx)
+static void deg_debug_graphviz_legend(DotExportContext &ctx)
{
- deg_debug_fprintf(ctx, "{" NL);
- deg_debug_fprintf(ctx, "rank = sink;" NL);
- deg_debug_fprintf(ctx, "Legend [shape=none, margin=0, label=<" NL);
- deg_debug_fprintf(
- ctx, " <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">" NL);
- deg_debug_fprintf(ctx, "<TR><TD COLSPAN=\"2\"><B>Legend</B></TD></TR>" NL);
+ dot::Node &legend_node = ctx.digraph.new_node("");
+ legend_node.attributes.set("rank", "sink");
+ legend_node.attributes.set("shape", "none");
+ legend_node.attributes.set("margin", 0);
+
+ std::stringstream ss;
+ ss << "<";
+ ss << "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">";
+ ss << "<TR><TD COLSPAN=\"2\"><B>Legend</B></TD></TR>";
#ifdef COLOR_SCHEME_NODE_CLASS
const char **colors = deg_debug_colors_light;
- deg_debug_graphviz_legend_color(ctx, "Operation", colors[4]);
- deg_debug_graphviz_legend_color(ctx, "Component", colors[1]);
- deg_debug_graphviz_legend_color(ctx, "ID Node", colors[5]);
- deg_debug_graphviz_legend_color(ctx, "NOOP", colors[8]);
- deg_debug_graphviz_legend_color(ctx, "Pinned OP", colors[7]);
+ deg_debug_graphviz_legend_color("Operation", colors[4], ss);
+ deg_debug_graphviz_legend_color("Component", colors[1], ss);
+ deg_debug_graphviz_legend_color("ID Node", colors[5], ss);
+ deg_debug_graphviz_legend_color("NOOP", colors[8], ss);
+ deg_debug_graphviz_legend_color("Pinned OP", colors[7], ss);
#endif
#ifdef COLOR_SCHEME_NODE_TYPE
@@ -206,18 +202,19 @@ static void deg_debug_graphviz_legend(const DebugContext &ctx)
for (pair = deg_debug_node_type_color_map; (*pair)[0] >= 0; pair++) {
DepsNodeFactory *nti = type_get_factory((NodeType)(*pair)[0]);
deg_debug_graphviz_legend_color(
- ctx, nti->tname().c_str(), deg_debug_colors_light[(*pair)[1] % deg_debug_max_colors]);
+ ctx, nti->tname().c_str(), deg_debug_colors_light[(*pair)[1] % deg_debug_max_colors], ss);
}
#endif
- deg_debug_fprintf(ctx, "</TABLE>" NL);
- deg_debug_fprintf(ctx, ">" NL);
- deg_debug_fprintf(ctx, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
- deg_debug_fprintf(ctx, "];" NL);
- deg_debug_fprintf(ctx, "}" NL);
+ ss << "</TABLE>";
+ ss << ">";
+ legend_node.attributes.set("label", ss.str());
+ legend_node.attributes.set("fontname", deg_debug_graphviz_fontname);
}
-static void deg_debug_graphviz_node_color(const DebugContext &ctx, const Node *node)
+static void deg_debug_graphviz_node_color(DotExportContext &ctx,
+ const Node *node,
+ dot::Attributes &dot_attributes)
{
const char *color_default = "black";
const char *color_modified = "orangered4";
@@ -234,10 +231,12 @@ static void deg_debug_graphviz_node_color(const DebugContext &ctx, const Node *n
}
}
}
- deg_debug_fprintf(ctx, "\"%s\"", color);
+ dot_attributes.set("color", color);
}
-static void deg_debug_graphviz_node_penwidth(const DebugContext &ctx, const Node *node)
+static void deg_debug_graphviz_node_penwidth(DotExportContext &ctx,
+ const Node *node,
+ dot::Attributes &dot_attributes)
{
float penwidth_default = 1.0f;
float penwidth_modified = 4.0f;
@@ -254,20 +253,20 @@ static void deg_debug_graphviz_node_penwidth(const DebugContext &ctx, const Node
}
}
}
- deg_debug_fprintf(ctx, "\"%f\"", penwidth);
+ dot_attributes.set("penwidth", penwidth);
}
-static void deg_debug_graphviz_node_fillcolor(const DebugContext &ctx, const Node *node)
+static void deg_debug_graphviz_node_fillcolor(const Node *node, dot::Attributes &dot_attributes)
{
const char *defaultcolor = "gainsboro";
int color_index = deg_debug_node_color_index(node);
const char *fillcolor = color_index < 0 ?
defaultcolor :
deg_debug_colors_light[color_index % deg_debug_max_colors];
- deg_debug_fprintf(ctx, "\"%s\"", fillcolor);
+ dot_attributes.set("fillcolor", fillcolor);
}
-static void deg_debug_graphviz_relation_color(const DebugContext &ctx, const Relation *rel)
+static void deg_debug_graphviz_relation_color(const Relation *rel, dot::DirectedEdge &edge)
{
const char *color_default = "black";
const char *color_cyclic = "red4"; /* The color of crime scene. */
@@ -279,10 +278,10 @@ static void deg_debug_graphviz_relation_color(const DebugContext &ctx, const Rel
else if (rel->flag & RELATION_FLAG_GODMODE) {
color = color_godmode;
}
- deg_debug_fprintf(ctx, "%s", color);
+ edge.attributes.set("color", color);
}
-static void deg_debug_graphviz_relation_style(const DebugContext &ctx, const Relation *rel)
+static void deg_debug_graphviz_relation_style(const Relation *rel, dot::DirectedEdge &edge)
{
const char *style_default = "solid";
const char *style_no_flush = "dashed";
@@ -294,10 +293,10 @@ static void deg_debug_graphviz_relation_style(const DebugContext &ctx, const Rel
if (rel->flag & RELATION_FLAG_FLUSH_USER_EDIT_ONLY) {
style = style_flush_user_only;
}
- deg_debug_fprintf(ctx, "%s", style);
+ edge.attributes.set("style", style);
}
-static void deg_debug_graphviz_relation_arrowhead(const DebugContext &ctx, const Relation *rel)
+static void deg_debug_graphviz_relation_arrowhead(const Relation *rel, dot::DirectedEdge &edge)
{
const char *shape_default = "normal";
const char *shape_no_cow = "box";
@@ -311,12 +310,14 @@ static void deg_debug_graphviz_relation_arrowhead(const DebugContext &ctx, const
shape = shape_no_cow;
}
}
- deg_debug_fprintf(ctx, "%s", shape);
+ edge.attributes.set("arrowhead", shape);
}
-static void deg_debug_graphviz_node_style(const DebugContext &ctx, const Node *node)
+static void deg_debug_graphviz_node_style(DotExportContext &ctx,
+ const Node *node,
+ dot::Attributes &dot_attributes)
{
- const char *base_style = "filled"; /* default style */
+ StringRef base_style = "filled"; /* default style */
if (ctx.show_tags) {
if (node->get_class() == NodeClass::OPERATION) {
OperationNode *op_node = (OperationNode *)node;
@@ -327,95 +328,78 @@ static void deg_debug_graphviz_node_style(const DebugContext &ctx, const Node *n
}
switch (node->get_class()) {
case NodeClass::GENERIC:
- deg_debug_fprintf(ctx, "\"%s\"", base_style);
+ dot_attributes.set("style", base_style);
break;
case NodeClass::COMPONENT:
- deg_debug_fprintf(ctx, "\"%s\"", base_style);
+ dot_attributes.set("style", base_style);
break;
case NodeClass::OPERATION:
- deg_debug_fprintf(ctx, "\"%s,rounded\"", base_style);
+ dot_attributes.set("style", base_style + ",rounded");
break;
}
}
-static void deg_debug_graphviz_node_single(const DebugContext &ctx, const Node *node)
+static void deg_debug_graphviz_node_single(DotExportContext &ctx,
+ const Node *node,
+ dot::Cluster *parent_cluster)
{
- const char *shape = "box";
string name = node->identifier();
- deg_debug_fprintf(ctx, "// %s\n", name.c_str());
- deg_debug_fprintf(ctx, "\"node_%p\"", node);
- deg_debug_fprintf(ctx, "[");
- // deg_debug_fprintf(ctx, "label=<<B>%s</B>>", name);
- deg_debug_fprintf(ctx, "label=<%s>", name.c_str());
- deg_debug_fprintf(ctx, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
- deg_debug_fprintf(ctx, ",fontsize=%f", deg_debug_graphviz_node_label_size);
- deg_debug_fprintf(ctx, ",shape=%s", shape);
- deg_debug_fprintf(ctx, ",style=");
- deg_debug_graphviz_node_style(ctx, node);
- deg_debug_fprintf(ctx, ",color=");
- deg_debug_graphviz_node_color(ctx, node);
- deg_debug_fprintf(ctx, ",fillcolor=");
- deg_debug_graphviz_node_fillcolor
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list