00_source_parent.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Wed Aug 03 16:10:24 2016
  4. Model author: Herr Joeri Exelmans
  5. Model name: source_parent
  6. Model description:
  7. 'Source Parent' priority-semantics: If 2 transitions are enabled, and the source state of the first is an ancestor of the second, only the first is executed.
  8. """
  9. from python_runtime.statecharts_core import *
  10. # package "source_parent"
  11. class c(RuntimeClassBase):
  12. def __init__(self, controller):
  13. RuntimeClassBase.__init__(self, controller)
  14. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  15. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  16. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  17. self.semantics.priority = StatechartSemantics.SourceParent
  18. self.semantics.concurrency = StatechartSemantics.Single
  19. # build Statechart structure
  20. self.build_statechart_structure()
  21. # call user defined constructor
  22. c.user_defined_constructor(self)
  23. def user_defined_constructor(self):
  24. pass
  25. def user_defined_destructor(self):
  26. pass
  27. # builds Statechart structure
  28. def build_statechart_structure(self):
  29. # state <root>
  30. self.states[""] = State(0, self)
  31. # state /parent
  32. self.states["/parent"] = State(1, self)
  33. self.states["/parent"].setEnter(self._parent_enter)
  34. # state /parent/a
  35. self.states["/parent/a"] = State(2, self)
  36. self.states["/parent/a"].setEnter(self._parent_a_enter)
  37. # state /parent/b
  38. self.states["/parent/b"] = State(3, self)
  39. self.states["/parent/b"].setEnter(self._parent_b_enter)
  40. # state /c
  41. self.states["/c"] = State(4, self)
  42. self.states["/c"].setEnter(self._c_enter)
  43. # add children
  44. self.states[""].addChild(self.states["/parent"])
  45. self.states[""].addChild(self.states["/c"])
  46. self.states["/parent"].addChild(self.states["/parent/a"])
  47. self.states["/parent"].addChild(self.states["/parent/b"])
  48. self.states[""].fixTree()
  49. self.states[""].default_state = self.states["/parent"]
  50. self.states["/parent"].default_state = self.states["/parent/a"]
  51. # transition /parent/a
  52. _parent_a_0 = Transition(self, self.states["/parent/a"], [self.states["/parent/b"]])
  53. self.states["/parent/a"].addTransition(_parent_a_0)
  54. # transition /parent
  55. _parent_0 = Transition(self, self.states["/parent"], [self.states["/c"]])
  56. self.states["/parent"].addTransition(_parent_0)
  57. def _parent_enter(self):
  58. self.big_step.outputEvent(Event("entered_parent", "out", []))
  59. def _parent_a_enter(self):
  60. self.big_step.outputEvent(Event("entered_a", "out", []))
  61. def _parent_b_enter(self):
  62. self.big_step.outputEvent(Event("entered_b", "out", []))
  63. def _c_enter(self):
  64. self.big_step.outputEvent(Event("entered_c", "out", []))
  65. def initializeStatechart(self):
  66. # enter default state
  67. states = self.states["/parent"].getEffectiveTargetStates()
  68. self.updateConfiguration(states)
  69. for state in states:
  70. if state.enter:
  71. state.enter()
  72. class ObjectManager(ObjectManagerBase):
  73. def __init__(self, controller):
  74. ObjectManagerBase.__init__(self, controller)
  75. def instantiate(self, class_name, construct_params):
  76. if class_name == "c":
  77. instance = c(self.controller)
  78. instance.associations = {}
  79. return instance
  80. class Controller(ThreadsControllerBase):
  81. def __init__(self, keep_running = None):
  82. if keep_running == None: keep_running = True
  83. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  84. self.addInputPort("in")
  85. self.addOutputPort("out")
  86. self.object_manager.createInstance("c", [])
  87. class InputEvent:
  88. def __init__(self, name, port, parameters, time_offset):
  89. self.name = name
  90. self.port = port
  91. self.parameters = parameters
  92. self.time_offset = time_offset
  93. class Test:
  94. def __init__(self):
  95. pass
  96. input_events = []
  97. expected_events = [[Event("entered_parent", "out", []), Event("entered_a", "out", [])], [Event("entered_c", "out", [])]]