main_window.xml 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. <class name="MainWindow">
  2. <relationships>
  3. <inheritance class="tk.Toplevel" priority="1"/>
  4. <inheritance class="SCCDWidget" priority="0"/>
  5. <association name="parent" class="A"/>
  6. <association name="generic_toolbars" class="Toolbar"/>
  7. <association name="model_toolbars" class="Toolbar"/>
  8. <association name="subwindow" class="Window"/>
  9. <association name="canvas" class="Canvas"/>
  10. <association name="progress_bar" class="ProgressBar"/>
  11. </relationships>
  12. <constructor>
  13. <super class="tk.Toplevel"/>
  14. <super class="SCCDWidget"/>
  15. <parameter name="open_model"/>
  16. <parameter name="limited_mode"/>
  17. <body>
  18. self.toolbar_frame = tk.Frame(self)
  19. self.canvas_frame = tk.Frame(self)
  20. self.progressbar_frame = tk.Frame(self)
  21. self.toolbar_frame.pack(fill=tk.X)
  22. self.canvas_frame.pack(fill=tk.BOTH, expand=tk.TRUE)
  23. self.progressbar_frame.pack(fill=tk.X)
  24. self.model_loaded = False
  25. self.preload_model = open_model
  26. self.limited_mode = limited_mode
  27. global current_mapper
  28. current_mapper = None
  29. global current_rendered_model
  30. current_rendered_model = None
  31. global current_metamodel
  32. current_metamodel = None
  33. global current_model
  34. current_model = None
  35. </body>
  36. </constructor>
  37. <destructor>
  38. <body>
  39. self.destroy()
  40. </body>
  41. </destructor>
  42. <scxml initial="init">
  43. <parallel id="init">
  44. <state id="init" initial="init">
  45. <state id="init" initial="determine_initial">
  46. <state id="determine_initial">
  47. <transition cond="self.limited_mode" target="../progressbar"/>
  48. <transition cond="not self.limited_mode" target="../generic_toolbar"/>
  49. </state>
  50. <state id="generic_toolbar">
  51. <onentry>
  52. <raise event="create_instance" scope="cd">
  53. <parameter expr="'generic_toolbars'"/>
  54. <parameter expr="'GenericToolbar'"/>
  55. <parameter expr="self.toolbar_frame"/>
  56. </raise>
  57. </onentry>
  58. <transition event="instance_created" target="../pack_generic">
  59. <parameter name="association_name"/>
  60. <raise event="start_instance" scope="cd">
  61. <parameter expr="association_name"/>
  62. </raise>
  63. </transition>
  64. </state>
  65. <state id="pack_generic">
  66. <transition event="tk_widget" target="../progressbar">
  67. <parameter name="tk_elem"/>
  68. <script>
  69. tk_elem.pack(anchor=tk.NW)
  70. </script>
  71. </transition>
  72. </state>
  73. <state id="progressbar">
  74. <onentry>
  75. <raise event="create_instance" scope="cd">
  76. <parameter expr="'progress_bar'"/>
  77. <parameter expr="'ProgressBar'"/>
  78. <parameter expr="{'parent': self.progressbar_frame}"/>
  79. </raise>
  80. </onentry>
  81. <transition event="instance_created" target="../pack_progressbar">
  82. <parameter name="association_name"/>
  83. <raise event="start_instance" scope="cd">
  84. <parameter expr="association_name"/>
  85. </raise>
  86. </transition>
  87. </state>
  88. <state id="pack_progressbar">
  89. <transition event="tk_widget" target="../../running">
  90. <parameter name="tk_elem"/>
  91. <script>
  92. tk_elem.pack(side=tk.BOTTOM, fill=tk.X, expand=tk.TRUE)
  93. </script>
  94. </transition>
  95. </state>
  96. </state>
  97. <state id="running" initial="idle">
  98. <state id="idle">
  99. <onentry>
  100. <raise event="update_status" scope="narrow" target="'progress_bar'">
  101. <parameter expr="0"/>
  102. <parameter expr="'Ready for action!'"/>
  103. </raise>
  104. </onentry>
  105. <transition event="create_new_model" target="../create_new_model"/>
  106. <transition event="open_model" target="../open_model"/>
  107. <transition event="rerender_model" target="../rerender_model"/>
  108. <transition event="minimal_rerender_model" target="../rerender_model/request_render"/>
  109. <transition event="new_rendered" cond="current_mapper is not None" target="../new_rendered"/>
  110. <transition event="verify" target="../verify_model"/>
  111. <transition event="conf_bottom" target="../conf_bottom"/>
  112. <transition event="custom_MM" target="../custom_MM"/>
  113. <transition event="upload_MVC" target="../upload_MVC"/>
  114. <transition event="add_object_diagrams" target="../add_object_diagrams"/>
  115. <transition event="activity" target="../execute_activity"/>
  116. <transition event="create_activity" target="../create_activity"/>
  117. <transition event="enact_process" target="../enact_process"/>
  118. <transition event="modify_defined_attrs" target="../modify_defined_attrs">
  119. <parameter name="as_element"/>
  120. <parameter name="cs_element"/>
  121. <script>
  122. self.as_element = as_element
  123. self.cs_element = cs_element
  124. </script>
  125. </transition>
  126. <transition event="change_metamodel" target="../change_metamodel">
  127. <parameter name="new_metamodel"/>
  128. <script>
  129. global current_metamodel
  130. current_metamodel = new_metamodel
  131. </script>
  132. </transition>
  133. <transition event="change_mapper" target="../change_mapper">
  134. <parameter name="new_mapper"/>
  135. <script>
  136. global current_mapper
  137. if new_mapper == "(none)":
  138. current_mapper = None
  139. else:
  140. current_mapper = new_mapper
  141. </script>
  142. </transition>
  143. <transition event="change_rendered" target="../change_rendered">
  144. <parameter name="new_rendered"/>
  145. <script>
  146. global current_rendered_model
  147. current_rendered_model = new_rendered
  148. </script>
  149. </transition>
  150. <transition event="select_for_creation" target=".">
  151. <parameter name="element_name"/>
  152. <raise event="select_for_creation" scope="narrow" target="'canvas'">
  153. <parameter expr="element_name"/>
  154. </raise>
  155. </transition>
  156. <transition cond="self.preload_model is not None" target="../open_model/search_metamodels">
  157. <script>
  158. global current_model
  159. current_model = self.preload_model
  160. self.preload_model = None
  161. self.locations = {}
  162. </script>
  163. </transition>
  164. </state>
  165. <state id="modify_defined_attrs" initial="create_window">
  166. <state id="create_window">
  167. <onentry>
  168. <raise event="create_instance" scope="cd">
  169. <parameter expr="'subwindow'"/>
  170. <parameter expr="'AttributeEditor'"/>
  171. <parameter expr="self.as_element"/>
  172. </raise>
  173. </onentry>
  174. <transition event="instance_created" target="../wait_for_finished">
  175. <parameter name="assoc_name"/>
  176. <raise event="start_instance" scope="cd">
  177. <parameter expr="assoc_name"/>
  178. </raise>
  179. <script>
  180. self.current_window = assoc_name
  181. </script>
  182. </transition>
  183. </state>
  184. <state id="wait_for_finished">
  185. <transition event="close_window" cond="current_rendered_model is not None" target="../mark_dirty">
  186. <script>
  187. print("Closed window!")
  188. </script>
  189. <raise event="delete_instance" scope="cd">
  190. <parameter expr="self.current_window"/>
  191. </raise>
  192. </transition>
  193. <transition event="close_window" cond="current_rendered_model is None" target="../../rerender_model/request_render">
  194. <script>
  195. print("Closed window!")
  196. </script>
  197. <raise event="delete_instance" scope="cd">
  198. <parameter expr="self.current_window"/>
  199. </raise>
  200. </transition>
  201. </state>
  202. <state id="mark_dirty">
  203. <onentry>
  204. <script>
  205. print("Marking as dirty")
  206. </script>
  207. <raise event="mv_request" scope="broad">
  208. <parameter expr="'attr_assign'"/>
  209. <parameter expr="[current_rendered_model, self.cs_element, 'dirty', True]"/>
  210. </raise>
  211. </onentry>
  212. <transition event="mv_response" target="../../rerender_model/request_render">
  213. <script>
  214. print("Response OK")
  215. </script>
  216. </transition>
  217. </state>
  218. </state>
  219. <state id="execute_activity" initial="open_window">
  220. <state id="open_window">
  221. <onentry>
  222. <raise event="create_instance" scope="cd">
  223. <parameter expr="'subwindow'"/>
  224. <parameter expr="'ActivityExecutor'"/>
  225. </raise>
  226. </onentry>
  227. <transition event="instance_created" target="../waiting">
  228. <parameter name="assoc_name"/>
  229. <raise event="start_instance" scope="cd">
  230. <parameter expr="assoc_name"/>
  231. </raise>
  232. <script>
  233. self.activity_executor = assoc_name
  234. </script>
  235. </transition>
  236. </state>
  237. <state id="waiting">
  238. <transition event="window_close" target="../../idle">
  239. <raise event="delete_instance" scope="cd">
  240. <parameter expr="self.activity_executor"/>
  241. </raise>
  242. </transition>
  243. </state>
  244. </state>
  245. <state id="create_activity" initial="open_window">
  246. <state id="open_window">
  247. <onentry>
  248. <raise event="create_instance" scope="cd">
  249. <parameter expr="'subwindow'"/>
  250. <parameter expr="'ActivityCreator'"/>
  251. </raise>
  252. </onentry>
  253. <transition event="instance_created" target="../waiting">
  254. <parameter name="assoc_name"/>
  255. <raise event="start_instance" scope="cd">
  256. <parameter expr="assoc_name"/>
  257. </raise>
  258. <script>
  259. self.activity_creator = assoc_name
  260. </script>
  261. </transition>
  262. </state>
  263. <state id="waiting">
  264. <transition event="close_window" target="../../idle">
  265. <raise event="delete_instance" scope="cd">
  266. <parameter expr="self.activity_creator"/>
  267. </raise>
  268. </transition>
  269. </state>
  270. </state>
  271. <state id="enact_process" initial="open_window">
  272. <state id="open_window">
  273. <onentry>
  274. <raise event="create_instance" scope="cd">
  275. <parameter expr="'subwindow'"/>
  276. <parameter expr="'ProcessEnactor'"/>
  277. </raise>
  278. </onentry>
  279. <transition event="instance_created" target="../waiting">
  280. <parameter name="assoc_name"/>
  281. <raise event="start_instance" scope="cd">
  282. <parameter expr="assoc_name"/>
  283. </raise>
  284. <script>
  285. self.process_enactor = assoc_name
  286. </script>
  287. </transition>
  288. </state>
  289. <state id="waiting">
  290. <transition event="window_close" target="../../idle">
  291. <raise event="delete_instance" scope="cd">
  292. <parameter expr="self.process_enactor"/>
  293. </raise>
  294. </transition>
  295. </state>
  296. </state>
  297. <state id="add_object_diagrams" initial="init">
  298. <state id="init">
  299. <onentry>
  300. <script>
  301. self.subprocess = subprocess.Popen([sys.executable, "add_render_OD.py", current_metamodel])
  302. </script>
  303. <raise event="update_status" scope="narrow" target="'progress_bar'">
  304. <parameter expr="10"/>
  305. <parameter expr="'Adding transformation...'"/>
  306. </raise>
  307. </onentry>
  308. <transition cond="self.subprocess.poll() is not None" target="../../open_model/search_CS_mappers">
  309. <script>
  310. global current_mapper
  311. current_mapper = 'models/render_OD/' + current_metamodel
  312. </script>
  313. </transition>
  314. </state>
  315. </state>
  316. <state id="upload_MVC" initial="load_code">
  317. <state id="load_code">
  318. <onentry>
  319. <raise event="create_instance" scope="cd">
  320. <parameter expr="'subwindow'"/>
  321. <parameter expr="'FileBrowser'"/>
  322. <parameter expr="'Select model code.'"/>
  323. </raise>
  324. <script>
  325. self.filename = None
  326. </script>
  327. </onentry>
  328. <transition event="instance_created" target="../waiting">
  329. <parameter name="result"/>
  330. <raise event="start_instance" scope="cd">
  331. <parameter expr="result"/>
  332. </raise>
  333. </transition>
  334. </state>
  335. <state id="waiting">
  336. <transition event="browse_result" target=".">
  337. <parameter name="result"/>
  338. <script>
  339. self.filename = result
  340. </script>
  341. </transition>
  342. <transition event="close_window" target="../got_filename">
  343. <raise event="delete_instance" scope="cd">
  344. <parameter expr="'subwindow'"/>
  345. </raise>
  346. </transition>
  347. </state>
  348. <state id="got_filename">
  349. <transition cond="self.filename is not None" target="../overwriting_model">
  350. <raise event="mv_request" scope="broad">
  351. <parameter expr="'model_overwrite'"/>
  352. <parameter expr="[current_model, open(self.filename, 'r').read()]"/>
  353. </raise>
  354. <raise event="update_status" scope="narrow" target="'progress_bar'">
  355. <parameter expr="10"/>
  356. <parameter expr="'Uploading model...'"/>
  357. </raise>
  358. </transition>
  359. <transition cond="self.filename is None" target="../../idle"/>
  360. </state>
  361. <state id="overwriting_model">
  362. <transition event="mv_response" target="../../rerender_model">
  363. <raise event="update_status" scope="narrow" target="'progress_bar'">
  364. <parameter expr="50"/>
  365. <parameter expr="'Rerendering model...'"/>
  366. </raise>
  367. </transition>
  368. </state>
  369. </state>
  370. <state id="change_metamodel">
  371. <onentry>
  372. <raise event="update_status" scope="narrow" target="'progress_bar'">
  373. <parameter expr="20"/>
  374. <parameter expr="'Storing model context...'"/>
  375. </raise>
  376. <raise event="mv_request" scope="broad">
  377. <parameter expr="'alter_context'"/>
  378. <parameter expr="[current_model, current_metamodel]"/>
  379. </raise>
  380. </onentry>
  381. <transition target="../open_model/search_CS_mappers"/>
  382. </state>
  383. <state id="conf_bottom" initial="check_if_exists">
  384. <state id="check_if_exists">
  385. <transition cond="'formalisms/Bottom' in self.allowed_metamodels" target="../../idle"/>
  386. <transition cond="'formalisms/Bottom' not in self.allowed_metamodels" target="../add_bottom"/>
  387. </state>
  388. <state id="add_bottom">
  389. <onentry>
  390. <raise event="mv_request" scope="broad">
  391. <parameter expr="'conformance_add'"/>
  392. <parameter expr="[current_model, 'formalisms/Bottom']"/>
  393. </raise>
  394. <raise event="update_status" scope="narrow" target="'progress_bar'">
  395. <parameter expr="10"/>
  396. <parameter expr="'Storing model context...'"/>
  397. </raise>
  398. <script>
  399. global current_metamodel
  400. current_metamodel = 'formalisms/Bottom'
  401. </script>
  402. </onentry>
  403. <transition event="mv_response" target="../../open_model/search_metamodels"/>
  404. </state>
  405. </state>
  406. <state id="custom_MM" initial="query">
  407. <state id="query">
  408. <onentry>
  409. <raise event="create_instance" scope="cd">
  410. <parameter expr="'subwindow'"/>
  411. <parameter expr="'Browser'"/>
  412. <parameter expr="'Select metamodel to use.'"/>
  413. <parameter expr="['formalisms/SimpleClassDiagrams']"/>
  414. </raise>
  415. <raise event="update_status" scope="narrow" target="'progress_bar'">
  416. <parameter expr="0"/>
  417. <parameter expr="'Browsing for metamodel...'"/>
  418. </raise>
  419. </onentry>
  420. <transition event="instance_created" target="../wait_for_metamodel">
  421. <parameter name="association_name"/>
  422. <raise event="start_instance" scope="cd">
  423. <parameter expr="association_name"/>
  424. </raise>
  425. <script>
  426. self.subwindow = association_name
  427. </script>
  428. </transition>
  429. </state>
  430. <state id="wait_for_metamodel" initial="wait_for_result">
  431. <onentry>
  432. <raise event="update_status" scope="narrow" target="'progress_bar'">
  433. <parameter expr="10"/>
  434. <parameter expr="'Browsing for model... OK'"/>
  435. </raise>
  436. </onentry>
  437. <state id="wait_for_result">
  438. <transition event="browse_result" cond="result not in self.allowed_metamodels" target="../got_result">
  439. <parameter name="result"/>
  440. <script>
  441. global current_metamodel
  442. current_metamodel = result
  443. </script>
  444. <raise event="mv_request" scope="broad">
  445. <parameter expr="'alter_context'"/>
  446. <parameter expr="[current_model, current_metamodel]"/>
  447. </raise>
  448. </transition>
  449. <transition event="close_window" target="../../../idle">
  450. <raise event="delete_instance" scope="cd">
  451. <parameter expr="self.subwindow"/>
  452. </raise>
  453. </transition>
  454. </state>
  455. <state id="got_result">
  456. <transition event="close_window" target="../mv_processing">
  457. <raise event="delete_instance" scope="cd">
  458. <parameter expr="self.subwindow"/>
  459. </raise>
  460. <raise event="mv_request" scope="broad">
  461. <parameter expr="'conformance_add'"/>
  462. <parameter expr="[current_model, current_metamodel]"/>
  463. </raise>
  464. </transition>
  465. </state>
  466. <state id="mv_processing">
  467. <transition event="mv_response" target="../../../open_model/search_metamodels"/>
  468. </state>
  469. </state>
  470. </state>
  471. <state id="change_mapper">
  472. <transition target="../open_model/search_CS_mappers"/>
  473. </state>
  474. <state id="change_rendered">
  475. <transition target="../rerender_model"/>
  476. </state>
  477. <state id="verify_model" initial="request">
  478. <state id="request">
  479. <onentry>
  480. <raise event="mv_request" scope="broad">
  481. <parameter expr="'verify'"/>
  482. <parameter expr="[current_model, current_metamodel]"/>
  483. </raise>
  484. </onentry>
  485. <transition event="mv_progress" target=".">
  486. <parameter name="result"/>
  487. <raise event="update_status" scope="narrow" target="'progress_bar'">
  488. <parameter expr="result * 100"/>
  489. <parameter expr="'Verifying...'"/>
  490. </raise>
  491. </transition>
  492. <transition event="mv_response" target="../show_result">
  493. <parameter name="result"/>
  494. <raise event="create_instance" scope="cd">
  495. <parameter expr="'subwindow'"/>
  496. <parameter expr="'Popup'"/>
  497. <parameter expr="result"/>
  498. </raise>
  499. </transition>
  500. </state>
  501. <state id="show_result">
  502. <transition event="instance_created" target="../wait_for_close">
  503. <parameter name="assoc_name"/>
  504. <raise event="start_instance" scope="cd">
  505. <parameter expr="assoc_name"/>
  506. </raise>
  507. </transition>
  508. </state>
  509. <state id="wait_for_close">
  510. <transition event="close_window" target="../../idle">
  511. <raise event="delete_instance" scope="cd">
  512. <parameter expr="'subwindow'"/>
  513. </raise>
  514. </transition>
  515. </state>
  516. </state>
  517. <state id="open_model" initial="query_model">
  518. <state id="query_model">
  519. <onentry>
  520. <raise event="create_instance" scope="cd">
  521. <parameter expr="'subwindow'"/>
  522. <parameter expr="'Browser'"/>
  523. <parameter expr="'Select model to open'"/>
  524. <parameter expr="[]"/>
  525. </raise>
  526. <raise event="update_status" scope="narrow" target="'progress_bar'">
  527. <parameter expr="0"/>
  528. <parameter expr="'Browsing for model...'"/>
  529. </raise>
  530. </onentry>
  531. <transition event="instance_created" target="../wait_for_model">
  532. <parameter name="association_name"/>
  533. <raise event="start_instance" scope="cd">
  534. <parameter expr="association_name"/>
  535. </raise>
  536. <script>
  537. self.subwindow = association_name
  538. </script>
  539. </transition>
  540. </state>
  541. <state id="wait_for_model">
  542. <transition event="close_window" target="../../idle">
  543. <raise event="delete_instance" scope="cd">
  544. <parameter expr="self.subwindow"/>
  545. </raise>
  546. <raise event="update_status" scope="narrow" target="'progress_bar'">
  547. <parameter expr="10"/>
  548. <parameter expr="'Browsing for model... OK'"/>
  549. </raise>
  550. </transition>
  551. <transition event="browse_result" target="../got_model">
  552. <parameter name="result"/>
  553. <script>
  554. global current_model
  555. current_model = result
  556. self.locations = {}
  557. </script>
  558. </transition>
  559. </state>
  560. <state id="got_model">
  561. <transition event="close_window" target="../search_metamodels">
  562. <raise event="delete_instance" scope="cd">
  563. <parameter expr="self.subwindow"/>
  564. </raise>
  565. </transition>
  566. </state>
  567. <state id="search_metamodels">
  568. <onentry>
  569. <raise event="mv_request" scope="broad">
  570. <parameter expr="'model_types'"/>
  571. <parameter expr="[current_model]"/>
  572. </raise>
  573. <raise event="update_status" scope="narrow" target="'progress_bar'">
  574. <parameter expr="10"/>
  575. <parameter expr="'Querying existing metamodels...'"/>
  576. </raise>
  577. </onentry>
  578. <transition event="mv_response" target="../search_CS_mappers">
  579. <parameter name="result"/>
  580. <script>
  581. global current_metamodel
  582. if len(result) > 0:
  583. current_metamodel = next(iter(result))[0]
  584. else:
  585. current_metamodel = 'formalisms/Bottom'
  586. self.allowed_metamodels = set([i[0] for i in result])
  587. </script>
  588. <raise event="mv_request" scope="broad">
  589. <parameter expr="'alter_context'"/>
  590. <parameter expr="[current_model, current_metamodel]"/>
  591. </raise>
  592. <raise event="update_status" scope="narrow" target="'progress_bar'">
  593. <parameter expr="20"/>
  594. <parameter expr="'Querying existing metamodels... OK'"/>
  595. </raise>
  596. </transition>
  597. </state>
  598. <state id="search_CS_mappers">
  599. <onentry>
  600. <raise event="mv_request" scope="broad">
  601. <parameter expr="'transformation_between'"/>
  602. <parameter expr="[{'abstract': current_metamodel, 'rendered': 'formalisms/MM_render/graphical'}, {'rendered': 'formalisms/MM_render/graphical'}]"/>
  603. </raise>
  604. <raise event="update_status" scope="narrow" target="'progress_bar'">
  605. <parameter expr="25"/>
  606. <parameter expr="'Querying available Concrete Syntax mappers...'"/>
  607. </raise>
  608. </onentry>
  609. <transition event="mv_response" target="../check_CS_mapper">
  610. <parameter name="result"/>
  611. <script>
  612. result.add("(none)")
  613. self.allowed_mappers = list(result)
  614. global current_mapper
  615. if current_mapper is None:
  616. current_mapper = None
  617. elif current_mapper not in result:
  618. current_mapper = next(iter(result))
  619. if current_mapper == "(none)":
  620. current_mapper = None
  621. </script>
  622. <raise event="update_status" scope="narrow" target="'progress_bar'">
  623. <parameter expr="30"/>
  624. <parameter expr="'Querying available Concrete Syntax mappers... OK'"/>
  625. </raise>
  626. </transition>
  627. <transition event="mv_exception" target="../check_CS_mapper">
  628. <script>
  629. self.allowed_mappers = ["(none)"]
  630. global current_mapper
  631. current_mapper = None
  632. </script>
  633. <raise event="update_status" scope="narrow" target="'progress_bar'">
  634. <parameter expr="30"/>
  635. <parameter expr="'Querying available Concrete Syntax mappers... OK'"/>
  636. </raise>
  637. </transition>
  638. </state>
  639. <state id="check_CS_mapper">
  640. <transition cond="current_mapper is None" target="../../rerender_model">
  641. <script>
  642. global current_rendered_model
  643. current_rendered_model = None
  644. self.allowed_rendered = []
  645. </script>
  646. <raise event="clear_canvas" scope="narrow" target="'canvas'"/>
  647. <raise event="update_status" scope="narrow" target="'progress_bar'">
  648. <parameter expr="35"/>
  649. <parameter expr="'Rendering model with internal renderer...'"/>
  650. </raise>
  651. </transition>
  652. <transition cond="current_mapper is not None" target="../search_CS_rendered"/>
  653. </state>
  654. <state id="search_CS_rendered">
  655. <onentry>
  656. <raise event="mv_request" scope="broad">
  657. <parameter expr="'model_rendered'"/>
  658. <parameter expr="[current_model, current_mapper]"/>
  659. </raise>
  660. <raise event="update_status" scope="narrow" target="'progress_bar'">
  661. <parameter expr="35"/>
  662. <parameter expr="'Rendering model with custom renderer...'"/>
  663. </raise>
  664. </onentry>
  665. <transition event="mv_response" target="../store_metamodel">
  666. <parameter name="result"/>
  667. <script>
  668. self.allowed_rendered = list(result)
  669. #self.allowed_rendered.append("(none)")
  670. global current_rendered_model
  671. if (len(result) > 0):
  672. if current_rendered_model not in result:
  673. current_rendered_model = next(iter(result))
  674. else:
  675. current_rendered_model = "rendered/%s" % str(uuid.uuid4())
  676. self.allowed_rendered.append(current_rendered_model)
  677. if current_rendered_model == "(none)":
  678. current_rendered_model = None
  679. </script>
  680. </transition>
  681. </state>
  682. <state id="store_metamodel">
  683. <onentry>
  684. <raise event="mv_request" scope="broad">
  685. <parameter expr="'alter_context'"/>
  686. <parameter expr="[current_model, current_metamodel]"/>
  687. </raise>
  688. <raise event="update_status" scope="narrow" target="'progress_bar'">
  689. <parameter expr="45"/>
  690. <parameter expr="'Storing model context...'"/>
  691. </raise>
  692. </onentry>
  693. <transition target="../../rerender_model"/>
  694. </state>
  695. </state>
  696. <state id="new_rendered">
  697. <onentry>
  698. <script>
  699. global current_rendered_model
  700. current_rendered_model = "rendered/%s" % str(uuid.uuid4())
  701. self.allowed_rendered.append(current_rendered_model)
  702. </script>
  703. </onentry>
  704. <transition target="../rerender_model"/>
  705. </state>
  706. <state id="create_new_model" initial="query_metamodel">
  707. <state id="query_metamodel">
  708. <onentry>
  709. <raise event="create_instance" scope="cd">
  710. <parameter expr="'subwindow'"/>
  711. <parameter expr="'Browser'"/>
  712. <parameter expr="'Select metamodel to instantiate'"/>
  713. <parameter expr="['formalisms/SimpleClassDiagrams']"/>
  714. </raise>
  715. <raise event="update_status" scope="narrow" target="'progress_bar'">
  716. <parameter expr="5"/>
  717. <parameter expr="'Browsing for metamodel...'"/>
  718. </raise>
  719. </onentry>
  720. <transition event="instance_created" target="../wait_for_metamodel">
  721. <parameter name="association_name"/>
  722. <raise event="start_instance" scope="cd">
  723. <parameter expr="association_name"/>
  724. </raise>
  725. <script>
  726. self.subwindow = association_name
  727. </script>
  728. </transition>
  729. </state>
  730. <state id="wait_for_metamodel">
  731. <transition event="close_window" target="../../idle">
  732. <raise event="delete_instance" scope="cd">
  733. <parameter expr="self.subwindow"/>
  734. </raise>
  735. </transition>
  736. <transition event="browse_result" target="../got_mm">
  737. <parameter name="result"/>
  738. <script>
  739. global current_metamodel
  740. current_metamodel = result
  741. </script>
  742. </transition>
  743. </state>
  744. <state id="got_mm">
  745. <transition event="close_window" target="../prompt_model_name">
  746. <raise event="delete_instance" scope="cd">
  747. <parameter expr="self.subwindow"/>
  748. </raise>
  749. </transition>
  750. </state>
  751. <state id="prompt_model_name">
  752. <onentry>
  753. <raise event="create_instance" scope="cd">
  754. <parameter expr="'subwindow'"/>
  755. <parameter expr="'PromptWindow'"/>
  756. <parameter expr="{'Model name': ''}"/>
  757. <parameter expr="{}"/>
  758. </raise>
  759. <raise event="update_status" scope="narrow" target="'progress_bar'">
  760. <parameter expr="15"/>
  761. <parameter expr="'Prompt model name...'"/>
  762. </raise>
  763. </onentry>
  764. <transition event="instance_created" target="../waiting_for_model_name">
  765. <parameter name="association_name"/>
  766. <raise event="start_instance" scope="cd">
  767. <parameter expr="association_name"/>
  768. </raise>
  769. <script>
  770. global current_model
  771. self.subwindow = association_name
  772. current_model = ""
  773. self.locations = {}
  774. </script>
  775. </transition>
  776. </state>
  777. <state id="waiting_for_model_name">
  778. <transition event="prompt_results" target=".">
  779. <parameter name="results"/>
  780. <script>
  781. global current_model
  782. current_model = results["Model name"]
  783. self.locations = {}
  784. </script>
  785. </transition>
  786. <transition event="close_window" cond="current_model != ''" target="../creating_model">
  787. <raise event="delete_instance" scope="cd">
  788. <parameter expr="self.subwindow"/>
  789. </raise>
  790. <raise event="mv_request" scope="broad">
  791. <parameter expr="'alter_context'"/>
  792. <parameter expr="[current_model, current_metamodel]"/>
  793. </raise>
  794. </transition>
  795. <transition event="close_window" cond="current_model == ''" target="../../idle">
  796. <raise event="delete_instance" scope="cd">
  797. <parameter expr="self.subwindow"/>
  798. </raise>
  799. </transition>
  800. </state>
  801. <state id="creating_model">
  802. <onentry>
  803. <raise event="mv_request" scope="broad">
  804. <parameter expr="'model_add'"/>
  805. <parameter expr="[current_model, current_metamodel, '']"/>
  806. </raise>
  807. <raise event="update_status" scope="narrow" target="'progress_bar'">
  808. <parameter expr="25"/>
  809. <parameter expr="'Creating empty model...'"/>
  810. </raise>
  811. </onentry>
  812. <transition event="mv_response" target="../../open_model/search_metamodels">
  813. <raise event="update_status" scope="narrow" target="'progress_bar'">
  814. <parameter expr="50"/>
  815. <parameter expr="'Creating empty model... OK'"/>
  816. </raise>
  817. </transition>
  818. </state>
  819. </state>
  820. <state id="rerender_model" initial="initial_render">
  821. <onentry>
  822. <raise event="update_status" scope="narrow" target="'progress_bar'">
  823. <parameter expr="50"/>
  824. <parameter expr="'Rendering model...'"/>
  825. </raise>
  826. </onentry>
  827. <state id="initial_render">
  828. <transition cond="self.model_loaded" target="../recreate_toolbars"/>
  829. <transition cond="not self.model_loaded" target="../canvas">
  830. <script>
  831. self.model_loaded = True
  832. </script>
  833. </transition>
  834. </state>
  835. <state id="recreate_toolbars" initial="waiting">
  836. <onentry>
  837. <raise event="close" scope="narrow" target="'model_toolbars'"/>
  838. <script>
  839. self.nr_toolbars = 3
  840. </script>
  841. </onentry>
  842. <state id="waiting">
  843. <transition event="close_window" target=".">
  844. <script>
  845. self.nr_toolbars -= 1
  846. </script>
  847. </transition>
  848. <transition cond="self.nr_toolbars == 0" target="../close_all"/>
  849. </state>
  850. <state id="close_all">
  851. <transition target="../../model_toolbars">
  852. <raise event="delete_instance" scope="cd">
  853. <parameter expr="'model_toolbars'"/>
  854. </raise>
  855. </transition>
  856. </state>
  857. </state>
  858. <state id="canvas">
  859. <onentry>
  860. <raise event="create_instance" scope="cd">
  861. <parameter expr="'canvas'"/>
  862. <parameter expr="'Canvas'"/>
  863. <parameter expr="self.canvas_frame"/>
  864. </raise>
  865. </onentry>
  866. <transition event="instance_created" target="../pack_canvas">
  867. <parameter name="association_name"/>
  868. <raise event="start_instance" scope="cd">
  869. <parameter expr="association_name"/>
  870. </raise>
  871. </transition>
  872. </state>
  873. <state id="pack_canvas">
  874. <transition event="tk_widget" target="../model_toolbars">
  875. <parameter name="tk_elem"/>
  876. <script>
  877. tk_elem.pack(fill=tk.BOTH, expand=tk.TRUE)
  878. </script>
  879. </transition>
  880. </state>
  881. <state id="model_toolbars" initial="mm_toolbar">
  882. <state id="mm_toolbar">
  883. <onentry>
  884. <raise event="create_instance" scope="cd">
  885. <parameter expr="'model_toolbars'"/>
  886. <parameter expr="'MetamodellingToolbar'"/>
  887. <parameter expr="self.toolbar_frame"/>
  888. <parameter expr="current_metamodel"/>
  889. <parameter expr="self.allowed_metamodels"/>
  890. </raise>
  891. </onentry>
  892. <transition event="instance_created" target="../pack_mm_toolbar">
  893. <parameter name="association_name"/>
  894. <raise event="start_instance" scope="cd">
  895. <parameter expr="association_name"/>
  896. </raise>
  897. </transition>
  898. </state>
  899. <state id="pack_mm_toolbar">
  900. <transition event="tk_widget" target="../cs_toolbar">
  901. <parameter name="tk_elem"/>
  902. <script>
  903. tk_elem.pack(anchor=tk.W)
  904. </script>
  905. </transition>
  906. </state>
  907. <state id="cs_toolbar">
  908. <onentry>
  909. <raise event="create_instance" scope="cd">
  910. <parameter expr="'model_toolbars'"/>
  911. <parameter expr="'ConcreteSyntaxToolbar'"/>
  912. <parameter expr="self.toolbar_frame"/>
  913. <parameter expr="self.allowed_mappers"/>
  914. <parameter expr="self.allowed_rendered"/>
  915. </raise>
  916. </onentry>
  917. <transition event="instance_created" target="../pack_cs_toolbar">
  918. <parameter name="association_name"/>
  919. <raise event="start_instance" scope="cd">
  920. <parameter expr="association_name"/>
  921. </raise>
  922. </transition>
  923. </state>
  924. <state id="pack_cs_toolbar">
  925. <transition event="tk_widget" target="../fetch_types">
  926. <parameter name="tk_elem"/>
  927. <script>
  928. tk_elem.pack(anchor=tk.W)
  929. </script>
  930. </transition>
  931. </state>
  932. <state id="fetch_types">
  933. <onentry>
  934. <raise event="mv_request" scope="broad">
  935. <parameter expr="'types'"/>
  936. <parameter expr="[current_model]"/>
  937. </raise>
  938. </onentry>
  939. <transition event="mv_response" target="../dsl_toolbar">
  940. <parameter name="result"/>
  941. <raise event="create_instance" scope="cd">
  942. <parameter expr="'model_toolbars'"/>
  943. <parameter expr="'DSLToolbar'"/>
  944. <parameter expr="self.toolbar_frame"/>
  945. <parameter expr="result"/>
  946. </raise>
  947. </transition>
  948. </state>
  949. <state id="dsl_toolbar">
  950. <transition event="instance_created" target="../pack_dsl_toolbar">
  951. <parameter name="association_name"/>
  952. <raise event="start_instance" scope="cd">
  953. <parameter expr="association_name"/>
  954. </raise>
  955. </transition>
  956. </state>
  957. <state id="pack_dsl_toolbar">
  958. <transition event="tk_widget" target="../../request_render">
  959. <parameter name="tk_elem"/>
  960. <script>
  961. tk_elem.pack(anchor=tk.W)
  962. </script>
  963. </transition>
  964. </state>
  965. </state>
  966. <state id="request_render">
  967. <onentry>
  968. <raise event="update_status" scope="narrow" target="'progress_bar'">
  969. <parameter expr="50"/>
  970. <parameter expr="'Perceptualizing model...'"/>
  971. </raise>
  972. <raise event="mv_request" scope="broad">
  973. <parameter expr="'model_render' if current_rendered_model else 'element_list_nice'"/>
  974. <parameter expr="[current_model, current_mapper, current_rendered_model] if current_rendered_model else [current_model]"/>
  975. </raise>
  976. </onentry>
  977. <transition event="mv_response" cond="current_rendered_model" target="../render_model">
  978. <parameter name="result"/>
  979. <script>
  980. self.rendered = result
  981. </script>
  982. </transition>
  983. <transition event="mv_response" cond="not current_rendered_model" target="../render_model">
  984. <parameter name="result"/>
  985. <script>
  986. self.rendered = []
  987. print("Got model: " + str(result))
  988. group_counter = 0
  989. groups = {}
  990. edges = []
  991. defined_attributes = {}
  992. names = {}
  993. if current_metamodel == "formalisms/SimpleClassDiagrams":
  994. for elem in result:
  995. if elem["__type"] == "AttributeLink":
  996. defined_attributes.setdefault(elem["__source"], []).append((elem["name"], elem["__target"], True if elem["optional"] == True else False))
  997. if "name" in elem:
  998. names[elem["__id"]] = elem["name"]
  999. print("Got defined attributes: " + str(defined_attributes))
  1000. print("Got names: " + str(names))
  1001. for elem in list(result):
  1002. is_edge = False
  1003. attrs = {}
  1004. for key, value in elem.items():
  1005. if key == "__id":
  1006. element_id = value
  1007. elif key == "__source":
  1008. element_source = value
  1009. is_edge = True
  1010. elif key == "__target":
  1011. element_target = value
  1012. is_edge = True
  1013. elif key == "__type":
  1014. element_type = value
  1015. else:
  1016. attrs[key] = value
  1017. max_text = 0
  1018. if is_edge:
  1019. edge_edge = len([x for x in result if (x["__id"] == element_source or x["__id"] == element_target) and "__source" in x]) > 0
  1020. else:
  1021. edge_edge = False
  1022. if is_edge:
  1023. if not (elem["__type"] == "AttributeLink" and current_metamodel == "formalisms/SimpleClassDiagrams"):
  1024. cs_elem_id = str(uuid.uuid4())
  1025. edges.append({"id": cs_elem_id, "type": "ConnectingLine", "offsetSourceX": 0 if edge_edge else 100, "offsetSourceY": 0 if edge_edge else 30, "offsetTargetX": 100, "offsetTargetY": 30, "lineWidth": 3, "lineColour": "black", "arrow": True, "__asid": element_id, "layer": 0, "__source": element_source, "__target": element_target})
  1026. groups[element_id] = cs_elem_id
  1027. else:
  1028. # Add the group
  1029. x, y = self.locations.get(element_id, (30 + (group_counter * 250) % 1000, 30 + ((group_counter / 4) * 250)))
  1030. self.rendered.append({"id": str(group_counter), "type": "Group", "x": x, "y": y, "__asid": element_id})
  1031. self.locations[element_id] = (x, y)
  1032. group_id = str(group_counter)
  1033. groups[element_id] = group_id
  1034. group_counter += 1
  1035. # Add the text elements
  1036. # First the header
  1037. cs_elem_id = str(uuid.uuid4())
  1038. self.rendered.append({"id": cs_elem_id, "type": "Text", "x": 10, "y": 10, "text": "%s : %s" % (element_id, element_type), "lineWidth": 1, "lineColour": "black", "layer": 2})
  1039. self.rendered.append({"id": str(uuid.uuid4()), "type": "contains", "__source": group_id, "__target": cs_elem_id})
  1040. max_text = max(len("%s : %s" % (element_id, element_type)), max_text)
  1041. # Then the attributes
  1042. text_counter = 1
  1043. for name, attr_type, optional in defined_attributes.get(elem["__id"], []):
  1044. cs_elem_id = str(uuid.uuid4())
  1045. text = "%s : %s" % (name, names.get(attr_type, "(%s)" % attr_type))
  1046. if optional:
  1047. text = text.replace(" : ", " ?: ")
  1048. self.rendered.append({"id": cs_elem_id, "type": "Text", "x": 10, "y": 25 + text_counter * 11, "text": text, "lineWidth": 3, "lineColour": "black", "layer": 2})
  1049. max_text = max(len(text), max_text)
  1050. self.rendered.append({"id": str(uuid.uuid4()), "type": "contains", "__source": group_id, "__target": cs_elem_id})
  1051. text_counter += 1
  1052. if text_counter > 1:
  1053. text_counter += 1
  1054. for key, value in attrs.items():
  1055. cs_elem_id = str(uuid.uuid4())
  1056. if isinstance(value, dict):
  1057. text = "%s = ^%s" % (key, value['AL'])
  1058. else:
  1059. text = ("%s = %s" % (key, value)) if value is not None else ("(%s)" % key)
  1060. self.rendered.append({"id": cs_elem_id, "type": "Text", "x": 10, "y": 25 + text_counter * 11, "text": text, "lineWidth": 3, "lineColour": "black", "layer": 2})
  1061. max_text = max(len(text), max_text)
  1062. self.rendered.append({"id": str(uuid.uuid4()), "type": "contains", "__source": group_id, "__target": cs_elem_id})
  1063. text_counter += 1
  1064. # Add the rectangle
  1065. cs_elem_id = str(uuid.uuid4())
  1066. self.rendered.append({"id": cs_elem_id, "type": "Rectangle", "x": 0, "y": 0, "width": max_text * 8, "height": 35 + text_counter * 11, "lineWidth": 1, "lineColour": "black", "fillColour": "white", "layer": 1})
  1067. self.rendered.append({"id": str(uuid.uuid4()), "type": "contains", "__source": group_id, "__target": cs_elem_id})
  1068. # Add the line
  1069. cs_elem_id = str(uuid.uuid4())
  1070. self.rendered.append({"id": cs_elem_id, "type": "Line", "x": 0, "y": 20, "targetX": max_text * 8, "targetY": 20, "lineWidth": 1, "lineColour": "black", "layer": 0, "arrow": False})
  1071. self.rendered.append({"id": str(uuid.uuid4()), "type": "contains", "__source": group_id, "__target": cs_elem_id})
  1072. for edge in edges:
  1073. edge["__source"] = groups[edge["__source"]]
  1074. edge["__target"] = groups[edge["__target"]]
  1075. self.rendered.append(edge)
  1076. </script>
  1077. </transition>
  1078. <transition event="mv_exception" target="../../../close"/>
  1079. </state>
  1080. <state id="render_model" initial="allocate_groups">
  1081. <onentry>
  1082. <raise event="update_status" scope="narrow" target="'progress_bar'">
  1083. <parameter expr="80"/>
  1084. <parameter expr="'Perceptualizing model... OK'"/>
  1085. </raise>
  1086. <raise event="clear_canvas" scope="narrow" target="'canvas'"/>
  1087. <script>
  1088. self.groups = [i for i in self.rendered if i["type"] == "Group"]
  1089. self.contains = [i for i in self.rendered if i["type"] == "contains"]
  1090. self.rendered = [i for i in self.rendered if i["type"] not in ["Group", "contains"]]
  1091. self.rendered.reverse()
  1092. </script>
  1093. <raise event="mv_request" scope="broad">
  1094. <parameter expr="'alter_context'"/>
  1095. <parameter expr="[current_rendered_model, 'formalisms/MM_render/graphical']"/>
  1096. </raise>
  1097. </onentry>
  1098. <state id="allocate_groups">
  1099. <transition cond="len(self.groups) > 0" target="../allocating_group">
  1100. <raise event="define_group" scope="narrow" target="'canvas'">
  1101. <parameter expr="self.groups.pop()"/>
  1102. </raise>
  1103. </transition>
  1104. <transition cond="len(self.groups) == 0" target="../allocate_contains"/>
  1105. </state>
  1106. <state id="allocating_group">
  1107. <transition event="group_ready" target="../allocate_groups"/>
  1108. </state>
  1109. <state id="allocate_contains">
  1110. <transition cond="len(self.contains) > 0" target=".">
  1111. <raise event="define_contains" scope="narrow" target="'canvas'">
  1112. <parameter expr="self.contains.pop()"/>
  1113. </raise>
  1114. </transition>
  1115. <transition cond="len(self.contains) == 0" target="../render_elements"/>
  1116. </state>
  1117. <state id="render_elements">
  1118. <transition cond="len(self.rendered) > 0" target=".">
  1119. <raise event="draw_canvas" scope="narrow" target="'canvas'">
  1120. <parameter expr="self.rendered.pop()"/>
  1121. </raise>
  1122. </transition>
  1123. <transition cond="len(self.rendered) == 0" target="../../../idle"/>
  1124. </state>
  1125. </state>
  1126. </state>
  1127. <transition event="window-close" cond="ID == id(self)" target="../close">
  1128. <parameter name="ID"/>
  1129. </transition>
  1130. </state>
  1131. <state id="close">
  1132. <onentry>
  1133. <raise event="close_window" scope="narrow" target="'parent'"/>
  1134. </onentry>
  1135. </state>
  1136. </state>
  1137. <state id="key_status">
  1138. <onentry>
  1139. <script>
  1140. global control_pressed
  1141. control_pressed = False
  1142. </script>
  1143. </onentry>
  1144. <state id="listening">
  1145. <transition event="control" target=".">
  1146. <script>
  1147. global control_pressed
  1148. control_pressed = True
  1149. </script>
  1150. </transition>
  1151. <transition event="control-release" target=".">
  1152. <script>
  1153. global control_pressed
  1154. control_pressed = False
  1155. </script>
  1156. </transition>
  1157. </state>
  1158. </state>
  1159. <state id="mover">
  1160. <state id="move">
  1161. <transition event="move" target=".">
  1162. <parameter name="asid"/>
  1163. <parameter name="location"/>
  1164. <script>
  1165. self.locations[asid] = location
  1166. </script>
  1167. </transition>
  1168. </state>
  1169. </state>
  1170. </parallel>
  1171. </scxml>
  1172. </class>