traffic.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /**
  2. * Statechart compiler by Glenn De Jonghe
  3. * Javascript generator by Joeri Exelmans
  4. *
  5. * Date: Tue Sep 09 17:59:36 2014
  6. *
  7. * Model author: Raphael Mannadiar
  8. * Model name: Traffic_Light
  9. * Model description:
  10. PIM Traffic lights.
  11. */
  12. // put everything in an object (serves as "namespace")
  13. Traffic_Light = {};
  14. // closure scope
  15. (function() {
  16. // The actual constructor
  17. var TrafficLight = function(controller, canvas) {
  18. // Unique IDs for all statechart nodes
  19. this.Root = 0;
  20. this.Root_on = 1;
  21. this.Root_on_interrupted = 2;
  22. this.Root_on_normal = 3;
  23. this.Root_on_interrupted_yellow = 4;
  24. this.Root_on_interrupted_black = 5;
  25. this.Root_on_normal_yellow = 6;
  26. this.Root_on_normal_green = 7;
  27. this.Root_on_normal_red = 8;
  28. this.Root_off = 9;
  29. TrafficLight.prototype.commonConstructor.call(this,controller);
  30. // constructor body (user-defined)
  31. var size = 100;
  32. var offset = size + 5;
  33. this.RED = 0;
  34. this.YELLOW = 1;
  35. this.GREEN = 2;
  36. this.colors = ['#f00', '#ff0', '#0f0'];
  37. this.lights = [canvas.add_rectangle(size / 2, size / 2, size, size, {'fill':'#000'}), canvas.add_rectangle(size / 2, size / 2 + offset, size, size, {'fill':'#000'}), canvas.add_rectangle(size / 2, size / 2 + 2 * offset, size, size, {'fill':'#000'})];
  38. };
  39. TrafficLight.prototype = new RuntimeClassBase();
  40. // User defined method
  41. TrafficLight.prototype.setYellow = function() {
  42. this.clear();
  43. this.lights[this.YELLOW].set_color(this.colors[this.YELLOW]);
  44. };
  45. // User defined method
  46. TrafficLight.prototype.setGreen = function() {
  47. this.clear();
  48. this.lights[this.GREEN].set_color(this.colors[this.GREEN]);
  49. };
  50. // User defined method
  51. TrafficLight.prototype.clear = function() {
  52. this.lights[this.RED].set_color('#000');
  53. this.lights[this.YELLOW].set_color('#000');
  54. this.lights[this.GREEN].set_color('#000');
  55. };
  56. // User defined method
  57. TrafficLight.prototype.setRed = function() {
  58. this.clear();
  59. this.lights[this.RED].set_color(this.colors[this.RED]);
  60. };
  61. // Statechart enter/exit action method(s) :
  62. TrafficLight.prototype.enter_Root_on = function() {
  63. this.current_state[this.Root].push(this.Root_on);
  64. };
  65. TrafficLight.prototype.exit_Root_on = function() {
  66. if (this.current_state[this.Root_on].indexOf(this.Root_on_interrupted) !== -1) {
  67. this.exit_Root_on_interrupted();
  68. }
  69. if (this.current_state[this.Root_on].indexOf(this.Root_on_normal) !== -1) {
  70. this.exit_Root_on_normal();
  71. }
  72. this.current_state[this.Root] = new Array();
  73. };
  74. TrafficLight.prototype.enter_Root_on_interrupted = function() {
  75. this.current_state[this.Root_on].push(this.Root_on_interrupted);
  76. };
  77. TrafficLight.prototype.exit_Root_on_interrupted = function() {
  78. if (this.current_state[this.Root_on_interrupted].indexOf(this.Root_on_interrupted_yellow) !== -1) {
  79. this.exit_Root_on_interrupted_yellow();
  80. }
  81. if (this.current_state[this.Root_on_interrupted].indexOf(this.Root_on_interrupted_black) !== -1) {
  82. this.exit_Root_on_interrupted_black();
  83. }
  84. this.current_state[this.Root_on] = new Array();
  85. };
  86. TrafficLight.prototype.enter_Root_on_normal = function() {
  87. this.current_state[this.Root_on].push(this.Root_on_normal);
  88. };
  89. TrafficLight.prototype.exit_Root_on_normal = function() {
  90. this.history_state[this.Root_on_normal] = this.current_state[this.Root_on_normal];
  91. if (this.current_state[this.Root_on_normal].indexOf(this.Root_on_normal_yellow) !== -1) {
  92. this.exit_Root_on_normal_yellow();
  93. }
  94. if (this.current_state[this.Root_on_normal].indexOf(this.Root_on_normal_green) !== -1) {
  95. this.exit_Root_on_normal_green();
  96. }
  97. if (this.current_state[this.Root_on_normal].indexOf(this.Root_on_normal_red) !== -1) {
  98. this.exit_Root_on_normal_red();
  99. }
  100. this.current_state[this.Root_on] = new Array();
  101. };
  102. TrafficLight.prototype.enter_Root_on_interrupted_yellow = function() {
  103. this.timers[0] = 0.5 * 1000.0; /* convert ms to s */
  104. this.setYellow();
  105. this.current_state[this.Root_on_interrupted].push(this.Root_on_interrupted_yellow);
  106. };
  107. TrafficLight.prototype.exit_Root_on_interrupted_yellow = function() {
  108. delete this.timers[0];
  109. this.current_state[this.Root_on_interrupted] = new Array();
  110. };
  111. TrafficLight.prototype.enter_Root_on_interrupted_black = function() {
  112. this.timers[1] = 0.5 * 1000.0; /* convert ms to s */
  113. this.clear();
  114. this.current_state[this.Root_on_interrupted].push(this.Root_on_interrupted_black);
  115. };
  116. TrafficLight.prototype.exit_Root_on_interrupted_black = function() {
  117. delete this.timers[1];
  118. this.current_state[this.Root_on_interrupted] = new Array();
  119. };
  120. TrafficLight.prototype.enter_Root_on_normal_yellow = function() {
  121. this.timers[2] = 1.0 * 1000.0; /* convert ms to s */
  122. this.setYellow();
  123. this.current_state[this.Root_on_normal].push(this.Root_on_normal_yellow);
  124. };
  125. TrafficLight.prototype.exit_Root_on_normal_yellow = function() {
  126. delete this.timers[2];
  127. this.current_state[this.Root_on_normal] = new Array();
  128. };
  129. TrafficLight.prototype.enter_Root_on_normal_green = function() {
  130. this.timers[3] = 2.0 * 1000.0; /* convert ms to s */
  131. this.setGreen();
  132. this.current_state[this.Root_on_normal].push(this.Root_on_normal_green);
  133. };
  134. TrafficLight.prototype.exit_Root_on_normal_green = function() {
  135. delete this.timers[3];
  136. this.current_state[this.Root_on_normal] = new Array();
  137. };
  138. TrafficLight.prototype.enter_Root_on_normal_red = function() {
  139. this.timers[4] = 3.0 * 1000.0; /* convert ms to s */
  140. this.setRed();
  141. this.current_state[this.Root_on_normal].push(this.Root_on_normal_red);
  142. };
  143. TrafficLight.prototype.exit_Root_on_normal_red = function() {
  144. delete this.timers[4];
  145. this.current_state[this.Root_on_normal] = new Array();
  146. };
  147. TrafficLight.prototype.enter_Root_off = function() {
  148. this.clear();
  149. this.current_state[this.Root].push(this.Root_off);
  150. };
  151. TrafficLight.prototype.exit_Root_off = function() {
  152. this.current_state[this.Root] = new Array();
  153. };
  154. // Statechart enter/exit default method(s) :
  155. TrafficLight.prototype.enterDefault_Root_on = function() {
  156. this.enter_Root_on();
  157. this.enterDefault_Root_on_normal();
  158. };
  159. TrafficLight.prototype.enterDefault_Root_on_interrupted = function() {
  160. this.enter_Root_on_interrupted();
  161. this.enter_Root_on_interrupted_yellow();
  162. };
  163. TrafficLight.prototype.enterDefault_Root_on_normal = function() {
  164. this.enter_Root_on_normal();
  165. this.enter_Root_on_normal_red();
  166. };
  167. // Statechart enter/exit history method(s) :
  168. TrafficLight.prototype.enterHistoryShallow_Root_on_normal = function() {
  169. if (this.history_state[this.Root_on_normal].length === 0) {
  170. this.enter_Root_on_normal_red();
  171. } else {
  172. if (this.history_state[this.Root_on_normal].indexOf(this.Root_on_normal_yellow) !== -1) {
  173. this.enter_Root_on_normal_yellow()
  174. }
  175. if (this.history_state[this.Root_on_normal].indexOf(this.Root_on_normal_green) !== -1) {
  176. this.enter_Root_on_normal_green()
  177. }
  178. if (this.history_state[this.Root_on_normal].indexOf(this.Root_on_normal_red) !== -1) {
  179. this.enter_Root_on_normal_red()
  180. }
  181. }
  182. };
  183. // Statechart transitions :
  184. TrafficLight.prototype.transition_Root = function(event) {
  185. var catched = false;
  186. if (!catched) {
  187. if (this.current_state[this.Root][0] === this.Root_on) {
  188. catched = this.transition_Root_on(event);
  189. }
  190. else if (this.current_state[this.Root][0] === this.Root_off) {
  191. catched = this.transition_Root_off(event);
  192. }
  193. }
  194. return catched;
  195. };
  196. TrafficLight.prototype.transition_Root_on = function(event) {
  197. var catched = false;
  198. var enableds = new Array();
  199. if (event.name === "stop_clicked" && event.port === "ui") {
  200. enableds.push(1);
  201. }
  202. if (enableds.length > 1) {
  203. console.log("Runtime warning : indeterminism detected in a transition from node Root_on. Only the first in document order enabled transition is executed.")
  204. }
  205. if (enableds.length > 0) {
  206. var enabled = enableds[0];
  207. if (enabled === 1) {
  208. this.exit_Root_on();
  209. this.enter_Root_off();
  210. }
  211. catched = true;
  212. }
  213. if (!catched) {
  214. if (this.current_state[this.Root_on][0] === this.Root_on_interrupted) {
  215. catched = this.transition_Root_on_interrupted(event);
  216. }
  217. else if (this.current_state[this.Root_on][0] === this.Root_on_normal) {
  218. catched = this.transition_Root_on_normal(event);
  219. }
  220. }
  221. return catched;
  222. };
  223. TrafficLight.prototype.transition_Root_on_interrupted = function(event) {
  224. var catched = false;
  225. var enableds = new Array();
  226. if (event.name === "police_interrupt_clicked" && event.port === "ui") {
  227. enableds.push(1);
  228. }
  229. if (enableds.length > 1) {
  230. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_interrupted. 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_on_interrupted();
  236. this.enter_Root_on_normal();
  237. this.enterHistoryShallow_Root_on_normal();
  238. }
  239. catched = true;
  240. }
  241. if (!catched) {
  242. if (this.current_state[this.Root_on_interrupted][0] === this.Root_on_interrupted_yellow) {
  243. catched = this.transition_Root_on_interrupted_yellow(event);
  244. }
  245. else if (this.current_state[this.Root_on_interrupted][0] === this.Root_on_interrupted_black) {
  246. catched = this.transition_Root_on_interrupted_black(event);
  247. }
  248. }
  249. return catched;
  250. };
  251. TrafficLight.prototype.transition_Root_on_interrupted_yellow = function(event) {
  252. var catched = false;
  253. var enableds = new Array();
  254. if (event.name === "_0after") {
  255. enableds.push(1);
  256. }
  257. if (enableds.length > 1) {
  258. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_interrupted_yellow. Only the first in document order enabled transition is executed.")
  259. }
  260. if (enableds.length > 0) {
  261. var enabled = enableds[0];
  262. if (enabled === 1) {
  263. this.exit_Root_on_interrupted_yellow();
  264. this.enter_Root_on_interrupted_black();
  265. }
  266. catched = true;
  267. }
  268. return catched;
  269. };
  270. TrafficLight.prototype.transition_Root_on_interrupted_black = function(event) {
  271. var catched = false;
  272. var enableds = new Array();
  273. if (event.name === "_1after") {
  274. enableds.push(1);
  275. }
  276. if (enableds.length > 1) {
  277. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_interrupted_black. 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_on_interrupted_black();
  283. this.enter_Root_on_interrupted_yellow();
  284. }
  285. catched = true;
  286. }
  287. return catched;
  288. };
  289. TrafficLight.prototype.transition_Root_on_normal = function(event) {
  290. var catched = false;
  291. var enableds = new Array();
  292. if (event.name === "police_interrupt_clicked" && event.port === "ui") {
  293. enableds.push(1);
  294. }
  295. if (enableds.length > 1) {
  296. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_normal. Only the first in document order enabled transition is executed.")
  297. }
  298. if (enableds.length > 0) {
  299. var enabled = enableds[0];
  300. if (enabled === 1) {
  301. this.exit_Root_on_normal();
  302. this.enterDefault_Root_on_interrupted();
  303. }
  304. catched = true;
  305. }
  306. if (!catched) {
  307. if (this.current_state[this.Root_on_normal][0] === this.Root_on_normal_yellow) {
  308. catched = this.transition_Root_on_normal_yellow(event);
  309. }
  310. else if (this.current_state[this.Root_on_normal][0] === this.Root_on_normal_green) {
  311. catched = this.transition_Root_on_normal_green(event);
  312. }
  313. else if (this.current_state[this.Root_on_normal][0] === this.Root_on_normal_red) {
  314. catched = this.transition_Root_on_normal_red(event);
  315. }
  316. }
  317. return catched;
  318. };
  319. TrafficLight.prototype.transition_Root_on_normal_yellow = function(event) {
  320. var catched = false;
  321. var enableds = new Array();
  322. if (event.name === "_2after") {
  323. enableds.push(1);
  324. }
  325. if (enableds.length > 1) {
  326. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_normal_yellow. Only the first in document order enabled transition is executed.")
  327. }
  328. if (enableds.length > 0) {
  329. var enabled = enableds[0];
  330. if (enabled === 1) {
  331. this.exit_Root_on_normal_yellow();
  332. this.enter_Root_on_normal_red();
  333. }
  334. catched = true;
  335. }
  336. return catched;
  337. };
  338. TrafficLight.prototype.transition_Root_on_normal_green = function(event) {
  339. var catched = false;
  340. var enableds = new Array();
  341. if (event.name === "_3after") {
  342. enableds.push(1);
  343. }
  344. if (enableds.length > 1) {
  345. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_normal_green. Only the first in document order enabled transition is executed.")
  346. }
  347. if (enableds.length > 0) {
  348. var enabled = enableds[0];
  349. if (enabled === 1) {
  350. this.exit_Root_on_normal_green();
  351. this.enter_Root_on_normal_yellow();
  352. }
  353. catched = true;
  354. }
  355. return catched;
  356. };
  357. TrafficLight.prototype.transition_Root_on_normal_red = function(event) {
  358. var catched = false;
  359. var enableds = new Array();
  360. if (event.name === "_4after") {
  361. enableds.push(1);
  362. }
  363. if (enableds.length > 1) {
  364. console.log("Runtime warning : indeterminism detected in a transition from node Root_on_normal_red. Only the first in document order enabled transition is executed.")
  365. }
  366. if (enableds.length > 0) {
  367. var enabled = enableds[0];
  368. if (enabled === 1) {
  369. this.exit_Root_on_normal_red();
  370. this.enter_Root_on_normal_green();
  371. }
  372. catched = true;
  373. }
  374. return catched;
  375. };
  376. TrafficLight.prototype.transition_Root_off = function(event) {
  377. var catched = false;
  378. return catched;
  379. };
  380. // Execute transitions
  381. TrafficLight.prototype.transition = function(event) {
  382. if (!event) event = new Event();
  383. this.state_changed = this.transition_Root(event);
  384. };
  385. // inState method for statechart
  386. TrafficLight.prototype.inState = function(nodes) {
  387. for (var c in this.current_state) {
  388. if (!this.current_state.hasOwnProperty(c)) continue;
  389. var new_nodes = new Array();
  390. for (var n in nodes) {
  391. if (!nodes.hasOwnProperty(n)) continue;
  392. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  393. new_nodes.push(nodes[n]);
  394. }
  395. }
  396. nodes = new_nodes;
  397. if (nodes.length === 0) {
  398. return true;
  399. }
  400. }
  401. return false;
  402. };
  403. TrafficLight.prototype.commonConstructor = function(controller) {
  404. if (!controller) controller = null;
  405. // Constructor part that is common for all constructors.
  406. RuntimeClassBase.call(this);
  407. // User defined input ports
  408. this.inports = new Object();
  409. this.controller = controller;
  410. this.object_manager = (controller == null ? null : controller.object_manager);
  411. this.current_state = new Object();
  412. this.history_state = new Object();
  413. this.timers = new Object();
  414. // Initialize statechart
  415. this.history_state[TrafficLight.Root_on_normal] = new Array();
  416. this.current_state[this.Root] = new Array();
  417. this.current_state[this.Root_on] = new Array();
  418. this.current_state[this.Root_on_interrupted] = new Array();
  419. this.current_state[this.Root_on_normal] = new Array();
  420. };
  421. TrafficLight.prototype.start = function() {
  422. RuntimeClassBase.prototype.start.call(this);
  423. this.enterDefault_Root_on();
  424. };
  425. // put class in global diagram object
  426. Traffic_Light.TrafficLight = TrafficLight;
  427. // The actual constructor
  428. var MainApp = function(controller) {
  429. // Unique IDs for all statechart nodes
  430. this.Root = 0;
  431. this.Root_initializing = 1;
  432. this.Root_creating = 2;
  433. this.Root_initialized = 3;
  434. MainApp.prototype.commonConstructor.call(this,controller);
  435. // constructor body (user-defined)
  436. this.canvas = ui.append_canvas(ui.window, 100, 310, {'background':'#eee'});
  437. var police_button = ui.append_button(ui.window, 'Police interrupt');
  438. var stop_button = ui.append_button(ui.window, 'Stop');
  439. ui.bind_event(police_button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'police_interrupt_clicked');
  440. ui.bind_event(stop_button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'stop_clicked');
  441. };
  442. MainApp.prototype = new RuntimeClassBase();
  443. // Statechart enter/exit action method(s) :
  444. MainApp.prototype.enter_Root_initializing = function() {
  445. this.current_state[this.Root].push(this.Root_initializing);
  446. };
  447. MainApp.prototype.exit_Root_initializing = function() {
  448. this.current_state[this.Root] = new Array();
  449. };
  450. MainApp.prototype.enter_Root_creating = function() {
  451. this.current_state[this.Root].push(this.Root_creating);
  452. };
  453. MainApp.prototype.exit_Root_creating = function() {
  454. this.current_state[this.Root] = new Array();
  455. };
  456. MainApp.prototype.enter_Root_initialized = function() {
  457. this.current_state[this.Root].push(this.Root_initialized);
  458. };
  459. MainApp.prototype.exit_Root_initialized = function() {
  460. this.current_state[this.Root] = new Array();
  461. };
  462. // Statechart transitions :
  463. MainApp.prototype.transition_Root = function(event) {
  464. var catched = false;
  465. if (!catched) {
  466. if (this.current_state[this.Root][0] === this.Root_initializing) {
  467. catched = this.transition_Root_initializing(event);
  468. }
  469. else if (this.current_state[this.Root][0] === this.Root_creating) {
  470. catched = this.transition_Root_creating(event);
  471. }
  472. else if (this.current_state[this.Root][0] === this.Root_initialized) {
  473. catched = this.transition_Root_initialized(event);
  474. }
  475. }
  476. return catched;
  477. };
  478. MainApp.prototype.transition_Root_initializing = function(event) {
  479. var catched = false;
  480. var enableds = new Array();
  481. enableds.push(1);
  482. if (enableds.length > 1) {
  483. console.log("Runtime warning : indeterminism detected in a transition from node Root_initializing. Only the first in document order enabled transition is executed.")
  484. }
  485. if (enableds.length > 0) {
  486. var enabled = enableds[0];
  487. if (enabled === 1) {
  488. this.exit_Root_initializing();
  489. this.object_manager.addEvent(new Event("create_instance", null, [this, 'trafficlight','TrafficLight',this.canvas]));
  490. this.enter_Root_creating();
  491. }
  492. catched = true;
  493. }
  494. return catched;
  495. };
  496. MainApp.prototype.transition_Root_creating = function(event) {
  497. var catched = false;
  498. var enableds = new Array();
  499. if (event.name === "instance_created") {
  500. enableds.push(1);
  501. }
  502. if (enableds.length > 1) {
  503. console.log("Runtime warning : indeterminism detected in a transition from node Root_creating. Only the first in document order enabled transition is executed.")
  504. }
  505. if (enableds.length > 0) {
  506. var enabled = enableds[0];
  507. if (enabled === 1) {
  508. var parameters = event.parameters;
  509. var association_name = parameters[0];
  510. this.exit_Root_creating();
  511. var send_event = new Event("set_association_name", null, [association_name]);
  512. this.object_manager.addEvent(new Event("narrow_cast", null, [this, association_name , send_event]));
  513. this.object_manager.addEvent(new Event("start_instance", null, [this, association_name]));
  514. this.enter_Root_initialized();
  515. }
  516. catched = true;
  517. }
  518. return catched;
  519. };
  520. MainApp.prototype.transition_Root_initialized = function(event) {
  521. var catched = false;
  522. return catched;
  523. };
  524. // Execute transitions
  525. MainApp.prototype.transition = function(event) {
  526. if (!event) event = new Event();
  527. this.state_changed = this.transition_Root(event);
  528. };
  529. // inState method for statechart
  530. MainApp.prototype.inState = function(nodes) {
  531. for (var c in this.current_state) {
  532. if (!this.current_state.hasOwnProperty(c)) continue;
  533. var new_nodes = new Array();
  534. for (var n in nodes) {
  535. if (!nodes.hasOwnProperty(n)) continue;
  536. if (this.current_state[c].indexOf(nodes[n]) === -1) {
  537. new_nodes.push(nodes[n]);
  538. }
  539. }
  540. nodes = new_nodes;
  541. if (nodes.length === 0) {
  542. return true;
  543. }
  544. }
  545. return false;
  546. };
  547. MainApp.prototype.commonConstructor = function(controller) {
  548. if (!controller) controller = null;
  549. // Constructor part that is common for all constructors.
  550. RuntimeClassBase.call(this);
  551. // User defined input ports
  552. this.inports = new Object();
  553. this.controller = controller;
  554. this.object_manager = (controller == null ? null : controller.object_manager);
  555. this.current_state = new Object();
  556. this.history_state = new Object();
  557. // Initialize statechart
  558. this.current_state[this.Root] = new Array();
  559. };
  560. MainApp.prototype.start = function() {
  561. RuntimeClassBase.prototype.start.call(this);
  562. this.enter_Root_initializing();
  563. };
  564. // put class in global diagram object
  565. Traffic_Light.MainApp = MainApp;
  566. var ObjectManager = function(controller) {
  567. ObjectManagerBase.call(this, controller);
  568. };
  569. ObjectManager.prototype = new ObjectManagerBase();
  570. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  571. if (class_name === "TrafficLight") {
  572. var instance = new TrafficLight(this.controller, construct_params[0]);
  573. instance.associations = new Object();
  574. } else if (class_name === "MainApp") {
  575. var instance = new MainApp(this.controller);
  576. instance.associations = new Object();
  577. instance.associations["trafficlight"] = new Association("TrafficLight", 0, -1);
  578. }
  579. return instance;
  580. };
  581. // put in global diagram object
  582. Traffic_Light.ObjectManager = ObjectManager;
  583. var Controller = function(keep_running, finished_callback) {
  584. if (keep_running === undefined) keep_running = true;
  585. JsEventLoopControllerBase.call(this, new ObjectManager(this), keep_running, finished_callback);
  586. this.addInputPort("ui");
  587. this.object_manager.createInstance("MainApp", []);
  588. };
  589. Controller.prototype = new JsEventLoopControllerBase();
  590. // put in global diagram object
  591. Traffic_Light.Controller = Controller;
  592. })();