BLI: improve node graph export in dot format
This makes it bit easier to export node graphs and also allows for more customization of links and sockets.
This commit is contained in:
@@ -152,7 +152,23 @@ std::string DummyDebugInfo::output_name(const int /*i*/) const
|
||||
return fallback_name;
|
||||
}
|
||||
|
||||
std::string Graph::to_dot() const
|
||||
std::string Graph::ToDotOptions::socket_name(const Socket &socket) const
|
||||
{
|
||||
return socket.name();
|
||||
}
|
||||
|
||||
std::optional<std::string> Graph::ToDotOptions::socket_font_color(const Socket & /*socket*/) const
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void Graph::ToDotOptions::add_edge_attributes(const OutputSocket & /*from*/,
|
||||
const InputSocket & /*to*/,
|
||||
dot::DirectedEdge & /*dot_edge*/) const
|
||||
{
|
||||
}
|
||||
|
||||
std::string Graph::to_dot(const ToDotOptions &options) const
|
||||
{
|
||||
dot::DirectedGraph digraph;
|
||||
digraph.set_rankdir(dot::Attr_rankdir::LeftToRight);
|
||||
@@ -168,17 +184,20 @@ std::string Graph::to_dot() const
|
||||
dot_node.set_background_color("white");
|
||||
}
|
||||
|
||||
Vector<std::string> input_names;
|
||||
Vector<std::string> output_names;
|
||||
dot::NodeWithSockets dot_node_with_sockets;
|
||||
dot_node_with_sockets.node_name = node->name();
|
||||
for (const InputSocket *socket : node->inputs()) {
|
||||
input_names.append(socket->name());
|
||||
dot::NodeWithSockets::Input &dot_input = dot_node_with_sockets.add_input(
|
||||
options.socket_name(*socket));
|
||||
dot_input.fontcolor = options.socket_font_color(*socket);
|
||||
}
|
||||
for (const OutputSocket *socket : node->outputs()) {
|
||||
output_names.append(socket->name());
|
||||
dot::NodeWithSockets::Output &dot_output = dot_node_with_sockets.add_output(
|
||||
options.socket_name(*socket));
|
||||
dot_output.fontcolor = options.socket_font_color(*socket);
|
||||
}
|
||||
|
||||
dot_nodes.add_new(node,
|
||||
dot::NodeWithSocketsRef(dot_node, node->name(), input_names, output_names));
|
||||
dot_nodes.add_new(node, dot::NodeWithSocketsRef(dot_node, dot_node_with_sockets));
|
||||
}
|
||||
|
||||
for (const Node *node : nodes_) {
|
||||
@@ -188,7 +207,9 @@ std::string Graph::to_dot() const
|
||||
|
||||
if (const OutputSocket *origin = socket->origin()) {
|
||||
dot::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(&origin->node());
|
||||
digraph.new_edge(from_dot_node.output(origin->index()), to_dot_port);
|
||||
dot::DirectedEdge &dot_edge = digraph.new_edge(from_dot_node.output(origin->index()),
|
||||
to_dot_port);
|
||||
options.add_edge_attributes(*origin, *socket, dot_edge);
|
||||
}
|
||||
else if (const void *default_value = socket->default_value()) {
|
||||
const CPPType &type = socket->type();
|
||||
|
||||
Reference in New Issue
Block a user