Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
zinc
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2019-12-18 17:59:58 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
594a3298d8f01e9c6bd09665d6684f5f479755b4
594a3298
1 parent
61168097
finished plugin draw (with GraphViz)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
zinc/plugins/draw.py
zinc/plugins/draw.py
View file @
594a329
...
...
@@ -3,6 +3,7 @@ plug = Plugin("zinc.nets")
import
subprocess
,
tempfile
,
json
,
io
,
ast
,
pathlib
@plug
class
GV
(
object
)
:
_arrowhead
=
{
"Fill"
:
"diamond"
,
...
...
@@ -89,7 +90,7 @@ class GV (object) :
return
self
@classmethod
def
read
(
cls
,
stream
)
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
)
as
dot
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
encoding
=
"utf-8"
)
as
dot
:
dot
.
write
(
stream
.
read
())
dot
.
flush
()
out
=
subprocess
.
check_output
([
"dot"
,
"-Tdot_json"
,
"-q"
,
...
...
@@ -97,7 +98,7 @@ class GV (object) :
dot
.
name
],
encoding
=
"utf-8"
)
return
cls
.
read_json
(
io
.
StringIO
(
out
))
def
dot
(
self
,
engine
=
"dot"
,
scale
=
72.0
,
landscape
=
False
)
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
)
as
dot
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
encoding
=
"utf-8"
)
as
dot
:
self
.
write
(
dot
)
dot
.
flush
()
out
=
subprocess
.
check_output
([
"dot"
,
"-Tdot_json"
,
"-q"
,
...
...
@@ -108,7 +109,7 @@ class GV (object) :
return
self
.
read
(
io
.
StringIO
(
out
))
def
draw
(
self
,
path
,
engine
=
"dot"
,
scale
=
72.0
,
landscape
=
False
)
:
fmt
=
pathlib
.
Path
(
path
)
.
suffix
.
lstrip
(
"."
)
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
)
as
dot
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
encoding
=
"utf-8"
)
as
dot
:
self
.
write
(
dot
)
dot
.
flush
()
subprocess
.
check_call
([
"dot"
,
"-q"
,
...
...
@@ -121,6 +122,9 @@ class GV (object) :
@plug
class
PetriNet
(
plug
.
PetriNet
)
:
def
draw
(
self
,
path
,
engine
=
"dot"
,
graph_attr
=
None
,
place_attr
=
None
,
trans_attr
=
None
,
arc_attr
=
None
)
:
pass
def
draw
(
self
,
path
,
engine
=
"dot"
,
scale
=
72.0
,
landscape
=
False
,
net_attr
=
None
,
place_attr
=
None
,
trans_attr
=
None
,
arc_attr
=
None
)
:
gv
=
GV
.
from_net
(
self
,
net_attr
,
place_attr
,
trans_attr
,
arc_attr
)
if
path
is
not
None
:
gv
.
draw
(
path
,
engine
,
scale
,
landscape
)
return
gv
...
...
Please
register
or
login
to post a comment