소스 검색

Deserialize communication and fix small textual bug

Yentl Van Tendeloo 8 년 전
부모
커밋
3718eccc04
2개의 변경된 파일51개의 추가작업 그리고 25개의 파일을 삭제
  1. 1 1
      integration/code/cbd_design.mvc
  2. 50 24
      interface/CBD/main.py

+ 1 - 1
integration/code/cbd_design.mvc

@@ -5,7 +5,7 @@ SCD CausalBlockDiagrams_Design{
     Class Float {
         $
             if (bool_not(is_physical_float(self))):
-                return "Natural has no float value"!
+                return "Float has no float value"!
             else:
                 return "OK"!
         $

+ 50 - 24
interface/CBD/main.py

@@ -5,8 +5,12 @@ from matplotlib.figure import Figure
 
 from Tkinter import *
 import tkSimpleDialog
+
 import urllib
 import urllib2
+import json
+
+import time
 
 JUMP = 40
 MAX_WIDTH = 20 * JUMP
@@ -68,26 +72,32 @@ def poll(address):
     working_simulation = None
 
     while 1:
-        print("Waiting for input for server!")
-        returnvalue = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
+        returnvalue = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read())
         print("Process " + str(returnvalue))
         if (returnvalue.startswith("AVAILABLE_ATTR_VALUE")):
-            working_available_attrs.append((returnvalue.split(" ", 1)[1], None))
+            working_available_attrs.append([json.loads(returnvalue.split(" ", 1)[1]), None])
         elif (returnvalue.startswith("AVAILABLE_ATTR_TYPE")):
-            working_available_attrs[-1][1] = returnvalue.split(" ", 1)[1]
+            working_available_attrs[-1][1] = json.loads(returnvalue.split(" ", 1)[1])
         elif (returnvalue.startswith("AVAILABLE_ATTR_END")):
-            available_attrs.append(working_available)
-            working_available = []
+            available_attrs.append(working_available_attrs)
+            working_available_attrs = []
         elif (returnvalue.startswith("ATTR_VALUE")):
-            attribute.append(returnvalue.split(" ", 1)[1])
+            v = returnvalue.split(" ", 1)[1]
+            if v == "None":
+                v = None
+            else:
+                v = json.loads(v)
+            attribute.append(v)
         elif (returnvalue.startswith("SIM_TIME")):
-            working_simulation = (float(returnvalue.split(" ", 1)[1]), {})
+            working_simulation = (json.loads(returnvalue.split(" ", 1)[1]), {})
         elif (returnvalue.startswith("SIM_PROBE")):
             blockname, blockvalue = returnvalue.split(" ", 1)[1].rsplit(" ", 1)
-            working_simulation[1][blockname] = blockvalue
+            working_simulation[1][json.loads(blockname)] = json.loads(blockvalue)
         elif (returnvalue.startswith("SIM_END")):
             simulation.append(working_simulation)
             working_simulation = None
+        else:
+            print("Error: got unknown result: " + returnvalue)
 
 class MvLayer():
     def __init__(self, address):
@@ -156,9 +166,6 @@ class InterfaceCore():
     mode = ""
     drawn = set()
     refs = dict()
-    mappings = {"+": "AdditionBlock",
-                "-": "NegationBlock",
-               }
 
     mv = MvLayer(address)
     #mv = FakeLayer(address)
@@ -167,7 +174,7 @@ class InterfaceCore():
         self.mode = mode
 
     def clicked(self, event):
-        if self.mode not in ["+", "-"]:
+        if self.mode not in ["AdditionBlock", "NegatorBlock", "ConstantBlock", "MultiplyBlock", "ConstantBlock"]:
             print("Cannot create something not guaranteed to be block type!")
         else:
             if self.find((event.x, event.y)):
@@ -175,10 +182,13 @@ class InterfaceCore():
                 lname = self.find((event.x, event.y))
 
                 attrs = self.mv.read_available_attributes(lname)
+                print("Managing " + str(attrs))
+
                 if not attrs:
                     print("No attrs to manage!")
 
                 for attr, t in attrs:
+                    print("Reading data from " + str(attr))
                     old_value = self.mv.read_attribute(lname, attr)
                     if old_value == "None":
                         old_value = None
@@ -192,7 +202,7 @@ class InterfaceCore():
                 global name
                 x = event.x
                 y = event.y
-                self.mv.instantiate_block(str(name), self.mappings[self.mode])
+                self.mv.instantiate_block(str(name), self.mode)
                 r = canvas.create_rectangle(lower(x), lower(y), upper(x), upper(y), fill="white")
                 t = canvas.create_text(avg(lower(x), upper(x)), avg(lower(y), upper(y)), text=self.mode, fill="black")
                 b = (lower(x), lower(y), upper(x), upper(y), str(name))
@@ -229,15 +239,6 @@ class InterfaceCore():
 
 core = InterfaceCore()
 
-def addition():
-    core.set_mode("+")
-
-def negation():
-    core.set_mode("-")
-
-def link():
-    core.set_mode("Link")
-
 def clicked(event):
     core.clicked(event)
 
@@ -257,10 +258,35 @@ def step():
 def pause():
     core.mv.pause()
 
+def addition():
+    core.set_mode("AdditionBlock")
+
+def negation():
+    core.set_mode("NegatorBlock")
+
+def link():
+    core.set_mode("Link")
+
+def multiply():
+    core.set_mode("MultiplyBlock")
+
+def constant():
+    core.set_mode("ConstantBlock")
+
+def inverse():
+    core.set_mode("InverseBlock")
+
+def ic():
+    core.set_mode("IC")
+
 Button(root, text="+", command=addition).pack()
-Button(root, text="-", command=negation).pack()
+Button(root, text="-x", command=negation).pack()
+Button(root, text="*", command=multiply).pack()
+Button(root, text="1/x", command=inverse).pack()
+Button(root, text="C", command=constant).pack()
 
 Button(root, text="Link", command=link).pack()
+Button(root, text="IC", command=ic).pack()
 
 Button(root, text="SIM", command=simulate).pack()
 Button(root, text="STEP", command=step).pack()