target.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) and Sam Pieters (DEVS)
  3. Model author: Sam Pieters
  4. Model name: AfterTransitionTest
  5. Model description:
  6. Test 2:
  7. """
  8. from sccd.runtime.DEVS_statecharts_core import *
  9. # package "AfterTransitionTest"
  10. class MainAppInstance(RuntimeClassBase):
  11. def __init__(self, atomdevs, id, start_port_id):
  12. RuntimeClassBase.__init__(self, atomdevs, id)
  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. MainAppInstance.user_defined_constructor(self)
  22. port_name = addInputPort("<narrow_cast>", start_port_id)
  23. atomdevs.state.port_mappings[port_name] = id
  24. def user_defined_constructor(self):
  25. pass
  26. def user_defined_destructor(self):
  27. pass
  28. # builds Statechart structure
  29. def build_statechart_structure(self):
  30. # state <root>
  31. self.states[""] = State(0, "", self)
  32. # state /state1
  33. self.states["/state1"] = State(1, "/state1", self)
  34. # add children
  35. self.states[""].addChild(self.states["/state1"])
  36. self.states[""].fixTree()
  37. self.states[""].default_state = self.states["/state1"]
  38. def initializeStatechart(self):
  39. # enter default state
  40. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  41. RuntimeClassBase.initializeStatechart(self)
  42. class MainApp(ClassBase):
  43. def __init__(self, name):
  44. ClassBase.__init__(self, name)
  45. self.input = self.addInPort("input")
  46. new_instance = self.constructObject(0, 0, [])
  47. self.state.instances[new_instance.instance_id] = new_instance
  48. self.state.next_instance = self.state.next_instance + 1
  49. def constructObject(self, id, start_port_id, parameters):
  50. new_instance = MainAppInstance(self, id, start_port_id)
  51. return new_instance
  52. def instantiate(self, class_name, construct_params):
  53. instance = {}
  54. instance["name"] = class_name
  55. if class_name == "MainApp":
  56. self.narrow_cast_id = self.narrow_cast_id + 0
  57. instance["associations"] = {}
  58. else:
  59. raise Exception("Cannot instantiate class " + class_name)
  60. return instance
  61. ObjectManagerState.instantiate = instantiate
  62. class ObjectManager(ObjectManagerBase):
  63. def __init__(self, name):
  64. ObjectManagerBase.__init__(self, name)
  65. self.state = ObjectManagerState()
  66. self.input = self.addInPort("input")
  67. self.output["MainApp"] = self.addOutPort()
  68. self.state.createInstance("MainApp", [])
  69. self.state.to_send.append((("MainApp", 0), ("MainApp", 0), Event("start_instance", None, ["MainApp[0]"])))
  70. class Controller(CoupledDEVS):
  71. def __init__(self, name):
  72. CoupledDEVS.__init__(self, name)
  73. self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
  74. self.atomics = []
  75. self.atomics.append(self.addSubModel(MainApp("MainApp")))
  76. self.connectPorts(self.atomics[0].obj_manager_out, self.objectmanager.input)
  77. self.connectPorts(self.objectmanager.output["MainApp"], self.atomics[0].obj_manager_in)