""" Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) Model author: Raphael Mannadiar """ from sccd.runtime.statecharts_core import * # package "" class MainApp(RuntimeClassBase): def __init__(self, controller): RuntimeClassBase.__init__(self, controller) self.semantics.big_step_maximality = StatechartSemantics.TakeMany self.semantics.internal_event_lifeline = StatechartSemantics.Queue self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep self.semantics.priority = StatechartSemantics.SourceParent self.semantics.concurrency = StatechartSemantics.Single # build Statechart structure self.build_statechart_structure() # call user defined constructor MainApp.user_defined_constructor(self) def user_defined_constructor(self): pass def user_defined_destructor(self): pass # builds Statechart structure def build_statechart_structure(self): # state self.states[""] = State(0, "", self) # state /on self.states["/on"] = State(1, "/on", self) # state /on/normal self.states["/on/normal"] = State(2, "/on/normal", self) self.states["/on/normal"].setEnter(self._on_normal_enter) self.states["/on/normal"].setExit(self._on_normal_exit) # state /on/normal/red self.states["/on/normal/red"] = State(3, "/on/normal/red", self) self.states["/on/normal/red"].setEnter(self._on_normal_red_enter) self.states["/on/normal/red"].setExit(self._on_normal_red_exit) # state /on/normal/green self.states["/on/normal/green"] = State(4, "/on/normal/green", self) self.states["/on/normal/green"].setEnter(self._on_normal_green_enter) self.states["/on/normal/green"].setExit(self._on_normal_green_exit) # state /on/normal/yellow self.states["/on/normal/yellow"] = State(5, "/on/normal/yellow", self) # state /on/normal/yellow/yellow1 self.states["/on/normal/yellow/yellow1"] = State(6, "/on/normal/yellow/yellow1", self) self.states["/on/normal/yellow/yellow1"].setEnter(self._on_normal_yellow_yellow1_enter) self.states["/on/normal/yellow/yellow1"].setExit(self._on_normal_yellow_yellow1_exit) # state /on/normal/yellow/yellow2 self.states["/on/normal/yellow/yellow2"] = State(7, "/on/normal/yellow/yellow2", self) self.states["/on/normal/yellow/yellow2"].setEnter(self._on_normal_yellow_yellow2_enter) self.states["/on/normal/yellow/yellow2"].setExit(self._on_normal_yellow_yellow2_exit) # state /on/normal/yellow/yellow3 self.states["/on/normal/yellow/yellow3"] = State(8, "/on/normal/yellow/yellow3", self) self.states["/on/normal/yellow/yellow3"].setEnter(self._on_normal_yellow_yellow3_enter) self.states["/on/normal/yellow/yellow3"].setExit(self._on_normal_yellow_yellow3_exit) # state /on/normal/history self.states["/on/normal/history"] = DeepHistoryState(9, "/on/normal/history", self) # state /on/interrupted self.states["/on/interrupted"] = State(10, "/on/interrupted", self) self.states["/on/interrupted"].setEnter(self._on_interrupted_enter) self.states["/on/interrupted"].setExit(self._on_interrupted_exit) # state /off self.states["/off"] = State(11, "/off", self) # add children self.states[""].addChild(self.states["/on"]) self.states[""].addChild(self.states["/off"]) self.states["/on"].addChild(self.states["/on/normal"]) self.states["/on"].addChild(self.states["/on/interrupted"]) self.states["/on/normal"].addChild(self.states["/on/normal/red"]) self.states["/on/normal"].addChild(self.states["/on/normal/green"]) self.states["/on/normal"].addChild(self.states["/on/normal/yellow"]) self.states["/on/normal"].addChild(self.states["/on/normal/history"]) self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow1"]) self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow2"]) self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow3"]) self.states[""].fixTree() self.states[""].default_state = self.states["/on"] self.states["/on"].default_state = self.states["/on/normal"] self.states["/on/normal"].default_state = self.states["/on/normal/red"] self.states["/on/normal/yellow"].default_state = self.states["/on/normal/yellow/yellow1"] # transition /on/normal/red _on_normal_red_0 = Transition(self, self.states["/on/normal/red"], [self.states["/on/normal/green"]]) _on_normal_red_0.setTrigger(Event("_1after")) self.states["/on/normal/red"].addTransition(_on_normal_red_0) # transition /on/normal/green _on_normal_green_0 = Transition(self, self.states["/on/normal/green"], [self.states["/on/normal/yellow"]]) _on_normal_green_0.setTrigger(Event("_2after")) self.states["/on/normal/green"].addTransition(_on_normal_green_0) # transition /on/normal/yellow/yellow1 _on_normal_yellow_yellow1_0 = Transition(self, self.states["/on/normal/yellow/yellow1"], [self.states["/on/normal/yellow/yellow2"]]) _on_normal_yellow_yellow1_0.setTrigger(Event("_3after")) self.states["/on/normal/yellow/yellow1"].addTransition(_on_normal_yellow_yellow1_0) # transition /on/normal/yellow/yellow2 _on_normal_yellow_yellow2_0 = Transition(self, self.states["/on/normal/yellow/yellow2"], [self.states["/on/normal/yellow/yellow3"]]) _on_normal_yellow_yellow2_0.setTrigger(Event("_4after")) self.states["/on/normal/yellow/yellow2"].addTransition(_on_normal_yellow_yellow2_0) # transition /on/normal/yellow/yellow3 _on_normal_yellow_yellow3_0 = Transition(self, self.states["/on/normal/yellow/yellow3"], [self.states["/off"]]) _on_normal_yellow_yellow3_0.setTrigger(Event("_5after")) self.states["/on/normal/yellow/yellow3"].addTransition(_on_normal_yellow_yellow3_0) # transition /on/interrupted _on_interrupted_0 = Transition(self, self.states["/on/interrupted"], [self.states["/on/normal/history"]]) _on_interrupted_0.setTrigger(Event("_6after")) self.states["/on/interrupted"].addTransition(_on_interrupted_0) # transition /on/normal _on_normal_0 = Transition(self, self.states["/on/normal"], [self.states["/on/interrupted"]]) _on_normal_0.setTrigger(Event("_0after")) self.states["/on/normal"].addTransition(_on_normal_0) def _on_normal_enter(self): self.addTimer(0, 3.5) def _on_normal_exit(self): self.removeTimer(0) def _on_normal_red_enter(self): self.addTimer(1, 2) def _on_normal_red_exit(self): self.removeTimer(1) def _on_normal_green_enter(self): self.addTimer(2, 1) def _on_normal_green_exit(self): self.removeTimer(2) def _on_normal_yellow_yellow1_enter(self): self.addTimer(3, 0.1) def _on_normal_yellow_yellow1_exit(self): self.removeTimer(3) def _on_normal_yellow_yellow2_enter(self): self.addTimer(4, 0.5) def _on_normal_yellow_yellow2_exit(self): self.removeTimer(4) def _on_normal_yellow_yellow3_enter(self): self.addTimer(5, 0.1) def _on_normal_yellow_yellow3_exit(self): self.removeTimer(5) def _on_interrupted_enter(self): self.addTimer(6, 1) def _on_interrupted_exit(self): self.removeTimer(6) def initializeStatechart(self): # enter default state self.default_targets = self.states["/on"].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 == "MainApp": instance = MainApp(self.controller) instance.associations = {} else: raise Exception("Cannot instantiate class " + class_name) return instance class Controller(ThreadsControllerBase): def __init__(self, keep_running = None, behind_schedule_callback = None): if keep_running == None: keep_running = True if behind_schedule_callback == None: behind_schedule_callback = None ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback) self.addInputPort("ui") self.object_manager.createInstance("MainApp", [])