Commit: 8ae3debad08d91b0e23e7be1c9615c5dbaa512bc Author: Jacques Lucke Date: Sun Nov 24 13:30:28 2019 +0100 Branches: functions https://developer.blender.org/rB8ae3debad08d91b0e23e7be1c9615c5dbaa512bc
node shape utility =================================================================== M source/blender/blenlib/BLI_dot_export.h M source/blender/blenlib/intern/dot_export.cc =================================================================== diff --git a/source/blender/blenlib/BLI_dot_export.h b/source/blender/blenlib/BLI_dot_export.h index 973962f44c3..73c5639408a 100644 --- a/source/blender/blenlib/BLI_dot_export.h +++ b/source/blender/blenlib/BLI_dot_export.h @@ -1,6 +1,13 @@ #ifndef __BLI_DOT_EXPORT_H__ #define __BLI_DOT_EXPORT_H__ +/** + * Language grammar: https://www.graphviz.org/doc/info/lang.html + * Attributes: https://www.graphviz.org/doc/info/attrs.html + * Node Shapes: https://www.graphviz.org/doc/info/shapes.html + * Preview: https://dreampuf.github.io/GraphvizOnline + */ + #include "BLI_vector.h" #include "BLI_optional.h" #include "BLI_string_map.h" @@ -168,6 +175,33 @@ class Node { void export__as_declaration(std::stringstream &ss) const; }; +namespace Utils { + +class NodeWithSocketsWrapper { + private: + Node *m_node; + + public: + NodeWithSocketsWrapper(Node &node, + StringRef name, + ArrayRef<std::string> input_names, + ArrayRef<std::string> output_names); + + NodePort input(uint index) const + { + std::string port = "\"in" + std::to_string(index) + "\""; + return NodePort(*m_node, port); + } + + NodePort output(uint index) const + { + std::string port = "\"out" + std::to_string(index) + "\""; + return NodePort(*m_node, port); + } +}; + +} // namespace Utils + } // namespace DotExport } // namespace BLI diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc index 5f7907c85b1..5cc8c5263f0 100644 --- a/source/blender/blenlib/intern/dot_export.cc +++ b/source/blender/blenlib/intern/dot_export.cc @@ -87,7 +87,13 @@ void AttributeList::export__as_bracket_list(std::stringstream &ss) const { ss << "["; for (auto item : m_attributes.items()) { - ss << item.key << "=\"" << item.value << "\", "; + if (StringRef(item.value).startswith("<")) { + /* Don't draw the quotes, this is an html-like value. */ + ss << item.key << "=" << item.value << ", "; + } + else { + ss << item.key << "=\"" << item.value << "\", "; + } } ss << "]"; } @@ -150,5 +156,56 @@ void NodePort::to_dot_string(std::stringstream &ss) const } } +namespace Utils { + +NodeWithSocketsWrapper::NodeWithSocketsWrapper(Node &node, + StringRef name, + ArrayRef<std::string> input_names, + ArrayRef<std::string> output_names) + : m_node(&node) +{ + std::stringstream ss; + + ss << "<<table border=\"0\" cellspacing=\"3\">"; + + /* Header */ + ss << "<tr><td colspan=\"3\" align=\"center\"><b>"; + ss << name; + ss << "</b></td></tr>"; + + /* Sockets */ + uint socket_max_amount = std::max(input_names.size(), output_names.size()); + for (uint i = 0; i < socket_max_amount; i++) { + ss << "<tr>"; + if (i < input_names.size()) { + StringRef name = input_names[i]; + ss << "<td align=\"left\" port=\"in" << i << "\">"; + ss << name; + ss << "</td>"; + } + else { + ss << "<td></td>"; + } + ss << "<td></td>"; + if (i < output_names.size()) { + StringRef name = output_names[i]; + ss << "<td align=\"right\" port=\"out" << i << "\">"; + ss << name; + ss << "</td>"; + } + else { + ss << "<td></td>"; + } + ss << "</tr>"; + } + + ss << "</table>>"; + + m_node->set_attribute("label", ss.str()); + m_node->set_attribute("shape", "box"); +} + +} // namespace Utils + } // namespace DotExport } // namespace BLI _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
