|
@@ -1,24 +1,24 @@
|
|
|
"""
|
|
"""
|
|
|
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) and Sam Pieters (DEVS)
|
|
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) and Sam Pieters (DEVS)
|
|
|
|
|
|
|
|
-Model author: Raphael Mannadiar
|
|
|
|
|
-Model name: Traffic_Light_Python_Version
|
|
|
|
|
-
|
|
|
|
|
|
|
+Model author: Sam Pieters
|
|
|
|
|
+Model name: TrafficLight
|
|
|
|
|
+Model description:
|
|
|
|
|
+Tkinter frame with Traffic light in a single statechart.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
from sccd.runtime.DEVS_statecharts_core import *
|
|
from sccd.runtime.DEVS_statecharts_core import *
|
|
|
-from pypdevs.DEVS import *
|
|
|
|
|
-from pypdevs.infinity import *
|
|
|
|
|
-from pypdevs.simulator import *
|
|
|
|
|
-from sccd.runtime.libs.ui import ui
|
|
|
|
|
|
|
+from sccd.runtime.libs import ui_v2 as ui
|
|
|
|
|
+CANVAS_DIMS = (100, 350)
|
|
|
|
|
+CANVAS_WIDTH = 100
|
|
|
|
|
+CANVAS_HEIGHT = 350
|
|
|
|
|
|
|
|
-# package "Traffic_Light_Python_Version"
|
|
|
|
|
|
|
+# package "TrafficLight"
|
|
|
|
|
|
|
|
class MainAppInstance(RuntimeClassBase):
|
|
class MainAppInstance(RuntimeClassBase):
|
|
|
def __init__(self, atomdevs):
|
|
def __init__(self, atomdevs):
|
|
|
RuntimeClassBase.__init__(self, atomdevs)
|
|
RuntimeClassBase.__init__(self, atomdevs)
|
|
|
self.associations = {}
|
|
self.associations = {}
|
|
|
- self.associations["trafficlight"] = Association("TrafficLight", 0, -1)
|
|
|
|
|
|
|
|
|
|
self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
@@ -29,15 +29,25 @@ class MainAppInstance(RuntimeClassBase):
|
|
|
# build Statechart structure
|
|
# build Statechart structure
|
|
|
self.build_statechart_structure()
|
|
self.build_statechart_structure()
|
|
|
|
|
|
|
|
|
|
+ # user defined attributes
|
|
|
|
|
+ self.window_id = None
|
|
|
|
|
+ self.canvas_id = None
|
|
|
|
|
+ self.green_id = None
|
|
|
|
|
+ self.yellow_id = None
|
|
|
|
|
+ self.red_id = None
|
|
|
|
|
+ self.police_button_id = None
|
|
|
|
|
+
|
|
|
# call user defined constructor
|
|
# call user defined constructor
|
|
|
MainAppInstance.user_defined_constructor(self)
|
|
MainAppInstance.user_defined_constructor(self)
|
|
|
|
|
+ port_name = Ports.addInputPort("<narrow_cast>", self)
|
|
|
|
|
+ atomdevs.addInPort(port_name)
|
|
|
|
|
+ port_name = Ports.addInputPort("field_ui", self)
|
|
|
|
|
+ atomdevs.addInPort(port_name)
|
|
|
|
|
+ atomdevs.port_mappings[port_name] = atomdevs.next_instance
|
|
|
|
|
+ self.inports["field_ui"] = port_name
|
|
|
|
|
|
|
|
def user_defined_constructor(self):
|
|
def user_defined_constructor(self):
|
|
|
- self.canvas = ui.append_canvas(ui.window,100,310,{'background':'#eee'});
|
|
|
|
|
- police_button = ui.append_button(ui.window, 'Police interrupt');
|
|
|
|
|
- quit_button = ui.append_button(ui.window, 'Quit');
|
|
|
|
|
- ui.bind_event(police_button.element, ui.EVENTS.MOUSE_CLICK, self.controller, 'police_interrupt_clicked');
|
|
|
|
|
- ui.bind_event(quit_button.element, ui.EVENTS.MOUSE_CLICK, self.controller, 'quit_clicked');
|
|
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
def user_defined_destructor(self):
|
|
def user_defined_destructor(self):
|
|
|
pass
|
|
pass
|
|
@@ -49,265 +59,146 @@ class MainAppInstance(RuntimeClassBase):
|
|
|
# state <root>
|
|
# state <root>
|
|
|
self.states[""] = State(0, "", self)
|
|
self.states[""] = State(0, "", self)
|
|
|
|
|
|
|
|
- # state /initializing
|
|
|
|
|
- self.states["/initializing"] = State(1, "/initializing", self)
|
|
|
|
|
|
|
+ # state /creating_window
|
|
|
|
|
+ self.states["/creating_window"] = State(1, "/creating_window", self)
|
|
|
|
|
+ self.states["/creating_window"].setEnter(self._creating_window_enter)
|
|
|
|
|
|
|
|
- # state /creating
|
|
|
|
|
- self.states["/creating"] = State(2, "/creating", self)
|
|
|
|
|
|
|
+ # state /creating_canvas
|
|
|
|
|
+ self.states["/creating_canvas"] = State(2, "/creating_canvas", self)
|
|
|
|
|
+ self.states["/creating_canvas"].setEnter(self._creating_canvas_enter)
|
|
|
|
|
|
|
|
- # state /initialized
|
|
|
|
|
- self.states["/initialized"] = State(3, "/initialized", self)
|
|
|
|
|
|
|
+ # state /creating_trafficlight
|
|
|
|
|
+ self.states["/creating_trafficlight"] = State(3, "/creating_trafficlight", self)
|
|
|
|
|
|
|
|
- # add children
|
|
|
|
|
- self.states[""].addChild(self.states["/initializing"])
|
|
|
|
|
- self.states[""].addChild(self.states["/creating"])
|
|
|
|
|
- self.states[""].addChild(self.states["/initialized"])
|
|
|
|
|
- self.states[""].fixTree()
|
|
|
|
|
- self.states[""].default_state = self.states["/initializing"]
|
|
|
|
|
|
|
+ # state /creating_trafficlight/creating_greenlight
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_greenlight"] = State(4, "/creating_trafficlight/creating_greenlight", self)
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_greenlight"].setEnter(self._creating_trafficlight_creating_greenlight_enter)
|
|
|
|
|
|
|
|
- # transition /initializing
|
|
|
|
|
- _initializing_0 = Transition(self, self.states["/initializing"], [self.states["/creating"]])
|
|
|
|
|
- _initializing_0.setAction(self._initializing_0_exec)
|
|
|
|
|
- _initializing_0.setTrigger(None)
|
|
|
|
|
- self.states["/initializing"].addTransition(_initializing_0)
|
|
|
|
|
|
|
+ # state /creating_trafficlight/creating_yellowlight
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_yellowlight"] = State(5, "/creating_trafficlight/creating_yellowlight", self)
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_yellowlight"].setEnter(self._creating_trafficlight_creating_yellowlight_enter)
|
|
|
|
|
|
|
|
- # transition /creating
|
|
|
|
|
- _creating_0 = Transition(self, self.states["/creating"], [self.states["/initialized"]])
|
|
|
|
|
- _creating_0.setAction(self._creating_0_exec)
|
|
|
|
|
- _creating_0.setTrigger(Event("instance_created", None))
|
|
|
|
|
- self.states["/creating"].addTransition(_creating_0)
|
|
|
|
|
-
|
|
|
|
|
- def _initializing_0_exec(self, parameters):
|
|
|
|
|
- self.big_step.outputEventOM(Event("create_instance", None, [self, "trafficlight", "TrafficLight", self.canvas]))
|
|
|
|
|
-
|
|
|
|
|
- def _creating_0_exec(self, parameters):
|
|
|
|
|
- association_name = parameters[0]
|
|
|
|
|
- self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
|
|
|
|
|
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name])]))
|
|
|
|
|
-
|
|
|
|
|
- def initializeStatechart(self):
|
|
|
|
|
- # enter default state
|
|
|
|
|
- self.default_targets = self.states["/initializing"].getEffectiveTargetStates()
|
|
|
|
|
- RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
-
|
|
|
|
|
-class MainApp(AtomicDEVS, ObjectManagerBase):
|
|
|
|
|
- def __init__(self, name):
|
|
|
|
|
- AtomicDEVS.__init__(self, name)
|
|
|
|
|
- ObjectManagerBase.__init__(self)
|
|
|
|
|
- self.elapsed = 0
|
|
|
|
|
- self.obj_manager_in = self.addInPort("obj_manager_in")
|
|
|
|
|
- self.obj_manager_out = self.addOutPort("obj_manager_out")
|
|
|
|
|
- self.input = self.addInPort("input")
|
|
|
|
|
- self.outputs = {}
|
|
|
|
|
- self.outputs["trafficlight"] = self.addOutPort("trafficlight")
|
|
|
|
|
- self.obj_manager_in = self.addInPort("obj_manager_in")
|
|
|
|
|
- self.input = self.addInPort("input")
|
|
|
|
|
- self.instances.add(MainAppInstance(self))
|
|
|
|
|
-
|
|
|
|
|
- self.name = "MainApp"
|
|
|
|
|
-
|
|
|
|
|
- def extTransition(self, inputs):
|
|
|
|
|
- self.simulated_time = (self.simulated_time + self.elapsed)
|
|
|
|
|
- all_inputs = []
|
|
|
|
|
- if self.obj_manager_in in inputs:
|
|
|
|
|
- all_inputs.extend(inputs[self.obj_manager_in])
|
|
|
|
|
- if self.input in inputs:
|
|
|
|
|
- all_inputs.extend(inputs[self.input])
|
|
|
|
|
- for input in all_inputs:
|
|
|
|
|
- if isinstance(input, str):
|
|
|
|
|
- tem = eval(input)
|
|
|
|
|
- self.addInput(tem)
|
|
|
|
|
- if input[3].name == "create_instance":
|
|
|
|
|
- self.instances.add(MainAppInstance(self))
|
|
|
|
|
- ev = Event("instance_created", None, parameters=[f"{input[0]}[{len(self.instances)-1}]"])
|
|
|
|
|
- self.to_send.append(("MainApp", TODO, input[2], ev))
|
|
|
|
|
- elif input[3].name == "start_instance":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.start()
|
|
|
|
|
- ev = Event("instance_started", None, parameters=[])
|
|
|
|
|
- self.to_send.append((input[0], input[1], input[2], ev))
|
|
|
|
|
- elif input[3].name == "delete_instance":
|
|
|
|
|
- ev = Event("instance_deleted", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "associate_instance":
|
|
|
|
|
- ev = Event("instance_associated", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "disassociate_instance":
|
|
|
|
|
- ev = Event("instance_disassociated", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "instance_created":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- instance.associations['fields'].instances[0] = input[3].parameters[0]
|
|
|
|
|
- elif input[3].name == "instance_started":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_deleted":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_associated":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_disassociated":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "set_association_name":
|
|
|
|
|
- ev = input[3]
|
|
|
|
|
- self.addInput(ev, force_internal=True)
|
|
|
|
|
- return self.instances
|
|
|
|
|
-
|
|
|
|
|
- def intTransition(self):
|
|
|
|
|
- self.to_send = []
|
|
|
|
|
- self.handleInput()
|
|
|
|
|
- self.stepAll()
|
|
|
|
|
- return self.instances
|
|
|
|
|
-
|
|
|
|
|
- def outputFnc(self):
|
|
|
|
|
- to_dict = {}
|
|
|
|
|
- for sending in self.to_send:
|
|
|
|
|
- if sending[0] == None:
|
|
|
|
|
- if self.obj_manager_out in to_dict:
|
|
|
|
|
- to_dict[self.obj_manager_out].append(sending)
|
|
|
|
|
- else:
|
|
|
|
|
- to_dict[self.obj_manager_out] = [sending]
|
|
|
|
|
- else:
|
|
|
|
|
- the_port = None
|
|
|
|
|
- for port in self.OPorts:
|
|
|
|
|
- if port.name == sending[0]:
|
|
|
|
|
- the_port = port
|
|
|
|
|
- if the_port in to_dict:
|
|
|
|
|
- to_dict[the_port].append(sending)
|
|
|
|
|
- else:
|
|
|
|
|
- to_dict[the_port] = [sending]
|
|
|
|
|
- return to_dict
|
|
|
|
|
-
|
|
|
|
|
- def timeAdvance(self):
|
|
|
|
|
- if not (len(self.to_send) == 0):
|
|
|
|
|
- return 0
|
|
|
|
|
- return self.getEarliestEventTime()
|
|
|
|
|
-
|
|
|
|
|
-class TrafficLightInstance(RuntimeClassBase):
|
|
|
|
|
- def __init__(self, atomdevs, canvas):
|
|
|
|
|
- RuntimeClassBase.__init__(self, atomdevs)
|
|
|
|
|
- self.associations = {}
|
|
|
|
|
|
|
+ # state /creating_trafficlight/creating_redlight
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_redlight"] = State(6, "/creating_trafficlight/creating_redlight", self)
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_redlight"].setEnter(self._creating_trafficlight_creating_redlight_enter)
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
|
|
+ # state /creating_interrupt_button
|
|
|
|
|
+ self.states["/creating_interrupt_button"] = State(7, "/creating_interrupt_button", self)
|
|
|
|
|
+ self.states["/creating_interrupt_button"].setEnter(self._creating_interrupt_button_enter)
|
|
|
|
|
|
|
|
- # build Statechart structure
|
|
|
|
|
- self.build_statechart_structure()
|
|
|
|
|
-
|
|
|
|
|
- # call user defined constructor
|
|
|
|
|
- TrafficLightInstance.user_defined_constructor(self, canvas)
|
|
|
|
|
-
|
|
|
|
|
- def user_defined_constructor(self, canvas):
|
|
|
|
|
- size = 100;
|
|
|
|
|
- offset = size+5;
|
|
|
|
|
- self.RED = 0;
|
|
|
|
|
- self.YELLOW = 1;
|
|
|
|
|
- self.GREEN = 2;
|
|
|
|
|
- self.colors = ['#f00','#ff0','#0f0']
|
|
|
|
|
- self.lights = [
|
|
|
|
|
- canvas.add_rectangle(size/2, size/2, size, size, {'fill':'#000'}),
|
|
|
|
|
- canvas.add_rectangle(size/2, size/2+offset, size, size, {'fill':'#000'}),
|
|
|
|
|
- canvas.add_rectangle(size/2, size/2+2*offset, size, size, {'fill':'#000'})];
|
|
|
|
|
-
|
|
|
|
|
- def user_defined_destructor(self):
|
|
|
|
|
- pass
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- # user defined method
|
|
|
|
|
- def clear(self):
|
|
|
|
|
- self.lights[self.RED].set_color('#000');
|
|
|
|
|
- self.lights[self.YELLOW].set_color('#000');
|
|
|
|
|
- self.lights[self.GREEN].set_color('#000');
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- # user defined method
|
|
|
|
|
- def setGreen(self):
|
|
|
|
|
- self.clear();
|
|
|
|
|
- self.lights[self.GREEN].set_color(self.colors[self.GREEN]);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- # user defined method
|
|
|
|
|
- def setYellow(self):
|
|
|
|
|
- self.clear();
|
|
|
|
|
- self.lights[self.YELLOW].set_color(self.colors[self.YELLOW]);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- # user defined method
|
|
|
|
|
- def setRed(self):
|
|
|
|
|
- self.clear();
|
|
|
|
|
- self.lights[self.RED].set_color(self.colors[self.RED]);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- # builds Statechart structure
|
|
|
|
|
- def build_statechart_structure(self):
|
|
|
|
|
-
|
|
|
|
|
- # state <root>
|
|
|
|
|
- self.states[""] = State(0, "", self)
|
|
|
|
|
|
|
+ # state /creating_quit_button
|
|
|
|
|
+ self.states["/creating_quit_button"] = State(8, "/creating_quit_button", self)
|
|
|
|
|
+ self.states["/creating_quit_button"].setEnter(self._creating_quit_button_enter)
|
|
|
|
|
|
|
|
# state /on
|
|
# state /on
|
|
|
- self.states["/on"] = State(1, "/on", self)
|
|
|
|
|
|
|
+ self.states["/on"] = State(9, "/on", self)
|
|
|
|
|
|
|
|
# state /on/normal
|
|
# state /on/normal
|
|
|
- self.states["/on/normal"] = State(2, "/on/normal", self)
|
|
|
|
|
|
|
+ self.states["/on/normal"] = State(10, "/on/normal", self)
|
|
|
|
|
|
|
|
# state /on/normal/red
|
|
# state /on/normal/red
|
|
|
- self.states["/on/normal/red"] = State(3, "/on/normal/red", self)
|
|
|
|
|
|
|
+ self.states["/on/normal/red"] = State(11, "/on/normal/red", self)
|
|
|
self.states["/on/normal/red"].setEnter(self._on_normal_red_enter)
|
|
self.states["/on/normal/red"].setEnter(self._on_normal_red_enter)
|
|
|
self.states["/on/normal/red"].setExit(self._on_normal_red_exit)
|
|
self.states["/on/normal/red"].setExit(self._on_normal_red_exit)
|
|
|
|
|
|
|
|
# state /on/normal/green
|
|
# state /on/normal/green
|
|
|
- self.states["/on/normal/green"] = State(4, "/on/normal/green", self)
|
|
|
|
|
|
|
+ self.states["/on/normal/green"] = State(12, "/on/normal/green", self)
|
|
|
self.states["/on/normal/green"].setEnter(self._on_normal_green_enter)
|
|
self.states["/on/normal/green"].setEnter(self._on_normal_green_enter)
|
|
|
self.states["/on/normal/green"].setExit(self._on_normal_green_exit)
|
|
self.states["/on/normal/green"].setExit(self._on_normal_green_exit)
|
|
|
|
|
|
|
|
# state /on/normal/yellow
|
|
# state /on/normal/yellow
|
|
|
- self.states["/on/normal/yellow"] = State(5, "/on/normal/yellow", self)
|
|
|
|
|
|
|
+ self.states["/on/normal/yellow"] = State(13, "/on/normal/yellow", self)
|
|
|
self.states["/on/normal/yellow"].setEnter(self._on_normal_yellow_enter)
|
|
self.states["/on/normal/yellow"].setEnter(self._on_normal_yellow_enter)
|
|
|
self.states["/on/normal/yellow"].setExit(self._on_normal_yellow_exit)
|
|
self.states["/on/normal/yellow"].setExit(self._on_normal_yellow_exit)
|
|
|
|
|
|
|
|
- # state /on/normal/history
|
|
|
|
|
- self.states["/on/normal/history"] = ShallowHistoryState(6, "/on/normal/history", self)
|
|
|
|
|
-
|
|
|
|
|
# state /on/interrupted
|
|
# state /on/interrupted
|
|
|
- self.states["/on/interrupted"] = State(7, "/on/interrupted", self)
|
|
|
|
|
|
|
+ self.states["/on/interrupted"] = State(14, "/on/interrupted", self)
|
|
|
|
|
|
|
|
# state /on/interrupted/yellow
|
|
# state /on/interrupted/yellow
|
|
|
- self.states["/on/interrupted/yellow"] = State(8, "/on/interrupted/yellow", self)
|
|
|
|
|
|
|
+ self.states["/on/interrupted/yellow"] = State(15, "/on/interrupted/yellow", self)
|
|
|
self.states["/on/interrupted/yellow"].setEnter(self._on_interrupted_yellow_enter)
|
|
self.states["/on/interrupted/yellow"].setEnter(self._on_interrupted_yellow_enter)
|
|
|
self.states["/on/interrupted/yellow"].setExit(self._on_interrupted_yellow_exit)
|
|
self.states["/on/interrupted/yellow"].setExit(self._on_interrupted_yellow_exit)
|
|
|
|
|
|
|
|
# state /on/interrupted/black
|
|
# state /on/interrupted/black
|
|
|
- self.states["/on/interrupted/black"] = State(9, "/on/interrupted/black", self)
|
|
|
|
|
|
|
+ self.states["/on/interrupted/black"] = State(16, "/on/interrupted/black", self)
|
|
|
self.states["/on/interrupted/black"].setEnter(self._on_interrupted_black_enter)
|
|
self.states["/on/interrupted/black"].setEnter(self._on_interrupted_black_enter)
|
|
|
self.states["/on/interrupted/black"].setExit(self._on_interrupted_black_exit)
|
|
self.states["/on/interrupted/black"].setExit(self._on_interrupted_black_exit)
|
|
|
|
|
|
|
|
# state /off
|
|
# state /off
|
|
|
- self.states["/off"] = State(10, "/off", self)
|
|
|
|
|
|
|
+ self.states["/off"] = State(17, "/off", self)
|
|
|
self.states["/off"].setEnter(self._off_enter)
|
|
self.states["/off"].setEnter(self._off_enter)
|
|
|
|
|
|
|
|
|
|
+ # state /deleted
|
|
|
|
|
+ self.states["/deleted"] = State(18, "/deleted", self)
|
|
|
|
|
+
|
|
|
# add children
|
|
# add children
|
|
|
|
|
+ self.states[""].addChild(self.states["/creating_window"])
|
|
|
|
|
+ self.states[""].addChild(self.states["/creating_canvas"])
|
|
|
|
|
+ self.states[""].addChild(self.states["/creating_trafficlight"])
|
|
|
|
|
+ self.states[""].addChild(self.states["/creating_interrupt_button"])
|
|
|
|
|
+ self.states[""].addChild(self.states["/creating_quit_button"])
|
|
|
self.states[""].addChild(self.states["/on"])
|
|
self.states[""].addChild(self.states["/on"])
|
|
|
self.states[""].addChild(self.states["/off"])
|
|
self.states[""].addChild(self.states["/off"])
|
|
|
|
|
+ self.states[""].addChild(self.states["/deleted"])
|
|
|
|
|
+ self.states["/creating_trafficlight"].addChild(self.states["/creating_trafficlight/creating_greenlight"])
|
|
|
|
|
+ self.states["/creating_trafficlight"].addChild(self.states["/creating_trafficlight/creating_yellowlight"])
|
|
|
|
|
+ self.states["/creating_trafficlight"].addChild(self.states["/creating_trafficlight/creating_redlight"])
|
|
|
self.states["/on"].addChild(self.states["/on/normal"])
|
|
self.states["/on"].addChild(self.states["/on/normal"])
|
|
|
self.states["/on"].addChild(self.states["/on/interrupted"])
|
|
self.states["/on"].addChild(self.states["/on/interrupted"])
|
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/red"])
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/red"])
|
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/green"])
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/green"])
|
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/yellow"])
|
|
self.states["/on/normal"].addChild(self.states["/on/normal/yellow"])
|
|
|
- self.states["/on/normal"].addChild(self.states["/on/normal/history"])
|
|
|
|
|
self.states["/on/interrupted"].addChild(self.states["/on/interrupted/yellow"])
|
|
self.states["/on/interrupted"].addChild(self.states["/on/interrupted/yellow"])
|
|
|
self.states["/on/interrupted"].addChild(self.states["/on/interrupted/black"])
|
|
self.states["/on/interrupted"].addChild(self.states["/on/interrupted/black"])
|
|
|
self.states[""].fixTree()
|
|
self.states[""].fixTree()
|
|
|
- self.states[""].default_state = self.states["/on"]
|
|
|
|
|
|
|
+ self.states[""].default_state = self.states["/creating_window"]
|
|
|
|
|
+ self.states["/creating_trafficlight"].default_state = self.states["/creating_trafficlight/creating_greenlight"]
|
|
|
self.states["/on"].default_state = self.states["/on/normal"]
|
|
self.states["/on"].default_state = self.states["/on/normal"]
|
|
|
self.states["/on/normal"].default_state = self.states["/on/normal/red"]
|
|
self.states["/on/normal"].default_state = self.states["/on/normal/red"]
|
|
|
self.states["/on/interrupted"].default_state = self.states["/on/interrupted/yellow"]
|
|
self.states["/on/interrupted"].default_state = self.states["/on/interrupted/yellow"]
|
|
|
|
|
|
|
|
|
|
+ # transition /creating_window
|
|
|
|
|
+ _creating_window_0 = Transition(self, self.states["/creating_window"], [self.states["/creating_canvas"]])
|
|
|
|
|
+ _creating_window_0.setAction(self._creating_window_0_exec)
|
|
|
|
|
+ _creating_window_0.setTrigger(Event("window_created", None))
|
|
|
|
|
+ self.states["/creating_window"].addTransition(_creating_window_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_canvas
|
|
|
|
|
+ _creating_canvas_0 = Transition(self, self.states["/creating_canvas"], [self.states["/creating_trafficlight"]])
|
|
|
|
|
+ _creating_canvas_0.setAction(self._creating_canvas_0_exec)
|
|
|
|
|
+ _creating_canvas_0.setTrigger(Event("canvas_created", None))
|
|
|
|
|
+ self.states["/creating_canvas"].addTransition(_creating_canvas_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_trafficlight/creating_greenlight
|
|
|
|
|
+ _creating_trafficlight_creating_greenlight_0 = Transition(self, self.states["/creating_trafficlight/creating_greenlight"], [self.states["/creating_trafficlight/creating_yellowlight"]])
|
|
|
|
|
+ _creating_trafficlight_creating_greenlight_0.setAction(self._creating_trafficlight_creating_greenlight_0_exec)
|
|
|
|
|
+ _creating_trafficlight_creating_greenlight_0.setTrigger(Event("rectangle_created", None))
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_greenlight"].addTransition(_creating_trafficlight_creating_greenlight_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_trafficlight/creating_yellowlight
|
|
|
|
|
+ _creating_trafficlight_creating_yellowlight_0 = Transition(self, self.states["/creating_trafficlight/creating_yellowlight"], [self.states["/creating_trafficlight/creating_redlight"]])
|
|
|
|
|
+ _creating_trafficlight_creating_yellowlight_0.setAction(self._creating_trafficlight_creating_yellowlight_0_exec)
|
|
|
|
|
+ _creating_trafficlight_creating_yellowlight_0.setTrigger(Event("rectangle_created", None))
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_yellowlight"].addTransition(_creating_trafficlight_creating_yellowlight_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_trafficlight/creating_redlight
|
|
|
|
|
+ _creating_trafficlight_creating_redlight_0 = Transition(self, self.states["/creating_trafficlight/creating_redlight"], [self.states["/creating_interrupt_button"]])
|
|
|
|
|
+ _creating_trafficlight_creating_redlight_0.setAction(self._creating_trafficlight_creating_redlight_0_exec)
|
|
|
|
|
+ _creating_trafficlight_creating_redlight_0.setTrigger(Event("rectangle_created", None))
|
|
|
|
|
+ self.states["/creating_trafficlight/creating_redlight"].addTransition(_creating_trafficlight_creating_redlight_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_interrupt_button
|
|
|
|
|
+ _creating_interrupt_button_0 = Transition(self, self.states["/creating_interrupt_button"], [self.states["/creating_quit_button"]])
|
|
|
|
|
+ _creating_interrupt_button_0.setAction(self._creating_interrupt_button_0_exec)
|
|
|
|
|
+ _creating_interrupt_button_0.setTrigger(Event("button_created", None))
|
|
|
|
|
+ self.states["/creating_interrupt_button"].addTransition(_creating_interrupt_button_0)
|
|
|
|
|
+
|
|
|
|
|
+ # transition /creating_quit_button
|
|
|
|
|
+ _creating_quit_button_0 = Transition(self, self.states["/creating_quit_button"], [self.states["/on"]])
|
|
|
|
|
+ _creating_quit_button_0.setAction(self._creating_quit_button_0_exec)
|
|
|
|
|
+ _creating_quit_button_0.setTrigger(Event("button_created", None))
|
|
|
|
|
+ self.states["/creating_quit_button"].addTransition(_creating_quit_button_0)
|
|
|
|
|
+
|
|
|
# transition /on/normal/red
|
|
# transition /on/normal/red
|
|
|
_on_normal_red_0 = Transition(self, self.states["/on/normal/red"], [self.states["/on/normal/green"]])
|
|
_on_normal_red_0 = Transition(self, self.states["/on/normal/red"], [self.states["/on/normal/green"]])
|
|
|
_on_normal_red_0.setTrigger(Event("_0after"))
|
|
_on_normal_red_0.setTrigger(Event("_0after"))
|
|
@@ -333,199 +224,192 @@ class TrafficLightInstance(RuntimeClassBase):
|
|
|
_on_interrupted_black_0.setTrigger(Event("_4after"))
|
|
_on_interrupted_black_0.setTrigger(Event("_4after"))
|
|
|
self.states["/on/interrupted/black"].addTransition(_on_interrupted_black_0)
|
|
self.states["/on/interrupted/black"].addTransition(_on_interrupted_black_0)
|
|
|
|
|
|
|
|
- # transition /on
|
|
|
|
|
- _on_0 = Transition(self, self.states["/on"], [self.states["/off"]])
|
|
|
|
|
- _on_0.setTrigger(Event("quit_clicked", self.getInPortName("ui")))
|
|
|
|
|
- self.states["/on"].addTransition(_on_0)
|
|
|
|
|
-
|
|
|
|
|
# transition /on/normal
|
|
# transition /on/normal
|
|
|
- _on_normal_0 = Transition(self, self.states["/on/normal"], [self.states["/on/interrupted"]])
|
|
|
|
|
- _on_normal_0.setTrigger(Event("police_interrupt_clicked", self.getInPortName("ui")))
|
|
|
|
|
|
|
+ _on_normal_0 = Transition(self, self.states["/on/normal"], [self.states["/deleted"]])
|
|
|
|
|
+ _on_normal_0.setAction(self._on_normal_0_exec)
|
|
|
|
|
+ _on_normal_0.setTrigger(Event("window_close", self.getInPortName("field_ui")))
|
|
|
self.states["/on/normal"].addTransition(_on_normal_0)
|
|
self.states["/on/normal"].addTransition(_on_normal_0)
|
|
|
|
|
+ _on_normal_1 = Transition(self, self.states["/on/normal"], [self.states["/off"]])
|
|
|
|
|
+ _on_normal_1.setTrigger(Event("quit_clicked", self.getInPortName("field_ui")))
|
|
|
|
|
+ _on_normal_1.setGuard(self._on_normal_1_guard)
|
|
|
|
|
+ self.states["/on/normal"].addTransition(_on_normal_1)
|
|
|
|
|
+ _on_normal_2 = Transition(self, self.states["/on/normal"], [self.states["/on/interrupted"]])
|
|
|
|
|
+ _on_normal_2.setAction(self._on_normal_2_exec)
|
|
|
|
|
+ _on_normal_2.setTrigger(Event("interrupt_clicked", self.getInPortName("field_ui")))
|
|
|
|
|
+ _on_normal_2.setGuard(self._on_normal_2_guard)
|
|
|
|
|
+ self.states["/on/normal"].addTransition(_on_normal_2)
|
|
|
|
|
|
|
|
# transition /on/interrupted
|
|
# transition /on/interrupted
|
|
|
- _on_interrupted_0 = Transition(self, self.states["/on/interrupted"], [self.states["/on/normal/history"]])
|
|
|
|
|
- _on_interrupted_0.setTrigger(Event("police_interrupt_clicked", self.getInPortName("ui")))
|
|
|
|
|
|
|
+ _on_interrupted_0 = Transition(self, self.states["/on/interrupted"], [self.states["/on/normal"]])
|
|
|
|
|
+ _on_interrupted_0.setTrigger(Event("interrupt_clicked", self.getInPortName("field_ui")))
|
|
|
|
|
+ _on_interrupted_0.setGuard(self._on_interrupted_0_guard)
|
|
|
self.states["/on/interrupted"].addTransition(_on_interrupted_0)
|
|
self.states["/on/interrupted"].addTransition(_on_interrupted_0)
|
|
|
|
|
|
|
|
|
|
+ def _creating_window_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_window", self.getOutPortName("ui"), [CANVAS_DIMS[0], CANVAS_DIMS[1], "Fixed Traffic Light", self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_canvas_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_canvas", self.getOutPortName("ui"), [self.window_id, CANVAS_DIMS[0], CANVAS_DIMS[1] - 100, {'background':'#222222'}, self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_greenlight_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_rectangle", self.getOutPortName("ui"), [self.canvas_id, 50, 50, 50, 50, {'fill':'#000'}, self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_yellowlight_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_rectangle", self.getOutPortName("ui"), [self.canvas_id, 50, 110, 50, 50, {'fill':'#000'}, self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_redlight_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_rectangle", self.getOutPortName("ui"), [self.canvas_id, 50, 170, 50, 50, {'fill':'#000'}, self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_interrupt_button_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_button", self.getOutPortName("ui"), [self.window_id, 'Police Interrupt', self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_quit_button_enter(self):
|
|
|
|
|
+ self.big_step.outputEvent(Event("create_button", self.getOutPortName("ui"), [self.window_id, 'Quit', self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
def _on_normal_red_enter(self):
|
|
def _on_normal_red_enter(self):
|
|
|
- self.setRed();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.red_id, 'red']))
|
|
|
self.addTimer(0, 3)
|
|
self.addTimer(0, 3)
|
|
|
|
|
|
|
|
def _on_normal_red_exit(self):
|
|
def _on_normal_red_exit(self):
|
|
|
self.removeTimer(0)
|
|
self.removeTimer(0)
|
|
|
|
|
|
|
|
def _on_normal_green_enter(self):
|
|
def _on_normal_green_enter(self):
|
|
|
- self.setGreen();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.red_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.green_id, 'green']))
|
|
|
self.addTimer(1, 2)
|
|
self.addTimer(1, 2)
|
|
|
|
|
|
|
|
def _on_normal_green_exit(self):
|
|
def _on_normal_green_exit(self):
|
|
|
self.removeTimer(1)
|
|
self.removeTimer(1)
|
|
|
|
|
|
|
|
def _on_normal_yellow_enter(self):
|
|
def _on_normal_yellow_enter(self):
|
|
|
- self.setYellow();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.green_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'yellow']))
|
|
|
self.addTimer(2, 1)
|
|
self.addTimer(2, 1)
|
|
|
|
|
|
|
|
def _on_normal_yellow_exit(self):
|
|
def _on_normal_yellow_exit(self):
|
|
|
self.removeTimer(2)
|
|
self.removeTimer(2)
|
|
|
|
|
|
|
|
def _on_interrupted_yellow_enter(self):
|
|
def _on_interrupted_yellow_enter(self):
|
|
|
- self.setYellow();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'yellow']))
|
|
|
self.addTimer(3, .5)
|
|
self.addTimer(3, .5)
|
|
|
|
|
|
|
|
def _on_interrupted_yellow_exit(self):
|
|
def _on_interrupted_yellow_exit(self):
|
|
|
self.removeTimer(3)
|
|
self.removeTimer(3)
|
|
|
|
|
|
|
|
def _on_interrupted_black_enter(self):
|
|
def _on_interrupted_black_enter(self):
|
|
|
- self.clear();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'black']))
|
|
|
self.addTimer(4, .5)
|
|
self.addTimer(4, .5)
|
|
|
|
|
|
|
|
def _on_interrupted_black_exit(self):
|
|
def _on_interrupted_black_exit(self):
|
|
|
self.removeTimer(4)
|
|
self.removeTimer(4)
|
|
|
|
|
|
|
|
def _off_enter(self):
|
|
def _off_enter(self):
|
|
|
- self.clear();
|
|
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.green_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.red_id, 'black']))
|
|
|
|
|
+
|
|
|
|
|
+ def _on_normal_0_exec(self, parameters):
|
|
|
|
|
+ self.big_step.outputEvent(Event("destroy_all", self.getOutPortName("ui"), []))
|
|
|
|
|
+
|
|
|
|
|
+ def _on_normal_1_guard(self, parameters):
|
|
|
|
|
+ x = parameters[0]
|
|
|
|
|
+ y = parameters[1]
|
|
|
|
|
+ button = parameters[2]
|
|
|
|
|
+ return button == ui.MOUSE_BUTTONS.LEFT
|
|
|
|
|
+
|
|
|
|
|
+ def _on_normal_2_exec(self, parameters):
|
|
|
|
|
+ x = parameters[0]
|
|
|
|
|
+ y = parameters[1]
|
|
|
|
|
+ button = parameters[2]
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.green_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.yellow_id, 'black']))
|
|
|
|
|
+ self.big_step.outputEvent(Event("set_element_color", self.getOutPortName("ui"), [self.canvas_id, self.red_id, 'black']))
|
|
|
|
|
+
|
|
|
|
|
+ def _on_normal_2_guard(self, parameters):
|
|
|
|
|
+ x = parameters[0]
|
|
|
|
|
+ y = parameters[1]
|
|
|
|
|
+ button = parameters[2]
|
|
|
|
|
+ return button == ui.MOUSE_BUTTONS.LEFT
|
|
|
|
|
+
|
|
|
|
|
+ def _on_interrupted_0_guard(self, parameters):
|
|
|
|
|
+ x = parameters[0]
|
|
|
|
|
+ y = parameters[1]
|
|
|
|
|
+ button = parameters[2]
|
|
|
|
|
+ return button == ui.MOUSE_BUTTONS.LEFT
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_window_0_exec(self, parameters):
|
|
|
|
|
+ window_id = parameters[0]
|
|
|
|
|
+ self.window_id = window_id
|
|
|
|
|
+ self.big_step.outputEvent(Event("bind_event", self.getOutPortName("ui"), [window_id, ui.EVENTS.WINDOW_CLOSE, 'window_close', self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_canvas_0_exec(self, parameters):
|
|
|
|
|
+ canvas_id = parameters[0]
|
|
|
|
|
+ self.canvas_id = canvas_id
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_greenlight_0_exec(self, parameters):
|
|
|
|
|
+ canvas_id = parameters[0]
|
|
|
|
|
+ green_id = parameters[1]
|
|
|
|
|
+ self.green_id = green_id
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_yellowlight_0_exec(self, parameters):
|
|
|
|
|
+ canvas_id = parameters[0]
|
|
|
|
|
+ yellow_id = parameters[1]
|
|
|
|
|
+ self.yellow_id = yellow_id
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_trafficlight_creating_redlight_0_exec(self, parameters):
|
|
|
|
|
+ canvas_id = parameters[0]
|
|
|
|
|
+ red_id = parameters[1]
|
|
|
|
|
+ self.red_id = red_id
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_interrupt_button_0_exec(self, parameters):
|
|
|
|
|
+ button_id = parameters[0]
|
|
|
|
|
+ self.police_button_id = button_id
|
|
|
|
|
+ self.big_step.outputEvent(Event("bind_event", self.getOutPortName("ui"), [button_id, ui.EVENTS.MOUSE_CLICK, "interrupt_clicked", self.inports['field_ui']]))
|
|
|
|
|
+
|
|
|
|
|
+ def _creating_quit_button_0_exec(self, parameters):
|
|
|
|
|
+ button_id = parameters[0]
|
|
|
|
|
+ self.quit_button_id = button_id
|
|
|
|
|
+ self.big_step.outputEvent(Event("bind_event", self.getOutPortName("ui"), [button_id, ui.EVENTS.MOUSE_CLICK, "quit_clicked", self.inports['field_ui']]))
|
|
|
|
|
|
|
|
def initializeStatechart(self):
|
|
def initializeStatechart(self):
|
|
|
# enter default state
|
|
# enter default state
|
|
|
- self.default_targets = self.states["/on"].getEffectiveTargetStates()
|
|
|
|
|
|
|
+ self.default_targets = self.states["/creating_window"].getEffectiveTargetStates()
|
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
|
|
-class TrafficLight(AtomicDEVS, ObjectManagerBase):
|
|
|
|
|
|
|
+class MainApp(ObjectManagerBase):
|
|
|
def __init__(self, name):
|
|
def __init__(self, name):
|
|
|
- AtomicDEVS.__init__(self, name)
|
|
|
|
|
- ObjectManagerBase.__init__(self)
|
|
|
|
|
- self.elapsed = 0
|
|
|
|
|
- self.obj_manager_in = self.addInPort("obj_manager_in")
|
|
|
|
|
- self.obj_manager_out = self.addOutPort("obj_manager_out")
|
|
|
|
|
- self.input = self.addInPort("input")
|
|
|
|
|
- self.outputs = {}
|
|
|
|
|
- self.obj_manager_in = self.addInPort("obj_manager_in")
|
|
|
|
|
|
|
+ ObjectManagerBase.__init__(self, name)
|
|
|
self.input = self.addInPort("input")
|
|
self.input = self.addInPort("input")
|
|
|
-
|
|
|
|
|
- def extTransition(self, inputs):
|
|
|
|
|
- self.simulated_time = (self.simulated_time + self.elapsed)
|
|
|
|
|
- all_inputs = []
|
|
|
|
|
- if self.obj_manager_in in inputs:
|
|
|
|
|
- all_inputs.extend(inputs[self.obj_manager_in])
|
|
|
|
|
- if self.input in inputs:
|
|
|
|
|
- all_inputs.extend(inputs[self.input])
|
|
|
|
|
- for input in all_inputs:
|
|
|
|
|
- if isinstance(input, str):
|
|
|
|
|
- tem = eval(input)
|
|
|
|
|
- self.addInput(tem)
|
|
|
|
|
- if input[3].name == "create_instance":
|
|
|
|
|
- self.instances.add(TrafficLightInstance(self))
|
|
|
|
|
- ev = Event("instance_created", None, parameters=[f"{input[0]}[{len(self.instances)-1}]"])
|
|
|
|
|
- self.to_send.append(("TrafficLight", TODO, input[2], ev))
|
|
|
|
|
- elif input[3].name == "start_instance":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.start()
|
|
|
|
|
- ev = Event("instance_started", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((input[0], input[1], input[2], ev))
|
|
|
|
|
- elif input[3].name == "delete_instance":
|
|
|
|
|
- ev = Event("instance_deleted", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "associate_instance":
|
|
|
|
|
- ev = Event("instance_associated", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "disassociate_instance":
|
|
|
|
|
- ev = Event("instance_disassociated", None, parameters=[TODO])
|
|
|
|
|
- self.to_send.append((TODO, TODO, TODO, ev))
|
|
|
|
|
- elif input[3].name == "instance_created":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- instance.associations['fields'].instances[0] = input[3].parameters[0]
|
|
|
|
|
- elif input[3].name == "instance_started":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_deleted":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_associated":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "instance_disassociated":
|
|
|
|
|
- instance = list(self.instances)[input[2]]
|
|
|
|
|
- instance.addEvent(input[3])
|
|
|
|
|
- elif input[3].name == "set_association_name":
|
|
|
|
|
- ev = input[3]
|
|
|
|
|
- self.addInput(ev, force_internal=True)
|
|
|
|
|
- return self.instances
|
|
|
|
|
-
|
|
|
|
|
- def intTransition(self):
|
|
|
|
|
- self.to_send = []
|
|
|
|
|
- self.handleInput()
|
|
|
|
|
- self.stepAll()
|
|
|
|
|
- return self.instances
|
|
|
|
|
-
|
|
|
|
|
- def outputFnc(self):
|
|
|
|
|
- to_dict = {}
|
|
|
|
|
- for sending in self.to_send:
|
|
|
|
|
- if sending[0] == None:
|
|
|
|
|
- if self.obj_manager_out in to_dict:
|
|
|
|
|
- to_dict[self.obj_manager_out].append(sending)
|
|
|
|
|
- else:
|
|
|
|
|
- to_dict[self.obj_manager_out] = [sending]
|
|
|
|
|
- else:
|
|
|
|
|
- the_port = None
|
|
|
|
|
- for port in self.OPorts:
|
|
|
|
|
- if port.name == sending[0]:
|
|
|
|
|
- the_port = port
|
|
|
|
|
- if the_port in to_dict:
|
|
|
|
|
- to_dict[the_port].append(sending)
|
|
|
|
|
- else:
|
|
|
|
|
- to_dict[the_port] = [sending]
|
|
|
|
|
- return to_dict
|
|
|
|
|
-
|
|
|
|
|
- def timeAdvance(self):
|
|
|
|
|
- if not (len(self.to_send) == 0):
|
|
|
|
|
- return 0
|
|
|
|
|
- return self.getEarliestEventTime()
|
|
|
|
|
|
|
+ self.output = self.addOutPort("ui")
|
|
|
|
|
+ self.field_ui = self.addInPort("field_ui")
|
|
|
|
|
+ self.instances[self.next_instance] = MainAppInstance(self)
|
|
|
|
|
+ self.next_instance = self.next_instance + 1
|
|
|
|
|
+
|
|
|
|
|
+ def constructObject(self, parameters):
|
|
|
|
|
+ new_instance = MainAppInstance(self)
|
|
|
|
|
+ return new_instance
|
|
|
|
|
|
|
|
class ObjectManagerState:
|
|
class ObjectManagerState:
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
|
- self.to_send = [(None, "MainApp", 0, Event("start_instance", None, None))]
|
|
|
|
|
|
|
+ self.to_send = [("MainApp", "MainApp", Event("start_instance", None, ["MainApp[0]"], 0))]
|
|
|
|
|
|
|
|
-class ObjectManager(AtomicDEVS):
|
|
|
|
|
|
|
+class ObjectManager(TheObjectManager):
|
|
|
def __init__(self, name):
|
|
def __init__(self, name):
|
|
|
- AtomicDEVS.__init__(self, name)
|
|
|
|
|
|
|
+ TheObjectManager.__init__(self, name)
|
|
|
self.State = ObjectManagerState()
|
|
self.State = ObjectManagerState()
|
|
|
self.input = self.addInPort("input")
|
|
self.input = self.addInPort("input")
|
|
|
- self.output = {}
|
|
|
|
|
self.output["MainApp"] = self.addOutPort()
|
|
self.output["MainApp"] = self.addOutPort()
|
|
|
- self.output["TrafficLight"] = self.addOutPort()
|
|
|
|
|
-
|
|
|
|
|
- def extTransition(self, inputs):
|
|
|
|
|
- all_inputs = inputs[self.input]
|
|
|
|
|
- for input in all_inputs:
|
|
|
|
|
- self.State.to_send.append(input)
|
|
|
|
|
- return self.State
|
|
|
|
|
-
|
|
|
|
|
- def intTransition(self):
|
|
|
|
|
- self.State.to_send = []
|
|
|
|
|
- return self.State
|
|
|
|
|
-
|
|
|
|
|
- def outputFnc(self):
|
|
|
|
|
- out_dict = {}
|
|
|
|
|
- for (source, target, id, message) in self.State.to_send:
|
|
|
|
|
- out_dict[self.output[target]] = [(source, target, id, message)]
|
|
|
|
|
- return out_dict
|
|
|
|
|
-
|
|
|
|
|
- def timeAdvance(self):
|
|
|
|
|
- if self.State.to_send:
|
|
|
|
|
- return 0
|
|
|
|
|
- return INFINITY
|
|
|
|
|
|
|
|
|
|
class Controller(CoupledDEVS):
|
|
class Controller(CoupledDEVS):
|
|
|
def __init__(self, name):
|
|
def __init__(self, name):
|
|
|
CoupledDEVS.__init__(self, name)
|
|
CoupledDEVS.__init__(self, name)
|
|
|
- self.ui = self.addInPort("ui")
|
|
|
|
|
|
|
+ self.in_ui = self.addInPort("ui")
|
|
|
|
|
+ Ports.addInputPort("ui")
|
|
|
|
|
+ self.out_ui = self.addOutPort("ui")
|
|
|
|
|
+ Ports.addOutputPort("ui")
|
|
|
self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
|
|
self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
|
|
|
self.atomic0 = self.addSubModel(MainApp("MainApp"))
|
|
self.atomic0 = self.addSubModel(MainApp("MainApp"))
|
|
|
- self.atomic1 = self.addSubModel(TrafficLight("TrafficLight"))
|
|
|
|
|
self.connectPorts(self.atomic0.obj_manager_out, self.objectmanager.input)
|
|
self.connectPorts(self.atomic0.obj_manager_out, self.objectmanager.input)
|
|
|
self.connectPorts(self.objectmanager.output["MainApp"], self.atomic0.obj_manager_in)
|
|
self.connectPorts(self.objectmanager.output["MainApp"], self.atomic0.obj_manager_in)
|
|
|
- self.connectPorts(self.atomic0.outputs["trafficlight"], self.atomic1.input)
|
|
|
|
|
- self.connectPorts(self.atomic1.obj_manager_out, self.objectmanager.input)
|
|
|
|
|
- self.connectPorts(self.objectmanager.output["TrafficLight"], self.atomic1.obj_manager_in)
|
|
|
|
|
|
|
+ self.connectPorts(self.atomic0.output, self.out_ui)
|