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

Date:   Wed Aug 10 11:42:10 2016

Model name:   exit-parallel

"""

from sccd.runtime.statecharts_core import *

# package "exit-parallel"

class A(RuntimeClassBase):
    def __init__(self, controller):
        RuntimeClassBase.__init__(self, controller)
        
        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
        self.semantics.internal_event_lifeline = StatechartSemantics.Queue
        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
        A.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 /x
        self.states["/x"] = ParallelState(1, self)
        
        # state /x/x1
        self.states["/x/x1"] = State(2, self)
        
        # state /x/x1/x1
        self.states["/x/x1/x1"] = State(3, self)
        
        # state /x/x2
        self.states["/x/x2"] = State(4, self)
        
        # state /x/x2/x2
        self.states["/x/x2/x2"] = State(5, self)
        
        # state /done
        self.states["/done"] = State(6, self)
        self.states["/done"].setEnter(self._done_enter)
        
        # add children
        self.states[""].addChild(self.states["/x"])
        self.states[""].addChild(self.states["/done"])
        self.states["/x"].addChild(self.states["/x/x1"])
        self.states["/x"].addChild(self.states["/x/x2"])
        self.states["/x/x1"].addChild(self.states["/x/x1/x1"])
        self.states["/x/x2"].addChild(self.states["/x/x2/x2"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/x"]
        self.states["/x/x1"].default_state = self.states["/x/x1/x1"]
        self.states["/x/x2"].default_state = self.states["/x/x2/x2"]
        
        # transition /x/x1/x1
        _x_x1_x1_0 = Transition(self, self.states["/x/x1/x1"], [self.states["/done"]])
        _x_x1_x1_0.setAction(self._x_x1_x1_0_exec)
        _x_x1_x1_0.setTrigger(None)
        _x_x1_x1_0.setGuard(self._x_x1_x1_0_guard)
        self.states["/x/x1/x1"].addTransition(_x_x1_x1_0)
        _x_x1_x1_1 = Transition(self, self.states["/x/x1/x1"], [self.states["/done"]])
        _x_x1_x1_1.setTrigger(Event("E", None))
        self.states["/x/x1/x1"].addTransition(_x_x1_x1_1)
    
    def _done_enter(self):
        print 'in done'
    
    def _x_x1_x1_0_exec(self, parameters):
        print 'taking transition'
    
    def _x_x1_x1_0_guard(self, parameters):
        return self.a == 5
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/x"].getEffectiveTargetStates()
        RuntimeClassBase.initializeStatechart(self)

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

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