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

Date:   Wed Nov 09 17:14:30 2016

Model author: Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo
Model name:   CBDSimulator_Coordinator
Model description:
A debuggeable CBD simulator.
"""

from sccd.runtime.statecharts_core import *
from sccd.runtime.libs.ui import *
from sccd.runtime.libs.utils import *
from CBD_Controller import CBDController
import Options
import sccd.runtime.accurate_time as accurate_time

class Breakpoint:
    def __init__(self, name, function, enabled, disable_on_trigger):
        self.name = name
        self.function = function
        self.enabled = enabled
        self.disable_on_trigger = disable_on_trigger

# package "CBDSimulator_Coordinator"

class CBDSimulator_Coordinator(RuntimeClassBase):
    def __init__(self, controller, options, model):
        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
        CBDSimulator_Coordinator.user_defined_constructor(self, options, model)
    
    def user_defined_constructor(self, options, model):
        self.options = options
        self.model = model
    
    def user_defined_destructor(self):
        pass
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /Main
        self.states["/Main"] = ParallelState(1, "/Main", self)
        
        # state /Main/ModeSelector
        self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
        
        # state /Main/ModeSelector/Paused
        self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
        
        # state /Main/ModeSelector/Running
        self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
        
        # state /Main/ModeSelector/Running/Continuous
        self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
        
        # state /Main/ModeSelector/Running/Realtime
        self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
        
        # state /Main/ModeSelector/Running/BigStep
        self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
        
        # state /Main/ModeSelector/Running/SmallStep
        self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
        
        # state /Main/ModeSelector/WaitingForPaused
        self.states["/Main/ModeSelector/WaitingForPaused"] = State(9, "/Main/ModeSelector/WaitingForPaused", self)
        
        # state /Main/ModeSelector/Stopped
        self.states["/Main/ModeSelector/Stopped"] = State(10, "/Main/ModeSelector/Stopped", self)
        
        # state /Main/ChildState
        self.states["/Main/ChildState"] = State(11, "/Main/ChildState", self)
        
        # state /Main/ChildState/Uninitialized
        self.states["/Main/ChildState/Uninitialized"] = State(12, "/Main/ChildState/Uninitialized", self)
        
        # state /Main/ChildState/Initialized
        self.states["/Main/ChildState/Initialized"] = State(13, "/Main/ChildState/Initialized", self)
        
        # state /Main/Initializer
        self.states["/Main/Initializer"] = State(14, "/Main/Initializer", self)
        
        # state /Main/Initializer/Waiting
        self.states["/Main/Initializer/Waiting"] = State(15, "/Main/Initializer/Waiting", self)
        
        # state /Main/Initializer/CreatingChildSimulator
        self.states["/Main/Initializer/CreatingChildSimulator"] = State(16, "/Main/Initializer/CreatingChildSimulator", self)
        
        # state /Main/Initializer/StartingChildSimulator
        self.states["/Main/Initializer/StartingChildSimulator"] = State(17, "/Main/Initializer/StartingChildSimulator", self)
        
        # state /Main/SimulationFlow
        self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
        
        # state /Main/SimulationFlow/PrePaused
        self.states["/Main/SimulationFlow/PrePaused"] = State(19, "/Main/SimulationFlow/PrePaused", self)
        self.states["/Main/SimulationFlow/PrePaused"].setEnter(self._Main_SimulationFlow_PrePaused_enter)
        self.states["/Main/SimulationFlow/PrePaused"].setExit(self._Main_SimulationFlow_PrePaused_exit)
        
        # state /Main/SimulationFlow/Paused
        self.states["/Main/SimulationFlow/Paused"] = State(20, "/Main/SimulationFlow/Paused", self)
        
        # state /Main/SimulationFlow/Executing
        self.states["/Main/SimulationFlow/Executing"] = State(21, "/Main/SimulationFlow/Executing", self)
        
        # state /Main/GodEventManager
        self.states["/Main/GodEventManager"] = State(22, "/Main/GodEventManager", self)
        
        # state /Main/GodEventManager/Listening
        self.states["/Main/GodEventManager/Listening"] = State(23, "/Main/GodEventManager/Listening", self)
        
        # state /Main/GodEventManager/Waiting
        self.states["/Main/GodEventManager/Waiting"] = State(24, "/Main/GodEventManager/Waiting", self)
        
        # state /Main/BreakpointManager
        self.states["/Main/BreakpointManager"] = State(25, "/Main/BreakpointManager", self)
        
        # state /Main/BreakpointManager/Listening
        self.states["/Main/BreakpointManager/Listening"] = State(26, "/Main/BreakpointManager/Listening", self)
        
        # state /Main/BreakpointManager/Waiting
        self.states["/Main/BreakpointManager/Waiting"] = State(27, "/Main/BreakpointManager/Waiting", self)
        
        # add children
        self.states[""].addChild(self.states["/Main"])
        self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
        self.states["/Main"].addChild(self.states["/Main/ChildState"])
        self.states["/Main"].addChild(self.states["/Main/Initializer"])
        self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
        self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
        self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/WaitingForPaused"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Stopped"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/PrePaused"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Paused"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
        self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
        self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Waiting"])
        self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
        self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Waiting"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Main"]
        self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
        self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
        self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
        self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
        self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Paused"]
        self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
        self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
        
        # transition /Main/ModeSelector/Paused
        _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
        _Main_ModeSelector_Paused_0.setTrigger(Event("small_step", "user_input"))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
        _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
        _Main_ModeSelector_Paused_1.setTrigger(Event("big_step", "user_input"))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
        _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
        _Main_ModeSelector_Paused_2.setTrigger(Event("continuous", "user_input"))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
        _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
        _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
        _Main_ModeSelector_Paused_3.setTrigger(Event("realtime", "user_input"))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
        _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
        _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
        _Main_ModeSelector_Paused_5 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Paused_5.setAction(self._Main_ModeSelector_Paused_5_exec)
        _Main_ModeSelector_Paused_5.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_5)
        
        # transition /Main/ModeSelector/Running/Continuous
        _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
        _Main_ModeSelector_Running_Continuous_0.setAction(self._Main_ModeSelector_Running_Continuous_0_exec)
        _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("pause", "user_input"))
        self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
        _Main_ModeSelector_Running_Continuous_1 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Stopped"]])
        _Main_ModeSelector_Running_Continuous_1.setAction(self._Main_ModeSelector_Running_Continuous_1_exec)
        _Main_ModeSelector_Running_Continuous_1.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_1)
        
        # transition /Main/ModeSelector/Running/Realtime
        _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
        _Main_ModeSelector_Running_Realtime_0.setAction(self._Main_ModeSelector_Running_Realtime_0_exec)
        _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("pause", "user_input"))
        self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
        _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Stopped"]])
        _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
        _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
        _Main_ModeSelector_Running_Realtime_2 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
        _Main_ModeSelector_Running_Realtime_2.setAction(self._Main_ModeSelector_Running_Realtime_2_exec)
        _Main_ModeSelector_Running_Realtime_2.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_2)
        
        # transition /Main/ModeSelector/Running/BigStep
        _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
        _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
        _Main_ModeSelector_Running_BigStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Stopped"]])
        _Main_ModeSelector_Running_BigStep_1.setAction(self._Main_ModeSelector_Running_BigStep_1_exec)
        _Main_ModeSelector_Running_BigStep_1.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_1)
        
        # transition /Main/ModeSelector/Running/SmallStep
        _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
        _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
        _Main_ModeSelector_Running_SmallStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_SmallStep_1.setAction(self._Main_ModeSelector_Running_SmallStep_1_exec)
        _Main_ModeSelector_Running_SmallStep_1.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_1)
        _Main_ModeSelector_Running_SmallStep_2 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Stopped"]])
        _Main_ModeSelector_Running_SmallStep_2.setAction(self._Main_ModeSelector_Running_SmallStep_2_exec)
        _Main_ModeSelector_Running_SmallStep_2.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_2)
        
        # transition /Main/ModeSelector/WaitingForPaused
        _Main_ModeSelector_WaitingForPaused_0 = Transition(self, self.states["/Main/ModeSelector/WaitingForPaused"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_WaitingForPaused_0.setAction(self._Main_ModeSelector_WaitingForPaused_0_exec)
        _Main_ModeSelector_WaitingForPaused_0.setTrigger(Event("Simulation.Paused", None))
        self.states["/Main/ModeSelector/WaitingForPaused"].addTransition(_Main_ModeSelector_WaitingForPaused_0)
        
        # transition /Main/ChildState/Uninitialized
        _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
        _Main_ChildState_Uninitialized_0.setTrigger(Event("Simulation.Initialized", None))
        self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
        
        # transition /Main/ChildState/Initialized
        _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
        _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
        _Main_ChildState_Initialized_0.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
        
        # transition /Main/Initializer/Waiting
        _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
        _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
        _Main_Initializer_Waiting_0.setTrigger(None)
        _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
        self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
        
        # transition /Main/Initializer/CreatingChildSimulator
        _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
        _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
        _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
        self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
        
        # transition /Main/Initializer/StartingChildSimulator
        _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Waiting"]])
        _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Simulation.Initialized", None))
        self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
        
        # transition /Main/SimulationFlow/PrePaused
        _Main_SimulationFlow_PrePaused_0 = Transition(self, self.states["/Main/SimulationFlow/PrePaused"], [self.states["/Main/SimulationFlow/Paused"]])
        _Main_SimulationFlow_PrePaused_0.setTrigger(Event("_0after"))
        self.states["/Main/SimulationFlow/PrePaused"].addTransition(_Main_SimulationFlow_PrePaused_0)
        
        # transition /Main/SimulationFlow/Paused
        _Main_SimulationFlow_Paused_0 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_Paused_0.setAction(self._Main_SimulationFlow_Paused_0_exec)
        _Main_SimulationFlow_Paused_0.setTrigger(None)
        _Main_SimulationFlow_Paused_0.setGuard(self._Main_SimulationFlow_Paused_0_guard)
        self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_0)
        _Main_SimulationFlow_Paused_1 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_Paused_1.setAction(self._Main_SimulationFlow_Paused_1_exec)
        _Main_SimulationFlow_Paused_1.setTrigger(None)
        _Main_SimulationFlow_Paused_1.setGuard(self._Main_SimulationFlow_Paused_1_guard)
        self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_1)
        _Main_SimulationFlow_Paused_2 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_Paused_2.setAction(self._Main_SimulationFlow_Paused_2_exec)
        _Main_SimulationFlow_Paused_2.setTrigger(None)
        _Main_SimulationFlow_Paused_2.setGuard(self._Main_SimulationFlow_Paused_2_guard)
        self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_2)
        _Main_SimulationFlow_Paused_3 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_Paused_3.setAction(self._Main_SimulationFlow_Paused_3_exec)
        _Main_SimulationFlow_Paused_3.setTrigger(None)
        _Main_SimulationFlow_Paused_3.setGuard(self._Main_SimulationFlow_Paused_3_guard)
        self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_3)
        
        # transition /Main/SimulationFlow/Executing
        _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/Paused"]])
        _Main_SimulationFlow_Executing_0.setTrigger(None)
        _Main_SimulationFlow_Executing_0.setGuard(self._Main_SimulationFlow_Executing_0_guard)
        self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
        _Main_SimulationFlow_Executing_1 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/PrePaused"]])
        _Main_SimulationFlow_Executing_1.setTrigger(Event("Simulation.Finished", None))
        _Main_SimulationFlow_Executing_1.setGuard(self._Main_SimulationFlow_Executing_1_guard)
        self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_1)
        
        # transition /Main/GodEventManager/Listening
        _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Waiting"]])
        _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
        _Main_GodEventManager_Listening_0.setTrigger(Event("god_event", "user_input"))
        _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
        self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
        
        # transition /Main/GodEventManager/Waiting
        _Main_GodEventManager_Waiting_0 = Transition(self, self.states["/Main/GodEventManager/Waiting"], [self.states["/Main/GodEventManager/Listening"]])
        _Main_GodEventManager_Waiting_0.setAction(self._Main_GodEventManager_Waiting_0_exec)
        _Main_GodEventManager_Waiting_0.setTrigger(Event("Simulation.GodEventResult", None))
        self.states["/Main/GodEventManager/Waiting"].addTransition(_Main_GodEventManager_Waiting_0)
        
        # transition /Main/BreakpointManager/Listening
        _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
        _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
        _Main_BreakpointManager_Listening_0.setTrigger(Event("add_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
        _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
        _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
        _Main_BreakpointManager_Listening_1.setTrigger(Event("del_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
        _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
        _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
        _Main_BreakpointManager_Listening_2.setTrigger(Event("toggle_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
        _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
        _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
        _Main_BreakpointManager_Listening_3.setTrigger(Event("list_breakpoints", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
        
        # transition /Main/BreakpointManager/Waiting
        _Main_BreakpointManager_Waiting_0 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Waiting_0.setAction(self._Main_BreakpointManager_Waiting_0_exec)
        _Main_BreakpointManager_Waiting_0.setTrigger(Event("Breakpoint.AddResult", None))
        self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_0)
        _Main_BreakpointManager_Waiting_1 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Waiting_1.setAction(self._Main_BreakpointManager_Waiting_1_exec)
        _Main_BreakpointManager_Waiting_1.setTrigger(Event("Breakpoint.DelResult", None))
        self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_1)
        _Main_BreakpointManager_Waiting_2 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Waiting_2.setAction(self._Main_BreakpointManager_Waiting_2_exec)
        _Main_BreakpointManager_Waiting_2.setTrigger(Event("Breakpoint.ToggleResult", None))
        self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_2)
        _Main_BreakpointManager_Waiting_3 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Waiting_3.setAction(self._Main_BreakpointManager_Waiting_3_exec)
        _Main_BreakpointManager_Waiting_3.setTrigger(Event("Breakpoint.ListResult", None))
        self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_3)
        
        # transition /Main/ModeSelector/Running
        _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_0.setAction(self._Main_ModeSelector_Running_0_exec)
        _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
        _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
        _Main_ModeSelector_Running_1.setTrigger(Event("Breakpoint.Triggered", None))
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
    
    def _Main_SimulationFlow_PrePaused_enter(self):
        self.addTimer(0, self.sccd_yield())
    
    def _Main_SimulationFlow_PrePaused_exit(self):
        self.removeTimer(0)
    
    def _Main_ModeSelector_Running_0_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_1_exec(self, parameters):
        triggered_bp = parameters[0]
        clock = parameters[1]
        state = parameters[2]
        self.big_step.outputEvent(Event("Breakpoint.Triggered", "user_output", [triggered_bp, clock]))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Paused_3_exec(self, parameters):
        realtime_scale = parameters[0]
        self.realtime_scale = float(realtime_scale)
    
    def _Main_ModeSelector_Paused_4_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Paused_5_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_Continuous_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
    
    def _Main_ModeSelector_Running_Continuous_1_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_Realtime_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
    
    def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_Realtime_2_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_BigStep_1_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
        current_component_idx = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("SmallStep.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [current_component_idx]))
    
    def _Main_ModeSelector_Running_SmallStep_1_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_Running_SmallStep_2_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ModeSelector_WaitingForPaused_0_exec(self, parameters):
        clock = parameters[0]
        state = parameters[1]
        self.big_step.outputEvent(Event("Simulation.Paused", "user_output", []))
        self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
    
    def _Main_ChildState_Initialized_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
    
    def _Main_Initializer_Waiting_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Simulation', self.options, self.model]))
    
    def _Main_Initializer_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ChildState/Uninitialized"])
    
    def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
    
    def _Main_SimulationFlow_Paused_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Execute", None, [])]))
    
    def _Main_SimulationFlow_Paused_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"])
    
    def _Main_SimulationFlow_Paused_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.ExecuteRealtime", None, [self.realtime_scale])]))
    
    def _Main_SimulationFlow_Paused_1_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"])
    
    def _Main_SimulationFlow_Paused_2_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_Paused_2_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/BigStep"]) and self.inState(["/Main/ChildState/Initialized"])
    
    def _Main_SimulationFlow_Paused_3_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_Paused_3_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"])
    
    def _Main_SimulationFlow_Executing_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Paused"])
    
    def _Main_SimulationFlow_Executing_1_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/Realtime"])
    
    def _Main_GodEventManager_Listening_0_exec(self, parameters):
        block_name = parameters[0]
        new_val = parameters[1]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.GodEvent", None, [block_name, new_val])]))
    
    def _Main_GodEventManager_Listening_0_guard(self, parameters):
        block_name = parameters[0]
        new_val = parameters[1]
        return self.inState(["/Main/ModeSelector/Paused"])
    
    def _Main_GodEventManager_Waiting_0_exec(self, parameters):
        result = parameters[0]
        self.big_step.outputEvent(Event("GodEventResult", "user_output", [result]))
    
    def _Main_BreakpointManager_Listening_0_exec(self, parameters):
        name = parameters[0]
        function = parameters[1]
        enabled = parameters[2]
        disable_on_trigger = parameters[3]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Add", None, [name, function, enabled, disable_on_trigger])]))
    
    def _Main_BreakpointManager_Listening_1_exec(self, parameters):
        name = parameters[0]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Del", None, [name])]))
    
    def _Main_BreakpointManager_Listening_2_exec(self, parameters):
        name = parameters[0]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Toggle", None, [name])]))
    
    def _Main_BreakpointManager_Listening_3_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.List", None, [])]))
    
    def _Main_BreakpointManager_Waiting_0_exec(self, parameters):
        result = parameters[0]
        self.big_step.outputEvent(Event("Breakpoint.AddResult", "user_output", [result]))
    
    def _Main_BreakpointManager_Waiting_1_exec(self, parameters):
        result = parameters[0]
        self.big_step.outputEvent(Event("Breakpoint.DelResult", "user_output", [result]))
    
    def _Main_BreakpointManager_Waiting_2_exec(self, parameters):
        result = parameters[0]
        self.big_step.outputEvent(Event("Breakpoint.ToggleResult", "user_output", [result]))
    
    def _Main_BreakpointManager_Waiting_3_exec(self, parameters):
        result = parameters[0]
        self.big_step.outputEvent(Event("Breakpoint.ListResult", "user_output", [result]))
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Main"].getEffectiveTargetStates()
        RuntimeClassBase.initializeStatechart(self)

class CBDSimulator_Simulation(RuntimeClassBase):
    def __init__(self, controller, options, model):
        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
        CBDSimulator_Simulation.user_defined_constructor(self, options, model)
    
    def user_defined_constructor(self, options, model):
        self.options = options
        self.delta = self.options.getDeltaT() * 1000.0 # in miliseconds for real-time simulation
        self.model = model
        self.initialized = False
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def initialize(self):
        self.iteration = 0
        self.clock = 0
        self.time_next = self.delta
        self.cbd_controller = CBDController(self.model, self.delta / 1000.0)
        self.cbd_controller.initSimulation()
        self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
        self.initialized = True
    
    
    # user defined method
    def endCondition(self):
        return self.initialized and self.iteration >= self.options.getMaxIterations()
    
    
    # user defined method
    def finalize(self):
        from bokeh.plotting import figure, output_file, show    
        times = []
        values = []
        for timeValuePair in self.model.getSignal("neg"):
            times.append(timeValuePair.time)
            values.append(timeValuePair.value)
        
        output_file("./plot.html", title="Plot")
        p = figure(title="Something vs Otherthing", x_axis_label="Time", y_axis_label="Values")
        p.line(times, values, legend="Something", line_width=1, line_color="red")
        show(p)
        print 'Simulation finalized.'
    
    
    # user defined method
    def initializeDebugger(self):
        self.breakpoints = []
        self.triggered_bp = None
    
    
    # user defined method
    def waitTime(self):
        # First, we convert from wall-clock time to simulated time.
        # This means the elapsed time in wall-clock time needs to be scaled according to the realtime scale (for example, if the realtime scale is 2, an elapsed time of 1 second in wall-clock time is equal to an elapsed time of 2 seconds in simulated time).
        simulated_diff = (accurate_time.time() - self.realtime_start_time) * self.realtime_scale
        # time_next and simulated_diff are both in simulated time: so now scale back to wall-clock time by dividing.
        # This function returns an amount of miliseconds.
        return ((self.time_next - simulated_diff) / self.realtime_scale)
    
    
    # user defined method
    def syncSimulatedTime(self):
        diff = accurate_time.time() - self.realtime_start_time
        self.clock = diff * self.realtime_scale
    
    
    # user defined method
    def addBreakpoint(self, name, function, enabled = None, disable_on_trigger = None):
        if enabled == None: enabled = true
        if disable_on_trigger == None: disable_on_trigger = true
        if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
            return -1
        self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
        return 0
    
    
    # user defined method
    def delBreakpoint(self, name):
        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
            return -1
        self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
        return 0
    
    
    # user defined method
    def toggleBreakpoint(self, name):
        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
            return -1
        for bp in self.breakpoints:
            if bp.name == name:
                bp.enabled = enabled
                break
        return 0
    
    
    # user defined method
    def breakpointTriggers(self, is_realtime_simulation):
        self.triggered_bp = None
        for bp in self.breakpoints:
            if not bp.enabled:
                continue
            # include the function in the scope...
            exec(bp.function)
            # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
            # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
            # this is to make sure that the simulation is stopped BEFORE the specified time is reached, and not AFTER (because we don't necessarily implement 'step back')
            # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
            if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.state}):
                # triggered!
                self.triggered_bp = bp.name
                if bp.disable_on_trigger:
                    bp.enabled = False
                return True
            else:
                # not triggered, so continue
                continue
        return False
    
    
    # user defined method
    def godEvent(self, block_name, new_val):
        if not self.initialized:
            return -1
        if block_name not in self.state:
            return -1
        for b in self.model.getBlocks():
            if b.getBlockName() == block_name:
                b.setSignal(new_val)
        self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
        return 0
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /Main
        self.states["/Main"] = ParallelState(1, "/Main", self)
        
        # state /Main/ModeSelector
        self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
        
        # state /Main/ModeSelector/Paused
        self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
        
        # state /Main/ModeSelector/Running
        self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
        
        # state /Main/ModeSelector/Running/Continuous
        self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
        
        # state /Main/ModeSelector/Running/Realtime
        self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
        
        # state /Main/ModeSelector/Running/BigStep
        self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
        
        # state /Main/ModeSelector/Running/SmallStep
        self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
        
        # state /Main/ChildState
        self.states["/Main/ChildState"] = State(9, "/Main/ChildState", self)
        
        # state /Main/ChildState/Uninitialized
        self.states["/Main/ChildState/Uninitialized"] = State(10, "/Main/ChildState/Uninitialized", self)
        
        # state /Main/ChildState/Initialized
        self.states["/Main/ChildState/Initialized"] = State(11, "/Main/ChildState/Initialized", self)
        
        # state /Main/Initializer
        self.states["/Main/Initializer"] = State(12, "/Main/Initializer", self)
        
        # state /Main/Initializer/Waiting
        self.states["/Main/Initializer/Waiting"] = State(13, "/Main/Initializer/Waiting", self)
        
        # state /Main/Initializer/CreatingChildSimulator
        self.states["/Main/Initializer/CreatingChildSimulator"] = State(14, "/Main/Initializer/CreatingChildSimulator", self)
        
        # state /Main/Initializer/StartingChildSimulator
        self.states["/Main/Initializer/StartingChildSimulator"] = State(15, "/Main/Initializer/StartingChildSimulator", self)
        
        # state /Main/Initializer/Running
        self.states["/Main/Initializer/Running"] = State(16, "/Main/Initializer/Running", self)
        
        # state /Main/Initializer/SettleBeforeWaiting
        self.states["/Main/Initializer/SettleBeforeWaiting"] = State(17, "/Main/Initializer/SettleBeforeWaiting", self)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
        
        # state /Main/SimulationFlow
        self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
        
        # state /Main/SimulationFlow/Started
        self.states["/Main/SimulationFlow/Started"] = State(19, "/Main/SimulationFlow/Started", self)
        
        # state /Main/SimulationFlow/Initialized
        self.states["/Main/SimulationFlow/Initialized"] = State(20, "/Main/SimulationFlow/Initialized", self)
        
        # state /Main/SimulationFlow/InitializeDebugger
        self.states["/Main/SimulationFlow/InitializeDebugger"] = State(21, "/Main/SimulationFlow/InitializeDebugger", self)
        
        # state /Main/SimulationFlow/Waiting
        self.states["/Main/SimulationFlow/Waiting"] = State(22, "/Main/SimulationFlow/Waiting", self)
        
        # state /Main/SimulationFlow/SettleBeforeCheckTermination
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(23, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
        
        # state /Main/SimulationFlow/CheckTermination
        self.states["/Main/SimulationFlow/CheckTermination"] = State(24, "/Main/SimulationFlow/CheckTermination", self)
        
        # state /Main/SimulationFlow/WaitingRealtime
        self.states["/Main/SimulationFlow/WaitingRealtime"] = State(25, "/Main/SimulationFlow/WaitingRealtime", self)
        self.states["/Main/SimulationFlow/WaitingRealtime"].setEnter(self._Main_SimulationFlow_WaitingRealtime_enter)
        self.states["/Main/SimulationFlow/WaitingRealtime"].setExit(self._Main_SimulationFlow_WaitingRealtime_exit)
        
        # state /Main/SimulationFlow/Executing
        self.states["/Main/SimulationFlow/Executing"] = State(26, "/Main/SimulationFlow/Executing", self)
        
        # state /Main/SimulationFlow/Stopped
        self.states["/Main/SimulationFlow/Stopped"] = State(27, "/Main/SimulationFlow/Stopped", self)
        
        # state /Main/GodEventManager
        self.states["/Main/GodEventManager"] = State(28, "/Main/GodEventManager", self)
        
        # state /Main/GodEventManager/Listening
        self.states["/Main/GodEventManager/Listening"] = State(29, "/Main/GodEventManager/Listening", self)
        
        # state /Main/BreakpointManager
        self.states["/Main/BreakpointManager"] = State(30, "/Main/BreakpointManager", self)
        
        # state /Main/BreakpointManager/Listening
        self.states["/Main/BreakpointManager/Listening"] = State(31, "/Main/BreakpointManager/Listening", self)
        
        # state /Stopped
        self.states["/Stopped"] = State(32, "/Stopped", self)
        
        # add children
        self.states[""].addChild(self.states["/Main"])
        self.states[""].addChild(self.states["/Stopped"])
        self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
        self.states["/Main"].addChild(self.states["/Main/ChildState"])
        self.states["/Main"].addChild(self.states["/Main/Initializer"])
        self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
        self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
        self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/WaitingRealtime"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
        self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
        self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Main"]
        self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
        self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
        self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
        self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
        self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
        self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
        self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
        
        # transition /Main/ModeSelector/Paused
        _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
        _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
        _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
        _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
        _Main_ModeSelector_Paused_1.setAction(self._Main_ModeSelector_Paused_1_exec)
        _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
        _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
        _Main_ModeSelector_Paused_2.setTrigger(Event("Simulation.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
        _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
        _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
        _Main_ModeSelector_Paused_3.setTrigger(Event("Simulation.ExecuteRealtime", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
        _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
        _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
        
        # transition /Main/ModeSelector/Running/Continuous
        _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("Simulation.Pause", None))
        self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
        
        # transition /Main/ModeSelector/Running/Realtime
        _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("Simulation.Pause", None))
        self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
        _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
        _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
        _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
        
        # transition /Main/ModeSelector/Running/BigStep
        _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
        _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
        
        # transition /Main/ModeSelector/Running/SmallStep
        _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
        _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
        
        # transition /Main/ChildState/Uninitialized
        _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
        _Main_ChildState_Uninitialized_0.setTrigger(Event("BigStep.Initialized", None))
        self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
        
        # transition /Main/ChildState/Initialized
        _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
        _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
        _Main_ChildState_Initialized_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
        
        # transition /Main/Initializer/Waiting
        _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
        _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
        _Main_Initializer_Waiting_0.setTrigger(None)
        _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
        self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
        
        # transition /Main/Initializer/CreatingChildSimulator
        _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
        _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
        _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
        self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
        
        # transition /Main/Initializer/StartingChildSimulator
        _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
        _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("BigStep.Initialized", None))
        self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
        
        # transition /Main/Initializer/Running
        _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
        _Main_Initializer_Running_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
        
        # transition /Main/Initializer/SettleBeforeWaiting
        _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
        _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
        self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
        
        # transition /Main/SimulationFlow/Started
        _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
        _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
        _Main_SimulationFlow_Started_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
        
        # transition /Main/SimulationFlow/Initialized
        _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
        _Main_SimulationFlow_Initialized_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
        
        # transition /Main/SimulationFlow/InitializeDebugger
        _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
        _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
        _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
        self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
        
        # transition /Main/SimulationFlow/Waiting
        _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_Waiting_0.setTrigger(None)
        _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
        self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
        
        # transition /Main/SimulationFlow/SettleBeforeCheckTermination
        _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
        _Main_SimulationFlow_SettleBeforeCheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_SettleBeforeCheckTermination_1.setAction(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_exec)
        _Main_SimulationFlow_SettleBeforeCheckTermination_1.setTrigger(None)
        _Main_SimulationFlow_SettleBeforeCheckTermination_1.setGuard(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_guard)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_1)
        
        # transition /Main/SimulationFlow/CheckTermination
        _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
        _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
        _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
        _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
        _Main_SimulationFlow_CheckTermination_2 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/WaitingRealtime"]])
        _Main_SimulationFlow_CheckTermination_2.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_2.setGuard(self._Main_SimulationFlow_CheckTermination_2_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_2)
        _Main_SimulationFlow_CheckTermination_3 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
        _Main_SimulationFlow_CheckTermination_3.setAction(self._Main_SimulationFlow_CheckTermination_3_exec)
        _Main_SimulationFlow_CheckTermination_3.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_3.setGuard(self._Main_SimulationFlow_CheckTermination_3_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_3)
        
        # transition /Main/SimulationFlow/WaitingRealtime
        _Main_SimulationFlow_WaitingRealtime_0 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_WaitingRealtime_0.setAction(self._Main_SimulationFlow_WaitingRealtime_0_exec)
        _Main_SimulationFlow_WaitingRealtime_0.setTrigger(Event("_2after"))
        _Main_SimulationFlow_WaitingRealtime_0.setGuard(self._Main_SimulationFlow_WaitingRealtime_0_guard)
        self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_0)
        _Main_SimulationFlow_WaitingRealtime_1 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_WaitingRealtime_1.setAction(self._Main_SimulationFlow_WaitingRealtime_1_exec)
        _Main_SimulationFlow_WaitingRealtime_1.setTrigger(None)
        _Main_SimulationFlow_WaitingRealtime_1.setGuard(self._Main_SimulationFlow_WaitingRealtime_1_guard)
        self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_1)
        _Main_SimulationFlow_WaitingRealtime_2 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_WaitingRealtime_2.setAction(self._Main_SimulationFlow_WaitingRealtime_2_exec)
        _Main_SimulationFlow_WaitingRealtime_2.setTrigger(None)
        _Main_SimulationFlow_WaitingRealtime_2.setGuard(self._Main_SimulationFlow_WaitingRealtime_2_guard)
        self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_2)
        
        # transition /Main/SimulationFlow/Executing
        _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
        _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
        _Main_SimulationFlow_Executing_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
        
        # transition /Main/GodEventManager/Listening
        _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Listening"]])
        _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
        _Main_GodEventManager_Listening_0.setTrigger(Event("Simulation.GodEvent", None))
        _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
        self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
        
        # transition /Main/BreakpointManager/Listening
        _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
        _Main_BreakpointManager_Listening_0.setTrigger(Event("Breakpoint.Add", None))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
        _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
        _Main_BreakpointManager_Listening_1.setTrigger(Event("Breakpoint.Del", None))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
        _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
        _Main_BreakpointManager_Listening_2.setTrigger(Event("Breakpoint.Toggle", None))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
        _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
        _Main_BreakpointManager_Listening_3.setTrigger(Event("Breakpoint.List", None))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
        
        # transition /Main/ModeSelector/Running
        _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
        _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
        _Main_ModeSelector_Running_1.setTrigger(None)
        _Main_ModeSelector_Running_1.setGuard(self._Main_ModeSelector_Running_1_guard)
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
    
    def _Main_Initializer_SettleBeforeWaiting_enter(self):
        self.addTimer(0, self.sccd_yield())
    
    def _Main_Initializer_SettleBeforeWaiting_exit(self):
        self.removeTimer(0)
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
        self.addTimer(1, self.sccd_yield())
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
        self.removeTimer(1)
    
    def _Main_SimulationFlow_WaitingRealtime_enter(self):
        self.addTimer(2, self.sccd_yield())
    
    def _Main_SimulationFlow_WaitingRealtime_exit(self):
        self.removeTimer(2)
    
    def _Main_ModeSelector_Running_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.Triggered", None, [self.triggered_bp, self.clock, self.state])]))
    
    def _Main_ModeSelector_Running_1_guard(self, parameters):
        return self.breakpointTriggers(self.inState(["/Main/ModeSelector/Running/Realtime"]))
    
    def _Main_ModeSelector_Paused_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
    
    def _Main_ModeSelector_Paused_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
    
    def _Main_ModeSelector_Paused_3_exec(self, parameters):
        realtime_scale = parameters[0]
        self.realtime_scale = float(realtime_scale)
        # If the simulation was paused, we need to reset the start time of the simulation.
        # The start time of the simulation is equal to the point in wall-clock time where simulated time is 0.
        # If the simulation was paused, we have to recompute this point in time: it is the difference of the wall-clock time and the simulated time.
        # If the scale was changed after the pause, this point of course moves backwards (for scales smaller than 1) or forwards (for scales larger than 1)
        self.realtime_start_time = accurate_time.time() - (self.clock / self.realtime_scale)
    
    def _Main_ModeSelector_Paused_4_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
    
    def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
    
    def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
    
    def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
        current_component_idx = parameters[0]
        state = parameters[1]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [current_component_idx, state])]))
    
    def _Main_ChildState_Initialized_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
    
    def _Main_Initializer_Waiting_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_BigStep', self.cbd_controller, self.clock, self.iteration, self.time_next, self.delta, self.state]))
    
    def _Main_Initializer_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
    
    def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
    
    def _Main_SimulationFlow_Started_0_exec(self, parameters):
        self.initialize()
    
    def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
        self.initializeDebugger()
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Initialized", None, [])]))
    
    def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"])
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_1_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Paused"])
    
    def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
        return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/BigStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
    
    def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
    
    def _Main_SimulationFlow_CheckTermination_2_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
    
    def _Main_SimulationFlow_CheckTermination_3_exec(self, parameters):
        # print 'simulation executed'
        self.finalize()
        self.raiseInternalEvent(Event("Simulation.Finished", None, []))
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Finished", None, [self.clock, self.state])]))
    
    def _Main_SimulationFlow_CheckTermination_3_guard(self, parameters):
        return self.endCondition()
    
    def _Main_SimulationFlow_WaitingRealtime_0_exec(self, parameters):
        self.syncSimulatedTime()
    
    def _Main_SimulationFlow_WaitingRealtime_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"])
    
    def _Main_SimulationFlow_WaitingRealtime_1_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
    
    def _Main_SimulationFlow_WaitingRealtime_1_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Paused"]) and (not ((self.waitTime() / 1000.0) <= self.sccd_yield()))
    
    def _Main_SimulationFlow_WaitingRealtime_2_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_WaitingRealtime_2_guard(self, parameters):
        return self.waitTime() / 1000.0 <= self.sccd_yield()
    
    def _Main_SimulationFlow_Executing_0_exec(self, parameters):
        clock = parameters[0]
        iteration = parameters[1]
        time_next = parameters[2]
        state = parameters[3]
        self.clock = clock
        self.iteration = iteration
        self.time_next = time_next
        self.state = state
    
    def _Main_GodEventManager_Listening_0_exec(self, parameters):
        block_name = parameters[0]
        new_val = parameters[1]
        result = self.godEvent(block_name, new_val)
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.GodEventResult", None, [result])]))
    
    def _Main_GodEventManager_Listening_0_guard(self, parameters):
        block_name = parameters[0]
        new_val = parameters[1]
        return self.inState(["/Main/ModeSelector/Paused"])
    
    def _Main_BreakpointManager_Listening_0_exec(self, parameters):
        name = parameters[0]
        function = parameters[1]
        enabled = parameters[2]
        disable_on_trigger = parameters[3]
        result = self.addBreakpoint(name, function, bool(enabled), bool(disable_on_trigger))
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.AddResult", None, [result])]))
    
    def _Main_BreakpointManager_Listening_1_exec(self, parameters):
        name = parameters[0]
        result = self.delBreakpoint(name)
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.DelResult", None, [result])]))
    
    def _Main_BreakpointManager_Listening_2_exec(self, parameters):
        name = parameters[0]
        result = self.toggleBreakpoint(name)
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ToggleResult", None, [result])]))
    
    def _Main_BreakpointManager_Listening_3_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ListResult", None, [[bp.name for bp in self.breakpoints]])]))
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Main"].getEffectiveTargetStates()
        RuntimeClassBase.initializeStatechart(self)

class CBDSimulator_BigStep(RuntimeClassBase):
    def __init__(self, controller, cbd_controller, clock, iteration, time_next, delta, state):
        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
        CBDSimulator_BigStep.user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state)
    
    def user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state):
        self.cbd_controller = cbd_controller
        self.clock = clock
        self.iteration = iteration
        self.time_next = time_next
        self.delta = delta
        self.state = state
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def initialize(self):
        self.current_component_idx = 0
        self.dependency_graph = self.cbd_controller.createDepGraph(self.iteration)
        self.strong_component_list = self.cbd_controller.createStrongComponents(self.dependency_graph, self.iteration)
    
    
    # user defined method
    def initializeDebugger(self):
        pass
    
    
    # user defined method
    def endCondition(self):
        return self.current_component_idx >= len(self.strong_component_list)
    
    
    # user defined method
    def finalize(self):
        self.advanceTime()
    
    
    # user defined method
    def advanceTime(self):
        self.clock = self.time_next
        self.iteration = self.iteration + 1
        self.cbd_controller.advanceTimeStep()
        self.time_next = self.clock + self.delta
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /Main
        self.states["/Main"] = ParallelState(1, "/Main", self)
        
        # state /Main/ModeSelector
        self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
        
        # state /Main/ModeSelector/Paused
        self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
        
        # state /Main/ModeSelector/Running
        self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
        
        # state /Main/ModeSelector/Running/Continuous
        self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
        
        # state /Main/ModeSelector/Running/SmallStep
        self.states["/Main/ModeSelector/Running/SmallStep"] = State(6, "/Main/ModeSelector/Running/SmallStep", self)
        
        # state /Main/ChildState
        self.states["/Main/ChildState"] = State(7, "/Main/ChildState", self)
        
        # state /Main/ChildState/Uninitialized
        self.states["/Main/ChildState/Uninitialized"] = State(8, "/Main/ChildState/Uninitialized", self)
        
        # state /Main/ChildState/Initialized
        self.states["/Main/ChildState/Initialized"] = State(9, "/Main/ChildState/Initialized", self)
        
        # state /Main/Initializer
        self.states["/Main/Initializer"] = State(10, "/Main/Initializer", self)
        
        # state /Main/Initializer/Waiting
        self.states["/Main/Initializer/Waiting"] = State(11, "/Main/Initializer/Waiting", self)
        
        # state /Main/Initializer/CreatingChildSimulator
        self.states["/Main/Initializer/CreatingChildSimulator"] = State(12, "/Main/Initializer/CreatingChildSimulator", self)
        
        # state /Main/Initializer/StartingChildSimulator
        self.states["/Main/Initializer/StartingChildSimulator"] = State(13, "/Main/Initializer/StartingChildSimulator", self)
        
        # state /Main/Initializer/Running
        self.states["/Main/Initializer/Running"] = State(14, "/Main/Initializer/Running", self)
        
        # state /Main/Initializer/SettleBeforeWaiting
        self.states["/Main/Initializer/SettleBeforeWaiting"] = State(15, "/Main/Initializer/SettleBeforeWaiting", self)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
        
        # state /Main/SimulationFlow
        self.states["/Main/SimulationFlow"] = State(16, "/Main/SimulationFlow", self)
        
        # state /Main/SimulationFlow/Started
        self.states["/Main/SimulationFlow/Started"] = State(17, "/Main/SimulationFlow/Started", self)
        
        # state /Main/SimulationFlow/Initialized
        self.states["/Main/SimulationFlow/Initialized"] = State(18, "/Main/SimulationFlow/Initialized", self)
        
        # state /Main/SimulationFlow/InitializeDebugger
        self.states["/Main/SimulationFlow/InitializeDebugger"] = State(19, "/Main/SimulationFlow/InitializeDebugger", self)
        
        # state /Main/SimulationFlow/Waiting
        self.states["/Main/SimulationFlow/Waiting"] = State(20, "/Main/SimulationFlow/Waiting", self)
        
        # state /Main/SimulationFlow/SettleBeforeCheckTermination
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(21, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
        
        # state /Main/SimulationFlow/CheckTermination
        self.states["/Main/SimulationFlow/CheckTermination"] = State(22, "/Main/SimulationFlow/CheckTermination", self)
        
        # state /Main/SimulationFlow/Executing
        self.states["/Main/SimulationFlow/Executing"] = State(23, "/Main/SimulationFlow/Executing", self)
        
        # state /Main/SimulationFlow/Stopped
        self.states["/Main/SimulationFlow/Stopped"] = State(24, "/Main/SimulationFlow/Stopped", self)
        
        # state /Stopped
        self.states["/Stopped"] = State(25, "/Stopped", self)
        
        # add children
        self.states[""].addChild(self.states["/Main"])
        self.states[""].addChild(self.states["/Stopped"])
        self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
        self.states["/Main"].addChild(self.states["/Main/ChildState"])
        self.states["/Main"].addChild(self.states["/Main/Initializer"])
        self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Main"]
        self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
        self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
        self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
        self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
        self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
        
        # transition /Main/ModeSelector/Paused
        _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
        _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
        _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
        _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
        _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
        
        # transition /Main/ModeSelector/Running/SmallStep
        _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
        _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
        
        # transition /Main/ChildState/Uninitialized
        _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
        _Main_ChildState_Uninitialized_0.setTrigger(Event("SmallStep.Initialized", None))
        self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
        
        # transition /Main/ChildState/Initialized
        _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
        _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
        _Main_ChildState_Initialized_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
        
        # transition /Main/Initializer/Waiting
        _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
        _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
        _Main_Initializer_Waiting_0.setTrigger(None)
        _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
        self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
        
        # transition /Main/Initializer/CreatingChildSimulator
        _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
        _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
        _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
        self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
        
        # transition /Main/Initializer/StartingChildSimulator
        _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
        _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("SmallStep.Initialized", None))
        self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
        
        # transition /Main/Initializer/Running
        _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
        _Main_Initializer_Running_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
        
        # transition /Main/Initializer/SettleBeforeWaiting
        _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
        _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
        self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
        
        # transition /Main/SimulationFlow/Started
        _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
        _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
        _Main_SimulationFlow_Started_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
        
        # transition /Main/SimulationFlow/Initialized
        _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
        _Main_SimulationFlow_Initialized_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
        
        # transition /Main/SimulationFlow/InitializeDebugger
        _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
        _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
        _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
        self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
        
        # transition /Main/SimulationFlow/Waiting
        _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_Waiting_0.setTrigger(None)
        _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
        self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
        
        # transition /Main/SimulationFlow/SettleBeforeCheckTermination
        _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
        
        # transition /Main/SimulationFlow/CheckTermination
        _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
        _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
        _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
        _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
        _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
        
        # transition /Main/SimulationFlow/Executing
        _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
        _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
        _Main_SimulationFlow_Executing_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
        
        # transition /Main/ModeSelector/Running
        _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_0.setTrigger(Event("BigStep.Finished", None))
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
    
    def _Main_Initializer_SettleBeforeWaiting_enter(self):
        self.addTimer(0, self.sccd_yield())
    
    def _Main_Initializer_SettleBeforeWaiting_exit(self):
        self.removeTimer(0)
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
        self.addTimer(1, self.sccd_yield())
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
        self.removeTimer(1)
    
    def _Main_ModeSelector_Paused_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
    
    def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
        new_current_component_idx = parameters[0]
        new_state = parameters[1]
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [new_current_component_idx, new_state])]))
    
    def _Main_ChildState_Initialized_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
    
    def _Main_Initializer_Waiting_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_SmallStep', self.cbd_controller, self.strong_component_list, self.current_component_idx, self.dependency_graph, self.iteration, self.state]))
    
    def _Main_Initializer_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
    
    def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
    
    def _Main_SimulationFlow_Started_0_exec(self, parameters):
        self.initialize()
    
    def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
        self.initializeDebugger()
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Initialized", None, [])]))
    
    def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"])
    
    def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
    
    def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
        return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/SmallStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
    
    def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
        # print '>>> big step executed <<<'
        self.finalize()
        self.raiseInternalEvent(Event("BigStep.Finished", None, []))
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [self.clock, self.iteration, self.time_next, self.state])]))
    
    def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
        return self.endCondition()
    
    def _Main_SimulationFlow_Executing_0_exec(self, parameters):
        new_current_component_idx = parameters[0]
        new_state = parameters[1]
        self.current_component_idx = new_current_component_idx
        self.state = new_state
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Main"].getEffectiveTargetStates()
        RuntimeClassBase.initializeStatechart(self)

class CBDSimulator_SmallStep(RuntimeClassBase):
    def __init__(self, controller, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
        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
        CBDSimulator_SmallStep.user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state)
    
    def user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
        self.cbd_controller = cbd_controller
        self.strong_component_list = strong_component_list
        self.current_component_idx = current_component_idx
        self.dependency_graph = dependency_graph
        self.iteration = iteration
        self.state = state
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def initialize(self):
        self.small_step_executed = False
    
    
    # user defined method
    def initializeDebugger(self):
        pass
    
    
    # user defined method
    def endCondition(self):
        return self.small_step_executed
    
    
    # user defined method
    def finalize(self):
        self.current_component_idx += 1
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /Main
        self.states["/Main"] = ParallelState(1, "/Main", self)
        
        # state /Main/ModeSelector
        self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
        
        # state /Main/ModeSelector/Paused
        self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
        
        # state /Main/ModeSelector/Running
        self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
        
        # state /Main/ModeSelector/Running/Continuous
        self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
        
        # state /Main/ChildState
        self.states["/Main/ChildState"] = State(6, "/Main/ChildState", self)
        
        # state /Main/ChildState/Uninitialized
        self.states["/Main/ChildState/Uninitialized"] = State(7, "/Main/ChildState/Uninitialized", self)
        
        # state /Main/ChildState/Initialized
        self.states["/Main/ChildState/Initialized"] = State(8, "/Main/ChildState/Initialized", self)
        
        # state /Main/Initializer
        self.states["/Main/Initializer"] = State(9, "/Main/Initializer", self)
        
        # state /Main/Initializer/Waiting
        self.states["/Main/Initializer/Waiting"] = State(10, "/Main/Initializer/Waiting", self)
        
        # state /Main/Initializer/CreatingChildSimulator
        self.states["/Main/Initializer/CreatingChildSimulator"] = State(11, "/Main/Initializer/CreatingChildSimulator", self)
        
        # state /Main/Initializer/StartingChildSimulator
        self.states["/Main/Initializer/StartingChildSimulator"] = State(12, "/Main/Initializer/StartingChildSimulator", self)
        
        # state /Main/Initializer/Running
        self.states["/Main/Initializer/Running"] = State(13, "/Main/Initializer/Running", self)
        
        # state /Main/Initializer/SettleBeforeWaiting
        self.states["/Main/Initializer/SettleBeforeWaiting"] = State(14, "/Main/Initializer/SettleBeforeWaiting", self)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
        self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
        
        # state /Main/SimulationFlow
        self.states["/Main/SimulationFlow"] = State(15, "/Main/SimulationFlow", self)
        
        # state /Main/SimulationFlow/Started
        self.states["/Main/SimulationFlow/Started"] = State(16, "/Main/SimulationFlow/Started", self)
        
        # state /Main/SimulationFlow/Initialized
        self.states["/Main/SimulationFlow/Initialized"] = State(17, "/Main/SimulationFlow/Initialized", self)
        
        # state /Main/SimulationFlow/InitializeDebugger
        self.states["/Main/SimulationFlow/InitializeDebugger"] = State(18, "/Main/SimulationFlow/InitializeDebugger", self)
        
        # state /Main/SimulationFlow/Waiting
        self.states["/Main/SimulationFlow/Waiting"] = State(19, "/Main/SimulationFlow/Waiting", self)
        
        # state /Main/SimulationFlow/SettleBeforeCheckTermination
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(20, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
        
        # state /Main/SimulationFlow/CheckTermination
        self.states["/Main/SimulationFlow/CheckTermination"] = State(21, "/Main/SimulationFlow/CheckTermination", self)
        
        # state /Main/SimulationFlow/Executing
        self.states["/Main/SimulationFlow/Executing"] = State(22, "/Main/SimulationFlow/Executing", self)
        
        # state /Main/SimulationFlow/Stopped
        self.states["/Main/SimulationFlow/Stopped"] = State(23, "/Main/SimulationFlow/Stopped", self)
        
        # state /Stopped
        self.states["/Stopped"] = State(24, "/Stopped", self)
        
        # add children
        self.states[""].addChild(self.states["/Main"])
        self.states[""].addChild(self.states["/Stopped"])
        self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
        self.states["/Main"].addChild(self.states["/Main/ChildState"])
        self.states["/Main"].addChild(self.states["/Main/Initializer"])
        self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
        self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
        self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
        self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
        self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Main"]
        self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
        self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
        self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
        self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
        self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
        
        # transition /Main/ModeSelector/Paused
        _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
        _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
        self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
        
        # transition /Main/ChildState/Uninitialized
        _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
        _Main_ChildState_Uninitialized_0.setTrigger(Event("Block.Initialized", None))
        self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
        
        # transition /Main/ChildState/Initialized
        _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
        _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
        _Main_ChildState_Initialized_0.setTrigger(Event("Block.Finished", None))
        self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
        
        # transition /Main/Initializer/Waiting
        _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
        _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
        _Main_Initializer_Waiting_0.setTrigger(None)
        _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
        self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
        
        # transition /Main/Initializer/CreatingChildSimulator
        _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
        _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
        _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
        self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
        
        # transition /Main/Initializer/StartingChildSimulator
        _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
        _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Block.Initialized", None))
        self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
        
        # transition /Main/Initializer/Running
        _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
        _Main_Initializer_Running_0.setTrigger(Event("Block.Finished", None))
        self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
        
        # transition /Main/Initializer/SettleBeforeWaiting
        _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
        _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
        self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
        
        # transition /Main/SimulationFlow/Started
        _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
        _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
        _Main_SimulationFlow_Started_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
        
        # transition /Main/SimulationFlow/Initialized
        _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
        _Main_SimulationFlow_Initialized_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
        
        # transition /Main/SimulationFlow/InitializeDebugger
        _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
        _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
        _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
        self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
        
        # transition /Main/SimulationFlow/Waiting
        _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_Waiting_0.setTrigger(None)
        _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
        self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
        
        # transition /Main/SimulationFlow/SettleBeforeCheckTermination
        _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
        self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
        
        # transition /Main/SimulationFlow/CheckTermination
        _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
        _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
        _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
        _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
        _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
        _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
        self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
        
        # transition /Main/SimulationFlow/Executing
        _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
        _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
        _Main_SimulationFlow_Executing_0.setTrigger(Event("Block.Finished", None))
        self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
        
        # transition /Main/ModeSelector/Running
        _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
        _Main_ModeSelector_Running_0.setTrigger(Event("SmallStep.Finished", None))
        self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
    
    def _Main_Initializer_SettleBeforeWaiting_enter(self):
        self.addTimer(0, self.sccd_yield())
    
    def _Main_Initializer_SettleBeforeWaiting_exit(self):
        self.removeTimer(0)
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
        self.addTimer(1, self.sccd_yield())
    
    def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
        self.removeTimer(1)
    
    def _Main_ChildState_Initialized_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
    
    def _Main_Initializer_Waiting_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Block', self.cbd_controller, self.strong_component_list[self.current_component_idx], self.cbd_controller.componentIsCycle(self.strong_component_list[self.current_component_idx], self.dependency_graph), self.iteration]))
    
    def _Main_Initializer_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
    
    def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
    
    def _Main_SimulationFlow_Started_0_exec(self, parameters):
        self.initialize()
    
    def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
        self.initializeDebugger()
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Initialized", None, [])]))
    
    def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running"])
    
    def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Block.Execute", None, [])]))
    
    def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
        return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
    
    def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
        # print '>>> small step executed <<<'
        self.finalize()
        self.raiseInternalEvent(Event("SmallStep.Finished", None, []))
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [self.current_component_idx, self.state])]))
    
    def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
        return self.endCondition()
    
    def _Main_SimulationFlow_Executing_0_exec(self, parameters):
        new_state = parameters[0]
        self.small_step_executed = True
        self.state = new_state
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Main"].getEffectiveTargetStates()
        RuntimeClassBase.initializeStatechart(self)

class CBDSimulator_Block(RuntimeClassBase):
    def __init__(self, controller, cbd_controller, block_to_compute, is_cycle, iteration):
        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
        CBDSimulator_Block.user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration)
    
    def user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration):
        self.cbd_controller = cbd_controller
        self.block_to_compute = block_to_compute
        self.is_cycle = is_cycle
        self.iteration = iteration
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def computeBlock(self):
        if self.is_cycle:
            self.cbd_controller.computeNextAlgebraicLoop(self.block_to_compute, self.iteration)
        else:
            self.cbd_controller.computeNextBlock(self.block_to_compute, self.iteration)
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, "", self)
        
        # state /Started
        self.states["/Started"] = State(1, "/Started", self)
        
        # state /Waiting
        self.states["/Waiting"] = State(2, "/Waiting", self)
        
        # state /Stopped
        self.states["/Stopped"] = State(3, "/Stopped", self)
        
        # add children
        self.states[""].addChild(self.states["/Started"])
        self.states[""].addChild(self.states["/Waiting"])
        self.states[""].addChild(self.states["/Stopped"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Started"]
        
        # transition /Started
        _Started_0 = Transition(self, self.states["/Started"], [self.states["/Waiting"]])
        _Started_0.setAction(self._Started_0_exec)
        _Started_0.setTrigger(None)
        self.states["/Started"].addTransition(_Started_0)
        
        # transition /Waiting
        _Waiting_0 = Transition(self, self.states["/Waiting"], [self.states["/Stopped"]])
        _Waiting_0.setAction(self._Waiting_0_exec)
        _Waiting_0.setTrigger(Event("Block.Execute", None))
        self.states["/Waiting"].addTransition(_Waiting_0)
    
    def _Started_0_exec(self, parameters):
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Initialized", None, [])]))
    
    def _Waiting_0_exec(self, parameters):
        self.computeBlock()
        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Finished", None, [{b.getBlockName(): b.getSignal() for b in self.cbd_controller.model.getBlocks()}])]))
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Started"].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 == "CBDSimulator_Coordinator":
            instance = CBDSimulator_Coordinator(self.controller, construct_params[0], construct_params[1])
            instance.associations = {}
            instance.associations["child_simulator"] = Association("CBDSimulator_Simulation", 0, 1)
        elif class_name == "CBDSimulator_Simulation":
            instance = CBDSimulator_Simulation(self.controller, construct_params[0], construct_params[1])
            instance.associations = {}
            instance.associations["parent"] = Association("CBDSimulator_Coordinator", 1, 1)
            instance.associations["child_simulator"] = Association("CBDSimulator_BigStep", 0, 1)
        elif class_name == "CBDSimulator_BigStep":
            instance = CBDSimulator_BigStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
            instance.associations = {}
            instance.associations["parent"] = Association("CBDSimulator_Simulation", 1, 1)
            instance.associations["child_simulator"] = Association("CBDSimulator_SmallStep", 0, 1)
        elif class_name == "CBDSimulator_SmallStep":
            instance = CBDSimulator_SmallStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
            instance.associations = {}
            instance.associations["parent"] = Association("CBDSimulator_BigStep", 1, 1)
            instance.associations["child_simulator"] = Association("CBDSimulator_Block", 0, 1)
        elif class_name == "CBDSimulator_Block":
            instance = CBDSimulator_Block(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3])
            instance.associations = {}
            instance.associations["parent"] = Association("CBDSimulator_SmallStep", 1, 1)
        else:
            raise Exception("Cannot instantiate class " + class_name)
        return instance

class Controller(ThreadsControllerBase):
    def __init__(self, options, model, 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.addInputPort("user_input")
        self.addInputPort("user_output")
        self.object_manager.createInstance("CBDSimulator_Coordinator", [options, model])