/* Generated by Statechart compiler by Glenn De Jonghe and Joeri Exelmans Date: Tue Feb 16 09:43:52 2016 Model author: Simon Van Mierlo+Joeri Exelmans+Raphael Mannadiar Model name: Bouncing_Balls Model description: Tkinter frame with bouncing balls in it.*/ // package "Bouncing_Balls" var Bouncing_Balls = {}; (function() { var Button = function(controller, parent, event_name, button_text) { RuntimeClassBase.call(this, controller); this.semantics.big_step_maximality = StatechartSemantics.TakeMany; this.semantics.internal_event_lifeline = StatechartSemantics.Queue; this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep; this.semantics.priority = StatechartSemantics.SourceParent; this.semantics.concurrency = StatechartSemantics.Single; // Call user defined constructor Button.prototype.user_defined_constructor.call(this, parent, event_name, button_text); }; Button.prototype = new Object(); (function() { var proto = new RuntimeClassBase(); for (prop in proto) { Button.prototype[prop] = proto[prop]; } })(); Button.prototype.user_defined_constructor = function(parent, event_name, button_text) { this.event_name = event_name; var button = ui.append_button(parent.field_window, event_name); ui.bind_event(button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'mouse_click'); }; Button.prototype.user_defined_destructor = function() { }; Button.prototype.initializeStatechart = function() { this.current_state[this.Root] = new Array(); // Enter default state this.enter_Root_initializing(); }; // Unique IDs for all statechart nodes Button.prototype.Root = 0; Button.prototype.Root_initializing = 1; Button.prototype.Root_running = 2; // Statechart enter/exit action method(s) Button.prototype.enter_Root_initializing = function() { this.current_state[this.Root].push(this.Root_initializing); }; Button.prototype.exit_Root_initializing = function() { this.current_state[this.Root] = new Array(); }; Button.prototype.enter_Root_running = function() { this.current_state[this.Root].push(this.Root_running); }; Button.prototype.exit_Root_running = function() { this.current_state[this.Root] = new Array(); }; // Statechart transitions Button.prototype.generateCandidatesChildren_Root = function() { if (this.current_state[this.Root][0] === this.Root_initializing) { return this.generateCandidates_Root_initializing(); } else if (this.current_state[this.Root][0] === this.Root_running) { return this.generateCandidates_Root_running(); } return false; }; Button.prototype.generateCandidates_Root = function() { if (!this.combo_step.isArenaChanged(this.Root)) { return this.generateCandidatesChildren_Root(); } else { return true; } }; Button.prototype.generateCandidatesCurrent_Root_initializing = function() { var enabled_events = this.getEnabledEvents(); this.small_step.addCandidate(this.transition_Root_initializing_1, new Array()); return true; return false; }; Button.prototype.generateCandidates_Root_initializing = function() { if (!this.combo_step.isArenaChanged(this.Root_initializing)) { return this.generateCandidatesCurrent_Root_initializing(); } else { return true; } }; Button.prototype.transition_Root_initializing_1 = function(parameters) { this.exit_Root_initializing(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_created", null, new Array())])); this.combo_step.setArenaChanged(this.Root); this.enter_Root_running(); }; Button.prototype.generateCandidatesCurrent_Root_running = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "mouse_click") && (enabled_events[e].port === "ui")) { var parameters = enabled_events[e].parameters; var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; if (button == ui.MOUSE_BUTTONS.LEFT) { this.small_step.addCandidate(this.transition_Root_running_1, enabled_events[e].parameters); return true; } } } return false; }; Button.prototype.generateCandidates_Root_running = function() { if (!this.combo_step.isArenaChanged(this.Root_running)) { return this.generateCandidatesCurrent_Root_running(); } else { return true; } }; Button.prototype.transition_Root_running_1 = function(parameters) { var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; this.exit_Root_running(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [this.event_name])])); this.combo_step.setArenaChanged(this.Root); this.enter_Root_running(); }; // Generate transition candidates for current small step // Generate transition candidates for current small step Button.prototype.generateCandidates = function() { this.generateCandidates_Root(); }; // add symbol 'Button' to package 'Bouncing_Balls' Bouncing_Balls.Button = Button; var Field = function(controller) { RuntimeClassBase.call(this, controller); this.semantics.big_step_maximality = StatechartSemantics.TakeMany; this.semantics.internal_event_lifeline = StatechartSemantics.Queue; this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep; this.semantics.priority = StatechartSemantics.SourceParent; this.semantics.concurrency = StatechartSemantics.Single; this.inports["field_ui"] = controller.addInputPort("field_ui", this); // User defined attributes this.field_window = null; this.canvas = null; // Call user defined constructor Field.prototype.user_defined_constructor.call(this); }; Field.prototype = new Object(); (function() { var proto = new RuntimeClassBase(); for (prop in proto) { Field.prototype[prop] = proto[prop]; } })(); Field.prototype.user_defined_constructor = function() { this.field_window = ui.new_window(400, 450); this.canvas = ui.append_canvas(this.field_window, 400, 400, {'background':'#eee'}); ui.bind_event(this.field_window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close'); ui.bind_event(this.field_window, ui.EVENTS.KEY_PRESS, this.controller, 'key_press'); ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click', this.inports['field_ui']); ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_MOVE, this.controller, 'mouse_move'); ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RELEASE, this.controller, 'mouse_release'); }; Field.prototype.user_defined_destructor = function() { ui.close_window(this.field_window); }; Field.prototype.initializeStatechart = function() { this.current_state[this.Root] = new Array(); this.current_state[this.Root_root] = new Array(); this.current_state[this.Root_root_running] = new Array(); this.current_state[this.Root_root_running_main_behaviour] = new Array(); this.current_state[this.Root_root_running_deleting_behaviour] = new Array(); this.current_state[this.Root_root_running_child_behaviour] = new Array(); // Enter default state this.enterDefault_Root_root(); }; // Unique IDs for all statechart nodes Field.prototype.Root = 0; Field.prototype.Root_root = 1; Field.prototype.Root_root_running = 2; Field.prototype.Root_root_running_main_behaviour = 3; Field.prototype.Root_root_running_deleting_behaviour = 4; Field.prototype.Root_root_running_child_behaviour = 5; Field.prototype.Root_root_waiting = 6; Field.prototype.Root_root_packing = 7; Field.prototype.Root_root_deleting = 8; Field.prototype.Root_root_creating = 9; Field.prototype.Root_root_initializing = 10; Field.prototype.Root_root_deleted = 11; Field.prototype.Root_root_running_main_behaviour_running = 12; Field.prototype.Root_root_running_main_behaviour_creating = 13; Field.prototype.Root_root_running_deleting_behaviour_running = 14; Field.prototype.Root_root_running_child_behaviour_listening = 15; // Statechart enter/exit action method(s) Field.prototype.enter_Root_root = function() { this.current_state[this.Root].push(this.Root_root); }; Field.prototype.exit_Root_root = function() { if ((this.current_state[this.Root_root].indexOf(this.Root_root_waiting) !== -1)) { this.exit_Root_root_waiting(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_packing) !== -1)) { this.exit_Root_root_packing(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_deleting) !== -1)) { this.exit_Root_root_deleting(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_creating) !== -1)) { this.exit_Root_root_creating(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_initializing) !== -1)) { this.exit_Root_root_initializing(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_deleted) !== -1)) { this.exit_Root_root_deleted(); } if ((this.current_state[this.Root_root].indexOf(this.Root_root_running) !== -1)) { this.exit_Root_root_running(); } this.current_state[this.Root] = new Array(); }; Field.prototype.enter_Root_root_running = function() { this.current_state[this.Root_root].push(this.Root_root_running); }; Field.prototype.exit_Root_root_running = function() { this.exit_Root_root_running_main_behaviour(); this.exit_Root_root_running_deleting_behaviour(); this.exit_Root_root_running_child_behaviour(); this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_running_main_behaviour = function() { this.current_state[this.Root_root_running].push(this.Root_root_running_main_behaviour); }; Field.prototype.exit_Root_root_running_main_behaviour = function() { if ((this.current_state[this.Root_root_running_main_behaviour].indexOf(this.Root_root_running_main_behaviour_running) !== -1)) { this.exit_Root_root_running_main_behaviour_running(); } if ((this.current_state[this.Root_root_running_main_behaviour].indexOf(this.Root_root_running_main_behaviour_creating) !== -1)) { this.exit_Root_root_running_main_behaviour_creating(); } this.current_state[this.Root_root_running] = new Array(); }; Field.prototype.enter_Root_root_running_deleting_behaviour = function() { this.current_state[this.Root_root_running].push(this.Root_root_running_deleting_behaviour); }; Field.prototype.exit_Root_root_running_deleting_behaviour = function() { if ((this.current_state[this.Root_root_running_deleting_behaviour].indexOf(this.Root_root_running_deleting_behaviour_running) !== -1)) { this.exit_Root_root_running_deleting_behaviour_running(); } this.current_state[this.Root_root_running] = new Array(); }; Field.prototype.enter_Root_root_running_child_behaviour = function() { this.current_state[this.Root_root_running].push(this.Root_root_running_child_behaviour); }; Field.prototype.exit_Root_root_running_child_behaviour = function() { if ((this.current_state[this.Root_root_running_child_behaviour].indexOf(this.Root_root_running_child_behaviour_listening) !== -1)) { this.exit_Root_root_running_child_behaviour_listening(); } this.current_state[this.Root_root_running] = new Array(); }; Field.prototype.enter_Root_root_waiting = function() { this.current_state[this.Root_root].push(this.Root_root_waiting); }; Field.prototype.exit_Root_root_waiting = function() { this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_packing = function() { this.current_state[this.Root_root].push(this.Root_root_packing); }; Field.prototype.exit_Root_root_packing = function() { this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_deleting = function() { this.timers[0] = 0.05; this.current_state[this.Root_root].push(this.Root_root_deleting); }; Field.prototype.exit_Root_root_deleting = function() { delete this.timers[0]; this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_creating = function() { this.current_state[this.Root_root].push(this.Root_root_creating); }; Field.prototype.exit_Root_root_creating = function() { this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_initializing = function() { this.current_state[this.Root_root].push(this.Root_root_initializing); }; Field.prototype.exit_Root_root_initializing = function() { this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_deleted = function() { this.current_state[this.Root_root].push(this.Root_root_deleted); }; Field.prototype.exit_Root_root_deleted = function() { this.current_state[this.Root_root] = new Array(); }; Field.prototype.enter_Root_root_running_main_behaviour_running = function() { this.current_state[this.Root_root_running_main_behaviour].push(this.Root_root_running_main_behaviour_running); }; Field.prototype.exit_Root_root_running_main_behaviour_running = function() { this.current_state[this.Root_root_running_main_behaviour] = new Array(); }; Field.prototype.enter_Root_root_running_main_behaviour_creating = function() { this.current_state[this.Root_root_running_main_behaviour].push(this.Root_root_running_main_behaviour_creating); }; Field.prototype.exit_Root_root_running_main_behaviour_creating = function() { this.current_state[this.Root_root_running_main_behaviour] = new Array(); }; Field.prototype.enter_Root_root_running_deleting_behaviour_running = function() { this.current_state[this.Root_root_running_deleting_behaviour].push(this.Root_root_running_deleting_behaviour_running); }; Field.prototype.exit_Root_root_running_deleting_behaviour_running = function() { this.current_state[this.Root_root_running_deleting_behaviour] = new Array(); }; Field.prototype.enter_Root_root_running_child_behaviour_listening = function() { this.current_state[this.Root_root_running_child_behaviour].push(this.Root_root_running_child_behaviour_listening); }; Field.prototype.exit_Root_root_running_child_behaviour_listening = function() { this.current_state[this.Root_root_running_child_behaviour] = new Array(); }; // Statechart enter/exit default method(s) Field.prototype.enterDefault_Root_root = function() { this.enter_Root_root(); this.enter_Root_root_waiting(); }; Field.prototype.enterDefault_Root_root_running = function() { this.enter_Root_root_running(); this.enterDefault_Root_root_running_main_behaviour(); this.enterDefault_Root_root_running_deleting_behaviour(); this.enterDefault_Root_root_running_child_behaviour(); }; Field.prototype.enterDefault_Root_root_running_main_behaviour = function() { this.enter_Root_root_running_main_behaviour(); this.enter_Root_root_running_main_behaviour_running(); }; Field.prototype.enterDefault_Root_root_running_deleting_behaviour = function() { this.enter_Root_root_running_deleting_behaviour(); this.enter_Root_root_running_deleting_behaviour_running(); }; Field.prototype.enterDefault_Root_root_running_child_behaviour = function() { this.enter_Root_root_running_child_behaviour(); this.enter_Root_root_running_child_behaviour_listening(); }; // Statechart transitions Field.prototype.generateCandidatesChildren_Root = function() { if (this.current_state[this.Root][0] === this.Root_root) { return this.generateCandidates_Root_root(); } return false; }; Field.prototype.generateCandidates_Root = function() { if (!this.combo_step.isArenaChanged(this.Root)) { return this.generateCandidatesChildren_Root(); } else { return true; } }; Field.prototype.generateCandidatesChildren_Root_root = function() { if (this.current_state[this.Root_root][0] === this.Root_root_waiting) { return this.generateCandidates_Root_root_waiting(); } else if (this.current_state[this.Root_root][0] === this.Root_root_packing) { return this.generateCandidates_Root_root_packing(); } else if (this.current_state[this.Root_root][0] === this.Root_root_deleting) { return this.generateCandidates_Root_root_deleting(); } else if (this.current_state[this.Root_root][0] === this.Root_root_creating) { return this.generateCandidates_Root_root_creating(); } else if (this.current_state[this.Root_root][0] === this.Root_root_initializing) { return this.generateCandidates_Root_root_initializing(); } else if (this.current_state[this.Root_root][0] === this.Root_root_deleted) { return this.generateCandidates_Root_root_deleted(); } else if (this.current_state[this.Root_root][0] === this.Root_root_running) { return this.generateCandidates_Root_root_running(); } return false; }; Field.prototype.generateCandidates_Root_root = function() { if (!this.combo_step.isArenaChanged(this.Root_root)) { return this.generateCandidatesChildren_Root_root(); } else { return true; } }; Field.prototype.generateCandidatesCurrent_Root_root_waiting = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "set_association_name") { this.small_step.addCandidate(this.transition_Root_root_waiting_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_waiting = function() { if (!this.combo_step.isArenaChanged(this.Root_root_waiting)) { return this.generateCandidatesCurrent_Root_root_waiting(); } else { return true; } }; Field.prototype.transition_Root_root_waiting_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_root_waiting(); this.association_name = association_name; this.combo_step.setArenaChanged(this.Root_root); this.enter_Root_root_initializing(); }; Field.prototype.generateCandidatesCurrent_Root_root_packing = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "button_created") { this.small_step.addCandidate(this.transition_Root_root_packing_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_packing = function() { if (!this.combo_step.isArenaChanged(this.Root_root_packing)) { return this.generateCandidatesCurrent_Root_root_packing(); } else { return true; } }; Field.prototype.transition_Root_root_packing_1 = function(parameters) { this.exit_Root_root_packing(); this.combo_step.setArenaChanged(this.Root_root); this.enterDefault_Root_root_running(); }; Field.prototype.generateCandidatesCurrent_Root_root_deleting = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "_0after") { this.small_step.addCandidate(this.transition_Root_root_deleting_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_deleting = function() { if (!this.combo_step.isArenaChanged(this.Root_root_deleting)) { return this.generateCandidatesCurrent_Root_root_deleting(); } else { return true; } }; Field.prototype.transition_Root_root_deleting_1 = function(parameters) { this.exit_Root_root_deleting(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_field", null, [this.association_name])])); this.combo_step.setArenaChanged(this.Root_root); this.enter_Root_root_deleted(); }; Field.prototype.generateCandidatesCurrent_Root_root_creating = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "instance_created") { this.small_step.addCandidate(this.transition_Root_root_creating_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_creating = function() { if (!this.combo_step.isArenaChanged(this.Root_root_creating)) { return this.generateCandidatesCurrent_Root_root_creating(); } else { return true; } }; Field.prototype.transition_Root_root_creating_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_root_creating(); this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name])); this.combo_step.setArenaChanged(this.Root_root); this.enter_Root_root_packing(); }; Field.prototype.generateCandidatesCurrent_Root_root_initializing = function() { var enabled_events = this.getEnabledEvents(); this.small_step.addCandidate(this.transition_Root_root_initializing_1, new Array()); return true; return false; }; Field.prototype.generateCandidates_Root_root_initializing = function() { if (!this.combo_step.isArenaChanged(this.Root_root_initializing)) { return this.generateCandidatesCurrent_Root_root_initializing(); } else { return true; } }; Field.prototype.transition_Root_root_initializing_1 = function(parameters) { this.exit_Root_root_initializing(); this.big_step.outputEventOM(new Event("create_instance", null, [this, 'buttons', 'Button', this, 'create_new_field', 'Spawn New Window'])); this.combo_step.setArenaChanged(this.Root_root); this.enter_Root_root_creating(); }; Field.prototype.generateCandidates_Root_root_deleted = function() { return false; }; Field.prototype.generateCandidatesChildren_Root_root_running = function() { var branch_done = false; branch_done = (this.generateCandidates_Root_root_running_main_behaviour() || branch_done); branch_done = (this.generateCandidates_Root_root_running_deleting_behaviour() || branch_done); branch_done = (this.generateCandidates_Root_root_running_child_behaviour() || branch_done); return branch_done; }; Field.prototype.generateCandidatesCurrent_Root_root_running = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "window_close") && (enabled_events[e].port === "ui")) { var parameters = enabled_events[e].parameters; var window = parameters[0]; if (window == this.field_window || window == ui.window) { this.small_step.addCandidate(this.transition_Root_root_running_1, enabled_events[e].parameters); return true; } } } return false; }; Field.prototype.generateCandidates_Root_root_running = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running)) { var branch_done = false; if (this.semantics.priority === StatechartSemantics.SourceParent) { branch_done = this.generateCandidatesCurrent_Root_root_running(); if (!branch_done) { branch_done = this.generateCandidatesChildren_Root_root_running(); } } else if (this.semantics.priority === StatechartSemantics.SourceChild) { branch_done = this.generateCandidatesChildren_Root_root_running(); if (!branch_done) { branch_done = this.generateCandidatesCurrent_Root_root_running(); } } return branch_done; } else { return true; } }; Field.prototype.transition_Root_root_running_1 = function(parameters) { var window = parameters[0]; this.exit_Root_root_running(); this.big_step.outputEventOM(new Event("delete_instance", null, [this, 'buttons'])); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'balls', new Event("delete_self", null, new Array())])); this.combo_step.setArenaChanged(this.Root_root); this.enter_Root_root_deleting(); }; Field.prototype.generateCandidatesChildren_Root_root_running_main_behaviour = function() { if (this.current_state[this.Root_root_running_main_behaviour][0] === this.Root_root_running_main_behaviour_running) { return this.generateCandidates_Root_root_running_main_behaviour_running(); } else if (this.current_state[this.Root_root_running_main_behaviour][0] === this.Root_root_running_main_behaviour_creating) { return this.generateCandidates_Root_root_running_main_behaviour_creating(); } return false; }; Field.prototype.generateCandidates_Root_root_running_main_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour)) { return this.generateCandidatesChildren_Root_root_running_main_behaviour(); } else { return true; } }; Field.prototype.generateCandidatesCurrent_Root_root_running_main_behaviour_running = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "right_click") && (enabled_events[e].port === "field_ui")) { this.small_step.addCandidate(this.transition_Root_root_running_main_behaviour_running_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_running_main_behaviour_running = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour_running)) { return this.generateCandidatesCurrent_Root_root_running_main_behaviour_running(); } else { return true; } }; Field.prototype.transition_Root_root_running_main_behaviour_running_1 = function(parameters) { var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; this.exit_Root_root_running_main_behaviour_running(); this.big_step.outputEventOM(new Event("create_instance", null, [this, 'balls', 'Ball', this.canvas, x, y, this.field_window])); this.combo_step.setArenaChanged(this.Root_root_running_main_behaviour); this.enter_Root_root_running_main_behaviour_creating(); }; Field.prototype.generateCandidatesCurrent_Root_root_running_main_behaviour_creating = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "instance_created") { this.small_step.addCandidate(this.transition_Root_root_running_main_behaviour_creating_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_running_main_behaviour_creating = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_main_behaviour_creating)) { return this.generateCandidatesCurrent_Root_root_running_main_behaviour_creating(); } else { return true; } }; Field.prototype.transition_Root_root_running_main_behaviour_creating_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_root_running_main_behaviour_creating(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])])); this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name])); this.combo_step.setArenaChanged(this.Root_root_running_main_behaviour); this.enter_Root_root_running_main_behaviour_running(); }; Field.prototype.generateCandidatesChildren_Root_root_running_deleting_behaviour = function() { if (this.current_state[this.Root_root_running_deleting_behaviour][0] === this.Root_root_running_deleting_behaviour_running) { return this.generateCandidates_Root_root_running_deleting_behaviour_running(); } return false; }; Field.prototype.generateCandidates_Root_root_running_deleting_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_deleting_behaviour)) { return this.generateCandidatesChildren_Root_root_running_deleting_behaviour(); } else { return true; } }; Field.prototype.generateCandidatesCurrent_Root_root_running_deleting_behaviour_running = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "delete_ball") { this.small_step.addCandidate(this.transition_Root_root_running_deleting_behaviour_running_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_running_deleting_behaviour_running = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_deleting_behaviour_running)) { return this.generateCandidatesCurrent_Root_root_running_deleting_behaviour_running(); } else { return true; } }; Field.prototype.transition_Root_root_running_deleting_behaviour_running_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_root_running_deleting_behaviour_running(); this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name])); this.combo_step.setArenaChanged(this.Root_root_running_deleting_behaviour); this.enter_Root_root_running_deleting_behaviour_running(); }; Field.prototype.generateCandidatesChildren_Root_root_running_child_behaviour = function() { if (this.current_state[this.Root_root_running_child_behaviour][0] === this.Root_root_running_child_behaviour_listening) { return this.generateCandidates_Root_root_running_child_behaviour_listening(); } return false; }; Field.prototype.generateCandidates_Root_root_running_child_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_child_behaviour)) { return this.generateCandidatesChildren_Root_root_running_child_behaviour(); } else { return true; } }; Field.prototype.generateCandidatesCurrent_Root_root_running_child_behaviour_listening = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "button_pressed") { this.small_step.addCandidate(this.transition_Root_root_running_child_behaviour_listening_1, enabled_events[e].parameters); return true; } } return false; }; Field.prototype.generateCandidates_Root_root_running_child_behaviour_listening = function() { if (!this.combo_step.isArenaChanged(this.Root_root_running_child_behaviour_listening)) { return this.generateCandidatesCurrent_Root_root_running_child_behaviour_listening(); } else { return true; } }; Field.prototype.transition_Root_root_running_child_behaviour_listening_1 = function(parameters) { var event_name = parameters[0]; this.exit_Root_root_running_child_behaviour_listening(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [event_name])])); this.combo_step.setArenaChanged(this.Root_root_running_child_behaviour); this.enter_Root_root_running_child_behaviour_listening(); }; // Generate transition candidates for current small step // Generate transition candidates for current small step Field.prototype.generateCandidates = function() { this.generateCandidates_Root(); }; // add symbol 'Field' to package 'Bouncing_Balls' Bouncing_Balls.Field = Field; var MainApp = function(controller) { RuntimeClassBase.call(this, controller); this.semantics.big_step_maximality = StatechartSemantics.TakeMany; this.semantics.internal_event_lifeline = StatechartSemantics.Queue; this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep; this.semantics.priority = StatechartSemantics.SourceParent; this.semantics.concurrency = StatechartSemantics.Single; // Call user defined constructor MainApp.prototype.user_defined_constructor.call(this); }; MainApp.prototype = new Object(); (function() { var proto = new RuntimeClassBase(); for (prop in proto) { MainApp.prototype[prop] = proto[prop]; } })(); MainApp.prototype.user_defined_constructor = function() { this.nr_of_fields = 0; ui.bind_event(ui.window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close'); }; MainApp.prototype.user_defined_destructor = function() { }; MainApp.prototype.initializeStatechart = function() { this.current_state[this.Root] = new Array(); this.current_state[this.Root_running] = new Array(); this.current_state[this.Root_running_root] = new Array(); this.current_state[this.Root_running_root_main_behaviour] = new Array(); this.current_state[this.Root_running_root_cd_behaviour] = new Array(); // Enter default state this.enterDefault_Root_running(); }; // Unique IDs for all statechart nodes MainApp.prototype.Root = 0; MainApp.prototype.Root_running = 1; MainApp.prototype.Root_running_root = 2; MainApp.prototype.Root_running_root_main_behaviour = 3; MainApp.prototype.Root_running_root_cd_behaviour = 4; MainApp.prototype.Root_running_stopped = 5; MainApp.prototype.Root_running_root_main_behaviour_initializing = 6; MainApp.prototype.Root_running_root_main_behaviour_running = 7; MainApp.prototype.Root_running_root_cd_behaviour_creating = 8; MainApp.prototype.Root_running_root_cd_behaviour_waiting = 9; MainApp.prototype.Root_running_root_cd_behaviour_check_nr_of_fields = 10; // Statechart enter/exit action method(s) MainApp.prototype.enter_Root_running = function() { this.current_state[this.Root].push(this.Root_running); }; MainApp.prototype.exit_Root_running = function() { if ((this.current_state[this.Root_running].indexOf(this.Root_running_stopped) !== -1)) { this.exit_Root_running_stopped(); } if ((this.current_state[this.Root_running].indexOf(this.Root_running_root) !== -1)) { this.exit_Root_running_root(); } this.current_state[this.Root] = new Array(); }; MainApp.prototype.enter_Root_running_root = function() { this.current_state[this.Root_running].push(this.Root_running_root); }; MainApp.prototype.exit_Root_running_root = function() { this.exit_Root_running_root_main_behaviour(); this.exit_Root_running_root_cd_behaviour(); this.current_state[this.Root_running] = new Array(); }; MainApp.prototype.enter_Root_running_root_main_behaviour = function() { this.current_state[this.Root_running_root].push(this.Root_running_root_main_behaviour); }; MainApp.prototype.exit_Root_running_root_main_behaviour = function() { if ((this.current_state[this.Root_running_root_main_behaviour].indexOf(this.Root_running_root_main_behaviour_initializing) !== -1)) { this.exit_Root_running_root_main_behaviour_initializing(); } if ((this.current_state[this.Root_running_root_main_behaviour].indexOf(this.Root_running_root_main_behaviour_running) !== -1)) { this.exit_Root_running_root_main_behaviour_running(); } this.current_state[this.Root_running_root] = new Array(); }; MainApp.prototype.enter_Root_running_root_cd_behaviour = function() { this.current_state[this.Root_running_root].push(this.Root_running_root_cd_behaviour); }; MainApp.prototype.exit_Root_running_root_cd_behaviour = function() { if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_creating) !== -1)) { this.exit_Root_running_root_cd_behaviour_creating(); } if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_waiting) !== -1)) { this.exit_Root_running_root_cd_behaviour_waiting(); } if ((this.current_state[this.Root_running_root_cd_behaviour].indexOf(this.Root_running_root_cd_behaviour_check_nr_of_fields) !== -1)) { this.exit_Root_running_root_cd_behaviour_check_nr_of_fields(); } this.current_state[this.Root_running_root] = new Array(); }; MainApp.prototype.enter_Root_running_stopped = function() { this.current_state[this.Root_running].push(this.Root_running_stopped); }; MainApp.prototype.exit_Root_running_stopped = function() { this.current_state[this.Root_running] = new Array(); }; MainApp.prototype.enter_Root_running_root_main_behaviour_initializing = function() { this.current_state[this.Root_running_root_main_behaviour].push(this.Root_running_root_main_behaviour_initializing); }; MainApp.prototype.exit_Root_running_root_main_behaviour_initializing = function() { this.current_state[this.Root_running_root_main_behaviour] = new Array(); }; MainApp.prototype.enter_Root_running_root_main_behaviour_running = function() { this.current_state[this.Root_running_root_main_behaviour].push(this.Root_running_root_main_behaviour_running); }; MainApp.prototype.exit_Root_running_root_main_behaviour_running = function() { this.current_state[this.Root_running_root_main_behaviour] = new Array(); }; MainApp.prototype.enter_Root_running_root_cd_behaviour_creating = function() { this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_creating); }; MainApp.prototype.exit_Root_running_root_cd_behaviour_creating = function() { this.current_state[this.Root_running_root_cd_behaviour] = new Array(); }; MainApp.prototype.enter_Root_running_root_cd_behaviour_waiting = function() { this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_waiting); }; MainApp.prototype.exit_Root_running_root_cd_behaviour_waiting = function() { this.current_state[this.Root_running_root_cd_behaviour] = new Array(); }; MainApp.prototype.enter_Root_running_root_cd_behaviour_check_nr_of_fields = function() { this.current_state[this.Root_running_root_cd_behaviour].push(this.Root_running_root_cd_behaviour_check_nr_of_fields); }; MainApp.prototype.exit_Root_running_root_cd_behaviour_check_nr_of_fields = function() { this.current_state[this.Root_running_root_cd_behaviour] = new Array(); }; // Statechart enter/exit default method(s) MainApp.prototype.enterDefault_Root_running = function() { this.enter_Root_running(); this.enterDefault_Root_running_root(); }; MainApp.prototype.enterDefault_Root_running_root = function() { this.enter_Root_running_root(); this.enterDefault_Root_running_root_main_behaviour(); this.enterDefault_Root_running_root_cd_behaviour(); }; MainApp.prototype.enterDefault_Root_running_root_main_behaviour = function() { this.enter_Root_running_root_main_behaviour(); this.enter_Root_running_root_main_behaviour_initializing(); }; MainApp.prototype.enterDefault_Root_running_root_cd_behaviour = function() { this.enter_Root_running_root_cd_behaviour(); this.enter_Root_running_root_cd_behaviour_waiting(); }; // Statechart transitions MainApp.prototype.generateCandidatesChildren_Root = function() { if (this.current_state[this.Root][0] === this.Root_running) { return this.generateCandidates_Root_running(); } return false; }; MainApp.prototype.generateCandidates_Root = function() { if (!this.combo_step.isArenaChanged(this.Root)) { return this.generateCandidatesChildren_Root(); } else { return true; } }; MainApp.prototype.generateCandidatesChildren_Root_running = function() { if (this.current_state[this.Root_running][0] === this.Root_running_stopped) { return this.generateCandidates_Root_running_stopped(); } else if (this.current_state[this.Root_running][0] === this.Root_running_root) { return this.generateCandidates_Root_running_root(); } return false; }; MainApp.prototype.generateCandidates_Root_running = function() { if (!this.combo_step.isArenaChanged(this.Root_running)) { return this.generateCandidatesChildren_Root_running(); } else { return true; } }; MainApp.prototype.generateCandidates_Root_running_stopped = function() { return false; }; MainApp.prototype.generateCandidatesChildren_Root_running_root = function() { var branch_done = false; branch_done = (this.generateCandidates_Root_running_root_main_behaviour() || branch_done); branch_done = (this.generateCandidates_Root_running_root_cd_behaviour() || branch_done); return branch_done; }; MainApp.prototype.generateCandidates_Root_running_root = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root)) { return this.generateCandidatesChildren_Root_running_root(); } else { return true; } }; MainApp.prototype.generateCandidatesChildren_Root_running_root_main_behaviour = function() { if (this.current_state[this.Root_running_root_main_behaviour][0] === this.Root_running_root_main_behaviour_initializing) { return this.generateCandidates_Root_running_root_main_behaviour_initializing(); } else if (this.current_state[this.Root_running_root_main_behaviour][0] === this.Root_running_root_main_behaviour_running) { return this.generateCandidates_Root_running_root_main_behaviour_running(); } return false; }; MainApp.prototype.generateCandidates_Root_running_root_main_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour)) { return this.generateCandidatesChildren_Root_running_root_main_behaviour(); } else { return true; } }; MainApp.prototype.generateCandidatesCurrent_Root_running_root_main_behaviour_initializing = function() { var enabled_events = this.getEnabledEvents(); this.small_step.addCandidate(this.transition_Root_running_root_main_behaviour_initializing_1, new Array()); return true; return false; }; MainApp.prototype.generateCandidates_Root_running_root_main_behaviour_initializing = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour_initializing)) { return this.generateCandidatesCurrent_Root_running_root_main_behaviour_initializing(); } else { return true; } }; MainApp.prototype.transition_Root_running_root_main_behaviour_initializing_1 = function(parameters) { this.exit_Root_running_root_main_behaviour_initializing(); this.raiseInternalEvent(new Event("create_field", null, new Array())); this.combo_step.setArenaChanged(this.Root_running_root_main_behaviour); this.enter_Root_running_root_main_behaviour_running(); }; MainApp.prototype.generateCandidatesCurrent_Root_running_root_main_behaviour_running = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "button_pressed") { var parameters = enabled_events[e].parameters; var event_name = parameters[0]; if (event_name == 'create_new_field') { this.small_step.addCandidate(this.transition_Root_running_root_main_behaviour_running_1, enabled_events[e].parameters); return true; } } } return false; }; MainApp.prototype.generateCandidates_Root_running_root_main_behaviour_running = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_main_behaviour_running)) { return this.generateCandidatesCurrent_Root_running_root_main_behaviour_running(); } else { return true; } }; MainApp.prototype.transition_Root_running_root_main_behaviour_running_1 = function(parameters) { var event_name = parameters[0]; this.exit_Root_running_root_main_behaviour_running(); this.raiseInternalEvent(new Event("create_field", null, new Array())); this.combo_step.setArenaChanged(this.Root_running_root_main_behaviour); this.enter_Root_running_root_main_behaviour_running(); }; MainApp.prototype.generateCandidatesChildren_Root_running_root_cd_behaviour = function() { if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_creating) { return this.generateCandidates_Root_running_root_cd_behaviour_creating(); } else if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_waiting) { return this.generateCandidates_Root_running_root_cd_behaviour_waiting(); } else if (this.current_state[this.Root_running_root_cd_behaviour][0] === this.Root_running_root_cd_behaviour_check_nr_of_fields) { return this.generateCandidates_Root_running_root_cd_behaviour_check_nr_of_fields(); } return false; }; MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour)) { return this.generateCandidatesChildren_Root_running_root_cd_behaviour(); } else { return true; } }; MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_creating = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "instance_created") { this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_creating_1, enabled_events[e].parameters); return true; } } return false; }; MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_creating = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_creating)) { return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_creating(); } else { return true; } }; MainApp.prototype.transition_Root_running_root_cd_behaviour_creating_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_running_root_cd_behaviour_creating(); this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name])); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])])); this.nr_of_fields += 1; this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour); this.enter_Root_running_root_cd_behaviour_waiting(); }; MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_waiting = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "create_field") { this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_waiting_1, enabled_events[e].parameters); return true; } } var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "delete_field") { this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_waiting_2, enabled_events[e].parameters); return true; } } return false; }; MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_waiting = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_waiting)) { return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_waiting(); } else { return true; } }; MainApp.prototype.transition_Root_running_root_cd_behaviour_waiting_1 = function(parameters) { this.exit_Root_running_root_cd_behaviour_waiting(); this.big_step.outputEventOM(new Event("create_instance", null, [this, 'fields'])); this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour); this.enter_Root_running_root_cd_behaviour_creating(); }; MainApp.prototype.transition_Root_running_root_cd_behaviour_waiting_2 = function(parameters) { var association_name = parameters[0]; this.exit_Root_running_root_cd_behaviour_waiting(); this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name])); this.nr_of_fields -= 1; this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour); this.enter_Root_running_root_cd_behaviour_check_nr_of_fields(); }; MainApp.prototype.generateCandidatesCurrent_Root_running_root_cd_behaviour_check_nr_of_fields = function() { var enabled_events = this.getEnabledEvents(); if (this.nr_of_fields != 0) { this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_check_nr_of_fields_1, new Array()); return true; } var enabled_events = this.getEnabledEvents(); if (this.nr_of_fields == 0) { this.small_step.addCandidate(this.transition_Root_running_root_cd_behaviour_check_nr_of_fields_2, new Array()); return true; } return false; }; MainApp.prototype.generateCandidates_Root_running_root_cd_behaviour_check_nr_of_fields = function() { if (!this.combo_step.isArenaChanged(this.Root_running_root_cd_behaviour_check_nr_of_fields)) { return this.generateCandidatesCurrent_Root_running_root_cd_behaviour_check_nr_of_fields(); } else { return true; } }; MainApp.prototype.transition_Root_running_root_cd_behaviour_check_nr_of_fields_1 = function(parameters) { this.exit_Root_running_root_cd_behaviour_check_nr_of_fields(); this.combo_step.setArenaChanged(this.Root_running_root_cd_behaviour); this.enter_Root_running_root_cd_behaviour_waiting(); }; MainApp.prototype.transition_Root_running_root_cd_behaviour_check_nr_of_fields_2 = function(parameters) { this.exit_Root_running_root(); ui.close_window(ui.window); this.combo_step.setArenaChanged(this.Root_running); this.enter_Root_running_stopped(); }; // Generate transition candidates for current small step // Generate transition candidates for current small step MainApp.prototype.generateCandidates = function() { this.generateCandidates_Root(); }; // add symbol 'MainApp' to package 'Bouncing_Balls' Bouncing_Balls.MainApp = MainApp; var Ball = function(controller, canvas, x, y, field_window) { RuntimeClassBase.call(this, controller); this.semantics.big_step_maximality = StatechartSemantics.TakeMany; this.semantics.internal_event_lifeline = StatechartSemantics.Queue; this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep; this.semantics.priority = StatechartSemantics.SourceParent; this.semantics.concurrency = StatechartSemantics.Single; this.inports["ball_ui"] = controller.addInputPort("ball_ui", this); // User defined attributes this.field_window = null; this.canvas = null; this.element = null; // Call user defined constructor Ball.prototype.user_defined_constructor.call(this, canvas, x, y, field_window); }; Ball.prototype = new Object(); (function() { var proto = new RuntimeClassBase(); for (prop in proto) { Ball.prototype[prop] = proto[prop]; } })(); Ball.prototype.user_defined_constructor = function(canvas, x, y, field_window) { this.canvas = canvas; this.field_window = field_window; this.r = 20.0; this.vel = {'x':utils.random() * 2.0 - 1.0, 'y':utils.random() * 2.0 - 1.0}; this.mouse_pos = {'':''}; this.smooth = 0.4; var circle = this.canvas.add_circle(x, y, this.r, {'fill':'#000'}); ui.bind_event(circle, ui.EVENTS.MOUSE_PRESS, this.controller, 'mouse_press', this.inports['ball_ui']); ui.bind_event(circle, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click'); this.element = circle; }; Ball.prototype.user_defined_destructor = function() { this.canvas.remove_element(this.element); }; Ball.prototype.initializeStatechart = function() { this.current_state[this.Root] = new Array(); this.current_state[this.Root_main_behaviour] = new Array(); // Enter default state this.enterDefault_Root_main_behaviour(); }; // Unique IDs for all statechart nodes Ball.prototype.Root = 0; Ball.prototype.Root_main_behaviour = 1; Ball.prototype.Root_main_behaviour_dragging = 2; Ball.prototype.Root_main_behaviour_selected = 3; Ball.prototype.Root_main_behaviour_initializing = 4; Ball.prototype.Root_main_behaviour_bouncing = 5; Ball.prototype.Root_deleted = 6; // Statechart enter/exit action method(s) Ball.prototype.enter_Root_main_behaviour = function() { this.current_state[this.Root].push(this.Root_main_behaviour); }; Ball.prototype.exit_Root_main_behaviour = function() { if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_dragging) !== -1)) { this.exit_Root_main_behaviour_dragging(); } if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_selected) !== -1)) { this.exit_Root_main_behaviour_selected(); } if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_initializing) !== -1)) { this.exit_Root_main_behaviour_initializing(); } if ((this.current_state[this.Root_main_behaviour].indexOf(this.Root_main_behaviour_bouncing) !== -1)) { this.exit_Root_main_behaviour_bouncing(); } this.current_state[this.Root] = new Array(); }; Ball.prototype.enter_Root_main_behaviour_dragging = function() { this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_dragging); }; Ball.prototype.exit_Root_main_behaviour_dragging = function() { this.current_state[this.Root_main_behaviour] = new Array(); }; Ball.prototype.enter_Root_main_behaviour_selected = function() { this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_selected); }; Ball.prototype.exit_Root_main_behaviour_selected = function() { this.current_state[this.Root_main_behaviour] = new Array(); }; Ball.prototype.enter_Root_main_behaviour_initializing = function() { this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_initializing); }; Ball.prototype.exit_Root_main_behaviour_initializing = function() { this.current_state[this.Root_main_behaviour] = new Array(); }; Ball.prototype.enter_Root_main_behaviour_bouncing = function() { this.timers[0] = 0.01; this.current_state[this.Root_main_behaviour].push(this.Root_main_behaviour_bouncing); }; Ball.prototype.exit_Root_main_behaviour_bouncing = function() { delete this.timers[0]; this.current_state[this.Root_main_behaviour] = new Array(); }; Ball.prototype.enter_Root_deleted = function() { this.current_state[this.Root].push(this.Root_deleted); }; Ball.prototype.exit_Root_deleted = function() { this.current_state[this.Root] = new Array(); }; // Statechart enter/exit default method(s) Ball.prototype.enterDefault_Root_main_behaviour = function() { this.enter_Root_main_behaviour(); this.enter_Root_main_behaviour_initializing(); }; // Statechart transitions Ball.prototype.generateCandidatesChildren_Root = function() { if (this.current_state[this.Root][0] === this.Root_main_behaviour) { return this.generateCandidates_Root_main_behaviour(); } else if (this.current_state[this.Root][0] === this.Root_deleted) { return this.generateCandidates_Root_deleted(); } return false; }; Ball.prototype.generateCandidates_Root = function() { if (!this.combo_step.isArenaChanged(this.Root)) { return this.generateCandidatesChildren_Root(); } else { return true; } }; Ball.prototype.generateCandidatesChildren_Root_main_behaviour = function() { if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_dragging) { return this.generateCandidates_Root_main_behaviour_dragging(); } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_selected) { return this.generateCandidates_Root_main_behaviour_selected(); } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_initializing) { return this.generateCandidates_Root_main_behaviour_initializing(); } else if (this.current_state[this.Root_main_behaviour][0] === this.Root_main_behaviour_bouncing) { return this.generateCandidates_Root_main_behaviour_bouncing(); } return false; }; Ball.prototype.generateCandidatesCurrent_Root_main_behaviour = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "delete_self") { this.small_step.addCandidate(this.transition_Root_main_behaviour_1, enabled_events[e].parameters); return true; } } return false; }; Ball.prototype.generateCandidates_Root_main_behaviour = function() { if (!this.combo_step.isArenaChanged(this.Root_main_behaviour)) { var branch_done = false; if (this.semantics.priority === StatechartSemantics.SourceParent) { branch_done = this.generateCandidatesCurrent_Root_main_behaviour(); if (!branch_done) { branch_done = this.generateCandidatesChildren_Root_main_behaviour(); } } else if (this.semantics.priority === StatechartSemantics.SourceChild) { branch_done = this.generateCandidatesChildren_Root_main_behaviour(); if (!branch_done) { branch_done = this.generateCandidatesCurrent_Root_main_behaviour(); } } return branch_done; } else { return true; } }; Ball.prototype.transition_Root_main_behaviour_1 = function(parameters) { this.exit_Root_main_behaviour(); this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_ball", null, [this.association_name])])); this.combo_step.setArenaChanged(this.Root); this.enter_Root_deleted(); }; Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_dragging = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "mouse_release") && (enabled_events[e].port === "ui")) { this.small_step.addCandidate(this.transition_Root_main_behaviour_dragging_1, enabled_events[e].parameters); return true; } } var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "mouse_move") && (enabled_events[e].port === "ui")) { this.small_step.addCandidate(this.transition_Root_main_behaviour_dragging_2, enabled_events[e].parameters); return true; } } return false; }; Ball.prototype.generateCandidates_Root_main_behaviour_dragging = function() { if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_dragging)) { return this.generateCandidatesCurrent_Root_main_behaviour_dragging(); } else { return true; } }; Ball.prototype.transition_Root_main_behaviour_dragging_1 = function(parameters) { var x = parameters[0]; var y = parameters[1]; this.exit_Root_main_behaviour_dragging(); this.element.set_color('#f00'); this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_bouncing(); }; Ball.prototype.transition_Root_main_behaviour_dragging_2 = function(parameters) { var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; this.exit_Root_main_behaviour_dragging(); var dx = x - this.mouse_pos['x']; var dy = y - this.mouse_pos['y']; this.element.move(dx, dy); var pos = this.element.get_position(); if(pos.x - this.r <= 0) { pos.x = this.r + 1; } else { if(pos.x + this.r >= this.canvas.width) { pos.x = this.canvas.width - this.r - 1; } } if(pos.y - this.r <= 0) { pos.y = this.r + 1; } else { if(pos.y + this.r >= this.canvas.height) { pos.y = this.canvas.height - this.r - 1; } } this.element.set_position(pos.x, pos.y); this.mouse_pos = {'x':x, 'y':y}; this.vel = {'x':(1 - this.smooth) * dx + this.smooth * this.vel['x'], 'y':(1 - this.smooth) * dy + this.smooth * this.vel['y']}; this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_dragging(); }; Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_selected = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "mouse_press") && (enabled_events[e].port === "ball_ui")) { var parameters = enabled_events[e].parameters; var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; if (button == ui.MOUSE_BUTTONS.LEFT) { this.small_step.addCandidate(this.transition_Root_main_behaviour_selected_1, enabled_events[e].parameters); return true; } } } var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "key_press") && (enabled_events[e].port === "ui")) { var parameters = enabled_events[e].parameters; var key = parameters[0]; var active_window = parameters[1]; if (key == ui.KEYCODES.DELETE && active_window == this.field_window) { this.small_step.addCandidate(this.transition_Root_main_behaviour_selected_2, enabled_events[e].parameters); return true; } } } return false; }; Ball.prototype.generateCandidates_Root_main_behaviour_selected = function() { if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_selected)) { return this.generateCandidatesCurrent_Root_main_behaviour_selected(); } else { return true; } }; Ball.prototype.transition_Root_main_behaviour_selected_1 = function(parameters) { var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; this.exit_Root_main_behaviour_selected(); this.mouse_pos = {'x':x, 'y':y}; this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_dragging(); }; Ball.prototype.transition_Root_main_behaviour_selected_2 = function(parameters) { var key = parameters[0]; var active_window = parameters[1]; this.exit_Root_main_behaviour_selected(); this.raiseInternalEvent(new Event("delete_self", null, new Array())); this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_selected(); }; Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_initializing = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "set_association_name") { this.small_step.addCandidate(this.transition_Root_main_behaviour_initializing_1, enabled_events[e].parameters); return true; } } return false; }; Ball.prototype.generateCandidates_Root_main_behaviour_initializing = function() { if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_initializing)) { return this.generateCandidatesCurrent_Root_main_behaviour_initializing(); } else { return true; } }; Ball.prototype.transition_Root_main_behaviour_initializing_1 = function(parameters) { var association_name = parameters[0]; this.exit_Root_main_behaviour_initializing(); this.association_name = association_name; this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_bouncing(); }; Ball.prototype.generateCandidatesCurrent_Root_main_behaviour_bouncing = function() { var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if (enabled_events[e].name === "_0after") { this.small_step.addCandidate(this.transition_Root_main_behaviour_bouncing_1, enabled_events[e].parameters); return true; } } var enabled_events = this.getEnabledEvents(); for (var e in enabled_events) { if (!enabled_events.hasOwnProperty(e)) continue; if ((enabled_events[e].name === "mouse_press") && (enabled_events[e].port === "ball_ui")) { var parameters = enabled_events[e].parameters; var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; if (button == ui.MOUSE_BUTTONS.LEFT) { this.small_step.addCandidate(this.transition_Root_main_behaviour_bouncing_2, enabled_events[e].parameters); return true; } } } return false; }; Ball.prototype.generateCandidates_Root_main_behaviour_bouncing = function() { if (!this.combo_step.isArenaChanged(this.Root_main_behaviour_bouncing)) { return this.generateCandidatesCurrent_Root_main_behaviour_bouncing(); } else { return true; } }; Ball.prototype.transition_Root_main_behaviour_bouncing_1 = function(parameters) { this.exit_Root_main_behaviour_bouncing(); var pos = this.element.get_position(); if(pos.x - this.r <= 0 || pos.x + this.r >= this.canvas.width) { this.vel['x'] = -this.vel['x']; } if(pos.y - this.r <= 0 || pos.y + this.r >= this.canvas.height) { this.vel['y'] = -this.vel['y']; } this.element.move(this.vel['x'], this.vel['y']); this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_bouncing(); }; Ball.prototype.transition_Root_main_behaviour_bouncing_2 = function(parameters) { var x = parameters[0]; var y = parameters[1]; var button = parameters[2]; this.exit_Root_main_behaviour_bouncing(); this.element.set_color('#ff0'); this.combo_step.setArenaChanged(this.Root_main_behaviour); this.enter_Root_main_behaviour_selected(); }; Ball.prototype.generateCandidates_Root_deleted = function() { return false; }; // Generate transition candidates for current small step // Generate transition candidates for current small step Ball.prototype.generateCandidates = function() { this.generateCandidates_Root(); }; // add symbol 'Ball' to package 'Bouncing_Balls' Bouncing_Balls.Ball = Ball; var ObjectManager = function(controller) { ObjectManagerBase.call(this, controller); }; ObjectManager.prototype = new Object(); (function() { var proto = new ObjectManagerBase(); for (prop in proto) { ObjectManager.prototype[prop] = proto[prop]; } })(); ObjectManager.prototype.instantiate = function(class_name, construct_params) { if (class_name === "Button") { var instance = new Button(this.controller, construct_params[0], construct_params[1], construct_params[2]); instance.associations = new Object(); instance.associations["parent"] = new Association("Field", 1, 1); } else if (class_name === "Field") { var instance = new Field(this.controller); instance.associations = new Object(); instance.associations["parent"] = new Association("MainApp", 1, 1); instance.associations["buttons"] = new Association("Button", 0, -1); instance.associations["balls"] = new Association("Ball", 0, -1); } else if (class_name === "MainApp") { var instance = new MainApp(this.controller); instance.associations = new Object(); instance.associations["fields"] = new Association("Field", 0, -1); } else if (class_name === "Ball") { var instance = new Ball(this.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3]); instance.associations = new Object(); instance.associations["parent"] = new Association("Field", 1, 1); } return instance; }; // add symbol 'ObjectManager' to package 'Bouncing_Balls' Bouncing_Balls.ObjectManager = ObjectManager; var Controller = function(event_loop_callbacks, finished_callback) { if (finished_callback === undefined) finished_callback = null; EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback); this.addInputPort("field_ui"); this.addInputPort("ball_ui"); this.addInputPort("input"); this.object_manager.createInstance("MainApp", new Array()); }; Controller.prototype = new Object(); (function() { var proto = new EventLoopControllerBase(); for (prop in proto) { Controller.prototype[prop] = proto[prop]; } })(); // add symbol 'Controller' to package 'Bouncing_Balls' Bouncing_Balls.Controller = Controller; })();