Browse Source

Nicer use of connecting lines

Yentl Van Tendeloo 8 years ago
parent
commit
329e113fe7
3 changed files with 33 additions and 17 deletions
  1. 14 6
      classes/canvas/canvas.xml
  2. 15 7
      frontend.py
  3. 4 4
      models/render_SCD.alc

+ 14 - 6
classes/canvas/canvas.xml

@@ -96,13 +96,17 @@
                     source_y = self.group_location[element['__source']][1] + element['offsetSourceY']
                     source_y = self.group_location[element['__source']][1] + element['offsetSourceY']
                     target_x = self.group_location[element['__target']][0] + element['offsetTargetX']
                     target_x = self.group_location[element['__target']][0] + element['offsetTargetX']
                     target_y = self.group_location[element['__target']][1] + element['offsetTargetY']
                     target_y = self.group_location[element['__target']][1] + element['offsetTargetY']
+                    middle_x = (source_x + target_x) / 2
+                    middle_y = (source_y + target_y) / 2
 
 
                     self.connecting_lines.setdefault(element['__source'], []).append(element)
                     self.connecting_lines.setdefault(element['__source'], []).append(element)
                     self.connecting_lines.setdefault(element['__target'], []).append(element)
                     self.connecting_lines.setdefault(element['__target'], []).append(element)
 
 
-                    line = self.create_line(source_x, source_y, target_x, target_y, fill=element['lineColour'], width=element['lineWidth'], arrow=tk.LAST if element['arrow'] else tk.NONE)
-                    element['elem'] = line
-                    self.lines.add(line)
+                    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)
+                    self.lines.add(line1)
+                    self.lines.add(line2)
                 </script>
                 </script>
             </transition>
             </transition>
 
 
@@ -115,19 +119,23 @@
                         lines_to_move = self.connecting_lines[group_element]
                         lines_to_move = self.connecting_lines[group_element]
 
 
                         for line_element in lines_to_move:
                         for line_element in lines_to_move:
-                            source_x, source_y, target_x, target_y = self.coords(line_element['elem'])
+                            source_x, source_y, _, _ = self.coords(line_element['elem'][0])
+                            _, _, target_x, target_y = self.coords(line_element['elem'][1])
 
 
                             if line_element['__source'] == group_element:
                             if line_element['__source'] == group_element:
                                 # Moved source
                                 # Moved source
                                 source_x = self.group_location[group_element][0] + line_element['offsetSourceX']
                                 source_x = self.group_location[group_element][0] + line_element['offsetSourceX']
                                 source_y = self.group_location[group_element][1] + line_element['offsetSourceY']
                                 source_y = self.group_location[group_element][1] + line_element['offsetSourceY']
-
                             if line_element['__target'] == group_element:
                             if line_element['__target'] == group_element:
                                 # Moved target
                                 # Moved target
                                 target_x = self.group_location[group_element][0] + line_element['offsetTargetX']
                                 target_x = self.group_location[group_element][0] + line_element['offsetTargetX']
                                 target_y = self.group_location[group_element][1] + line_element['offsetTargetY']
                                 target_y = self.group_location[group_element][1] + line_element['offsetTargetY']
 
 
-                            self.coords(line_element['elem'], source_x, source_y, target_x, target_y)
+                            middle_x = (source_x + target_x) / 2
+                            middle_y = (source_y + target_y) / 2
+
+                            self.coords(line_element['elem'][0], source_x, source_y, middle_x, middle_y)
+                            self.coords(line_element['elem'][1], middle_x, middle_y, target_x, target_y)
                 </script>
                 </script>
             </transition>
             </transition>
         </state>
         </state>

+ 15 - 7
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:   Mon Oct  2 11:56:15 2017
+Date:   Mon Oct  2 12:47:20 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   Modelverse Visual Editor - Tkinter Version 
 Model name:   Modelverse Visual Editor - Tkinter Version 
@@ -6763,13 +6763,17 @@ class Canvas(RuntimeClassBase, tk.Canvas, SCCDWidget):
         source_y = self.group_location[element['__source']][1] + element['offsetSourceY']
         source_y = self.group_location[element['__source']][1] + element['offsetSourceY']
         target_x = self.group_location[element['__target']][0] + element['offsetTargetX']
         target_x = self.group_location[element['__target']][0] + element['offsetTargetX']
         target_y = self.group_location[element['__target']][1] + element['offsetTargetY']
         target_y = self.group_location[element['__target']][1] + element['offsetTargetY']
