Yentl Van Tendeloo 8 лет назад
Родитель
Сommit
c10268c2b1
2 измененных файлов с 20 добавлено и 2 удалено
  1. 5 1
      integration/code/cbd_semantics.alc
  2. 15 1
      interface/CBD/main.py

+ 5 - 1
integration/code/cbd_semantics.alc

@@ -298,7 +298,7 @@ Void function execute_cbd(design_model : Element):
 			// Returns the value of an attribute
 			output("ATTR_VALUE " + cast_v2s(read_attribute(design_model, input(), input())))
 
-		elif (bool_or(bool_or(cmd == "set_attribute", cmd == "instantiate_node"), cmd == "instantiate_association")):
+		elif (bool_or(bool_or(cmd == "set_attribute", cmd == "instantiate_node"), bool_or(cmd == "delete_element", cmd == "instantiate_association"))):
 			// Modify the structure
 			if (cmd == "set_attribute"):
 				// Setting an attribute
@@ -322,6 +322,10 @@ Void function execute_cbd(design_model : Element):
 				// Instantiate an association
 				instantiate_link(design_model, input(), input(), input(), input())
 
+			elif (cmd == "delete_element"):
+				// Delete the provided element
+				model_delete_element(design_model, input())
+
 			// After changes, we check whether or not the design model conforms
 			conforming = conformance_scd(design_model)
 			if (conforming == "OK"):

+ 15 - 1
interface/CBD/main.py

@@ -65,7 +65,6 @@ class FakeLayer():
 attribute = []
 available_attrs = []
 simulation = []
-#simulation = [(1, {"a": 1, "b": 2}), (2, {"a": 3}), (3, {"a": 4, "b": 6})]
 
 def poll(address):
     working_available_attrs = []
@@ -157,6 +156,10 @@ class MvLayer():
     def pause(self):
         urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"pause"', "username": username}))).read()
 
+    def delete(self, block):
+        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 lower(value):
     return value / JUMP * JUMP
 
@@ -177,6 +180,12 @@ class InterfaceCore():
     def set_mode(self, mode):
         self.mode = mode
 
+    def delete(self, x, y):
+        lname = self.find((x, y))
+        self.mv.delete(lname)
+        for i in self.refs[lname]:
+            canvas.delete(i)
+
     def clicked(self, event):
         if self.find((event.x, event.y)):
             # Something already there, so don't add, but modify
@@ -287,6 +296,10 @@ def ic():
 def delay():
     core.set_mode("DelayBlock")
 
+def delete(event):
+    print("DELETE")
+    core.delete(event.x, event.y)
+
 Button(root, text="+", command=addition).pack()
 Button(root, text="-x", command=negation).pack()
 Button(root, text="*", command=multiply).pack()
@@ -309,6 +322,7 @@ for i in range(JUMP, MAX_WIDTH, JUMP):
     canvas.create_line(i, 0, i, MAX_WIDTH, fill="grey")
 
 canvas.bind("<Button-1>", clicked)
+canvas.bind("<Button-2>", delete)
 canvas.bind("<Button-3>", draw)
 canvas.bind("<ButtonRelease-3>", release)