Przeglądaj źródła

Fixed UI for initial state and added some new buttons and keybindings

Yentl Van Tendeloo 8 lat temu
rodzic
commit
8f74dccf7c
2 zmienionych plików z 59 dodań i 5 usunięć
  1. 4 1
      integration/code/fsa_semantics.alc
  2. 55 4
      interface/FSA/main.py

+ 4 - 1
integration/code/fsa_semantics.alc

@@ -112,6 +112,7 @@ Void function execute_fsa(design_model : Element):
 	String conforming
 	Float simulation_time
 	Float start_time
+	Boolean automatic_sanitization
 
 	start_time = time()
 	simulation_time = 0.0
@@ -147,6 +148,8 @@ Void function execute_fsa(design_model : Element):
 			start_time = time() - simulation_time
 			output("CONTINUE")
 		
+		elif (cmd == "auto_sanitize"):
+			automatic_sanitization = input()
 		elif (cmd == "event"):
 			String evt
 			evt = input()
@@ -213,7 +216,7 @@ Void function execute_fsa(design_model : Element):
 			if (conforming == "OK"):
 				// Conforming, so do the retyping and sanitization step
 				runtime_model = retype_to_runtime(design_model)
-				runtime_model = sanitize(runtime_model, old_runtime_model)
+				runtime_model = sanitize(runtime_model, old_runtime_model, automatic_sanitization)
 				schedule_init = create_schedule(runtime_model)
 				schedule_run = read_root()
 				old_runtime_model = runtime_model

+ 55 - 4
interface/FSA/main.py

@@ -26,6 +26,7 @@ username = "test"
 root = Tk()
 names = {}
 event_entry = StringVar()
+setting_initial = False
 
 canvas = Canvas(root, width=MAX_WIDTH, height=MAX_HEIGHT, bg="white")
 
@@ -50,7 +51,7 @@ class FakeLayer():
     def set_attribute(self, name, attr, value):
         self.attrs.setdefault(name, {})[attr] = value
 
-    def instantiate_block(self, name, block_type):
+    def instantiate_element(self, name, block_type):
         self.types[name] = block_type
 
     def instantiate_link(self, name, link_type, source, target):
@@ -68,6 +69,12 @@ class FakeLayer():
     def delete(self):
         pass
 
+    def switch_initial(self, name):
+        pass
+
+    def auto_sanitize(self, auto):
+        pass
+
 attribute = []
 available_attrs = []
 simulation = []
@@ -143,7 +150,7 @@ class MvLayer():
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % attr, "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": json.dumps(value), "username": username}))).read()
 
-    def instantiate_block(self, name, block_type):
+    def instantiate_element(self, name, block_type):
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"instantiate_node"', "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (block_type), "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (name), "username": username}))).read()
@@ -169,6 +176,14 @@ class MvLayer():
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"delete_element"', "username": username}))).read()
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (block), "username": username}))).read()
 
+    def switch_initial(self, name):
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"switch_initial"', "username": username}))).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (name), "username": username}))).read()
+
+    def auto_sanitize(self, auto):
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"auto_sanitize"', "username": username}))).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": "true" if auto else "false", "username": username}))).read()
+
 def lower(value):
     return value / JUMP * JUMP
 
@@ -209,6 +224,7 @@ class InterfaceCore():
                     old_value = None
 
                 new_value = tkSimpleDialog.askstring("Attribute modification", attr, initialvalue=old_value)
+                canvas.focus_set()
                 if t == "Float":
                     new_value = float(new_value)
                 elif t == "String":
@@ -231,13 +247,24 @@ class InterfaceCore():
             global name
             x = event.x
             y = event.y
-            self.mv.instantiate_block(str(name), "State")
+            self.mv.instantiate_element(str(name), "State")
             r = canvas.create_oval(lower(x), lower(y), upper(x), upper(y), fill="white")
             b = (lower(x), lower(y), upper(x), upper(y), str(name), "NODE")
             self.drawn.add(b)
             self.refs[str(name)] = [r]
             name += 1
 
+    def switch_initial(self, evt):
+        if self.find((evt.x, evt.y)):
+            lname = self.find((evt.x, evt.y))
+            self.mv.switch_initial(lname)
+
+            # Update visual representation
+            for f in self.refs.values():
+                self.canvas.itemconfigure(f, width=1)
+
+            self.canvas.itemconfigure(self.refs[lname], width=4)
+
     def find(self, location):
         def sqrt(a):
             return a**0.5
@@ -279,7 +306,10 @@ class InterfaceCore():
 core = InterfaceCore()
 
 def clicked(event):
-    core.clicked(event)
+    if setting_initial:
+        core.switch_initial(event)
+    else:
+        core.clicked(event)
 
 def draw(event):
     global start_location
@@ -300,9 +330,27 @@ def delete(event):
 def add_event():
     core.add_event(event_entry.get())
 
+def control_released(evt):
+    print("Control released")
+    global setting_initial
+    setting_initial = False
+
+def control_pressed(evt):
+    print("Control pressed")
+    global setting_initial
+    setting_initial = True
+
+def auto_sanitize():
+    core.mv.auto_sanitize(True)
+
+def manual_sanitize():
+    core.mv.auto_sanitize(False)
+
 buttons = [
         Button(root, text="START", command=simulate),
         Button(root, text="PAUSE", command=pause),
+        Button(root, text="AUTO", command=auto_sanitize),
+        Button(root, text="MANUAL", command=manual_sanitize),
         Entry(root, textvariable=event_entry),
         Button(root, text="EVENT", command=add_event),
     ]
@@ -319,6 +367,9 @@ for i in range(JUMP, MAX_HEIGHT, JUMP):
 for i in range(JUMP, MAX_WIDTH, JUMP):
     canvas.create_line(i, 0, i, MAX_WIDTH, fill="grey")
 
+canvas.focus_set()
+canvas.bind("<KeyPress-Control_L>", control_pressed)
+canvas.bind("<KeyRelease-Control_L>", control_released)
 canvas.bind("<Button-1>", clicked)
 canvas.bind("<Button-2>", delete)
 canvas.bind("<Button-3>", draw)