29 import latex_equations
45 self.
label.append(label)
52 if shape ==
"rounded_box":
54 elif shape ==
"ellipse" or shape ==
None:
61 if e.id_from == id_from
and e.id_to == id_to:
70 dot =
"digraph transition {\n" 73 if (e.id_from ==
None or e.id_to ==
None)
and not draw_unconnected:
82 for i
in range(len(e.latex_label)):
83 latex = e.latex_label[i]
85 latex = latex_equations.toMathText(e.label[i])
86 edge_latex_str += sep + latex
89 if edge_latex_str
in latex_formulas:
90 handle, path = eps_file_list[latex_formulas.index(edge_latex_str)]
92 handle, path = tempfile.mkstemp(suffix=
".eps")
93 eps_file_list.append( (handle, path) )
94 latex_formulas.append( edge_latex_str )
97 dot +=
"\"" + e.id_to +
"_unconnected_in\" [shape=point label=\"\"];\n" 98 dot += e.id_to +
"_unconnected_in -> " + e.id_to +
" [label=<<TABLE BORDER=\"0\"><TR><TD><IMG src=\"" + path +
"\"/></TD></TR></TABLE>>];\n" 100 dot +=
"\"" + e.id_from +
"_unconnected_out\" [shape=point label=\"\"];\n" 101 dot += e.id_from +
" -> " + e.id_from +
"_unconnected_out [label=<<TABLE BORDER=\"0\"><TR><TD><IMG src=\"" + path +
"\"/></TD></TR></TABLE>>];\n" 103 dot += e.id_from +
" -> " + e.id_to +
" [label=<<TABLE BORDER=\"0\"><TR><TD><IMG src=\"" + path +
"\"/></TD></TR></TABLE>>];\n" 108 for label
in e.label:
109 edge_str += sep + label
111 if e.id_from ==
None:
112 dot +=
"\"" + e.id_to +
"_unconnected_in\" [shape=point label=\"\"];\n" 113 dot += e.id_to +
"_unconnected_in -> " + e.id_to +
" [label=\"" + edge_str +
"\"];\n" 114 elif e.id_to ==
None:
115 dot +=
"\"" + e.id_from +
"_unconnected_out\" [shape=point label=\"\"];\n" 116 dot += e.id_from +
" -> " + e.id_from +
"_unconnected_out [label=\"" + edge_str +
"\"];\n" 118 dot += e.id_from +
" -> " + e.id_to +
" [label=\"" + edge_str +
"\"];\n" 121 for name
in self.
nodes:
123 latex_label = n.latex_label
125 latex_label =
'\\text{' + n.label.replace(
'_',
'\_') +
'}' 126 if latex_label
in latex_formulas:
127 handle, path = eps_file_list[latex_formulas.index(latex_label)]
129 handle, path = tempfile.mkstemp(suffix=
".eps")
130 eps_file_list.append( (handle, path) )
131 latex_formulas.append( latex_label )
132 dot += n.label +
" [" + self.
shape_str +
" label=\"\"; image=\"" + path +
"\"];\n" 134 for name
in self.
nodes:
136 dot += n.label +
" [" + self.
shape_str +
" label=\"" + n.label +
"\"];\n" 139 return dot, eps_file_list, latex_formulas
142 dot, eps_file_list, latex_formulas = self.
generateDotFile(draw_unconnected=
False, use_latex=
True)
144 latex_equations.exportToEpsList(eps_file_list, latex_formulas)
147 in_read, in_write = os.pipe()
148 os.write(in_write, dot)
150 subprocess.call([
'dot',
'-Teps',
'-o'+filename+
'.eps'], stdin=in_read)
153 latex_equations.removeEpsListFiles(eps_file_list)
155 subprocess.call([
'epspdf', filename+
'.eps', filename])
156 os.remove(filename+
'.eps')
159 dot, eps_file_list, latex_formulas = self.
generateDotFile(draw_unconnected=
False, use_latex=
False)
161 in_read, in_write = os.pipe()
162 os.write(in_write, dot)
165 out_read, out_write = os.pipe()
166 subprocess.call([
'dot',
'-Tplain'], stdin=in_read, stdout=out_write)
168 graph_str = os.read(out_read, 1000000)
171 graph_str = graph_str.replace(
"\\\n",
"")
def __init__(self, shape=None)
def exportToPdf(self, filename)
def generateDotFile(self, draw_unconnected=False, use_latex=False)
def addLabel(self, label, latex_label)
def getEdge(self, id_from, id_to)