|
@@ -1,4 +1,5 @@
|
|
import subprocess
|
|
import subprocess
|
|
|
|
+import sys
|
|
|
|
|
|
try:
|
|
try:
|
|
import pydot
|
|
import pydot
|
|
@@ -7,15 +8,11 @@ try:
|
|
except ImportError:
|
|
except ImportError:
|
|
has_pydot = False
|
|
has_pydot = False
|
|
|
|
|
|
-class LoLADraw:
|
|
|
|
|
|
|
|
- def __init__(self):
|
|
|
|
- print("Starting LoLADraw...")
|
|
|
|
- print("Please ensure that GraphViz is installed before use.")
|
|
|
|
|
|
+class LoLADraw:
|
|
|
|
|
|
def get_net(self, filename):
|
|
def get_net(self, filename):
|
|
|
|
|
|
-
|
|
|
|
places = []
|
|
places = []
|
|
markings = {}
|
|
markings = {}
|
|
transitions = {}
|
|
transitions = {}
|
|
@@ -126,29 +123,37 @@ class LoLADraw:
|
|
c, p = conpro
|
|
c, p = conpro
|
|
|
|
|
|
for c_name, weight in c.items():
|
|
for c_name, weight in c.items():
|
|
- graph.add_edge(pydot.Edge(nodes[c_name], nodes[t_name]))#, color=color))
|
|
|
|
|
|
+ graph.add_edge(pydot.Edge(nodes[c_name], nodes[t_name])) # , color=color))
|
|
|
|
|
|
for p_name, weight in p.items():
|
|
for p_name, weight in p.items():
|
|
graph.add_edge(pydot.Edge(nodes[t_name], nodes[p_name], label=weight))
|
|
graph.add_edge(pydot.Edge(nodes[t_name], nodes[p_name], label=weight))
|
|
# , color=color))
|
|
# , color=color))
|
|
|
|
|
|
-
|
|
|
|
dot_filename = filename.replace(".lola", ".dot")
|
|
dot_filename = filename.replace(".lola", ".dot")
|
|
graph.write(dot_filename, prog='dot')
|
|
graph.write(dot_filename, prog='dot')
|
|
|
|
|
|
- command = "dot -Tsvg " + dot_filename + " -o " + filename.replace(".lola", ".svg")
|
|
|
|
- subprocess.call(command, shell=True)
|
|
|
|
|
|
+ svg_filename = filename.replace(".lola", ".svg")
|
|
|
|
+ command = "dot -Tsvg " + dot_filename + " -o " + svg_filename
|
|
|
|
+ returncode = subprocess.call(command, shell=True)
|
|
|
|
+ if returncode != 0:
|
|
|
|
+ print("ERROR: Please ensure that GraphViz is installed!")
|
|
|
|
|
|
|
|
+ print("Exported drawing to file: " + svg_filename)
|
|
# command = "rm " + dot_filename
|
|
# command = "rm " + dot_filename
|
|
# subprocess.call(command, shell=True)
|
|
# subprocess.call(command, shell=True)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
+ print("Starting LoLADraw...")
|
|
|
|
+ if len(sys.argv) < 2:
|
|
|
|
+ print("Error: Please pass a filename as the first argument.")
|
|
|
|
+ exit(1)
|
|
|
|
+
|
|
if not has_pydot:
|
|
if not has_pydot:
|
|
print("ERROR: Install pydot first!")
|
|
print("ERROR: Install pydot first!")
|
|
exit(1)
|
|
exit(1)
|
|
|
|
|
|
- filename = "dining_philo.lola"
|
|
|
|
|
|
+ filename = sys.argv[1]
|
|
ld = LoLADraw()
|
|
ld = LoLADraw()
|
|
ld.draw(filename)
|
|
ld.draw(filename)
|