5#ifndef LINE_IO_TIKZ_TIKZ_NODE_RENDERER_H
6#define LINE_IO_TIKZ_TIKZ_NODE_RENDERER_H
35 std::ostringstream sb;
36 sb <<
"\\documentclass[tikz,border=" <<
opt.border_padding <<
"pt]{standalone}\n";
37 sb <<
"\\usepackage{tikz}\n";
38 sb <<
"\\usetikzlibrary{arrows.meta,positioning,shapes.geometric,shapes.misc,calc,"
39 "decorations.pathreplacing}\n";
42 sb <<
" % Queue: Rectangle buffer\n"
46 " minimum width=1.1cm,\n"
47 " minimum height=0.72cm,\n"
50 sb <<
" % Server circle\n"
54 " minimum size=0.6cm,\n"
57 sb <<
" % Delay: Vertical rectangle (infinite server)\n"
61 " minimum width=0.8cm,\n"
62 " minimum height=1.5cm,\n"
65 sb <<
" % Source: Small circle (white)\n"
69 " minimum size=0.3cm,\n"
72 sb <<
" % Sink: Small circle (black)\n"
76 " minimum size=0.3cm,\n"
79 sb <<
" % Fork: Diamond\n"
83 " minimum size=1cm,\n"
87 sb <<
" % Join: Diamond\n"
88 " joinnode/.style={\n"
91 " minimum size=1cm,\n"
95 sb <<
" % Router: Hexagon\n"
98 " regular polygon sides=6,\n"
100 " minimum size=1cm,\n"
103 sb <<
" % ClassSwitch: Trapezium\n"
104 " classswitch/.style={\n"
107 " trapezium left angle=70,\n"
108 " trapezium right angle=110,\n"
109 " minimum width=1.5cm,\n"
110 " minimum height=0.8cm,\n"
113 sb <<
" % Cache: Stacked rectangle\n"
117 " minimum width=1.5cm,\n"
118 " minimum height=1.2cm,\n"
121 sb <<
" % Logger: Rectangle with lines\n"
125 " minimum width=1.2cm,\n"
126 " minimum height=0.8cm,\n"
129 sb <<
" % Place (Petri net): Circle\n"
133 " minimum size=0.8cm,\n"
136 sb <<
" % Transition (Petri net): Rectangle\n"
137 " transition/.style={\n"
140 " minimum width=0.2cm,\n"
141 " minimum height=1cm,\n"
144 sb <<
" % Connection arrow\n"
150 sb <<
" % Probability label\n"
151 " problabel/.style={\n"
152 " font=\\footnotesize,\n"
157 sb <<
" % Node name label\n"
158 " nodelabel/.style={\n"
165namespace tikz_detail {
168inline std::string
styled_node(
const std::string& style,
const std::string&
id,
double x,
double y,
170 std::string s =
"\\node[" + style +
"] (" +
id +
") at (" +
java_fixed(x, 2) +
"," +
172 if (
opt.show_node_names)
173 s +=
"\\node[nodelabel,above=2pt of " +
id +
"] {" +
escape_latex(nd.
name) +
"};\n";
179 if (std::isinf(c) || c >= 2147483647.0)
return "$\\infty$";
180 std::ostringstream o;
181 o << static_cast<long long>(c);
194 case NodeType::Delay:
195 return styled_node(
"delay",
id, x, y,
"$\\infty$", nd,
opt);
196 case NodeType::Queue:
197 s = styled_node(
"queue",
id, x, y,
"", nd,
opt);
198 if (
opt.show_scheduling && !nd.
sched.empty())
199 s +=
"\\node[font=\\tiny,below=2pt of " +
id +
"] {" + nd.
sched +
"};\n";
200 if (
opt.show_server_count)
201 s +=
"\\node[server,anchor=west] (" +
id +
"_server) at (" +
id +
".east) {" +
204 case NodeType::Source:
205 s = styled_node(
"source",
id, x, y,
"", nd,
opt);
206 s +=
"\\draw[conn] ([xshift=-0.6cm]" +
id +
".west) -- (" +
id +
".west);\n";
209 s = styled_node(
"sink",
id, x, y,
"", nd,
opt);
210 s +=
"\\draw[conn] (" +
id +
".east) -- ([xshift=0.6cm]" +
id +
".east);\n";
213 return styled_node(
"fork",
id, x, y,
"", nd,
opt);
215 return styled_node(
"joinnode",
id, x, y,
"", nd,
opt);
216 case NodeType::Router:
217 return styled_node(
"router",
id, x, y,
"", nd,
opt);
218 case NodeType::ClassSwitch:
219 return styled_node(
"classswitch",
id, x, y,
"", nd,
opt);
220 case NodeType::Cache:
221 s = styled_node(
"cache",
id, x, y,
"", nd,
opt);
222 s +=
"\\draw ([yshift=-0.3cm]" +
id +
".north west) -- ([yshift=-0.3cm]" +
id +
224 s +=
"\\draw (" +
id +
".west) -- (" +
id +
".east);\n";
225 s +=
"\\draw ([yshift=0.3cm]" +
id +
".south west) -- ([yshift=0.3cm]" +
id +
228 case NodeType::Logger:
229 return styled_node(
"logger",
id, x, y,
"", nd,
opt);
230 case NodeType::Place:
231 return styled_node(
"place",
id, x, y,
"", nd,
opt);
232 case NodeType::Transition:
233 return styled_node(
"transition",
id, x, y,
"", nd,
opt);
235 return styled_node(
"draw,circle,minimum size=0.8cm",
id, x, y,
"", nd,
opt);
std::string escape_latex(std::string t)
TikZNodeRenderer.escapeLatex, applied in the SAME sequence of whole-string replacements,...
std::string sanitize_id(const std::string &name)
name.replaceAll("[^a-zA-Z0-9]", "_"): one underscore per CODE POINT, so a UTF-8 sequence is one chara...
std::string server_label(double c)
String.valueOf(queue.getNumberOfServers()), the JAR's Integer.MAX_VALUE pool being infinity.
std::string java_fixed(double v, int prec)
Java's String.format("%." + prec + "f", v).
std::string styled_node(const std::string &style, const std::string &id, double x, double y, const std::string &body, const TikzNode &nd, const TikzOptions &opt)
\node[style] (id) at (x,y) {body}; followed by the name label the options ask for.
std::string tikz_preamble(const TikzOptions &opt)
TikZNodeRenderer.getPreamble, byte for byte.
std::string tikz_render_node(const TikzNode &nd, double x, double y, const TikzOptions &opt)
TikZNodeRenderer.renderNode.
NodeType
Node kinds, with the values of MATLAB NodeType.
Conservation laws of a layered queueing network, enumerated from its structure.
One node as the TikZ exporter sees it.
std::string sched
Java SchedStrategy.name() of a Queue (FCFSPRIO is HOL, as in MATLAB), empty when none.
double servers
a Queue's server count, infinite for an unbounded pool
Layout and rendering options of the network TikZ exporter (TikZOptions).
The part of a network the TikZ exporter draws, and the text helpers the JAR's exporter uses to write ...
Port of jline.io.tikz.TikZOptions: the knobs of the network TikZ exporter.