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

Date:   Wed Aug 03 16:10:20 2016

Model author: Glenn De Jonghe
Model name:   TestParallelHistory2
Model description:
Testing history where the history state is directly inside a parallel element (shallow).*/


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

var TestClass = 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
    TestClass.prototype.user_defined_constructor.call(this);
};
TestClass.prototype = new Object();
(function() {
    var proto = new RuntimeClassBase();
    for (prop in proto) {
        TestClass.prototype[prop] = proto[prop];
    }
})();

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

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


// builds Statechart structure
TestClass.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/orthogonal_inner_1
    this.states["/parallel/orthogonal_1/orthogonal_inner_1"] = new State(3, this);
    
    // state /parallel/orthogonal_1/orthogonal_inner_1/state_1
    this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"] = new State(4, this);
    this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"].setEnter(this._parallel_orthogonal_1_orthogonal_inner_1_state_1_enter);
    
    // state /parallel/orthogonal_1/orthogonal_inner_1/state_2
    this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_2"] = new State(5, this);
    this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_2"].setEnter(this._parallel_orthogonal_1_orthogonal_inner_1_state_2_enter);
    
    // state /parallel/orthogonal_1/outer_1
    this.states["/parallel/orthogonal_1/outer_1"] = new State(6, this);
    this.states["/parallel/orthogonal_1/outer_1"].setEnter(this._parallel_orthogonal_1_outer_1_enter);
    
    // state /parallel/orthogonal_2
    this.states["/parallel/orthogonal_2"] = new State(7, this);
    
    // state /parallel/orthogonal_2/orthogonal_inner_2
    this.states["/parallel/orthogonal_2/orthogonal_inner_2"] = new State(8, this);
    
    // state /parallel/orthogonal_2/orthogonal_inner_2/state_3
    this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"] = new State(9, this);
    this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"].setEnter(this._parallel_orthogonal_2_orthogonal_inner_2_state_3_enter);
    
    // state /parallel/orthogonal_2/orthogonal_inner_2/state_4
    this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_4"] = new State(10, this);
    this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_4"].setEnter(this._parallel_orthogonal_2_orthogonal_inner_2_state_4_enter);
    
    // state /parallel/orthogonal_2/outer_2
    this.states["/parallel/orthogonal_2/outer_2"] = new State(11, this);
    this.states["/parallel/orthogonal_2/outer_2"].setEnter(this._parallel_orthogonal_2_outer_2_enter);
    
    // state /parallel/history_1
    this.states["/parallel/history_1"] = new ShallowHistoryState(12, this);
    
    // state /next_to_parallel
    this.states["/next_to_parallel"] = new State(13, 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"].addChild(this.states["/parallel/history_1"]);
    this.states["/parallel/orthogonal_1"].addChild(this.states["/parallel/orthogonal_1/orthogonal_inner_1"]);
    this.states["/parallel/orthogonal_1"].addChild(this.states["/parallel/orthogonal_1/outer_1"]);
    this.states["/parallel/orthogonal_1/orthogonal_inner_1"].addChild(this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"]);
    this.states["/parallel/orthogonal_1/orthogonal_inner_1"].addChild(this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_2"]);
    this.states["/parallel/orthogonal_2"].addChild(this.states["/parallel/orthogonal_2/orthogonal_inner_2"]);
    this.states["/parallel/orthogonal_2"].addChild(this.states["/parallel/orthogonal_2/outer_2"]);
    this.states["/parallel/orthogonal_2/orthogonal_inner_2"].addChild(this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"]);
    this.states["/parallel/orthogonal_2/orthogonal_inner_2"].addChild(this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_4"]);
    this.states[""].fixTree();
    this.states[""].default_state = this.states["/parallel"];
    this.states["/parallel/orthogonal_1"].default_state = this.states["/parallel/orthogonal_1/orthogonal_inner_1"];
    this.states["/parallel/orthogonal_1/orthogonal_inner_1"].default_state = this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"];
    this.states["/parallel/orthogonal_2"].default_state = this.states["/parallel/orthogonal_2/orthogonal_inner_2"];
    this.states["/parallel/orthogonal_2/orthogonal_inner_2"].default_state = this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"];
    
    // transition /parallel/orthogonal_1/orthogonal_inner_1/state_1
    var _parallel_orthogonal_1_orthogonal_inner_1_state_1_0 = new Transition(this, this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"], [this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_2"]]);
    _parallel_orthogonal_1_orthogonal_inner_1_state_1_0.trigger = new Event("to_state_2", "test_input");
    this.states["/parallel/orthogonal_1/orthogonal_inner_1/state_1"].addTransition(_parallel_orthogonal_1_orthogonal_inner_1_state_1_0);
    
    // transition /parallel/orthogonal_2/orthogonal_inner_2/state_3
    var _parallel_orthogonal_2_orthogonal_inner_2_state_3_0 = new Transition(this, this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"], [this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_4"]]);
    _parallel_orthogonal_2_orthogonal_inner_2_state_3_0.trigger = new Event("to_state_4", "test_input");
    this.states["/parallel/orthogonal_2/orthogonal_inner_2/state_3"].addTransition(_parallel_orthogonal_2_orthogonal_inner_2_state_3_0);
    
    // transition /next_to_parallel
    var _next_to_parallel_0 = new Transition(this, this.states["/next_to_parallel"], [this.states["/parallel/history_1"]]);
    _next_to_parallel_0.trigger = new Event("to_history_1", "test_input");
    this.states["/next_to_parallel"].addTransition(_next_to_parallel_0);
    
    // transition /parallel
    var _parallel_0 = new Transition(this, this.states["/parallel"], [this.states["/next_to_parallel"]]);
    _parallel_0.trigger = new Event("exit", "test_input");
    this.states["/parallel"].addTransition(_parallel_0);
    
    // transition /parallel/orthogonal_1/orthogonal_inner_1
    var _parallel_orthogonal_1_orthogonal_inner_1_0 = new Transition(this, this.states["/parallel/orthogonal_1/orthogonal_inner_1"], [this.states["/parallel/orthogonal_1/outer_1"]]);
    _parallel_orthogonal_1_orthogonal_inner_1_0.trigger = new Event("to_outer_1", "test_input");
    this.states["/parallel/orthogonal_1/orthogonal_inner_1"].addTransition(_parallel_orthogonal_1_orthogonal_inner_1_0);
    
    // transition /parallel/orthogonal_2/orthogonal_inner_2
    var _parallel_orthogonal_2_orthogonal_inner_2_0 = new Transition(this, this.states["/parallel/orthogonal_2/orthogonal_inner_2"], [this.states["/parallel/orthogonal_2/outer_2"]]);
    _parallel_orthogonal_2_orthogonal_inner_2_0.trigger = new Event("to_outer_2", "test_input");
    this.states["/parallel/orthogonal_2/orthogonal_inner_2"].addTransition(_parallel_orthogonal_2_orthogonal_inner_2_0);
};

