canvas.xml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <class name="Canvas">
  2. <relationships>
  3. <association name="parent" class="A" min="1" max="1" />
  4. <inheritance class="SCCDWidget" priority='0'/>
  5. <inheritance class="tk.Canvas" priority='1'/>
  6. <association name="elements" class="CanvasElement"/>
  7. <association name="connecting_lines" class="ConnectingLines"/>
  8. </relationships>
  9. <constructor>
  10. <parameter name="parent" />
  11. <super class="SCCDWidget"/>
  12. <super class="tk.Canvas">
  13. <parameter expr="parent" />
  14. <parameter expr="**{'scrollregion': (0, 0, parent.winfo_screenwidth()*2, parent.winfo_screenheight() * 2)}"/>
  15. </super>
  16. <body>
  17. vbar = tk.Scrollbar(self, orient=tk.VERTICAL)
  18. vbar.config(command=self.yview)
  19. vbar.pack(side=tk.RIGHT, fill=tk.Y, pady=(0, 16))
  20. hbar = tk.Scrollbar(self, orient=tk.HORIZONTAL)
  21. hbar.config(command=self.xview)
  22. hbar.pack(side=tk.BOTTOM, fill=tk.X)
  23. self.config(background='white', yscrollcommand=vbar.set, xscrollcommand=hbar.set)
  24. self.focus_set()
  25. self.assoc_links = {}
  26. self.element_group = {}
  27. self.group_location = {}
  28. self.connecting_lines = {}
  29. self.lines = set()
  30. self.layers = []
  31. print("RESET CANVAS")
  32. self.to_move = {}
  33. self.elems = []
  34. self.currently_selected = None
  35. self.loading = [tk.PhotoImage(file="icons/loading.gif", format="gif -index %i" % i) for i in range(8)]
  36. </body>
  37. </constructor>
  38. <destructor>
  39. <body>
  40. print("CANVAS DESTROYED")
  41. self.destroy()
  42. </body>
  43. </destructor>
  44. <scxml initial="main">
  45. <state id="main">
  46. <transition target="../ready">
  47. <raise event="tk_widget" scope="narrow" target="'parent'">
  48. <parameter expr="self"/>
  49. </raise>
  50. </transition>
  51. </state>
  52. <parallel id="ready">
  53. <state id="process_events" initial="ready">
  54. <state id="ready">
  55. <transition event="clear_canvas" target=".">
  56. <raise event="delete_instance" scope="cd">
  57. <parameter expr="'elements'"/>
  58. </raise>
  59. <raise event="delete_instance" scope="cd">
  60. <parameter expr="'connecting_lines'"/>
  61. </raise>
  62. <script>
  63. self.group_location = {}
  64. self.layers = []
  65. </script>
  66. </transition>
  67. <transition event="select_for_creation" target=".">
  68. <parameter name="element_name"/>
  69. <script>
  70. self.currently_selected = element_name
  71. </script>
  72. </transition>
  73. <transition event="right-click" cond="self.currently_selected is not None" target="../creating_element">
  74. <script>
  75. self.create_location = (self.last_x, self.last_y)
  76. </script>
  77. </transition>
  78. <transition event="define_group" target="../creating_group">
  79. <parameter name="element"/>
  80. <script>
  81. self.creating_id = element["id"]
  82. self.group_location[element['id']] = (element['x'], element['y'])
  83. </script>
  84. <raise event="create_instance" scope="cd">
  85. <parameter expr="'elements'"/>
  86. <parameter expr="'CanvasElement'"/>
  87. <parameter expr="self"/>
  88. <parameter expr="(element['x'], element['y'])"/>
  89. <parameter expr="element['id']"/>
  90. <parameter expr="element['__asid']"/>
  91. </raise>
  92. </transition>
  93. <transition event="define_contains" target=".">
  94. <parameter name="element"/>
  95. <script>
  96. self.element_group[element["__target"]] = element["__source"]
  97. </script>
  98. </transition>
  99. <transition event="draw_canvas" cond="element['type'] != 'ConnectingLine'" target=".">
  100. <parameter name="element"/>
  101. <raise event="draw_element" scope="narrow" target="self.assoc_links[self.element_group[element['id']]]">
  102. <parameter expr="element"/>
  103. </raise>
  104. </transition>
  105. <transition event="draw_canvas" cond="element['type'] == 'ConnectingLine'" target=".">
  106. <parameter name="element"/>
  107. <raise event="create_instance" scope="cd">
  108. <parameter expr="'connecting_lines'"/>
  109. <parameter expr="'ConnectingLine'"/>
  110. <parameter expr="self"/>
  111. <parameter expr="element"/>
  112. </raise>
  113. </transition>
  114. <transition event="instance_created" target=".">
  115. <parameter name="result"/>
  116. <raise event="start_instance" scope="cd">
  117. <parameter expr="result"/>
  118. </raise>
  119. </transition>
  120. <transition event="moved_group" target=".">
  121. <parameter name="group_element"/>
  122. <parameter name="new_location"/>
  123. <script>
  124. self.group_location[group_element] = new_location
  125. </script>
  126. <raise event="moved_element" scope="narrow" target="'connecting_lines'">
  127. <parameter expr="group_element"/>
  128. <parameter expr="new_location"/>
  129. </raise>
  130. </transition>
  131. </state>
  132. <state id="creating_group">
  133. <transition event="instance_created" target="../wait_canvas_element_ready">
  134. <parameter name="assoc_name"/>
  135. <raise event="start_instance" scope="cd">
  136. <parameter expr="assoc_name"/>
  137. </raise>
  138. <script>
  139. self.assoc_links[self.creating_id] = assoc_name
  140. </script>
  141. </transition>
  142. </state>
  143. <state id="wait_canvas_element_ready">
  144. <transition event="moved_group" target=".">
  145. <parameter name="group_element"/>
  146. <parameter name="new_location"/>
  147. <script>
  148. self.group_location[group_element] = new_location
  149. </script>
  150. <raise event="moved_element" scope="narrow" target="'connecting_lines'">
  151. <parameter expr="group_element"/>
  152. <parameter expr="new_location"/>
  153. </raise>
  154. </transition>
  155. <transition event="canvas_element_ready" target="../ready">
  156. <raise event="group_ready" scope="narrow" target="'parent'"/>
  157. </transition>
  158. </state>
  159. <state id="creating_element">
  160. <onentry>
  161. <raise event="mv_request" scope="broad">
  162. <parameter expr="'instantiate'"/>
  163. <parameter expr="[current_model, self.currently_selected, None, '']"/>
  164. </raise>
  165. <script>
  166. self.elems.append([0, self.create_image(self.last_x, self.last_y, image=self.loading[0])])
  167. </script>
  168. </onentry>
  169. <transition event="mv_response" target="../waiting_for_clear">
  170. <parameter name="ID"/>
  171. <script>
  172. self.to_move[ID] = self.create_location
  173. </script>
  174. <raise event="rerender_model" scope="narrow" target="'parent'"/>
  175. </transition>
  176. </state>
  177. <state id="waiting_for_clear">
  178. <transition event="clear_canvas" target="../ready">
  179. <raise event="delete_instance" scope="cd">
  180. <parameter expr="'elements'"/>
  181. </raise>
  182. <raise event="delete_instance" scope="cd">
  183. <parameter expr="'connecting_lines'"/>
  184. </raise>
  185. <script>
  186. self.group_location = {}
  187. self.layers = []
  188. </script>
  189. </transition>
  190. </state>
  191. </state>
  192. <state id="update_loading">
  193. <state id="updating">
  194. <transition after="self.sccd_yield() + 0.1" target=".">
  195. <script>
  196. for i in self.elems:
  197. self.itemconfigure(i[1], image=self.loading[i[0]])
  198. i[0] = (i[0] + 1) % 8
  199. </script>
  200. </transition>
  201. </state>
  202. </state>
  203. </parallel>
  204. </scxml>
  205. </class>