particle_interaction_vis_js.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /**
  2. * Statechart compiler by Glenn De Jonghe
  3. * Javascript generator by Joeri Exelmans
  4. *
  5. * Date: Tue Mar 01 17:22:48 2016
  6. *
  7. * Model author: Simon Van Mierlo
  8. * Model name: ParticleInteraction
  9. * Model description:
  10. Visualization of Particle Interaction Simulation
  11. */
  12. // put everything in an object (serves as "namespace")
  13. ParticleInteraction = {};
  14. // closure scope
  15. (function() {
  16. // The actual constructor
  17. var MainApp = function(controller, resolution) {
  18. MainApp.prototype.commonConstructor.call(this,controller);
  19. // constructor body (user-defined)
  20. this.nr_of_fields = 0
  21. this.resolution = resolution
  22. ui.bind_event(ui.window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close');
  23. };
  24. MainApp.prototype = new RuntimeClassBase();
  25. // Unique IDs for all statechart nodes
  26. MainApp.prototype.Root = 0;
  27. MainApp.prototype.Root_main = 1;
  28. MainApp.prototype.Root_main_main_behaviour = 2;
  29. MainApp.prototype.Root_main_creating_behaviour = 3;
  30. MainApp.prototype.Root_main_deleting_behaviour = 4;
  31. MainApp.prototype.Root_main_main_behaviour_initializing = 5;
  32. MainApp.prototype.Root_main_main_behaviour_running = 6;
  33. MainApp.prototype.Root_main_creating_behaviour_waiting = 7;
  34. MainApp.prototype.Root_main_creating_behaviour_creating = 8;
  35. MainApp.prototype.Root_main_deleting_behaviour_waiting = 9;
  36. MainApp.prototype.Root_main_deleting_behaviour_deleting = 10;
  37. MainApp.prototype.Root_stopped = 11;
  38. // Statechart enter/exit action method(s) :
  39. MainApp.prototype.enter_Root_main = function() {
  40. this.current_state[this.Root].push(this.Root_main);
  41. };
  42. MainApp.prototype.exit_Root_main = function() {
  43. this.exit_Root_main_main_behaviour();
  44. this.exit_Root_main_creating_behaviour();
  45. this.exit_Root_main_deleting_behaviour();
  46. this.current_state[this.Root] = new Array();
  47. };
  48. MainApp.prototype.enter_Root_main_main_behaviour = function() {
  49. this.current_state[this.Root_main].push(this.Root_main_main_behaviour);
  50. };
  51. MainApp.prototype.exit_Root_main_main_behaviour = function() {
  52. if (this.current_state[this.Root_main_main_behaviour].indexOf(this.Root_main_main_behaviour_initializing) !== -1) {
  53. this.exit_Root_main_main_behaviour_initializing();
  54. }
  55. if (this.current_state[this.Root_main_main_behaviour].indexOf(this.Root_main_main_behaviour_running) !== -1) {
  56. this.exit_Root_main_main_behaviour_running();
  57. }
  58. this.current_state[this.Root_main] = new Array();
  59. };
  60. MainApp.prototype.enter_Root_main_creating_behaviour = function() {
  61. this.current_state[this.Root_main].push(this.Root_main_creating_behaviour);
  62. };
  63. MainApp.prototype.exit_Root_main_creating_behaviour = function() {
  64. if (this.current_state[this.Root_main_creating_behaviour].indexOf(this.Root_main_creating_behaviour_waiting) !== -1) {
  65. this.exit_Root_main_creating_behaviour_waiting();
  66. }
  67. if (this.current_state[this.Root_main_creating_behaviour].indexOf(this.Root_main_creating_behaviour_creating) !== -1) {
  68. this.exit_Root_main_creating_behaviour_creating();
  69. }
  70. this.current_state[this.Root_main] = new Array();
  71. };
  72. MainApp.prototype.enter_Root_main_deleting_behaviour = function() {
  73. this.current_state[this.Root_main].push(this.Root_main_deleting_behaviour);
  74. };
  75. MainApp.prototype.exit_Root_main_deleting_behaviour = function() {
  76. if (this.current_state[this.Root_main_deleting_behaviour].indexOf(this.Root_main_deleting_behaviour_waiting) !== -1) {
  77. this.exit_Root_main_deleting_behaviour_waiting();
  78. }
  79. if (this.current_state[this.Root_main_deleting_behaviour].indexOf(this.Root_main_deleting_behaviour_deleting) !== -1) {
  80. this.exit_Root_main_deleting_behaviour_deleting();
  81. }
  82. this.current_state[this.Root_main] = new Array();
  83. };
  84. MainApp.prototype.enter_Root_main_main_behaviour_initializing = function() {
  85. this.addEvent(new Event("create_field", null, []));
  86. this.current_state[this.Root_main_main_behaviour].push(this.Root_main_main_behaviour_initializing);
  87. };
  88. MainApp.prototype.exit_Root_main_main_behaviour_initializing = function() {
  89. this.current_state[this.Root_main_main_behaviour] = new Array();
  90. };
  91. MainApp.prototype.enter_Root_main_main_behaviour_running = function() {
  92. this.current_state[this.Root_main_main_behaviour].push(this.Root_main_main_behaviour_running);
  93. };
  94. MainApp.prototype.exit_Root_main_main_behaviour_running = function() {
  95. this.current_state[this.Root_main_main_behaviour] = new Array();
  96. };
  97. MainApp.prototype.enter_Root_main_creating_behaviour_waiting = function() {
  98. this.current_state[this.Root_main_creating_behaviour].push(this.Root_main_creating_behaviour_waiting);
  99. };
  100. MainApp.prototype.exit_Root_main_creating_behaviour_waiting = function() {
  101. this.current_state[this.Root_main_creating_behaviour] = new Array();
  102. };
  103. MainApp.prototype.enter_Root_main_creating_behaviour_creating = function() {
  104. this.current_state[this.Root_main_creating_behaviour].push(this.Root_main_creating_behaviour_creating);
  105. };
  106. MainApp.prototype.exit_Root_main_creating_behaviour_creating = function() {
  107. this.current_state[this.Root_main_creating_behaviour] = new Array();
  108. };
  109. MainApp.prototype.enter_Root_main_deleting_behaviour_waiting = function() {
  110. this.current_state[this.Root_main_deleting_behaviour].push(this.Root_main_deleting_behaviour_waiting);
  111. };
  112. MainApp.prototype.exit_Root_main_deleting_behaviour_waiting = function() {
  113. this.current_state[this.Root_main_deleting_behaviour] = new Array();
  114. };
  115. MainApp.prototype.enter_Root_main_deleting_behaviour_deleting = function() {
  116. this.current_state[this.Root_main_deleting_behaviour].push(this.Root_main_deleting_behaviour_deleting);
  117. };
  118. MainApp.prototype.exit_Root_main_deleting_behaviour_deleting = function() {
  119. this.current_state[this.Root_main_deleting_behaviour] = new Array();
  120. };
  121. MainApp.prototype.enter_Root_stopped = function() {
  122. ui.close_window(ui.window);
  123. this.current_state[this.Root].push(this.Root_stopped);
  124. };
  125. MainApp.prototype.exit_Root_stopped = function() {
  126. this.current_state[this.Root] = new Array();
  127. };
  128. // Statechart enter/exit default method(s) :
  129. MainApp.prototype.enterDefault_Root_main = function() {
  130. this.enter_Root_main();
  131. this.enterDefault_Root_main_main_behaviour();
  132. this.enterDefault_Root_main_creating_behaviour();
  133. this.enterDefault_Root_main_deleting_behaviour();
  134. };
  135. MainApp.prototype.enterDefault_Root_main_main_behaviour = function() {
  136. this.enter_Root_main_main_behaviour();
  137. this.enter_Root_main_main_behaviour_initializing();
  138. };
  139. MainApp.prototype.enterDefault_Root_main_creating_behaviour = function() {
  140. this.enter_Root_main_creating_behaviour();
  141. this.enter_Root_main_creating_behaviour_waiting();
  142. };
  143. MainApp.prototype.enterDefault_Root_main_deleting_behaviour = function() {
  144. this.enter_Root_main_deleting_behaviour();
  145. this.enter_Root_main_deleting_behaviour_waiting();
  146. };
  147. // Statechart transitions :
  148. MainApp.prototype.transition_Root = function(event) {
  149. var catched = false;
  150. if (!catched) {
  151. if (this.current_state[this.Root][0] === this.Root_main) {
  152. catched = this.transition_Root_main(event);
  153. }
  154. else if (this.current_state[this.Root][0] === this.Root_stopped) {
  155. catched = this.transition_Root_stopped(event);
  156. }
  157. }
  158. return catched;
  159. };
  160. MainApp.prototype.transition_Root_main = function(event) {
  161. var catched = false;
  162. var enableds = new Array();
  163. if (event.name === "stop") {
  164. enableds.push(1);
  165. }
  166. if (enableds.length > 1) {
  167. console.log("Runtime warning : indeterminism detected in a transition from node Root_main. Only the first in document order enabled transition is executed.")
  168. }
  169. if (enableds.length > 0) {
  170. var enabled = enableds[0];
  171. if (enabled === 1) {
  172. this.exit_Root_main();
  173. this.enter_Root_stopped();
  174. }
  175. catched = true;
  176. }
  177. if (!catched) {
  178. catched = this.transition_Root_main_main_behaviour(event) || catched
  179. catched = this.transition_Root_main_creating_behaviour(event) || catched
  180. catched = this.transition_Root_main_deleting_behaviour(event) || catched
  181. }
  182. return catched;
  183. };
  184. MainApp.prototype.transition_Root_main_main_behaviour = function(event) {
  185. var catched = false;
  186. if (!catched) {
  187. if (this.current_state[this.Root_main_main_behaviour][0] === this.Root_main_main_behaviour_initializing) {
  188. catched = this.transition_Root_main_main_behaviour_initializing(event);
  189. }
  190. else if (this.current_state[this.Root_main_main_behaviour][0] === this.Root_main_main_behaviour_running) {
  191. catched = this.transition_Root_main_main_behaviour_running(event);
  192. }
  193. }
  194. return catched;
  195. };
  196. MainApp.prototype.transition_Root_main_main_behaviour_initializing = function(event) {
  197. var catched = false;
  198. var enableds = new Array();
  199. enableds.push(1);
  200. if (enableds.length > 1) {
  201. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_main_behaviour_initializing. Only the first in document order enabled transition is executed.")
  202. }
  203. if (enableds.length > 0) {
  204. var enabled = enableds[0];
  205. if (enabled === 1) {
  206. this.exit_Root_main_main_behaviour_initializing();
  207. this.enter_Root_main_main_behaviour_running();
  208. }
  209. catched = true;
  210. }
  211. return catched;
  212. };
  213. MainApp.prototype.transition_Root_main_main_behaviour_running = function(event) {
  214. var catched = false;
  215. var enableds = new Array();
  216. if (event.name === "field_created") {
  217. enableds.push(1);
  218. }
  219. if (event.name === "field_deleted") {
  220. if (this.nr_of_fields > 1) {
  221. enableds.push(2);
  222. }
  223. }
  224. if (event.name === "field_deleted") {
  225. if (this.nr_of_fields == 1) {
  226. enableds.push(3);
  227. }
  228. }
  229. if (enableds.length > 1) {
  230. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_main_behaviour_running. Only the first in document order enabled transition is executed.")
  231. }
  232. if (enableds.length > 0) {
  233. var enabled = enableds[0];
  234. if (enabled === 1) {
  235. this.exit_Root_main_main_behaviour_running();
  236. this.nr_of_fields += 1
  237. this.enter_Root_main_main_behaviour_running();
  238. }
  239. else if (enabled === 2) {
  240. this.exit_Root_main_main_behaviour_running();
  241. console.log('not stopped')
  242. this.nr_of_fields -= 1
  243. this.enter_Root_main_main_behaviour_running();
  244. }
  245. else if (enabled === 3) {
  246. this.exit_Root_main_main_behaviour_running();
  247. console.log('stopped')
  248. this.addEvent(new Event("stop", null, []));
  249. this.enter_Root_main_main_behaviour_running();
  250. }
  251. catched = true;
  252. }
  253. return catched;
  254. };
  255. MainApp.prototype.transition_Root_main_creating_behaviour = function(event) {
  256. var catched = false;
  257. if (!catched) {
  258. if (this.current_state[this.Root_main_creating_behaviour][0] === this.Root_main_creating_behaviour_waiting) {
  259. catched = this.transition_Root_main_creating_behaviour_waiting(event);
  260. }
  261. else if (this.current_state[this.Root_main_creating_behaviour][0] === this.Root_main_creating_behaviour_creating) {
  262. catched = this.transition_Root_main_creating_behaviour_creating(event);
  263. }
  264. }
  265. return catched;
  266. };
  267. MainApp.prototype.transition_Root_main_creating_behaviour_waiting = function(event) {
  268. var catched = false;
  269. var enableds = new Array();
  270. if (event.name === "create_field") {
  271. enableds.push(1);
  272. }
  273. if (enableds.length > 1) {
  274. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_creating_behaviour_waiting. Only the first in document order enabled transition is executed.")
  275. }
  276. if (enableds.length > 0) {
  277. var enabled = enableds[0];
  278. if (enabled === 1) {
  279. this.exit_Root_main_creating_behaviour_waiting();
  280. this.object_manager.addEvent(new Event("create_instance", null, [this, 'fields','Field',this.resolution]));
  281. this.enter_Root_main_creating_behaviour_creating();
  282. }
  283. catched = true;
  284. }
  285. return catched;
  286. };
  287. MainApp.prototype.transition_Root_main_creating_behaviour_creating = function(event) {
  288. var catched = false;
  289. var enableds = new Array();
  290. if (event.name === "instance_created") {
  291. enableds.push(1);
  292. }
  293. if (enableds.length > 1) {
  294. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_creating_behaviour_creating. Only the first in document order enabled transition is executed.")
  295. }
  296. if (enableds.length > 0) {
  297. var enabled = enableds[0];
  298. if (enabled === 1) {
  299. var parameters = event.parameters;
  300. var association_name = parameters[0];
  301. this.exit_Root_main_creating_behaviour_creating();
  302. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  303. var send_event = new Event("set_association_name", null, [association_name]);
  304. this.object_manager.addEvent(new Event("narrow_cast", null, [this, association_name , send_event]));
  305. this.addEvent(new Event("field_created", null, []));
  306. this.enter_Root_main_creating_behaviour_waiting();
  307. }
  308. catched = true;
  309. }
  310. return catched;
  311. };
  312. MainApp.prototype.transition_Root_main_deleting_behaviour = function(event) {
  313. var catched = false;
  314. if (!catched) {
  315. if (this.current_state[this.Root_main_deleting_behaviour][0] === this.Root_main_deleting_behaviour_waiting) {
  316. catched = this.transition_Root_main_deleting_behaviour_waiting(event);
  317. }
  318. else if (this.current_state[this.Root_main_deleting_behaviour][0] === this.Root_main_deleting_behaviour_deleting) {
  319. catched = this.transition_Root_main_deleting_behaviour_deleting(event);
  320. }
  321. }
  322. return catched;
  323. };
  324. MainApp.prototype.transition_Root_main_deleting_behaviour_waiting = function(event) {
  325. var catched = false;
  326. var enableds = new Array();
  327. if (event.name === "delete_field") {
  328. enableds.push(1);
  329. }
  330. if (enableds.length > 1) {
  331. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_deleting_behaviour_waiting. Only the first in document order enabled transition is executed.")
  332. }
  333. if (enableds.length > 0) {
  334. var enabled = enableds[0];
  335. if (enabled === 1) {
  336. var parameters = event.parameters;
  337. var association_name = parameters[0];
  338. this.exit_Root_main_deleting_behaviour_waiting();
  339. this.object_manager.addEvent(new Event("delete_instance", null, [this, association_name]));
  340. this.enter_Root_main_deleting_behaviour_deleting();
  341. }
  342. catched = true;
  343. }
  344. return catched;
  345. };
  346. MainApp.prototype.transition_Root_main_deleting_behaviour_deleting = function(event) {
  347. var catched = false;
  348. var enableds = new Array();
  349. if (event.name === "instance_deleted") {
  350. enableds.push(1);
  351. }
  352. if (enableds.length > 1) {
  353. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_deleting_behaviour_deleting. Only the first in document order enabled transition is executed.")
  354. }
  355. if (enableds.length > 0) {
  356. var enabled = enableds[0];
  357. if (enabled === 1) {
  358. this.exit_Root_main_deleting_behaviour_deleting();
  359. this.addEvent(new Event("field_deleted", null, []));
  360. this.enter_Root_main_deleting_behaviour_waiting();
  361. }
  362. catched = true;
  363. }
  364. return catched;
  365. };
  366. MainApp.prototype.transition_Root_stopped = function(event) {
  367. var catched = false;
  368. return catched;
  369. };
  370. // Execute transitions
  371. MainApp.prototype.transition = function(event) {
  372. if (!event) event = new Event();
  373. this.state_changed = this.transition_Root(event);
  374. };
  375. // inState method for statechart
  376. MainApp.prototype.inState = function(nodes) {
  377. for (var c in this.current_state) {
  378. if (!this.current_state.hasOwnProperty(c)) continue;
  379. var new_nodes = new Array();
  380. for (var n in nodes) {
  381. if (!nodes.hasOwnProperty(n)) continue;
  382. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  383. new_nodes.push(nodes[n]);
  384. }
  385. }
  386. nodes = new_nodes;
  387. if (nodes.length === 0) {
  388. return true;
  389. }
  390. }
  391. return false;
  392. };
  393. MainApp.prototype.commonConstructor = function(controller) {
  394. if (!controller) controller = null;
  395. // Constructor part that is common for all constructors.
  396. RuntimeClassBase.call(this);
  397. // User defined input ports
  398. this.inports = new Object();
  399. this.controller = controller;
  400. this.object_manager = (controller == null ? null : controller.object_manager);
  401. this.current_state = new Object();
  402. this.history_state = new Object();
  403. // Initialize statechart
  404. this.current_state[this.Root] = new Array();
  405. this.current_state[this.Root_main] = new Array();
  406. this.current_state[this.Root_main_main_behaviour] = new Array();
  407. this.current_state[this.Root_main_creating_behaviour] = new Array();
  408. this.current_state[this.Root_main_deleting_behaviour] = new Array();
  409. };
  410. MainApp.prototype.start = function() {
  411. RuntimeClassBase.prototype.start.call(this);
  412. this.enterDefault_Root_main();
  413. };
  414. // put class in global diagram object
  415. ParticleInteraction.MainApp = MainApp;
  416. // The actual constructor
  417. var Field = function(controller, resolution) {
  418. Field.prototype.commonConstructor.call(this,controller);
  419. // constructor body (user-defined)
  420. this.field_window = ui.new_window(resolution[0] * 1.28, resolution[1] * 1.28);
  421. this.canvas = ui.append_canvas(this.field_window, resolution[0], resolution[1], {'background':'#eee'});
  422. this.text = this.canvas.add_text(5, 10, '0.0', {})
  423. ui.bind_event(this.field_window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close');
  424. ui.bind_event(this.field_window, ui.EVENTS.KEY_PRESS, this.controller, 'key_press');
  425. this.particles = {}
  426. this.creates = []
  427. this.moves = []
  428. this.color_changes = []
  429. this.deletes = []
  430. this.new_particle_id = undefined
  431. this.positions = {}
  432. this.curr_positions = {}
  433. };
  434. Field.prototype = new RuntimeClassBase();
  435. // Unique IDs for all statechart nodes
  436. Field.prototype.Root = 0;
  437. Field.prototype.Root_main = 1;
  438. Field.prototype.Root_main_main_behaviour = 2;
  439. Field.prototype.Root_main_creating_behaviour = 3;
  440. Field.prototype.Root_main_listening_behaviour = 4;
  441. Field.prototype.Root_main_main_behaviour_initializing = 5;
  442. Field.prototype.Root_main_main_behaviour_running = 6;
  443. Field.prototype.Root_main_creating_behaviour_idle = 7;
  444. Field.prototype.Root_main_creating_behaviour_creating_particle = 8;
  445. Field.prototype.Root_main_listening_behaviour_listening = 9;
  446. Field.prototype.Root_stopped = 10;
  447. // User defined destructor
  448. Field.prototype.destructor = function() {
  449. ui.close_window(this.field_window);
  450. };
  451. // Statechart enter/exit action method(s) :
  452. Field.prototype.enter_Root_main = function() {
  453. this.current_state[this.Root].push(this.Root_main);
  454. };
  455. Field.prototype.exit_Root_main = function() {
  456. this.exit_Root_main_main_behaviour();
  457. this.exit_Root_main_creating_behaviour();
  458. this.exit_Root_main_listening_behaviour();
  459. this.current_state[this.Root] = new Array();
  460. };
  461. Field.prototype.enter_Root_main_main_behaviour = function() {
  462. this.current_state[this.Root_main].push(this.Root_main_main_behaviour);
  463. };
  464. Field.prototype.exit_Root_main_main_behaviour = function() {
  465. if (this.current_state[this.Root_main_main_behaviour].indexOf(this.Root_main_main_behaviour_initializing) !== -1) {
  466. this.exit_Root_main_main_behaviour_initializing();
  467. }
  468. if (this.current_state[this.Root_main_main_behaviour].indexOf(this.Root_main_main_behaviour_running) !== -1) {
  469. this.exit_Root_main_main_behaviour_running();
  470. }
  471. this.current_state[this.Root_main] = new Array();
  472. };
  473. Field.prototype.enter_Root_main_creating_behaviour = function() {
  474. this.current_state[this.Root_main].push(this.Root_main_creating_behaviour);
  475. };
  476. Field.prototype.exit_Root_main_creating_behaviour = function() {
  477. if (this.current_state[this.Root_main_creating_behaviour].indexOf(this.Root_main_creating_behaviour_idle) !== -1) {
  478. this.exit_Root_main_creating_behaviour_idle();
  479. }
  480. if (this.current_state[this.Root_main_creating_behaviour].indexOf(this.Root_main_creating_behaviour_creating_particle) !== -1) {
  481. this.exit_Root_main_creating_behaviour_creating_particle();
  482. }
  483. this.current_state[this.Root_main] = new Array();
  484. };
  485. Field.prototype.enter_Root_main_listening_behaviour = function() {
  486. this.current_state[this.Root_main].push(this.Root_main_listening_behaviour);
  487. };
  488. Field.prototype.exit_Root_main_listening_behaviour = function() {
  489. if (this.current_state[this.Root_main_listening_behaviour].indexOf(this.Root_main_listening_behaviour_listening) !== -1) {
  490. this.exit_Root_main_listening_behaviour_listening();
  491. }
  492. this.current_state[this.Root_main] = new Array();
  493. };
  494. Field.prototype.enter_Root_main_main_behaviour_initializing = function() {
  495. this.current_state[this.Root_main_main_behaviour].push(this.Root_main_main_behaviour_initializing);
  496. };
  497. Field.prototype.exit_Root_main_main_behaviour_initializing = function() {
  498. this.current_state[this.Root_main_main_behaviour] = new Array();
  499. };
  500. Field.prototype.enter_Root_main_main_behaviour_running = function() {
  501. this.current_state[this.Root_main_main_behaviour].push(this.Root_main_main_behaviour_running);
  502. };
  503. Field.prototype.exit_Root_main_main_behaviour_running = function() {
  504. this.current_state[this.Root_main_main_behaviour] = new Array();
  505. };
  506. Field.prototype.enter_Root_main_creating_behaviour_idle = function() {
  507. this.current_state[this.Root_main_creating_behaviour].push(this.Root_main_creating_behaviour_idle);
  508. };
  509. Field.prototype.exit_Root_main_creating_behaviour_idle = function() {
  510. this.current_state[this.Root_main_creating_behaviour] = new Array();
  511. };
  512. Field.prototype.enter_Root_main_creating_behaviour_creating_particle = function() {
  513. this.current_state[this.Root_main_creating_behaviour].push(this.Root_main_creating_behaviour_creating_particle);
  514. };
  515. Field.prototype.exit_Root_main_creating_behaviour_creating_particle = function() {
  516. this.current_state[this.Root_main_creating_behaviour] = new Array();
  517. };
  518. Field.prototype.enter_Root_main_listening_behaviour_listening = function() {
  519. this.current_state[this.Root_main_listening_behaviour].push(this.Root_main_listening_behaviour_listening);
  520. };
  521. Field.prototype.exit_Root_main_listening_behaviour_listening = function() {
  522. this.current_state[this.Root_main_listening_behaviour] = new Array();
  523. };
  524. Field.prototype.enter_Root_stopped = function() {
  525. var send_event = new Event("delete_field", null, [this.association_name]);
  526. this.object_manager.addEvent(new Event("narrow_cast", null, [this, 'parent' , send_event]));
  527. this.current_state[this.Root].push(this.Root_stopped);
  528. };
  529. Field.prototype.exit_Root_stopped = function() {
  530. this.current_state[this.Root] = new Array();
  531. };
  532. // Statechart enter/exit default method(s) :
  533. Field.prototype.enterDefault_Root_main = function() {
  534. this.enter_Root_main();
  535. this.enterDefault_Root_main_main_behaviour();
  536. this.enterDefault_Root_main_creating_behaviour();
  537. this.enterDefault_Root_main_listening_behaviour();
  538. };
  539. Field.prototype.enterDefault_Root_main_main_behaviour = function() {
  540. this.enter_Root_main_main_behaviour();
  541. this.enter_Root_main_main_behaviour_initializing();
  542. };
  543. Field.prototype.enterDefault_Root_main_creating_behaviour = function() {
  544. this.enter_Root_main_creating_behaviour();
  545. this.enter_Root_main_creating_behaviour_idle();
  546. };
  547. Field.prototype.enterDefault_Root_main_listening_behaviour = function() {
  548. this.enter_Root_main_listening_behaviour();
  549. this.enter_Root_main_listening_behaviour_listening();
  550. };
  551. // Statechart transitions :
  552. Field.prototype.transition_Root = function(event) {
  553. var catched = false;
  554. if (!catched) {
  555. if (this.current_state[this.Root][0] === this.Root_main) {
  556. catched = this.transition_Root_main(event);
  557. }
  558. else if (this.current_state[this.Root][0] === this.Root_stopped) {
  559. catched = this.transition_Root_stopped(event);
  560. }
  561. }
  562. return catched;
  563. };
  564. Field.prototype.transition_Root_main = function(event) {
  565. var catched = false;
  566. var enableds = new Array();
  567. if (event.name === "stop") {
  568. enableds.push(1);
  569. }
  570. if (enableds.length > 1) {
  571. console.log("Runtime warning : indeterminism detected in a transition from node Root_main. Only the first in document order enabled transition is executed.")
  572. }
  573. if (enableds.length > 0) {
  574. var enabled = enableds[0];
  575. if (enabled === 1) {
  576. this.exit_Root_main();
  577. this.object_manager.addEvent(new Event("delete_instance", null, [this, 'particles']));
  578. this.enter_Root_stopped();
  579. }
  580. catched = true;
  581. }
  582. if (!catched) {
  583. catched = this.transition_Root_main_main_behaviour(event) || catched
  584. catched = this.transition_Root_main_creating_behaviour(event) || catched
  585. catched = this.transition_Root_main_listening_behaviour(event) || catched
  586. }
  587. return catched;
  588. };
  589. Field.prototype.transition_Root_main_main_behaviour = function(event) {
  590. var catched = false;
  591. if (!catched) {
  592. if (this.current_state[this.Root_main_main_behaviour][0] === this.Root_main_main_behaviour_initializing) {
  593. catched = this.transition_Root_main_main_behaviour_initializing(event);
  594. }
  595. else if (this.current_state[this.Root_main_main_behaviour][0] === this.Root_main_main_behaviour_running) {
  596. catched = this.transition_Root_main_main_behaviour_running(event);
  597. }
  598. }
  599. return catched;
  600. };
  601. Field.prototype.transition_Root_main_main_behaviour_initializing = function(event) {
  602. var catched = false;
  603. var enableds = new Array();
  604. if (event.name === "set_association_name") {
  605. enableds.push(1);
  606. }
  607. if (enableds.length > 1) {
  608. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_main_behaviour_initializing. Only the first in document order enabled transition is executed.")
  609. }
  610. if (enableds.length > 0) {
  611. var enabled = enableds[0];
  612. if (enabled === 1) {
  613. var parameters = event.parameters;
  614. var association_name = parameters[0];
  615. this.exit_Root_main_main_behaviour_initializing();
  616. this.association_name = association_name
  617. this.enter_Root_main_main_behaviour_running();
  618. }
  619. catched = true;
  620. }
  621. return catched;
  622. };
  623. Field.prototype.transition_Root_main_main_behaviour_running = function(event) {
  624. var catched = false;
  625. var enableds = new Array();
  626. if (event.name === "window_close" && event.port === "ui") {
  627. var parameters = event.parameters;
  628. var window = parameters[0];
  629. if (window == this.field_window || window == ui.window) {
  630. enableds.push(1);
  631. }
  632. }
  633. if (enableds.length > 1) {
  634. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_main_behaviour_running. Only the first in document order enabled transition is executed.")
  635. }
  636. if (enableds.length > 0) {
  637. var enabled = enableds[0];
  638. if (enabled === 1) {
  639. var parameters = event.parameters;
  640. var window = parameters[0];
  641. this.exit_Root_main_main_behaviour_running();
  642. this.addEvent(new Event("stop", null, []));
  643. this.enter_Root_main_main_behaviour_running();
  644. }
  645. catched = true;
  646. }
  647. return catched;
  648. };
  649. Field.prototype.transition_Root_main_creating_behaviour = function(event) {
  650. var catched = false;
  651. if (!catched) {
  652. if (this.current_state[this.Root_main_creating_behaviour][0] === this.Root_main_creating_behaviour_idle) {
  653. catched = this.transition_Root_main_creating_behaviour_idle(event);
  654. }
  655. else if (this.current_state[this.Root_main_creating_behaviour][0] === this.Root_main_creating_behaviour_creating_particle) {
  656. catched = this.transition_Root_main_creating_behaviour_creating_particle(event);
  657. }
  658. }
  659. return catched;
  660. };
  661. Field.prototype.transition_Root_main_creating_behaviour_idle = function(event) {
  662. var catched = false;
  663. var enableds = new Array();
  664. if (event.name === "create_particle") {
  665. enableds.push(1);
  666. }
  667. if (enableds.length > 1) {
  668. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_creating_behaviour_idle. Only the first in document order enabled transition is executed.")
  669. }
  670. if (enableds.length > 0) {
  671. var enabled = enableds[0];
  672. if (enabled === 1) {
  673. var parameters = event.parameters;
  674. var new_particle_info = parameters[0];
  675. this.exit_Root_main_creating_behaviour_idle();
  676. this.object_manager.addEvent(new Event("create_instance", null, [this, "particles","Particle",this.canvas,new_particle_info[0],new_particle_info[1][0],new_particle_info[1][1],new_particle_info[2]]));
  677. this.new_particle_id = new_particle_info[0]
  678. this.enter_Root_main_creating_behaviour_creating_particle();
  679. }
  680. catched = true;
  681. }
  682. return catched;
  683. };
  684. Field.prototype.transition_Root_main_creating_behaviour_creating_particle = function(event) {
  685. var catched = false;
  686. var enableds = new Array();
  687. if (event.name === "instance_created") {
  688. enableds.push(1);
  689. }
  690. if (enableds.length > 1) {
  691. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_creating_behaviour_creating_particle. Only the first in document order enabled transition is executed.")
  692. }
  693. if (enableds.length > 0) {
  694. var enabled = enableds[0];
  695. if (enabled === 1) {
  696. var parameters = event.parameters;
  697. var association_name = parameters[0];
  698. this.exit_Root_main_creating_behaviour_creating_particle();
  699. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  700. var send_event = new Event("set_association_name", null, [association_name]);
  701. this.object_manager.addEvent(new Event("narrow_cast", null, [this, association_name , send_event]));
  702. this.particles[this.new_particle_id] = association_name
  703. this.enter_Root_main_creating_behaviour_idle();
  704. }
  705. catched = true;
  706. }
  707. return catched;
  708. };
  709. Field.prototype.transition_Root_main_listening_behaviour = function(event) {
  710. var catched = false;
  711. if (!catched) {
  712. if (this.current_state[this.Root_main_listening_behaviour][0] === this.Root_main_listening_behaviour_listening) {
  713. catched = this.transition_Root_main_listening_behaviour_listening(event);
  714. }
  715. }
  716. return catched;
  717. };
  718. Field.prototype.transition_Root_main_listening_behaviour_listening = function(event) {
  719. var catched = false;
  720. var enableds = new Array();
  721. if (event.name === "reset" && event.port === "input") {
  722. enableds.push(1);
  723. }
  724. if (event.name === "update_time" && event.port === "input") {
  725. enableds.push(2);
  726. }
  727. if (event.name === "create_particle" && event.port === "input") {
  728. enableds.push(3);
  729. }
  730. if (event.name === "delete_particle" && event.port === "input") {
  731. enableds.push(4);
  732. }
  733. if (event.name === "key_press" && event.port === "ui") {
  734. var parameters = event.parameters;
  735. var key = parameters[0];
  736. var active_window = parameters[1];
  737. if (key == ui.KEYCODES.DELETE && active_window == this.field_window) {
  738. enableds.push(5);
  739. }
  740. }
  741. if (enableds.length > 1) {
  742. console.log("Runtime warning : indeterminism detected in a transition from node Root_main_listening_behaviour_listening. Only the first in document order enabled transition is executed.")
  743. }
  744. if (enableds.length > 0) {
  745. var enabled = enableds[0];
  746. if (enabled === 1) {
  747. this.exit_Root_main_listening_behaviour_listening();
  748. this.text.set_text("0.0");
  749. this.particles = {};
  750. this.object_manager.addEvent(new Event("delete_instance", null, [this, 'particles']));
  751. this.enter_Root_main_listening_behaviour_listening();
  752. }
  753. else if (enabled === 2) {
  754. var parameters = event.parameters;
  755. var new_time = parameters[0];
  756. this.exit_Root_main_listening_behaviour_listening();
  757. this.text.set_text(new_time)
  758. this.enter_Root_main_listening_behaviour_listening();
  759. }
  760. else if (enabled === 3) {
  761. var parameters = event.parameters;
  762. var params = parameters[0];
  763. this.exit_Root_main_listening_behaviour_listening();
  764. this.addEvent(new Event("create_particle", null, [params]));
  765. this.enter_Root_main_listening_behaviour_listening();
  766. }
  767. else if (enabled === 4) {
  768. var parameters = event.parameters;
  769. var particle_id = parameters[0];
  770. this.exit_Root_main_listening_behaviour_listening();
  771. this.object_manager.addEvent(new Event("delete_instance", null, [this, this.particles[particle_id]]));
  772. delete this.particles[particle_id]
  773. this.enter_Root_main_listening_behaviour_listening();
  774. }
  775. else if (enabled === 5) {
  776. var parameters = event.parameters;
  777. var key = parameters[0];
  778. var active_window = parameters[1];
  779. this.exit_Root_main_listening_behaviour_listening();
  780. this.controller.outputEvent(new Event("delete_selected", "output", []));
  781. this.enter_Root_main_listening_behaviour_listening();
  782. }
  783. catched = true;
  784. }
  785. return catched;
  786. };
  787. Field.prototype.transition_Root_stopped = function(event) {
  788. var catched = false;
  789. return catched;
  790. };
  791. // Execute transitions
  792. Field.prototype.transition = function(event) {
  793. if (!event) event = new Event();
  794. this.state_changed = this.transition_Root(event);
  795. };
  796. // inState method for statechart
  797. Field.prototype.inState = function(nodes) {
  798. for (var c in this.current_state) {
  799. if (!this.current_state.hasOwnProperty(c)) continue;
  800. var new_nodes = new Array();
  801. for (var n in nodes) {
  802. if (!nodes.hasOwnProperty(n)) continue;
  803. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  804. new_nodes.push(nodes[n]);
  805. }
  806. }
  807. nodes = new_nodes;
  808. if (nodes.length === 0) {
  809. return true;
  810. }
  811. }
  812. return false;
  813. };
  814. Field.prototype.commonConstructor = function(controller) {
  815. if (!controller) controller = null;
  816. // Constructor part that is common for all constructors.
  817. RuntimeClassBase.call(this);
  818. // User defined input ports
  819. this.inports = new Object();
  820. this.controller = controller;
  821. this.object_manager = (controller == null ? null : controller.object_manager);
  822. this.current_state = new Object();
  823. this.history_state = new Object();
  824. // Initialize statechart
  825. this.current_state[this.Root] = new Array();
  826. this.current_state[this.Root_main] = new Array();
  827. this.current_state[this.Root_main_main_behaviour] = new Array();
  828. this.current_state[this.Root_main_creating_behaviour] = new Array();
  829. this.current_state[this.Root_main_listening_behaviour] = new Array();
  830. };
  831. Field.prototype.start = function() {
  832. RuntimeClassBase.prototype.start.call(this);
  833. this.enterDefault_Root_main();
  834. };
  835. // put class in global diagram object
  836. ParticleInteraction.Field = Field;
  837. // The actual constructor
  838. var Particle = function(controller, canvas, particle_id, x, y, r) {
  839. Particle.prototype.commonConstructor.call(this,controller);
  840. // constructor body (user-defined)
  841. this.canvas = canvas
  842. this.x = x
  843. this.y = y
  844. this.r = r
  845. this.circle_id = this.canvas.add_circle(x, y, r, {fill:"red"})
  846. this.middle_id = this.canvas.add_circle(x, y, 4, {fill:"orange"})
  847. this.particle_id = particle_id
  848. ui.bind_event(this.circle_id, ui.EVENTS.MOUSE_PRESS, this.controller, 'mouse_click', this.inports['particle_ui']);
  849. ui.bind_event(this.circle_id, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'mouse_click', this.inports['particle_ui']);
  850. };
  851. Particle.prototype = new RuntimeClassBase();
  852. // Unique IDs for all statechart nodes
  853. Particle.prototype.Root = 0;
  854. Particle.prototype.Root_initializing = 1;
  855. Particle.prototype.Root_running = 2;
  856. Particle.prototype.Root_deleted = 3;
  857. // User defined destructor
  858. Particle.prototype.destructor = function() {
  859. this.canvas.remove_element(this.circle_id)
  860. this.canvas.remove_element(this.middle_id)
  861. };
  862. // Statechart enter/exit action method(s) :
  863. Particle.prototype.enter_Root_initializing = function() {
  864. this.current_state[this.Root].push(this.Root_initializing);
  865. };
  866. Particle.prototype.exit_Root_initializing = function() {
  867. this.current_state[this.Root] = new Array();
  868. };
  869. Particle.prototype.enter_Root_running = function() {
  870. this.current_state[this.Root].push(this.Root_running);
  871. };
  872. Particle.prototype.exit_Root_running = function() {
  873. this.current_state[this.Root] = new Array();
  874. };
  875. Particle.prototype.enter_Root_deleted = function() {
  876. this.current_state[this.Root].push(this.Root_deleted);
  877. };
  878. Particle.prototype.exit_Root_deleted = function() {
  879. this.current_state[this.Root] = new Array();
  880. };
  881. // Statechart transitions :
  882. Particle.prototype.transition_Root = function(event) {
  883. var catched = false;
  884. if (!catched) {
  885. if (this.current_state[this.Root][0] === this.Root_initializing) {
  886. catched = this.transition_Root_initializing(event);
  887. }
  888. else if (this.current_state[this.Root][0] === this.Root_running) {
  889. catched = this.transition_Root_running(event);
  890. }
  891. else if (this.current_state[this.Root][0] === this.Root_deleted) {
  892. catched = this.transition_Root_deleted(event);
  893. }
  894. }
  895. return catched;
  896. };
  897. Particle.prototype.transition_Root_initializing = function(event) {
  898. var catched = false;
  899. var enableds = new Array();
  900. if (event.name === "set_association_name") {
  901. enableds.push(1);
  902. }
  903. if (enableds.length > 1) {
  904. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing. Only the first in document order enabled transition is executed.")
  905. }
  906. if (enableds.length > 0) {
  907. var enabled = enableds[0];
  908. if (enabled === 1) {
  909. var parameters = event.parameters;
  910. var association_name = parameters[0];
  911. this.exit_Root_initializing();
  912. this.association_name = association_name
  913. this.enter_Root_running();
  914. }
  915. catched = true;
  916. }
  917. return catched;
  918. };
  919. Particle.prototype.transition_Root_running = function(event) {
  920. var catched = false;
  921. var enableds = new Array();
  922. if (event.name === "move_particle" && event.port === "input") {
  923. var parameters = event.parameters;
  924. var params = parameters[0];
  925. if (params[0] == this.particle_id) {
  926. enableds.push(1);
  927. }
  928. }
  929. if (event.name === "color_particle" && event.port === "input") {
  930. var parameters = event.parameters;
  931. var params = parameters[0];
  932. if (params[0] == this.particle_id) {
  933. enableds.push(2);
  934. }
  935. }
  936. if (event.name === "mouse_click" && event.port === "particle_ui") {
  937. var parameters = event.parameters;
  938. var x = parameters[0];
  939. var y = parameters[1];
  940. var button = parameters[2];
  941. if (button == ui.MOUSE_BUTTONS.LEFT) {
  942. enableds.push(3);
  943. }
  944. }
  945. if (event.name === "mouse_click" && event.port === "particle_ui") {
  946. var parameters = event.parameters;
  947. var x = parameters[0];
  948. var y = parameters[1];
  949. var button = parameters[2];
  950. if (button == ui.MOUSE_BUTTONS.RIGHT) {
  951. enableds.push(4);
  952. }
  953. }
  954. if (enableds.length > 1) {
  955. console.log("Runtime warning : indeterminism detected in a transition from node Root_running. Only the first in document order enabled transition is executed.")
  956. }
  957. if (enableds.length > 0) {
  958. var enabled = enableds[0];
  959. if (enabled === 1) {
  960. var parameters = event.parameters;
  961. var params = parameters[0];
  962. this.exit_Root_running();
  963. var x = params[1][0]
  964. var y = params[1][1]
  965. this.circle_id.set_position(x, y)
  966. this.middle_id.set_position(x, y)
  967. this.enter_Root_running();
  968. }
  969. else if (enabled === 2) {
  970. var parameters = event.parameters;
  971. var params = parameters[0];
  972. this.exit_Root_running();
  973. this.circle_id.set_color(params[1])
  974. this.enter_Root_running();
  975. }
  976. else if (enabled === 3) {
  977. var parameters = event.parameters;
  978. var x = parameters[0];
  979. var y = parameters[1];
  980. var button = parameters[2];
  981. this.exit_Root_running();
  982. this.controller.outputEvent(new Event("particle_clicked", "output", [this.particle_id]));
  983. this.enter_Root_running();
  984. }
  985. else if (enabled === 4) {
  986. var parameters = event.parameters;
  987. var x = parameters[0];
  988. var y = parameters[1];
  989. var button = parameters[2];
  990. this.exit_Root_running();
  991. this.controller.outputEvent(new Event("particle_right_clicked", "output", [this.particle_id]));
  992. this.enter_Root_running();
  993. }
  994. catched = true;
  995. }
  996. return catched;
  997. };
  998. Particle.prototype.transition_Root_deleted = function(event) {
  999. var catched = false;
  1000. return catched;
  1001. };
  1002. // Execute transitions
  1003. Particle.prototype.transition = function(event) {
  1004. if (!event) event = new Event();
  1005. this.state_changed = this.transition_Root(event);
  1006. };
  1007. // inState method for statechart
  1008. Particle.prototype.inState = function(nodes) {
  1009. for (var c in this.current_state) {
  1010. if (!this.current_state.hasOwnProperty(c)) continue;
  1011. var new_nodes = new Array();
  1012. for (var n in nodes) {
  1013. if (!nodes.hasOwnProperty(n)) continue;
  1014. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  1015. new_nodes.push(nodes[n]);
  1016. }
  1017. }
  1018. nodes = new_nodes;
  1019. if (nodes.length === 0) {
  1020. return true;
  1021. }
  1022. }
  1023. return false;
  1024. };
  1025. Particle.prototype.commonConstructor = function(controller) {
  1026. if (!controller) controller = null;
  1027. // Constructor part that is common for all constructors.
  1028. RuntimeClassBase.call(this);
  1029. // User defined input ports
  1030. this.inports = new Object();
  1031. this.inports["particle_ui"] = controller.addInputPort("particle_ui", this);
  1032. this.controller = controller;
  1033. this.object_manager = (controller == null ? null : controller.object_manager);
  1034. this.current_state = new Object();
  1035. this.history_state = new Object();
  1036. // Initialize statechart
  1037. this.current_state[this.Root] = new Array();
  1038. };
  1039. Particle.prototype.start = function() {
  1040. RuntimeClassBase.prototype.start.call(this);
  1041. this.enter_Root_initializing();
  1042. };
  1043. // put class in global diagram object
  1044. ParticleInteraction.Particle = Particle;
  1045. var ObjectManager = function(controller) {
  1046. ObjectManagerBase.call(this, controller);
  1047. };
  1048. ObjectManager.prototype = new ObjectManagerBase();
  1049. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  1050. if (class_name === "MainApp") {
  1051. var instance = new MainApp(this.controller, construct_params[0]);
  1052. instance.associations = new Object();
  1053. instance.associations["fields"] = new Association("Field", 0, -1);
  1054. } else if (class_name === "Field") {
  1055. var instance = new Field(this.controller, construct_params[0]);
  1056. instance.associations = new Object();
  1057. instance.associations["parent"] = new Association("MainApp", 1, 1);
  1058. instance.associations["particles"] = new Association("Particle", 0, -1);
  1059. } else if (class_name === "Particle") {
  1060. var instance = new Particle(this.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4]);
  1061. instance.associations = new Object();
  1062. instance.associations["parent"] = new Association("Field", 1, 1);
  1063. }
  1064. return instance;
  1065. };
  1066. // put in global diagram object
  1067. ParticleInteraction.ObjectManager = ObjectManager;
  1068. var Controller = function(resolution, keep_running, finished_callback) {
  1069. if (keep_running === undefined) keep_running = true;
  1070. JsEventLoopControllerBase.call(this, new ObjectManager(this), keep_running, finished_callback);
  1071. this.addInputPort("ui");
  1072. this.addInputPort("input");
  1073. this.object_manager.createInstance("MainApp", [resolution]);
  1074. };
  1075. Controller.prototype = new JsEventLoopControllerBase();
  1076. // put in global diagram object
  1077. ParticleInteraction.Controller = Controller;
  1078. })();