|
|
@@ -1,4 +1,12 @@
|
|
|
+import sys, json, threading
|
|
|
import Tkinter as tk
|
|
|
+from modelverse import *
|
|
|
+
|
|
|
+places = []
|
|
|
+transitions = []
|
|
|
+p2ts = []
|
|
|
+t2ps = []
|
|
|
+cond = threading.Condition()
|
|
|
|
|
|
class AttributeEditor(tk.Toplevel):
|
|
|
def __init__(self, title, entries, callback):
|
|
|
@@ -30,18 +38,65 @@ class PlaceVis:
|
|
|
def __init__(self, canvas, x, y, name="", tokens=0):
|
|
|
self.canvas = canvas
|
|
|
self.vis = canvas.create_oval(x - PlaceVis.R, y - PlaceVis.R, x + PlaceVis.R, y + PlaceVis.R, fill="white")
|
|
|
+ self.name = name
|
|
|
self.name_text = canvas.create_text(x, y + PlaceVis.R + 10, text=name, font=('Helvetica', '12'))
|
|
|
+ self.tokens = tokens
|
|
|
self.tokens_text = canvas.create_text(x, y, text=tokens, font=('Helvetica', '12'))
|
|
|
canvas.tag_bind(self.vis, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.name_text, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.tokens_text, "<Button-1>", self.clicked)
|
|
|
canvas.tag_bind(self.vis, "<Double-Button-1>", self.edit)
|
|
|
+ canvas.tag_bind(self.name_text, "<Double-Button-1>", self.edit)
|
|
|
+ canvas.tag_bind(self.tokens_text, "<Double-Button-1>", self.edit)
|
|
|
+ canvas.tag_bind(self.vis, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.name_text, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.tokens_text, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.vis, "<Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.name_text, "<Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.tokens_text, "<Button-3>", self.delete)
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
+ self.t2ps = []
|
|
|
+ self.p2ts = []
|
|
|
+ self.last_click_x = None
|
|
|
+ self.last_click_y = None
|
|
|
|
|
|
def get_name(self):
|
|
|
- return self.canvas.itemcget(self.name_text, "text")
|
|
|
+ return self.name
|
|
|
|
|
|
def clicked(self, event):
|
|
|
event.widget.clicked = True
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ def delete(self, event):
|
|
|
+ self.canvas.delete(self.vis)
|
|
|
+ self.canvas.delete(self.name_text)
|
|
|
+ self.canvas.delete(self.tokens_text)
|
|
|
+
|
|
|
+ for t2p in self.t2ps:
|
|
|
+ t2p.delete()
|
|
|
+ for p2t in self.p2ts:
|
|
|
+ p2t.delete()
|
|
|
+
|
|
|
+ global places
|
|
|
+ places = [el for el in places if el.name != self.name]
|
|
|
+
|
|
|
+ def move(self, event):
|
|
|
+ delta_x = event.x - self.last_click_x
|
|
|
+ delta_y = event.y - self.last_click_y
|
|
|
+ self.canvas.move(self.vis, delta_x, delta_y)
|
|
|
+ self.canvas.move(self.name_text, delta_x, delta_y)
|
|
|
+ self.canvas.move(self.tokens_text, delta_x, delta_y)
|
|
|
+ self.x += delta_x
|
|
|
+ self.y += delta_y
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ for t2p in self.t2ps:
|
|
|
+ t2p.moved()
|
|
|
+ for p2t in self.p2ts:
|
|
|
+ p2t.moved()
|
|
|
|
|
|
def edit(self, event):
|
|
|
event.widget.clicked = True
|
|
|
@@ -58,18 +113,58 @@ class TransitionVis:
|
|
|
|
|
|
def __init__(self, canvas, x, y, name=""):
|
|
|
self.canvas = canvas
|
|
|
- vis = canvas.create_rectangle(x - TransitionVis.W/2, y - TransitionVis.H/2, x + TransitionVis.W/2, y + TransitionVis.H/2, fill="black")
|
|
|
- canvas.tag_bind(vis, "<Button-1>", self.clicked)
|
|
|
- canvas.tag_bind(vis, "<Double-Button-1>", self.edit)
|
|
|
+ self.vis = canvas.create_rectangle(x - TransitionVis.W/2, y - TransitionVis.H/2, x + TransitionVis.W/2, y + TransitionVis.H/2, fill="black")
|
|
|
+ self.name = name
|
|
|
self.name_text = canvas.create_text(x, y + TransitionVis.H/2 + 10, text=name, font=('Helvetica', '12'))
|
|
|
+ canvas.tag_bind(self.vis, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.name_text, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.vis, "<Double-Button-1>", self.edit)
|
|
|
+ canvas.tag_bind(self.name_text, "<Double-Button-1>", self.edit)
|
|
|
+ canvas.tag_bind(self.vis, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.name_text, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.vis, "<Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.name_text, "<Button-3>", self.delete)
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
+ self.t2ps = []
|
|
|
+ self.p2ts = []
|
|
|
+ self.last_click_x = None
|
|
|
+ self.last_click_y = None
|
|
|
|
|
|
def get_name(self):
|
|
|
- return self.canvas.itemcget(self.name_text, "text")
|
|
|
+ return self.name
|
|
|
|
|
|
def clicked(self, event):
|
|
|
event.widget.clicked = True
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ def delete(self, event):
|
|
|
+ self.canvas.delete(self.vis)
|
|
|
+ self.canvas.delete(self.name_text)
|
|
|
+
|
|
|
+ for t2p in self.t2ps:
|
|
|
+ t2p.delete()
|
|
|
+ for p2t in self.p2ts:
|
|
|
+ p2t.delete()
|
|
|
+
|
|
|
+ global transitions
|
|
|
+ transitions = [el for el in transitions if el.name != self.name]
|
|
|
+
|
|
|
+ def move(self, event):
|
|
|
+ delta_x = event.x - self.last_click_x
|
|
|
+ delta_y = event.y - self.last_click_y
|
|
|
+ self.canvas.move(self.vis, delta_x, delta_y)
|
|
|
+ self.canvas.move(self.name_text, delta_x, delta_y)
|
|
|
+ self.x += delta_x
|
|
|
+ self.y += delta_y
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ for t2p in self.t2ps:
|
|
|
+ t2p.moved()
|
|
|
+ for p2t in self.p2ts:
|
|
|
+ p2t.moved()
|
|
|
|
|
|
def edit(self, event):
|
|
|
event.widget.clicked = True
|
|
|
@@ -79,23 +174,136 @@ class TransitionVis:
|
|
|
self.canvas.itemconfig(self.name_text, text=attr_vals["name"])
|
|
|
window.destroy()
|
|
|
|
|
|
+class TransitionToPlaceVis:
|
|
|
+ def __init__(self, canvas, transition, place, weight=1):
|
|
|
+ self.canvas = canvas
|
|
|
+ self.transition = transition
|
|
|
+ self.place = place
|
|
|
+ self.weight = 1
|
|
|
+
|
|
|
+ self.line = self.canvas.create_line(transition.x, transition.y, place.x, place.y, fill="black", arrow=tk.LAST, arrowshape=(12, 14, 6))
|
|
|
+ x_coords = sorted([self.transition.x, self.place.x])
|
|
|
+ y_coords = sorted([self.transition.y, self.place.y])
|
|
|
+ self.text = self.canvas.create_text(5 + x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2, text=self.weight, font=('Helvetica', '12'))
|
|
|
+ canvas.tag_bind(self.line, "<Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.text, "<Button-3>", self.delete)
|
|
|
+
|
|
|
+ self.transition.t2ps.append(self)
|
|
|
+ self.place.t2ps.append(self)
|
|
|
+
|
|
|
+ def moved(self):
|
|
|
+ self.canvas.coords(self.line, self.transition.x, self.transition.y, self.place.x, self.place.y)
|
|
|
+ x_coords = sorted([self.transition.x, self.place.x])
|
|
|
+ y_coords = sorted([self.transition.y, self.place.y])
|
|
|
+ self.canvas.coords(self.text, 5 + x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2)
|
|
|
+
|
|
|
+ def delete(self, event=None):
|
|
|
+ self.canvas.delete(self.line)
|
|
|
+ self.canvas.delete(self.text)
|
|
|
+
|
|
|
+ global t2ps
|
|
|
+ t2ps = [el for el in t2ps if el.transition != self.transition and el.place != self.place]
|
|
|
+
|
|
|
+class PlaceToTransitionVis:
|
|
|
+ def __init__(self, canvas, place, transition, weight=1):
|
|
|
+ self.canvas = canvas
|
|
|
+ self.place = place
|
|
|
+ self.transition = transition
|
|
|
+ self.weight = 1
|
|
|
+
|
|
|
+ self.line = self.canvas.create_line(place.x, place.y, transition.x, transition.y, fill="black", arrow=tk.LAST, arrowshape=(12, 14, 6))
|
|
|
+ x_coords = sorted([self.transition.x, self.place.x])
|
|
|
+ y_coords = sorted([self.transition.y, self.place.y])
|
|
|
+ self.text = self.canvas.create_text(5 + x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2, text=self.weight, font=('Helvetica', '12'))
|
|
|
+ canvas.tag_bind(self.line, "<Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.text, "<Button-3>", self.delete)
|
|
|
+
|
|
|
+ self.place.p2ts.append(self)
|
|
|
+ self.transition.p2ts.append(self)
|
|
|
+
|
|
|
+ def moved(self):
|
|
|
+ self.canvas.coords(self.line, self.place.x, self.place.y, self.transition.x, self.transition.y)
|
|
|
+ x_coords = sorted([self.transition.x, self.place.x])
|
|
|
+ y_coords = sorted([self.transition.y, self.place.y])
|
|
|
+ self.canvas.coords(self.text, 5 + x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2)
|
|
|
+
|
|
|
+ def delete(self, event=None):
|
|
|
+ self.canvas.delete(self.line)
|
|
|
+ self.canvas.delete(self.text)
|
|
|
+
|
|
|
+ global p2ts
|
|
|
+ p2ts = [el for el in p2ts if el.place != self.place and el.transition != self.transition]
|
|
|
+
|
|
|
class MarkingVis:
|
|
|
- def __init__(self, canvas, x, y, content={}, fill=""):
|
|
|
+ def __init__(self, canvas, x, y, node_id, content={}):
|
|
|
+ self.node_id = node_id
|
|
|
self.canvas = canvas
|
|
|
- vis = canvas.create_text(x, y, text=str(content), font=('Helvetica', '14'))
|
|
|
- bbox = canvas.bbox(vis)
|
|
|
- canvas.move(vis, (bbox[2]-bbox[0])/2, (bbox[3]-bbox[1])/2)
|
|
|
- self.bbox = canvas.bbox(vis)
|
|
|
- rect = canvas.create_rectangle(*self.bbox, fill=fill)
|
|
|
- canvas.tag_lower(rect)
|
|
|
+ self.vis = canvas.create_text(x, y, text=str(content), font=('Helvetica', '14'))
|
|
|
+ self.bbox = canvas.bbox(self.vis)
|
|
|
+ canvas.move(self.vis, (self.bbox[2]-self.bbox[0])/2, (self.bbox[3]-self.bbox[1])/2)
|
|
|
+ self.bbox = canvas.bbox(self.vis)
|
|
|
+ self.rect = canvas.create_rectangle(*self.bbox, fill="")
|
|
|
+ canvas.tag_bind(self.vis, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.rect, "<Button-1>", self.clicked)
|
|
|
+ canvas.tag_bind(self.vis, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_bind(self.rect, "<B1-Motion>", self.move)
|
|
|
+ canvas.tag_lower(self.rect)
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
+ self.m2ms = []
|
|
|
+ self.last_click_x = None
|
|
|
+ self.last_click_y = None
|
|
|
|
|
|
def get_width(self):
|
|
|
return self.bbox[2]-self.bbox[0]
|
|
|
|
|
|
def get_height(self):
|
|
|
return self.bbox[3]-self.bbox[1]
|
|
|
+
|
|
|
+ def set_current(self, current=False):
|
|
|
+ if current:
|
|
|
+ self.canvas.itemconfig(self.rect, fill="yellow")
|
|
|
+ else:
|
|
|
+ self.canvas.itemconfig(self.rect, fill="")
|
|
|
+
|
|
|
+ def clicked(self, event):
|
|
|
+ event.widget.clicked = True
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ def move(self, event):
|
|
|
+ delta_x = event.x - self.last_click_x
|
|
|
+ delta_y = event.y - self.last_click_y
|
|
|
+ self.canvas.move(self.vis, delta_x, delta_y)
|
|
|
+ self.canvas.move(self.rect, delta_x, delta_y)
|
|
|
+ self.x += delta_x
|
|
|
+ self.y += delta_y
|
|
|
+ self.last_click_x = event.x
|
|
|
+ self.last_click_y = event.y
|
|
|
+
|
|
|
+ for m2m in self.m2ms:
|
|
|
+ m2m.moved()
|
|
|
+
|
|
|
+class MarkingToMarkingVis:
|
|
|
+ def __init__(self, canvas, m1, m2, transition):
|
|
|
+ self.canvas = canvas
|
|
|
+ self.m1 = m1
|
|
|
+ self.m2 = m2
|
|
|
+ self.transition = transition
|
|
|
+
|
|
|
+ self.line = self.canvas.create_line(self.m1.x, self.m1.y, self.m2.x, self.m2.y, fill="black", arrow=tk.LAST, arrowshape=(12, 14, 6))
|
|
|
+ x_coords = sorted([self.m1.x, self.m2.x])
|
|
|
+ y_coords = sorted([self.m1.y, self.m2.y])
|
|
|
+ self.text = self.canvas.create_text(x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2, text=self.transition.name, font=('Helvetica', '12'))
|
|
|
+
|
|
|
+ self.m1.m2ms.append(self)
|
|
|
+ self.m2.m2ms.append(self)
|
|
|
+
|
|
|
+ def moved(self):
|
|
|
+ self.canvas.coords(self.line, self.m1.x, self.m1.y, self.m2.x, self.m2.y)
|
|
|
+ x_coords = sorted([self.m1.x, self.m2.x])
|
|
|
+ y_coords = sorted([self.m1.y, self.m2.y])
|
|
|
+ self.canvas.coords(self.text, x_coords[0] + (x_coords[1] - x_coords[0]) / 2, y_coords[0] + (y_coords[1] - y_coords[0]) / 2)
|
|
|
|
|
|
class PNInterface(tk.Tk):
|
|
|
MAX_WIDTH = 8192
|
|
|
@@ -103,14 +311,50 @@ class PNInterface(tk.Tk):
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
tk.Tk.__init__(self, *args, **kwargs)
|
|
|
+
|
|
|
+ print("Init")
|
|
|
+ init()
|
|
|
+ print("Login")
|
|
|
+ #login(str(random.random()), str(random.random()))
|
|
|
+ login("admin", "admin")
|
|
|
+
|
|
|
+ # Add the metamodels for PetriNet and ReachabilityGraph
|
|
|
+ print("Add metamodels")
|
|
|
+ try:
|
|
|
+ model_add("PetriNet", "SimpleClassDiagrams", open("../../models/petrinets.mvc").read())
|
|
|
+ except ModelExists:
|
|
|
+ pass
|
|
|
+
|
|
|
+ try:
|
|
|
+ model_add("ReachabilityGraph", "SimpleClassDiagrams", open("../../models/reachability_graph.mvc").read())
|
|
|
+ except ModelExists:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Remove the action language code to transform between them
|
|
|
+ print("Remove AL model")
|
|
|
+ try:
|
|
|
+ model_delete("analyseReachability")
|
|
|
+ except ModelverseException:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Add the action language code to transform between them
|
|
|
+ print("Add AL model")
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"PetriNet": "PetriNet"}, {"ReachabilityGraph": "ReachabilityGraph"}, "analyseReachability", open("../../models/reachability.alc", "r").read())
|
|
|
+ except ModelExists:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Add an example model transformation to print the reachability graph
|
|
|
+ print("Add MT model")
|
|
|
+ try:
|
|
|
+ transformation_add_MT({"ReachabilityGraph": "ReachabilityGraph"}, {}, "printReachability", open("../../models/reachabilitygraph_print.mvc").read())
|
|
|
+ except ModelExists:
|
|
|
+ pass
|
|
|
|
|
|
- self.places = []
|
|
|
- self.p2ts = []
|
|
|
- self.t2ps = []
|
|
|
- self.transitions = []
|
|
|
- self.links = []
|
|
|
self.markings = []
|
|
|
+ self.m2ms = []
|
|
|
self.mode = "PLACE"
|
|
|
+ self.sim_mode = None
|
|
|
|
|
|
# global attributes
|
|
|
self.title('Petrinets Debugging Interface')
|
|
|
@@ -146,12 +390,14 @@ class PNInterface(tk.Tk):
|
|
|
|
|
|
self.INTER_SPACING = 5
|
|
|
|
|
|
- self.buttons = ["Continuous", "Step", "Manual", "Add_Breakpoint"]
|
|
|
- self.button_config = {"Continuous": self.continuous,
|
|
|
+ self.buttons = ["Load", "Continuous", "Step", "Manual", "Add_Breakpoint"]
|
|
|
+ self.button_config = {"Load": self.load,
|
|
|
+ "Continuous": self.continuous,
|
|
|
"Step": self.step,
|
|
|
"Manual": self.manual,
|
|
|
"Add_Breakpoint": self.add_breakpoint}
|
|
|
- self.button_img = {"Continuous": tk.PhotoImage(file="simulate.icon.gif"),
|
|
|
+ self.button_img = {"Load": tk.PhotoImage(file="load.icon.gif"),
|
|
|
+ "Continuous": tk.PhotoImage(file="simulate.icon.gif"),
|
|
|
"Step": tk.PhotoImage(file="step.icon.gif"),
|
|
|
"Manual": tk.PhotoImage(file="godevent.icon.gif"),
|
|
|
"Add_Breakpoint": tk.PhotoImage(file="addbp.icon.gif")}
|
|
|
@@ -202,48 +448,53 @@ class PNInterface(tk.Tk):
|
|
|
self.setup()
|
|
|
|
|
|
def setup(self):
|
|
|
- free = PlaceVis(self.pn_canvas, 100, 200, "free", 2)
|
|
|
- producing = PlaceVis(self.pn_canvas, 200, 200, "producing", 1)
|
|
|
+ free = PlaceVis(self.pn_canvas, 100, 200, "free", 3)
|
|
|
+ producing = PlaceVis(self.pn_canvas, 200, 200, "producing", 0)
|
|
|
produced = PlaceVis(self.pn_canvas, 300, 200, "produced", 0)
|
|
|
- waiting = PlaceVis(self.pn_canvas, 400, 200, "waiting", 1)
|
|
|
- consuming = PlaceVis(self.pn_canvas, 500, 200, "consuming", 1)
|
|
|
- self.places = [free, producing, produced, waiting, consuming]
|
|
|
+ waiting = PlaceVis(self.pn_canvas, 400, 200, "waiting", 2)
|
|
|
+ consuming = PlaceVis(self.pn_canvas, 500, 200, "consuming", 0)
|
|
|
+ global places
|
|
|
+ places = [free, producing, produced, waiting, consuming]
|
|
|
|
|
|
start_produce = TransitionVis(self.pn_canvas, 150, 100, "start producing")
|
|
|
end_produce = TransitionVis(self.pn_canvas, 150, 300, "end producing")
|
|
|
start_consume = TransitionVis(self.pn_canvas, 450, 100, "start consuming")
|
|
|
end_consume = TransitionVis(self.pn_canvas, 450, 300, "end consuming")
|
|
|
- self.transitions = [start_produce, end_produce, start_consume, end_consume]
|
|
|
-
|
|
|
- f_to_s_p = self.pn_canvas.create_line(free.x, free.y - PlaceVis.R, start_produce.x - TransitionVis.W/2, start_produce.y, fill="black", arrow=tk.LAST)
|
|
|
- s_p_to_p = self.pn_canvas.create_line(start_produce.x + TransitionVis.W/2, start_produce.y, producing.x, producing.y - PlaceVis.R, fill="black", arrow=tk.LAST)
|
|
|
- p_to_e_p = self.pn_canvas.create_line(producing.x, producing.y + PlaceVis.R, end_produce.x + TransitionVis.W/2, end_produce.y, fill="black", arrow=tk.LAST)
|
|
|
- e_p_to_f = self.pn_canvas.create_line(end_produce.x - TransitionVis.W/2, end_produce.y, free.x, free.y + PlaceVis.R, fill="black", arrow=tk.LAST)
|
|
|
-
|
|
|
- w_to_s_c = self.pn_canvas.create_line(waiting.x, waiting.y - PlaceVis.R, start_consume.x - TransitionVis.W/2, start_consume.y, fill="black", arrow=tk.LAST)
|
|
|
- s_c_to_c = self.pn_canvas.create_line(start_consume.x + TransitionVis.W/2, start_consume.y, consuming.x, consuming.y - PlaceVis.R, fill="black", arrow=tk.LAST)
|
|
|
- c_to_e_c = self.pn_canvas.create_line(consuming.x, consuming.y + PlaceVis.R, end_consume.x + TransitionVis.W/2, end_consume.y, fill="black", arrow=tk.LAST)
|
|
|
- e_c_to_w = self.pn_canvas.create_line(end_consume.x - TransitionVis.W/2, end_consume.y, waiting.x, waiting.y + PlaceVis.R, fill="black", arrow=tk.LAST)
|
|
|
-
|
|
|
- e_p_to_p = self.pn_canvas.create_line(end_produce.x + TransitionVis.W/2, end_produce.y, produced.x , produced.y + PlaceVis.R, fill="black", arrow=tk.LAST)
|
|
|
- p_to_s_c = self.pn_canvas.create_line(produced.x + PlaceVis.R, produced.y, start_consume.x - TransitionVis.W/2, start_consume.y, fill="black", arrow=tk.LAST)
|
|
|
-
|
|
|
+ global transitions
|
|
|
+ transitions = [start_produce, end_produce, start_consume, end_consume]
|
|
|
+
|
|
|
+ f_to_s_p = PlaceToTransitionVis(self.pn_canvas, free, start_produce)
|
|
|
+ s_p_to_p = TransitionToPlaceVis(self.pn_canvas, start_produce, producing)
|
|
|
+ p_to_e_p = PlaceToTransitionVis(self.pn_canvas, producing, end_produce)
|
|
|
+ e_p_to_f = TransitionToPlaceVis(self.pn_canvas, end_produce, free)
|
|
|
+
|
|
|
+ w_to_s_c = PlaceToTransitionVis(self.pn_canvas, waiting, start_consume)
|
|
|
+ s_c_to_c = TransitionToPlaceVis(self.pn_canvas, start_consume, consuming)
|
|
|
+ c_to_e_c = PlaceToTransitionVis(self.pn_canvas, consuming, end_consume)
|
|
|
+ e_c_to_w = TransitionToPlaceVis(self.pn_canvas, end_consume, waiting)
|
|
|
+
|
|
|
+ e_p_to_p = TransitionToPlaceVis(self.pn_canvas, end_produce, produced)
|
|
|
+ p_to_s_c = PlaceToTransitionVis(self.pn_canvas, produced, start_consume)
|
|
|
+ global p2ts
|
|
|
+ p2ts = [f_to_s_p, p_to_e_p, w_to_s_c, c_to_e_c, p_to_s_c]
|
|
|
+ global t2ps
|
|
|
+ t2ps = [s_p_to_p, e_p_to_f, s_c_to_c, e_c_to_w, e_p_to_p]
|
|
|
+
|
|
|
+ '''
|
|
|
marking_1 = MarkingVis(self.rg_canvas, 100, 50, {"free": 3, "producing": 0, "produced": 0, "waiting": 2, "consuming": 0})
|
|
|
marking_2 = MarkingVis(self.rg_canvas, 150, 150, {"free": 2, "producing": 1, "produced": 0, "waiting": 2, "consuming": 0})
|
|
|
marking_3 = MarkingVis(self.rg_canvas, 200, 250, {"free": 3, "producing": 0, "produced": 1, "waiting": 2, "consuming": 0})
|
|
|
marking_4 = MarkingVis(self.rg_canvas, 100, 350, {"free": 3, "producing": 0, "produced": 0, "waiting": 1, "consuming": 1})
|
|
|
- marking_5 = MarkingVis(self.rg_canvas, 150, 450, {"free": 2, "producing": 1, "produced": 0, "waiting": 1, "consuming": 1}, fill="yellow")
|
|
|
-
|
|
|
- m1_to_m2 = self.rg_canvas.create_line(marking_1.x+50, marking_1.y+marking_1.get_height(), marking_2.x+50, marking_2.y, fill="black", arrow=tk.LAST)
|
|
|
- m1_to_m2_text = self.rg_canvas.create_text(marking_1.x+100, marking_1.y + (marking_2.y - marking_1.y)/2, text="start producing", font=('Helvetica', '12'))
|
|
|
- m2_to_m3 = self.rg_canvas.create_line(marking_2.x+50, marking_2.y+marking_2.get_height(), marking_3.x+50, marking_3.y, fill="black", arrow=tk.LAST)
|
|
|
- m2_to_m3_text = self.rg_canvas.create_text(marking_2.x+125, marking_2.y + (marking_3.y - marking_2.y)/2, text="end producing", font=('Helvetica', '12'))
|
|
|
- m3_to_m4 = self.rg_canvas.create_line(marking_3.x+50, marking_3.y+marking_3.get_height(), marking_4.x+50, marking_4.y, fill="black", arrow=tk.LAST)
|
|
|
- m3_to_m4_text = self.rg_canvas.create_text(marking_3.x+100, marking_3.y + (marking_4.y - marking_3.y)/2, text="start consuming", font=('Helvetica', '12'))
|
|
|
- m4_to_m5 = self.rg_canvas.create_line(marking_4.x+50, marking_4.y+marking_4.get_height(), marking_5.x+50, marking_5.y, fill="black", arrow=tk.LAST)
|
|
|
- m4_to_m5_text = self.rg_canvas.create_text(marking_4.x+100, marking_4.y + (marking_5.y - marking_4.y)/2, text="start producing", font=('Helvetica', '12'))
|
|
|
- m4_to_m1 = self.rg_canvas.create_line(marking_4.x+25, marking_4.y, marking_1.x+25, marking_1.y+marking_1.get_height(), fill="black", arrow=tk.LAST)
|
|
|
- m4_to_m1_text = self.rg_canvas.create_text(marking_4.x, marking_4.y + (marking_1.y - marking_4.y)/2, text="end consuming", font=('Helvetica', '12'))
|
|
|
+ marking_5 = MarkingVis(self.rg_canvas, 150, 450, {"free": 2, "producing": 1, "produced": 0, "waiting": 1, "consuming": 1})
|
|
|
+
|
|
|
+ marking_5.set_current(True)
|
|
|
+
|
|
|
+ m1_to_m2 = MarkingToMarkingVis(self.rg_canvas, marking_1, marking_2, start_produce)
|
|
|
+ m2_to_m3 = MarkingToMarkingVis(self.rg_canvas, marking_2, marking_3, end_produce)
|
|
|
+ m3_to_m4 = MarkingToMarkingVis(self.rg_canvas, marking_3, marking_4, start_consume)
|
|
|
+ m4_to_m5 = MarkingToMarkingVis(self.rg_canvas, marking_4, marking_5, start_produce)
|
|
|
+ m4_to_m1 = MarkingToMarkingVis(self.rg_canvas, marking_4, marking_1, end_consume)
|
|
|
+ '''
|
|
|
|
|
|
def place(self):
|
|
|
self.mode = "PLACE"
|
|
|
@@ -256,7 +507,10 @@ class PNInterface(tk.Tk):
|
|
|
src = [p for p in self.places if p.get_name() == attr_vals["src"]]
|
|
|
dst = [t for t in self.transitions if t.get_name() == attr_vals["dst"]]
|
|
|
if len(src) == 1 and len(dst) == 1:
|
|
|
- self.p2ts.append(self.pn_canvas.create_line(src[0].x, src[0].y, dst[0].x, dst[0].y, fill="black", arrow=tk.LAST))
|
|
|
+ global p2ts
|
|
|
+ p2ts.append(PlaceToTransitionVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
|
|
|
+ else:
|
|
|
+ print 'could not find source and/or target nodes'
|
|
|
window.destroy()
|
|
|
editor = AttributeEditor('Create P2T', {"weight": 1, "src": "", "dst": ""}, create_p2t)
|
|
|
|
|
|
@@ -265,21 +519,117 @@ class PNInterface(tk.Tk):
|
|
|
src = [t for t in self.transitions if t.get_name() == attr_vals["src"]]
|
|
|
dst = [p for p in self.places if p.get_name() == attr_vals["dst"]]
|
|
|
if len(src) == 1 and len(dst) == 1:
|
|
|
- self.t2ps.append(self.pn_canvas.create_line(src[0].x, src[0].y, dst[0].x, dst[0].y, fill="black", arrow=tk.LAST))
|
|
|
+ global t2ps
|
|
|
+ t2ps.append(TransitionToPlaceVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
|
|
|
+ else:
|
|
|
+ print 'could not find source and/or target nodes'
|
|
|
window.destroy()
|
|
|
editor = AttributeEditor('Create T2P', {"weight": 1, "src": "", "dst": ""}, create_t2p)
|
|
|
|
|
|
+ def load(self):
|
|
|
+ with open("model.mvc", "w+") as model_file:
|
|
|
+ for p in places:
|
|
|
+ model_file.write("Place %s {\n" % p.name.replace(" ", "_"))
|
|
|
+ model_file.write("\ttokens = %i\n" % p.tokens)
|
|
|
+ model_file.write("\tname = \"%s\"\n" % p.name)
|
|
|
+ model_file.write("}\n")
|
|
|
+ for t in transitions:
|
|
|
+ model_file.write("Transition %s {\n" % t.name.replace(" ", "_"))
|
|
|
+ model_file.write("\tname = \"%s\"\n" % t.name)
|
|
|
+ model_file.write("}\n")
|
|
|
+ for t2p in t2ps:
|
|
|
+ model_file.write("T2P (%s, %s) {\n" % (t2p.transition.name.replace(" ", "_"), t2p.place.name.replace(" ", "_")))
|
|
|
+ model_file.write("\tweight = %i\n" % t2p.weight)
|
|
|
+ model_file.write("}\n")
|
|
|
+ for p2t in p2ts:
|
|
|
+ model_file.write("P2T (%s, %s) {\n" % (p2t.place.name.replace(" ", "_"), p2t.transition.name.replace(" ", "_")))
|
|
|
+ model_file.write("\tweight = %i\n" % p2t.weight)
|
|
|
+ model_file.write("}\n")
|
|
|
+
|
|
|
+ print("Delete model")
|
|
|
+ try:
|
|
|
+ model_delete("my_pn")
|
|
|
+ except ModelverseException:
|
|
|
+ pass
|
|
|
+
|
|
|
+ print("Add model")
|
|
|
+ try:
|
|
|
+ model_add("my_pn", "PetriNet", open("model.mvc").read())
|
|
|
+ except ModelExists:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Start the reachability graph generation
|
|
|
+ print("Execute AL")
|
|
|
+ thrd = threading.Thread(target=transformation_execute_AL, args=["analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, self.callback])
|
|
|
+ thrd.daemon = True
|
|
|
+ thrd.start()
|
|
|
+ # status = transformation_execute_AL("analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, callback=self.callback)
|
|
|
+
|
|
|
+ def callback(self, value):
|
|
|
+ if value.startswith("{"):
|
|
|
+ print(value)
|
|
|
+ parsed_value = json.loads(value)
|
|
|
+ if parsed_value["msg_type"] == 'node_added':
|
|
|
+ self.markings.append(MarkingVis(self.rg_canvas, 100, 50, parsed_value['node_info']['node_id'], parsed_value['node_info']['node_marking']))
|
|
|
+ elif parsed_value["msg_type"] == 'link_added':
|
|
|
+ m1 = [m for m in self.markings if m.node_id == parsed_value['link_info']['source']][0]
|
|
|
+ m2 = [m for m in self.markings if m.node_id == parsed_value['link_info']['target']][0]
|
|
|
+ t = [t for t in transitions if t.name == parsed_value['link_info']['transition']][0]
|
|
|
+ self.m2ms.append(MarkingToMarkingVis(self.rg_canvas, m1, m2, t))
|
|
|
+ return
|
|
|
+ if value.startswith("#"):
|
|
|
+ value = value[1:]
|
|
|
+ print(value)
|
|
|
+ return
|
|
|
+ if value.startswith("%"):
|
|
|
+ if (value[1:] == "construct_function"):
|
|
|
+ print("Enter your code...")
|
|
|
+ code = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+
|
|
|
+ Boolean function bp_1(reachable_states: Element, mappings: Element):
|
|
|
+ log("Breakpoint check!")
|
|
|
+
|
|
|
+ Element keys
|
|
|
+ Element node
|
|
|
+ String msg
|
|
|
+ keys = dict_keys(reachable_states)
|
|
|
+ while (read_nr_out(keys) > 0):
|
|
|
+ node = reachable_states[set_pop(keys)]
|
|
|
+ msg = cast_v2s(node["critical_section_2"])
|
|
|
+ msg = "critical_section_2 = " + msg
|
|
|
+ log(msg)
|
|
|
+ if (integer_gt(node["critical_section_2"], 0)):
|
|
|
+ return True!
|
|
|
+ return False!
|
|
|
+ """
|
|
|
+ upload_code(code)
|
|
|
+ return
|
|
|
+ print(value)
|
|
|
+ with cond:
|
|
|
+ cond.wait()
|
|
|
+ return self.sim_mode
|
|
|
+
|
|
|
def continuous(self):
|
|
|
- pass
|
|
|
+ self.sim_mode = "continuous"
|
|
|
+ with cond:
|
|
|
+ cond.notify()
|
|
|
|
|
|
def step(self):
|
|
|
- pass
|
|
|
+ self.sim_mode = "step"
|
|
|
+ with cond:
|
|
|
+ cond.notify()
|
|
|
|
|
|
def manual(self):
|
|
|
- pass
|
|
|
+ self.sim_mode = "manual"
|
|
|
+ with cond:
|
|
|
+ cond.notify()
|
|
|
|
|
|
def add_breakpoint(self):
|
|
|
- pass
|
|
|
+ self.sim_mode = "add_breakpoint"
|
|
|
+ with cond:
|
|
|
+ cond.notify()
|
|
|
|
|
|
def clicked(self, event):
|
|
|
if hasattr(event.widget, 'clicked') and event.widget.clicked:
|