def load_transition(element, net, loader): id = loader.get_id(element) transition = net.add_transition((xml_int(element,"x"), xml_int(element, "y")), id) sx = xml_int(element,"sx") sy = xml_int(element,"sy") transition.box.size = (sx, sy) transition.box.name = xml_str(element,"name", "") if element.find("guard") is not None: canvastext_from_xml(element.find("guard"), transition.guard) else: transition.guard.text = element.get("guard", "") # Backward compatability transition.set_code(load_code(element)) transition.tracing = load_tracing(element) transition.clock = utils.xml_bool(element, "clock", False) if element.find("time-substitution") is not None: transition.time_substitution = True transition.time_substitution_code = element.find("time-substitution").text if element.find("clock-substitution") is not None: transition.clock_substitution = True transition.clock_substitution_code = element.find("clock-substitution").text e = element.find("verif-occurrence") if e is not None: transition.occurrence_analysis = True transition.occurrence_analysis_compare_process = utils.xml_bool(e, "process") transition.occurrence_analysis_compare_binding = utils.xml_bool(e, "binding") transition.set_priority(element.get("priority", ""))
def load_place_tracing(element, place): if element is None: return place.trace_tokens = utils.xml_bool(element, "trace-tokens", False) for e in element.findall("function"): name = e.get("name") return_type = e.get("return-type") place.trace_tokens_functions.append(tracing.TraceFunction(name, return_type))
def reports_callback(line): root = xml.fromstring(line) net_id = utils.xml_int(root, "net-id") runinstance = RunInstance(self.project, self.process_count) for process_id, e in enumerate(root.findall("process")): runinstance.event_spawn(process_id, 0, net_id) for pe in e.findall("place"): place_id = utils.xml_int(pe, "id") for te in pe.findall("token"): name = te.get("value") source = te.get("source") if source is not None: name = "{{{0}}} {1}".format(source, name) runinstance.add_token(place_id, 0, name) runinstance.clear_removed_and_new_tokens() for tre in e.findall("enabled"): runinstance.add_enabled_transition(utils.xml_int(tre, "id")) for e in root.findall("activation"): process_id = utils.xml_int(e, "process-id") transition_id = utils.xml_int(e, "transition-id") runinstance.transition_fired(process_id, 0, transition_id, []) if utils.xml_bool(e, "blocked", False): runinstance.transition_blocked(process_id) for e in root.findall("packet"): origin_id = utils.xml_int(e, "origin-id") target_id = utils.xml_int(e, "target-id") size = utils.xml_int(e, "size") edge_id = utils.xml_int(e, "edge-id") runinstance.event_send(origin_id, 0, target_id, size, edge_id) runinstance.reset_last_event_info() self.runinstance = runinstance self.history_instances.append(runinstance) if self.state != "finished" and utils.xml_bool(root, "quit"): self.state = "finished" self.emit_event("error", "Program finished\n") if callback: callback() self.emit_event("changed", True)
def load_transition(element, net, loader): id = loader.get_id(element) transition = net.add_transition( (xml_int(element, "x"), xml_int(element, "y")), id) sx = xml_int(element, "sx") sy = xml_int(element, "sy") if element.get("label-x") and element.get("label-y"): label_x = xml_int(element, "label-x") label_y = xml_int(element, "label-y") transition.label_placement.set_position((label_x, label_y)) transition.box.size = (sx, sy) transition.box.name = xml_str(element, "name", "") if element.find("guard") is not None: canvastext_from_xml(element.find("guard"), transition.guard) else: transition.guard.text = element.get("guard", "") # Backward compatability if element.find("root") is not None: canvastext_from_xml(element.find("root"), transition.root) transition.set_code(load_code(element)) transition.trace_fire = element.find("trace") is not None transition.clock = utils.xml_bool(element, "clock", False) transition.set_collective(utils.xml_bool(element, "collective", False)) if element.find("time-substitution") is not None: transition.time_substitution = True transition.time_substitution_code = element.find( "time-substitution").text if element.find("clock-substitution") is not None: transition.clock_substitution = True transition.clock_substitution_code = element.find( "clock-substitution").text e = element.find("verif-occurrence") if e is not None: transition.occurrence_analysis = True transition.occurrence_analysis_compare_process = utils.xml_bool( e, "process") transition.occurrence_analysis_compare_binding = utils.xml_bool( e, "binding") transition.set_priority(element.get("priority", ""))
def load_place_tracing(element, place): if element is None: return place.trace_tokens = utils.xml_bool(element, "trace-tokens", False) for e in element.findall("function"): name = e.get("name") return_type = e.get("return-type") place.trace_tokens_functions.append( tracing.TraceFunction(name, return_type))
def load_project_from_xml(root, filename): target_env_name = root.get("target_env") if target_env_name is None: # For backward compatability target_env_name = root.get("extenv", "C++") project = create_project(filename, target_env_name) project.library_rpc = utils.xml_bool(root, "library-rpc", False) project.library_octave = utils.xml_bool(root, "library-octave", False) loader = BasicLoader(project) if root.find("configuration") is not None: load_configuration(root.find("configuration"), project, loader) for e in root.findall("net"): project.add_net(load_net(e, project, loader)) assert project.nets for e in root.findall("sequence"): project.sequences.append(controlseq.ControlSequence(element=e)) project.build_net = project.nets[0] project.id_counter += 1 return project
def load_edge(element, net, loader): id = loader.get_id(element) fitem = net.item_by_id(loader.translate_id(xml_int(element, "from_item"))) assert fitem is not None titem = net.item_by_id(loader.translate_id(xml_int(element, "to_item"))) assert titem is not None points = [ (xml_int(e, "x"), xml_int(e,"y")) for e in element.findall("point") ] edge = net.add_edge(fitem, titem, points, id) edge.line.bidirectional = utils.xml_bool(element, "bidirectional", False) if element.find("inscription") is not None: canvastext_from_xml(element.find("inscription"), edge.inscription) else: # Backward compitabality if element.get("inscription") is not None: edge.inscription.text = xml_str(element, "inscription") if element.find("size-substitution") is not None: edge.size_substitution = True edge.size_substitution_code = element.find("size-substitution").text
def load_edge(element, net, loader): id = loader.get_id(element) fitem = net.item_by_id(loader.translate_id(xml_int(element, "from_item"))) assert fitem is not None titem = net.item_by_id(loader.translate_id(xml_int(element, "to_item"))) assert titem is not None points = [(xml_int(e, "x"), xml_int(e, "y")) for e in element.findall("point")] edge = net.add_edge(fitem, titem, points, id) edge.line.bidirectional = utils.xml_bool(element, "bidirectional", False) if element.find("inscription") is not None: canvastext_from_xml(element.find("inscription"), edge.inscription) else: # Backward compitabality if element.get("inscription") is not None: edge.inscription.text = xml_str(element, "inscription") if element.find("size-substitution") is not None: edge.size_substitution = True edge.size_substitution_code = element.find("size-substitution").text