target.py 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Wed Nov 09 17:14:30 2016
  4. Model author: Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo
  5. Model name: CBDSimulator_Coordinator
  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_Coordinator"
  22. class CBDSimulator_Coordinator(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.Queue
  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. # call user defined constructor
  33. CBDSimulator_Coordinator.user_defined_constructor(self, options, model)
  34. def user_defined_constructor(self, options, model):
  35. self.options = options
  36. self.model = model
  37. def user_defined_destructor(self):
  38. pass
  39. # builds Statechart structure
  40. def build_statechart_structure(self):
  41. # state <root>
  42. self.states[""] = State(0, "", self)
  43. # state /Main
  44. self.states["/Main"] = ParallelState(1, "/Main", self)
  45. # state /Main/ModeSelector
  46. self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
  47. # state /Main/ModeSelector/Paused
  48. self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
  49. # state /Main/ModeSelector/Running
  50. self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
  51. # state /Main/ModeSelector/Running/Continuous
  52. self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
  53. # state /Main/ModeSelector/Running/Realtime
  54. self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
  55. # state /Main/ModeSelector/Running/BigStep
  56. self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
  57. # state /Main/ModeSelector/Running/SmallStep
  58. self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
  59. # state /Main/ModeSelector/WaitingForPaused
  60. self.states["/Main/ModeSelector/WaitingForPaused"] = State(9, "/Main/ModeSelector/WaitingForPaused", self)
  61. # state /Main/ModeSelector/Stopped
  62. self.states["/Main/ModeSelector/Stopped"] = State(10, "/Main/ModeSelector/Stopped", self)
  63. # state /Main/ChildState
  64. self.states["/Main/ChildState"] = State(11, "/Main/ChildState", self)
  65. # state /Main/ChildState/Uninitialized
  66. self.states["/Main/ChildState/Uninitialized"] = State(12, "/Main/ChildState/Uninitialized", self)
  67. # state /Main/ChildState/Initialized
  68. self.states["/Main/ChildState/Initialized"] = State(13, "/Main/ChildState/Initialized", self)
  69. # state /Main/Initializer
  70. self.states["/Main/Initializer"] = State(14, "/Main/Initializer", self)
  71. # state /Main/Initializer/Waiting
  72. self.states["/Main/Initializer/Waiting"] = State(15, "/Main/Initializer/Waiting", self)
  73. # state /Main/Initializer/CreatingChildSimulator
  74. self.states["/Main/Initializer/CreatingChildSimulator"] = State(16, "/Main/Initializer/CreatingChildSimulator", self)
  75. # state /Main/Initializer/StartingChildSimulator
  76. self.states["/Main/Initializer/StartingChildSimulator"] = State(17, "/Main/Initializer/StartingChildSimulator", self)
  77. # state /Main/SimulationFlow
  78. self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
  79. # state /Main/SimulationFlow/PrePaused
  80. self.states["/Main/SimulationFlow/PrePaused"] = State(19, "/Main/SimulationFlow/PrePaused", self)
  81. self.states["/Main/SimulationFlow/PrePaused"].setEnter(self._Main_SimulationFlow_PrePaused_enter)
  82. self.states["/Main/SimulationFlow/PrePaused"].setExit(self._Main_SimulationFlow_PrePaused_exit)
  83. # state /Main/SimulationFlow/Paused
  84. self.states["/Main/SimulationFlow/Paused"] = State(20, "/Main/SimulationFlow/Paused", self)
  85. # state /Main/SimulationFlow/Executing
  86. self.states["/Main/SimulationFlow/Executing"] = State(21, "/Main/SimulationFlow/Executing", self)
  87. # state /Main/GodEventManager
  88. self.states["/Main/GodEventManager"] = State(22, "/Main/GodEventManager", self)
  89. # state /Main/GodEventManager/Listening
  90. self.states["/Main/GodEventManager/Listening"] = State(23, "/Main/GodEventManager/Listening", self)
  91. # state /Main/GodEventManager/Waiting
  92. self.states["/Main/GodEventManager/Waiting"] = State(24, "/Main/GodEventManager/Waiting", self)
  93. # state /Main/BreakpointManager
  94. self.states["/Main/BreakpointManager"] = State(25, "/Main/BreakpointManager", self)
  95. # state /Main/BreakpointManager/Listening
  96. self.states["/Main/BreakpointManager/Listening"] = State(26, "/Main/BreakpointManager/Listening", self)
  97. # state /Main/BreakpointManager/Waiting
  98. self.states["/Main/BreakpointManager/Waiting"] = State(27, "/Main/BreakpointManager/Waiting", self)
  99. # add children
  100. self.states[""].addChild(self.states["/Main"])
  101. self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
  102. self.states["/Main"].addChild(self.states["/Main/ChildState"])
  103. self.states["/Main"].addChild(self.states["/Main/Initializer"])
  104. self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
  105. self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
  106. self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
  107. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
  108. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
  109. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/WaitingForPaused"])
  110. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Stopped"])
  111. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
  112. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
  113. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
  114. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
  115. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
  116. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
  117. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
  118. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
  119. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
  120. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/PrePaused"])
  121. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Paused"])
  122. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
  123. self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
  124. self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Waiting"])
  125. self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
  126. self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Waiting"])
  127. self.states[""].fixTree()
  128. self.states[""].default_state = self.states["/Main"]
  129. self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
  130. self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
  131. self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
  132. self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
  133. self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Paused"]
  134. self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
  135. self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
  136. # transition /Main/ModeSelector/Paused
  137. _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
  138. _Main_ModeSelector_Paused_0.setTrigger(Event("small_step", "user_input"))
  139. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
  140. _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
  141. _Main_ModeSelector_Paused_1.setTrigger(Event("big_step", "user_input"))
  142. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
  143. _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
  144. _Main_ModeSelector_Paused_2.setTrigger(Event("continuous", "user_input"))
  145. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
  146. _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
  147. _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
  148. _Main_ModeSelector_Paused_3.setTrigger(Event("realtime", "user_input"))
  149. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
  150. _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
  151. _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
  152. _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
  153. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
  154. _Main_ModeSelector_Paused_5 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
  155. _Main_ModeSelector_Paused_5.setAction(self._Main_ModeSelector_Paused_5_exec)
  156. _Main_ModeSelector_Paused_5.setTrigger(Event("Simulation.Finished", None))
  157. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_5)
  158. # transition /Main/ModeSelector/Running/Continuous
  159. _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
  160. _Main_ModeSelector_Running_Continuous_0.setAction(self._Main_ModeSelector_Running_Continuous_0_exec)
  161. _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("pause", "user_input"))
  162. self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
  163. _Main_ModeSelector_Running_Continuous_1 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Stopped"]])
  164. _Main_ModeSelector_Running_Continuous_1.setAction(self._Main_ModeSelector_Running_Continuous_1_exec)
  165. _Main_ModeSelector_Running_Continuous_1.setTrigger(Event("Simulation.Finished", None))
  166. self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_1)
  167. # transition /Main/ModeSelector/Running/Realtime
  168. _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
  169. _Main_ModeSelector_Running_Realtime_0.setAction(self._Main_ModeSelector_Running_Realtime_0_exec)
  170. _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("pause", "user_input"))
  171. self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
  172. _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Stopped"]])
  173. _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
  174. _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("Simulation.Finished", None))
  175. self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
  176. _Main_ModeSelector_Running_Realtime_2 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
  177. _Main_ModeSelector_Running_Realtime_2.setAction(self._Main_ModeSelector_Running_Realtime_2_exec)
  178. _Main_ModeSelector_Running_Realtime_2.setTrigger(Event("BigStep.Finished", None))
  179. self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_2)
  180. # transition /Main/ModeSelector/Running/BigStep
  181. _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
  182. _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
  183. _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
  184. self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
  185. _Main_ModeSelector_Running_BigStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Stopped"]])
  186. _Main_ModeSelector_Running_BigStep_1.setAction(self._Main_ModeSelector_Running_BigStep_1_exec)
  187. _Main_ModeSelector_Running_BigStep_1.setTrigger(Event("Simulation.Finished", None))
  188. self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_1)
  189. # transition /Main/ModeSelector/Running/SmallStep
  190. _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
  191. _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
  192. _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
  193. self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
  194. _Main_ModeSelector_Running_SmallStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
  195. _Main_ModeSelector_Running_SmallStep_1.setAction(self._Main_ModeSelector_Running_SmallStep_1_exec)
  196. _Main_ModeSelector_Running_SmallStep_1.setTrigger(Event("BigStep.Finished", None))
  197. self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_1)
  198. _Main_ModeSelector_Running_SmallStep_2 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Stopped"]])
  199. _Main_ModeSelector_Running_SmallStep_2.setAction(self._Main_ModeSelector_Running_SmallStep_2_exec)
  200. _Main_ModeSelector_Running_SmallStep_2.setTrigger(Event("Simulation.Finished", None))
  201. self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_2)
  202. # transition /Main/ModeSelector/WaitingForPaused
  203. _Main_ModeSelector_WaitingForPaused_0 = Transition(self, self.states["/Main/ModeSelector/WaitingForPaused"], [self.states["/Main/ModeSelector/Paused"]])
  204. _Main_ModeSelector_WaitingForPaused_0.setAction(self._Main_ModeSelector_WaitingForPaused_0_exec)
  205. _Main_ModeSelector_WaitingForPaused_0.setTrigger(Event("Simulation.Paused", None))
  206. self.states["/Main/ModeSelector/WaitingForPaused"].addTransition(_Main_ModeSelector_WaitingForPaused_0)
  207. # transition /Main/ChildState/Uninitialized
  208. _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
  209. _Main_ChildState_Uninitialized_0.setTrigger(Event("Simulation.Initialized", None))
  210. self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
  211. # transition /Main/ChildState/Initialized
  212. _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
  213. _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
  214. _Main_ChildState_Initialized_0.setTrigger(Event("Simulation.Finished", None))
  215. self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
  216. # transition /Main/Initializer/Waiting
  217. _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
  218. _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
  219. _Main_Initializer_Waiting_0.setTrigger(None)
  220. _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
  221. self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
  222. # transition /Main/Initializer/CreatingChildSimulator
  223. _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
  224. _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
  225. _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
  226. self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
  227. # transition /Main/Initializer/StartingChildSimulator
  228. _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Waiting"]])
  229. _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Simulation.Initialized", None))
  230. self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
  231. # transition /Main/SimulationFlow/PrePaused
  232. _Main_SimulationFlow_PrePaused_0 = Transition(self, self.states["/Main/SimulationFlow/PrePaused"], [self.states["/Main/SimulationFlow/Paused"]])
  233. _Main_SimulationFlow_PrePaused_0.setTrigger(Event("_0after"))
  234. self.states["/Main/SimulationFlow/PrePaused"].addTransition(_Main_SimulationFlow_PrePaused_0)
  235. # transition /Main/SimulationFlow/Paused
  236. _Main_SimulationFlow_Paused_0 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
  237. _Main_SimulationFlow_Paused_0.setAction(self._Main_SimulationFlow_Paused_0_exec)
  238. _Main_SimulationFlow_Paused_0.setTrigger(None)
  239. _Main_SimulationFlow_Paused_0.setGuard(self._Main_SimulationFlow_Paused_0_guard)
  240. self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_0)
  241. _Main_SimulationFlow_Paused_1 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
  242. _Main_SimulationFlow_Paused_1.setAction(self._Main_SimulationFlow_Paused_1_exec)
  243. _Main_SimulationFlow_Paused_1.setTrigger(None)
  244. _Main_SimulationFlow_Paused_1.setGuard(self._Main_SimulationFlow_Paused_1_guard)
  245. self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_1)
  246. _Main_SimulationFlow_Paused_2 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
  247. _Main_SimulationFlow_Paused_2.setAction(self._Main_SimulationFlow_Paused_2_exec)
  248. _Main_SimulationFlow_Paused_2.setTrigger(None)
  249. _Main_SimulationFlow_Paused_2.setGuard(self._Main_SimulationFlow_Paused_2_guard)
  250. self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_2)
  251. _Main_SimulationFlow_Paused_3 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
  252. _Main_SimulationFlow_Paused_3.setAction(self._Main_SimulationFlow_Paused_3_exec)
  253. _Main_SimulationFlow_Paused_3.setTrigger(None)
  254. _Main_SimulationFlow_Paused_3.setGuard(self._Main_SimulationFlow_Paused_3_guard)
  255. self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_3)
  256. # transition /Main/SimulationFlow/Executing
  257. _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/Paused"]])
  258. _Main_SimulationFlow_Executing_0.setTrigger(None)
  259. _Main_SimulationFlow_Executing_0.setGuard(self._Main_SimulationFlow_Executing_0_guard)
  260. self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
  261. _Main_SimulationFlow_Executing_1 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/PrePaused"]])
  262. _Main_SimulationFlow_Executing_1.setTrigger(Event("Simulation.Finished", None))
  263. _Main_SimulationFlow_Executing_1.setGuard(self._Main_SimulationFlow_Executing_1_guard)
  264. self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_1)
  265. # transition /Main/GodEventManager/Listening
  266. _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Waiting"]])
  267. _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
  268. _Main_GodEventManager_Listening_0.setTrigger(Event("god_event", "user_input"))
  269. _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
  270. self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
  271. # transition /Main/GodEventManager/Waiting
  272. _Main_GodEventManager_Waiting_0 = Transition(self, self.states["/Main/GodEventManager/Waiting"], [self.states["/Main/GodEventManager/Listening"]])
  273. _Main_GodEventManager_Waiting_0.setAction(self._Main_GodEventManager_Waiting_0_exec)
  274. _Main_GodEventManager_Waiting_0.setTrigger(Event("Simulation.GodEventResult", None))
  275. self.states["/Main/GodEventManager/Waiting"].addTransition(_Main_GodEventManager_Waiting_0)
  276. # transition /Main/BreakpointManager/Listening
  277. _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
  278. _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
  279. _Main_BreakpointManager_Listening_0.setTrigger(Event("add_breakpoint", "user_input"))
  280. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
  281. _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
  282. _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
  283. _Main_BreakpointManager_Listening_1.setTrigger(Event("del_breakpoint", "user_input"))
  284. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
  285. _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
  286. _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
  287. _Main_BreakpointManager_Listening_2.setTrigger(Event("toggle_breakpoint", "user_input"))
  288. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
  289. _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
  290. _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
  291. _Main_BreakpointManager_Listening_3.setTrigger(Event("list_breakpoints", "user_input"))
  292. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
  293. # transition /Main/BreakpointManager/Waiting
  294. _Main_BreakpointManager_Waiting_0 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
  295. _Main_BreakpointManager_Waiting_0.setAction(self._Main_BreakpointManager_Waiting_0_exec)
  296. _Main_BreakpointManager_Waiting_0.setTrigger(Event("Breakpoint.AddResult", None))
  297. self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_0)
  298. _Main_BreakpointManager_Waiting_1 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
  299. _Main_BreakpointManager_Waiting_1.setAction(self._Main_BreakpointManager_Waiting_1_exec)
  300. _Main_BreakpointManager_Waiting_1.setTrigger(Event("Breakpoint.DelResult", None))
  301. self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_1)
  302. _Main_BreakpointManager_Waiting_2 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
  303. _Main_BreakpointManager_Waiting_2.setAction(self._Main_BreakpointManager_Waiting_2_exec)
  304. _Main_BreakpointManager_Waiting_2.setTrigger(Event("Breakpoint.ToggleResult", None))
  305. self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_2)
  306. _Main_BreakpointManager_Waiting_3 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
  307. _Main_BreakpointManager_Waiting_3.setAction(self._Main_BreakpointManager_Waiting_3_exec)
  308. _Main_BreakpointManager_Waiting_3.setTrigger(Event("Breakpoint.ListResult", None))
  309. self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_3)
  310. # transition /Main/ModeSelector/Running
  311. _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  312. _Main_ModeSelector_Running_0.setAction(self._Main_ModeSelector_Running_0_exec)
  313. _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
  314. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
  315. _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  316. _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
  317. _Main_ModeSelector_Running_1.setTrigger(Event("Breakpoint.Triggered", None))
  318. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
  319. def _Main_SimulationFlow_PrePaused_enter(self):
  320. self.addTimer(0, self.sccd_yield())
  321. def _Main_SimulationFlow_PrePaused_exit(self):
  322. self.removeTimer(0)
  323. def _Main_ModeSelector_Running_0_exec(self, parameters):
  324. clock = parameters[0]
  325. state = parameters[1]
  326. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  327. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  328. def _Main_ModeSelector_Running_1_exec(self, parameters):
  329. triggered_bp = parameters[0]
  330. clock = parameters[1]
  331. state = parameters[2]
  332. self.big_step.outputEvent(Event("Breakpoint.Triggered", "user_output", [triggered_bp, clock]))
  333. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  334. def _Main_ModeSelector_Paused_3_exec(self, parameters):
  335. realtime_scale = parameters[0]
  336. self.realtime_scale = float(realtime_scale)
  337. def _Main_ModeSelector_Paused_4_exec(self, parameters):
  338. clock = parameters[0]
  339. iteration = parameters[1]
  340. time_next = parameters[2]
  341. state = parameters[3]
  342. self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
  343. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  344. def _Main_ModeSelector_Paused_5_exec(self, parameters):
  345. clock = parameters[0]
  346. state = parameters[1]
  347. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  348. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  349. def _Main_ModeSelector_Running_Continuous_0_exec(self, parameters):
  350. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
  351. def _Main_ModeSelector_Running_Continuous_1_exec(self, parameters):
  352. clock = parameters[0]
  353. state = parameters[1]
  354. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  355. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  356. def _Main_ModeSelector_Running_Realtime_0_exec(self, parameters):
  357. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
  358. def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
  359. clock = parameters[0]
  360. state = parameters[1]
  361. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  362. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  363. def _Main_ModeSelector_Running_Realtime_2_exec(self, parameters):
  364. clock = parameters[0]
  365. iteration = parameters[1]
  366. time_next = parameters[2]
  367. state = parameters[3]
  368. self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
  369. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  370. def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
  371. clock = parameters[0]
  372. iteration = parameters[1]
  373. time_next = parameters[2]
  374. state = parameters[3]
  375. self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
  376. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  377. def _Main_ModeSelector_Running_BigStep_1_exec(self, parameters):
  378. clock = parameters[0]
  379. state = parameters[1]
  380. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  381. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  382. def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
  383. current_component_idx = parameters[0]
  384. state = parameters[1]
  385. self.big_step.outputEvent(Event("SmallStep.Finished", "user_output", []))
  386. self.big_step.outputEvent(Event("State", "user_output", [current_component_idx]))
  387. def _Main_ModeSelector_Running_SmallStep_1_exec(self, parameters):
  388. clock = parameters[0]
  389. iteration = parameters[1]
  390. time_next = parameters[2]
  391. state = parameters[3]
  392. self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
  393. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  394. def _Main_ModeSelector_Running_SmallStep_2_exec(self, parameters):
  395. clock = parameters[0]
  396. state = parameters[1]
  397. self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
  398. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  399. def _Main_ModeSelector_WaitingForPaused_0_exec(self, parameters):
  400. clock = parameters[0]
  401. state = parameters[1]
  402. self.big_step.outputEvent(Event("Simulation.Paused", "user_output", []))
  403. self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
  404. def _Main_ChildState_Initialized_0_exec(self, parameters):
  405. self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
  406. def _Main_Initializer_Waiting_0_exec(self, parameters):
  407. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Simulation', self.options, self.model]))
  408. def _Main_Initializer_Waiting_0_guard(self, parameters):
  409. return self.inState(["/Main/ChildState/Uninitialized"])
  410. def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
  411. self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
  412. def _Main_SimulationFlow_Paused_0_exec(self, parameters):
  413. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Execute", None, [])]))
  414. def _Main_SimulationFlow_Paused_0_guard(self, parameters):
  415. return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"])
  416. def _Main_SimulationFlow_Paused_1_exec(self, parameters):
  417. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.ExecuteRealtime", None, [self.realtime_scale])]))
  418. def _Main_SimulationFlow_Paused_1_guard(self, parameters):
  419. return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"])
  420. def _Main_SimulationFlow_Paused_2_exec(self, parameters):
  421. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
  422. def _Main_SimulationFlow_Paused_2_guard(self, parameters):
  423. return self.inState(["/Main/ModeSelector/Running/BigStep"]) and self.inState(["/Main/ChildState/Initialized"])
  424. def _Main_SimulationFlow_Paused_3_exec(self, parameters):
  425. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
  426. def _Main_SimulationFlow_Paused_3_guard(self, parameters):
  427. return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"])
  428. def _Main_SimulationFlow_Executing_0_guard(self, parameters):
  429. return self.inState(["/Main/ModeSelector/Paused"])
  430. def _Main_SimulationFlow_Executing_1_guard(self, parameters):
  431. return self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/Realtime"])
  432. def _Main_GodEventManager_Listening_0_exec(self, parameters):
  433. block_name = parameters[0]
  434. new_val = parameters[1]
  435. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.GodEvent", None, [block_name, new_val])]))
  436. def _Main_GodEventManager_Listening_0_guard(self, parameters):
  437. block_name = parameters[0]
  438. new_val = parameters[1]
  439. return self.inState(["/Main/ModeSelector/Paused"])
  440. def _Main_GodEventManager_Waiting_0_exec(self, parameters):
  441. result = parameters[0]
  442. self.big_step.outputEvent(Event("GodEventResult", "user_output", [result]))
  443. def _Main_BreakpointManager_Listening_0_exec(self, parameters):
  444. name = parameters[0]
  445. function = parameters[1]
  446. enabled = parameters[2]
  447. disable_on_trigger = parameters[3]
  448. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Add", None, [name, function, enabled, disable_on_trigger])]))
  449. def _Main_BreakpointManager_Listening_1_exec(self, parameters):
  450. name = parameters[0]
  451. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Del", None, [name])]))
  452. def _Main_BreakpointManager_Listening_2_exec(self, parameters):
  453. name = parameters[0]
  454. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Toggle", None, [name])]))
  455. def _Main_BreakpointManager_Listening_3_exec(self, parameters):
  456. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.List", None, [])]))
  457. def _Main_BreakpointManager_Waiting_0_exec(self, parameters):
  458. result = parameters[0]
  459. self.big_step.outputEvent(Event("Breakpoint.AddResult", "user_output", [result]))
  460. def _Main_BreakpointManager_Waiting_1_exec(self, parameters):
  461. result = parameters[0]
  462. self.big_step.outputEvent(Event("Breakpoint.DelResult", "user_output", [result]))
  463. def _Main_BreakpointManager_Waiting_2_exec(self, parameters):
  464. result = parameters[0]
  465. self.big_step.outputEvent(Event("Breakpoint.ToggleResult", "user_output", [result]))
  466. def _Main_BreakpointManager_Waiting_3_exec(self, parameters):
  467. result = parameters[0]
  468. self.big_step.outputEvent(Event("Breakpoint.ListResult", "user_output", [result]))
  469. def initializeStatechart(self):
  470. # enter default state
  471. self.default_targets = self.states["/Main"].getEffectiveTargetStates()
  472. RuntimeClassBase.initializeStatechart(self)
  473. class CBDSimulator_Simulation(RuntimeClassBase):
  474. def __init__(self, controller, options, model):
  475. RuntimeClassBase.__init__(self, controller)
  476. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  477. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  478. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  479. self.semantics.priority = StatechartSemantics.SourceParent
  480. self.semantics.concurrency = StatechartSemantics.Single
  481. # build Statechart structure
  482. self.build_statechart_structure()
  483. # call user defined constructor
  484. CBDSimulator_Simulation.user_defined_constructor(self, options, model)
  485. def user_defined_constructor(self, options, model):
  486. self.options = options
  487. self.delta = self.options.getDeltaT() * 1000.0 # in miliseconds for real-time simulation
  488. self.model = model
  489. self.initialized = False
  490. def user_defined_destructor(self):
  491. pass
  492. # user defined method
  493. def initialize(self):
  494. self.iteration = 0
  495. self.clock = 0
  496. self.time_next = self.delta
  497. self.cbd_controller = CBDController(self.model, self.delta / 1000.0)
  498. self.cbd_controller.initSimulation()
  499. self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
  500. self.initialized = True
  501. # user defined method
  502. def endCondition(self):
  503. return self.initialized and self.iteration >= self.options.getMaxIterations()
  504. # user defined method
  505. def finalize(self):
  506. from bokeh.plotting import figure, output_file, show
  507. times = []
  508. values = []
  509. for timeValuePair in self.model.getSignal("neg"):
  510. times.append(timeValuePair.time)
  511. values.append(timeValuePair.value)
  512. output_file("./plot.html", title="Plot")
  513. p = figure(title="Something vs Otherthing", x_axis_label="Time", y_axis_label="Values")
  514. p.line(times, values, legend="Something", line_width=1, line_color="red")
  515. show(p)
  516. print 'Simulation finalized.'
  517. # user defined method
  518. def initializeDebugger(self):
  519. self.breakpoints = []
  520. self.triggered_bp = None
  521. # user defined method
  522. def waitTime(self):
  523. # First, we convert from wall-clock time to simulated time.
  524. # 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).
  525. simulated_diff = (accurate_time.time() - self.realtime_start_time) * self.realtime_scale
  526. # time_next and simulated_diff are both in simulated time: so now scale back to wall-clock time by dividing.
  527. # This function returns an amount of miliseconds.
  528. return ((self.time_next - simulated_diff) / self.realtime_scale)
  529. # user defined method
  530. def syncSimulatedTime(self):
  531. diff = accurate_time.time() - self.realtime_start_time
  532. self.clock = diff * self.realtime_scale
  533. # user defined method
  534. def addBreakpoint(self, name, function, enabled = None, disable_on_trigger = None):
  535. if enabled == None: enabled = true
  536. if disable_on_trigger == None: disable_on_trigger = true
  537. if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
  538. return -1
  539. self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
  540. return 0
  541. # user defined method
  542. def delBreakpoint(self, name):
  543. if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
  544. return -1
  545. self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
  546. return 0
  547. # user defined method
  548. def toggleBreakpoint(self, name):
  549. if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
  550. return -1
  551. for bp in self.breakpoints:
  552. if bp.name == name:
  553. bp.enabled = enabled
  554. break
  555. return 0
  556. # user defined method
  557. def breakpointTriggers(self, is_realtime_simulation):
  558. self.triggered_bp = None
  559. for bp in self.breakpoints:
  560. if not bp.enabled:
  561. continue
  562. # include the function in the scope...
  563. exec(bp.function)
  564. # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
  565. # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
  566. # 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')
  567. # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
  568. if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.state}):
  569. # triggered!
  570. self.triggered_bp = bp.name
  571. if bp.disable_on_trigger:
  572. bp.enabled = False
  573. return True
  574. else:
  575. # not triggered, so continue
  576. continue
  577. return False
  578. # user defined method
  579. def godEvent(self, block_name, new_val):
  580. if not self.initialized:
  581. return -1
  582. if block_name not in self.state:
  583. return -1
  584. for b in self.model.getBlocks():
  585. if b.getBlockName() == block_name:
  586. b.setSignal(new_val)
  587. self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
  588. return 0
  589. # builds Statechart structure
  590. def build_statechart_structure(self):
  591. # state <root>
  592. self.states[""] = State(0, "", self)
  593. # state /Main
  594. self.states["/Main"] = ParallelState(1, "/Main", self)
  595. # state /Main/ModeSelector
  596. self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
  597. # state /Main/ModeSelector/Paused
  598. self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
  599. # state /Main/ModeSelector/Running
  600. self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
  601. # state /Main/ModeSelector/Running/Continuous
  602. self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
  603. # state /Main/ModeSelector/Running/Realtime
  604. self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
  605. # state /Main/ModeSelector/Running/BigStep
  606. self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
  607. # state /Main/ModeSelector/Running/SmallStep
  608. self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
  609. # state /Main/ChildState
  610. self.states["/Main/ChildState"] = State(9, "/Main/ChildState", self)
  611. # state /Main/ChildState/Uninitialized
  612. self.states["/Main/ChildState/Uninitialized"] = State(10, "/Main/ChildState/Uninitialized", self)
  613. # state /Main/ChildState/Initialized
  614. self.states["/Main/ChildState/Initialized"] = State(11, "/Main/ChildState/Initialized", self)
  615. # state /Main/Initializer
  616. self.states["/Main/Initializer"] = State(12, "/Main/Initializer", self)
  617. # state /Main/Initializer/Waiting
  618. self.states["/Main/Initializer/Waiting"] = State(13, "/Main/Initializer/Waiting", self)
  619. # state /Main/Initializer/CreatingChildSimulator
  620. self.states["/Main/Initializer/CreatingChildSimulator"] = State(14, "/Main/Initializer/CreatingChildSimulator", self)
  621. # state /Main/Initializer/StartingChildSimulator
  622. self.states["/Main/Initializer/StartingChildSimulator"] = State(15, "/Main/Initializer/StartingChildSimulator", self)
  623. # state /Main/Initializer/Running
  624. self.states["/Main/Initializer/Running"] = State(16, "/Main/Initializer/Running", self)
  625. # state /Main/Initializer/SettleBeforeWaiting
  626. self.states["/Main/Initializer/SettleBeforeWaiting"] = State(17, "/Main/Initializer/SettleBeforeWaiting", self)
  627. self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
  628. self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
  629. # state /Main/SimulationFlow
  630. self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
  631. # state /Main/SimulationFlow/Started
  632. self.states["/Main/SimulationFlow/Started"] = State(19, "/Main/SimulationFlow/Started", self)
  633. # state /Main/SimulationFlow/Initialized
  634. self.states["/Main/SimulationFlow/Initialized"] = State(20, "/Main/SimulationFlow/Initialized", self)
  635. # state /Main/SimulationFlow/InitializeDebugger
  636. self.states["/Main/SimulationFlow/InitializeDebugger"] = State(21, "/Main/SimulationFlow/InitializeDebugger", self)
  637. # state /Main/SimulationFlow/Waiting
  638. self.states["/Main/SimulationFlow/Waiting"] = State(22, "/Main/SimulationFlow/Waiting", self)
  639. # state /Main/SimulationFlow/SettleBeforeCheckTermination
  640. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(23, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
  641. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
  642. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
  643. # state /Main/SimulationFlow/CheckTermination
  644. self.states["/Main/SimulationFlow/CheckTermination"] = State(24, "/Main/SimulationFlow/CheckTermination", self)
  645. # state /Main/SimulationFlow/WaitingRealtime
  646. self.states["/Main/SimulationFlow/WaitingRealtime"] = State(25, "/Main/SimulationFlow/WaitingRealtime", self)
  647. self.states["/Main/SimulationFlow/WaitingRealtime"].setEnter(self._Main_SimulationFlow_WaitingRealtime_enter)
  648. self.states["/Main/SimulationFlow/WaitingRealtime"].setExit(self._Main_SimulationFlow_WaitingRealtime_exit)
  649. # state /Main/SimulationFlow/Executing
  650. self.states["/Main/SimulationFlow/Executing"] = State(26, "/Main/SimulationFlow/Executing", self)
  651. # state /Main/SimulationFlow/Stopped
  652. self.states["/Main/SimulationFlow/Stopped"] = State(27, "/Main/SimulationFlow/Stopped", self)
  653. # state /Main/GodEventManager
  654. self.states["/Main/GodEventManager"] = State(28, "/Main/GodEventManager", self)
  655. # state /Main/GodEventManager/Listening
  656. self.states["/Main/GodEventManager/Listening"] = State(29, "/Main/GodEventManager/Listening", self)
  657. # state /Main/BreakpointManager
  658. self.states["/Main/BreakpointManager"] = State(30, "/Main/BreakpointManager", self)
  659. # state /Main/BreakpointManager/Listening
  660. self.states["/Main/BreakpointManager/Listening"] = State(31, "/Main/BreakpointManager/Listening", self)
  661. # state /Stopped
  662. self.states["/Stopped"] = State(32, "/Stopped", self)
  663. # add children
  664. self.states[""].addChild(self.states["/Main"])
  665. self.states[""].addChild(self.states["/Stopped"])
  666. self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
  667. self.states["/Main"].addChild(self.states["/Main/ChildState"])
  668. self.states["/Main"].addChild(self.states["/Main/Initializer"])
  669. self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
  670. self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
  671. self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
  672. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
  673. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
  674. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
  675. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
  676. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
  677. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
  678. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
  679. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
  680. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
  681. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
  682. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
  683. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
  684. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
  685. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
  686. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
  687. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
  688. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
  689. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
  690. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
  691. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/WaitingRealtime"])
  692. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
  693. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
  694. self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
  695. self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
  696. self.states[""].fixTree()
  697. self.states[""].default_state = self.states["/Main"]
  698. self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
  699. self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
  700. self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
  701. self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
  702. self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
  703. self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
  704. self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
  705. # transition /Main/ModeSelector/Paused
  706. _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
  707. _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
  708. _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
  709. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
  710. _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
  711. _Main_ModeSelector_Paused_1.setAction(self._Main_ModeSelector_Paused_1_exec)
  712. _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
  713. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
  714. _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
  715. _Main_ModeSelector_Paused_2.setTrigger(Event("Simulation.Execute", None))
  716. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
  717. _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
  718. _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
  719. _Main_ModeSelector_Paused_3.setTrigger(Event("Simulation.ExecuteRealtime", None))
  720. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
  721. _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
  722. _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
  723. _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
  724. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
  725. # transition /Main/ModeSelector/Running/Continuous
  726. _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Paused"]])
  727. _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("Simulation.Pause", None))
  728. self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
  729. # transition /Main/ModeSelector/Running/Realtime
  730. _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Paused"]])
  731. _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("Simulation.Pause", None))
  732. self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
  733. _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
  734. _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
  735. _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("BigStep.Finished", None))
  736. self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
  737. # transition /Main/ModeSelector/Running/BigStep
  738. _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
  739. _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
  740. _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
  741. self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
  742. # transition /Main/ModeSelector/Running/SmallStep
  743. _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
  744. _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
  745. _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
  746. self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
  747. # transition /Main/ChildState/Uninitialized
  748. _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
  749. _Main_ChildState_Uninitialized_0.setTrigger(Event("BigStep.Initialized", None))
  750. self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
  751. # transition /Main/ChildState/Initialized
  752. _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
  753. _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
  754. _Main_ChildState_Initialized_0.setTrigger(Event("BigStep.Finished", None))
  755. self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
  756. # transition /Main/Initializer/Waiting
  757. _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
  758. _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
  759. _Main_Initializer_Waiting_0.setTrigger(None)
  760. _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
  761. self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
  762. # transition /Main/Initializer/CreatingChildSimulator
  763. _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
  764. _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
  765. _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
  766. self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
  767. # transition /Main/Initializer/StartingChildSimulator
  768. _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
  769. _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("BigStep.Initialized", None))
  770. self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
  771. # transition /Main/Initializer/Running
  772. _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
  773. _Main_Initializer_Running_0.setTrigger(Event("BigStep.Finished", None))
  774. self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
  775. # transition /Main/Initializer/SettleBeforeWaiting
  776. _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
  777. _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
  778. self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
  779. # transition /Main/SimulationFlow/Started
  780. _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
  781. _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
  782. _Main_SimulationFlow_Started_0.setTrigger(None)
  783. self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
  784. # transition /Main/SimulationFlow/Initialized
  785. _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
  786. _Main_SimulationFlow_Initialized_0.setTrigger(None)
  787. self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
  788. # transition /Main/SimulationFlow/InitializeDebugger
  789. _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
  790. _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
  791. _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
  792. self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
  793. # transition /Main/SimulationFlow/Waiting
  794. _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  795. _Main_SimulationFlow_Waiting_0.setTrigger(None)
  796. _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
  797. self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
  798. # transition /Main/SimulationFlow/SettleBeforeCheckTermination
  799. _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  800. _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
  801. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
  802. _Main_SimulationFlow_SettleBeforeCheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  803. _Main_SimulationFlow_SettleBeforeCheckTermination_1.setAction(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_exec)
  804. _Main_SimulationFlow_SettleBeforeCheckTermination_1.setTrigger(None)
  805. _Main_SimulationFlow_SettleBeforeCheckTermination_1.setGuard(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_guard)
  806. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_1)
  807. # transition /Main/SimulationFlow/CheckTermination
  808. _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
  809. _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
  810. _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
  811. _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
  812. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
  813. _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
  814. _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
  815. _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
  816. _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
  817. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
  818. _Main_SimulationFlow_CheckTermination_2 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/WaitingRealtime"]])
  819. _Main_SimulationFlow_CheckTermination_2.setTrigger(None)
  820. _Main_SimulationFlow_CheckTermination_2.setGuard(self._Main_SimulationFlow_CheckTermination_2_guard)
  821. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_2)
  822. _Main_SimulationFlow_CheckTermination_3 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
  823. _Main_SimulationFlow_CheckTermination_3.setAction(self._Main_SimulationFlow_CheckTermination_3_exec)
  824. _Main_SimulationFlow_CheckTermination_3.setTrigger(None)
  825. _Main_SimulationFlow_CheckTermination_3.setGuard(self._Main_SimulationFlow_CheckTermination_3_guard)
  826. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_3)
  827. # transition /Main/SimulationFlow/WaitingRealtime
  828. _Main_SimulationFlow_WaitingRealtime_0 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  829. _Main_SimulationFlow_WaitingRealtime_0.setAction(self._Main_SimulationFlow_WaitingRealtime_0_exec)
  830. _Main_SimulationFlow_WaitingRealtime_0.setTrigger(Event("_2after"))
  831. _Main_SimulationFlow_WaitingRealtime_0.setGuard(self._Main_SimulationFlow_WaitingRealtime_0_guard)
  832. self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_0)
  833. _Main_SimulationFlow_WaitingRealtime_1 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  834. _Main_SimulationFlow_WaitingRealtime_1.setAction(self._Main_SimulationFlow_WaitingRealtime_1_exec)
  835. _Main_SimulationFlow_WaitingRealtime_1.setTrigger(None)
  836. _Main_SimulationFlow_WaitingRealtime_1.setGuard(self._Main_SimulationFlow_WaitingRealtime_1_guard)
  837. self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_1)
  838. _Main_SimulationFlow_WaitingRealtime_2 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/Executing"]])
  839. _Main_SimulationFlow_WaitingRealtime_2.setAction(self._Main_SimulationFlow_WaitingRealtime_2_exec)
  840. _Main_SimulationFlow_WaitingRealtime_2.setTrigger(None)
  841. _Main_SimulationFlow_WaitingRealtime_2.setGuard(self._Main_SimulationFlow_WaitingRealtime_2_guard)
  842. self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_2)
  843. # transition /Main/SimulationFlow/Executing
  844. _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
  845. _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
  846. _Main_SimulationFlow_Executing_0.setTrigger(Event("BigStep.Finished", None))
  847. self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
  848. # transition /Main/GodEventManager/Listening
  849. _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Listening"]])
  850. _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
  851. _Main_GodEventManager_Listening_0.setTrigger(Event("Simulation.GodEvent", None))
  852. _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
  853. self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
  854. # transition /Main/BreakpointManager/Listening
  855. _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  856. _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
  857. _Main_BreakpointManager_Listening_0.setTrigger(Event("Breakpoint.Add", None))
  858. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
  859. _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  860. _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
  861. _Main_BreakpointManager_Listening_1.setTrigger(Event("Breakpoint.Del", None))
  862. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
  863. _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  864. _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
  865. _Main_BreakpointManager_Listening_2.setTrigger(Event("Breakpoint.Toggle", None))
  866. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
  867. _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
  868. _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
  869. _Main_BreakpointManager_Listening_3.setTrigger(Event("Breakpoint.List", None))
  870. self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
  871. # transition /Main/ModeSelector/Running
  872. _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  873. _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
  874. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
  875. _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  876. _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
  877. _Main_ModeSelector_Running_1.setTrigger(None)
  878. _Main_ModeSelector_Running_1.setGuard(self._Main_ModeSelector_Running_1_guard)
  879. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
  880. def _Main_Initializer_SettleBeforeWaiting_enter(self):
  881. self.addTimer(0, self.sccd_yield())
  882. def _Main_Initializer_SettleBeforeWaiting_exit(self):
  883. self.removeTimer(0)
  884. def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
  885. self.addTimer(1, self.sccd_yield())
  886. def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
  887. self.removeTimer(1)
  888. def _Main_SimulationFlow_WaitingRealtime_enter(self):
  889. self.addTimer(2, self.sccd_yield())
  890. def _Main_SimulationFlow_WaitingRealtime_exit(self):
  891. self.removeTimer(2)
  892. def _Main_ModeSelector_Running_1_exec(self, parameters):
  893. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.Triggered", None, [self.triggered_bp, self.clock, self.state])]))
  894. def _Main_ModeSelector_Running_1_guard(self, parameters):
  895. return self.breakpointTriggers(self.inState(["/Main/ModeSelector/Running/Realtime"]))
  896. def _Main_ModeSelector_Paused_0_exec(self, parameters):
  897. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
  898. def _Main_ModeSelector_Paused_1_exec(self, parameters):
  899. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
  900. def _Main_ModeSelector_Paused_3_exec(self, parameters):
  901. realtime_scale = parameters[0]
  902. self.realtime_scale = float(realtime_scale)
  903. # If the simulation was paused, we need to reset the start time of the simulation.
  904. # The start time of the simulation is equal to the point in wall-clock time where simulated time is 0.
  905. # 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.
  906. # 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)
  907. self.realtime_start_time = accurate_time.time() - (self.clock / self.realtime_scale)
  908. def _Main_ModeSelector_Paused_4_exec(self, parameters):
  909. clock = parameters[0]
  910. iteration = parameters[1]
  911. time_next = parameters[2]
  912. state = parameters[3]
  913. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
  914. def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
  915. clock = parameters[0]
  916. iteration = parameters[1]
  917. time_next = parameters[2]
  918. state = parameters[3]
  919. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
  920. def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
  921. clock = parameters[0]
  922. iteration = parameters[1]
  923. time_next = parameters[2]
  924. state = parameters[3]
  925. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
  926. def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
  927. current_component_idx = parameters[0]
  928. state = parameters[1]
  929. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [current_component_idx, state])]))
  930. def _Main_ChildState_Initialized_0_exec(self, parameters):
  931. self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
  932. def _Main_Initializer_Waiting_0_exec(self, parameters):
  933. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_BigStep', self.cbd_controller, self.clock, self.iteration, self.time_next, self.delta, self.state]))
  934. def _Main_Initializer_Waiting_0_guard(self, parameters):
  935. return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
  936. def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
  937. self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
  938. def _Main_SimulationFlow_Started_0_exec(self, parameters):
  939. self.initialize()
  940. def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
  941. self.initializeDebugger()
  942. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Initialized", None, [])]))
  943. def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
  944. return self.inState(["/Main/ModeSelector/Running"])
  945. def _Main_SimulationFlow_SettleBeforeCheckTermination_1_exec(self, parameters):
  946. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
  947. def _Main_SimulationFlow_SettleBeforeCheckTermination_1_guard(self, parameters):
  948. return self.inState(["/Main/ModeSelector/Paused"])
  949. def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
  950. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
  951. def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
  952. return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/BigStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
  953. def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
  954. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
  955. def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
  956. return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
  957. def _Main_SimulationFlow_CheckTermination_2_guard(self, parameters):
  958. return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
  959. def _Main_SimulationFlow_CheckTermination_3_exec(self, parameters):
  960. # print 'simulation executed'
  961. self.finalize()
  962. self.raiseInternalEvent(Event("Simulation.Finished", None, []))
  963. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Finished", None, [self.clock, self.state])]))
  964. def _Main_SimulationFlow_CheckTermination_3_guard(self, parameters):
  965. return self.endCondition()
  966. def _Main_SimulationFlow_WaitingRealtime_0_exec(self, parameters):
  967. self.syncSimulatedTime()
  968. def _Main_SimulationFlow_WaitingRealtime_0_guard(self, parameters):
  969. return self.inState(["/Main/ModeSelector/Running"])
  970. def _Main_SimulationFlow_WaitingRealtime_1_exec(self, parameters):
  971. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
  972. def _Main_SimulationFlow_WaitingRealtime_1_guard(self, parameters):
  973. return self.inState(["/Main/ModeSelector/Paused"]) and (not ((self.waitTime() / 1000.0) <= self.sccd_yield()))
  974. def _Main_SimulationFlow_WaitingRealtime_2_exec(self, parameters):
  975. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
  976. def _Main_SimulationFlow_WaitingRealtime_2_guard(self, parameters):
  977. return self.waitTime() / 1000.0 <= self.sccd_yield()
  978. def _Main_SimulationFlow_Executing_0_exec(self, parameters):
  979. clock = parameters[0]
  980. iteration = parameters[1]
  981. time_next = parameters[2]
  982. state = parameters[3]
  983. self.clock = clock
  984. self.iteration = iteration
  985. self.time_next = time_next
  986. self.state = state
  987. def _Main_GodEventManager_Listening_0_exec(self, parameters):
  988. block_name = parameters[0]
  989. new_val = parameters[1]
  990. result = self.godEvent(block_name, new_val)
  991. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.GodEventResult", None, [result])]))
  992. def _Main_GodEventManager_Listening_0_guard(self, parameters):
  993. block_name = parameters[0]
  994. new_val = parameters[1]
  995. return self.inState(["/Main/ModeSelector/Paused"])
  996. def _Main_BreakpointManager_Listening_0_exec(self, parameters):
  997. name = parameters[0]
  998. function = parameters[1]
  999. enabled = parameters[2]
  1000. disable_on_trigger = parameters[3]
  1001. result = self.addBreakpoint(name, function, bool(enabled), bool(disable_on_trigger))
  1002. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.AddResult", None, [result])]))
  1003. def _Main_BreakpointManager_Listening_1_exec(self, parameters):
  1004. name = parameters[0]
  1005. result = self.delBreakpoint(name)
  1006. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.DelResult", None, [result])]))
  1007. def _Main_BreakpointManager_Listening_2_exec(self, parameters):
  1008. name = parameters[0]
  1009. result = self.toggleBreakpoint(name)
  1010. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ToggleResult", None, [result])]))
  1011. def _Main_BreakpointManager_Listening_3_exec(self, parameters):
  1012. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ListResult", None, [[bp.name for bp in self.breakpoints]])]))
  1013. def initializeStatechart(self):
  1014. # enter default state
  1015. self.default_targets = self.states["/Main"].getEffectiveTargetStates()
  1016. RuntimeClassBase.initializeStatechart(self)
  1017. class CBDSimulator_BigStep(RuntimeClassBase):
  1018. def __init__(self, controller, cbd_controller, clock, iteration, time_next, delta, state):
  1019. RuntimeClassBase.__init__(self, controller)
  1020. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  1021. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  1022. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  1023. self.semantics.priority = StatechartSemantics.SourceParent
  1024. self.semantics.concurrency = StatechartSemantics.Single
  1025. # build Statechart structure
  1026. self.build_statechart_structure()
  1027. # call user defined constructor
  1028. CBDSimulator_BigStep.user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state)
  1029. def user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state):
  1030. self.cbd_controller = cbd_controller
  1031. self.clock = clock
  1032. self.iteration = iteration
  1033. self.time_next = time_next
  1034. self.delta = delta
  1035. self.state = state
  1036. def user_defined_destructor(self):
  1037. pass
  1038. # user defined method
  1039. def initialize(self):
  1040. self.current_component_idx = 0
  1041. self.dependency_graph = self.cbd_controller.createDepGraph(self.iteration)
  1042. self.strong_component_list = self.cbd_controller.createStrongComponents(self.dependency_graph, self.iteration)
  1043. # user defined method
  1044. def initializeDebugger(self):
  1045. pass
  1046. # user defined method
  1047. def endCondition(self):
  1048. return self.current_component_idx >= len(self.strong_component_list)
  1049. # user defined method
  1050. def finalize(self):
  1051. self.advanceTime()
  1052. # user defined method
  1053. def advanceTime(self):
  1054. self.clock = self.time_next
  1055. self.iteration = self.iteration + 1
  1056. self.cbd_controller.advanceTimeStep()
  1057. self.time_next = self.clock + self.delta
  1058. # builds Statechart structure
  1059. def build_statechart_structure(self):
  1060. # state <root>
  1061. self.states[""] = State(0, "", self)
  1062. # state /Main
  1063. self.states["/Main"] = ParallelState(1, "/Main", self)
  1064. # state /Main/ModeSelector
  1065. self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
  1066. # state /Main/ModeSelector/Paused
  1067. self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
  1068. # state /Main/ModeSelector/Running
  1069. self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
  1070. # state /Main/ModeSelector/Running/Continuous
  1071. self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
  1072. # state /Main/ModeSelector/Running/SmallStep
  1073. self.states["/Main/ModeSelector/Running/SmallStep"] = State(6, "/Main/ModeSelector/Running/SmallStep", self)
  1074. # state /Main/ChildState
  1075. self.states["/Main/ChildState"] = State(7, "/Main/ChildState", self)
  1076. # state /Main/ChildState/Uninitialized
  1077. self.states["/Main/ChildState/Uninitialized"] = State(8, "/Main/ChildState/Uninitialized", self)
  1078. # state /Main/ChildState/Initialized
  1079. self.states["/Main/ChildState/Initialized"] = State(9, "/Main/ChildState/Initialized", self)
  1080. # state /Main/Initializer
  1081. self.states["/Main/Initializer"] = State(10, "/Main/Initializer", self)
  1082. # state /Main/Initializer/Waiting
  1083. self.states["/Main/Initializer/Waiting"] = State(11, "/Main/Initializer/Waiting", self)
  1084. # state /Main/Initializer/CreatingChildSimulator
  1085. self.states["/Main/Initializer/CreatingChildSimulator"] = State(12, "/Main/Initializer/CreatingChildSimulator", self)
  1086. # state /Main/Initializer/StartingChildSimulator
  1087. self.states["/Main/Initializer/StartingChildSimulator"] = State(13, "/Main/Initializer/StartingChildSimulator", self)
  1088. # state /Main/Initializer/Running
  1089. self.states["/Main/Initializer/Running"] = State(14, "/Main/Initializer/Running", self)
  1090. # state /Main/Initializer/SettleBeforeWaiting
  1091. self.states["/Main/Initializer/SettleBeforeWaiting"] = State(15, "/Main/Initializer/SettleBeforeWaiting", self)
  1092. self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
  1093. self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
  1094. # state /Main/SimulationFlow
  1095. self.states["/Main/SimulationFlow"] = State(16, "/Main/SimulationFlow", self)
  1096. # state /Main/SimulationFlow/Started
  1097. self.states["/Main/SimulationFlow/Started"] = State(17, "/Main/SimulationFlow/Started", self)
  1098. # state /Main/SimulationFlow/Initialized
  1099. self.states["/Main/SimulationFlow/Initialized"] = State(18, "/Main/SimulationFlow/Initialized", self)
  1100. # state /Main/SimulationFlow/InitializeDebugger
  1101. self.states["/Main/SimulationFlow/InitializeDebugger"] = State(19, "/Main/SimulationFlow/InitializeDebugger", self)
  1102. # state /Main/SimulationFlow/Waiting
  1103. self.states["/Main/SimulationFlow/Waiting"] = State(20, "/Main/SimulationFlow/Waiting", self)
  1104. # state /Main/SimulationFlow/SettleBeforeCheckTermination
  1105. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(21, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
  1106. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
  1107. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
  1108. # state /Main/SimulationFlow/CheckTermination
  1109. self.states["/Main/SimulationFlow/CheckTermination"] = State(22, "/Main/SimulationFlow/CheckTermination", self)
  1110. # state /Main/SimulationFlow/Executing
  1111. self.states["/Main/SimulationFlow/Executing"] = State(23, "/Main/SimulationFlow/Executing", self)
  1112. # state /Main/SimulationFlow/Stopped
  1113. self.states["/Main/SimulationFlow/Stopped"] = State(24, "/Main/SimulationFlow/Stopped", self)
  1114. # state /Stopped
  1115. self.states["/Stopped"] = State(25, "/Stopped", self)
  1116. # add children
  1117. self.states[""].addChild(self.states["/Main"])
  1118. self.states[""].addChild(self.states["/Stopped"])
  1119. self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
  1120. self.states["/Main"].addChild(self.states["/Main/ChildState"])
  1121. self.states["/Main"].addChild(self.states["/Main/Initializer"])
  1122. self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
  1123. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
  1124. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
  1125. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
  1126. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
  1127. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
  1128. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
  1129. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
  1130. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
  1131. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
  1132. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
  1133. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
  1134. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
  1135. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
  1136. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
  1137. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
  1138. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
  1139. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
  1140. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
  1141. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
  1142. self.states[""].fixTree()
  1143. self.states[""].default_state = self.states["/Main"]
  1144. self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
  1145. self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
  1146. self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
  1147. self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
  1148. self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
  1149. # transition /Main/ModeSelector/Paused
  1150. _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
  1151. _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
  1152. _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
  1153. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
  1154. _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
  1155. _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
  1156. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
  1157. # transition /Main/ModeSelector/Running/SmallStep
  1158. _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
  1159. _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
  1160. _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
  1161. self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
  1162. # transition /Main/ChildState/Uninitialized
  1163. _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
  1164. _Main_ChildState_Uninitialized_0.setTrigger(Event("SmallStep.Initialized", None))
  1165. self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
  1166. # transition /Main/ChildState/Initialized
  1167. _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
  1168. _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
  1169. _Main_ChildState_Initialized_0.setTrigger(Event("SmallStep.Finished", None))
  1170. self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
  1171. # transition /Main/Initializer/Waiting
  1172. _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
  1173. _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
  1174. _Main_Initializer_Waiting_0.setTrigger(None)
  1175. _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
  1176. self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
  1177. # transition /Main/Initializer/CreatingChildSimulator
  1178. _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
  1179. _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
  1180. _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
  1181. self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
  1182. # transition /Main/Initializer/StartingChildSimulator
  1183. _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
  1184. _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("SmallStep.Initialized", None))
  1185. self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
  1186. # transition /Main/Initializer/Running
  1187. _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
  1188. _Main_Initializer_Running_0.setTrigger(Event("SmallStep.Finished", None))
  1189. self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
  1190. # transition /Main/Initializer/SettleBeforeWaiting
  1191. _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
  1192. _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
  1193. self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
  1194. # transition /Main/SimulationFlow/Started
  1195. _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
  1196. _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
  1197. _Main_SimulationFlow_Started_0.setTrigger(None)
  1198. self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
  1199. # transition /Main/SimulationFlow/Initialized
  1200. _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
  1201. _Main_SimulationFlow_Initialized_0.setTrigger(None)
  1202. self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
  1203. # transition /Main/SimulationFlow/InitializeDebugger
  1204. _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
  1205. _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
  1206. _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
  1207. self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
  1208. # transition /Main/SimulationFlow/Waiting
  1209. _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  1210. _Main_SimulationFlow_Waiting_0.setTrigger(None)
  1211. _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
  1212. self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
  1213. # transition /Main/SimulationFlow/SettleBeforeCheckTermination
  1214. _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  1215. _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
  1216. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
  1217. # transition /Main/SimulationFlow/CheckTermination
  1218. _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
  1219. _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
  1220. _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
  1221. _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
  1222. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
  1223. _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
  1224. _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
  1225. _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
  1226. _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
  1227. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
  1228. # transition /Main/SimulationFlow/Executing
  1229. _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
  1230. _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
  1231. _Main_SimulationFlow_Executing_0.setTrigger(Event("SmallStep.Finished", None))
  1232. self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
  1233. # transition /Main/ModeSelector/Running
  1234. _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  1235. _Main_ModeSelector_Running_0.setTrigger(Event("BigStep.Finished", None))
  1236. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
  1237. def _Main_Initializer_SettleBeforeWaiting_enter(self):
  1238. self.addTimer(0, self.sccd_yield())
  1239. def _Main_Initializer_SettleBeforeWaiting_exit(self):
  1240. self.removeTimer(0)
  1241. def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
  1242. self.addTimer(1, self.sccd_yield())
  1243. def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
  1244. self.removeTimer(1)
  1245. def _Main_ModeSelector_Paused_0_exec(self, parameters):
  1246. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
  1247. def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
  1248. new_current_component_idx = parameters[0]
  1249. new_state = parameters[1]
  1250. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [new_current_component_idx, new_state])]))
  1251. def _Main_ChildState_Initialized_0_exec(self, parameters):
  1252. self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
  1253. def _Main_Initializer_Waiting_0_exec(self, parameters):
  1254. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_SmallStep', self.cbd_controller, self.strong_component_list, self.current_component_idx, self.dependency_graph, self.iteration, self.state]))
  1255. def _Main_Initializer_Waiting_0_guard(self, parameters):
  1256. return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
  1257. def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
  1258. self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
  1259. def _Main_SimulationFlow_Started_0_exec(self, parameters):
  1260. self.initialize()
  1261. def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
  1262. self.initializeDebugger()
  1263. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Initialized", None, [])]))
  1264. def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
  1265. return self.inState(["/Main/ModeSelector/Running"])
  1266. def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
  1267. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
  1268. def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
  1269. return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/SmallStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
  1270. def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
  1271. # print '>>> big step executed <<<'
  1272. self.finalize()
  1273. self.raiseInternalEvent(Event("BigStep.Finished", None, []))
  1274. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [self.clock, self.iteration, self.time_next, self.state])]))
  1275. def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
  1276. return self.endCondition()
  1277. def _Main_SimulationFlow_Executing_0_exec(self, parameters):
  1278. new_current_component_idx = parameters[0]
  1279. new_state = parameters[1]
  1280. self.current_component_idx = new_current_component_idx
  1281. self.state = new_state
  1282. def initializeStatechart(self):
  1283. # enter default state
  1284. self.default_targets = self.states["/Main"].getEffectiveTargetStates()
  1285. RuntimeClassBase.initializeStatechart(self)
  1286. class CBDSimulator_SmallStep(RuntimeClassBase):
  1287. def __init__(self, controller, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
  1288. RuntimeClassBase.__init__(self, controller)
  1289. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  1290. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  1291. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  1292. self.semantics.priority = StatechartSemantics.SourceParent
  1293. self.semantics.concurrency = StatechartSemantics.Single
  1294. # build Statechart structure
  1295. self.build_statechart_structure()
  1296. # call user defined constructor
  1297. CBDSimulator_SmallStep.user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state)
  1298. def user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
  1299. self.cbd_controller = cbd_controller
  1300. self.strong_component_list = strong_component_list
  1301. self.current_component_idx = current_component_idx
  1302. self.dependency_graph = dependency_graph
  1303. self.iteration = iteration
  1304. self.state = state
  1305. def user_defined_destructor(self):
  1306. pass
  1307. # user defined method
  1308. def initialize(self):
  1309. self.small_step_executed = False
  1310. # user defined method
  1311. def initializeDebugger(self):
  1312. pass
  1313. # user defined method
  1314. def endCondition(self):
  1315. return self.small_step_executed
  1316. # user defined method
  1317. def finalize(self):
  1318. self.current_component_idx += 1
  1319. # builds Statechart structure
  1320. def build_statechart_structure(self):
  1321. # state <root>
  1322. self.states[""] = State(0, "", self)
  1323. # state /Main
  1324. self.states["/Main"] = ParallelState(1, "/Main", self)
  1325. # state /Main/ModeSelector
  1326. self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
  1327. # state /Main/ModeSelector/Paused
  1328. self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
  1329. # state /Main/ModeSelector/Running
  1330. self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
  1331. # state /Main/ModeSelector/Running/Continuous
  1332. self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
  1333. # state /Main/ChildState
  1334. self.states["/Main/ChildState"] = State(6, "/Main/ChildState", self)
  1335. # state /Main/ChildState/Uninitialized
  1336. self.states["/Main/ChildState/Uninitialized"] = State(7, "/Main/ChildState/Uninitialized", self)
  1337. # state /Main/ChildState/Initialized
  1338. self.states["/Main/ChildState/Initialized"] = State(8, "/Main/ChildState/Initialized", self)
  1339. # state /Main/Initializer
  1340. self.states["/Main/Initializer"] = State(9, "/Main/Initializer", self)
  1341. # state /Main/Initializer/Waiting
  1342. self.states["/Main/Initializer/Waiting"] = State(10, "/Main/Initializer/Waiting", self)
  1343. # state /Main/Initializer/CreatingChildSimulator
  1344. self.states["/Main/Initializer/CreatingChildSimulator"] = State(11, "/Main/Initializer/CreatingChildSimulator", self)
  1345. # state /Main/Initializer/StartingChildSimulator
  1346. self.states["/Main/Initializer/StartingChildSimulator"] = State(12, "/Main/Initializer/StartingChildSimulator", self)
  1347. # state /Main/Initializer/Running
  1348. self.states["/Main/Initializer/Running"] = State(13, "/Main/Initializer/Running", self)
  1349. # state /Main/Initializer/SettleBeforeWaiting
  1350. self.states["/Main/Initializer/SettleBeforeWaiting"] = State(14, "/Main/Initializer/SettleBeforeWaiting", self)
  1351. self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
  1352. self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
  1353. # state /Main/SimulationFlow
  1354. self.states["/Main/SimulationFlow"] = State(15, "/Main/SimulationFlow", self)
  1355. # state /Main/SimulationFlow/Started
  1356. self.states["/Main/SimulationFlow/Started"] = State(16, "/Main/SimulationFlow/Started", self)
  1357. # state /Main/SimulationFlow/Initialized
  1358. self.states["/Main/SimulationFlow/Initialized"] = State(17, "/Main/SimulationFlow/Initialized", self)
  1359. # state /Main/SimulationFlow/InitializeDebugger
  1360. self.states["/Main/SimulationFlow/InitializeDebugger"] = State(18, "/Main/SimulationFlow/InitializeDebugger", self)
  1361. # state /Main/SimulationFlow/Waiting
  1362. self.states["/Main/SimulationFlow/Waiting"] = State(19, "/Main/SimulationFlow/Waiting", self)
  1363. # state /Main/SimulationFlow/SettleBeforeCheckTermination
  1364. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(20, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
  1365. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
  1366. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
  1367. # state /Main/SimulationFlow/CheckTermination
  1368. self.states["/Main/SimulationFlow/CheckTermination"] = State(21, "/Main/SimulationFlow/CheckTermination", self)
  1369. # state /Main/SimulationFlow/Executing
  1370. self.states["/Main/SimulationFlow/Executing"] = State(22, "/Main/SimulationFlow/Executing", self)
  1371. # state /Main/SimulationFlow/Stopped
  1372. self.states["/Main/SimulationFlow/Stopped"] = State(23, "/Main/SimulationFlow/Stopped", self)
  1373. # state /Stopped
  1374. self.states["/Stopped"] = State(24, "/Stopped", self)
  1375. # add children
  1376. self.states[""].addChild(self.states["/Main"])
  1377. self.states[""].addChild(self.states["/Stopped"])
  1378. self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
  1379. self.states["/Main"].addChild(self.states["/Main/ChildState"])
  1380. self.states["/Main"].addChild(self.states["/Main/Initializer"])
  1381. self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
  1382. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
  1383. self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
  1384. self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
  1385. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
  1386. self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
  1387. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
  1388. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
  1389. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
  1390. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
  1391. self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
  1392. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
  1393. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
  1394. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
  1395. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
  1396. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
  1397. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
  1398. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
  1399. self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
  1400. self.states[""].fixTree()
  1401. self.states[""].default_state = self.states["/Main"]
  1402. self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
  1403. self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
  1404. self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
  1405. self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
  1406. self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
  1407. # transition /Main/ModeSelector/Paused
  1408. _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
  1409. _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
  1410. self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
  1411. # transition /Main/ChildState/Uninitialized
  1412. _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
  1413. _Main_ChildState_Uninitialized_0.setTrigger(Event("Block.Initialized", None))
  1414. self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
  1415. # transition /Main/ChildState/Initialized
  1416. _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
  1417. _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
  1418. _Main_ChildState_Initialized_0.setTrigger(Event("Block.Finished", None))
  1419. self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
  1420. # transition /Main/Initializer/Waiting
  1421. _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
  1422. _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
  1423. _Main_Initializer_Waiting_0.setTrigger(None)
  1424. _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
  1425. self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
  1426. # transition /Main/Initializer/CreatingChildSimulator
  1427. _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
  1428. _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
  1429. _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
  1430. self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
  1431. # transition /Main/Initializer/StartingChildSimulator
  1432. _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
  1433. _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Block.Initialized", None))
  1434. self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
  1435. # transition /Main/Initializer/Running
  1436. _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
  1437. _Main_Initializer_Running_0.setTrigger(Event("Block.Finished", None))
  1438. self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
  1439. # transition /Main/Initializer/SettleBeforeWaiting
  1440. _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
  1441. _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
  1442. self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_0)
  1443. # transition /Main/SimulationFlow/Started
  1444. _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
  1445. _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
  1446. _Main_SimulationFlow_Started_0.setTrigger(None)
  1447. self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
  1448. # transition /Main/SimulationFlow/Initialized
  1449. _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
  1450. _Main_SimulationFlow_Initialized_0.setTrigger(None)
  1451. self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
  1452. # transition /Main/SimulationFlow/InitializeDebugger
  1453. _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/Waiting"]])
  1454. _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
  1455. _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
  1456. self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
  1457. # transition /Main/SimulationFlow/Waiting
  1458. _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  1459. _Main_SimulationFlow_Waiting_0.setTrigger(None)
  1460. _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
  1461. self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
  1462. # transition /Main/SimulationFlow/SettleBeforeCheckTermination
  1463. _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
  1464. _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
  1465. self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
  1466. # transition /Main/SimulationFlow/CheckTermination
  1467. _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
  1468. _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
  1469. _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
  1470. _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
  1471. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
  1472. _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
  1473. _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
  1474. _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
  1475. _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
  1476. self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
  1477. # transition /Main/SimulationFlow/Executing
  1478. _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
  1479. _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
  1480. _Main_SimulationFlow_Executing_0.setTrigger(Event("Block.Finished", None))
  1481. self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
  1482. # transition /Main/ModeSelector/Running
  1483. _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
  1484. _Main_ModeSelector_Running_0.setTrigger(Event("SmallStep.Finished", None))
  1485. self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
  1486. def _Main_Initializer_SettleBeforeWaiting_enter(self):
  1487. self.addTimer(0, self.sccd_yield())
  1488. def _Main_Initializer_SettleBeforeWaiting_exit(self):
  1489. self.removeTimer(0)
  1490. def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
  1491. self.addTimer(1, self.sccd_yield())
  1492. def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
  1493. self.removeTimer(1)
  1494. def _Main_ChildState_Initialized_0_exec(self, parameters):
  1495. self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
  1496. def _Main_Initializer_Waiting_0_exec(self, parameters):
  1497. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Block', self.cbd_controller, self.strong_component_list[self.current_component_idx], self.cbd_controller.componentIsCycle(self.strong_component_list[self.current_component_idx], self.dependency_graph), self.iteration]))
  1498. def _Main_Initializer_Waiting_0_guard(self, parameters):
  1499. return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
  1500. def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
  1501. self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
  1502. def _Main_SimulationFlow_Started_0_exec(self, parameters):
  1503. self.initialize()
  1504. def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
  1505. self.initializeDebugger()
  1506. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Initialized", None, [])]))
  1507. def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
  1508. return self.inState(["/Main/ModeSelector/Running"])
  1509. def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
  1510. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Block.Execute", None, [])]))
  1511. def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
  1512. return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
  1513. def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
  1514. # print '>>> small step executed <<<'
  1515. self.finalize()
  1516. self.raiseInternalEvent(Event("SmallStep.Finished", None, []))
  1517. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [self.current_component_idx, self.state])]))
  1518. def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
  1519. return self.endCondition()
  1520. def _Main_SimulationFlow_Executing_0_exec(self, parameters):
  1521. new_state = parameters[0]
  1522. self.small_step_executed = True
  1523. self.state = new_state
  1524. def initializeStatechart(self):
  1525. # enter default state
  1526. self.default_targets = self.states["/Main"].getEffectiveTargetStates()
  1527. RuntimeClassBase.initializeStatechart(self)
  1528. class CBDSimulator_Block(RuntimeClassBase):
  1529. def __init__(self, controller, cbd_controller, block_to_compute, is_cycle, iteration):
  1530. RuntimeClassBase.__init__(self, controller)
  1531. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  1532. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  1533. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  1534. self.semantics.priority = StatechartSemantics.SourceParent
  1535. self.semantics.concurrency = StatechartSemantics.Single
  1536. # build Statechart structure
  1537. self.build_statechart_structure()
  1538. # call user defined constructor
  1539. CBDSimulator_Block.user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration)
  1540. def user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration):
  1541. self.cbd_controller = cbd_controller
  1542. self.block_to_compute = block_to_compute
  1543. self.is_cycle = is_cycle
  1544. self.iteration = iteration
  1545. def user_defined_destructor(self):
  1546. pass
  1547. # user defined method
  1548. def computeBlock(self):
  1549. if self.is_cycle:
  1550. self.cbd_controller.computeNextAlgebraicLoop(self.block_to_compute, self.iteration)
  1551. else:
  1552. self.cbd_controller.computeNextBlock(self.block_to_compute, self.iteration)
  1553. # builds Statechart structure
  1554. def build_statechart_structure(self):
  1555. # state <root>
  1556. self.states[""] = State(0, "", self)
  1557. # state /Started
  1558. self.states["/Started"] = State(1, "/Started", self)
  1559. # state /Waiting
  1560. self.states["/Waiting"] = State(2, "/Waiting", self)
  1561. # state /Stopped
  1562. self.states["/Stopped"] = State(3, "/Stopped", self)
  1563. # add children
  1564. self.states[""].addChild(self.states["/Started"])
  1565. self.states[""].addChild(self.states["/Waiting"])
  1566. self.states[""].addChild(self.states["/Stopped"])
  1567. self.states[""].fixTree()
  1568. self.states[""].default_state = self.states["/Started"]
  1569. # transition /Started
  1570. _Started_0 = Transition(self, self.states["/Started"], [self.states["/Waiting"]])
  1571. _Started_0.setAction(self._Started_0_exec)
  1572. _Started_0.setTrigger(None)
  1573. self.states["/Started"].addTransition(_Started_0)
  1574. # transition /Waiting
  1575. _Waiting_0 = Transition(self, self.states["/Waiting"], [self.states["/Stopped"]])
  1576. _Waiting_0.setAction(self._Waiting_0_exec)
  1577. _Waiting_0.setTrigger(Event("Block.Execute", None))
  1578. self.states["/Waiting"].addTransition(_Waiting_0)
  1579. def _Started_0_exec(self, parameters):
  1580. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Initialized", None, [])]))
  1581. def _Waiting_0_exec(self, parameters):
  1582. self.computeBlock()
  1583. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Finished", None, [{b.getBlockName(): b.getSignal() for b in self.cbd_controller.model.getBlocks()}])]))
  1584. def initializeStatechart(self):
  1585. # enter default state
  1586. self.default_targets = self.states["/Started"].getEffectiveTargetStates()
  1587. RuntimeClassBase.initializeStatechart(self)
  1588. class ObjectManager(ObjectManagerBase):
  1589. def __init__(self, controller):
  1590. ObjectManagerBase.__init__(self, controller)
  1591. def instantiate(self, class_name, construct_params):
  1592. if class_name == "CBDSimulator_Coordinator":
  1593. instance = CBDSimulator_Coordinator(self.controller, construct_params[0], construct_params[1])
  1594. instance.associations = {}
  1595. instance.associations["child_simulator"] = Association("CBDSimulator_Simulation", 0, 1)
  1596. elif class_name == "CBDSimulator_Simulation":
  1597. instance = CBDSimulator_Simulation(self.controller, construct_params[0], construct_params[1])
  1598. instance.associations = {}
  1599. instance.associations["parent"] = Association("CBDSimulator_Coordinator", 1, 1)
  1600. instance.associations["child_simulator"] = Association("CBDSimulator_BigStep", 0, 1)
  1601. elif class_name == "CBDSimulator_BigStep":
  1602. instance = CBDSimulator_BigStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
  1603. instance.associations = {}
  1604. instance.associations["parent"] = Association("CBDSimulator_Simulation", 1, 1)
  1605. instance.associations["child_simulator"] = Association("CBDSimulator_SmallStep", 0, 1)
  1606. elif class_name == "CBDSimulator_SmallStep":
  1607. instance = CBDSimulator_SmallStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
  1608. instance.associations = {}
  1609. instance.associations["parent"] = Association("CBDSimulator_BigStep", 1, 1)
  1610. instance.associations["child_simulator"] = Association("CBDSimulator_Block", 0, 1)
  1611. elif class_name == "CBDSimulator_Block":
  1612. instance = CBDSimulator_Block(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3])
  1613. instance.associations = {}
  1614. instance.associations["parent"] = Association("CBDSimulator_SmallStep", 1, 1)
  1615. else:
  1616. raise Exception("Cannot instantiate class " + class_name)
  1617. return instance
  1618. class Controller(ThreadsControllerBase):
  1619. def __init__(self, options, model, keep_running = None, behind_schedule_callback = None):
  1620. if keep_running == None: keep_running = True
  1621. if behind_schedule_callback == None: behind_schedule_callback = None
  1622. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  1623. self.addInputPort("user_input")
  1624. self.addInputPort("user_output")
  1625. self.object_manager.createInstance("CBDSimulator_Coordinator", [options, model])