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

Date:   Fri Oct 06 16:24:33 2017

Model author: Yentl Van Tendeloo
Model name:   Testing
Model description:
Testing
"""

from sccd.runtime.statecharts_core import *
import time

# package "Testing"

class Testing(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
        Testing.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 /A
        self.states["/A"] = State(1, "/A", self)
        self.states["/A"].setEnter(self._A_enter)
        self.states["/A"].setExit(self._A_exit)
        
        # add children
        self.states[""].addChild(self.states["/A"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/A"]
        
        # transition /A
        _A_0 = Transition(self, self.states["/A"], [self.states["/A"]])
        _A_0.setAction(self._A_0_exec)
        _A_0.setTrigger(Event("_0after"))
        self.states["/A"].addTransition(_A_0)
    
    def _A_enter(self):
        self.addTimer(0, 0.01)
    
    def _A_exit(self):
        self.removeTimer(0)
    
    def _A_0_exec(self, parameters):
        print(time.time())
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/A"].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 == "Testing":
            instance = Testing(self.controller)
            instance.associations = {}
        else:
            raise Exception("Cannot instantiate class " + class_name)
        return instance

class Controller(EventLoopControllerBase):
    def __init__(self, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
        if finished_callback == None: finished_callback = None
        if behind_schedule_callback == None: behind_schedule_callback = None
        EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
        self.addInputPort("input")
        self.object_manager.createInstance("Testing", [])