Browse Source

Fixed exceptions during creation of connecting lines

Yentl Van Tendeloo 8 years ago
parent
commit
587ba90b3a
4 changed files with 19 additions and 10 deletions
  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=".">
             <transition event="draw_element" target=".">
                 <parameter name="element"/>
                 <parameter name="element"/>
                 <script>
                 <script>
+                    print("Create element with ID %s" % (element['id']))
                     elem_x = self.coordinates[0] + element["x"]
                     elem_x = self.coordinates[0] + element["x"]
                     elem_y = self.coordinates[1] + element["y"]
                     elem_y = self.coordinates[1] + element["y"]
                     if element["type"] == "Rectangle":
                     if element["type"] == "Rectangle":

+ 6 - 5
classes/canvas/connecting_line.xml

@@ -28,7 +28,7 @@
 
 
     <scxml initial="init">
     <scxml initial="init">
         <state id="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>
                 <script>
                     print("Draw connecting line %s from %s to %s" % (self.cs_element['id'], self.cs_element['__source'], self.cs_element['__target']))
                     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']
                     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)
                     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'])
                     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.cs_element['elem'] = (line1, line2)
                     self.elements.add(line1)
                     self.elements.add(line1)
@@ -64,7 +68,6 @@
                 <parameter name="element"/>
                 <parameter name="element"/>
                 <parameter name="new_location"/>
                 <parameter name="new_location"/>
                 <script>
                 <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])
                     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])
                     _, _, target_x, target_y = self.containing_canvas.coords(self.cs_element['elem'][1])
 
 
@@ -72,13 +75,11 @@
                         # Changed source of our link
                         # Changed source of our link
                         source_x = new_location[0] + self.cs_element['offsetSourceX']
                         source_x = new_location[0] + self.cs_element['offsetSourceX']
                         source_y = new_location[1] + self.cs_element['offsetSourceY']
                         source_y = new_location[1] + self.cs_element['offsetSourceY']
-                        print("Move source of line " + self.cs_element['id'])
 
 
                     if element == self.cs_element['__target']:
                     if element == self.cs_element['__target']:
                         # Changed target of our link
                         # Changed target of our link
                         target_x = new_location[0] + self.cs_element['offsetTargetX']
                         target_x = new_location[0] + self.cs_element['offsetTargetX']
                         target_y = new_location[1] + self.cs_element['offsetTargetY']
                         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_x = (source_x + target_x) / 2
                     self.middle_y = (source_y + target_y) / 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)
 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 author: Yentl Van Tendeloo
 Model name:   Modelverse Visual Editor - Tkinter Version 
 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 = Transition(self, self.states["/init"], [self.states["/main"]])
         _init_0.setAction(self._init_0_exec)
         _init_0.setAction(self._init_0_exec)
         _init_0.setTrigger(None)
         _init_0.setTrigger(None)
+        _init_0.setGuard(self._init_0_guard)
         self.states["/init"].addTransition(_init_0)
         self.states["/init"].addTransition(_init_0)
         
         
         # transition /main
         # transition /main
@@ -7406,7 +7407,11 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
         
         
         self.containing_canvas.group_location[self.cs_element['id']] = (middle_x, middle_y)
         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'])
         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.cs_element['elem'] = (line1, line2)
         self.elements.add(line1)
         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, line1)
         self.set_bindable_and_tagorid(self.containing_canvas, line2)
         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):
     def _main_0_guard(self, parameters):
         ID = parameters[0]
         ID = parameters[0]
         return id(self) == ID
         return id(self) == ID
@@ -7425,7 +7433,6 @@ class ConnectingLine(RuntimeClassBase, SCCDWidget):
     def _main_1_exec(self, parameters):
     def _main_1_exec(self, parameters):
         element = parameters[0]
         element = parameters[0]
         new_location = parameters[1]
         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])
         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])
         _, _, 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
             # Changed source of our link
             source_x = new_location[0] + self.cs_element['offsetSourceX']
             source_x = new_location[0] + self.cs_element['offsetSourceX']
             source_y = new_location[1] + self.cs_element['offsetSourceY']
             source_y = new_location[1] + self.cs_element['offsetSourceY']
-            print("Move source of line " + self.cs_element['id'])
         
         
         if element == self.cs_element['__target']:
         if element == self.cs_element['__target']:
             # Changed target of our link
             # Changed target of our link
             target_x = new_location[0] + self.cs_element['offsetTargetX']
             target_x = new_location[0] + self.cs_element['offsetTargetX']
             target_y = new_location[1] + self.cs_element['offsetTargetY']
             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_x = (source_x + target_x) / 2
         self.middle_y = (source_y + target_y) / 2
         self.middle_y = (source_y + target_y) / 2
@@ -7700,6 +7705,7 @@ class CanvasElement(RuntimeClassBase, SCCDWidget):
     
     
     def _main_0_exec(self, parameters):
     def _main_0_exec(self, parameters):
         element = parameters[0]
         element = parameters[0]
+        print("Create element with ID %s" % (element['id']))
         elem_x = self.coordinates[0] + element["x"]
         elem_x = self.coordinates[0] + element["x"]
         elem_y = self.coordinates[1] + element["y"]
         elem_y = self.coordinates[1] + element["y"]
         if element["type"] == "Rectangle":
         if element["type"] == "Rectangle":

+ 1 - 0
models/MM_render.mvc

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