canvas.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. <association name="prompt" class="ChoicePrompt"/>
  9. </relationships>
  10. <constructor>
  11. <parameter name="parent" />
  12. <super class="SCCDWidget"/>
  13. <super class="tk.Canvas">
  14. <parameter expr="parent" />
  15. <parameter expr="**{'scrollregion': (0, 0, parent.winfo_screenwidth()*2, parent.winfo_screenheight() * 2)}"/>
  16. </super>
  17. <body>
  18. vbar = tk.Scrollbar(self, orient=tk.VERTICAL)
  19. vbar.config(command=self.yview)
  20. vbar.pack(side=tk.RIGHT, fill=tk.Y, pady=(0, 16))
  21. hbar = tk.Scrollbar(self, orient=tk.HORIZONTAL)
  22. hbar.config(command=self.xview)
  23. hbar.pack(side=tk.BOTTOM, fill=tk.X)
  24. self.config(background='white', yscrollcommand=vbar.set, xscrollcommand=hbar.set)
  25. self.focus_set()
  26. self.assoc_links = {}
  27. self.element_group = {}
  28. self.group_location = {}
  29. self.connecting_lines = {}
  30. self.lines = set()
  31. self.layers = []
  32. self.to_move = {}
  33. self.elems = []
  34. self.tmp_line = None
  35. self.currently_selected = None
  36. self.loading = [tk.PhotoImage(file="icons/loading.gif", format="gif -index %i" % i) for i in range(8)]
  37. </body>
  38. </constructor>
  39. <destructor>
  40. <body>
  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="select_for_creation" target=".">
  56. <parameter name="element_name"/>
  57. <script>
  58. self.currently_selected = element_name
  59. </script>
  60. </transition>
  61. <transition event="right-click" cond="self.currently_selected is not None and id(self) == ID and not control_pressed" target="../creating_element">
  62. <parameter name="ID"/>
  63. <script>
  64. self.create_location = (self.last_x, self.last_y)
  65. </script>
  66. </transition>
  67. <transition event="create_line" target="../creating_line">
  68. <parameter name="cs_element"/>
  69. <parameter name="as_element"/>
  70. <parameter name="coordinates"/>
  71. <script>
  72. self.creating_line = (cs_element, as_element, coordinates)
  73. </script>
  74. </transition>
  75. <transition event="define_group" target="../creating_group">
  76. <parameter name="element"/>
  77. <script>
  78. self.creating_id = element["id"]
  79. self.group_location[element['id']] = (element['x'], element['y'])
  80. </script>
  81. <raise event="create_instance" scope="cd">
  82. <parameter expr="'elements'"/>
  83. <parameter expr="'CanvasElement'"/>
  84. <parameter expr="self"/>
  85. <parameter expr="(element['x'], element['y'])"/>
  86. <parameter expr="element['id']"/>
  87. <parameter expr="element['__asid']"/>
  88. </raise>
  89. </transition>
  90. <transition event="define_contains" target=".">
  91. <parameter name="element"/>
  92. <script>
  93. self.element_group[element["__target"]] = element["__source"]
  94. </script>
  95. </transition>
  96. <transition event="draw_canvas" cond="element['type'] != 'ConnectingLine'" target=".">
  97. <parameter name="element"/>
  98. <raise event="draw_element" scope="narrow" target="self.assoc_links[self.element_group[element['id']]]">
  99. <parameter expr="element"/>
  100. </raise>
  101. </transition>
  102. <transition event="draw_canvas" cond="element['type'] == 'ConnectingLine'" target=".">
  103. <parameter name="element"/>
  104. <raise event="create_instance" scope="cd">
  105. <parameter expr="'connecting_lines'"/>
  106. <parameter expr="'ConnectingLine'"/>
  107. <parameter expr="self"/>
  108. <parameter expr="element"/>
  109. </raise>
  110. </transition>
  111. <transition event="instance_created" target=".">
  112. <parameter name="result"/>
  113. <raise event="start_instance" scope="cd">
  114. <parameter expr="result"/>
  115. </raise>
  116. </transition>
  117. <transition event="moved_group" target=".">
  118. <parameter name="group_element"/>
  119. <parameter name="new_location"/>
  120. <script>
  121. self.group_location[group_element] = new_location
  122. </script>
  123. <raise event="moved_element" scope="narrow" target="'connecting_lines'">
  124. <parameter expr="group_element"/>
  125. <parameter expr="new_location"/>
  126. </raise>
  127. </transition>
  128. <transition event="deleted_group" target=".">
  129. <parameter name="group_element"/>
  130. <script>
  131. del self.group_location[group_element]
  132. print("Remove group_location " + str(group_element))
  133. </script>
  134. <raise event="deleted_element" scope="narrow" target="'connecting_lines'">
  135. <parameter expr="group_element"/>
  136. </raise>
  137. </transition>
  138. </state>
  139. <state id="creating_line" initial="drawing">
  140. <onentry>
  141. <script>
  142. self.tmp_line = self.create_line(self.creating_line[2][0], self.creating_line[2][1], self.last_x, self.last_y)
  143. </script>
  144. </onentry>
  145. <state id="drawing">
  146. <transition event="motion" target=".">
  147. <script>
  148. x, y, _, _ = self.coords(self.tmp_line)
  149. # NOTE: make sure that you can not click on the temporary line itself
  150. if x > self.last_x:
  151. self.last_x += 2
  152. else:
  153. self.last_x -= 2
  154. if y > self.last_y:
  155. self.last_y += 2
  156. else:
  157. self.last_y -= 2
  158. self.coords(self.tmp_line, x, y, self.last_x, self.last_y)
  159. </script>
  160. </transition>
  161. <transition event="right-click" cond="ID == id(self) and not control_pressed" target="../../ready">
  162. <parameter name="ID"/>
  163. <script>
  164. self.delete(self.tmp_line)
  165. self.tmp_line = None
  166. </script>
  167. </transition>
  168. <transition event="create_line" target="../create_in_mv">
  169. <parameter name="cs_element"/>
  170. <parameter name="as_element"/>
  171. <script>
  172. origin_cs, origin_as, _ = self.creating_line
  173. self.creating_line = (origin_cs, origin_as, cs_element, as_element)
  174. </script>
  175. </transition>
  176. </state>
  177. <state id="create_in_mv" initial="query_type">
  178. <state id="query_type">
  179. <onentry>
  180. <raise event="mv_request" scope="broad">
  181. <parameter expr="'connections_between'"/>
  182. <parameter expr="[current_model, self.creating_line[1], self.creating_line[3]]"/>
  183. </raise>
  184. </onentry>
  185. <transition event="mv_response" target="../check_types">
  186. <parameter name="result"/>
  187. <script>
  188. self.allowed_types = result
  189. </script>
  190. </transition>
  191. </state>
  192. <state id="check_types">
  193. <transition cond="len(self.allowed_types) == 0" target="../../../ready"/>
  194. <transition cond="len(self.allowed_types) == 1" target="../create">
  195. <script>
  196. self.assoc_type = self.allowed_types.pop()
  197. </script>
  198. </transition>
  199. <transition cond="len(self.allowed_types) > 1" target="../request_user">
  200. <script>
  201. self.allowed_types = list(self.allowed_types)
  202. </script>
  203. </transition>
  204. </state>
  205. <state id="request_user" initial="check_next">
  206. <onentry>
  207. <script>
  208. self.new_allowed_types = {}
  209. </script>
  210. </onentry>
  211. <state id="check_next">
  212. <transition cond="len(self.allowed_types) > 0" target="../convert_to_name"/>
  213. <transition cond="len(self.allowed_types) == 0" target="../request">
  214. <script>
  215. self.allowed_types = self.new_allowed_types
  216. </script>
  217. </transition>
  218. </state>
  219. <state id="convert_to_name">
  220. <onentry>
  221. <raise event="mv_request" scope="broad">
  222. <parameter expr="'read_attrs'"/>
  223. <parameter expr="[current_metamodel, self.allowed_types[0]]"/>
  224. </raise>
  225. </onentry>
  226. <transition event="mv_response" target="../check_next">
  227. <parameter name="result"/>
  228. <script>
  229. if 'name' in result and result['name'] is not None:
  230. self.new_allowed_types[result['name']] = self.allowed_types[0]
  231. self.allowed_types.pop(0)
  232. </script>
  233. </transition>
  234. </state>
  235. <state id="request">
  236. <onentry>
  237. <raise event="create_instance" scope="cd">
  238. <parameter expr="'prompt'"/>
  239. <parameter expr="'ChoicePrompt'"/>
  240. <parameter expr="'Pick desired link type:'"/>
  241. <parameter expr="self.allowed_types.keys()"/>
  242. </raise>
  243. </onentry>
  244. <transition event="instance_created" target="../wait_for_response">
  245. <parameter name="assoc_name"/>
  246. <raise event="start_instance" scope="cd">
  247. <parameter expr="assoc_name"/>
  248. </raise>
  249. <script>
  250. self.assoc_type = None
  251. </script>
  252. </transition>
  253. </state>
  254. <state id="wait_for_response">
  255. <transition event="choice_result" target=".">
  256. <parameter name="result"/>
  257. <script>
  258. self.assoc_type = self.allowed_types[result]
  259. </script>
  260. </transition>
  261. <transition event="close_window" cond="self.assoc_type is not None" target="../../create">
  262. <raise event="delete_instance" scope="cd">
  263. <parameter expr="'prompt'"/>
  264. </raise>
  265. </transition>
  266. <transition event="close_window" cond="self.assoc_type is None" target="../../../../ready">
  267. <raise event="delete_instance" scope="cd">
  268. <parameter expr="'prompt'"/>
  269. </raise>
  270. <script>
  271. self.delete(self.tmp_line)
  272. self.tmp_line = None
  273. </script>
  274. </transition>
  275. </state>
  276. </state>
  277. <state id="create">
  278. <onentry>
  279. <raise event="mv_request" scope="broad">
  280. <parameter expr="'instantiate'"/>
  281. <parameter expr="[current_model, self.assoc_type, (self.creating_line[1], self.creating_line[3]), '']"/>
  282. </raise>
  283. </onentry>
  284. <transition event="mv_response" target="../../../waiting_for_clear">
  285. <parameter name="ID"/>
  286. <raise event="minimal_rerender_model" scope="narrow" target="'parent'"/>
  287. </transition>
  288. </state>
  289. </state>
  290. </state>
  291. <state id="creating_group">
  292. <transition event="instance_created" target="../wait_canvas_element_ready">
  293. <parameter name="assoc_name"/>
  294. <raise event="start_instance" scope="cd">
  295. <parameter expr="assoc_name"/>
  296. </raise>
  297. <script>
  298. self.assoc_links[self.creating_id] = assoc_name
  299. </script>
  300. </transition>
  301. </state>
  302. <state id="wait_canvas_element_ready">
  303. <transition event="moved_group" target=".">
  304. <parameter name="group_element"/>
  305. <parameter name="new_location"/>
  306. <script>
  307. self.group_location[group_element] = new_location
  308. </script>
  309. <raise event="moved_element" scope="narrow" target="'connecting_lines'">
  310. <parameter expr="group_element"/>
  311. <parameter expr="new_location"/>
  312. </raise>
  313. </transition>
  314. <transition event="canvas_element_ready" target="../ready">
  315. <raise event="group_ready" scope="narrow" target="'parent'"/>
  316. </transition>
  317. </state>
  318. <state id="creating_element">
  319. <onentry>
  320. <raise event="mv_request" scope="broad">
  321. <parameter expr="'instantiate'"/>
  322. <parameter expr="[current_model, self.currently_selected, None, '']"/>
  323. </raise>
  324. <script>
  325. self.elems.append([0, self.create_image(self.last_x, self.last_y, image=self.loading[0])])
  326. </script>
  327. </onentry>
  328. <transition event="mv_response" target="../waiting_for_clear">
  329. <parameter name="ID"/>
  330. <script>
  331. self.to_move[ID] = self.create_location
  332. </script>
  333. <raise event="minimal_rerender_model" scope="narrow" target="'parent'"/>
  334. </transition>
  335. </state>
  336. <state id="waiting_for_clear"/>
  337. <transition event="clear_canvas" target="ready">
  338. <raise event="delete_instance" scope="cd">
  339. <parameter expr="'elements'"/>
  340. </raise>
  341. <raise event="delete_instance" scope="cd">
  342. <parameter expr="'connecting_lines'"/>
  343. </raise>
  344. <script>
  345. for f in self.elems:
  346. self.delete(f[1])
  347. if self.tmp_line is not None:
  348. self.delete(self.tmp_line)
  349. self.tmp_line = None
  350. self.elems = []
  351. self.group_location = {}
  352. self.layers = []
  353. </script>
  354. </transition>
  355. </state>
  356. <state id="update_loading">
  357. <state id="updating">
  358. <transition after="self.sccd_yield() + 0.1" target=".">
  359. <script>
  360. for i in self.elems:
  361. self.itemconfigure(i[1], image=self.loading[i[0]])
  362. i[0] = (i[0] + 1) % 8
  363. </script>
  364. </transition>
  365. </state>
  366. </state>
  367. </parallel>
  368. </scxml>
  369. </class>