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

"""

from sccd.runtime.statecharts_core import *

# package ""

class Train(RuntimeClassBase):
    def __init__(self, controller, root):
        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.SourceChild
        self.semantics.concurrency = StatechartSemantics.Single
        
        # build Statechart structure
        self.build_statechart_structure()
        
        # call user defined constructor
        Train.user_defined_constructor(self, root)
    
    def user_defined_constructor(self, root):
        self.root, self.acceleration, self.velocity = root, 0.0, 0.0
        self.root.trainIs(self)
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def updateState(self):
        self.root.updateState()
    
    
    # user defined method
    def openDoors(self):
        self.root.openDoors()
    
    
    # user defined method
    def closeDoors(self):
        self.root.closeDoors()
    
    
    # user defined method
    def notify(self, message, color):
        self.root.notify(message, color)
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /normal_operation
        self.states["/normal_operation"] = State(1, "/normal_operation", self)
        
        # state /normal_operation/for_history
        self.states["/normal_operation/for_history"] = ParallelState(2, "/normal_operation/for_history", self)
        
        # state /normal_operation/for_history/train
        self.states["/normal_operation/for_history/train"] = State(3, "/normal_operation/for_history/train", self)
        
        # state /normal_operation/for_history/train/train
        self.states["/normal_operation/for_history/train/train"] = State(4, "/normal_operation/for_history/train/train", self)
        
        # state /normal_operation/for_history/train/train/stopped
        self.states["/normal_operation/for_history/train/train/stopped"] = State(5, "/normal_operation/for_history/train/train/stopped", self)
        self.states["/normal_operation/for_history/train/train/stopped"].setEnter(self._normal_operation_for_history_train_train_stopped_enter)
        
        # state /normal_operation/for_history/train/train/stopped/opened_doors
        self.states["/normal_operation/for_history/train/train/stopped/opened_doors"] = State(6, "/normal_operation/for_history/train/train/stopped/opened_doors", self)
        self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setEnter(self._normal_operation_for_history_train_train_stopped_opened_doors_enter)
        self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].setExit(self._normal_operation_for_history_train_train_stopped_opened_doors_exit)
        
        # state /normal_operation/for_history/train/train/stopped/in_station
        self.states["/normal_operation/for_history/train/train/stopped/in_station"] = State(7, "/normal_operation/for_history/train/train/stopped/in_station", self)
        
        # state /normal_operation/for_history/train/train/stopped/allow_closing
        self.states["/normal_operation/for_history/train/train/stopped/allow_closing"] = State(8, "/normal_operation/for_history/train/train/stopped/allow_closing", self)
        self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].setEnter(self._normal_operation_for_history_train_train_stopped_allow_closing_enter)
        
        # state /normal_operation/for_history/train/train/stopped/ready_to_leave
        self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"] = State(9, "/normal_operation/for_history/train/train/stopped/ready_to_leave", self)
        
        # state /normal_operation/for_history/train/train/approaching_station
        self.states["/normal_operation/for_history/train/train/approaching_station"] = State(10, "/normal_operation/for_history/train/train/approaching_station", self)
        
        # state /normal_operation/for_history/train/train/driving
        self.states["/normal_operation/for_history/train/train/driving"] = State(11, "/normal_operation/for_history/train/train/driving", self)
        
        # state /normal_operation/for_history/train/train/max_speed
        self.states["/normal_operation/for_history/train/train/max_speed"] = State(12, "/normal_operation/for_history/train/train/max_speed", self)
        self.states["/normal_operation/for_history/train/train/max_speed"].setEnter(self._normal_operation_for_history_train_train_max_speed_enter)
        self.states["/normal_operation/for_history/train/train/max_speed"].setExit(self._normal_operation_for_history_train_train_max_speed_exit)
        
        # state /normal_operation/for_history/GUI_update
        self.states["/normal_operation/for_history/GUI_update"] = State(13, "/normal_operation/for_history/GUI_update", self)
        
        # state /normal_operation/for_history/GUI_update/S_
        self.states["/normal_operation/for_history/GUI_update/S_"] = State(14, "/normal_operation/for_history/GUI_update/S_", self)
        
        # state /normal_operation/for_history/GUI_update/S_/updating
        self.states["/normal_operation/for_history/GUI_update/S_/updating"] = State(15, "/normal_operation/for_history/GUI_update/S_/updating", self)
        self.states["/normal_operation/for_history/GUI_update/S_/updating"].setEnter(self._normal_operation_for_history_GUI_update_S__updating_enter)
        self.states["/normal_operation/for_history/GUI_update/S_/updating"].setExit(self._normal_operation_for_history_GUI_update_S__updating_exit)
        
        # state /normal_operation/for_history/polling
        self.states["/normal_operation/for_history/polling"] = State(16, "/normal_operation/for_history/polling", self)
        
        # state /normal_operation/for_history/polling/S_
        self.states["/normal_operation/for_history/polling/S_"] = State(17, "/normal_operation/for_history/polling/S_", self)
        
        # state /normal_operation/for_history/polling/S_/okay
        self.states["/normal_operation/for_history/polling/S_/okay"] = State(18, "/normal_operation/for_history/polling/S_/okay", self)
        self.states["/normal_operation/for_history/polling/S_/okay"].setEnter(self._normal_operation_for_history_polling_S__okay_enter)
        self.states["/normal_operation/for_history/polling/S_/okay"].setExit(self._normal_operation_for_history_polling_S__okay_exit)
        
        # state /normal_operation/for_history/polling/S_/warn
        self.states["/normal_operation/for_history/polling/S_/warn"] = State(19, "/normal_operation/for_history/polling/S_/warn", self)
        self.states["/normal_operation/for_history/polling/S_/warn"].setEnter(self._normal_operation_for_history_polling_S__warn_enter)
        self.states["/normal_operation/for_history/polling/S_/warn"].setExit(self._normal_operation_for_history_polling_S__warn_exit)
        
        # state /normal_operation/H
        self.states["/normal_operation/H"] = DeepHistoryState(20, "/normal_operation/H", self)
        
        # state /emergency_stop
        self.states["/emergency_stop"] = State(21, "/emergency_stop", self)
        self.states["/emergency_stop"].setEnter(self._emergency_stop_enter)
        self.states["/emergency_stop"].setExit(self._emergency_stop_exit)
        
        # state /finished
        self.states["/finished"] = State(22, "/finished", self)
        self.states["/finished"].setEnter(self._finished_enter)
        
        # state /paused
        self.states["/paused"] = State(23, "/paused", self)
        
        # add children
        self.states[""].addChild(self.states["/normal_operation"])
        self.states[""].addChild(self.states["/emergency_stop"])
        self.states[""].addChild(self.states["/finished"])
        self.states[""].addChild(self.states["/paused"])
        self.states["/normal_operation"].addChild(self.states["/normal_operation/for_history"])
        self.states["/normal_operation"].addChild(self.states["/normal_operation/H"])
        self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/train"])
        self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/GUI_update"])
        self.states["/normal_operation/for_history"].addChild(self.states["/normal_operation/for_history/polling"])
        self.states["/normal_operation/for_history/train"].addChild(self.states["/normal_operation/for_history/train/train"])
        self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/stopped"])
        self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/approaching_station"])
        self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/driving"])
        self.states["/normal_operation/for_history/train/train"].addChild(self.states["/normal_operation/for_history/train/train/max_speed"])
        self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/opened_doors"])
        self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/in_station"])
        self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/allow_closing"])
        self.states["/normal_operation/for_history/train/train/stopped"].addChild(self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"])
        self.states["/normal_operation/for_history/GUI_update"].addChild(self.states["/normal_operation/for_history/GUI_update/S_"])
        self.states["/normal_operation/for_history/GUI_update/S_"].addChild(self.states["/normal_operation/for_history/GUI_update/S_/updating"])
        self.states["/normal_operation/for_history/polling"].addChild(self.states["/normal_operation/for_history/polling/S_"])
        self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/okay"])
        self.states["/normal_operation/for_history/polling/S_"].addChild(self.states["/normal_operation/for_history/polling/S_/warn"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/paused"]
        self.states["/normal_operation"].default_state = self.states["/normal_operation/for_history"]
        self.states["/normal_operation/for_history/train"].default_state = self.states["/normal_operation/for_history/train/train"]
        self.states["/normal_operation/for_history/train/train"].default_state = self.states["/normal_operation/for_history/train/train/stopped"]
        self.states["/normal_operation/for_history/train/train/stopped"].default_state = self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]
        self.states["/normal_operation/for_history/GUI_update"].default_state = self.states["/normal_operation/for_history/GUI_update/S_"]
        self.states["/normal_operation/for_history/GUI_update/S_"].default_state = self.states["/normal_operation/for_history/GUI_update/S_/updating"]
        self.states["/normal_operation/for_history/polling"].default_state = self.states["/normal_operation/for_history/polling/S_"]
        self.states["/normal_operation/for_history/polling/S_"].default_state = self.states["/normal_operation/for_history/polling/S_/okay"]
        
        # transition /normal_operation/for_history/train/train/stopped/opened_doors
        _normal_operation_for_history_train_train_stopped_opened_doors_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/opened_doors"], [self.states["/normal_operation/for_history/train/train/stopped/allow_closing"]])
        _normal_operation_for_history_train_train_stopped_opened_doors_0.setTrigger(Event("_0after"))
        self.states["/normal_operation/for_history/train/train/stopped/opened_doors"].addTransition(_normal_operation_for_history_train_train_stopped_opened_doors_0)
        
        # transition /normal_operation/for_history/train/train/stopped/in_station
        _normal_operation_for_history_train_train_stopped_in_station_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/in_station"], [self.states["/normal_operation/for_history/train/train/stopped/opened_doors"]])
        _normal_operation_for_history_train_train_stopped_in_station_0.setAction(self._normal_operation_for_history_train_train_stopped_in_station_0_exec)
        _normal_operation_for_history_train_train_stopped_in_station_0.setTrigger(Event("open", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/stopped/in_station"].addTransition(_normal_operation_for_history_train_train_stopped_in_station_0)
        
        # transition /normal_operation/for_history/train/train/stopped/allow_closing
        _normal_operation_for_history_train_train_stopped_allow_closing_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/allow_closing"], [self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]])
        _normal_operation_for_history_train_train_stopped_allow_closing_0.setAction(self._normal_operation_for_history_train_train_stopped_allow_closing_0_exec)
        _normal_operation_for_history_train_train_stopped_allow_closing_0.setTrigger(Event("close", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/stopped/allow_closing"].addTransition(_normal_operation_for_history_train_train_stopped_allow_closing_0)
        
        # transition /normal_operation/for_history/train/train/stopped/ready_to_leave
        _normal_operation_for_history_train_train_stopped_ready_to_leave_0 = Transition(self, self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"], [self.states["/normal_operation/for_history/train/train/driving"]])
        _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setAction(self._normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec)
        _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setTrigger(Event("accel", self.getInPortName("tkinter_input")))
        _normal_operation_for_history_train_train_stopped_ready_to_leave_0.setGuard(self._normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard)
        self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"].addTransition(_normal_operation_for_history_train_train_stopped_ready_to_leave_0)
        
        # transition /normal_operation/for_history/train/train/approaching_station
        _normal_operation_for_history_train_train_approaching_station_0 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/stopped/in_station"]])
        _normal_operation_for_history_train_train_approaching_station_0.setTrigger(None)
        _normal_operation_for_history_train_train_approaching_station_0.setGuard(self._normal_operation_for_history_train_train_approaching_station_0_guard)
        self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_0)
        _normal_operation_for_history_train_train_approaching_station_1 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
        _normal_operation_for_history_train_train_approaching_station_1.setAction(self._normal_operation_for_history_train_train_approaching_station_1_exec)
        _normal_operation_for_history_train_train_approaching_station_1.setTrigger(Event("accel", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_1)
        _normal_operation_for_history_train_train_approaching_station_2 = Transition(self, self.states["/normal_operation/for_history/train/train/approaching_station"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
        _normal_operation_for_history_train_train_approaching_station_2.setAction(self._normal_operation_for_history_train_train_approaching_station_2_exec)
        _normal_operation_for_history_train_train_approaching_station_2.setTrigger(Event("leave", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/approaching_station"].addTransition(_normal_operation_for_history_train_train_approaching_station_2)
        
        # transition /normal_operation/for_history/train/train/driving
        _normal_operation_for_history_train_train_driving_0 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
        _normal_operation_for_history_train_train_driving_0.setTrigger(Event("enter", self.getInPortName("tkinter_input")))
        _normal_operation_for_history_train_train_driving_0.setGuard(self._normal_operation_for_history_train_train_driving_0_guard)
        self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_0)
        _normal_operation_for_history_train_train_driving_1 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/max_speed"]])
        _normal_operation_for_history_train_train_driving_1.setTrigger(None)
        _normal_operation_for_history_train_train_driving_1.setGuard(self._normal_operation_for_history_train_train_driving_1_guard)
        self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_1)
        _normal_operation_for_history_train_train_driving_2 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/driving"]])
        _normal_operation_for_history_train_train_driving_2.setAction(self._normal_operation_for_history_train_train_driving_2_exec)
        _normal_operation_for_history_train_train_driving_2.setTrigger(Event("accel", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_2)
        _normal_operation_for_history_train_train_driving_3 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/stopped/ready_to_leave"]])
        _normal_operation_for_history_train_train_driving_3.setTrigger(None)
        _normal_operation_for_history_train_train_driving_3.setGuard(self._normal_operation_for_history_train_train_driving_3_guard)
        self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_3)
        _normal_operation_for_history_train_train_driving_4 = Transition(self, self.states["/normal_operation/for_history/train/train/driving"], [self.states["/normal_operation/for_history/train/train/approaching_station"]])
        _normal_operation_for_history_train_train_driving_4.setAction(self._normal_operation_for_history_train_train_driving_4_exec)
        _normal_operation_for_history_train_train_driving_4.setTrigger(Event("enter", None))
        _normal_operation_for_history_train_train_driving_4.setGuard(self._normal_operation_for_history_train_train_driving_4_guard)
        self.states["/normal_operation/for_history/train/train/driving"].addTransition(_normal_operation_for_history_train_train_driving_4)
        
        # transition /normal_operation/for_history/train/train/max_speed
        _normal_operation_for_history_train_train_max_speed_0 = Transition(self, self.states["/normal_operation/for_history/train/train/max_speed"], [self.states["/normal_operation/for_history/train/train/driving"]])
        _normal_operation_for_history_train_train_max_speed_0.setAction(self._normal_operation_for_history_train_train_max_speed_0_exec)
        _normal_operation_for_history_train_train_max_speed_0.setTrigger(Event("accel", self.getInPortName("tkinter_input")))
        _normal_operation_for_history_train_train_max_speed_0.setGuard(self._normal_operation_for_history_train_train_max_speed_0_guard)
        self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_0)
        _normal_operation_for_history_train_train_max_speed_1 = Transition(self, self.states["/normal_operation/for_history/train/train/max_speed"], [self.states["/normal_operation/for_history/train/train/max_speed"]])
        _normal_operation_for_history_train_train_max_speed_1.setAction(self._normal_operation_for_history_train_train_max_speed_1_exec)
        _normal_operation_for_history_train_train_max_speed_1.setTrigger(Event("enter", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/train/train/max_speed"].addTransition(_normal_operation_for_history_train_train_max_speed_1)
        
        # transition /normal_operation/for_history/GUI_update/S_/updating
        _normal_operation_for_history_GUI_update_S__updating_0 = Transition(self, self.states["/normal_operation/for_history/GUI_update/S_/updating"], [self.states["/normal_operation/for_history/GUI_update/S_/updating"]])
        _normal_operation_for_history_GUI_update_S__updating_0.setAction(self._normal_operation_for_history_GUI_update_S__updating_0_exec)
        _normal_operation_for_history_GUI_update_S__updating_0.setTrigger(Event("_1after"))
        self.states["/normal_operation/for_history/GUI_update/S_/updating"].addTransition(_normal_operation_for_history_GUI_update_S__updating_0)
        
        # transition /normal_operation/for_history/polling/S_/okay
        _normal_operation_for_history_polling_S__okay_0 = Transition(self, self.states["/normal_operation/for_history/polling/S_/okay"], [self.states["/normal_operation/for_history/polling/S_/warn"]])
        _normal_operation_for_history_polling_S__okay_0.setAction(self._normal_operation_for_history_polling_S__okay_0_exec)
        _normal_operation_for_history_polling_S__okay_0.setTrigger(Event("_2after"))
        self.states["/normal_operation/for_history/polling/S_/okay"].addTransition(_normal_operation_for_history_polling_S__okay_0)
        
        # transition /normal_operation/for_history/polling/S_/warn
        _normal_operation_for_history_polling_S__warn_0 = Transition(self, self.states["/normal_operation/for_history/polling/S_/warn"], [self.states["/normal_operation/for_history/polling/S_/okay"]])
        _normal_operation_for_history_polling_S__warn_0.setAction(self._normal_operation_for_history_polling_S__warn_0_exec)
        _normal_operation_for_history_polling_S__warn_0.setTrigger(Event("awake", self.getInPortName("tkinter_input")))
        self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_0)
        _normal_operation_for_history_polling_S__warn_1 = Transition(self, self.states["/normal_operation/for_history/polling/S_/warn"], [self.states["/normal_operation/for_history/polling/S_/warn"]])
        _normal_operation_for_history_polling_S__warn_1.setAction(self._normal_operation_for_history_polling_S__warn_1_exec)
        _normal_operation_for_history_polling_S__warn_1.setTrigger(Event("_3after"))
        self.states["/normal_operation/for_history/polling/S_/warn"].addTransition(_normal_operation_for_history_polling_S__warn_1)
        
        # transition /emergency_stop
        _emergency_stop_0 = Transition(self, self.states["/emergency_stop"], [self.states["/finished"]])
        _emergency_stop_0.setTrigger(None)
        _emergency_stop_0.setGuard(self._emergency_stop_0_guard)
        self.states["/emergency_stop"].addTransition(_emergency_stop_0)
        _emergency_stop_1 = Transition(self, self.states["/emergency_stop"], [self.states["/emergency_stop"]])
        _emergency_stop_1.setAction(self._emergency_stop_1_exec)
        _emergency_stop_1.setTrigger(Event("_4after"))
        self.states["/emergency_stop"].addTransition(_emergency_stop_1)
        
        # transition /paused
        _paused_0 = Transition(self, self.states["/paused"], [self.states["/normal_operation/H"]])
        _paused_0.setAction(self._paused_0_exec)
        _paused_0.setTrigger(Event("continue", self.getInPortName("tkinter_input")))
        self.states["/paused"].addTransition(_paused_0)
        
        # transition /normal_operation
        _normal_operation_0 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
        _normal_operation_0.setAction(self._normal_operation_0_exec)
        _normal_operation_0.setTrigger(Event("red_light", self.getInPortName("tkinter_input")))
        self.states["/normal_operation"].addTransition(_normal_operation_0)
        _normal_operation_1 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
        _normal_operation_1.setAction(self._normal_operation_1_exec)
        _normal_operation_1.setTrigger(Event("yellow_light", self.getInPortName("tkinter_input")))
        _normal_operation_1.setGuard(self._normal_operation_1_guard)
        self.states["/normal_operation"].addTransition(_normal_operation_1)
        _normal_operation_2 = Transition(self, self.states["/normal_operation"], [self.states["/emergency_stop"]])
        _normal_operation_2.setTrigger(Event("error", None))
        self.states["/normal_operation"].addTransition(_normal_operation_2)
        _normal_operation_3 = Transition(self, self.states["/normal_operation"], [self.states["/paused"]])
        _normal_operation_3.setAction(self._normal_operation_3_exec)
        _normal_operation_3.setTrigger(Event("pause", self.getInPortName("tkinter_input")))
        self.states["/normal_operation"].addTransition(_normal_operation_3)
    
    def _normal_operation_for_history_train_train_stopped_enter(self):
        self.speed = 0.0
        self.acceleration = 0.0
    
    def _normal_operation_for_history_train_train_stopped_opened_doors_enter(self):
        self.notify("Please wait before closing doors", "white")
        self.addTimer(0, 5)
    
    def _normal_operation_for_history_train_train_stopped_opened_doors_exit(self):
        self.removeTimer(0)
    
    def _normal_operation_for_history_train_train_stopped_allow_closing_enter(self):
        self.notify("You can now close the doors!", "white")
    
    def _normal_operation_for_history_train_train_max_speed_enter(self):
        self.speed = 120.0
        self.acceleration = 0.0
        print("MAX")
    
    def _normal_operation_for_history_train_train_max_speed_exit(self):
        print("LEAVE MAX")
    
    def _normal_operation_for_history_GUI_update_S__updating_enter(self):
        self.addTimer(1, 0.02)
    
    def _normal_operation_for_history_GUI_update_S__updating_exit(self):
        self.removeTimer(1)
    
    def _normal_operation_for_history_polling_S__okay_enter(self):
        self.addTimer(2, 20.0)
    
    def _normal_operation_for_history_polling_S__okay_exit(self):
        self.removeTimer(2)
    
    def _normal_operation_for_history_polling_S__warn_enter(self):
        self.addTimer(3, 10.0)
    
    def _normal_operation_for_history_polling_S__warn_exit(self):
        self.removeTimer(3)
    
    def _emergency_stop_enter(self):
        self.acceleration = -1
        self.addTimer(4, 0.02)
    
    def _emergency_stop_exit(self):
        self.removeTimer(4)
    
    def _finished_enter(self):
        self.acceleration = 0.0
        self.speed = 0.0
    
    def _normal_operation_0_exec(self, parameters):
        self.notify("Passed red light", "red")
    
    def _normal_operation_1_exec(self, parameters):
        self.notify("Passed yellow light while driving too fast", "red")
    
    def _normal_operation_1_guard(self, parameters):
        return self.speed > 50
    
    def _normal_operation_3_exec(self, parameters):
        self.notify("Paused", "white")
    
    def _normal_operation_for_history_train_train_stopped_in_station_0_exec(self, parameters):
        self.openDoors()
    
    def _normal_operation_for_history_train_train_stopped_allow_closing_0_exec(self, parameters):
        self.closeDoors()
    
    def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_exec(self, parameters):
        value = parameters[0]
        self.acceleration = value
    
    def _normal_operation_for_history_train_train_stopped_ready_to_leave_0_guard(self, parameters):
        value = parameters[0]
        return value > 0
    
    def _normal_operation_for_history_train_train_approaching_station_0_guard(self, parameters):
        return self.speed <= 0
    
    def _normal_operation_for_history_train_train_approaching_station_1_exec(self, parameters):
        value = parameters[0]
        self.acceleration = value
    
    def _normal_operation_for_history_train_train_approaching_station_2_exec(self, parameters):
        self.notify("Left station without stopping", "red")
        self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("error", None, [])]))
    
    def _normal_operation_for_history_train_train_driving_0_guard(self, parameters):
        return self.speed <= 50
    
    def _normal_operation_for_history_train_train_driving_1_guard(self, parameters):
        return self.speed >= 100 and self.acceleration > 0
    
    def _normal_operation_for_history_train_train_driving_2_exec(self, parameters):
        value = parameters[0]
        self.acceleration = value
    
    def _normal_operation_for_history_train_train_driving_3_guard(self, parameters):
        return self.speed <= 0 and self.acceleration < 0
    
    def _normal_operation_for_history_train_train_driving_4_exec(self, parameters):
        self.notify("Entered station too fast", "red")
        self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("error", None, [])]))
    
    def _normal_operation_for_history_train_train_driving_4_guard(self, parameters):
        return self.speed > 50
    
    def _normal_operation_for_history_train_train_max_speed_0_exec(self, parameters):
        value = parameters[0]
        self.acceleration = value
    
    def _normal_operation_for_history_train_train_max_speed_0_guard(self, parameters):
        value = parameters[0]
        return value < 0
    
    def _normal_operation_for_history_train_train_max_speed_1_exec(self, parameters):
        self.notify("Entered station at maximum speed!", "red")
        self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("error", None, [])]))
    
    def _normal_operation_for_history_GUI_update_S__updating_0_exec(self, parameters):
        self.updateState()
    
    def _normal_operation_for_history_polling_S__okay_0_exec(self, parameters):
        self.notify("Please press button!", "yellow")
    
    def _normal_operation_for_history_polling_S__warn_0_exec(self, parameters):
        self.notify("", "gray")
    
    def _normal_operation_for_history_polling_S__warn_1_exec(self, parameters):
        self.notify("Did not press the button in time", "red")
        self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("error", None, [])]))
    
    def _emergency_stop_0_guard(self, parameters):
        return self.speed <= 0
    
    def _emergency_stop_1_exec(self, parameters):
        self.updateState()
    
    def _paused_0_exec(self, parameters):
        self.notify("", "gray")
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/paused"].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 == "Train":
            instance = Train(self.controller, construct_params[0])
            instance.associations = {}
        else:
            raise Exception("Cannot instantiate class " + class_name)
        return instance

class Controller(EventLoopControllerBase):
    def __init__(self, root, 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("tkinter_input")
        self.object_manager.createInstance("Train", [root])