Franck Pommereau

finished plugin draw (with GraphViz)

...@@ -3,6 +3,7 @@ plug = Plugin("zinc.nets") ...@@ -3,6 +3,7 @@ plug = Plugin("zinc.nets")
3 3
4 import subprocess, tempfile, json, io, ast, pathlib 4 import subprocess, tempfile, json, io, ast, pathlib
5 5
6 +@plug
6 class GV (object) : 7 class GV (object) :
7 _arrowhead = { 8 _arrowhead = {
8 "Fill" : "diamond", 9 "Fill" : "diamond",
...@@ -89,7 +90,7 @@ class GV (object) : ...@@ -89,7 +90,7 @@ class GV (object) :
89 return self 90 return self
90 @classmethod 91 @classmethod
91 def read (cls, stream) : 92 def read (cls, stream) :
92 - with tempfile.NamedTemporaryFile(mode="w") as dot : 93 + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as dot :
93 dot.write(stream.read()) 94 dot.write(stream.read())
94 dot.flush() 95 dot.flush()
95 out = subprocess.check_output(["dot", "-Tdot_json", "-q", 96 out = subprocess.check_output(["dot", "-Tdot_json", "-q",
...@@ -97,7 +98,7 @@ class GV (object) : ...@@ -97,7 +98,7 @@ class GV (object) :
97 dot.name], encoding="utf-8") 98 dot.name], encoding="utf-8")
98 return cls.read_json(io.StringIO(out)) 99 return cls.read_json(io.StringIO(out))
99 def dot (self, engine="dot", scale=72.0, landscape=False) : 100 def dot (self, engine="dot", scale=72.0, landscape=False) :
100 - with tempfile.NamedTemporaryFile(mode="w") as dot : 101 + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as dot :
101 self.write(dot) 102 self.write(dot)
102 dot.flush() 103 dot.flush()
103 out = subprocess.check_output(["dot", "-Tdot_json", "-q", 104 out = subprocess.check_output(["dot", "-Tdot_json", "-q",
...@@ -108,7 +109,7 @@ class GV (object) : ...@@ -108,7 +109,7 @@ class GV (object) :
108 return self.read(io.StringIO(out)) 109 return self.read(io.StringIO(out))
109 def draw (self, path, engine="dot", scale=72.0, landscape=False) : 110 def draw (self, path, engine="dot", scale=72.0, landscape=False) :
110 fmt = pathlib.Path(path).suffix.lstrip(".") 111 fmt = pathlib.Path(path).suffix.lstrip(".")
111 - with tempfile.NamedTemporaryFile(mode="w") as dot : 112 + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as dot :
112 self.write(dot) 113 self.write(dot)
113 dot.flush() 114 dot.flush()
114 subprocess.check_call(["dot", "-q", 115 subprocess.check_call(["dot", "-q",
...@@ -121,6 +122,9 @@ class GV (object) : ...@@ -121,6 +122,9 @@ class GV (object) :
121 122
122 @plug 123 @plug
123 class PetriNet (plug.PetriNet) : 124 class PetriNet (plug.PetriNet) :
124 - def draw (self, path, engine="dot", 125 + def draw (self, path, engine="dot", scale=72.0, landscape=False,
125 - graph_attr=None, place_attr=None, trans_attr=None, arc_attr=None) : 126 + net_attr=None, place_attr=None, trans_attr=None, arc_attr=None) :
126 - pass 127 + gv = GV.from_net(self, net_attr, place_attr, trans_attr, arc_attr)
128 + if path is not None :
129 + gv.draw(path, engine, scale, landscape)
130 + return gv
......