Bladeren bron

Fixed exceptions during creation of connecting lines

Yentl Van Tendeloo 8 jaren geleden
bovenliggende
commit
587ba90b3a
4 gewijzigde bestanden met toevoegingen van 19 en 10 verwijderingen
  1. 1 0
      classes/canvas/canvas_element.xml
  2. 6 5
      classes/canvas/connecting_line.xml
  3. 11 5
      frontend.py
  4. 1 0
      models/MM_render.mvc

+ 1 - 0
classes/canvas/canvas_element.xml

@@ -35,6 +35,7 @@
             <transition event="draw_element" target=".">
                 <parameter name="element"/>
                 <script>
+                    print("Create element with ID %s" % (element['id']))
                     elem_x = self.coordinates[0] + element["x"]
                     elem_y = self.coordinates[1] + element["y"]
                     if element["type"] == "Rectangle":

+ 6 - 5
classes/canvas/connecting_line.xml

@@ -28,7 +28,7 @@
 
     <scxml initial="init">
         <state id="init">
-            <transition target="../main">
+            <transition cond="self.cs_element['__source'] in self.containing_canvas.group_location and self.cs_element['__target'] in self.containing_canvas.group_location" target="../main">
                 <script>
                     print("Draw connecting line %s from %s to %s" % (self.cs_element['id'], self.cs_element['__source'], self.cs_element['__target']))
                     source_x = self.containing_canvas.group_location[self.cs_element['__source']][0] + self.cs_element['offsetSourceX']
@@ -40,7 +40,11 @@
 
                     self.containing_canvas.group_location[self.cs_element['id']] = (middle_x, middle_y)
 
-                    line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'], arrow=tk.LAST if self.cs_element['arrow'] else tk.NONE)
+                    if self.cs_element['arrow']:
+                        lw = self.cs_element['lineWidth']
+                        line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'], arrow=tk.LAST, arrowshape=(lw*8, lw*10, lw*3))
+                    else:
+                        line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'])
                     line2 = self.containing_canvas.create_line(middle_x, middle_y, target_x, target_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'])
                     self.cs_element['elem'] = (line1, line2)
                     self.elements.add(line1)
@@ -64,7 +68,6 @@
                 <parameter name="element"/>
                 <parameter name="new_location"/>
                 <script>
-                    print("Moving line %s with source %s and target %s" % (self.cs_element['id'], self.cs_element['__source'], self.cs_element['__target']))
                     source_x, source_y, _, _ = self.containing_canvas.coords(self.cs_element['elem'][0])
                     _, _, target_x, target_y = self.containing_canvas.coords(self.cs_element['elem'][1])
 
@@ -72,13 +75,11 @@
                         # Changed source of our link
                         source_x = new_location[0] + self.cs_element['offsetSourceX']
                         source_y = new_location[1] + self.cs_element['offsetSourceY']
-                        print("Move source of line " + self.cs_element['id'])
 
                     if element == self.cs_element['__target']:
                         # Changed target of our link
                         target_x = new_location[0] + self.cs_element['offsetTargetX']
                         target_y = new_location[1] + self.cs_element['offsetTargetY']
-                        print("Move target of line " + self.cs_element['id'])
 
                     self.middle_x = (source_x + target_x) / 2
                     self.middle_y = (source_y + target_y) / 2

+ 11 - 5
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:   Fri Oct  6 08:46:10 2017
+Date:   Fri Oct  6 09:28:21 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   Modelverse Visual Editor - Tkinter Version 
@@ -7324,6 +7324,7 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
         _init_0 = Transition(self, self.states["/init"], [self.states["/main"]])
         _init_0.setAction(self._init_0_exec)
         _init_0.setTrigger(None)
+        _init_0.setGuard(self._init_0_guard)
         self.states["/init"].addTransition(_init_0)
         
         # transition /main
@@ -7406,7 +7407,11 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
         
         self.containing_canvas.group_location[self.cs_element['id']] = (middle_x, middle_y)
         
-        line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'], arrow=tk.LAST if self.cs_element['arrow'] else tk.NONE)
+        if self.cs_element['arrow']:
+            lw = self.cs_element['lineWidth']
+            line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'], arrow=tk.LAST, arrowshape=(lw*8, lw*10, lw*3))
+        else:
+            line1 = self.containing_canvas.create_line(source_x, source_y, middle_x, middle_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'])
         line2 = self.containing_canvas.create_line(middle_x, middle_y, target_x, target_y, fill=self.cs_element['lineColour'], width=self.cs_element['lineWidth'])
         self.cs_element['elem'] = (line1, line2)
         self.elements.add(line1)
@@ -7418,6 +7423,9 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
         self.set_bindable_and_tagorid(self.containing_canvas, line1)
         self.set_bindable_and_tagorid(self.containing_canvas, line2)
     
+    def _init_0_guard(self, parameters):
+        return self.cs_element['__source'] in self.containing_canvas.group_location and self.cs_element['__target'] in self.containing_canvas.group_location
+    
     def _main_0_guard(self, parameters):
         ID = parameters[0]
         return id(self) == ID
@@ -7425,7 +7433,6 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
     def _main_1_exec(self, parameters):
         element = parameters[0]
         new_location = parameters[1]
-        print("Moving line %s with source %s and target %s" % (self.cs_element['id'], self.cs_element['__source'], self.cs_element['__target']))
         source_x, source_y, _, _ = self.containing_canvas.coords(self.cs_element['elem'][0])
         _, _, target_x, target_y = self.containing_canvas.coords(self.cs_element['elem'][1])
         
@@ -7433,13 +7440,11 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
             # Changed source of our link
             source_x = new_location[0] + self.cs_element['offsetSourceX']
             source_y = new_location[1] + self.cs_element['offsetSourceY']
-            print("Move source of line " + self.cs_element['id'])
         
         if element == self.cs_element['__target']:
             # Changed target of our link
             target_x = new_location[0] + self.cs_element['offsetTargetX']
             target_y = new_location[1] + self.cs_element['offsetTargetY']
-            print("Move target of line " + self.cs_element['id'])
         
         self.middle_x = (source_x + target_x) / 2
         self.middle_y = (source_y + target_y) / 2
@@ -7700,6 +7705,7 @@ class CanvasElement(RuntimeClassBase, SCCDWidget):
     
     def _main_0_exec(self, parameters):
         element = parameters[0]
+        print("Create element with ID %s" % (element['id']))
         elem_x = self.coordinates[0] + element["x"]
         elem_y = self.coordinates[1] + element["y"]
         if element["type"] == "Rectangle":

+ 1 - 0
models/MM_render.mvc

@@ -23,6 +23,7 @@ Association ConnectingLine (Group, Group) {
     lineColour : String
     arrow : Boolean
     __asid : String
+    dirty : Boolean
 }
 
 Class LineElement : GraphicalElement {