123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- """
- Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
- Model author: Sam Pieters
- Model name: Multiple Output Test
- Model description:
- Test 3: Check if the model outputs multiple events with an interval on the right time.
- """
- from sccd.runtime.statecharts_core import *
- # package "Multiple Output Test"
- class MainApp(RuntimeClassBase):
- def __init__(self, controller):
- RuntimeClassBase.__init__(self, controller)
-
-
- self.semantics.big_step_maximality = StatechartSemantics.TakeMany
- self.semantics.internal_event_lifeline = StatechartSemantics.Queue
- self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
- self.semantics.priority = StatechartSemantics.SourceParent
- self.semantics.concurrency = StatechartSemantics.Single
-
- # build Statechart structure
- self.build_statechart_structure()
-
- # call user defined constructor
- MainApp.user_defined_constructor(self)
-
- def user_defined_constructor(self):
- self.amount = 1
-
- def user_defined_destructor(self):
- pass
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /state1
- self.states["/state1"] = State(1, "/state1", self)
- self.states["/state1"].setEnter(self._state1_enter)
- self.states["/state1"].setExit(self._state1_exit)
-
- # state /state2
- self.states["/state2"] = State(2, "/state2", self)
- self.states["/state2"].setEnter(self._state2_enter)
-
- # state /end
- self.states["/end"] = State(3, "/end", self)
-
- # add children
- self.states[""].addChild(self.states["/state1"])
- self.states[""].addChild(self.states["/state2"])
- self.states[""].addChild(self.states["/end"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/state1"]
-
- # transition /state1
- _state1_0 = Transition(self, self.states["/state1"], [self.states["/state2"]])
- _state1_0.setTrigger(Event("_0after"))
- self.states["/state1"].addTransition(_state1_0)
-
- # transition /state2
- _state2_0 = Transition(self, self.states["/state2"], [self.states["/state1"]])
- _state2_0.setAction(self._state2_0_exec)
- _state2_0.setTrigger(None)
- _state2_0.setGuard(self._state2_0_guard)
- self.states["/state2"].addTransition(_state2_0)
- _state2_1 = Transition(self, self.states["/state2"], [self.states["/end"]])
- _state2_1.setTrigger(None)
- _state2_1.setGuard(self._state2_1_guard)
- self.states["/state2"].addTransition(_state2_1)
-
- def _state1_enter(self):
- self.addTimer(0, 1)
-
- def _state1_exit(self):
- self.removeTimer(0)
-
- def _state2_enter(self):
- self.big_step.outputEvent(Event("test_event", self.getOutPortName("ui"), [str(self.amount), str('%.2f' % (self.getSimulatedTime() / 1000.0))]))
-
- def _state2_0_exec(self, parameters):
- self.amount += 1
-
- def _state2_0_guard(self, parameters):
- return self.amount != 5
-
- def _state2_1_guard(self, parameters):
- return self.amount == 5
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/state1"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class ObjectManager(ObjectManagerBase):
- def __init__(self, controller):
- ObjectManagerBase.__init__(self, controller)
-
- def instantiate(self, class_name, construct_params):
- if class_name == "MainApp":
- instance = MainApp(self.controller)
- instance.associations = {}
- else:
- raise Exception("Cannot instantiate class " + class_name)
- return instance
- class Controller(ThreadsControllerBase):
- def __init__(self, keep_running = None, behind_schedule_callback = None):
- if keep_running == None: keep_running = True
- if behind_schedule_callback == None: behind_schedule_callback = None
- ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
- self.addInputPort("ui")
- self.addOutputPort("ui")
- self.object_manager.createInstance("MainApp", [])
|