debugging_environment.js 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. /**
  2. * Statechart compiler by Glenn De Jonghe
  3. * Javascript generator by Joeri Exelmans
  4. *
  5. * Date: Tue Jun 26 11:21:44 2018
  6. *
  7. * Model author: Simon Van Mierlo
  8. * Model name: DebuggingEnvironment
  9. * Model description:
  10. Debugging environment for Dynamic Structure DEVS in HTML + JS (d3/w2ui).
  11. */
  12. // put everything in an object (serves as "namespace")
  13. DebuggingEnvironment = {};
  14. // closure scope
  15. (function() {
  16. // The actual constructor
  17. var MainApp = function(controller) {
  18. MainApp.prototype.commonConstructor.call(this,controller);
  19. // constructor body (user-defined)
  20. };
  21. MainApp.prototype = new RuntimeClassBase();
  22. // Unique IDs for all statechart nodes
  23. MainApp.prototype.Root = 0;
  24. MainApp.prototype.Root_creating_toolbar = 1;
  25. MainApp.prototype.Root_creating_visualizer = 2;
  26. MainApp.prototype.Root_running = 3;
  27. // Statechart enter/exit action method(s) :
  28. MainApp.prototype.enter_Root_creating_toolbar = function() {
  29. this.object_manager.addEvent(new Event("create_instance", null, [this, 'toolbar','DebuggingToolbar']));
  30. this.current_state[this.Root].push(this.Root_creating_toolbar);
  31. };
  32. MainApp.prototype.exit_Root_creating_toolbar = function() {
  33. this.current_state[this.Root] = new Array();
  34. };
  35. MainApp.prototype.enter_Root_creating_visualizer = function() {
  36. this.object_manager.addEvent(new Event("create_instance", null, [this, 'visualizer','Visualizer']));
  37. this.current_state[this.Root].push(this.Root_creating_visualizer);
  38. };
  39. MainApp.prototype.exit_Root_creating_visualizer = function() {
  40. this.current_state[this.Root] = new Array();
  41. };
  42. MainApp.prototype.enter_Root_running = function() {
  43. this.current_state[this.Root].push(this.Root_running);
  44. };
  45. MainApp.prototype.exit_Root_running = function() {
  46. this.current_state[this.Root] = new Array();
  47. };
  48. // Statechart transitions :
  49. MainApp.prototype.transition_Root = function(event) {
  50. var catched = false;
  51. if (!catched) {
  52. if (this.current_state[this.Root][0] === this.Root_creating_toolbar) {
  53. catched = this.transition_Root_creating_toolbar(event);
  54. }
  55. else if (this.current_state[this.Root][0] === this.Root_creating_visualizer) {
  56. catched = this.transition_Root_creating_visualizer(event);
  57. }
  58. else if (this.current_state[this.Root][0] === this.Root_running) {
  59. catched = this.transition_Root_running(event);
  60. }
  61. }
  62. return catched;
  63. };
  64. MainApp.prototype.transition_Root_creating_toolbar = function(event) {
  65. var catched = false;
  66. var enableds = new Array();
  67. if (event.name === "instance_created") {
  68. enableds.push(1);
  69. }
  70. if (enableds.length > 1) {
  71. console.log("Runtime warning : indeterminism detected in a transition from node Root_creating_toolbar. Only the first in document order enabled transition is executed.")
  72. }
  73. if (enableds.length > 0) {
  74. var enabled = enableds[0];
  75. if (enabled === 1) {
  76. var parameters = event.parameters;
  77. var association_name = parameters[0];
  78. this.exit_Root_creating_toolbar();
  79. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  80. this.enter_Root_creating_visualizer();
  81. }
  82. catched = true;
  83. }
  84. return catched;
  85. };
  86. MainApp.prototype.transition_Root_creating_visualizer = function(event) {
  87. var catched = false;
  88. var enableds = new Array();
  89. if (event.name === "instance_created") {
  90. enableds.push(1);
  91. }
  92. if (enableds.length > 1) {
  93. console.log("Runtime warning : indeterminism detected in a transition from node Root_creating_visualizer. Only the first in document order enabled transition is executed.")
  94. }
  95. if (enableds.length > 0) {
  96. var enabled = enableds[0];
  97. if (enabled === 1) {
  98. var parameters = event.parameters;
  99. var association_name = parameters[0];
  100. this.exit_Root_creating_visualizer();
  101. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  102. this.enter_Root_running();
  103. }
  104. catched = true;
  105. }
  106. return catched;
  107. };
  108. MainApp.prototype.transition_Root_running = function(event) {
  109. var catched = false;
  110. return catched;
  111. };
  112. // Execute transitions
  113. MainApp.prototype.transition = function(event) {
  114. if (!event) event = new Event();
  115. this.state_changed = this.transition_Root(event);
  116. };
  117. // inState method for statechart
  118. MainApp.prototype.inState = function(nodes) {
  119. for (var c in this.current_state) {
  120. if (!this.current_state.hasOwnProperty(c)) continue;
  121. var new_nodes = new Array();
  122. for (var n in nodes) {
  123. if (!nodes.hasOwnProperty(n)) continue;
  124. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  125. new_nodes.push(nodes[n]);
  126. }
  127. }
  128. nodes = new_nodes;
  129. if (nodes.length === 0) {
  130. return true;
  131. }
  132. }
  133. return false;
  134. };
  135. MainApp.prototype.commonConstructor = function(controller) {
  136. if (!controller) controller = null;
  137. // Constructor part that is common for all constructors.
  138. RuntimeClassBase.call(this);
  139. // User defined input ports
  140. this.inports = new Object();
  141. this.controller = controller;
  142. this.object_manager = (controller == null ? null : controller.object_manager);
  143. this.current_state = new Object();
  144. this.history_state = new Object();
  145. // Initialize statechart
  146. this.current_state[this.Root] = new Array();
  147. };
  148. MainApp.prototype.start = function() {
  149. RuntimeClassBase.prototype.start.call(this);
  150. this.enter_Root_creating_toolbar();
  151. };
  152. // put class in global diagram object
  153. DebuggingEnvironment.MainApp = MainApp;
  154. // The actual constructor
  155. var DebuggingToolbar = function(controller) {
  156. DebuggingToolbar.prototype.commonConstructor.call(this,controller);
  157. // constructor body (user-defined)
  158. this.visualized_simulator = "NETLOGO"
  159. this.parameters = {};
  160. this.buttons = {};
  161. this.curr_parameter = null;
  162. this.button_counter = 0;
  163. if (this.visualized_simulator == "NETLOGO") {
  164. this.buttons_to_create = [{parent: this, description: 'Simulate', icon: 'simulate', command: 'simulate'},
  165. {parent: this, description: 'Realtime Simulate', icon: 'simulatert', command: 'realtime', parameter_needed: 'realtime_scale'},
  166. {parent: this, description: 'Realtime Scale', html: 'input size="1" value="1.0" style="border: 1px solid silver"', default: 1.0, parameter: 'realtime_scale'},
  167. {parent: this, description: 'Pause', icon: 'pause', command: 'pause'},
  168. {parent: this, description: 'Big Step', icon: 'bigstep', command: 'big_step'},
  169. {parent: this, description: 'Reset', icon: 'reset', command: 'reset'},
  170. {parent: this, description: 'Add Breakpoint', icon: 'breakpoint', action: function() {breakpoint_dialog.dialog( "open" );}}];
  171. } else {
  172. this.buttons_to_create = [{parent: this, description: 'Simulate', icon: 'simulate', command: 'simulate'},
  173. {parent: this, description: 'Realtime Simulate', icon: 'simulatert', command: 'realtime', parameter_needed: 'realtime_scale'},
  174. {parent: this, description: 'Realtime Scale', html: 'input size="1" value="1.0" style="border: 1px solid silver"', default: 1.0, parameter: 'realtime_scale'},
  175. {parent: this, description: 'Pause', icon: 'pause', command: 'pause'},
  176. {parent: this, description: 'Big Step', icon: 'bigstep', command: 'big_step'},
  177. {parent: this, description: 'Small Step', icon: 'smallstep', command: 'small_step'},
  178. {parent: this, description: 'Reset', icon: 'reset', command: 'reset'},
  179. {parent: this, description: 'Add Breakpoint', icon: 'breakpoint', action: function() {breakpoint_dialog.dialog( "open" );}}];
  180. }
  181. this.tb = ui.create_toolbar('DebuggingToolbar');
  182. };
  183. DebuggingToolbar.prototype = new RuntimeClassBase();
  184. // Unique IDs for all statechart nodes
  185. DebuggingToolbar.prototype.Root = 0;
  186. DebuggingToolbar.prototype.Root_initializing = 1;
  187. DebuggingToolbar.prototype.Root_initializing_check = 2;
  188. DebuggingToolbar.prototype.Root_initializing_creating_button = 3;
  189. DebuggingToolbar.prototype.Root_initializing_running = 4;
  190. DebuggingToolbar.prototype.Root_initializing_getting_parameter = 5;
  191. // Statechart enter/exit action method(s) :
  192. DebuggingToolbar.prototype.enter_Root_initializing = function() {
  193. this.current_state[this.Root].push(this.Root_initializing);
  194. };
  195. DebuggingToolbar.prototype.exit_Root_initializing = function() {
  196. if (this.current_state[this.Root_initializing].indexOf(this.Root_initializing_check) !== -1) {
  197. this.exit_Root_initializing_check();
  198. }
  199. if (this.current_state[this.Root_initializing].indexOf(this.Root_initializing_creating_button) !== -1) {
  200. this.exit_Root_initializing_creating_button();
  201. }
  202. if (this.current_state[this.Root_initializing].indexOf(this.Root_initializing_running) !== -1) {
  203. this.exit_Root_initializing_running();
  204. }
  205. if (this.current_state[this.Root_initializing].indexOf(this.Root_initializing_getting_parameter) !== -1) {
  206. this.exit_Root_initializing_getting_parameter();
  207. }
  208. this.current_state[this.Root] = new Array();
  209. };
  210. DebuggingToolbar.prototype.enter_Root_initializing_check = function() {
  211. this.current_state[this.Root_initializing].push(this.Root_initializing_check);
  212. };
  213. DebuggingToolbar.prototype.exit_Root_initializing_check = function() {
  214. this.current_state[this.Root_initializing] = new Array();
  215. };
  216. DebuggingToolbar.prototype.enter_Root_initializing_creating_button = function() {
  217. this.current_state[this.Root_initializing].push(this.Root_initializing_creating_button);
  218. };
  219. DebuggingToolbar.prototype.exit_Root_initializing_creating_button = function() {
  220. this.current_state[this.Root_initializing] = new Array();
  221. };
  222. DebuggingToolbar.prototype.enter_Root_initializing_running = function() {
  223. this.current_state[this.Root_initializing].push(this.Root_initializing_running);
  224. };
  225. DebuggingToolbar.prototype.exit_Root_initializing_running = function() {
  226. this.current_state[this.Root_initializing] = new Array();
  227. };
  228. DebuggingToolbar.prototype.enter_Root_initializing_getting_parameter = function() {
  229. this.current_state[this.Root_initializing].push(this.Root_initializing_getting_parameter);
  230. };
  231. DebuggingToolbar.prototype.exit_Root_initializing_getting_parameter = function() {
  232. this.current_state[this.Root_initializing] = new Array();
  233. };
  234. // Statechart enter/exit default method(s) :
  235. DebuggingToolbar.prototype.enterDefault_Root_initializing = function() {
  236. this.enter_Root_initializing();
  237. this.enter_Root_initializing_check();
  238. };
  239. // Statechart transitions :
  240. DebuggingToolbar.prototype.transition_Root = function(event) {
  241. var catched = false;
  242. if (!catched) {
  243. if (this.current_state[this.Root][0] === this.Root_initializing) {
  244. catched = this.transition_Root_initializing(event);
  245. }
  246. }
  247. return catched;
  248. };
  249. DebuggingToolbar.prototype.transition_Root_initializing = function(event) {
  250. var catched = false;
  251. if (!catched) {
  252. if (this.current_state[this.Root_initializing][0] === this.Root_initializing_check) {
  253. catched = this.transition_Root_initializing_check(event);
  254. }
  255. else if (this.current_state[this.Root_initializing][0] === this.Root_initializing_creating_button) {
  256. catched = this.transition_Root_initializing_creating_button(event);
  257. }
  258. else if (this.current_state[this.Root_initializing][0] === this.Root_initializing_running) {
  259. catched = this.transition_Root_initializing_running(event);
  260. }
  261. else if (this.current_state[this.Root_initializing][0] === this.Root_initializing_getting_parameter) {
  262. catched = this.transition_Root_initializing_getting_parameter(event);
  263. }
  264. }
  265. return catched;
  266. };
  267. DebuggingToolbar.prototype.transition_Root_initializing_check = function(event) {
  268. var catched = false;
  269. var enableds = new Array();
  270. if (this.buttons_to_create.length > 0) {
  271. enableds.push(1);
  272. }
  273. if (this.buttons_to_create.length == 0) {
  274. enableds.push(2);
  275. }
  276. if (enableds.length > 1) {
  277. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing_check. Only the first in document order enabled transition is executed.")
  278. }
  279. if (enableds.length > 0) {
  280. var enabled = enableds[0];
  281. if (enabled === 1) {
  282. this.exit_Root_initializing_check();
  283. if ('parameter' in this.buttons_to_create[0]) {
  284. this.curr_parameter = this.buttons_to_create[0]['parameter']
  285. }
  286. this.object_manager.addEvent(new Event("create_instance", null, [this, 'buttons','Button','button' + this.button_counter,this.tb,this.buttons_to_create.shift()]));
  287. this.enter_Root_initializing_creating_button();
  288. }
  289. else if (enabled === 2) {
  290. this.exit_Root_initializing_check();
  291. this.enter_Root_initializing_running();
  292. }
  293. catched = true;
  294. }
  295. return catched;
  296. };
  297. DebuggingToolbar.prototype.transition_Root_initializing_creating_button = function(event) {
  298. var catched = false;
  299. var enableds = new Array();
  300. if (event.name === "instance_created") {
  301. enableds.push(1);
  302. }
  303. if (enableds.length > 1) {
  304. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing_creating_button. Only the first in document order enabled transition is executed.")
  305. }
  306. if (enableds.length > 0) {
  307. var enabled = enableds[0];
  308. if (enabled === 1) {
  309. var parameters = event.parameters;
  310. var association_name = parameters[0];
  311. this.exit_Root_initializing_creating_button();
  312. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  313. if (this.curr_parameter) {
  314. this.parameters[this.curr_parameter] = association_name;
  315. this.curr_parameter = null;
  316. }
  317. this.buttons['button' + this.button_counter] = association_name;
  318. this.button_counter += 1;
  319. this.enter_Root_initializing_check();
  320. }
  321. catched = true;
  322. }
  323. return catched;
  324. };
  325. DebuggingToolbar.prototype.transition_Root_initializing_running = function(event) {
  326. var catched = false;
  327. var enableds = new Array();
  328. if (event.name === "get_parameter") {
  329. enableds.push(1);
  330. }
  331. if (enableds.length > 1) {
  332. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing_running. Only the first in document order enabled transition is executed.")
  333. }
  334. if (enableds.length > 0) {
  335. var enabled = enableds[0];
  336. if (enabled === 1) {
  337. var parameters = event.parameters;
  338. var the_parameter = parameters[0];
  339. var respond_id = parameters[1];
  340. this.exit_Root_initializing_running();
  341. var send_event = new Event("get_parameter", null, []);
  342. this.object_manager.addEvent(new Event("narrow_cast", null, [this, this.parameters[the_parameter] , send_event]));
  343. this.respond_id = respond_id;
  344. this.enter_Root_initializing_getting_parameter();
  345. }
  346. catched = true;
  347. }
  348. return catched;
  349. };
  350. DebuggingToolbar.prototype.transition_Root_initializing_getting_parameter = function(event) {
  351. var catched = false;
  352. var enableds = new Array();
  353. if (event.name === "parameter_reply") {
  354. enableds.push(1);
  355. }
  356. if (enableds.length > 1) {
  357. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing_getting_parameter. Only the first in document order enabled transition is executed.")
  358. }
  359. if (enableds.length > 0) {
  360. var enabled = enableds[0];
  361. if (enabled === 1) {
  362. var parameters = event.parameters;
  363. var parameter_value = parameters[0];
  364. this.exit_Root_initializing_getting_parameter();
  365. var send_event = new Event("parameter_reply", null, [parameter_value]);
  366. this.object_manager.addEvent(new Event("narrow_cast", null, [this, this.buttons[this.respond_id] , send_event]));
  367. this.enter_Root_initializing_running();
  368. }
  369. catched = true;
  370. }
  371. return catched;
  372. };
  373. // Execute transitions
  374. DebuggingToolbar.prototype.transition = function(event) {
  375. if (!event) event = new Event();
  376. this.state_changed = this.transition_Root(event);
  377. };
  378. // inState method for statechart
  379. DebuggingToolbar.prototype.inState = function(nodes) {
  380. for (var c in this.current_state) {
  381. if (!this.current_state.hasOwnProperty(c)) continue;
  382. var new_nodes = new Array();
  383. for (var n in nodes) {
  384. if (!nodes.hasOwnProperty(n)) continue;
  385. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  386. new_nodes.push(nodes[n]);
  387. }
  388. }
  389. nodes = new_nodes;
  390. if (nodes.length === 0) {
  391. return true;
  392. }
  393. }
  394. return false;
  395. };
  396. DebuggingToolbar.prototype.commonConstructor = function(controller) {
  397. if (!controller) controller = null;
  398. // Constructor part that is common for all constructors.
  399. RuntimeClassBase.call(this);
  400. // User defined input ports
  401. this.inports = new Object();
  402. this.controller = controller;
  403. this.object_manager = (controller == null ? null : controller.object_manager);
  404. this.current_state = new Object();
  405. this.history_state = new Object();
  406. // Initialize statechart
  407. this.current_state[this.Root] = new Array();
  408. this.current_state[this.Root_initializing] = new Array();
  409. };
  410. DebuggingToolbar.prototype.start = function() {
  411. RuntimeClassBase.prototype.start.call(this);
  412. this.enterDefault_Root_initializing();
  413. };
  414. // put class in global diagram object
  415. DebuggingEnvironment.DebuggingToolbar = DebuggingToolbar;
  416. // The actual constructor
  417. var Button = function(controller, button_id, toolbar, parameters) {
  418. Button.prototype.commonConstructor.call(this,controller);
  419. // constructor body (user-defined)
  420. this.button_id = button_id;
  421. this.toolbar = toolbar;
  422. this.action = null;
  423. this.command = null;
  424. if ('parameter_needed' in parameters) {
  425. this.parameter_needed = parameters['parameter_needed'];
  426. } else {
  427. this.parameter_needed = null;
  428. }
  429. if ('html' in parameters) {
  430. var the_html = parameters['html']
  431. the_html += ' id="' + this.button_id + '_input" onchange="ui.parameter_changed(\'' + button_id + '\');"'
  432. this.btn = ui.create_tb_element(this.button_id, '<' + the_html + ' />', parameters['default'], this.toolbar, this.controller, this.inports['button_ui_input']);
  433. } else if ('action' in parameters) {
  434. this.action = parameters['action'];
  435. this.btn = ui.create_button(this.button_id, parameters['description'], parameters['icon'], this.toolbar, this.controller, this.inports['button_ui_input']);
  436. } else {
  437. this.command = parameters['command'];
  438. this.btn = ui.create_button(this.button_id, parameters['description'], parameters['icon'], this.toolbar, this.controller, this.inports['button_ui_input']);
  439. }
  440. };
  441. Button.prototype = new RuntimeClassBase();
  442. // Unique IDs for all statechart nodes
  443. Button.prototype.Root = 0;
  444. Button.prototype.Root_listening = 1;
  445. Button.prototype.Root_getting_parameter = 2;
  446. // Statechart enter/exit action method(s) :
  447. Button.prototype.enter_Root_listening = function() {
  448. this.current_state[this.Root].push(this.Root_listening);
  449. };
  450. Button.prototype.exit_Root_listening = function() {
  451. this.current_state[this.Root] = new Array();
  452. };
  453. Button.prototype.enter_Root_getting_parameter = function() {
  454. this.current_state[this.Root].push(this.Root_getting_parameter);
  455. };
  456. Button.prototype.exit_Root_getting_parameter = function() {
  457. this.current_state[this.Root] = new Array();
  458. };
  459. // Statechart transitions :
  460. Button.prototype.transition_Root = function(event) {
  461. var catched = false;
  462. if (!catched) {
  463. if (this.current_state[this.Root][0] === this.Root_listening) {
  464. catched = this.transition_Root_listening(event);
  465. }
  466. else if (this.current_state[this.Root][0] === this.Root_getting_parameter) {
  467. catched = this.transition_Root_getting_parameter(event);
  468. }
  469. }
  470. return catched;
  471. };
  472. Button.prototype.transition_Root_listening = function(event) {
  473. var catched = false;
  474. var enableds = new Array();
  475. if (event.name === "mouse_press" && event.port === "button_ui_input") {
  476. if (this.action) {
  477. enableds.push(1);
  478. }
  479. }
  480. if (event.name === "mouse_press" && event.port === "button_ui_input") {
  481. if (this.parameter_needed == null && this.command) {
  482. enableds.push(2);
  483. }
  484. }
  485. if (event.name === "mouse_press" && event.port === "button_ui_input") {
  486. if (this.parameter_needed != null && this.command) {
  487. enableds.push(3);
  488. }
  489. }
  490. if (event.name === "get_parameter") {
  491. enableds.push(4);
  492. }
  493. if (enableds.length > 1) {
  494. console.log("Runtime warning : indeterminism detected in a transition from node Root_listening. Only the first in document order enabled transition is executed.")
  495. }
  496. if (enableds.length > 0) {
  497. var enabled = enableds[0];
  498. if (enabled === 1) {
  499. this.exit_Root_listening();
  500. this.action();
  501. this.enter_Root_listening();
  502. }
  503. else if (enabled === 2) {
  504. this.exit_Root_listening();
  505. this.controller.outputEvent(new Event("debugging_command", "output", [this.command]));
  506. this.enter_Root_listening();
  507. }
  508. else if (enabled === 3) {
  509. this.exit_Root_listening();
  510. var send_event = new Event("get_parameter", null, [this.parameter_needed,this.button_id]);
  511. this.object_manager.addEvent(new Event("narrow_cast", null, [this, 'parent' , send_event]));
  512. this.enter_Root_getting_parameter();
  513. }
  514. else if (enabled === 4) {
  515. this.exit_Root_listening();
  516. var send_event = new Event("parameter_reply", null, [this.btn.value]);
  517. this.object_manager.addEvent(new Event("narrow_cast", null, [this, 'parent' , send_event]));
  518. this.enter_Root_listening();
  519. }
  520. catched = true;
  521. }
  522. return catched;
  523. };
  524. Button.prototype.transition_Root_getting_parameter = function(event) {
  525. var catched = false;
  526. var enableds = new Array();
  527. if (event.name === "parameter_reply") {
  528. enableds.push(1);
  529. }
  530. if (enableds.length > 1) {
  531. console.log("Runtime warning : indeterminism detected in a transition from node Root_getting_parameter. Only the first in document order enabled transition is executed.")
  532. }
  533. if (enableds.length > 0) {
  534. var enabled = enableds[0];
  535. if (enabled === 1) {
  536. var parameters = event.parameters;
  537. var the_parameter = parameters[0];
  538. this.exit_Root_getting_parameter();
  539. var the_parameters = {};
  540. the_parameters[this.parameter_needed] = the_parameter;
  541. this.controller.outputEvent(new Event("debugging_command", "output", [this.command,the_parameters]));
  542. this.enter_Root_listening();
  543. }
  544. catched = true;
  545. }
  546. return catched;
  547. };
  548. // Execute transitions
  549. Button.prototype.transition = function(event) {
  550. if (!event) event = new Event();
  551. this.state_changed = this.transition_Root(event);
  552. };
  553. // inState method for statechart
  554. Button.prototype.inState = function(nodes) {
  555. for (var c in this.current_state) {
  556. if (!this.current_state.hasOwnProperty(c)) continue;
  557. var new_nodes = new Array();
  558. for (var n in nodes) {
  559. if (!nodes.hasOwnProperty(n)) continue;
  560. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  561. new_nodes.push(nodes[n]);
  562. }
  563. }
  564. nodes = new_nodes;
  565. if (nodes.length === 0) {
  566. return true;
  567. }
  568. }
  569. return false;
  570. };
  571. Button.prototype.commonConstructor = function(controller) {
  572. if (!controller) controller = null;
  573. // Constructor part that is common for all constructors.
  574. RuntimeClassBase.call(this);
  575. // User defined input ports
  576. this.inports = new Object();
  577. this.inports["button_ui_input"] = controller.addInputPort("button_ui_input", this);
  578. this.controller = controller;
  579. this.object_manager = (controller == null ? null : controller.object_manager);
  580. this.current_state = new Object();
  581. this.history_state = new Object();
  582. // Initialize statechart
  583. this.current_state[this.Root] = new Array();
  584. };
  585. Button.prototype.start = function() {
  586. RuntimeClassBase.prototype.start.call(this);
  587. this.enter_Root_listening();
  588. };
  589. // put class in global diagram object
  590. DebuggingEnvironment.Button = Button;
  591. // The actual constructor
  592. var Visualizer = function(controller) {
  593. Visualizer.prototype.commonConstructor.call(this,controller);
  594. // constructor body (user-defined)
  595. this.visualized_simulator = "NETLOGO"
  596. the_controller = this.controller;
  597. this.simulation_info = d3.select("body").append("div")
  598. .attr("class", "simulationInfo")
  599. .style("margin", "5px")
  600. .style("display", "block");
  601. this.simulation_time = this.simulation_info.append("span")
  602. .append("text")
  603. .text("SIMULATION TIME: (not started)")
  604. .style("float", "left");
  605. this.simulation_steps = this.simulation_info.append("span")
  606. .style("margin", "5px")
  607. .style("float", "left")
  608. .attr("class", "invisibleInfo")
  609. .attr("id", "smallStepInfo");
  610. this.simulation_steps.selectAll("div").data([0,1,2,3,4,5,6,7])
  611. .enter()
  612. .append("div")
  613. .attr("id", function(d) {return "smallStepInfo_" + d})
  614. .attr("class", "smallStepInfo inactive")
  615. .style("transform", function(d) {return "translate(" + d * 5 + "px, -4px) rotate(45deg)"});
  616. d3.select("body").append("br");
  617. this.breakpoint_info = d3.select("body").append("div")
  618. .attr("class", "breakpointInfo")
  619. .style("margin", "5px")
  620. .style("display", "block");
  621. this.breakpoint_text = this.breakpoint_info.append("span")
  622. .append("text")
  623. .text("BREAKPOINTS: ")
  624. .style("float", "left");
  625. this.breakpoint_infos = this.breakpoint_info.append("span")
  626. .style("margin", "5px")
  627. .style("float", "left")
  628. .attr("id", "breakpointInfos");
  629. this.breakpoints = [];
  630. this.port_connections = [];
  631. this.loc_to_item = {};
  632. event_to_inject = undefined;
  633. god_event_to_process = undefined;
  634. // TODO: this is domain-specific!
  635. this.particle_id_to_item = {};
  636. var margin = {top: 50, right: 0, bottom: 0, left: 0},
  637. width = 960 - margin.right - margin.left,
  638. height = 1024 - margin.top - margin.bottom;
  639. this.node_id = 0;
  640. if (this.visualized_simulator == "NETLOGO") {
  641. this.data = [{'name': '<root>', 'children': [], 'loc': '', 'id': this.node_id}];
  642. this.node_id++;
  643. } else {
  644. this.data = [];
  645. }
  646. this.tree = d3.layout.tree()
  647. .size([width, height]);
  648. this.diagonal = d3.svg.diagonal();
  649. this.port_connection_diagonal = d3.svg.diagonal().projection(function(d) {return [d.x, d.y]});
  650. this.parent_svg = d3.select("body").append("svg")
  651. .attr("width", width + margin.right + margin.left)
  652. .attr("height", height + margin.top + margin.bottom);
  653. var defs = this.parent_svg.append('svg:defs')
  654. var markers = [{name: 'arrow', path: 'M2,2 L2,11 L10,6 L2,2', fill: "red"},
  655. {name: 'arrow_green', path: 'M2,2 L2,11 L10,6 L2,2', fill: "green"}];
  656. var marker = defs.selectAll('marker')
  657. .data(markers)
  658. .enter()
  659. .append('svg:marker')
  660. .attr('id', function(d){ return 'marker_' + d.name})
  661. .attr('markerHeight', 13)
  662. .attr('markerWidth', 13)
  663. .attr('markerUnits', 'strokeWidth')
  664. .attr('orient', 'auto')
  665. .attr('refX', 2)
  666. .attr('refY', 6)
  667. .append('svg:path')
  668. .attr('d', function(d){ return d.path })
  669. .attr('fill', function(d){ return d.fill });
  670. this.svg = this.parent_svg.append("g")
  671. .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  672. this_object = this;
  673. function godEvent() {
  674. if (this_object.visualized_simulator == "NETLOGO") {
  675. god_event_to_process = {'turtle': $('#currLoc').text(), 'attribute': $('#godEventName').val(), 'value': eval($('#godEventValue').val())};
  676. the_controller.addInput(new Event("process_god_event", "ui_input", [god_event_to_process]), 0.0);
  677. dialog.dialog("close");
  678. } else {
  679. god_event_to_process = {'model': $('#currLoc').text(), 'attribute': $('#godEventName').val(), 'value': eval($('#godEventValue').val())};
  680. the_controller.addInput(new Event("process_god_event", "ui_input", [god_event_to_process]), 0.0);
  681. dialog.dialog("close");
  682. }
  683. }
  684. dialog = $( "#godEventPopup" ).dialog({
  685. autoOpen: false,
  686. height: 200,
  687. width: 325,
  688. modal: true,
  689. buttons: {
  690. "Submit": godEvent,
  691. Cancel: function() {
  692. dialog.dialog( "close" );
  693. }
  694. },
  695. close: function() {
  696. form[ 0 ].reset();
  697. }
  698. }).css("font-size", "14px");;
  699. form = dialog.find( "form" ).on( "submit", function( event ) {
  700. event.preventDefault();
  701. godEvent();
  702. });
  703. function injectEvent() {
  704. event_to_inject = {'port': $('#currLoc').text(), 'event': eval($('#injectEvent').val()), 'time': eval($('#injectTime').val())};
  705. the_controller.addInput(new Event("inject_event", "ui_input", [event_to_inject]), 0.0);
  706. inject_dialog.dialog("close");
  707. }
  708. inject_dialog = $( "#injectEventPopup" ).dialog({
  709. autoOpen: false,
  710. height: 200,
  711. width: 325,
  712. modal: true,
  713. buttons: {
  714. "Submit": injectEvent,
  715. Cancel: function() {
  716. inject_dialog.dialog( "close" );
  717. }
  718. },
  719. close: function() {
  720. inject_form[ 0 ].reset();
  721. }
  722. }).css("font-size", "14px");
  723. inject_form = inject_dialog.find( "form" ).on( "submit", function( event ) {
  724. event.preventDefault();
  725. injectEvent();
  726. });
  727. if (this.visualized_simulator == "NETLOGO") {
  728. $('#breakpointFunction').text("def breakpoint(time, turtles):\n")
  729. }
  730. function addBreakpoint() {
  731. breakpoint_to_add = [$('#breakpointName').val(), $('#breakpointFunction').val(), $('#breakpointEnabled').is(":checked"), $('#breakpointDisableOnTrigger').is(":checked")];
  732. the_controller.addInput(new Event("add_breakpoint", "ui_input", [breakpoint_to_add]), 0.0);
  733. breakpoint_dialog.dialog("close");
  734. }
  735. breakpoint_dialog = $( "#breakpointPopup" ).dialog({
  736. autoOpen: false,
  737. height: 400,
  738. width: 600,
  739. modal: true,
  740. buttons: {
  741. "Submit": addBreakpoint,
  742. Cancel: function() {
  743. breakpoint_dialog.dialog( "close" );
  744. }
  745. },
  746. close: function() {
  747. breakpoint_form[ 0 ].reset();
  748. }
  749. }).css("font-size", "14px");
  750. breakpoint_form = breakpoint_dialog.find( "form" ).on( "submit", function( event ) {
  751. event.preventDefault();
  752. addBreakpoint();
  753. });
  754. };
  755. Visualizer.prototype = new RuntimeClassBase();
  756. // Unique IDs for all statechart nodes
  757. Visualizer.prototype.Root = 0;
  758. Visualizer.prototype.Root_initializing = 1;
  759. Visualizer.prototype.Root_running = 2;
  760. // User defined method
  761. Visualizer.prototype.update_vis = function(structural_changes) {
  762. if (this.visualized_simulator == "NETLOGO") {
  763. var created_turtles = [],
  764. deleted_turtles = [];
  765. if ('CREATED_TURTLES' in structural_changes) {
  766. created_turtles = structural_changes['CREATED_TURTLES'];
  767. }
  768. if ('DELETED_TURTLES' in structural_changes) {
  769. deleted_turtles = structural_changes['DELETED_TURTLES'];
  770. }
  771. var node_id = this.node_id;
  772. var loc_to_item = this.loc_to_item;
  773. var data = this.data;
  774. created_turtles.forEach(function(item) {
  775. var node = {'name': 'turtle[' + item + ']', 'children': [], 'id': node_id++, 'turtle_id': item}
  776. if (!data[0].hasOwnProperty('children')) {
  777. data[0]['children'] = [];
  778. }
  779. data[0].children.push(node);
  780. loc_to_item[item] = node;
  781. });
  782. deleted_turtles.forEach(function(item) {
  783. curr_array = data;
  784. data[0]['children'] = data[0]['children'].filter(function(el) {return el['name'] != ('turtle[' + item + ']')});
  785. });
  786. this.node_id = node_id;
  787. this.data = data;
  788. var nodes = this.tree.nodes(this.data[0]),
  789. links = this.tree.links(nodes);
  790. nodes.forEach(function(d, i) {
  791. d.y = d.depth * 100 + i * 40;
  792. });
  793. // Declare the nodes...
  794. var node = this.svg.selectAll("g.node")
  795. .data(nodes, function(d) { return d.id; });
  796. // Enter the nodes.
  797. var nodeEnter = node.enter().append("g")
  798. .attr("class", "node")
  799. .attr("id", function(d) {return 'instance_' + d.id;})
  800. .attr("transform", function(d) {
  801. return "translate(" + d.x + "," + d.y + ")";
  802. });
  803. nodeEnter.append("rect")
  804. .attr("width", 120)
  805. .attr("height", 25)
  806. .attr("transform", "translate(-60, 0)")
  807. .on("click", function(d) {
  808. console.log(JSON.stringify(d.state, null, 2));
  809. })
  810. .on("mouseover", function(d) {
  811. var node = d3.select("#instance_" + d.id)
  812. var stateInfo = node.selectAll(".stateInfo")
  813. .data(function(n) {if (n.state) {return [n.state]} else {return []}}, function(d) {return d.id});
  814. var stateInfoEnter = stateInfo.enter().append("text")
  815. .attr("transform", "translate(-60, 60)")
  816. .attr("id", this.node_id++)
  817. .attr("class", "stateInfo");
  818. var stateInfoText = stateInfo.selectAll("tspan")
  819. .data(function(d) {return JSON.stringify(d, null, 2).split("\n")});
  820. var stateInfoTextEnter = stateInfoText.enter().append("tspan")
  821. .attr("x", "0.0")
  822. .attr("dy", "1.4em")
  823. .attr("xml:space", "preserve")
  824. .text(function(d) {return d});
  825. })
  826. .on("mouseout", function(d) {
  827. var node = d3.select("#instance_" + d.id)
  828. var stateInfo = node.selectAll(".stateInfo");
  829. stateInfo.selectAll("tspan").data([]).exit().remove();
  830. })
  831. .on("contextmenu", function (d, i) {
  832. $( "#currLoc" ).html(d.turtle_id);
  833. d3.event.preventDefault();
  834. if (!d.children) {
  835. dialog.dialog( "open" );
  836. }
  837. });
  838. nodeEnter.append("text")
  839. .attr("y", 12)
  840. .attr("dy", ".35em")
  841. .attr("text-anchor", "middle")
  842. .text(function(d) { return d.name; })
  843. .style("fill-opacity", 1);
  844. // Declare the links...
  845. var link = this.svg.selectAll("path.link")
  846. .data(links);
  847. // Enter the links.
  848. link.enter().insert("path", "g")
  849. .attr("class", "link")
  850. .attr("d", this.diagonal);
  851. // Update the nodes.
  852. node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
  853. node.classed("coupled", function(d) {return d.name == '<root>'});
  854. // Transition links to their new position.
  855. link.attr("d", this.diagonal);
  856. // Remove nodes and links.
  857. node.exit().remove();
  858. link.exit().remove();
  859. } else {
  860. d3.select("#smallStepInfo_7").classed("inactive", false);
  861. var created_models = [],
  862. created_ports = [],
  863. connected_ports = [],
  864. deleted_models = [],
  865. deleted_ports = [],
  866. disconnected_ports = [];
  867. if ('CREATED_MODELS' in structural_changes) {
  868. created_models = structural_changes['CREATED_MODELS'];
  869. }
  870. if ('CREATED_PORTS' in structural_changes) {
  871. created_ports = structural_changes['CREATED_PORTS'];
  872. }
  873. if ('CONNECTED_PORTS' in structural_changes) {
  874. connected_ports = structural_changes['CONNECTED_PORTS'];
  875. }
  876. if ('DELETED_MODELS' in structural_changes) {
  877. deleted_models = structural_changes['DELETED_MODELS'];
  878. }
  879. if ('DELETED_PORTS' in structural_changes) {
  880. deleted_ports = structural_changes['DELETED_PORTS'];
  881. }
  882. if ('DISCONNECTED_PORTS' in structural_changes) {
  883. disconnected_ports = structural_changes['DISCONNECTED_PORTS'];
  884. }
  885. // sort according to their depth (amounts of dots in their name)
  886. created_models.sort(function(a, b) {
  887. return (a.match(/./g) || []).length - (b.match(/./g) || []).length
  888. })
  889. data = this.data;
  890. var node_id = this.node_id;
  891. var loc_to_item = this.loc_to_item;
  892. created_models.forEach(function(item) {
  893. splitted_path = item.split('.');
  894. element_to_insert = data;
  895. while (splitted_path.length > 1) {
  896. curr_name = splitted_path.shift();
  897. element_to_insert = element_to_insert.find(function(el) {return el['name'] == curr_name}).children;
  898. }
  899. var node = {'name': splitted_path[0], 'children': [], 'ports': [], 'loc': item, 'id': node_id++}
  900. element_to_insert.push(node);
  901. loc_to_item[item] = node;
  902. });
  903. created_ports.forEach(function(item) {
  904. splitted_path = item[0].split('.');
  905. curr_array = data;
  906. while (splitted_path.length > 2) {
  907. curr_name = splitted_path.shift();
  908. curr_array = curr_array.find(function(el) {return el['name'] == curr_name}).children;
  909. }
  910. ports = curr_array.find(function(el) {return el['name'] == splitted_path[0]})['ports'];
  911. var node = {'name': splitted_path[1], 'is_input': item[1], 'loc': item[0], 'id': node_id++};
  912. ports.push(node);
  913. loc_to_item[item[0]] = node;
  914. });
  915. this.node_id = node_id;
  916. port_connections = this.port_connections
  917. connected_ports.forEach(function(item) {
  918. splitted_path_src = item[0].split('.');
  919. curr_array = data;
  920. while (splitted_path_src.length > 2) {
  921. curr_name = splitted_path_src.shift();
  922. curr_array = curr_array.find(function(el) {return el['name'] == curr_name}).children;
  923. }
  924. src_parent = curr_array.find(function(el) {return el['name'] == splitted_path_src[0]});
  925. src = src_parent['ports'].find(function(el) {return el['name'] == splitted_path_src[1]});
  926. splitted_path_dst = item[1].split('.');
  927. curr_array = data;
  928. while (splitted_path_dst.length > 2) {
  929. curr_name = splitted_path_dst.shift();
  930. curr_array = curr_array.find(function(el) {return el['name'] == curr_name}).children;
  931. }
  932. dst_parent = curr_array.find(function(el) {return el['name'] == splitted_path_dst[0]});
  933. dst = dst_parent['ports'].find(function(el) {return el['name'] == splitted_path_dst[1]});
  934. port_connections.push({'source': src, 'target': dst});
  935. });
  936. disconnected_ports.forEach(function(item) {
  937. port_connections = port_connections.filter(function(el) {return el.source.loc != item[0] || el.target.loc != item[1];});
  938. });
  939. this.port_connections = port_connections
  940. deleted_ports.forEach(function(item) {
  941. splitted_path = item.split('.');
  942. curr_array = data;
  943. while (splitted_path.length > 2) {
  944. curr_name = splitted_path.shift();
  945. curr_array = curr_array.find(function(el) {return el['name'] == curr_name}).children;
  946. }
  947. parent = curr_array.find(function(el) {return el['name'] == splitted_path[0]});
  948. parent['ports'] = parent['ports'].filter(function(el) {return el['name'] != splitted_path[1]});
  949. });
  950. deleted_models.forEach(function(item) {
  951. splitted_path = item.split('.');
  952. curr_array = data;
  953. while (splitted_path.length > 2) {
  954. curr_name = splitted_path.shift();
  955. curr_array = element_to_insert.find(function(el) {return el['name'] == curr_name}).children;
  956. }
  957. parent = curr_array.find(function(el) {return el['name'] == splitted_path[0]});
  958. parent['children'] = parent['children'].filter(function(el) {return el['name'] != splitted_path[1]});
  959. });
  960. this.data = data;
  961. var nodes = this.tree.nodes(this.data[0]),
  962. links = this.tree.links(nodes);
  963. nodes.forEach(function(d, i) {
  964. d.y = d.depth * 100 + i * 40
  965. d.ports.forEach(function(p, i) {p.dx = 13, p.dy = 18; p.x = (d.x - 40) + i * p.dx; p.y = d.y + p.dy;});
  966. });
  967. // Declare the nodes...
  968. var node = this.svg.selectAll("g.node")
  969. .data(nodes, function(d) { return d.id; });
  970. // Enter the nodes.
  971. var nodeEnter = node.enter().append("g")
  972. .attr("class", "node")
  973. .attr("id", function(d) {return 'instance_' + d.id;})
  974. .attr("transform", function(d) {
  975. return "translate(" + d.x + "," + d.y + ")";
  976. });
  977. nodeEnter.append("rect")
  978. .attr("width", 120)
  979. .attr("height", 25)
  980. .attr("transform", "translate(-60, 0)")
  981. .on("click", function(d) {
  982. console.log(JSON.stringify(d.state, null, 2));
  983. })
  984. .on("mouseover", function(d) {
  985. var node = d3.select("#instance_" + d.id)
  986. var stateInfo = node.selectAll(".stateInfo")
  987. .data(function(n) {if (n.state) {return [n.state]} else {return []}}, function(d) {return d.id});
  988. var stateInfoEnter = stateInfo.enter().append("text")
  989. .attr("transform", "translate(-60, 60)")
  990. .attr("id", this.node_id++)
  991. .attr("class", "stateInfo");
  992. var stateInfoText = stateInfo.selectAll("tspan")
  993. .data(function(d) {return JSON.stringify(d, null, 2).split("\n")});
  994. var stateInfoTextEnter = stateInfoText.enter().append("tspan")
  995. .attr("x", "0.0")
  996. .attr("dy", "1.4em")
  997. .attr("xml:space", "preserve")
  998. .text(function(d) {return d});
  999. })
  1000. .on("mouseout", function(d) {
  1001. var node = d3.select("#instance_" + d.id)
  1002. var stateInfo = node.selectAll(".stateInfo");
  1003. stateInfo.selectAll("tspan").data([]).exit().remove();
  1004. })
  1005. .on("contextmenu", function (d, i) {
  1006. $( "#currLoc" ).html(d.loc);
  1007. d3.event.preventDefault();
  1008. if (!d.children) {
  1009. dialog.dialog( "open" );
  1010. }
  1011. });
  1012. nodeEnter.append("text")
  1013. .attr("y", 12)
  1014. .attr("dy", ".35em")
  1015. .attr("text-anchor", "middle")
  1016. .text(function(d) { return d.name; })
  1017. .style("fill-opacity", 1);
  1018. nodeEnter.append("text")
  1019. .attr("class", "timeNext")
  1020. .attr("y", -10)
  1021. .attr("x", 30)
  1022. .attr("dy", ".35em")
  1023. .attr("text-anchor", "middle")
  1024. .text("TN: --")
  1025. .style("fill-opacity", 1);
  1026. port = node.selectAll("g.port")
  1027. .data(function(n) {return n.ports}, function(d) { return d.id; })
  1028. portEnter = port.enter().append("g")
  1029. .attr("class", "port invisible")
  1030. .attr("id", function(d) {return 'port_' + d.id;})
  1031. .on("mouseover", function(d) {
  1032. d3.selectAll(".source_" + d.id).classed("invisibleLink", false)
  1033. .classed("input", false);
  1034. d3.selectAll(".target_" + d.id).classed("invisibleLink", false)
  1035. .classed("input", true);
  1036. port_connections.forEach(function(port_connection) {
  1037. if (port_connection.source.id == d.id) {
  1038. d3.select('#port_' + port_connection.target.id).attr("class", "port visible");
  1039. } else if (port_connection.target.id == d.id) {
  1040. d3.select('#port_' + port_connection.source.id).attr("class", "port visible");
  1041. }
  1042. });
  1043. d3.select(this).attr("class", "port visible");
  1044. })
  1045. .on("mouseout", function(d) {
  1046. d3.selectAll(".source_" + d.id).classed("invisibleLink", true);
  1047. d3.selectAll(".target_" + d.id).classed("invisibleLink", true);
  1048. d3.selectAll(".port").attr("class", "port invisible");
  1049. })
  1050. .on("click", function (d, i) {
  1051. $('#currLoc').html(d.loc);
  1052. d3.event.preventDefault();
  1053. if (d.is_input) {
  1054. inject_dialog.dialog( "open" );
  1055. }
  1056. });
  1057. portEnter.append("rect")
  1058. .attr("width", 10)
  1059. .attr("height", 10)
  1060. .style("fill", function(d) {return d.is_input ? "green" : "purple";})
  1061. .attr("transform", "rotate(45)");
  1062. portEnter.append("text")
  1063. .attr("dy", ".35em")
  1064. .attr("text-anchor", "left")
  1065. .text(function(d) {return d.name;})
  1066. .attr("transform", "translate(0, 20) rotate(30)");
  1067. port.attr("transform", function(d, i) {return "translate(" + (-40 + i * d.dx) + ", " + d.dy + ")"});
  1068. // Declare the links...
  1069. var link = this.svg.selectAll("path.link")
  1070. .data(links);
  1071. // Enter the links.
  1072. link.enter().insert("path", "g")
  1073. .attr("class", "link")
  1074. .attr("d", this.diagonal);
  1075. // Declare port connections...
  1076. var port_connection = this.svg.selectAll("path.portConnection")
  1077. .data(port_connections);
  1078. // Enter port connections.
  1079. port_connection.enter().insert("path", "g")
  1080. .attr("class", "invisibleLink portConnection");
  1081. // Update the nodes.
  1082. node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
  1083. node.classed("coupled", function(d) {return d.children});
  1084. // Transition links to their new position.
  1085. link.attr("d", this.diagonal);
  1086. // Transition links to their new position.
  1087. port_connection.attr("d", function(d) {
  1088. var dx = d.target.x - d.source.x,
  1089. dy = d.target.y - d.source.y,
  1090. dr = Math.sqrt(dx * dx + dy * dy)/4,
  1091. mx = d.source.x + dx/2,
  1092. my = d.source.y + dy/2 + 30;
  1093. return [
  1094. "M",d.source.x,d.source.y+5,
  1095. "T",mx,my,
  1096. "T",d.target.x,d.target.y+5
  1097. ].join(" ");
  1098. })
  1099. .attr("class", function(d) {return "invisibleLink portConnection source_" + d.source.id + " target_" + d.target.id});
  1100. // Remove nodes and links.
  1101. node.exit().remove();
  1102. link.exit().remove();
  1103. port.exit().remove();
  1104. port_connection.exit().remove();
  1105. }
  1106. };
  1107. // User defined method
  1108. Visualizer.prototype.visualize_initial_state = function(initial_states) {
  1109. if (this.visualized_simulator == "NETLOGO") {
  1110. for (var loc in initial_states) {
  1111. var item = this.loc_to_item[loc];
  1112. item.state = initial_states[loc];
  1113. }
  1114. } else {
  1115. d3.select("#smallStepInfo").classed("invisibleInfo", true);
  1116. d3.selectAll("g.node").attr("class", "node")
  1117. .classed("coupled", function(d) {return d.children});
  1118. d3.selectAll("circle.inmessage").data([]).exit().remove();
  1119. d3.selectAll("circle.outmessage").data([]).exit().remove();
  1120. d3.selectAll(".portConnection").classed("invisibleLink", true);
  1121. d3.selectAll(".port").classed("visible", false);
  1122. d3.selectAll(".port").classed("invisible", true);
  1123. d3.selectAll(".stateInfo").data([]).exit().remove();
  1124. for (var loc in initial_states) {
  1125. var item = this.loc_to_item[loc];
  1126. d3.select("#instance_" + item.id + " .timeNext").text("TN: " + initial_states[loc][0][0] + "/" + initial_states[loc][0][1])
  1127. item.state = initial_states[loc][1];
  1128. if (item.state.particle_id) {
  1129. this.particle_id_to_item[item.state.particle_id] = item; // TODO: this is somewhat ugly, we're making a lot of assumptions here and it's no longer domain-independent!
  1130. }
  1131. }
  1132. }
  1133. };
  1134. // User defined method
  1135. Visualizer.prototype.visualize_new_state = function(new_states, new_tn) {
  1136. d3.select("#smallStepInfo").classed("invisibleInfo", true);
  1137. d3.selectAll("g.node").attr("class", "node")
  1138. .classed("coupled", function(d) {return d.children});
  1139. d3.selectAll("circle.inmessage").data([]).exit().remove();
  1140. d3.selectAll("circle.outmessage").data([]).exit().remove();
  1141. d3.selectAll(".portConnection").classed("invisibleLink", true);
  1142. d3.selectAll(".port").classed("visible", false);
  1143. d3.selectAll(".port").classed("invisible", true);
  1144. d3.selectAll(".stateInfo").data([]).exit().remove();
  1145. for (var loc in new_tn) {
  1146. var item = this.loc_to_item[loc];
  1147. d3.select("#instance_" + item.id + " .timeNext").text("TN: " + new_tn[loc][0] + "/" + new_tn[loc][1])
  1148. item.state = new_states[loc];
  1149. if (item.state.particle_id != undefined) {
  1150. this.particle_id_to_item[item.state.particle_id] = item; // TODO: this is somewhat ugly, we're making a lot of assumptions here and it's no longer domain-independent!
  1151. }
  1152. }
  1153. };
  1154. // User defined method
  1155. Visualizer.prototype.visualize_imminents = function(imminents) {
  1156. d3.selectAll(".portConnection").classed("invisibleLink", true);
  1157. d3.selectAll(".port").classed("visible", false);
  1158. d3.selectAll(".port").classed("invisible", true);
  1159. d3.selectAll("circle.inmessage").data([]).exit().remove();
  1160. d3.selectAll("circle.outmessage").data([]).exit().remove();
  1161. if (this.transitioning_nodes) {
  1162. this.transitioning_nodes.forEach(function(n) {n.attr("class", "node")
  1163. .classed("coupled", function(d) {return d.children});});
  1164. }
  1165. d3.select("#smallStepInfo").classed("invisibleInfo", false);
  1166. d3.selectAll(".smallStepInfo").classed("inactive", true);
  1167. d3.select("#smallStepInfo_0").classed("inactive", false);
  1168. var loc_to_item = this.loc_to_item;
  1169. this.imminents = imminents;
  1170. imminents.forEach(function(imminent) {
  1171. d3.select("#instance_" + loc_to_item[imminent].id).classed("imminent", true);
  1172. })
  1173. };
  1174. // User defined method
  1175. Visualizer.prototype.visualize_selected_imminent = function(selected_imminent) {
  1176. d3.select("#smallStepInfo_1").classed("inactive", false);
  1177. var loc_to_item = this.loc_to_item;
  1178. this.imminents.forEach(function(imminent) {
  1179. if (!(imminent == selected_imminent)) {
  1180. d3.select("#instance_" + loc_to_item[imminent].id).classed("imminent", false);
  1181. }
  1182. })
  1183. };
  1184. // User defined method
  1185. Visualizer.prototype.visualize_messages = function(bag, msg_type) {
  1186. var total_msgs = [];
  1187. for (var key in bag) {
  1188. var msgs = bag[key];
  1189. var port = this.loc_to_item[key];
  1190. if (port != undefined) {
  1191. msgs[0].port = port;
  1192. Array.prototype.push.apply(total_msgs, msgs);
  1193. }
  1194. }
  1195. var msgs_vis = this.svg.selectAll("circle." + msg_type)
  1196. .data(total_msgs);
  1197. var msg_enter = msgs_vis.enter().append("circle")
  1198. .attr("class", msg_type)
  1199. .attr("id", function(m) {return "msg_" + m.port.id;})
  1200. .attr("r", 5)
  1201. .attr("transform", function(m) {return "translate(" + m.port.x + "," + (m.port.y + 22) + ")"})
  1202. .on("click", function(d) {console.log(d[0])});
  1203. };
  1204. // User defined method
  1205. Visualizer.prototype.visualize_inbags = function(inbags) {
  1206. d3.select("#smallStepInfo_3").classed("inactive", false);
  1207. function transition(circle, path, source_port_vis, target_port_vis) {
  1208. circle.transition()
  1209. .duration(3000)
  1210. .attrTween("transform", translateAlong(path.node()))
  1211. .each("end", function() {
  1212. path.classed("invisibleLink", true);
  1213. source_port_vis.classed("invisible", true);
  1214. target_port_vis.classed("invisible", true);
  1215. source_port_vis.classed("visible", false);
  1216. target_port_vis.classed("visible", false);
  1217. circle.attr("class", "inmessage");
  1218. });
  1219. }
  1220. // Returns an attrTween for translating along the specified path element.
  1221. function translateAlong(path) {
  1222. var l = path.getTotalLength();
  1223. return function(d, i, a) {
  1224. return function(t) {
  1225. var p = path.getPointAtLength(t * l);
  1226. return "translate(" + p.x + "," + (p.y + 17) + ")";
  1227. };
  1228. };
  1229. }
  1230. var outports_visited = []
  1231. for (var key in inbags) {
  1232. if (inbags[key].length == 2) {
  1233. var msgs = inbags[key][1];
  1234. var inport = this.loc_to_item[key];
  1235. if (inport != undefined) {
  1236. var circle = undefined;
  1237. var outport_id = this.loc_to_item[inbags[key][0]].id;
  1238. if (outports_visited.indexOf(outport_id) > -1) {
  1239. circle = d3.select('#msg_' + outport_id);
  1240. var parent = d3.select(circle.node().parentNode);
  1241. circle = parent.append("circle")
  1242. .attr("class", "outmessage")
  1243. .attr("id", circle.id + outports_visited.indexOf(outport_id))
  1244. .attr("r", 5)
  1245. .attr("transform", circle.transform)
  1246. .on("click", (function(msgs) {return function(d) {console.log(msgs[0])}})(msgs));
  1247. } else {
  1248. circle = d3.select('#msg_' + outport_id);
  1249. circle.on("click", (function(msgs) {return function(d) {console.log(msgs[0])}})(msgs));
  1250. }
  1251. var path = d3.select(".source_" + outport_id + ".target_" + inport.id);
  1252. var source_port_vis = d3.select("#port_" + outport_id)
  1253. var target_port_vis = d3.select("#port_" + inport.id)
  1254. source_port_vis.classed("invisible", false);
  1255. target_port_vis.classed("invisible", false);
  1256. source_port_vis.classed("visible", true);
  1257. target_port_vis.classed("visible", true);
  1258. path.classed("invisibleLink", false);
  1259. transition(circle, path, source_port_vis, target_port_vis);
  1260. outports_visited.push(outport_id);
  1261. }
  1262. } else {
  1263. var msgs = inbags[key][0];
  1264. var inport = this.loc_to_item[key];
  1265. this.svg.append("circle")
  1266. .attr("class", "inmessage")
  1267. .attr("id", "msg_" + inport.id)
  1268. .attr("r", 5)
  1269. .attr("transform", "translate(" + inport.x + "," + (inport.y + 22) + ")")
  1270. .on("click", (function(msgs) {return function(d) {console.log(msgs[0])}})(msgs));
  1271. }
  1272. }
  1273. };
  1274. // User defined method
  1275. Visualizer.prototype.visualize_transitioning = function(transitioning) {
  1276. var transitioning_nodes = [];
  1277. var loc_to_item = this.loc_to_item;
  1278. Object.keys(transitioning).forEach(function(key) {
  1279. transitioning_nodes.push(d3.select("#instance_" + loc_to_item[key].id).classed(transitioning[key], true));
  1280. });
  1281. this.transitioning_nodes = transitioning_nodes;
  1282. };
  1283. // User defined method
  1284. Visualizer.prototype.handle_internal_state_change = function(new_internal_states) {
  1285. d3.select("#smallStepInfo_5").classed("inactive", false);
  1286. for (var loc in new_internal_states) {
  1287. var item = this.loc_to_item[loc];
  1288. item.state = new_internal_states[loc];
  1289. }
  1290. if (this.transitioning_nodes) {
  1291. this.transitioning_nodes.forEach(function(n) {n.attr("class", "node")
  1292. .classed("coupled", function(d) {return d.children});});
  1293. }
  1294. var node = this.svg.selectAll("g.node");
  1295. var stateInfo = node.selectAll("g.state");
  1296. stateInfo.text(function(d) {return JSON.stringify(d);});
  1297. };
  1298. // User defined method
  1299. Visualizer.prototype.visualize_new_tn = function(new_tn) {
  1300. d3.select("#smallStepInfo_6").classed("inactive", false);
  1301. for (var loc in new_tn) {
  1302. var item = this.loc_to_item[loc];
  1303. d3.select("#instance_" + item.id + " .timeNext").text("TN: " + new_tn[loc][0] + "/" + new_tn[loc][1])
  1304. }
  1305. };
  1306. // User defined method
  1307. Visualizer.prototype.select_instance = function(instance_id) {
  1308. d3.selectAll(".stateInfo").data([]).exit().remove();
  1309. if (instance_id in this.particle_id_to_item) {
  1310. var d = this.particle_id_to_item[instance_id];
  1311. var node = d3.select("#instance_" + d.id)
  1312. var stateInfo = node.selectAll(".stateInfo")
  1313. .data(function(n) {if (n.state) {return [n.state]} else {return []}}, function(d) {return d.id});
  1314. var stateInfoEnter = stateInfo.enter().append("text")
  1315. .attr("transform", "translate(-60, 60)")
  1316. .attr("id", this.node_id++)
  1317. .attr("class", "stateInfo");
  1318. var stateInfoText = stateInfo.selectAll("tspan")
  1319. .data(function(d) {return JSON.stringify(d, null, 2).split("\n")});
  1320. var stateInfoTextEnter = stateInfoText.enter().append("tspan")
  1321. .attr("x", "0.0")
  1322. .attr("dy", "1.4em")
  1323. .attr("xml:space", "preserve")
  1324. .text(function(d) {return d});
  1325. }
  1326. };
  1327. // User defined method
  1328. Visualizer.prototype.visualize_breakpoints = function() {
  1329. if (this.visualized_simulator == "PYDEVS") {
  1330. for (idx in this.breakpoints) {
  1331. var curr_bp = this.breakpoints[idx];
  1332. if (curr_bp.triggered) {
  1333. this.visualize_messages(curr_bp.outbag, 'outmessage');
  1334. for (var key in curr_bp.inbags) {
  1335. if (curr_bp.inbags[key].length == 2) {
  1336. curr_bp.inbags[key] = [curr_bp.inbags[key][1]];
  1337. }
  1338. }
  1339. this.visualize_messages(curr_bp.inbags, 'inmessage');
  1340. this.visualize_transitioning(curr_bp.transitioned);
  1341. }
  1342. }
  1343. }
  1344. var curr_bps = this.breakpoint_infos.selectAll("div").data(this.breakpoints)
  1345. curr_bps_enter = curr_bps.enter().append("div")
  1346. .attr("id", function(d) {return "breakpoint_" + d.name})
  1347. .attr("class", "breakpoint")
  1348. .style("transform", function(d, i) {return "translate(" + i * 5 + "px, -8px)"})
  1349. .style("float", "left");
  1350. curr_bps_enter.append("text")
  1351. .text(function(d) {return d.name})
  1352. .on("click", function(d) {
  1353. d.enabled = !d.enabled;
  1354. the_controller.addInput(new Event("toggle_breakpoint", "ui_input", [d.name, d.enabled]), 0.0);
  1355. })
  1356. .on('mouseover', function() {
  1357. d3.event.preventDefault();
  1358. });
  1359. curr_bps_enter.append("img")
  1360. .attr('src', 'img/delete-bp.png')
  1361. .style('transform', 'translate(1px, 2px)')
  1362. .on("click", function(d) {
  1363. the_controller.addInput(new Event("del_breakpoint", "ui_input", [d.name]), 0.0);
  1364. });
  1365. curr_bps.exit().remove();
  1366. curr_bps.style("background-color", function(d) {
  1367. if (d.triggered) {
  1368. d.triggered = false;
  1369. if (d.disable_on_trigger) {
  1370. d.enabled = false;
  1371. }
  1372. return "red";
  1373. } else {
  1374. return "transparent";
  1375. }});
  1376. curr_bps.select("text").style("opacity", function(d) {if (d.enabled) return "1"; else return "0.5";});
  1377. };
  1378. // Statechart enter/exit action method(s) :
  1379. Visualizer.prototype.enter_Root_initializing = function() {
  1380. this.current_state[this.Root].push(this.Root_initializing);
  1381. };
  1382. Visualizer.prototype.exit_Root_initializing = function() {
  1383. this.current_state[this.Root] = new Array();
  1384. };
  1385. Visualizer.prototype.enter_Root_running = function() {
  1386. this.current_state[this.Root].push(this.Root_running);
  1387. };
  1388. Visualizer.prototype.exit_Root_running = function() {
  1389. this.current_state[this.Root] = new Array();
  1390. };
  1391. // Statechart transitions :
  1392. Visualizer.prototype.transition_Root = function(event) {
  1393. var catched = false;
  1394. if (!catched) {
  1395. if (this.current_state[this.Root][0] === this.Root_initializing) {
  1396. catched = this.transition_Root_initializing(event);
  1397. }
  1398. else if (this.current_state[this.Root][0] === this.Root_running) {
  1399. catched = this.transition_Root_running(event);
  1400. }
  1401. }
  1402. return catched;
  1403. };
  1404. Visualizer.prototype.transition_Root_initializing = function(event) {
  1405. var catched = false;
  1406. var enableds = new Array();
  1407. enableds.push(1);
  1408. if (enableds.length > 1) {
  1409. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing. Only the first in document order enabled transition is executed.")
  1410. }
  1411. if (enableds.length > 0) {
  1412. var enabled = enableds[0];
  1413. if (enabled === 1) {
  1414. this.exit_Root_initializing();
  1415. this.controller.outputEvent(new Event("reset", "output", []));
  1416. this.enter_Root_running();
  1417. }
  1418. catched = true;
  1419. }
  1420. return catched;
  1421. };
  1422. Visualizer.prototype.transition_Root_running = function(event) {
  1423. var catched = false;
  1424. var enableds = new Array();
  1425. if (event.name === "all_states_reset" && event.port === "simulation_input") {
  1426. enableds.push(1);
  1427. }
  1428. if (event.name === "all_states" && event.port === "simulation_input") {
  1429. enableds.push(2);
  1430. }
  1431. if (event.name === "new_states" && event.port === "simulation_input") {
  1432. enableds.push(3);
  1433. }
  1434. if (event.name === "imminents" && event.port === "simulation_input") {
  1435. enableds.push(4);
  1436. }
  1437. if (event.name === "selected_imminent" && event.port === "simulation_input") {
  1438. enableds.push(5);
  1439. }
  1440. if (event.name === "outbag" && event.port === "simulation_input") {
  1441. enableds.push(6);
  1442. }
  1443. if (event.name === "inbags" && event.port === "simulation_input") {
  1444. enableds.push(7);
  1445. }
  1446. if (event.name === "transitioning" && event.port === "simulation_input") {
  1447. enableds.push(8);
  1448. }
  1449. if (event.name === "new_internal_states" && event.port === "simulation_input") {
  1450. enableds.push(9);
  1451. }
  1452. if (event.name === "new_tn" && event.port === "simulation_input") {
  1453. enableds.push(10);
  1454. }
  1455. if (event.name === "structural_changes" && event.port === "simulation_input") {
  1456. enableds.push(11);
  1457. }
  1458. if (event.name === "select_instance" && event.port === "ui_input") {
  1459. enableds.push(12);
  1460. }
  1461. if (event.name === "process_god_event" && event.port === "ui_input") {
  1462. enableds.push(13);
  1463. }
  1464. if (event.name === "god_event_ok" && event.port === "simulation_input") {
  1465. enableds.push(14);
  1466. }
  1467. if (event.name === "inject_event" && event.port === "ui_input") {
  1468. enableds.push(15);
  1469. }
  1470. if (event.name === "inject_ok" && event.port === "simulation_input") {
  1471. enableds.push(16);
  1472. }
  1473. if (event.name === "add_breakpoint" && event.port === "ui_input") {
  1474. enableds.push(17);
  1475. }
  1476. if (event.name === "toggle_breakpoint" && event.port === "ui_input") {
  1477. enableds.push(18);
  1478. }
  1479. if (event.name === "del_breakpoint" && event.port === "ui_input") {
  1480. enableds.push(19);
  1481. }
  1482. if (event.name === "breakpoint_triggered" && event.port === "simulation_input") {
  1483. enableds.push(20);
  1484. }
  1485. if (enableds.length > 1) {
  1486. console.log("Runtime warning : indeterminism detected in a transition from node Root_running. Only the first in document order enabled transition is executed.")
  1487. }
  1488. if (enableds.length > 0) {
  1489. var enabled = enableds[0];
  1490. if (enabled === 1) {
  1491. var parameters = event.parameters;
  1492. var the_parameters = parameters[0];
  1493. this.exit_Root_running();
  1494. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1495. this.data = [];
  1496. this.port_connections = [];
  1497. this.update_vis(the_parameters[2]);
  1498. this.visualize_initial_state(the_parameters[1]);
  1499. this.breakpoints = the_parameters[3];
  1500. this.visualize_breakpoints();
  1501. this.enter_Root_running();
  1502. }
  1503. else if (enabled === 2) {
  1504. var parameters = event.parameters;
  1505. var the_parameters = parameters[0];
  1506. this.exit_Root_running();
  1507. if (this.visualized_simulator == "NETLOGO") {
  1508. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0]);
  1509. this.update_vis(the_parameters[2]);
  1510. this.visualize_initial_state(the_parameters[1]);
  1511. this.visualize_breakpoints();
  1512. } else {
  1513. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1514. this.update_vis(the_parameters[2]);
  1515. this.visualize_initial_state(the_parameters[1]);
  1516. this.visualize_breakpoints();
  1517. }
  1518. this.enter_Root_running();
  1519. }
  1520. else if (enabled === 3) {
  1521. var parameters = event.parameters;
  1522. var the_parameters = parameters[0];
  1523. this.exit_Root_running();
  1524. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1525. this.update_vis(the_parameters[3]);
  1526. this.visualize_new_state(the_parameters[1], the_parameters[2]);
  1527. this.visualize_breakpoints();
  1528. this.enter_Root_running();
  1529. }
  1530. else if (enabled === 4) {
  1531. var parameters = event.parameters;
  1532. var the_parameters = parameters[0];
  1533. this.exit_Root_running();
  1534. this.visualize_breakpoints();
  1535. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1536. this.visualize_imminents(the_parameters[1]);
  1537. this.enter_Root_running();
  1538. }
  1539. else if (enabled === 5) {
  1540. var parameters = event.parameters;
  1541. var the_parameters = parameters[0];
  1542. this.exit_Root_running();
  1543. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1544. this.visualize_selected_imminent(the_parameters[1]);
  1545. this.enter_Root_running();
  1546. }
  1547. else if (enabled === 6) {
  1548. var parameters = event.parameters;
  1549. var the_parameters = parameters[0];
  1550. this.exit_Root_running();
  1551. d3.select("#smallStepInfo_2").classed("inactive", false);
  1552. d3.selectAll("g.node").classed("imminent", false);
  1553. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1554. this.visualize_messages(the_parameters[1], 'outmessage');
  1555. this.enter_Root_running();
  1556. }
  1557. else if (enabled === 7) {
  1558. var parameters = event.parameters;
  1559. var the_parameters = parameters[0];
  1560. this.exit_Root_running();
  1561. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1562. this.visualize_inbags(the_parameters[1]);
  1563. this.enter_Root_running();
  1564. }
  1565. else if (enabled === 8) {
  1566. var parameters = event.parameters;
  1567. var the_parameters = parameters[0];
  1568. this.exit_Root_running();
  1569. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1570. d3.select("#smallStepInfo_4").classed("inactive", false);
  1571. d3.selectAll(".portConnection").classed("invisibleLink", true);
  1572. d3.selectAll(".port").classed("visible", false);
  1573. d3.selectAll(".port").classed("invisible", true);
  1574. d3.selectAll("circle.inmessage").data([]).exit().remove();
  1575. d3.selectAll("circle.outmessage").data([]).exit().remove();
  1576. this.visualize_transitioning(the_parameters[1]);
  1577. this.enter_Root_running();
  1578. }
  1579. else if (enabled === 9) {
  1580. var parameters = event.parameters;
  1581. var the_parameters = parameters[0];
  1582. this.exit_Root_running();
  1583. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1584. this.handle_internal_state_change(the_parameters[1]);
  1585. this.enter_Root_running();
  1586. }
  1587. else if (enabled === 10) {
  1588. var parameters = event.parameters;
  1589. var the_parameters = parameters[0];
  1590. this.exit_Root_running();
  1591. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1592. this.visualize_new_tn(the_parameters[1]);
  1593. this.enter_Root_running();
  1594. }
  1595. else if (enabled === 11) {
  1596. var parameters = event.parameters;
  1597. var the_parameters = parameters[0];
  1598. this.exit_Root_running();
  1599. this.simulation_time.text("SIMULATION TIME: " + the_parameters[0][0] + "/" + the_parameters[0][1]);
  1600. this.update_vis(the_parameters[1]);
  1601. this.enter_Root_running();
  1602. }
  1603. else if (enabled === 12) {
  1604. var parameters = event.parameters;
  1605. var the_parameters = parameters[0];
  1606. this.exit_Root_running();
  1607. this.select_instance(the_parameters);
  1608. this.enter_Root_running();
  1609. }
  1610. else if (enabled === 13) {
  1611. this.exit_Root_running();
  1612. this.controller.outputEvent(new Event("god_event", "output", [god_event_to_process]));
  1613. this.enter_Root_running();
  1614. }
  1615. else if (enabled === 14) {
  1616. var parameters = event.parameters;
  1617. var the_parameters = parameters[0];
  1618. this.exit_Root_running();
  1619. this.handle_internal_state_change(the_parameters[0]);
  1620. this.enter_Root_running();
  1621. }
  1622. else if (enabled === 15) {
  1623. this.exit_Root_running();
  1624. this.controller.outputEvent(new Event("inject", "output", [event_to_inject]));
  1625. this.enter_Root_running();
  1626. }
  1627. else if (enabled === 16) {
  1628. this.exit_Root_running();
  1629. this.enter_Root_running();
  1630. }
  1631. else if (enabled === 17) {
  1632. this.exit_Root_running();
  1633. this.controller.outputEvent(new Event("add_breakpoint", "output", [breakpoint_to_add]));
  1634. this.breakpoints.push({'name': breakpoint_to_add[0], 'enabled': breakpoint_to_add[2], 'disable_on_trigger': breakpoint_to_add[3], 'triggered': false});
  1635. this.visualize_breakpoints();
  1636. this.enter_Root_running();
  1637. }
  1638. else if (enabled === 18) {
  1639. var parameters = event.parameters;
  1640. var breakpoint_id = parameters[0];
  1641. var enabled = parameters[1];
  1642. this.exit_Root_running();
  1643. this.controller.outputEvent(new Event("toggle_breakpoint", "output", [breakpoint_id,enabled]));
  1644. this.visualize_breakpoints();
  1645. this.enter_Root_running();
  1646. }
  1647. else if (enabled === 19) {
  1648. var parameters = event.parameters;
  1649. var breakpoint_id = parameters[0];
  1650. this.exit_Root_running();
  1651. this.controller.outputEvent(new Event("del_breakpoint", "output", [breakpoint_id]));
  1652. this.breakpoints = this.breakpoints.filter(function(bp) {return bp.name != breakpoint_id});
  1653. this.visualize_breakpoints();
  1654. this.enter_Root_running();
  1655. }
  1656. else if (enabled === 20) {
  1657. var parameters = event.parameters;
  1658. var the_parameters = parameters[0];
  1659. this.exit_Root_running();
  1660. for (var idx in this.breakpoints) {
  1661. var curr_bp = this.breakpoints[idx];
  1662. if (curr_bp.name == the_parameters[0]) {
  1663. curr_bp.triggered = true;
  1664. curr_bp.transitioned = the_parameters[1];
  1665. curr_bp.outbag = the_parameters[2];
  1666. curr_bp.inbags = the_parameters[3];
  1667. }
  1668. }
  1669. this.visualize_breakpoints()
  1670. this.enter_Root_running();
  1671. }
  1672. catched = true;
  1673. }
  1674. return catched;
  1675. };
  1676. // Execute transitions
  1677. Visualizer.prototype.transition = function(event) {
  1678. if (!event) event = new Event();
  1679. this.state_changed = this.transition_Root(event);
  1680. };
  1681. // inState method for statechart
  1682. Visualizer.prototype.inState = function(nodes) {
  1683. for (var c in this.current_state) {
  1684. if (!this.current_state.hasOwnProperty(c)) continue;
  1685. var new_nodes = new Array();
  1686. for (var n in nodes) {
  1687. if (!nodes.hasOwnProperty(n)) continue;
  1688. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  1689. new_nodes.push(nodes[n]);
  1690. }
  1691. }
  1692. nodes = new_nodes;
  1693. if (nodes.length === 0) {
  1694. return true;
  1695. }
  1696. }
  1697. return false;
  1698. };
  1699. Visualizer.prototype.commonConstructor = function(controller) {
  1700. if (!controller) controller = null;
  1701. // Constructor part that is common for all constructors.
  1702. RuntimeClassBase.call(this);
  1703. // User defined input ports
  1704. this.inports = new Object();
  1705. this.controller = controller;
  1706. this.object_manager = (controller == null ? null : controller.object_manager);
  1707. this.current_state = new Object();
  1708. this.history_state = new Object();
  1709. // Initialize statechart
  1710. this.current_state[this.Root] = new Array();
  1711. };
  1712. Visualizer.prototype.start = function() {
  1713. RuntimeClassBase.prototype.start.call(this);
  1714. this.enter_Root_initializing();
  1715. };
  1716. // put class in global diagram object
  1717. DebuggingEnvironment.Visualizer = Visualizer;
  1718. var ObjectManager = function(controller) {
  1719. ObjectManagerBase.call(this, controller);
  1720. };
  1721. ObjectManager.prototype = new ObjectManagerBase();
  1722. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  1723. if (class_name === "MainApp") {
  1724. var instance = new MainApp(this.controller);
  1725. instance.associations = new Object();
  1726. instance.associations["toolbar"] = new Association("DebuggingToolbar", 1, 1);
  1727. instance.associations["visualizer"] = new Association("Visualizer", 1, 1);
  1728. } else if (class_name === "DebuggingToolbar") {
  1729. var instance = new DebuggingToolbar(this.controller);
  1730. instance.associations = new Object();
  1731. instance.associations["parent"] = new Association("MainApp", 1, 1);
  1732. instance.associations["buttons"] = new Association("Button", 0, -1);
  1733. } else if (class_name === "Button") {
  1734. var instance = new Button(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  1735. instance.associations = new Object();
  1736. instance.associations["parent"] = new Association("DebuggingToolbar", 1, 1);
  1737. } else if (class_name === "Visualizer") {
  1738. var instance = new Visualizer(this.controller);
  1739. instance.associations = new Object();
  1740. instance.associations["parent"] = new Association("MainApp", 1, 1);
  1741. }
  1742. return instance;
  1743. };
  1744. // put in global diagram object
  1745. DebuggingEnvironment.ObjectManager = ObjectManager;
  1746. var Controller = function(keep_running, finished_callback) {
  1747. if (keep_running === undefined) keep_running = true;
  1748. JsEventLoopControllerBase.call(this, new ObjectManager(this), keep_running, finished_callback);
  1749. this.addInputPort("ui_input");
  1750. this.addInputPort("simulation_input");
  1751. this.addOutputPort("output");
  1752. this.object_manager.createInstance("MainApp", []);
  1753. };
  1754. Controller.prototype = new JsEventLoopControllerBase();
  1755. // put in global diagram object
  1756. DebuggingEnvironment.Controller = Controller;
  1757. })();