target.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Model author: Raphael Mannadiar
  4. """
  5. from sccd.runtime.statecharts_core import *
  6. # package ""
  7. class MainApp(RuntimeClassBase):
  8. def __init__(self, controller):
  9. RuntimeClassBase.__init__(self, controller)
  10. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  11. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  12. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  13. self.semantics.priority = StatechartSemantics.SourceParent
  14. self.semantics.concurrency = StatechartSemantics.Single
  15. # build Statechart structure
  16. self.build_statechart_structure()
  17. # call user defined constructor
  18. MainApp.user_defined_constructor(self)
  19. def user_defined_constructor(self):
  20. pass
  21. def user_defined_destructor(self):
  22. pass
  23. # builds Statechart structure
  24. def build_statechart_structure(self):
  25. # state <root>
  26. self.states[""] = State(0, "", self)
  27. # state /on
  28. self.states["/on"] = State(1, "/on", self)
  29. # state /on/normal
  30. self.states["/on/normal"] = State(2, "/on/normal", self)
  31. self.states["/on/normal"].setEnter(self._on_normal_enter)
  32. self.states["/on/normal"].setExit(self._on_normal_exit)
  33. # state /on/normal/red
  34. self.states["/on/normal/red"] = State(3, "/on/normal/red", self)
  35. self.states["/on/normal/red"].setEnter(self._on_normal_red_enter)
  36. self.states["/on/normal/red"].setExit(self._on_normal_red_exit)
  37. # state /on/normal/green
  38. self.states["/on/normal/green"] = State(4, "/on/normal/green", self)
  39. self.states["/on/normal/green"].setEnter(self._on_normal_green_enter)
  40. self.states["/on/normal/green"].setExit(self._on_normal_green_exit)
  41. # state /on/normal/yellow
  42. self.states["/on/normal/yellow"] = State(5, "/on/normal/yellow", self)
  43. # state /on/normal/yellow/yellow1
  44. self.states["/on/normal/yellow/yellow1"] = State(6, "/on/normal/yellow/yellow1", self)
  45. self.states["/on/normal/yellow/yellow1"].setEnter(self._on_normal_yellow_yellow1_enter)
  46. self.states["/on/normal/yellow/yellow1"].setExit(self._on_normal_yellow_yellow1_exit)
  47. # state /on/normal/yellow/yellow2
  48. self.states["/on/normal/yellow/yellow2"] = State(7, "/on/normal/yellow/yellow2", self)
  49. self.states["/on/normal/yellow/yellow2"].setEnter(self._on_normal_yellow_yellow2_enter)
  50. self.states["/on/normal/yellow/yellow2"].setExit(self._on_normal_yellow_yellow2_exit)
  51. # state /on/normal/yellow/yellow3
  52. self.states["/on/normal/yellow/yellow3"] = State(8, "/on/normal/yellow/yellow3", self)
  53. self.states["/on/normal/yellow/yellow3"].setEnter(self._on_normal_yellow_yellow3_enter)
  54. self.states["/on/normal/yellow/yellow3"].setExit(self._on_normal_yellow_yellow3_exit)
  55. # state /on/normal/history
  56. self.states["/on/normal/history"] = DeepHistoryState(9, "/on/normal/history", self)
  57. # state /on/interrupted
  58. self.states["/on/interrupted"] = State(10, "/on/interrupted", self)
  59. self.states["/on/interrupted"].setEnter(self._on_interrupted_enter)
  60. self.states["/on/interrupted"].setExit(self._on_interrupted_exit)
  61. # state /off
  62. self.states["/off"] = State(11, "/off", self)
  63. # add children
  64. self.states[""].addChild(self.states["/on"])
  65. self.states[""].addChild(self.states["/off"])
  66. self.states["/on"].addChild(self.states["/on/normal"])
  67. self.states["/on"].addChild(self.states["/on/interrupted"])
  68. self.states["/on/normal"].addChild(self.states["/on/normal/red"])
  69. self.states["/on/normal"].addChild(self.states["/on/normal/green"])
  70. self.states["/on/normal"].addChild(self.states["/on/normal/yellow"])
  71. self.states["/on/normal"].addChild(self.states["/on/normal/history"])
  72. self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow1"])
  73. self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow2"])
  74. self.states["/on/normal/yellow"].addChild(self.states["/on/normal/yellow/yellow3"])
  75. self.states[""].fixTree()
  76. self.states[""].default_state = self.states["/on"]
  77. self.states["/on"].default_state = self.states["/on/normal"]
  78. self.states["/on/normal"].default_state = self.states["/on/normal/red"]
  79. self.states["/on/normal/yellow"].default_state = self.states["/on/normal/yellow/yellow1"]
  80. # transition /on/normal/red
  81. _on_normal_red_0 = Transition(self, self.states["/on/normal/red"], [self.states["/on/normal/green"]])
  82. _on_normal_red_0.setTrigger(Event("_1after"))
  83. self.states["/on/normal/red"].addTransition(_on_normal_red_0)
  84. # transition /on/normal/green
  85. _on_normal_green_0 = Transition(self, self.states["/on/normal/green"], [self.states["/on/normal/yellow"]])
  86. _on_normal_green_0.setTrigger(Event("_2after"))
  87. self.states["/on/normal/green"].addTransition(_on_normal_green_0)
  88. # transition /on/normal/yellow/yellow1
  89. _on_normal_yellow_yellow1_0 = Transition(self, self.states["/on/normal/yellow/yellow1"], [self.states["/on/normal/yellow/yellow2"]])
  90. _on_normal_yellow_yellow1_0.setTrigger(Event("_3after"))
  91. self.states["/on/normal/yellow/yellow1"].addTransition(_on_normal_yellow_yellow1_0)
  92. # transition /on/normal/yellow/yellow2
  93. _on_normal_yellow_yellow2_0 = Transition(self, self.states["/on/normal/yellow/yellow2"], [self.states["/on/normal/yellow/yellow3"]])
  94. _on_normal_yellow_yellow2_0.setTrigger(Event("_4after"))
  95. self.states["/on/normal/yellow/yellow2"].addTransition(_on_normal_yellow_yellow2_0)
  96. # transition /on/normal/yellow/yellow3
  97. _on_normal_yellow_yellow3_0 = Transition(self, self.states["/on/normal/yellow/yellow3"], [self.states["/off"]])
  98. _on_normal_yellow_yellow3_0.setTrigger(Event("_5after"))
  99. self.states["/on/normal/yellow/yellow3"].addTransition(_on_normal_yellow_yellow3_0)
  100. # transition /on/interrupted
  101. _on_interrupted_0 = Transition(self, self.states["/on/interrupted"], [self.states["/on/normal/history"]])
  102. _on_interrupted_0.setTrigger(Event("_6after"))
  103. self.states["/on/interrupted"].addTransition(_on_interrupted_0)
  104. # transition /on/normal
  105. _on_normal_0 = Transition(self, self.states["/on/normal"], [self.states["/on/interrupted"]])
  106. _on_normal_0.setTrigger(Event("_0after"))
  107. self.states["/on/normal"].addTransition(_on_normal_0)
  108. def _on_normal_enter(self):
  109. self.addTimer(0, 3.5)
  110. def _on_normal_exit(self):
  111. self.removeTimer(0)
  112. def _on_normal_red_enter(self):
  113. self.addTimer(1, 2)
  114. def _on_normal_red_exit(self):
  115. self.removeTimer(1)
  116. def _on_normal_green_enter(self):
  117. self.addTimer(2, 1)
  118. def _on_normal_green_exit(self):
  119. self.removeTimer(2)
  120. def _on_normal_yellow_yellow1_enter(self):
  121. self.addTimer(3, 0.1)
  122. def _on_normal_yellow_yellow1_exit(self):
  123. self.removeTimer(3)
  124. def _on_normal_yellow_yellow2_enter(self):
  125. self.addTimer(4, 0.5)
  126. def _on_normal_yellow_yellow2_exit(self):
  127. self.removeTimer(4)
  128. def _on_normal_yellow_yellow3_enter(self):
  129. self.addTimer(5, 0.1)
  130. def _on_normal_yellow_yellow3_exit(self):
  131. self.removeTimer(5)
  132. def _on_interrupted_enter(self):
  133. self.addTimer(6, 1)
  134. def _on_interrupted_exit(self):
  135. self.removeTimer(6)
  136. def initializeStatechart(self):
  137. # enter default state
  138. self.default_targets = self.states["/on"].getEffectiveTargetStates()
  139. RuntimeClassBase.initializeStatechart(self)
  140. class ObjectManager(ObjectManagerBase):
  141. def __init__(self, controller):
  142. ObjectManagerBase.__init__(self, controller)
  143. def instantiate(self, class_name, construct_params):
  144. if class_name == "MainApp":
  145. instance = MainApp(self.controller)
  146. instance.associations = {}
  147. else:
  148. raise Exception("Cannot instantiate class " + class_name)
  149. return instance
  150. class Controller(ThreadsControllerBase):
  151. def __init__(self, keep_running = None, behind_schedule_callback = None):
  152. if keep_running == None: keep_running = True
  153. if behind_schedule_callback == None: behind_schedule_callback = None
  154. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  155. self.addInputPort("ui")
  156. self.object_manager.createInstance("MainApp", [])