[Bf-blender-cvs] [c0d0aff4da9] functions: import dot export
Jacques Lucke
noreply at git.blender.org
Sun Nov 24 14:59:20 CET 2019
Commit: c0d0aff4da9caefff5d738d1e10c221ea61a9e0e
Author: Jacques Lucke
Date: Sun Nov 24 13:56:34 2019 +0100
Branches: functions
https://developer.blender.org/rBc0d0aff4da9caefff5d738d1e10c221ea61a9e0e
import dot export
===================================================================
M source/blender/blenlib/BLI_dot_export.h
A source/blender/blenlib/BLI_dot_export_attribute_enums.h
M source/blender/blenlib/CMakeLists.txt
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 73c5639408a..8ba4d3b14c5 100644
--- a/source/blender/blenlib/BLI_dot_export.h
+++ b/source/blender/blenlib/BLI_dot_export.h
@@ -14,6 +14,8 @@
#include "BLI_map.h"
#include "BLI_utility_mixins.h"
+#include "BLI_dot_export_attribute_enums.h"
+
#include <sstream>
namespace BLI {
@@ -44,6 +46,7 @@ class AttributeList {
class Graph {
private:
+ AttributeList m_attributes;
Vector<std::unique_ptr<Node>> m_nodes;
Vector<std::unique_ptr<Cluster>> m_clusters;
@@ -54,6 +57,16 @@ class Graph {
Cluster &new_cluster();
void export__declare_nodes_and_clusters(std::stringstream &ss) const;
+
+ void set_attribute(StringRef key, StringRef value)
+ {
+ m_attributes.set(key, value);
+ }
+
+ void set_rankdir(Attr_rankdir::Enum rankdir)
+ {
+ this->set_attribute("rankdir", Attr_rankdir::to_string(rankdir));
+ }
};
class UndirectedGraph final : public Graph {
@@ -130,6 +143,21 @@ class Edge : BLI::NonCopyable, BLI::NonMovable {
{
m_attributes.set(key, value);
}
+
+ void set_arrowhead(Attr_arrowType::Enum type)
+ {
+ this->set_attribute("arrowhead", Attr_arrowType::to_string(type));
+ }
+
+ void set_arrowtail(Attr_arrowType::Enum type)
+ {
+ this->set_attribute("arrowtail", Attr_arrowType::to_string(type));
+ }
+
+ void set_dir(Attr_dirType::Enum type)
+ {
+ this->set_attribute("dir", Attr_dirType::to_string(type));
+ }
};
class DirectedEdge : public Edge {
@@ -170,6 +198,11 @@ class Node {
m_attributes.set(key, value);
}
+ void set_shape(Attr_shape::Enum shape)
+ {
+ this->set_attribute("shape", Attr_shape::to_string(shape));
+ }
+
void export__as_id(std::stringstream &ss) const;
void export__as_declaration(std::stringstream &ss) const;
diff --git a/source/blender/blenlib/BLI_dot_export_attribute_enums.h b/source/blender/blenlib/BLI_dot_export_attribute_enums.h
new file mode 100644
index 00000000000..3e7f1d7623d
--- /dev/null
+++ b/source/blender/blenlib/BLI_dot_export_attribute_enums.h
@@ -0,0 +1,112 @@
+#ifndef __BLI_DOT_EXPORT_ATTRIBUTE_ENUMS_H__
+#define __BLI_DOT_EXPORT_ATTRIBUTE_ENUMS_H__
+
+#include "BLI_string_ref.h"
+
+namespace BLI {
+namespace DotExport {
+
+namespace Attr_rankdir {
+enum Enum {
+ LeftToRight,
+ TopToBottom,
+};
+
+static StringRef to_string(Enum value)
+{
+ switch (value) {
+ case LeftToRight:
+ return "LR";
+ case TopToBottom:
+ return "TB";
+ }
+ return "";
+}
+} // namespace Attr_rankdir
+
+namespace Attr_shape {
+enum Enum {
+ Rectangle,
+ Ellipse,
+ Circle,
+ Point,
+ Diamond,
+ Square,
+};
+
+static StringRef to_string(Enum value)
+{
+ switch (value) {
+ case Rectangle:
+ return "rectangle";
+ case Ellipse:
+ return "ellipse";
+ case Circle:
+ return "circle";
+ case Point:
+ return "point";
+ case Diamond:
+ return "diamond";
+ case Square:
+ return "square";
+ }
+ return "";
+}
+} // namespace Attr_shape
+
+namespace Attr_arrowType {
+enum Enum {
+ Normal,
+ Inv,
+ Dot,
+ None,
+ Empty,
+ Box,
+ Vee,
+};
+
+static StringRef to_string(Enum value)
+{
+ switch (value) {
+ case Normal:
+ return "normal";
+ case Inv:
+ return "inv";
+ case Dot:
+ return "dot";
+ case None:
+ return "none";
+ case Empty:
+ return "empty";
+ case Box:
+ return "box";
+ case Vee:
+ return "vee";
+ }
+ return "";
+}
+} // namespace Attr_arrowType
+
+namespace Attr_dirType {
+enum Enum { Forward, Back, Both, None };
+
+static StringRef to_string(Enum value)
+{
+ switch (value) {
+ case Forward:
+ return "forward";
+ case Back:
+ return "back";
+ case Both:
+ return "both";
+ case None:
+ return "none";
+ }
+ return "";
+}
+} // namespace Attr_dirType
+
+} // namespace DotExport
+} // namespace BLI
+
+#endif /* __BLI_DOT_EXPORT_ATTRIBUTE_ENUMS_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index b10f513c471..629058d67ca 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -256,6 +256,7 @@ set(SRC
PIL_time_utildefines.h
BLI_dot_export.h
+ BLI_dot_export_attribute_enums.h
intern/dot_export.cc
BLI_chained_strings.h
BLI_lazy_init.h
diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc
index 5cc8c5263f0..c79d7e4a010 100644
--- a/source/blender/blenlib/intern/dot_export.cc
+++ b/source/blender/blenlib/intern/dot_export.cc
@@ -37,6 +37,10 @@ std::string UndirectedGraph::to_dot_string() const
void Graph::export__declare_nodes_and_clusters(std::stringstream &ss) const
{
+ ss << "graph ";
+ m_attributes.export__as_bracket_list(ss);
+ ss << "\n\n";
+
for (auto &node : m_nodes) {
node->export__as_declaration(ss);
}
@@ -202,7 +206,7 @@ NodeWithSocketsWrapper::NodeWithSocketsWrapper(Node &node,
ss << "</table>>";
m_node->set_attribute("label", ss.str());
- m_node->set_attribute("shape", "box");
+ m_node->set_shape(Attr_shape::Rectangle);
}
} // namespace Utils
More information about the Bf-blender-cvs
mailing list