Procházet zdrojové kódy

Fixed object diagrams with disappearing associations after rerender

Yentl Van Tendeloo před 8 roky
rodič
revize
a5eaf444ca
3 změnil soubory, kde provedl 24 přidání a 21 odebrání
  1. 5 0
      classes/canvas/canvas.xml
  2. 6 1
      frontend.py
  3. 13 20
      models/render_OD.alc

+ 5 - 0
classes/canvas/canvas.xml

@@ -85,6 +85,7 @@
                     for l in self.lines:
                         self.delete(l)
                     self.connecting_lines = {}
+                    self.group_location = {}
                 </script>
             </transition>
 
@@ -93,6 +94,7 @@
                 <script>
                     self.creating_id = element["id"]
                     self.group_location[element['id']] = (element['x'], element['y'])
+                    print("Creating new group %s --> %s" % (element['id'], (element['x'], element['y'])))
                 </script>
                 <raise event="create_instance" scope="cd">
                     <parameter expr="'elements'"/>
@@ -132,6 +134,9 @@
                     self.connecting_lines.setdefault(element['__source'], []).append(element)
                     self.connecting_lines.setdefault(element['__target'], []).append(element)
 
+                    print("DRAW connecting line from ((%s, %s) to (%s, %s))" % (source_x, source_y, target_x, target_y))
+                    print("Source: " + str(element['__source']))
+                    print("Target: " + str(element['__target']))
                     line1 = self.create_line(source_x, source_y, middle_x, middle_y, fill=element['lineColour'], width=element['lineWidth'], arrow=tk.LAST if element['arrow'] else tk.NONE)
                     line2 = self.create_line(middle_x, middle_y, target_x, target_y, fill=element['lineColour'], width=element['lineWidth'])
                     element['elem'] = (line1, line2)

+ 6 - 1
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)
 
-Date:   Thu Oct  5 14:45:25 2017
+Date:   Thu Oct  5 15:39:06 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   Modelverse Visual Editor - Tkinter Version 
@@ -7219,11 +7219,13 @@ class Canvas(RuntimeClassBase, tk.Canvas, SCCDWidget):
         for l in self.lines:
             self.delete(l)
         self.connecting_lines = {}
+        self.group_location = {}
     
     def _ready_1_exec(self, parameters):
         element = parameters[0]
         self.creating_id = element["id"]
         self.group_location[element['id']] = (element['x'], element['y'])
+        print("Creating new group %s --> %s" % (element['id'], (element['x'], element['y'])))
         self.big_step.outputEventOM(Event("create_instance", None, [self, 'elements', 'CanvasElement', self, (element['x'], element['y']), element['id'], element['__asid']]))
     
     def _ready_2_exec(self, parameters):
@@ -7251,6 +7253,9 @@ class Canvas(RuntimeClassBase, tk.Canvas, SCCDWidget):
         self.connecting_lines.setdefault(element['__source'], []).append(element)
         self.connecting_lines.setdefault(element['__target'], []).append(element)
         
+        print("DRAW connecting line from ((%s, %s) to (%s, %s))" % (source_x, source_y, target_x, target_y))
+        print("Source: " + str(element['__source']))
+        print("Target: " + str(element['__target']))
         line1 = self.create_line(source_x, source_y, middle_x, middle_y, fill=element['lineColour'], width=element['lineWidth'], arrow=tk.LAST if element['arrow'] else tk.NONE)
         line2 = self.create_line(middle_x, middle_y, target_x, target_y, fill=element['lineColour'], width=element['lineWidth'])
         element['elem'] = (line1, line2)

+ 13 - 20
models/render_OD.alc

@@ -63,26 +63,14 @@ Boolean function main(model : Element):
 				if (dict_in(as_to_cs, class)):
 					// Yes, but is it still clean?
 					Element related_groups
-					Boolean dirty
-					dirty = False
-
-					related_groups = as_to_cs[class]
-					while (set_len(related_groups) > 0):
-						group = set_pop(related_groups)
-						if (value_eq(read_attribute(model, group, "dirty"), True)):
-							// No, so mark all as dirty
-							dirty = True
-							break!
-						else:
-							// Yes, so just ignore this!
-							continue!
-
-					if (bool_not(dirty)):
+					group = as_to_cs[class]
+
+					if (bool_not(read_attribute(model, group, "dirty"))):
 						dict_add(groups, class, group)
+						log("Element not dirty, so reuse group " + group)
 						continue!
 					else:
 						group = as_to_cs[class]
-						group = set_pop(related_groups)
 						to_remove = allAssociationDestinations(model, group, "rendered/contains")
 						x = create_value(read_attribute(model, group, "x"))
 						y = create_value(read_attribute(model, group, "y"))
@@ -94,9 +82,11 @@ Boolean function main(model : Element):
 							else:
 								model_delete_element(model, elem_to_remove)
 						model_delete_element(model, group)
+						log("Element dirty, so remove group " + group)
 
 				if (dict_in(groups, class)):
 					// Already rendered this, so skip
+					log("Already rendered, so skip " + class)
 					continue!
 
 				text_loc = 5
@@ -106,6 +96,7 @@ Boolean function main(model : Element):
 				instantiate_attribute(model, group, "y", y)
 				instantiate_attribute(model, group, "__asid", list_read(string_split(class, "/"), 1))
 				dict_add(groups, class, group)
+				log("Created new group " + group + " for element " + class)
 
 				loc_x = loc_x + 250
 				if (loc_x > 2000):
@@ -184,14 +175,16 @@ Boolean function main(model : Element):
 			class = list_pop_final(to_render)
 			attr_keys = dict_keys(getAttributes(model, class))
 
-			log("Association: " + class)
-			log("Connects " + cast_v2s(readAssociationSource(model, class)))
-			log("      to " + cast_v2s(readAssociationDestination(model, class)))
 			if (bool_not(bool_and(dict_in(groups, readAssociationSource(model, class)), dict_in(groups, readAssociationDestination(model, class))))):
-				log("DELAY")
 				list_append(delayed_elements, class)
 				continue!
 
+			log("Association: " + class)
+			log("Connects " + cast_v2s(readAssociationSource(model, class)))
+			log(" (group) " + cast_v2s(groups[readAssociationSource(model, class)]))
+			log("      to " + cast_v2s(readAssociationDestination(model, class)))
+			log(" (group) " + cast_v2s(groups[readAssociationDestination(model, class)]))
+
 			elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
 			dict_add(groups, class, elem)
 			if (is_edge(model["model"][readAssociationSource(model, class)])):