Blender V5.0
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
5#include "BKE_node_runtime.hh"
7
8#include "BLI_dot_export.hh"
9
10namespace blender::bke {
11
12std::string bNodeTreeToDotOptions::socket_name(const bNodeSocket &socket) const
13{
14 return socket.identifier;
15}
16
18 const bNodeSocket &socket) const
19{
20 if (!socket.is_available()) {
21 return "#999999";
22 }
23 return std::nullopt;
24}
25
27 dot_export::DirectedEdge &dot_edge) const
28{
29 if (!link.is_used()) {
30 dot_edge.attributes.set("color", "#999999");
31 }
32}
33
35{
36 namespace dot = blender::dot_export;
37 tree.ensure_topology_cache();
38
41
43
44 for (const bNode *node : tree.all_nodes()) {
45 dot_export::Node &dot_node = digraph.new_node("");
46 dot_export::NodeWithSockets dot_node_with_sockets;
47 dot_node_with_sockets.node_name = node->label_or_name();
48 for (const bNodeSocket *socket : node->input_sockets()) {
49 dot_export::NodeWithSockets::Input &dot_input = dot_node_with_sockets.add_input(
50 options.socket_name(*socket));
51 dot_input.fontcolor = options.socket_font_color(*socket);
52 }
53 for (const bNodeSocket *socket : node->output_sockets()) {
54 dot_export::NodeWithSockets::Output &dot_output = dot_node_with_sockets.add_output(
55 options.socket_name(*socket));
56 dot_output.fontcolor = options.socket_font_color(*socket);
57 }
58 dot_nodes.add_new(node, dot_export::NodeWithSocketsRef(dot_node, dot_node_with_sockets));
59 }
60
61 for (const bNodeLink *link : tree.all_links()) {
62 const dot_export::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(link->fromnode);
63 const dot_export::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(link->tonode);
64 const dot_export::NodePort from_dot_port = from_dot_node.output(link->fromsock->index());
65 const dot_export::NodePort to_dot_port = to_dot_node.input(link->tosock->index());
66
67 dot_export::DirectedEdge &dot_edge = digraph.new_edge(from_dot_port, to_dot_port);
68 options.add_edge_attributes(*link, dot_edge);
69 }
70
71 return digraph.to_dot_string();
72}
73
74} // 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:45
void set_rankdir(Attr_rankdir rankdir)
Node & new_node(StringRef label)
Definition dot_export.cc:20
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
CCL_NAMESPACE_BEGIN struct Options options
KDTree_3d * tree
std::string node_tree_to_dot(const bNodeTree &tree, const bNodeTreeToDotOptions &options=bNodeTreeToDotOptions())
char identifier[64]
Input & add_input(std::string name)
Output & add_output(std::string name)