target.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: EndingTest
  5. Model description:
  6. Test 1: Check if the model ends on time.
  7. """
  8. from sccd.runtime.statecharts_core import *
  9. # package "EndingTest"
  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 /end
  35. self.states["/end"] = State(2, "/end", self)
  36. # add children
  37. self.states[""].addChild(self.states["/state1"])
  38. self.states[""].addChild(self.states["/end"])
  39. self.states[""].fixTree()
  40. self.states[""].default_state = self.states["/state1"]
  41. # transition /state1
  42. _state1_0 = Transition(self, self.states["/state1"], [self.states["/end"]])
  43. _state1_0.setTrigger(Event("_0after"))
  44. self.states["/state1"].addTransition(_state1_0)
  45. def _state1_enter(self):
  46. self.addTimer(0, 1)
  47. def _state1_exit(self):
  48. self.removeTimer(0)
  49. def initializeStatechart(self):
  50. # enter default state
  51. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  52. RuntimeClassBase.initializeStatechart(self)
  53. class ObjectManager(ObjectManagerBase):
  54. def __init__(self, controller):
  55. ObjectManagerBase.__init__(self, controller)
  56. def instantiate(self, class_name, construct_params):
  57. if class_name == "MainApp":
  58. instance = MainApp(self.controller)
  59. instance.associations = {}
  60. else:
  61. raise Exception("Cannot instantiate class " + class_name)
  62. return instance
  63. class Controller(ThreadsControllerBase):
  64. def __init__(self, keep_running = None, behind_schedule_callback = None):
  65. if keep_running == None: keep_running = True
  66. if behind_schedule_callback == None: behind_schedule_callback = None
  67. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  68. self.addInputPort("ui")
  69. self.addOutputPort("ui")
  70. self.object_manager.createInstance("MainApp", [])