target.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: Sam Pieters
  4. Model name: AfterTransitionTest
  5. Model description:
  6. Test 2: Check if a statechart transitions after a certain time.
  7. """
  8. from sccd.runtime.statecharts_core import *
  9. # package "AfterTransitionTest"
  10. class MainApp(RuntimeClassBase):
  11. def __init__(self, controller):
  12. RuntimeClassBase.__init__(self, controller)
  13. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  14. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  15. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  16. self.semantics.priority = StatechartSemantics.SourceParent
  17. self.semantics.concurrency = StatechartSemantics.Single
  18. # build Statechart structure
  19. self.build_statechart_structure()
  20. # call user defined constructor
  21. MainApp.user_defined_constructor(self)
  22. def user_defined_constructor(self):
  23. pass
  24. def user_defined_destructor(self):
  25. pass
  26. # builds Statechart structure
  27. def build_statechart_structure(self):
  28. # state <root>
  29. self.states[""] = State(0, "", self)
  30. # state /state1
  31. self.states["/state1"] = State(1, "/state1", self)
  32. self.states["/state1"].setEnter(self._state1_enter)
  33. self.states["/state1"].setExit(self._state1_exit)
  34. # state /state2
  35. self.states["/state2"] = State(2, "/state2", self)
  36. # state /state3
  37. self.states["/state3"] = State(3, "/state3", self)
  38. # add children
  39. self.states[""].addChild(self.states["/state1"])
  40. self.states[""].addChild(self.states["/state2"])
  41. self.states[""].addChild(self.states["/state3"])
  42. self.states[""].fixTree()
  43. self.states[""].default_state = self.states["/state1"]
  44. # transition /state1
  45. _state1_0 = Transition(self, self.states["/state1"], [self.states["/state3"]])
  46. _state1_0.setTrigger(Event("_0after"))
  47. self.states["/state1"].addTransition(_state1_0)
  48. def _state1_enter(self):
  49. self.addTimer(0, 1)
  50. def _state1_exit(self):
  51. self.removeTimer(0)
  52. def initializeStatechart(self):
  53. # enter default state
  54. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  55. RuntimeClassBase.initializeStatechart(self)
  56. class ObjectManager(ObjectManagerBase):
  57. def __init__(self, controller):
  58. ObjectManagerBase.__init__(self, controller)
  59. def instantiate(self, class_name, construct_params):
  60. if class_name == "MainApp":
  61. instance = MainApp(self.controller)
  62. instance.associations = {}
  63. else:
  64. raise Exception("Cannot instantiate class " + class_name)
  65. return instance
  66. class Controller(ThreadsControllerBase):
  67. def __init__(self, keep_running = None, behind_schedule_callback = None):
  68. if keep_running == None: keep_running = True
  69. if behind_schedule_callback == None: behind_schedule_callback = None
  70. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  71. self.object_manager.createInstance("MainApp", [])