target.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 3: Check if a state can transition to itself
  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. self.value = 0
  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. # state /state2
  33. self.states["/state2"] = State(2, "/state2", self)
  34. # add children
  35. self.states[""].addChild(self.states["/state1"])
  36. self.states[""].addChild(self.states["/state2"])
  37. self.states[""].fixTree()
  38. self.states[""].default_state = self.states["/state1"]
  39. # transition /state1
  40. _state1_0 = Transition(self, self.states["/state1"], [self.states["/state1"]])
  41. _state1_0.setAction(self._state1_0_exec)
  42. _state1_0.setTrigger(None)
  43. _state1_0.setGuard(self._state1_0_guard)
  44. self.states["/state1"].addTransition(_state1_0)
  45. _state1_1 = Transition(self, self.states["/state1"], [self.states["/state2"]])
  46. _state1_1.setTrigger(None)
  47. _state1_1.setGuard(self._state1_1_guard)
  48. self.states["/state1"].addTransition(_state1_1)
  49. def _state1_0_exec(self, parameters):
  50. self.value = 1
  51. def _state1_0_guard(self, parameters):
  52. return self.value == 0
  53. def _state1_1_guard(self, parameters):
  54. return self.value == 1
  55. def initializeStatechart(self):
  56. # enter default state
  57. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  58. RuntimeClassBase.initializeStatechart(self)
  59. class ObjectManager(ObjectManagerBase):
  60. def __init__(self, controller):
  61. ObjectManagerBase.__init__(self, controller)
  62. def instantiate(self, class_name, construct_params):
  63. if class_name == "MainApp":
  64. instance = MainApp(self.controller)
  65. instance.associations = {}
  66. else:
  67. raise Exception("Cannot instantiate class " + class_name)
  68. return instance
  69. class Controller(ThreadsControllerBase):
  70. def __init__(self, keep_running = None, behind_schedule_callback = None):
  71. if keep_running == None: keep_running = True
  72. if behind_schedule_callback == None: behind_schedule_callback = None
  73. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  74. self.object_manager.createInstance("MainApp", [])