Sfoglia il codice sorgente

Also draw associations

Yentl Van Tendeloo 8 anni fa
parent
commit
97be3e06ba
4 ha cambiato i file con 37 aggiunte e 20 eliminazioni
  1. 1 1
      classes/canvas/canvas.xml
  2. 2 2
      frontend.py
  3. 2 0
      models/MM_render.mvc
  4. 32 17
      models/render_SCD.alc

+ 1 - 1
classes/canvas/canvas.xml

@@ -80,7 +80,7 @@
                     elif element["type"] == "Text":
                     elif element["type"] == "Text":
                         self.create_text(elem_x, elem_y, fill=element["lineColour"], text=element["text"], anchor=tk.NW)
                         self.create_text(elem_x, elem_y, fill=element["lineColour"], text=element["text"], anchor=tk.NW)
                     elif element["type"] == "Line":
                     elif element["type"] == "Line":
-                        self.create_line(elem_x, elem_y, shift_x + element["targetX"], shift_y + element["targetY"], fill=element["lineColour"], width=element["lineWidth"])
+                        self.create_line(elem_x, elem_y, shift_x + element["targetX"], shift_y + element["targetY"], fill=element["lineColour"], width=element["lineWidth"], arrow=tk.LAST if element["arrow"] else tk.NONE)
                     else:
                     else:
                         print("Undefined render format: " + str(element))
                         print("Undefined render format: " + str(element))
                 </script>
                 </script>

+ 2 - 2
frontend.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Wed Sep 13 11:02:32 2017
+Date:   Wed Sep 13 11:45:24 2017
 
 
 Model author: Yentl Van Tendeloo and Addis Gebremichael
 Model author: Yentl Van Tendeloo and Addis Gebremichael
 Model name:   Modelverse Visual Editor - Tkinter Version 
 Model name:   Modelverse Visual Editor - Tkinter Version 
@@ -5633,7 +5633,7 @@ class Canvas(RuntimeClassBase, tk.Canvas, SCCDWidget):
         elif element["type"] == "Text":
         elif element["type"] == "Text":
             self.create_text(elem_x, elem_y, fill=element["lineColour"], text=element["text"], anchor=tk.NW)
             self.create_text(elem_x, elem_y, fill=element["lineColour"], text=element["text"], anchor=tk.NW)
         elif element["type"] == "Line":
         elif element["type"] == "Line":
-            self.create_line(elem_x, elem_y, shift_x + element["targetX"], shift_y + element["targetY"], fill=element["lineColour"], width=element["lineWidth"])
+            self.create_line(elem_x, elem_y, shift_x + element["targetX"], shift_y + element["targetY"], fill=element["lineColour"], width=element["lineWidth"], arrow=tk.LAST if element["arrow"] else tk.NONE)
         else:
         else:
             print("Undefined render format: " + str(element))
             print("Undefined render format: " + str(element))
     
     

+ 2 - 0
models/MM_render.mvc

@@ -2,6 +2,7 @@ include "primitives.alh"
 
 
 SimpleAttribute Natural {}
 SimpleAttribute Natural {}
 SimpleAttribute String {}
 SimpleAttribute String {}
