2
# pylint: disable=C0103,C0114,C0115,C0116,C0209,C0301
3
######################################################################
8
######################################################################
14
#######################################################################
18
with open(filename, "r", encoding="utf8") as fh:
22
vertex_re = re.compile(r'^\t([a-zA-Z0-9_]+)\t(.*)$')
24
r'^\t([a-zA-Z0-9_]+)\s+->\s+([a-zA-Z0-9_]+)\s*(.*)$')
27
vertex_match = re.search(vertex_re, line)
28
edge_match = re.search(edge_re, line)
30
if vertex_match.group(1) != 'nTITLE':
35
'name': vertex_match.group(1)
39
fromv = edge_match.group(1)
40
tov = edge_match.group(2)
41
w = re.match(r'weight=(\d+)', line)
42
weight = w.group(1) if w else 1
43
w = re.match(r'style=(\S+)', line)
44
cutable = w.group(1) if w else None
57
print("IGNORE: " + line)
60
#######################################################################
64
with open(filename, "w", encoding="utf8") as fh:
65
fh.write("void V3GraphTestImport::dotImport() {\n")
66
fh.write(" auto* gp = &m_graph;\n")
67
for ver in sorted(Vertexes, key=lambda ver: ver['num']):
69
" auto* %s = new V3GraphTestVertex{gp, \"%s\"}; if (%s) {}\n"
70
% (ver['name'], ver['name'], ver['name']))
73
fh.write(" new V3GraphEdge{gp, %s, %s, %s, %s};\n" %
74
(edge['from'], edge['to'], edge['weight'],
75
"true" if edge['cutable'] else "false"))
79
######################################################################
82
parser = argparse.ArgumentParser(
84
formatter_class=argparse.RawDescriptionHelpFormatter,
86
"""dot_importer takes a graphvis .dot file and converts into .cpp file.
87
This x.cpp file is then manually included in V3GraphTest.cpp to verify
88
various xsub-algorithms.""",
90
"""Copyright 2005-2024 by Wilson Snyder. This program is free software; you
91
can redistribute it and/or modify it under the terms of either the GNU
92
Lesser General Public License Version 3 or the Perl Artistic License
95
SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0""")
97
parser.add_argument('--debug',
101
parser.add_argument('filename', help='input .dot filename to process')
103
Args = parser.parse_args()
104
dotread(Args.filename)
105
cwrite("graph_export.cpp")
107
######################################################################
109
# compile-command: "./dot_importer ../test_regress/obj_vlt/t_EXAMPLE/*orderg_o*.dot && cat graph_export.cpp"