Jelajahi Sumber

Working renderer

Yentl Van Tendeloo 8 tahun lalu
induk
melakukan
cd86678ef8
2 mengubah file dengan 62 tambahan dan 3 penghapusan
  1. 62 0
      interface/graphical/main.py
  2. 0 3
      models/MM_rendered_graphical.mvc

+ 62 - 0
interface/graphical/main.py

@@ -33,8 +33,70 @@ available_mappers = []
 model_options = OptionMenu(root, selected_model, *[i[0] for i in available_models])
 mapper_options = OptionMenu(root, selected_mapper, "", *available_mappers)
 
+
 def visualize(model):
     print("Visualizing model: " + str(model))
+    cache = {}
+    hierarchy = {}
+    parent = {}
+
+    def findXY(element_id):
+        print(cache[element_id])
+        x = cache[element_id]["x"]
+        y = cache[element_id]["y"]
+
+        while element_id in parent:
+            # Has a parent (group), so increment the XY values and keep going
+            element_id = parent[element_id]
+            x += cache[element_id]["x"]
+            y += cache[element_id]["y"]
+
+        return x, y
+
+    for element in model:
+        # Determine type of element
+        cache[element["id"]] = element
+        t = element["type"]
+
+        if t == "contains":
+            # Cache the containment links as well
+            parent[element["__target"]] = element["__source"]
+
+    # Caches filled, so go over all elements, ignoring groups, and draw them relative to their enclosing groups
+    for element in model:
+        t = element["type"]
+        if t in ["Rectangle", "Ellipse", "Line", "Text", "Figure"]:
+            x, y = findXY(element["id"])
+
+        if t == "Rectangle":
+            fillColour = element["fillColour"]
+            width = element["width"]
+            height = element["height"]
+            lineWidth = element["lineWidth"]
+            lineColour = element["lineColour"]
+            print("Coordinates: " + str((x, y, x+width, y+height)))
+            canvas.create_rectangle(x, y, x+width, y+height, fill=fillColour, outline=lineColour)
+        elif t == "Ellipse":
+            fillColour = element["fillColour"]
+            width = element["width"]
+            height = element["height"]
+            lineWidth = element["lineWidth"]
+            lineColour = element["lineColour"]
+            canvas.create_ellipse(x, y, x+width, y+height, fill=fillColour, outline=lineColour)
+        elif t == "Line":
+            targetX = element["targetX"]
+            targetY = element["targetY"]
+            lineWidth = element["lineWidth"]
+            lineColour = element["lineColour"]
+            canvas.create_line(x, y, targetX, targetY, fill=lineColour, width=lineWidth)
+        elif t == "Text":
+            lineWidth = element["lineWidth"]
+            lineColour = element["lineColour"]
+            text = element["text"]
+            canvas.create_text(x, y, fill=lineColour, text=text)
+        elif t == "Figure":
+            # Fetch associated SVG figure
+            raise NotImplementedError()
 
 def reset_optionmenu(optionmenu, options, var):
     menu = optionmenu.children["menu"]

+ 0 - 3
models/MM_rendered_graphical.mvc

@@ -47,9 +47,6 @@ SimpleClassDiagram MM_rendered_graphical{
     Class Ellipse : Shape {
     }
 
-    Class Polygon : Shape {
-    }
-
     Association contains (Group, GraphicalElement) {}
     Association renders (Figure, SVG) {
         source_lower_cardinality = 1