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

Date:   Thu Aug 04 12:51:05 2016

Model author: Glenn De Jonghe
Model name:   TestInstate
Model description:
Testing the INSTATE macro.
"""

from sccd.runtime.statecharts_core import *

# package "TestInstate"

class Class1(RuntimeClassBase):
    def __init__(self, controller):
        RuntimeClassBase.__init__(self, controller)
        
        self.semantics.big_step_maximality = StatechartSemantics.TakeOne
        self.semantics.internal_event_lifeline = StatechartSemantics.NextSmallStep
        self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
        self.semantics.priority = StatechartSemantics.SourceParent
        self.semantics.concurrency = StatechartSemantics.Single
        
        # build Statechart structure
        self.build_statechart_structure()
        
        # call user defined constructor
        Class1.user_defined_constructor(self)
    
    def user_defined_constructor(self):
        pass
    
    def user_defined_destructor(self):
        pass
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, self)
        
        # state /parallel_1
        self.states["/parallel_1"] = ParallelState(1, self)
        
        # state /parallel_1/orthogonal1
        self.states["/parallel_1/orthogonal1"] = State(2, self)
        
        # state /parallel_1/orthogonal1/state1
        self.states["/parallel_1/orthogonal1/state1"] = State(3, self)
        
        # state /parallel_1/orthogonal1/inner
        self.states["/parallel_1/orthogonal1/inner"] = State(4, self)
        
        # state /parallel_1/orthogonal1/inner/state2
        self.states["/parallel_1/orthogonal1/inner/state2"] = State(5, self)
        
        # state /parallel_1/orthogonal1/inner/state3
        self.states["/parallel_1/orthogonal1/inner/state3"] = State(6, self)
        
        # state /parallel_1/orthogonal2
        self.states["/parallel_1/orthogonal2"] = State(7, self)
        
        # state /parallel_1/orthogonal2/tester
        self.states["/parallel_1/orthogonal2/tester"] = State(8, self)
        
        # state /parallel_1/orthogonal2/stop
        self.states["/parallel_1/orthogonal2/stop"] = State(9, self)
        
        # add children
        self.states[""].addChild(self.states["/parallel_1"])
        self.states["/parallel_1"].addChild(self.states["/parallel_1/orthogonal1"])
        self.states["/parallel_1"].addChild(self.states["/parallel_1/orthogonal2"])
        self.states["/parallel_1/orthogonal1"].addChild(self.states["/parallel_1/orthogonal1/state1"])
        self.states["/parallel_1/orthogonal1"].addChild(self.states["/parallel_1/orthogonal1/inner"])
        self.states["/parallel_1/orthogonal1/inner"].addChild(self.states["/parallel_1/orthogonal1/inner/state2"])
        self.states["/parallel_1/orthogonal1/inner"].addChild(self.states["/parallel_1/orthogonal1/inner/state3"])
        self.states["/parallel_1/orthogonal2"].addChild(self.states["/parallel_1/orthogonal2/tester"])
        self.states["/parallel_1/orthogonal2"].addChild(self.states["/parallel_1/orthogonal2/stop"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/parallel_1"]
        self.states["/parallel_1/orthogonal1"].default_state = self.states["/parallel_1/orthogonal1/state1"]
        self.states["/parallel_1/orthogonal1/inner"].default_state = self.states["/parallel_1/orthogonal1/inner/state2"]
        self.states["/parallel_1/orthogonal2"].default_state = self.states["/parallel_1/orthogonal2/tester"]
        
        # transition /parallel_1/orthogonal1/state1
        _parallel_1_orthogonal1_state1_0 = Transition(self, self.states["/parallel_1/orthogonal1/state1"], [self.states["/parallel_1/orthogonal1/inner"]])
        _parallel_1_orthogonal1_state1_0.trigger = Event("to_inner", None)
        self.states["/parallel_1/orthogonal1/state1"].addTransition(_parallel_1_orthogonal1_state1_0)
        
        # transition /parallel_1/orthogonal1/inner/state2
        _parallel_1_orthogonal1_inner_state2_0 = Transition(self, self.states["/parallel_1/orthogonal1/inner/state2"], [self.states["/parallel_1/orthogonal1/inner/state3"]])
        _parallel_1_orthogonal1_inner_state2_0.trigger = Event("to_state3", None)
        self.states["/parallel_1/orthogonal1/inner/state2"].addTransition(_parallel_1_orthogonal1_inner_state2_0)
        
        # transition /parallel_1/orthogonal2/tester
        _parallel_1_orthogonal2_tester_0 = Transition(self, self.states["/parallel_1/orthogonal2/tester"], [self.states["/parallel_1/orthogonal2/tester"]])
        _parallel_1_orthogonal2_tester_0.setAction(self._parallel_1_orthogonal2_tester_0_exec)
        _parallel_1_orthogonal2_tester_0.setGuard(self._parallel_1_orthogonal2_tester_0_guard)
        self.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_0)
        _parallel_1_orthogonal2_tester_1 = Transition(self, self.states["/parallel_1/orthogonal2/tester"], [self.states["/parallel_1/orthogonal2/tester"]])
        _parallel_1_orthogonal2_tester_1.setAction(self._parallel_1_orthogonal2_tester_1_exec)
        _parallel_1_orthogonal2_tester_1.setGuard(self._parallel_1_orthogonal2_tester_1_guard)
        self.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_1)
        _parallel_1_orthogonal2_tester_2 = Transition(self, self.states["/parallel_1/orthogonal2/tester"], [self.states["/parallel_1/orthogonal2/stop"]])
        _parallel_1_orthogonal2_tester_2.setAction(self._parallel_1_orthogonal2_tester_2_exec)
        _parallel_1_orthogonal2_tester_2.setGuard(self._parallel_1_orthogonal2_tester_2_guard)
        self.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_2)
    
    def _parallel_1_orthogonal2_tester_0_exec(self, parameters):
        self.big_step.outputEvent(Event("check1", "test_output", []))
        self.raiseInternalEvent(Event("to_inner", None, []))
    
    def _parallel_1_orthogonal2_tester_0_guard(self, parameters):
        return self.inState(["/parallel_1/orthogonal1/state1"])
    
    def _parallel_1_orthogonal2_tester_1_exec(self, parameters):
        self.big_step.outputEvent(Event("check2", "test_output", []))
        self.raiseInternalEvent(Event("to_state3", None, []))
    
    def _parallel_1_orthogonal2_tester_1_guard(self, parameters):
        return self.inState(["/parallel_1/orthogonal1/inner/state2"])
    
    def _parallel_1_orthogonal2_tester_2_exec(self, parameters):
        self.big_step.outputEvent(Event("check3", "test_output", []))
    
    def _parallel_1_orthogonal2_tester_2_guard(self, parameters):
        return self.inState(["/parallel_1/orthogonal1/inner/state3"])
    
    def initializeStatechart(self):
        # enter default state
        states = self.states["/parallel_1"].getEffectiveTargetStates()
        self.updateConfiguration(states)
        for state in states:
            if state.enter:
                state.enter()

class ObjectManager(ObjectManagerBase):
    def __init__(self, controller):
        ObjectManagerBase.__init__(self, controller)
    
    def instantiate(self, class_name, construct_params):
        if class_name == "Class1":
            instance = Class1(self.controller)
            instance.associations = {}
        else:
            raise Exception("Cannot instantiate class " + class_name)
        return instance

class Controller(ThreadsControllerBase):
    def __init__(self, keep_running = None):
        if keep_running == None: keep_running = True
        ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
        self.addOutputPort("test_output")
        self.object_manager.createInstance("Class1", [])

class InputEvent:
    def __init__(self, name, port, parameters, time_offset):
        self.name = name
        self.port = port
        self.parameters = parameters
        self.time_offset = time_offset

class Test:
    def __init__(self):
        pass
    input_events = []
    expected_events = [[Event("check1", "test_output", [])], [Event("check2", "test_output", [])], [Event("check3", "test_output", [])]]