target.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Fri Oct 21 13:30:15 2016
  4. Model author: Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo
  5. Model name: CBDSimulator
  6. Model description:
  7. A debuggeable CBD simulator.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. from sccd.runtime.libs.ui import *
  11. from sccd.runtime.libs.utils import *
  12. from CBD_Controller import CBDController
  13. import Options
  14. import sccd.runtime.accurate_time as accurate_time
  15. class Breakpoint:
  16. def __init__(self, name, function, enabled, disable_on_trigger):
  17. self.name = name
  18. self.function = function
  19. self.enabled = enabled
  20. self.disable_on_trigger = disable_on_trigger
  21. # package "CBDSimulator"
  22. class CBDSimulator(RuntimeClassBase):
  23. def __init__(self, controller, options, model):
  24. RuntimeClassBase.__init__(self, controller)
  25. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  26. self.semantics.internal_event_lifeline = StatechartSemantics.NextComboStep
  27. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  28. self.semantics.priority = StatechartSemantics.SourceParent
  29. self.semantics.concurrency = StatechartSemantics.Single
  30. # build Statechart structure
  31. self.build_statechart_structure()
  32. # user defined attributes
  33. self.iteration = None
  34. self.cbdController = None
  35. self.delta = None
  36. self.clock = None
  37. self.model = None
  38. self.depGraph = None
  39. self.strongComponentList = None
  40. self.currentCompIdx = None
  41. # call user defined constructor
  42. CBDSimulator.user_defined_constructor(self, options, model)
  43. def user_defined_constructor(self, options, model):
  44. self.options = options
  45. self.delta = self.options.getDeltaT() * 1000.0
  46. self.model = model
  47. self.initialized = False
  48. def user_defined_destructor(self):
  49. pass
  50. # user defined method
  51. def currentComponentIsCycle(self):
  52. return self.cbdController.componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
  53. # user defined method
  54. def hasNextStrongComponent(self):
  55. return self.currentCompIdx < len(self.strongComponentList)
  56. # user defined method
  57. def computeBlock(self):
  58. if self.currentComponentIsCycle():
  59. self.cbdController.computeNextAlgebraicLoop(self.strongComponentList[self.currentCompIdx], self.iteration)
  60. else:
  61. self.cbdController.computeNextBlock(self.strongComponentList[self.currentCompIdx], self.iteration)
  62. # user defined method
  63. def advanceTime(self):
  64. self.iteration = self.iteration + 1
  65. self.clock = self.time_next
  66. self.cbdController.advanceTimeStep()
  67. self.time_next = self.clock + self.delta
  68. # user defined method
  69. def initialize(self):
  70. self.iteration = 0
  71. self.clock = 0
  72. self.time_next = self.delta
  73. self.cbdController = CBDController(self.model, self.delta / 1000.0)
  74. self.cbdController.initSimulation()
  75. self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
  76. self.initialized = True
  77. # user defined method
  78. def initializeDebugger(self):
  79. self.breakpoints = []
  80. self.triggered_bp = None
  81. # user defined method
  82. def endCondition(self):
  83. return self.initialized and self.iteration >= self.options.getMaxIterations()
  84. # user defined method
  85. def finalize(self):
  86. from bokeh.plotting import figure, output_file, show
  87. times = []
  88. values = []
  89. for timeValuePair in self.model.getSignal("neg"):
  90. times.append(timeValuePair.time)
  91. values.append(timeValuePair.value)
  92. output_file("./plot.html", title="Plot")
  93. p = figure(title="Something vs Otherthing", x_axis_label="Time", y_axis_label="Values")
  94. p.line(times, values, legend="Something", line_width=1, line_color="red")
  95. show(p)
  96. # user defined method
  97. def waitTime(self):
  98. # First, we convert from wall-clock time to simulated time.
  99. # This means the elapsed time in wall-clock time needs to be scaled according to the realtime scale (for example, if the realtime scale is 2, an elapsed time of 1 second in wall-clock time is equal to an elapsed time of 2 seconds in simulated time).
  100. simulated_diff = (accurate_time.time() - self.realtime_start_time) * self.realtime_scale
  101. # time_next and simulated_diff are both in simulated time: so now scale back to wall-clock time by dividing.
  102. # This function returns an amount of miliseconds.
  103. return ((self.time_next - simulated_diff) / self.realtime_scale)
  104. # user defined method
  105. def addBreakpoint(self, name, function, enabled = None, disable_on_trigger = None):
  106. if enabled == None: enabled = true
  107. if disable_on_trigger == None: disable_on_trigger = true
  108. if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
  109. return -1
  110. self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
  111. return 0
  112. # user defined method
  113. def delBreakpoint(self, name):
  114. if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
  115. return -1
  116. self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
  117. return 0
  118. # user defined method
  119. def toggleBreakpoint(self, name):
  120. if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
  121. return -1
  122. for bp in self.breakpoints:
  123. if bp.name == name:
  124. bp.enabled = enabled
  125. break
  126. return 0
  127. # user defined method
  128. def breakpointTriggers(self, is_realtime_simulation):
  129. self.triggered_bp = None
  130. for bp in self.breakpoints:
  131. if not bp.enabled:
  132. continue
  133. # include the function in the scope...
  134. exec(bp.function)
  135. # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
  136. # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
  137. # this is to make sure that the simulation is stopped BEFORE the specified time is reached, and not AFTER (because we don't necessarily implement 'step back')
  138. # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
  139. if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.state}):
  140. # triggered!
  141. self.triggered_bp = bp.name
  142. if bp.disable_on_trigger:
  143. bp.enabled = False
  144. return True
  145. else:
  146. # not triggered, so continue
  147. continue
  148. return False
  149. # user defined method
  150. def godEvent(self, block_name, new_val):
  151. if block_name not in self.state:
  152. return -1
  153. for b in self.model.getBlocks():
  154. if b.getBlockName() == block_name:
  155. b.setSignal(new_val)
  156. self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
  157. return 0
  158. # builds Statechart structure
  159. def build_statechart_structure(self):
  160. # state <root>
  161. self.states[""] = State(0, self)
  162. # state /Main
  163. self.states["/Main"] = ParallelState(1, self)
  164. # state /Main/SimulationState
  165. self.states["/Main/SimulationState"] = State(2, self)
  166. # state /Main/SimulationState/Paused
  167. self.states["/Main/SimulationState/Paused"] = State(3, self)
  168. # state /Main/SimulationState/PrePaused
  169. self.states["/Main/SimulationState/PrePaused"] = State(4, self)
  170. self.states["/Main/SimulationState/PrePaused"].setEnter(self._Main_SimulationState_PrePaused_enter)
  171. self.states["/Main/SimulationState/PrePaused"].setExit(self._Main_SimulationState_PrePaused_exit)
  172. # state /Main/SimulationState/PreBreakpointTriggered
  173. self.states["/Main/SimulationState/PreBreakpointTriggered"] = State(5, self)
  174. self.states["/Main/SimulationState/PreBreakpointTriggered"].setEnter(self._Main_SimulationState_PreBreakpointTriggered_enter)
  175. self.states["/Main/SimulationState/PreBreakpointTriggered"].setExit(self._Main_SimulationState_PreBreakpointTriggered_exit)
  176. # state /Main/SimulationState/Running
  177. self.states["/Main/SimulationState/Running"] = State(6, self)
  178. # state /Main/SimulationState/Running/Continuous
  179. self.states["/Main/SimulationState/Running/Continuous"] = State(7, self)
  180. # state /Main/SimulationState/Running/BigStep
  181. self.states["/Main/SimulationState/Running/BigStep"] = State(8, self)
  182. # state /Main/SimulationState/Running/BigStepDone
  183. self.states["/Main/SimulationState/Running/BigStepDone"] = State(9, self)
  184. self.states["/Main/SimulationState/Running/BigStepDone"].setEnter(self._Main_SimulationState_Running_BigStepDone_enter)
  185. self.states["/Main/SimulationState/Running/BigStepDone"].setExit(self._Main_SimulationState_Running_BigStepDone_exit)
  186. # state /Main/SimulationState/Running/SmallStep
  187. self.states["/Main/SimulationState/Running/SmallStep"] = State(10, self)
  188. # state /Main/SimulationState/Running/SmallStepDone
  189. self.states["/Main/SimulationState/Running/SmallStepDone"] = State(11, self)
  190. self.states["/Main/SimulationState/Running/SmallStepDone"].setEnter(self._Main_SimulationState_Running_SmallStepDone_enter)
  191. self.states["/Main/SimulationState/Running/SmallStepDone"].setExit(self._Main_SimulationState_Running_SmallStepDone_exit)
  192. # state /Main/SimulationState/Running/Realtime
  193. self.states["/Main/SimulationState/Running/Realtime"] = State(12, self)
  194. self.states["/Main/SimulationState/Running/Realtime"].setEnter(self._Main_SimulationState_Running_Realtime_enter)
  195. # state /Main/SimulationState/PreStopped
  196. self.states["/Main/SimulationState/PreStopped"] = State(13, self)
  197. self.states["/Main/SimulationState/PreStopped"].setEnter(self._Main_SimulationState_PreStopped_enter)
  198. self.states["/Main/SimulationState/PreStopped"].setExit(self._Main_SimulationState_PreStopped_exit)
  199. # state /Main/SimulationState/Stopped
  200. self.states["/Main/SimulationState/Stopped"] = State(14, self)
  201. self.states["/Main/SimulationState/Stopped"].setEnter(self._Main_SimulationState_Stopped_enter)
  202. # state /Main/SimulationFlow
  203. self.states["/Main/SimulationFlow"] = State(15, self)
  204. # state /Main/SimulationFlow/Initialize
  205. self.states["/Main/SimulationFlow/Initialize"] = State(16, self)
  206. self.states["/Main/SimulationFlow/Initialize"].setEnter(self._Main_SimulationFlow_Initialize_enter)
  207. # state /Main/SimulationFlow/InitializeDebugger
  208. self.states["/Main/SimulationFlow/InitializeDebugger"] = State(17, self)
  209. self.states["/Main/SimulationFlow/InitializeDebugger"].setEnter(self._Main_SimulationFlow_InitializeDebugger_enter)
  210. # state /Main/SimulationFlow/CheckTerminationCondition
  211. self.states["/Main/SimulationFlow/CheckTerminationCondition"] = State(18, self)
  212. # state /Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed
  213. self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"] = State(19, self)
  214. # state /Main/SimulationFlow/Waiting
  215. self.states["/Main/SimulationFlow/Waiting"] = State(20, self)
  216. self.states["/Main/SimulationFlow/Waiting"].setEnter(self._Main_SimulationFlow_Waiting_enter)
  217. self.states["/Main/SimulationFlow/Waiting"].setExit(self._Main_SimulationFlow_Waiting_exit)
  218. # state /Main/SimulationFlow/DoSimulation
  219. self.states["/Main/SimulationFlow/DoSimulation"] = State(21, self)
  220. # state /Main/SimulationFlow/DoSimulation/MacroStepPrepared
  221. self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"] = State(22, self)
  222. # state /Main/SimulationFlow/DoSimulation/MicroStepProcessed
  223. self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"] = State(23, self)
  224. self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].setEnter(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_enter)
  225. self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].setExit(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_exit)
  226. # state /Main/SimulationFlow/DoSimulation/PreMicroStepPrepared
  227. self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"] = State(24, self)
  228. # state /Main/SimulationFlow/DoSimulation/MicroStepPrepared
  229. self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"] = State(25, self)
  230. # state /Main/SimulationFlow/Stopped
  231. self.states["/Main/SimulationFlow/Stopped"] = State(26, self)
  232. self.states["/Main/SimulationFlow/Stopped"].setEnter(self._Main_SimulationFlow_Stopped_enter)
  233. # state /Main/BreakpointManager
  234. self.states["/Main/BreakpointManager"] = State(27, self)
  235. # state /Main/BreakpointManager/Listening
  236. self.states["/Main/BreakpointManager/Listening"] = State(28, self)
  237. # state /Main/GodEventManager
  238. self.states["/Main/GodEventManager"] = State(29, self)
  239. # state /Main/GodEventManager/Listening
  240. self.states["/Main/GodEventManager/Listening"] = State(30, self)
  241. # state /Main/UserOutput
  242. self.states["/Main/UserOutput"] = State(31, self)
  243. # state /Main/UserOutput/Waiting
  244. self.states["/Main/UserOutput/Waiting"] = State(32, self)
  245. # state /SimulationComplete
  246. self.states["/SimulationComplete"] = State(33, self)
  247. # add children
  248. self.states[""].addChild(self.states["/Main"])
  249. self.states[""].addChild(self.states["/SimulationComplete"])
  250. self.states["/Main"].addChild(self.states["/Main/SimulationState"])
  251. self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
  252. self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
  253. self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
  254. self.states["/Main"].addChild(self.states["/Main/UserOutput"])
  255. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Paused"])
  256. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PrePaused"])
  257. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PreBreakpointTriggered"])
  258. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Running"])
  259. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PreStopped"])
  260. self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Stopped"])
  261. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/Continuous"])
  262. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/BigStep"])
  263. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/BigStepDone"])
  264. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/SmallStep"])
  265. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/SmallStepDone"])
  266. self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/Realtime"])
  267. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialize"])
  268. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
  269. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTerminationCondition"])
  270. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
  271. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/DoSimulation"])
  272. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
  273. self.states["/Main/SimulationFlow/CheckTerminationCondition"].addChild(self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"])
  274. self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"])
  275. self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"])
  276. self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"])
  277. self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"])
  278. self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
  279. self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
  280. self.states["/Main/UserOutput"].addChild(self.states["/Main/UserOutput/Waiting"])
  281. self.states[""].fixTree()
  282. self.states[""].default_state = self.states["/Main"]
  283. self.states["/Main/SimulationState"].default_state = self.states["/Main/SimulationState/Paused"]
  284. self.states["/Main/SimulationState/Running"].default_state = self.states["/Main/SimulationState/Running/Continuous"]
  285. self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Initialize"]
  286. self.states["/Main/SimulationFlow/CheckTerminationCondition"].default_state = self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"]
  287. self.states["/Main/SimulationFlow/DoSimulation"].default_state = self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"]
  288. self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
  289. self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
  290. self.states["/Main/UserOutput"].default_state = self.states["/Main/UserOutput/Waiting"]
  291. # transition /Main/SimulationState/Paused
  292. _Main_SimulationState_Paused_0 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/Continuous"]])
  293. _Main_SimulationState_Paused_0.setTrigger(Event("continuous", "user_input"))
  294. self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_0)
  295. _Main_SimulationState_Paused_1 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/Realtime"]])
  296. _Main_SimulationState_Paused_1.setAction(self._Main_SimulationState_Paused_1_exec)
  297. _Main_SimulationState_Paused_1.setTrigger(Event("realtime", "user_input"))
  298. self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_1)
  299. _Main_SimulationState_Paused_2 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/BigStep"]])
  300. _Main_SimulationState_Paused_2.setTrigger(Event("big_step", "user_input"))
  301. self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_2)
  302. _Main_SimulationState_Paused_3 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/SmallStep"]])
  303. _Main_SimulationState_Paused_3.setTrigger(Event("small_step", "user_input"))
  304. self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_3)
  305. _Main_SimulationState_Paused_4 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/PreStopped"]])
  306. _Main_SimulationState_Paused_4.setTrigger(None)
  307. _Main_SimulationState_Paused_4.setGuard(self._Main_SimulationState_Paused_4_guard)
  308. self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_4)
  309. # transition /Main/SimulationState/PrePaused
  310. _Main_SimulationState_PrePaused_0 = Transition(self, self.states["/Main/SimulationState/PrePaused"], [self.states["/Main/SimulationState/Paused"]])
  311. _Main_SimulationState_PrePaused_0.setAction(self._Main_SimulationState_PrePaused_0_exec)
  312. _Main_SimulationState_PrePaused_0.setTrigger(Event("_0after"))
  313. self.states["/Main/SimulationState/PrePaused"].addTransition(_Main_SimulationState_PrePaused_0)
  314. # transition /Main/SimulationState/PreBreakpointTriggered
  315. _Main_SimulationState_PreBreakpointTriggered_0 = Transition(self, self.states["/Main/SimulationState/PreBreakpointTriggered"], [self.states["/Main/SimulationState/Paused"]])
  316. _Main_SimulationState_PreBreakpointTriggered_0.setAction(self._Main_SimulationState_PreBreakpointTriggered_0_exec)
  317. _Main_SimulationState_PreBreakpointTriggered_0.setTrigger(Event("_1after"))
  318. self.states["/Main/SimulationState/PreBreakpointTriggered"].addTransition(_Main_SimulationState_PreBreakpointTriggered_0)
  319. # transition /Main/SimulationState/Running/BigStep
  320. _Main_SimulationState_Running_BigStep_0 = Transition(self, self.states["/Main/SimulationState/Running/BigStep"], [self.states["/Main/SimulationState/Running/BigStepDone"]])
  321. _Main_SimulationState_Running_BigStep_0.setTrigger(Event("big_step_done", None))
  322. self.states["/Main/SimulationState/Running/BigStep"].addTransition(_Main_SimulationState_Running_BigStep_0)
  323. # transition /Main/SimulationState/Running/BigStepDone
  324. _Main_SimulationState_Running_BigStepDone_0 = Transition(self, self.states["/Main/SimulationState/Running/BigStepDone"], [self.states["/Main/SimulationState/Paused"]])
  325. _Main_SimulationState_Running_BigStepDone_0.setTrigger(Event("_2after"))
  326. self.states["/Main/SimulationState/Running/BigStepDone"].addTransition(_Main_SimulationState_Running_BigStepDone_0)
  327. # transition /Main/SimulationState/Running/SmallStep
  328. _Main_SimulationState_Running_SmallStep_0 = Transition(self, self.states["/Main/SimulationState/Running/SmallStep"], [self.states["/Main/SimulationState/Running/SmallStepDone"]])
  329. _Main_SimulationState_Running_SmallStep_0.setTrigger(Event("small_step_done", None))
  330. self.states["/Main/SimulationState/Running/SmallStep"].addTransition(_Main_SimulationState_Running_SmallStep_0)
  331. # transition /Main/SimulationState/Running/SmallStepDone
  332. _Main_SimulationState_Running_SmallStepDone_0 = Transition(self, self.states["/Main/SimulationState/Running/SmallStepDone"], [self.states["/Main/SimulationState/Paused"]])
  333. _Main_SimulationState_Running_SmallStepDone_0.setTrigger(Event("_3after"))
  334. self.states["/Main/SimulationState/Running/SmallStepDone"].addTransition(_Main_SimulationState_Running_SmallStepDone_0)
  335. # transition /Main/SimulationState/PreStopped
  336. _Main_SimulationState_PreStopped_0 = Transition(self, self.states["/Main/SimulationState/PreStopped"], [self.states["/Main/SimulationState/Stopped"]])
  337. _Main_SimulationState_PreStopped_0.setAction(self._Main_SimulationState_PreStopped_0_exec)
  338. _Main_SimulationState_PreStopped_0.setTrigger(Event("_4after"))
  339. self.states["/Main/SimulationState/PreStopped"].addTransition(_Main_SimulationState_PreStopped_0)
  340. # transition /Main/SimulationFlow/Initialize
  341. _Main_SimulationFlow_Initialize_0 = Transition(self, self.states["/Main/SimulationFlow/Initialize"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
  342. _Main_SimulationFlow_Initialize_0.setTrigger(None)
  343. self.states["/Main/SimulationFlow/Initialize"].addTransition(_Main_SimulationFlow_Initialize_0)
  344. # transition /Main/SimulationFlow/InitializeDebugger
  345. _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/CheckTerminationCondition"]])
  346. _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
  347. self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
  348. # transition /Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed
  349. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"], [self.states["/Main/SimulationFlow/DoSimulation"]])
  350. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0.setAction(self._Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0_exec)
  351. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0.setTrigger(None)
  352. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0.setGuard(self._Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0_guard)
  353. self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0)
  354. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"], [self.states["/Main/SimulationFlow/Waiting"]])
  355. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1.setTrigger(None)
  356. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1.setGuard(self._Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1_guard)
  357. self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1)
  358. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2 = Transition(self, self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"], [self.states["/Main/SimulationFlow/Stopped"]])
  359. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2.setTrigger(None)
  360. _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2.setGuard(self._Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2_guard)
  361. self.states["/Main/SimulationFlow/CheckTerminationCondition/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2)
  362. # transition /Main/SimulationFlow/Waiting
  363. _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTerminationCondition"]])
  364. _Main_SimulationFlow_Waiting_0.setAction(self._Main_SimulationFlow_Waiting_0_exec)
  365. _Main_SimulationFlow_Waiting_0.setTrigger(Event("_5after"))
  366. self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
  367. _Main_SimulationFlow_Waiting_1 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/DoSimulation"]])
  368. _Main_SimulationFlow_Waiting_1.setAction(self._Main_SimulationFlow_Waiting_1_exec)
  369. _Main_SimulationFlow_Waiting_1.setTrigger(None)
  370. _Main_SimulationFlow_Waiting_1.setGuard(self._Main_SimulationFlow_Waiting_1_guard)
  371. self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_1)
  372. # transition /Main/SimulationFlow/DoSimulation/MacroStepPrepared
  373. _Main_SimulationFlow_DoSimulation_MacroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"]])
  374. _Main_SimulationFlow_DoSimulation_MacroStepPrepared_0.setTrigger(None)
  375. self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_MacroStepPrepared_0)
  376. # transition /Main/SimulationFlow/DoSimulation/MicroStepProcessed
  377. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"], [self.states["/Main/SimulationFlow/CheckTerminationCondition"]])
  378. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0.setAction(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_exec)
  379. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0.setTrigger(Event("_6after"))
  380. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0.setGuard(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_guard)
  381. self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepProcessed_0)
  382. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"], [self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"]])
  383. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1.setTrigger(Event("_7after"))
  384. _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1.setGuard(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_guard)
  385. self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepProcessed_1)
  386. # transition /Main/SimulationFlow/DoSimulation/PreMicroStepPrepared
  387. _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"]])
  388. _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0.setTrigger(None)
  389. _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0.setGuard(self._Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0_guard)
  390. self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0)
  391. # transition /Main/SimulationFlow/DoSimulation/MicroStepPrepared
  392. _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"]])
  393. _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0.setAction(self._Main_SimulationFlow_DoSimulation_MicroStepPrepared_0_exec)
  394. _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0.setTrigger(None)
  395. self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepPrepared_0)
  396. # transition /Main/BreakpointManager/Listening
  397. _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  398. _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
  399. _Main_BreakpointManager_Listening_0.setTrigger(Event("add_breakpoint", "user_input"))
  400. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
  401. _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  402. _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
  403. _Main_BreakpointManager_Listening_1.setTrigger(Event("del_breakpoint", "user_input"))
  404. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
  405. _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  406. _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
  407. _Main_BreakpointManager_Listening_2.setTrigger(Event("toggle_breakpoint", "user_input"))
  408. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
  409. _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  410. _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
  411. _Main_BreakpointManager_Listening_3.setTrigger(Event("list_breakpoints", "user_input"))
  412. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
  413. # transition /Main/GodEventManager/Listening
  414. _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Listening"]])
  415. _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
  416. _Main_GodEventManager_Listening_0.setTrigger(Event("god_event", "user_input"))
  417. _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
  418. self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
  419. # transition /Main/UserOutput/Waiting
  420. _Main_UserOutput_Waiting_0 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
  421. _Main_UserOutput_Waiting_0.setAction(self._Main_UserOutput_Waiting_0_exec)
  422. _Main_UserOutput_Waiting_0.setTrigger(Event("termination_condition", None))
  423. self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_0)
  424. _Main_UserOutput_Waiting_1 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
  425. _Main_UserOutput_Waiting_1.setAction(self._Main_UserOutput_Waiting_1_exec)
  426. _Main_UserOutput_Waiting_1.setTrigger(Event("paused", None))
  427. self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_1)
  428. _Main_UserOutput_Waiting_2 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
  429. _Main_UserOutput_Waiting_2.setAction(self._Main_UserOutput_Waiting_2_exec)
  430. _Main_UserOutput_Waiting_2.setTrigger(Event("big_step_done", None))
  431. _Main_UserOutput_Waiting_2.setGuard(self._Main_UserOutput_Waiting_2_guard)
  432. self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_2)
  433. _Main_UserOutput_Waiting_3 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
  434. _Main_UserOutput_Waiting_3.setAction(self._Main_UserOutput_Waiting_3_exec)
  435. _Main_UserOutput_Waiting_3.setTrigger(Event("small_step_done", None))
  436. _Main_UserOutput_Waiting_3.setGuard(self._Main_UserOutput_Waiting_3_guard)
  437. self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_3)
  438. _Main_UserOutput_Waiting_4 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
  439. _Main_UserOutput_Waiting_4.setAction(self._Main_UserOutput_Waiting_4_exec)
  440. _Main_UserOutput_Waiting_4.setTrigger(Event("breakpoint_triggered", None))
  441. self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_4)
  442. # transition /Main
  443. _Main_0 = Transition(self, self.states["/Main"], [self.states["/SimulationComplete"]])
  444. _Main_0.setAction(self._Main_0_exec)
  445. _Main_0.setTrigger(None)
  446. _Main_0.setGuard(self._Main_0_guard)
  447. self.states["/Main"].addTransition(_Main_0)
  448. # transition /Main/SimulationState/Running
  449. _Main_SimulationState_Running_0 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PreStopped"]])
  450. _Main_SimulationState_Running_0.setTrigger(None)
  451. _Main_SimulationState_Running_0.setGuard(self._Main_SimulationState_Running_0_guard)
  452. self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_0)
  453. _Main_SimulationState_Running_1 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PrePaused"]])
  454. _Main_SimulationState_Running_1.setTrigger(Event("pause", "user_input"))
  455. self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_1)
  456. _Main_SimulationState_Running_2 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PreBreakpointTriggered"]])
  457. _Main_SimulationState_Running_2.setTrigger(None)
  458. _Main_SimulationState_Running_2.setGuard(self._Main_SimulationState_Running_2_guard)
  459. self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_2)
  460. def _Main_SimulationState_PrePaused_enter(self):
  461. self.addTimer(0, self.sccd_yield() * 2)
  462. def _Main_SimulationState_PrePaused_exit(self):
  463. self.removeTimer(0)
  464. def _Main_SimulationState_PreBreakpointTriggered_enter(self):
  465. self.addTimer(1, self.sccd_yield() * 2)
  466. def _Main_SimulationState_PreBreakpointTriggered_exit(self):
  467. self.removeTimer(1)
  468. def _Main_SimulationState_Running_BigStepDone_enter(self):
  469. self.addTimer(2, self.sccd_yield())
  470. def _Main_SimulationState_Running_BigStepDone_exit(self):
  471. self.removeTimer(2)
  472. def _Main_SimulationState_Running_SmallStepDone_enter(self):
  473. self.addTimer(3, self.sccd_yield())
  474. def _Main_SimulationState_Running_SmallStepDone_exit(self):
  475. self.removeTimer(3)
  476. def _Main_SimulationState_Running_Realtime_enter(self):
  477. # If the simulation was paused, we need to reset the start time of the simulation.
  478. # The start time of the simulation is equal to the point in wall-clock time where simulated time is 0.
  479. # If the simulation was paused, we have to recompute this point in time: it is the difference of the wall-clock time and the simulated time.
  480. # If the scale was changed after the pause, this point of course moves backwards (for scales smaller than 1) or forwards (for scales larger than 1)
  481. self.realtime_start_time = accurate_time.time() - (self.clock / self.realtime_scale)
  482. def _Main_SimulationState_PreStopped_enter(self):
  483. self.addTimer(4, self.sccd_yield() * 2)
  484. def _Main_SimulationState_PreStopped_exit(self):
  485. self.removeTimer(4)
  486. def _Main_SimulationState_Stopped_enter(self):
  487. print 'arriving in SimulationState/Stopped'
  488. def _Main_SimulationFlow_Initialize_enter(self):
  489. self.initialize()
  490. def _Main_SimulationFlow_InitializeDebugger_enter(self):
  491. self.initializeDebugger()
  492. def _Main_SimulationFlow_Waiting_enter(self):
  493. self.addTimer(5, self.sccd_yield())
  494. def _Main_SimulationFlow_Waiting_exit(self):
  495. self.removeTimer(5)
  496. def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_enter(self):
  497. self.addTimer(6, self.sccd_yield())
  498. self.addTimer(7, self.sccd_yield() * 3)
  499. def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_exit(self):
  500. self.removeTimer(6)
  501. self.removeTimer(7)
  502. def _Main_SimulationFlow_Stopped_enter(self):
  503. print 'arriving in SimulationFlow/Stopped'
  504. def _Main_0_exec(self, parameters):
  505. print 'finalizing'
  506. self.finalize()
  507. def _Main_0_guard(self, parameters):
  508. return self.inState(["/Main/SimulationState/Stopped"]) and self.inState(["/Main/SimulationFlow/Stopped"])
  509. def _Main_SimulationState_Running_0_guard(self, parameters):
  510. return self.endCondition()
  511. def _Main_SimulationState_Running_2_guard(self, parameters):
  512. return self.breakpointTriggers(self.inState(["/Main/SimulationState/Running/Realtime"]))
  513. def _Main_SimulationState_Paused_1_exec(self, parameters):
  514. realtime_scale = parameters[0]
  515. self.realtime_scale = float(realtime_scale)
  516. def _Main_SimulationState_Paused_4_guard(self, parameters):
  517. return self.endCondition()
  518. def _Main_SimulationState_PrePaused_0_exec(self, parameters):
  519. self.raiseInternalEvent(Event("paused", None, []))
  520. def _Main_SimulationState_PreBreakpointTriggered_0_exec(self, parameters):
  521. self.raiseInternalEvent(Event("breakpoint_triggered", None, []))
  522. def _Main_SimulationState_PreStopped_0_exec(self, parameters):
  523. self.raiseInternalEvent(Event("termination_condition", None, []))
  524. def _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0_exec(self, parameters):
  525. self.currentCompIdx = 0
  526. self.depGraph = self.cbdController.createDepGraph(self.iteration)
  527. self.strongComponentList = self.cbdController.createStrongComponents(self.depGraph, self.iteration)
  528. def _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_0_guard(self, parameters):
  529. return self.inState(["/Main/SimulationState/Running/Continuous"]) or self.inState(["/Main/SimulationState/Running/BigStep"]) or self.inState(["/Main/SimulationState/Running/SmallStep"])
  530. def _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_1_guard(self, parameters):
  531. return self.inState(["/Main/SimulationState/Running/Realtime"])
  532. def _Main_SimulationFlow_CheckTerminationCondition_MacroStepProcessed_2_guard(self, parameters):
  533. return self.inState(["/Main/SimulationState/Stopped"])
  534. def _Main_SimulationFlow_Waiting_0_exec(self, parameters):
  535. diff = accurate_time.time() - self.realtime_start_time
  536. self.clock = diff * self.realtime_scale
  537. def _Main_SimulationFlow_Waiting_1_exec(self, parameters):
  538. self.currentCompIdx = 0
  539. self.depGraph = self.cbdController.createDepGraph(self.iteration)
  540. self.strongComponentList = self.cbdController.createStrongComponents(self.depGraph, self.iteration)
  541. def _Main_SimulationFlow_Waiting_1_guard(self, parameters):
  542. return self.waitTime() / 1000.0 <= self.sccd_yield()
  543. def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_exec(self, parameters):
  544. self.advanceTime()
  545. self.raiseInternalEvent(Event("big_step_done", None, []))
  546. def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_guard(self, parameters):
  547. return not self.hasNextStrongComponent()
  548. def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_guard(self, parameters):
  549. return self.hasNextStrongComponent()
  550. def _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0_guard(self, parameters):
  551. return self.inState(["/Main/SimulationState/Running"])
  552. def _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0_exec(self, parameters):
  553. self.computeBlock()
  554. self.currentCompIdx = self.currentCompIdx + 1
  555. self.raiseInternalEvent(Event("small_step_done", None, []))
  556. def _Main_BreakpointManager_Listening_0_exec(self, parameters):
  557. name = parameters[0]
  558. function = parameters[1]
  559. enabled = parameters[2]
  560. disable_on_trigger = parameters[3]
  561. result = self.addBreakpoint(name, function, bool(enabled), bool(disable_on_trigger))
  562. self.big_step.outputEvent(Event("add_breakpoint_result", "user_output", [result]))
  563. def _Main_BreakpointManager_Listening_1_exec(self, parameters):
  564. name = parameters[0]
  565. result = self.delBreakpoint(name)
  566. self.big_step.outputEvent(Event("del_breakpoint_result", "user_output", [result]))
  567. def _Main_BreakpointManager_Listening_2_exec(self, parameters):
  568. name = parameters[0]
  569. result = self.toggleBreakpoint(name)
  570. self.big_step.outputEvent(Event("toggle_breakpoint_result", "user_output", [result]))
  571. def _Main_BreakpointManager_Listening_3_exec(self, parameters):
  572. self.big_step.outputEvent(Event("list_breakpoints_result", "user_output", [[bp.name for bp in self.breakpoints]]))
  573. def _Main_GodEventManager_Listening_0_exec(self, parameters):
  574. block_name = parameters[0]
  575. new_val = parameters[1]
  576. result = self.godEvent(block_name, new_val)
  577. self.big_step.outputEvent(Event("god_event_result", "user_output", [result]))
  578. def _Main_GodEventManager_Listening_0_guard(self, parameters):
  579. block_name = parameters[0]
  580. new_val = parameters[1]
  581. return self.inState(["/Main/SimulationState/Paused"])
  582. def _Main_UserOutput_Waiting_0_exec(self, parameters):
  583. self.big_step.outputEvent(Event("terminated", "user_output", []))
  584. self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0]))
  585. def _Main_UserOutput_Waiting_1_exec(self, parameters):
  586. self.big_step.outputEvent(Event("paused", "user_output", []))
  587. self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0]))
  588. def _Main_UserOutput_Waiting_2_exec(self, parameters):
  589. self.big_step.outputEvent(Event("big_step_done", "user_output", []))
  590. self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0]))
  591. def _Main_UserOutput_Waiting_2_guard(self, parameters):
  592. return self.inState(["/Main/SimulationState/Running/Realtime"]) or self.inState(["/Main/SimulationState/Running/BigStep"]) or self.inState(["/Main/SimulationState/Running/BigStepDone"])
  593. def _Main_UserOutput_Waiting_3_exec(self, parameters):
  594. self.big_step.outputEvent(Event("small_step_done", "user_output", []))
  595. self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0]))
  596. def _Main_UserOutput_Waiting_3_guard(self, parameters):
  597. return self.inState(["/Main/SimulationState/Running/SmallStep"]) or self.inState(["/Main/SimulationState/Running/SmallStepDone"])
  598. def _Main_UserOutput_Waiting_4_exec(self, parameters):
  599. self.big_step.outputEvent(Event("breakpoint_triggered", "user_output", [self.triggered_bp]))
  600. self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0]))
  601. def initializeStatechart(self):
  602. # enter default state
  603. self.default_targets = self.states["/Main"].getEffectiveTargetStates()
  604. RuntimeClassBase.initializeStatechart(self)
  605. class ObjectManager(ObjectManagerBase):
  606. def __init__(self, controller):
  607. ObjectManagerBase.__init__(self, controller)
  608. def instantiate(self, class_name, construct_params):
  609. if class_name == "CBDSimulator":
  610. instance = CBDSimulator(self.controller, construct_params[0], construct_params[1])
  611. instance.associations = {}
  612. else:
  613. raise Exception("Cannot instantiate class " + class_name)
  614. return instance
  615. class Controller(ThreadsControllerBase):
  616. def __init__(self, options, model, keep_running = None, behind_schedule_callback = None):
  617. if keep_running == None: keep_running = True
  618. if behind_schedule_callback == None: behind_schedule_callback = None
  619. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  620. self.addInputPort("user_input")
  621. self.addInputPort("user_output")
  622. self.object_manager.createInstance("CBDSimulator", [options, model])