Blender V5.3
node_tree_dot_export.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_node_runtime.hh"
11
12#include "BLI_dot_export.hh"
13
14namespace blender::bke {
15
16std::string bNodeTreeToDotOptions::socket_name(const bNodeSocket &socket) const
17{
18 return socket.identifier;
19}
20
22 const bNodeSocket &socket) const
23{
24 if (!socket.is_available()) {
25 return "#999999";
26 }
27 return std::nullopt;
28}
29
31 dot_export::DirectedEdge &dot_edge) const
32{
33 if (!link.is_used()) {
34 dot_edge.attributes.set("color", "#999999");
35 }
36}
37
39{
40 namespace dot = dot_export;
41 tree.ensure_topology_cache();
42
45
47
48 for (const bNode *node : tree.all_nodes()) {
49 dot_export::Node &dot_node = digraph.new_node("");
50 dot_export::NodeWithSockets dot_node_with_sockets;
51 dot_node_with_sockets.node_name = node->label_or_name();
52 for (const bNodeSocket *socket : node->input_sockets()) {
53 dot_export::NodeWithSockets::Input &dot_input = dot_node_with_sockets.add_input(
54 options.socket_name(*socket));
55 dot_input.fontcolor = options.socket_font_color(*socket);
56 }
57 for (const bNodeSocket *socket : node->output_sockets()) {
58 dot_export::NodeWithSockets::Output &dot_output = dot_node_with_sockets.add_output(
59 options.socket_name(*socket));
60 dot_output.fontcolor = options.socket_font_color(*socket);
61 }
62 dot_nodes.add_new(node, dot_export::NodeWithSocketsRef(dot_node, dot_node_with_sockets));
63 }
64
65 for (const bNodeLink *link : tree.all_links()) {
66 const dot_export::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(link->fromnode);
67 const dot_export::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(link->tonode);
68 const dot_export::NodePort from_dot_port = from_dot_node.output(link->fromsock->index());
69 const dot_export::NodePort to_dot_port = to_dot_node.input(link->tosock->index());
70
71 dot_export::DirectedEdge &dot_edge = digraph.new_edge(from_dot_port, to_dot_port);
72 options.add_edge_attributes(*link, dot_edge);
73 }
74
75 return digraph.to_dot_string();
76}
77
78} // namespace blender::bke
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
virtual std::string socket_name(const bNodeSocket &socket) const
virtual std::optional< std::string > socket_font_color(const bNodeSocket &socket) const
virtual void add_edge_attributes(const bNodeLink &link, dot_export::DirectedEdge &dot_edge) const
void set(StringRef key, StringRef value)
std::string to_dot_string() const
DirectedEdge & new_edge(NodePort from, NodePort to)
Definition dot_export.cc:46
void set_rankdir(Attr_rankdir rankdir)
Node & new_node(StringRef label)
Definition dot_export.cc:21
CCL_NAMESPACE_BEGIN struct Options options
float dot(VecOp< float, D >, VecOp< float, D >) RET
std::string node_tree_to_dot(const bNodeTree &tree, const bNodeTreeToDotOptions &options=bNodeTreeToDotOptions())
Input & add_input(std::string name)
Output & add_output(std::string name)