+SimpleAttribute Boolean {}
 
 
 Class GraphicalElement {
 Class GraphicalElement {
     x : Natural
     x : Natural
@@ -24,6 +25,7 @@ Class Text : LineElement {
 Class Line : LineElement {
 Class Line : LineElement {
     targetX : Natural
     targetX : Natural
     targetY : Natural
     targetY : Natural
+    arrow : Boolean
 }
 }
 
 
 Class Shape : LineElement {
 Class Shape : LineElement {

+ 32 - 17
models/render_SCD.alc

@@ -3,9 +3,6 @@ include "modelling.alh"
 include "object_operations.alh"
 include "object_operations.alh"
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
-	log("Got model to render!")
-	log("Classes:")
-
 	Element elements
 	Element elements
 	String class
 	String class
 	Element attrs
 	Element attrs
@@ -17,9 +14,12 @@ Boolean function main(model : Element):
 	Integer text_loc
 	Integer text_loc
 	loc = 10
 	loc = 10
 
 
-	log("Classes:")
-	elements = allInstances(model, "abstract/Class")
+	Element locations_x
+	Element locations_y
+	locations_x = dict_create()
+	locations_y = dict_create()
 
 
+	elements = allInstances(model, "abstract/Class")
 	while (set_len(elements) > 0):
 	while (set_len(elements) > 0):
 		class = set_pop(elements)
 		class = set_pop(elements)
 		attr_keys = dict_keys(getAttributeList(model, class))
 		attr_keys = dict_keys(getAttributeList(model, class))
@@ -28,6 +28,8 @@ Boolean function main(model : Element):
 		group = instantiate_node(model, "rendered/Group", "")
 		group = instantiate_node(model, "rendered/Group", "")
 		instantiate_attribute(model, group, "x", loc)
 		instantiate_attribute(model, group, "x", loc)
 		instantiate_attribute(model, group, "y", 10)
 		instantiate_attribute(model, group, "y", 10)
+		dict_add(locations_x, class, loc)
+		dict_add(locations_y, class, 10)
 		loc = loc + 200
 		loc = loc + 200
 
 
 		elem = instantiate_node(model, "rendered/Rectangle", "")
 		elem = instantiate_node(model, "rendered/Rectangle", "")
@@ -68,6 +70,7 @@ Boolean function main(model : Element):
 		instantiate_attribute(model, elem, "targetY", 20)
 		instantiate_attribute(model, elem, "targetY", 20)
 		instantiate_attribute(model, elem, "lineWidth", 1)
 		instantiate_attribute(model, elem, "lineWidth", 1)
 		instantiate_attribute(model, elem, "lineColour", "black")
 		instantiate_attribute(model, elem, "lineColour", "black")
+		instantiate_attribute(model, elem, "arrow", False)
 		instantiate_link(model, "rendered/contains", "", group, elem)
 		instantiate_link(model, "rendered/contains", "", group, elem)
 
 
 		attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
 		attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
@@ -75,7 +78,6 @@ Boolean function main(model : Element):
 		while (dict_len(attr_keys) > 0):
 		while (dict_len(attr_keys) > 0):
 			attr_key = set_pop(attr_keys)
 			attr_key = set_pop(attr_keys)
 			elem = instantiate_node(model, "rendered/Text", "")
 			elem = instantiate_node(model, "rendered/Text", "")
-			log((("  " + attr_key) + " : ") + cast_v2s(list_read(string_split(attrs[attr_key], "/"), 1)))
 			instantiate_attribute(model, elem, "x", 5)
 			instantiate_attribute(model, elem, "x", 5)
 			instantiate_attribute(model, elem, "y", text_loc + 20)
 			instantiate_attribute(model, elem, "y", text_loc + 20)
 			instantiate_attribute(model, elem, "lineWidth", 1)
 			instantiate_attribute(model, elem, "lineWidth", 1)
@@ -84,24 +86,37 @@ Boolean function main(model : Element):
 			instantiate_link(model, "rendered/contains", "", group, elem)
 			instantiate_link(model, "rendered/contains", "", group, elem)
 			text_loc = text_loc + 15
 			text_loc = text_loc + 15
 
 
-		log("")
-
-	log("Associations:")
 	elements = allInstances(model, "abstract/Association")
 	elements = allInstances(model, "abstract/Association")
 	while (set_len(elements) > 0):
 	while (set_len(elements) > 0):
 		class = set_pop(elements)
 		class = set_pop(elements)
 		attr_keys = dict_keys(getAttributeList(model, class))
 		attr_keys = dict_keys(getAttributeList(model, class))
 
 
+		group = instantiate_node(model, "rendered/Group", "")
+		instantiate_attribute(model, group, "x", 0)
+		instantiate_attribute(model, group, "y", 0)
+
+		elem = instantiate_node(model, "rendered/Line", "")
+		instantiate_attribute(model, elem, "x", locations_x[readAssociationSource(model, class)])
+		instantiate_attribute(model, elem, "y", locations_y[readAssociationSource(model, class)])
+		instantiate_attribute(model, elem, "targetX", locations_x[readAssociationSource(model, class)])
+		instantiate_attribute(model, elem, "targetY", locations_y[readAssociationDestination(model, class)])
+		instantiate_attribute(model, elem, "lineWidth", 1)
+		instantiate_attribute(model, elem, "lineColour", "black")
+		instantiate_attribute(model, elem, "arrow", False)
+		instantiate_link(model, "rendered/contains", "", group, elem)
+
+		elem = instantiate_node(model, "rendered/Line", "")
+		instantiate_attribute(model, elem, "x", locations_x[readAssociationSource(model, class)])
+		instantiate_attribute(model, elem, "y", locations_y[readAssociationDestination(model, class)])
+		instantiate_attribute(model, elem, "targetX", locations_x[readAssociationDestination(model, class)])
+		instantiate_attribute(model, elem, "targetY", locations_y[readAssociationDestination(model, class)])
+		instantiate_attribute(model, elem, "lineWidth", 1)
+		instantiate_attribute(model, elem, "lineColour", "black")
+		instantiate_attribute(model, elem, "arrow", True)
+		instantiate_link(model, "rendered/contains", "", group, elem)
+
 		while (set_len(attr_keys) > 0):
 		while (set_len(attr_keys) > 0):
 			attr_key = set_pop(attr_keys)
 			attr_key = set_pop(attr_keys)
 			log((("  " + attr_key) + " = ") + cast_v2s(read_attribute(model, class, attr_key)))
 			log((("  " + attr_key) + " = ") + cast_v2s(read_attribute(model, class, attr_key)))
 
 
-		attrs = getInstantiatableAttributes(model, class, "abstract/AttributeLink")
-		attr_keys = dict_keys(attrs)
-		while (dict_len(attr_keys) > 0):
-			attr_key = set_pop(attr_keys)
-			log((("  " + attr_key) + " : ") + cast_v2s(list_read(string_split(attrs[attr_key], "/"), 1)))
-
-		log("")
-
 	return True!
 	return True!