/* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)

Date:   Mon Aug 08 09:49:19 2016

Model author: Glenn De Jonghe
Model name:   TestMultipleTarget
Model description:
Testing the enter-exit sequence when having a transition that specificies a target state with multiple nodes.*/


// package "TestMultipleTarget"
var TestMultipleTarget = {};
(function() {

var Class1 = 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;
    
    // build Statechart structure
    this.build_statechart_structure();
    
    // call user defined constructor
    Class1.prototype.user_defined_constructor.call(this);
};
Class1.prototype = new Object();
(function() {
    var proto = new RuntimeClassBase();
    for (prop in proto) {
        Class1.prototype[prop] = proto[prop];
    }
})();

Class1.prototype.user_defined_constructor = function() {
};

Class1.prototype.user_defined_destructor = function() {
};


// builds Statechart structure
Class1.prototype.build_statechart_structure = function() {
    
    // state <root>
    this.states[""] = new State(0, this);
    
    // state /parallel
    this.states["/parallel"] = new ParallelState(1, this);
    
    // state /parallel/orthogonal_1
    this.states["/parallel/orthogonal_1"] = new State(2, this);
    
    // state /parallel/orthogonal_1/inner_1
    this.states["/parallel/orthogonal_1/inner_1"] = new State(3, this);
    this.states["/parallel/orthogonal_1/inner_1"].setEnter(this._parallel_orthogonal_1_inner_1_enter);
    
    // state /parallel/orthogonal_1/inner_2
    this.states["/parallel/orthogonal_1/inner_2"] = new State(4, this);
    this.states["/parallel/orthogonal_1/inner_2"].setEnter(this._parallel_orthogonal_1_inner_2_enter);
    
    // state /parallel/orthogonal_2
    this.states["/parallel/orthogonal_2"] = new State(5, this);
    
    // state /parallel/orthogonal_2/inner_1
    this.states["/parallel/orthogonal_2/inner_1"] = new State(6, this);
    this.states["/parallel/orthogonal_2/inner_1"].setEnter(this._parallel_orthogonal_2_inner_1_enter);
    
    // state /parallel/orthogonal_2/inner_2
    this.states["/parallel/orthogonal_2/inner_2"] = new State(7, this);
    this.states["/parallel/orthogonal_2/inner_2"].setEnter(this._parallel_orthogonal_2_inner_2_enter);
    
    // state /next_to_parallel
    this.states["/next_to_parallel"] = new State(8, this);
    this.states["/next_to_parallel"].setEnter(this._next_to_parallel_enter);
    
    // add children
    this.states[""].addChild(this.states["/parallel"]);
    this.states[""].addChild(this.states["/next_to_parallel"]);
    this.states["/parallel"].addChild(this.states["/parallel/orthogonal_1"]);
    this.states["/parallel"].addChild(this.states["/parallel/orthogonal_2"]);
    this.states["/parallel/orthogonal_1"].addChild(this.states["/parallel/orthogonal_1/inner_1"]);
    this.states["/parallel/orthogonal_1"].addChild(this.states["/parallel/orthogonal_1/inner_2"]);
    this.states["/parallel/orthogonal_2"].addChild(this.states["/parallel/orthogonal_2/inner_1"]);
    this.states["/parallel/orthogonal_2"].addChild(this.states["/parallel/orthogonal_2/inner_2"]);
    this.states[""].fixTree();
    this.states[""].default_state = this.states["/next_to_parallel"];
    this.states["/parallel/orthogonal_1"].default_state = this.states["/parallel/orthogonal_1/inner_1"];
    this.states["/parallel/orthogonal_2"].default_state = this.states["/parallel/orthogonal_2/inner_1"];
    
    // transition /next_to_parallel
    var _next_to_parallel_0 = new Transition(this, this.states["/next_to_parallel"], [this.states["/parallel/orthogonal_1/inner_2"], this.states["/parallel/orthogonal_2/inner_2"]]);
    _next_to_parallel_0.setTrigger(null);
    this.states["/next_to_parallel"].addTransition(_next_to_parallel_0);
};

Class1.prototype._parallel_orthogonal_1_inner_1_enter = function() {
    this.big_step.outputEvent(new Event("enter_1_1", "test_output", new Array()));
};

Class1.prototype._parallel_orthogonal_1_inner_2_enter = function() {
    this.big_step.outputEvent(new Event("enter_1_2", "test_output", new Array()));
};

Class1.prototype._parallel_orthogonal_2_inner_1_enter = function() {
    this.big_step.outputEvent(new Event("enter_2_1", "test_output", new Array()));
};

Class1.prototype._parallel_orthogonal_2_inner_2_enter = function() {
    this.big_step.outputEvent(new Event("enter_2_2", "test_output", new Array()));
};

Class1.prototype._next_to_parallel_enter = function() {
    this.big_step.outputEvent(new Event("enter_0", "test_output", new Array()));
};

Class1.prototype.initializeStatechart = function() {
    // enter default state
    var states = this.states["/next_to_parallel"].getEffectiveTargetStates();
    this.updateConfiguration(states);
    for (var state_idx in states) {
        if (!states.hasOwnProperty(state_idx)) continue;
        var state = states[state_idx]
        if (state.enter) {
            state.enter();
        }
    }
};

// add symbol 'Class1' to package 'TestMultipleTarget'
TestMultipleTarget.Class1 = Class1;

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 === "Class1") {
        var instance = new Class1(this.controller);
        instance.associations = new Object();
    } else  {
        throw new Error("Cannot instantiate class " + class_name);
    }
    return instance;
};

// add symbol 'ObjectManager' to package 'TestMultipleTarget'
TestMultipleTarget.ObjectManager = ObjectManager;

var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
    if (finished_callback === undefined) finished_callback = null;
    if (behind_schedule_callback === undefined) behind_schedule_callback = null;
    EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
    this.addInputPort("test_input");
    this.addOutputPort("test_output");
    this.object_manager.createInstance("Class1", 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 'TestMultipleTarget'
TestMultipleTarget.Controller = Controller;

var InputEvent = function(name, port, parameters, time_offset) {
    this.name = name;
    this.port = port;
    this.parameters = parameters;
    this.time_offset = time_offset;
};

// add symbol 'InputEvent' to package 'TestMultipleTarget'
TestMultipleTarget.InputEvent = InputEvent;

var Test = function() {
};
Test.prototype.input_events = new Array();
Test.prototype.expected_events = [[new Event("enter_0", "test_output", new Array())], [new Event("enter_1_2", "test_output", new Array()), new Event("enter_2_2", "test_output", new Array())]];

// add symbol 'Test' to package 'TestMultipleTarget'
TestMultipleTarget.Test = Test;
})();