TestClass.prototype._parallel_orthogonal_1_orthogonal_inner_1_state_1_enter = function() {
    this.big_step.outputEvent(new Event("in_state_1", "test_output", new Array()));
};

TestClass.prototype._parallel_orthogonal_1_orthogonal_inner_1_state_2_enter = function() {
    this.big_step.outputEvent(new Event("in_state_2", "test_output", new Array()));
};

TestClass.prototype._parallel_orthogonal_1_outer_1_enter = function() {
    this.big_step.outputEvent(new Event("in_outer_1", "test_output", new Array()));
};

TestClass.prototype._parallel_orthogonal_2_orthogonal_inner_2_state_3_enter = function() {
    this.big_step.outputEvent(new Event("in_state_3", "test_output", new Array()));
};

TestClass.prototype._parallel_orthogonal_2_orthogonal_inner_2_state_4_enter = function() {
    this.big_step.outputEvent(new Event("in_state_4", "test_output", new Array()));
};

TestClass.prototype._parallel_orthogonal_2_outer_2_enter = function() {
    this.big_step.outputEvent(new Event("in_outer_2", "test_output", new Array()));
};

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

TestClass.prototype.initializeStatechart = function() {
    // enter default state
    var states = this.states["/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 'TestClass' to package 'TestParallelHistory2'
TestParallelHistory2.TestClass = TestClass;

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 === "TestClass") {
        var instance = new TestClass(this.controller);
        instance.associations = new Object();
    }
    return instance;
};

// add symbol 'ObjectManager' to package 'TestParallelHistory2'
TestParallelHistory2.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("test_input");
    this.addOutputPort("test_output");
    this.object_manager.createInstance("TestClass", 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 'TestParallelHistory2'
TestParallelHistory2.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 'TestParallelHistory2'
TestParallelHistory2.InputEvent = InputEvent;

var Test = function() {
};
Test.prototype.input_events = [new InputEvent("to_outer_1", "test_input", new Array(), 0.0), new InputEvent("to_outer_2", "test_input", new Array(), 0.0), new InputEvent("exit", "test_input", new Array(), 0.0), new InputEvent("to_history_1", "test_input", new Array(), 0.0)];
Test.prototype.expected_events = [[new Event("in_state_1", "test_output", new Array()), new Event("in_state_3", "test_output", new Array())], [new Event("in_outer_1", "test_output", new Array())], [new Event("in_outer_2", "test_output", new Array())], [new Event("outside", "test_output", new Array())], [new Event("in_state_1", "test_output", new Array()), new Event("in_state_3", "test_output", new Array())]];

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