+        middle_x = (source_x + target_x) / 2
+        middle_y = (source_y + target_y) / 2
         
         
         self.connecting_lines.setdefault(element['__source'], []).append(element)
         self.connecting_lines.setdefault(element['__source'], []).append(element)
         self.connecting_lines.setdefault(element['__target'], []).append(element)
         self.connecting_lines.setdefault(element['__target'], []).append(element)
         
         
-        line = self.create_line(source_x, source_y, target_x, target_y, fill=element['lineColour'], width=element['lineWidth'], arrow=tk.LAST if element['arrow'] else tk.NONE)
-        element['elem'] = line
-        self.lines.add(line)
+        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)
+        self.lines.add(line1)
+        self.lines.add(line2)
     
     
     def _ready_4_guard(self, parameters):
     def _ready_4_guard(self, parameters):
         element = parameters[0]
         element = parameters[0]
@@ -6783,19 +6787,23 @@ class Canvas(RuntimeClassBase, tk.Canvas, SCCDWidget):
             lines_to_move = self.connecting_lines[group_element]
             lines_to_move = self.connecting_lines[group_element]
         
         
             for line_element in lines_to_move:
             for line_element in lines_to_move:
-                source_x, source_y, target_x, target_y = self.coords(line_element['elem'])
+                source_x, source_y, _, _ = self.coords(line_element['elem'][0])
+                _, _, target_x, target_y = self.coords(line_element['elem'][1])
         
         
                 if line_element['__source'] == group_element:
                 if line_element['__source'] == group_element:
                     # Moved source
                     # Moved source
                     source_x = self.group_location[group_element][0] + line_element['offsetSourceX']
                     source_x = self.group_location[group_element][0] + line_element['offsetSourceX']
                     source_y = self.group_location[group_element][1] + line_element['offsetSourceY']
                     source_y = self.group_location[group_element][1] + line_element['offsetSourceY']
-        
                 if line_element['__target'] == group_element:
                 if line_element['__target'] == group_element:
                     # Moved target
                     # Moved target
                     target_x = self.group_location[group_element][0] + line_element['offsetTargetX']
                     target_x = self.group_location[group_element][0] + line_element['offsetTargetX']
                     target_y = self.group_location[group_element][1] + line_element['offsetTargetY']
                     target_y = self.group_location[group_element][1] + line_element['offsetTargetY']
         
         
-                self.coords(line_element['elem'], source_x, source_y, target_x, target_y)
+                middle_x = (source_x + target_x) / 2
+                middle_y = (source_y + target_y) / 2
+        
+                self.coords(line_element['elem'][0], source_x, source_y, middle_x, middle_y)
+                self.coords(line_element['elem'][1], middle_x, middle_y, target_x, target_y)
     
     
     def _creating_group_0_exec(self, parameters):
     def _creating_group_0_exec(self, parameters):
         assoc_name = parameters[0]
         assoc_name = parameters[0]

+ 4 - 4
models/render_SCD.alc

@@ -144,10 +144,10 @@ Boolean function main(model : Element):
 		attr_keys = dict_keys(getAttributeList(model, class))
 		attr_keys = dict_keys(getAttributeList(model, class))
 
 
 		elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
 		elem = instantiate_link(model, "rendered/ConnectingLine", "", groups[readAssociationSource(model, class)], groups[readAssociationDestination(model, class)])
-		instantiate_attribute(model, elem, "offsetSourceX", 0)
-		instantiate_attribute(model, elem, "offsetSourceY", 0)
-		instantiate_attribute(model, elem, "offsetTargetX", 0)
-		instantiate_attribute(model, elem, "offsetTargetY", 0)
+		instantiate_attribute(model, elem, "offsetSourceX", 75)
+		instantiate_attribute(model, elem, "offsetSourceY", 30)
+		instantiate_attribute(model, elem, "offsetTargetX", 75)
+		instantiate_attribute(model, elem, "offsetTargetY", 30)
 		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", True)
 		instantiate_attribute(model, elem, "arrow", True)