|
|
@@ -7,6 +7,8 @@ transitions = []
|
|
|
p2ts = []
|
|
|
t2ps = []
|
|
|
cond = threading.Condition()
|
|
|
+small_step_cond = threading.Condition()
|
|
|
+small_step_input = None
|
|
|
|
|
|
class AttributeEditor(tk.Toplevel):
|
|
|
def __init__(self, title, entries, callback):
|
|
|
@@ -106,6 +108,9 @@ class PlaceVis:
|
|
|
self.canvas.itemconfig(self.name_text, text=attr_vals["name"])
|
|
|
self.canvas.itemconfig(self.tokens_text, text=attr_vals["tokens"])
|
|
|
window.destroy()
|
|
|
+
|
|
|
+ def set_tokens(self, tokens):
|
|
|
+ self.canvas.itemconfig(self.tokens_text, text=str(tokens))
|
|
|
|
|
|
class TransitionVis:
|
|
|
H = 30
|
|
|
@@ -122,8 +127,10 @@ class TransitionVis:
|
|
|
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)
|
|
|
+ canvas.tag_bind(self.vis, "<Button-3>", self.select)
|
|
|
+ canvas.tag_bind(self.name_text, "<Button-3>", self.select)
|
|
|
+ canvas.tag_bind(self.vis, "<Double-Button-3>", self.delete)
|
|
|
+ canvas.tag_bind(self.name_text, "<Double-Button-3>", self.delete)
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
self.t2ps = []
|
|
|
@@ -139,6 +146,18 @@ class TransitionVis:
|
|
|
self.last_click_x = event.x
|
|
|
self.last_click_y = event.y
|
|
|
|
|
|
+ def set_enabled(self, enabled=False):
|
|
|
+ if enabled:
|
|
|
+ self.canvas.itemconfig(self.vis, fill="green")
|
|
|
+ else:
|
|
|
+ self.canvas.itemconfig(self.vis, fill="black")
|
|
|
+
|
|
|
+ def select(self, event):
|
|
|
+ global small_step_input
|
|
|
+ small_step_input = {'type': 'selected_transition', 'value': self.name}
|
|
|
+ with small_step_cond:
|
|
|
+ small_step_cond.notify()
|
|
|
+
|
|
|
def delete(self, event):
|
|
|
self.canvas.delete(self.vis)
|
|
|
self.canvas.delete(self.name_text)
|
|
|
@@ -238,6 +257,7 @@ class MarkingVis:
|
|
|
def __init__(self, canvas, x, y, node_id, content={}):
|
|
|
self.node_id = node_id
|
|
|
self.canvas = canvas
|
|
|
+ self.marking_val = content
|
|
|
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)
|
|
|
@@ -247,6 +267,8 @@ class MarkingVis:
|
|
|
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_bind(self.vis, "<Button-3>", self.rightclicked)
|
|
|
+ canvas.tag_bind(self.rect, "<Button-3>", self.rightclicked)
|
|
|
canvas.tag_lower(self.rect)
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
@@ -265,6 +287,12 @@ class MarkingVis:
|
|
|
self.canvas.itemconfig(self.rect, fill="yellow")
|
|
|
else:
|
|
|
self.canvas.itemconfig(self.rect, fill="")
|
|
|
+
|
|
|
+ def rightclicked(self, event):
|
|
|
+ global small_step_input
|
|
|
+ small_step_input = {'type': 'selected_marking', 'value': self.node_id}
|
|
|
+ with small_step_cond:
|
|
|
+ small_step_cond.notify()
|
|
|
|
|
|
def clicked(self, event):
|
|
|
event.widget.clicked = True
|
|
|
@@ -372,7 +400,7 @@ class PNInterface(tk.Tk):
|
|
|
"P2T": self.place_to_transition,
|
|
|
"T2P": self.transition_to_place}
|
|
|
self.button_img = {}
|
|
|
- self.buttons_vis = []
|
|
|
+ self.buttons_vis = {}
|
|
|
i = 0
|
|
|
for k in self.buttons:
|
|
|
v = self.button_config[k]
|
|
|
@@ -381,7 +409,7 @@ class PNInterface(tk.Tk):
|
|
|
else:
|
|
|
btn = tk.Button(self.modelling_toolbar_frame, text=k, command=v)
|
|
|
btn.grid(row=0, column=i, padx=self.INTER_SPACING, sticky=tk.W)
|
|
|
- self.buttons_vis.append(btn)
|
|
|
+ self.buttons_vis[k] = btn
|
|
|
i += 1
|
|
|
|
|
|
# debugging toolbar
|
|
|
@@ -390,18 +418,23 @@ class PNInterface(tk.Tk):
|
|
|
|
|
|
self.INTER_SPACING = 5
|
|
|
|
|
|
- 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 = {"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")}
|
|
|
- self.buttons_vis = []
|
|
|
+ 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 = {"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")}
|
|
|
+ self.button_img_disabled = {"load": tk.PhotoImage(file="load.disabled.icon.gif"),
|
|
|
+ "continuous": tk.PhotoImage(file="simulate.disabled.icon.gif"),
|
|
|
+ "step": tk.PhotoImage(file="step.disabled.icon.gif"),
|
|
|
+ "manual": tk.PhotoImage(file="godevent.disabled.icon.gif"),
|
|
|
+ "add_breakpoint": tk.PhotoImage(file="addbp.disabled.icon.gif")}
|
|
|
+ self.buttons_vis = {}
|
|
|
i = 0
|
|
|
for k in self.buttons:
|
|
|
v = self.button_config[k]
|
|
|
@@ -410,7 +443,10 @@ class PNInterface(tk.Tk):
|
|
|
else:
|
|
|
btn = tk.Button(self.debugging_toolbar_frame, text=k, command=v)
|
|
|
btn.grid(row=0, column=i, padx=self.INTER_SPACING, sticky=tk.W)
|
|
|
- self.buttons_vis.append(btn)
|
|
|
+ self.buttons_vis[k] = btn
|
|
|
+ if k != "load":
|
|
|
+ btn.config(state=tk.DISABLED)
|
|
|
+ btn.config(image=self.button_img_disabled[k])
|
|
|
i += 1
|
|
|
|
|
|
# Petrinets canvas
|
|
|
@@ -446,6 +482,15 @@ class PNInterface(tk.Tk):
|
|
|
self.grid_rowconfigure(1, weight=1)
|
|
|
|
|
|
self.setup()
|
|
|
+
|
|
|
+ def enable_buttons(self, commands):
|
|
|
+ for (k, btn) in self.buttons_vis.items():
|
|
|
+ if k in commands:
|
|
|
+ btn.config(state=tk.NORMAL)
|
|
|
+ btn.config(image=self.button_img[k])
|
|
|
+ else:
|
|
|
+ btn.config(state=tk.DISABLED)
|
|
|
+ btn.config(image=self.button_img_disabled[k])
|
|
|
|
|
|
def setup(self):
|
|
|
free = PlaceVis(self.pn_canvas, 100, 200, "free", 3)
|
|
|
@@ -506,8 +551,8 @@ class PNInterface(tk.Tk):
|
|
|
|
|
|
def place_to_transition(self):
|
|
|
def create_p2t(attr_vals, window):
|
|
|
- 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"]]
|
|
|
+ src = [p for p in places if p.get_name() == attr_vals["src"]]
|
|
|
+ dst = [t for t in transitions if t.get_name() == attr_vals["dst"]]
|
|
|
if len(src) == 1 and len(dst) == 1:
|
|
|
global p2ts
|
|
|
p2ts.append(PlaceToTransitionVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
|
|
|
@@ -518,8 +563,8 @@ class PNInterface(tk.Tk):
|
|
|
|
|
|
def transition_to_place(self):
|
|
|
def create_t2p(attr_vals, window):
|
|
|
- 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"]]
|
|
|
+ src = [t for t in transitions if t.get_name() == attr_vals["src"]]
|
|
|
+ dst = [p for p in places if p.get_name() == attr_vals["dst"]]
|
|
|
if len(src) == 1 and len(dst) == 1:
|
|
|
global t2ps
|
|
|
t2ps.append(TransitionToPlaceVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
|
|
|
@@ -529,6 +574,7 @@ class PNInterface(tk.Tk):
|
|
|
editor = AttributeEditor('Create T2P', {"weight": 1, "src": "", "dst": ""}, create_t2p)
|
|
|
|
|
|
def load(self):
|
|
|
+ self.enable_buttons([])
|
|
|
with open("model.mvc", "w+") as model_file:
|
|
|
for p in places:
|
|
|
model_file.write("Place %s {\n" % p.name.replace(" ", "_"))
|
|
|
@@ -592,40 +638,70 @@ class PNInterface(tk.Tk):
|
|
|
node_id = n['node_id']
|
|
|
if len([m for m in self.markings if m.node_id == node_id]) == 0:
|
|
|
self.markings.append(MarkingVis(self.rg_canvas, 100, 50, node_id, n['node_marking']))
|
|
|
+ elif parsed_value["msg_type"] == "input_required":
|
|
|
+ if (not self.breakpoint_info_entered):
|
|
|
+ with cond:
|
|
|
+ cond.wait()
|
|
|
+ if parsed_value["name"] == "breakpoint name":
|
|
|
+ return self.breakpoint_name
|
|
|
+ elif parsed_value["name"] == "disable on trigger?":
|
|
|
+ return self.breakpoint_disable_on_trigger
|
|
|
+ elif parsed_value["name"] == "breakpoint function":
|
|
|
+ upload_code(self.breakpoint_code)
|
|
|
+ elif parsed_value["msg_type"] == "enabled_commands":
|
|
|
+ self.enable_buttons(set(parsed_value["commands"]))
|
|
|
+ with cond:
|
|
|
+ cond.wait()
|
|
|
+ return self.sim_mode
|
|
|
+ elif parsed_value["msg_type"] == "unexplored_markings":
|
|
|
+ unexplored_markings = set(parsed_value["markings"])
|
|
|
+ for m in self.markings:
|
|
|
+ if m.node_id in unexplored_markings:
|
|
|
+ m.set_current(True)
|
|
|
+ global small_step_input
|
|
|
+ small_step_input = None
|
|
|
+ while (small_step_input == None or small_step_input['type'] != 'selected_marking'):
|
|
|
+ print 'waiting'
|
|
|
+ with small_step_cond:
|
|
|
+ small_step_cond.wait()
|
|
|
+ print 'waiting done'
|
|
|
+ if (small_step_input['type'] == 'selected_marking'):
|
|
|
+ self.load_marking(small_step_input['value'])
|
|
|
+ return small_step_input['value']
|
|
|
+ elif parsed_value["msg_type"] == "enabled_transitions":
|
|
|
+ enabled_transitions = set(parsed_value["transitions"])
|
|
|
+ for t in transitions:
|
|
|
+ if t.name in enabled_transitions:
|
|
|
+ t.set_enabled(True)
|
|
|
+ global small_step_input
|
|
|
+ small_step_input = None
|
|
|
+ while (small_step_input == None or small_step_input['type'] != 'selected_transition'):
|
|
|
+ print 'waiting'
|
|
|
+ with small_step_cond:
|
|
|
+ small_step_cond.wait()
|
|
|
+ print 'waiting done'
|
|
|
+ if (small_step_input['type'] == 'selected_transition'):
|
|
|
+ for t in transitions:
|
|
|
+ t.set_enabled(False)
|
|
|
+ for m in self.markings:
|
|
|
+ m.set_current(False)
|
|
|
+ return small_step_input['value']
|
|
|
+ elif parsed_value["msg_type"] == "mode_change":
|
|
|
+ if parsed_value["mode"] == "paused":
|
|
|
+ with cond:
|
|
|
+ cond.wait()
|
|
|
+ return self.sim_mode
|
|
|
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 load_marking(self, node_id):
|
|
|
+ marking = [m for m in self.markings if m.node_id == node_id][0]
|
|
|
+ for (k, v) in marking.marking_val.iteritems():
|
|
|
+ place = [p for p in places if p.name == k][0]
|
|
|
+ place.set_tokens(v)
|
|
|
|
|
|
def continuous(self):
|
|
|
self.sim_mode = "continuous"
|
|
|
@@ -646,16 +722,51 @@ class PNInterface(tk.Tk):
|
|
|
self.sim_mode = "add_breakpoint"
|
|
|
with cond:
|
|
|
cond.notify()
|
|
|
+ self.breakpoint_name = None
|
|
|
+ self.breakpoint_disable_on_trigger = False
|
|
|
+ self.breakpoint_code = None
|
|
|
+ def edit_done(attr_vals, window):
|
|
|
+ self.breakpoint_name = attr_vals["breakpoint name"]
|
|
|
+ if attr_vals["disable on trigger?"] == "True":
|
|
|
+ self.breakpoint_disable_on_trigger = True
|
|
|
+ window.destroy()
|
|
|
+ with cond:
|
|
|
+ cond.notify()
|
|
|
+ self.breakpoint_info_entered = True
|
|
|
+ self.breakpoint_info_entered = False
|
|
|
+ editor = AttributeEditor('Input', {"breakpoint name": "", "disable on trigger?": "True"}, edit_done)
|
|
|
+ self.breakpoint_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["produced"])
|
|
|
+ msg = "produced = " + msg
|
|
|
+ log(msg)
|
|
|
+ if (integer_gt(node["produced"], 0)):
|
|
|
+ return True!
|
|
|
+ return False!
|
|
|
+ """
|
|
|
|
|
|
def clicked(self, event):
|
|
|
if hasattr(event.widget, 'clicked') and event.widget.clicked:
|
|
|
event.widget.clicked = False
|
|
|
return
|
|
|
+ global places
|
|
|
+ global transitions
|
|
|
if self.mode in ["PLACE", "TRANSITION"]:
|
|
|
if self.mode == "PLACE":
|
|
|
- self.places.append(PlaceVis(self.pn_canvas, event.x, event.y))
|
|
|
+ places.append(PlaceVis(self.pn_canvas, event.x, event.y))
|
|
|
if self.mode == "TRANSITION":
|
|
|
- self.transitions.append(TransitionVis(self.pn_canvas, event.x, event.y))
|
|
|
+ transitions.append(TransitionVis(self.pn_canvas, event.x, event.y))
|
|
|
|
|
|
def draw(self, event):
|
|
|
pass
|