"""Implementation of statechart statechart_v2.
Generated by YAKINDU Statechart Tools code generator.
"""

import queue
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))
from yakindu.rx import Observable

class Statechart_v2:
	"""Implementation of the state machine Statechart_v2.
	"""

	class State:
		""" State Enum
		"""
		(
			main_region_engine_active,
			main_region_engine_active_gear_neutral,
			main_region_engine_active_gear_forward,
			main_region_engine_active_gear_forward_gears_1st,
			main_region_engine_active_gear_forward_gears_2nd,
			main_region_engine_active_gear_forward_gears_3rd,
			main_region_engine_active_gear_forward_gears_4th,
			main_region_engine_active_gear_forward_gears_5th,
			main_region_engine_active_speed_change_static,
			main_region_engine_active_speed_change_accellerating,
			main_region_engine_active_speed_change_slowing,
			main_region_engine_active_status_ok,
			main_region_engine_active_status_overloading,
			main_region_engine_active_status_overloaded,
			main_region_engine_active_status_emergency_brake,
			main_region_engine_standby,
			null_state
		) = range(17)
	
	
	class User:
		"""Implementation of scope User.
		"""
		
		def __init__(self, statemachine):
			self.start_engine_button = None
			self.brake_pressed_button = None
			self.gas_pressed_button = None
			self.emergency_brake_button = None
			
			self.statemachine = statemachine
		
		def raise_start_engine_button(self):
			"""Raise method for event start_engine_button.
			"""
			self.statemachine.in_event_queue.put(self.__raise_start_engine_button_call)
			self.statemachine.run_cycle()
		
		def __raise_start_engine_button_call(self):
			"""Raise callback for event start_engine_button.
			"""
			self.start_engine_button = True
		
		def raise_brake_pressed_button(self):
			"""Raise method for event brake_pressed_button.
			"""
			self.statemachine.in_event_queue.put(self.__raise_brake_pressed_button_call)
			self.statemachine.run_cycle()
		
		def __raise_brake_pressed_button_call(self):
			"""Raise callback for event brake_pressed_button.
			"""
			self.brake_pressed_button = True
		
		def raise_gas_pressed_button(self):
			"""Raise method for event gas_pressed_button.
			"""
			self.statemachine.in_event_queue.put(self.__raise_gas_pressed_button_call)
			self.statemachine.run_cycle()
		
		def __raise_gas_pressed_button_call(self):
			"""Raise callback for event gas_pressed_button.
			"""
			self.gas_pressed_button = True
		
		def raise_emergency_brake_button(self):
			"""Raise method for event emergency_brake_button.
			"""
			self.statemachine.in_event_queue.put(self.__raise_emergency_brake_button_call)
			self.statemachine.run_cycle()
		
		def __raise_emergency_brake_button_call(self):
			"""Raise callback for event emergency_brake_button.
			"""
			self.emergency_brake_button = True
		
	
	class System:
		"""Implementation of scope System.
		"""
		
		def __init__(self, statemachine):
			self.speed = None
			self.differential = None
			self.max_speed = None
			self.counter = None
			self.gear_max = None
			self.gear_min = None
			self.emergency_brake = None
			self.max_speed_reached = None
			self.speed_stop = None
			self.gear_change = None
			self.start_engine_event = None
			self.start_engine_event_observable = Observable()
			self.first_gear_event = None
			self.first_gear_event_observable = Observable()
			self.second_gear_event = None
			self.second_gear_event_observable = Observable()
			self.third_gear_event = None
			self.third_gear_event_observable = Observable()
			self.fourth_gear_event = None
			self.fourth_gear_event_observable = Observable()
			self.fifth_gear_event = None
			self.fifth_gear_event_observable = Observable()
			self.accellerating_event = None
			self.accellerating_event_observable = Observable()
			self.slowing_event = None
			self.slowing_event_observable = Observable()
			self.ok_event = None
			self.ok_event_observable = Observable()
			self.static_event = None
			self.static_event_observable = Observable()
			self.emergency_brake_event = None
			self.emergency_brake_event_observable = Observable()
			self.engine_standby_event = None
			self.engine_standby_event_observable = Observable()
			self.in_over_loading_proccess_event = None
			self.in_over_loading_proccess_event_observable = Observable()
			self.over_loaded_event = None
			self.over_loaded_event_observable = Observable()
			
			self.statemachine = statemachine
		
		def raise_emergency_brake(self):
			"""Raise method for event emergency_brake.
			"""
			self.statemachine.in_event_queue.put(self.__raise_emergency_brake_call)
			self.statemachine.run_cycle()
		
		def __raise_emergency_brake_call(self):
			"""Raise callback for event emergency_brake.
			"""
			self.emergency_brake = True
		
		def raise_max_speed_reached(self):
			"""Raise method for event max_speed_reached.
			"""
			self.statemachine.in_event_queue.put(self.__raise_max_speed_reached_call)
			self.statemachine.run_cycle()
		
		def __raise_max_speed_reached_call(self):
			"""Raise callback for event max_speed_reached.
			"""
			self.max_speed_reached = True
		
		def raise_speed_stop(self):
			"""Raise method for event speed_stop.
			"""
			self.statemachine.in_event_queue.put(self.__raise_speed_stop_call)
			self.statemachine.run_cycle()
		
		def __raise_speed_stop_call(self):
			"""Raise callback for event speed_stop.
			"""
			self.speed_stop = True
		
		def raise_gear_change(self):
			"""Raise method for event gear_change.
			"""
			self.statemachine.in_event_queue.put(self.__raise_gear_change_call)
			self.statemachine.run_cycle()
		
		def __raise_gear_change_call(self):
			"""Raise callback for event gear_change.
			"""
			self.gear_change = True
		
	
	def __init__(self):
		""" Declares all necessary variables including list of states, histories etc. 
		"""
		self.user = Statechart_v2.User(self)
		self.system = Statechart_v2.System(self)
		
		self.in_event_queue = queue.Queue()
		# enumeration of all states:
		self.__State = Statechart_v2.State
		self.__state_conf_vector_changed = None
		self.__state_vector = [None] * 3
		for __state_index in range(3):
			self.__state_vector[__state_index] = self.State.null_state
		
		# for timed statechart:
		self.timer_service = None
		self.__time_events = [None] * 7
		
		# initializations:
		self.system.speed = 0
		self.system.differential = 0
		self.system.max_speed = 120
		self.system.counter = 0
		self.system.gear_max = 0
		self.system.gear_min = 0
		self.__is_executing = False
		self.__state_conf_vector_position = None
	
	def is_active(self):
		"""Checks if the state machine is active.
		"""
		return self.__state_vector[0] is not self.__State.null_state or self.__state_vector[1] is not self.__State.null_state or self.__state_vector[2] is not self.__State.null_state
	
	def is_final(self):
		"""Checks if the statemachine is final.
		Always returns 'false' since this state machine can never become final.
		"""
		return False
			
	def is_state_active(self, state):
		"""Checks if the state is currently active.
		"""
		s = state
		if s == self.__State.main_region_engine_active:
			return (self.__state_vector[0] >= self.__State.main_region_engine_active)\
				and (self.__state_vector[0] <= self.__State.main_region_engine_active_status_emergency_brake)
		if s == self.__State.main_region_engine_active_gear_neutral:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_neutral
		if s == self.__State.main_region_engine_active_gear_forward:
			return (self.__state_vector[0] >= self.__State.main_region_engine_active_gear_forward)\
				and (self.__state_vector[0] <= self.__State.main_region_engine_active_gear_forward_gears_5th)
		if s == self.__State.main_region_engine_active_gear_forward_gears_1st:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_forward_gears_1st
		if s == self.__State.main_region_engine_active_gear_forward_gears_2nd:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_forward_gears_2nd
		if s == self.__State.main_region_engine_active_gear_forward_gears_3rd:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_forward_gears_3rd
		if s == self.__State.main_region_engine_active_gear_forward_gears_4th:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_forward_gears_4th
		if s == self.__State.main_region_engine_active_gear_forward_gears_5th:
			return self.__state_vector[0] == self.__State.main_region_engine_active_gear_forward_gears_5th
		if s == self.__State.main_region_engine_active_speed_change_static:
			return self.__state_vector[1] == self.__State.main_region_engine_active_speed_change_static
		if s == self.__State.main_region_engine_active_speed_change_accellerating:
			return self.__state_vector[1] == self.__State.main_region_engine_active_speed_change_accellerating
		if s == self.__State.main_region_engine_active_speed_change_slowing:
			return self.__state_vector[1] == self.__State.main_region_engine_active_speed_change_slowing
		if s == self.__State.main_region_engine_active_status_ok:
			return self.__state_vector[2] == self.__State.main_region_engine_active_status_ok
		if s == self.__State.main_region_engine_active_status_overloading:
			return self.__state_vector[2] == self.__State.main_region_engine_active_status_overloading
		if s == self.__State.main_region_engine_active_status_overloaded:
			return self.__state_vector[2] == self.__State.main_region_engine_active_status_overloaded
		if s == self.__State.main_region_engine_active_status_emergency_brake:
			return self.__state_vector[2] == self.__State.main_region_engine_active_status_emergency_brake
		if s == self.__State.main_region_engine_standby:
			return self.__state_vector[0] == self.__State.main_region_engine_standby
		return False
		
	def time_elapsed(self, event_id):
		"""Add time events to in event queue
		"""
		if event_id in range(7):
			self.in_event_queue.put(lambda: self.raise_time_event(event_id))
			self.run_cycle()
	
	def raise_time_event(self, event_id):
		"""Raise timed events using the event_id.
		"""
		self.__time_events[event_id] = True
	
	def __execute_queued_event(self, func):
		func()
	
	def __get_next_event(self):
		if not self.in_event_queue.empty():
			return self.in_event_queue.get()
		return None
	
	def __entry_action_main_region_engine_active_gear_neutral(self):
		"""Entry action for state 'Neutral'..
		"""
		self.system.start_engine_event_observable.next()
		
	def __entry_action_main_region_engine_active_gear_forward_gears__1st(self):
		"""Entry action for state '1st'..
		"""
		self.system.differential = 5
		self.system.gear_max = 10
		self.system.gear_min = 0
		self.system.first_gear_event_observable.next()
		
	def __entry_action_main_region_engine_active_gear_forward_gears__2nd(self):
		"""Entry action for state '2nd'..
		"""
		self.system.differential = 5
		self.system.gear_max = 30
		self.system.gear_min = 10
		self.system.second_gear_event_observable.next()
		
	def __entry_action_main_region_engine_active_gear_forward_gears__3rd(self):
		"""Entry action for state '3rd'..
		"""
		self.system.differential = 7
		self.system.gear_max = 60
		self.system.gear_min = 30
		self.system.third_gear_event_observable.next()
		
	def __entry_action_main_region_engine_active_gear_forward_gears__4th(self):
		"""Entry action for state '4th'..
		"""
		self.system.differential = 10
		self.system.gear_max = 90
		self.system.gear_min = 60
		self.system.fourth_gear_event_observable.next()
		
	def __entry_action_main_region_engine_active_gear_forward_gears__5th(self):
		"""Entry action for state '5th'..
		"""
		self.system.differential = 15
		self.system.gear_max = self.system.max_speed
		self.system.gear_min = 90
		self.system.fifth_gear_event_observable.next()
		
	def __entry_action_main_region_engine_active_speed_change_static(self):
		"""Entry action for state 'Static'..
		"""
		self.timer_service.set_timer(self, 0, (1 * 1000), True)
		self.system.static_event_observable.next()
		
	def __entry_action_main_region_engine_active_speed_change_accellerating(self):
		"""Entry action for state 'Accellerating'..
		"""
		self.timer_service.set_timer(self, 1, (1 * 1000), True)
		self.timer_service.set_timer(self, 2, (1 * 1000), True)
		self.timer_service.set_timer(self, 3, (1 * 1000), True)
		self.system.accellerating_event_observable.next()
		
	def __entry_action_main_region_engine_active_speed_change_slowing(self):
		"""Entry action for state 'Slowing'..
		"""
		self.timer_service.set_timer(self, 4, (1 * 1000), True)
		self.timer_service.set_timer(self, 5, (1 * 1000), True)
		self.timer_service.set_timer(self, 6, (1 * 1000), True)
		self.system.slowing_event_observable.next()
		
	def __entry_action_main_region_engine_active_status_ok(self):
		"""Entry action for state 'OK'..
		"""
		self.system.ok_event_observable.next()
		
	def __entry_action_main_region_engine_active_status_overloading(self):
		"""Entry action for state 'Overloading'..
		"""
		self.system.in_over_loading_proccess_event_observable.next()
		
	def __entry_action_main_region_engine_active_status_overloaded(self):
		"""Entry action for state 'Overloaded'..
		"""
		self.system.over_loaded_event_observable.next()
		
	def __entry_action_main_region_engine_active_status_emergency_brake(self):
		"""Entry action for state 'Emergency Brake'..
		"""
		self.system.emergency_brake_event_observable.next()
		
	def __entry_action_main_region_engine_standby(self):
		"""Entry action for state 'Engine_Standby'..
		"""
		self.system.engine_standby_event_observable.next()
		
	def __exit_action_main_region_engine_active_speed_change_static(self):
		"""Exit action for state 'Static'..
		"""
		self.timer_service.unset_timer(self, 0)
		
	def __exit_action_main_region_engine_active_speed_change_accellerating(self):
		"""Exit action for state 'Accellerating'..
		"""
		self.timer_service.unset_timer(self, 1)
		self.timer_service.unset_timer(self, 2)
		self.timer_service.unset_timer(self, 3)
		
	def __exit_action_main_region_engine_active_speed_change_slowing(self):
		"""Exit action for state 'Slowing'..
		"""
		self.timer_service.unset_timer(self, 4)
		self.timer_service.unset_timer(self, 5)
		self.timer_service.unset_timer(self, 6)
		
	def __enter_sequence_main_region_engine_active_default(self):
		"""'default' enter sequence for state Engine_Active.
		"""
		self.__enter_sequence_main_region_engine_active_gear_default()
		self.__enter_sequence_main_region_engine_active_speed_change_default()
		self.__enter_sequence_main_region_engine_active_status_default()
		
	def __enter_sequence_main_region_engine_active_gear_neutral_default(self):
		"""'default' enter sequence for state Neutral.
		"""
		self.__entry_action_main_region_engine_active_gear_neutral()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_neutral
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_gear_forward_default(self):
		"""'default' enter sequence for state Forward.
		"""
		self.__enter_sequence_main_region_engine_active_gear_forward_gears_default()
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears__1st_default(self):
		"""'default' enter sequence for state 1st.
		"""
		self.__entry_action_main_region_engine_active_gear_forward_gears__1st()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_forward_gears_1st
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears__2nd_default(self):
		"""'default' enter sequence for state 2nd.
		"""
		self.__entry_action_main_region_engine_active_gear_forward_gears__2nd()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_forward_gears_2nd
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears__3rd_default(self):
		"""'default' enter sequence for state 3rd.
		"""
		self.__entry_action_main_region_engine_active_gear_forward_gears__3rd()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_forward_gears_3rd
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears__4th_default(self):
		"""'default' enter sequence for state 4th.
		"""
		self.__entry_action_main_region_engine_active_gear_forward_gears__4th()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_forward_gears_4th
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears__5th_default(self):
		"""'default' enter sequence for state 5th.
		"""
		self.__entry_action_main_region_engine_active_gear_forward_gears__5th()
		self.__state_vector[0] = self.State.main_region_engine_active_gear_forward_gears_5th
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_speed_change_static_default(self):
		"""'default' enter sequence for state Static.
		"""
		self.__entry_action_main_region_engine_active_speed_change_static()
		self.__state_vector[1] = self.State.main_region_engine_active_speed_change_static
		self.__state_conf_vector_position = 1
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_speed_change_accellerating_default(self):
		"""'default' enter sequence for state Accellerating.
		"""
		self.__entry_action_main_region_engine_active_speed_change_accellerating()
		self.__state_vector[1] = self.State.main_region_engine_active_speed_change_accellerating
		self.__state_conf_vector_position = 1
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_speed_change_slowing_default(self):
		"""'default' enter sequence for state Slowing.
		"""
		self.__entry_action_main_region_engine_active_speed_change_slowing()
		self.__state_vector[1] = self.State.main_region_engine_active_speed_change_slowing
		self.__state_conf_vector_position = 1
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_status_ok_default(self):
		"""'default' enter sequence for state OK.
		"""
		self.__entry_action_main_region_engine_active_status_ok()
		self.__state_vector[2] = self.State.main_region_engine_active_status_ok
		self.__state_conf_vector_position = 2
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_status_overloading_default(self):
		"""'default' enter sequence for state Overloading.
		"""
		self.__entry_action_main_region_engine_active_status_overloading()
		self.__state_vector[2] = self.State.main_region_engine_active_status_overloading
		self.__state_conf_vector_position = 2
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_status_overloaded_default(self):
		"""'default' enter sequence for state Overloaded.
		"""
		self.__entry_action_main_region_engine_active_status_overloaded()
		self.__state_vector[2] = self.State.main_region_engine_active_status_overloaded
		self.__state_conf_vector_position = 2
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_active_status_emergency_brake_default(self):
		"""'default' enter sequence for state Emergency Brake.
		"""
		self.__entry_action_main_region_engine_active_status_emergency_brake()
		self.__state_vector[2] = self.State.main_region_engine_active_status_emergency_brake
		self.__state_conf_vector_position = 2
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_engine_standby_default(self):
		"""'default' enter sequence for state Engine_Standby.
		"""
		self.__entry_action_main_region_engine_standby()
		self.__state_vector[0] = self.State.main_region_engine_standby
		self.__state_conf_vector_position = 0
		self.__state_conf_vector_changed = True
		
	def __enter_sequence_main_region_default(self):
		"""'default' enter sequence for region main region.
		"""
		self.__react_main_region__entry_default()
		
	def __enter_sequence_main_region_engine_active_gear_default(self):
		"""'default' enter sequence for region Gear.
		"""
		self.__react_main_region_engine_active_gear__entry_default()
		
	def __enter_sequence_main_region_engine_active_gear_forward_gears_default(self):
		"""'default' enter sequence for region Gears.
		"""
		self.__react_main_region_engine_active_gear_forward_gears__entry_default()
		
	def __enter_sequence_main_region_engine_active_speed_change_default(self):
		"""'default' enter sequence for region Speed_Change.
		"""
		self.__react_main_region_engine_active_speed_change__entry_default()
		
	def __enter_sequence_main_region_engine_active_status_default(self):
		"""'default' enter sequence for region Status.
		"""
		self.__react_main_region_engine_active_status__entry_default()
		
	def __exit_sequence_main_region_engine_active(self):
		"""Default exit sequence for state Engine_Active.
		"""
		self.__exit_sequence_main_region_engine_active_gear()
		self.__exit_sequence_main_region_engine_active_speed_change()
		self.__exit_sequence_main_region_engine_active_status()
		
	def __exit_sequence_main_region_engine_active_gear_neutral(self):
		"""Default exit sequence for state Neutral.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_gear_forward(self):
		"""Default exit sequence for state Forward.
		"""
		self.__exit_sequence_main_region_engine_active_gear_forward_gears()
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears__1st(self):
		"""Default exit sequence for state 1st.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears__2nd(self):
		"""Default exit sequence for state 2nd.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears__3rd(self):
		"""Default exit sequence for state 3rd.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears__4th(self):
		"""Default exit sequence for state 4th.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears__5th(self):
		"""Default exit sequence for state 5th.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region_engine_active_speed_change_static(self):
		"""Default exit sequence for state Static.
		"""
		self.__state_vector[1] = self.State.null_state
		self.__state_conf_vector_position = 1
		self.__exit_action_main_region_engine_active_speed_change_static()
		
	def __exit_sequence_main_region_engine_active_speed_change_accellerating(self):
		"""Default exit sequence for state Accellerating.
		"""
		self.__state_vector[1] = self.State.null_state
		self.__state_conf_vector_position = 1
		self.__exit_action_main_region_engine_active_speed_change_accellerating()
		
	def __exit_sequence_main_region_engine_active_speed_change_slowing(self):
		"""Default exit sequence for state Slowing.
		"""
		self.__state_vector[1] = self.State.null_state
		self.__state_conf_vector_position = 1
		self.__exit_action_main_region_engine_active_speed_change_slowing()
		
	def __exit_sequence_main_region_engine_active_status_ok(self):
		"""Default exit sequence for state OK.
		"""
		self.__state_vector[2] = self.State.null_state
		self.__state_conf_vector_position = 2
		
	def __exit_sequence_main_region_engine_active_status_overloading(self):
		"""Default exit sequence for state Overloading.
		"""
		self.__state_vector[2] = self.State.null_state
		self.__state_conf_vector_position = 2
		
	def __exit_sequence_main_region_engine_active_status_overloaded(self):
		"""Default exit sequence for state Overloaded.
		"""
		self.__state_vector[2] = self.State.null_state
		self.__state_conf_vector_position = 2
		
	def __exit_sequence_main_region_engine_active_status_emergency_brake(self):
		"""Default exit sequence for state Emergency Brake.
		"""
		self.__state_vector[2] = self.State.null_state
		self.__state_conf_vector_position = 2
		
	def __exit_sequence_main_region_engine_standby(self):
		"""Default exit sequence for state Engine_Standby.
		"""
		self.__state_vector[0] = self.State.null_state
		self.__state_conf_vector_position = 0
		
	def __exit_sequence_main_region(self):
		"""Default exit sequence for region main region.
		"""
		state = self.__state_vector[0]
		if state == self.State.main_region_engine_active_gear_neutral:
			self.__exit_sequence_main_region_engine_active_gear_neutral()
		elif state == self.State.main_region_engine_active_gear_forward_gears_1st:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__1st()
		elif state == self.State.main_region_engine_active_gear_forward_gears_2nd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__2nd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_3rd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__3rd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_4th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__4th()
		elif state == self.State.main_region_engine_active_gear_forward_gears_5th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__5th()
		elif state == self.State.main_region_engine_standby:
			self.__exit_sequence_main_region_engine_standby()
		state = self.__state_vector[1]
		if state == self.State.main_region_engine_active_speed_change_static:
			self.__exit_sequence_main_region_engine_active_speed_change_static()
		elif state == self.State.main_region_engine_active_speed_change_accellerating:
			self.__exit_sequence_main_region_engine_active_speed_change_accellerating()
		elif state == self.State.main_region_engine_active_speed_change_slowing:
			self.__exit_sequence_main_region_engine_active_speed_change_slowing()
		state = self.__state_vector[2]
		if state == self.State.main_region_engine_active_status_ok:
			self.__exit_sequence_main_region_engine_active_status_ok()
		elif state == self.State.main_region_engine_active_status_overloading:
			self.__exit_sequence_main_region_engine_active_status_overloading()
		elif state == self.State.main_region_engine_active_status_overloaded:
			self.__exit_sequence_main_region_engine_active_status_overloaded()
		elif state == self.State.main_region_engine_active_status_emergency_brake:
			self.__exit_sequence_main_region_engine_active_status_emergency_brake()
		
	def __exit_sequence_main_region_engine_active_gear(self):
		"""Default exit sequence for region Gear.
		"""
		state = self.__state_vector[0]
		if state == self.State.main_region_engine_active_gear_neutral:
			self.__exit_sequence_main_region_engine_active_gear_neutral()
		elif state == self.State.main_region_engine_active_gear_forward_gears_1st:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__1st()
		elif state == self.State.main_region_engine_active_gear_forward_gears_2nd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__2nd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_3rd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__3rd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_4th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__4th()
		elif state == self.State.main_region_engine_active_gear_forward_gears_5th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__5th()
		
	def __exit_sequence_main_region_engine_active_gear_forward_gears(self):
		"""Default exit sequence for region Gears.
		"""
		state = self.__state_vector[0]
		if state == self.State.main_region_engine_active_gear_forward_gears_1st:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__1st()
		elif state == self.State.main_region_engine_active_gear_forward_gears_2nd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__2nd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_3rd:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__3rd()
		elif state == self.State.main_region_engine_active_gear_forward_gears_4th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__4th()
		elif state == self.State.main_region_engine_active_gear_forward_gears_5th:
			self.__exit_sequence_main_region_engine_active_gear_forward_gears__5th()
		
	def __exit_sequence_main_region_engine_active_speed_change(self):
		"""Default exit sequence for region Speed_Change.
		"""
		state = self.__state_vector[1]
		if state == self.State.main_region_engine_active_speed_change_static:
			self.__exit_sequence_main_region_engine_active_speed_change_static()
		elif state == self.State.main_region_engine_active_speed_change_accellerating:
			self.__exit_sequence_main_region_engine_active_speed_change_accellerating()
		elif state == self.State.main_region_engine_active_speed_change_slowing:
			self.__exit_sequence_main_region_engine_active_speed_change_slowing()
		
	def __exit_sequence_main_region_engine_active_status(self):
		"""Default exit sequence for region Status.
		"""
		state = self.__state_vector[2]
		if state == self.State.main_region_engine_active_status_ok:
			self.__exit_sequence_main_region_engine_active_status_ok()
		elif state == self.State.main_region_engine_active_status_overloading:
			self.__exit_sequence_main_region_engine_active_status_overloading()
		elif state == self.State.main_region_engine_active_status_overloaded:
			self.__exit_sequence_main_region_engine_active_status_overloaded()
		elif state == self.State.main_region_engine_active_status_emergency_brake:
			self.__exit_sequence_main_region_engine_active_status_emergency_brake()
		
	def __react_main_region__entry_default(self):
		"""Default react sequence for initial entry .
		"""
		self.__enter_sequence_main_region_engine_standby_default()
		
	def __react_main_region_engine_active_gear__entry_default(self):
		"""Default react sequence for initial entry .
		"""
		self.__enter_sequence_main_region_engine_active_gear_neutral_default()
		
	def __react_main_region_engine_active_gear_forward_gears__entry_default(self):
		"""Default react sequence for initial entry .
		"""
		self.__enter_sequence_main_region_engine_active_gear_forward_gears__1st_default()
		
	def __react_main_region_engine_active_speed_change__entry_default(self):
		"""Default react sequence for initial entry .
		"""
		self.__enter_sequence_main_region_engine_active_speed_change_static_default()
		
	def __react_main_region_engine_active_status__entry_default(self):
		"""Default react sequence for initial entry .
		"""
		self.__enter_sequence_main_region_engine_active_status_ok_default()
		
	def __react(self, transitioned_before):
		"""Implementation of __react function.
		"""
		return transitioned_before
	
	
	def __main_region_engine_active_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_react function.
		"""
		transitioned_after = transitioned_before
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_gear_neutral_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_neutral_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.user.gas_pressed_button) and (self.is_state_active(self.State.main_region_engine_active_status_ok)):
				self.__exit_sequence_main_region_engine_active_gear_neutral()
				self.system.speed = 0
				self.__enter_sequence_main_region_engine_active_gear_forward_default()
				transitioned_after = 0
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if self.system.speed_stop:
				self.__exit_sequence_main_region_engine_active_gear_forward()
				self.__enter_sequence_main_region_engine_active_gear_neutral_default()
				transitioned_after = 0
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_gears__1st_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_gears__1st_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_accellerating)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__1st()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__2nd_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
			elif (self.system.gear_change) and (not self.is_state_active(self.State.main_region_engine_active_speed_change_accellerating)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__1st()
				self.system.raise_speed_stop()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__1st_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_gear_forward_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_gears__2nd_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_gears__2nd_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_slowing)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__2nd()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__1st_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
			elif (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_accellerating)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__2nd()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__3rd_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_gear_forward_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_gears__3rd_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_gears__3rd_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_slowing)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__3rd()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__2nd_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
			elif (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_accellerating)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__3rd()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__4th_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_gear_forward_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_gears__4th_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_gears__4th_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_slowing)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__4th()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__3rd_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
			elif (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_accellerating)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__4th()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__5th_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_gear_forward_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_gear_forward_gears__5th_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_gear_forward_gears__5th_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if (self.system.gear_change) and (self.is_state_active(self.State.main_region_engine_active_speed_change_slowing)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__5th()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__4th_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
			elif (self.system.gear_change) and (not self.is_state_active(self.State.main_region_engine_active_speed_change_slowing)):
				self.__exit_sequence_main_region_engine_active_gear_forward_gears__5th()
				self.system.raise_max_speed_reached()
				self.__enter_sequence_main_region_engine_active_gear_forward_gears__5th_default()
				self.__main_region_engine_active_gear_forward_react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_gear_forward_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_speed_change_static_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_speed_change_static_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 1:
			if (self.user.gas_pressed_button) and (not self.is_state_active(self.State.main_region_engine_active_gear_neutral) and self.is_state_active(self.State.main_region_engine_active_status_ok)):
				self.__exit_sequence_main_region_engine_active_speed_change_static()
				self.__enter_sequence_main_region_engine_active_speed_change_accellerating_default()
				transitioned_after = 1
			elif (self.user.brake_pressed_button) and (not self.is_state_active(self.State.main_region_engine_active_gear_neutral)):
				self.__exit_sequence_main_region_engine_active_speed_change_static()
				self.__enter_sequence_main_region_engine_active_speed_change_slowing_default()
				transitioned_after = 1
			elif (self.system.emergency_brake) and (not self.is_state_active(self.State.main_region_engine_active_gear_neutral)):
				self.__exit_sequence_main_region_engine_active_speed_change_static()
				self.__enter_sequence_main_region_engine_active_speed_change_slowing_default()
				transitioned_after = 1
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			if (self.__time_events[0]) and (self.system.speed == self.system.max_speed):
				self.system.raise_max_speed_reached()
		return transitioned_after
	
	
	def __main_region_engine_active_speed_change_accellerating_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_speed_change_accellerating_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 1:
			if self.user.brake_pressed_button:
				self.__exit_sequence_main_region_engine_active_speed_change_accellerating()
				self.__enter_sequence_main_region_engine_active_speed_change_slowing_default()
				transitioned_after = 1
			elif self.user.emergency_brake_button:
				self.__exit_sequence_main_region_engine_active_speed_change_accellerating()
				self.__enter_sequence_main_region_engine_active_speed_change_slowing_default()
				transitioned_after = 1
			elif self.system.max_speed_reached:
				self.__exit_sequence_main_region_engine_active_speed_change_accellerating()
				self.system.speed = self.system.max_speed
				self.__enter_sequence_main_region_engine_active_speed_change_static_default()
				transitioned_after = 1
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			if (self.__time_events[1]) and ((self.system.speed + self.system.differential) >= self.system.max_speed):
				self.system.speed = self.system.max_speed
			if (self.__time_events[2]) and ((self.system.speed + self.system.differential) < self.system.max_speed):
				self.system.speed = self.system.speed + self.system.differential
			if (self.__time_events[3]) and (self.system.speed >= self.system.gear_max):
				self.system.raise_gear_change()
		return transitioned_after
	
	
	def __main_region_engine_active_speed_change_slowing_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_speed_change_slowing_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 1:
			if (self.user.gas_pressed_button) and (not self.is_state_active(self.State.main_region_engine_active_gear_neutral) and self.is_state_active(self.State.main_region_engine_active_status_ok)):
				self.__exit_sequence_main_region_engine_active_speed_change_slowing()
				self.__enter_sequence_main_region_engine_active_speed_change_accellerating_default()
				transitioned_after = 1
			elif self.system.speed_stop:
				self.__exit_sequence_main_region_engine_active_speed_change_slowing()
				self.system.speed = 0
				self.__enter_sequence_main_region_engine_active_speed_change_static_default()
				transitioned_after = 1
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			if (self.__time_events[4]) and ((self.system.speed - self.system.differential) <= 0):
				self.system.speed = 0
			if (self.__time_events[5]) and ((self.system.speed - self.system.differential) > 0):
				self.system.speed = self.system.speed - self.system.differential
			if (self.__time_events[6]) and (self.system.speed <= self.system.gear_min):
				self.system.raise_gear_change()
		return transitioned_after
	
	
	def __main_region_engine_active_status_ok_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_status_ok_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 2:
			if self.system.max_speed_reached:
				self.__exit_sequence_main_region_engine_active_status_ok()
				self.system.counter = 1
				self.__enter_sequence_main_region_engine_active_status_overloading_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
			elif (self.user.emergency_brake_button) and (not self.is_state_active(self.State.main_region_engine_active_gear_neutral)):
				self.__exit_sequence_main_region_engine_active_status_ok()
				self.__enter_sequence_main_region_engine_active_status_emergency_brake_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_status_overloading_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_status_overloading_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 2:
			if self.user.brake_pressed_button:
				self.__exit_sequence_main_region_engine_active_status_overloading()
				self.__enter_sequence_main_region_engine_active_status_ok_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
			elif (self.system.max_speed_reached) and (self.system.counter >= 3):
				self.__exit_sequence_main_region_engine_active_status_overloading()
				self.system.raise_emergency_brake()
				self.__enter_sequence_main_region_engine_active_status_overloaded_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
			elif self.system.max_speed_reached:
				self.__exit_sequence_main_region_engine_active_status_overloading()
				self.system.counter = self.system.counter + 1
				self.__enter_sequence_main_region_engine_active_status_overloading_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_status_overloaded_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_status_overloaded_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 2:
			if self.system.speed_stop:
				self.__exit_sequence_main_region_engine_active()
				self.__enter_sequence_main_region_engine_standby_default()
				self.__react(0)
				transitioned_after = 2
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_active_status_emergency_brake_react(self, transitioned_before):
		"""Implementation of __main_region_engine_active_status_emergency_brake_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 2:
			if self.system.speed_stop:
				self.__exit_sequence_main_region_engine_active_status_emergency_brake()
				self.__enter_sequence_main_region_engine_active_status_ok_default()
				self.__main_region_engine_active_react(0)
				transitioned_after = 2
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__main_region_engine_active_react(transitioned_before)
		return transitioned_after
	
	
	def __main_region_engine_standby_react(self, transitioned_before):
		"""Implementation of __main_region_engine_standby_react function.
		"""
		transitioned_after = transitioned_before
		if transitioned_after < 0:
			if self.user.start_engine_button:
				self.__exit_sequence_main_region_engine_standby()
				self.__enter_sequence_main_region_engine_active_default()
				self.__react(0)
				transitioned_after = 0
		#If no transition was taken then execute local reactions
		if transitioned_after == transitioned_before:
			transitioned_after = self.__react(transitioned_before)
		return transitioned_after
	
	
	def __clear_in_events(self):
		"""Implementation of __clear_in_events function.
		"""
		self.user.start_engine_button = False
		self.user.brake_pressed_button = False
		self.user.gas_pressed_button = False
		self.user.emergency_brake_button = False
		self.system.emergency_brake = False
		self.system.max_speed_reached = False
		self.system.speed_stop = False
		self.system.gear_change = False
		self.__time_events[0] = False
		self.__time_events[1] = False
		self.__time_events[2] = False
		self.__time_events[3] = False
		self.__time_events[4] = False
		self.__time_events[5] = False
		self.__time_events[6] = False
	
	
	def __micro_step(self):
		"""Implementation of __micro_step function.
		"""
		transitioned = -1
		self.__state_conf_vector_position = 0
		state = self.__state_vector[0]
		if state == self.State.main_region_engine_active_gear_neutral:
			transitioned = self.__main_region_engine_active_gear_neutral_react(transitioned)
		elif state == self.State.main_region_engine_active_gear_forward_gears_1st:
			transitioned = self.__main_region_engine_active_gear_forward_gears__1st_react(transitioned)
		elif state == self.State.main_region_engine_active_gear_forward_gears_2nd:
			transitioned = self.__main_region_engine_active_gear_forward_gears__2nd_react(transitioned)
		elif state == self.State.main_region_engine_active_gear_forward_gears_3rd:
			transitioned = self.__main_region_engine_active_gear_forward_gears__3rd_react(transitioned)
		elif state == self.State.main_region_engine_active_gear_forward_gears_4th:
			transitioned = self.__main_region_engine_active_gear_forward_gears__4th_react(transitioned)
		elif state == self.State.main_region_engine_active_gear_forward_gears_5th:
			transitioned = self.__main_region_engine_active_gear_forward_gears__5th_react(transitioned)
		elif state == self.State.main_region_engine_standby:
			transitioned = self.__main_region_engine_standby_react(transitioned)
		if self.__state_conf_vector_position < 1:
			state = self.__state_vector[1]
			if state == self.State.main_region_engine_active_speed_change_static:
				transitioned = self.__main_region_engine_active_speed_change_static_react(transitioned)
			elif state == self.State.main_region_engine_active_speed_change_accellerating:
				transitioned = self.__main_region_engine_active_speed_change_accellerating_react(transitioned)
			elif state == self.State.main_region_engine_active_speed_change_slowing:
				transitioned = self.__main_region_engine_active_speed_change_slowing_react(transitioned)
		if self.__state_conf_vector_position < 2:
			state = self.__state_vector[2]
			if state == self.State.main_region_engine_active_status_ok:
				transitioned = self.__main_region_engine_active_status_ok_react(transitioned)
			elif state == self.State.main_region_engine_active_status_overloading:
				transitioned = self.__main_region_engine_active_status_overloading_react(transitioned)
			elif state == self.State.main_region_engine_active_status_overloaded:
				transitioned = self.__main_region_engine_active_status_overloaded_react(transitioned)
			elif state == self.State.main_region_engine_active_status_emergency_brake:
				transitioned = self.__main_region_engine_active_status_emergency_brake_react(transitioned)
	
	
	def run_cycle(self):
		"""Implementation of run_cycle function.
		"""
		if self.timer_service is None:
			raise ValueError('Timer service must be set.')
		
		if self.__is_executing:
			return
		self.__is_executing = True
		next_event = self.__get_next_event()
		if next_event is not None:
			self.__execute_queued_event(next_event)
		condition_0 = True
		while condition_0:
			self.__micro_step()
			self.__clear_in_events()
			next_event = self.__get_next_event()
			if next_event is not None:
				self.__execute_queued_event(next_event)
			condition_0 = self.user.start_engine_button or self.user.brake_pressed_button or self.user.gas_pressed_button or self.user.emergency_brake_button or self.system.emergency_brake or self.system.max_speed_reached or self.system.speed_stop or self.system.gear_change or self.__time_events[0] or self.__time_events[1] or self.__time_events[2] or self.__time_events[3] or self.__time_events[4] or self.__time_events[5] or self.__time_events[6]
		self.__is_executing = False
	
	
	def enter(self):
		"""Implementation of enter function.
		"""
		if self.timer_service is None:
			raise ValueError('Timer service must be set.')
		
		if self.__is_executing:
			return
		self.__is_executing = True
		self.__enter_sequence_main_region_default()
		self.__is_executing = False
	
	
	def exit(self):
		"""Implementation of exit function.
		"""
		if self.__is_executing:
			return
		self.__is_executing = True
		self.__exit_sequence_main_region()
		self.__is_executing = False
	
	
	
