def _read_header(self): with open(self.filename, "r") as f: header = xml.fromstring(f.readline()) self.pointer_size = utils.xml_int(header, "pointer-size") self.process_count = utils.xml_int(header, "process-count") x = xml.fromstring(f.read()) self.project = loader.load_project_from_xml(x, "")
def read_header(self, stream): header = xml.fromstring(stream.readline()) self.process_count = utils.xml_int(header, "process-count") self.threads_count = utils.xml_int(header, "threads-count") lines_count = utils.xml_int(header, "description-lines") project_string = "\n".join((stream.readline() for i in xrange(lines_count))) self.project = load_project_from_xml(xml.fromstring(project_string), "")
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 canvastext_from_xml(element, obj): position = (utils.xml_int(element, "x"), utils.xml_int(element, "y")) obj.set_position(position) if element.text is None: obj.text = "" else: obj.text = element.text
def load_area(element, net, loader): id = loader.get_id(element) sx = xml_int(element, "sx") sy = xml_int(element, "sy") px = xml_int(element, "x") py = xml_int(element, "y") area = net.add_area((px, py), (sx, sy), id) if element.find("init") is not None: canvastext_from_xml(element.find("init"), area.init) else: area.init.text = xml_str(element, "init-expr", "")
def load_area(element, net, loader): id = loader.get_id(element) sx = xml_int(element,"sx") sy = xml_int(element,"sy") px = xml_int(element, "x") py = xml_int(element, "y") area = net.add_area((px, py), (sx, sy), id) if element.find("init") is not None: canvastext_from_xml(element.find("init"), area.init) else: area.init.text = xml_str(element,"init-expr", "")
def reports_callback(line): root = xml.fromstring(line) net_id = utils.xml_int(root, "net-id") runinstance = RunInstance(self.project, self.process_count, self.threads_count) for process_id, e in enumerate(root.findall("process")): runinstance.event_spawn(process_id, None, 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") thread_id = utils.xml_int(e, "thread-id") transition_id = utils.xml_int(e, "transition-id") runinstance.transition_fired(process_id, thread_id, 0, transition_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, 0, target_id, size, edge_id) runinstance.reset_last_event_info() self.runinstance = runinstance print("UKLADAM")######################################################################## self.history_instances.append(runinstance) if self.running and utils.xml_bool(root, "quit"): self.running = False self.emit_event("error", "Program finished\n") if callback: callback() self.emit_event("changed", True)
def load_place(element, net, loader): id = loader.get_id(element) place = net.add_place((xml_int(element,"x"), xml_int(element, "y")), id) place.box.name = xml_str(element, "name", "") place.box.radius = xml_int(element,"radius") place.box.size = (xml_int(element,"sx", 0), xml_int(element,"sy", 0)) if element.find("place-type") is not None: canvastext_from_xml(element.find("place-type"), place.place_type) else: place.place_type.text = element.get("place_type", "") # Backward compatability if element.find("init") is not None: canvastext_from_xml(element.find("init"), place.init) else: place.init.text = element.get("init_string", "") # Backward compatability place.set_code(load_code(element)) place.tracing = load_place_tracing(element) interface = element.find("interface") if interface is not None: place.interface.set_position((xml_int(interface, "x"), xml_int(interface, "y"))) place.interface.interface_in = interface.get("in") place.interface.interface_out = interface.get("out") place.interface.update() e = element.find("verif-final-marking") if e is not None: place.final_marking = bool(e.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
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 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_place(element, net, loader): id = loader.get_id(element) place = net.add_place((xml_int(element, "x"), xml_int(element, "y")), id) place.box.name = xml_str(element, "name", "") place.box.radius = xml_int(element, "radius") place.box.size = (xml_int(element, "sx", 0), xml_int(element, "sy", 0)) if element.get("label-x") and element.get("label-y"): label_x = xml_int(element, "label-x") label_y = xml_int(element, "label-y") place.label_placement.set_position((label_x, label_y)) if element.find("place-type") is not None: canvastext_from_xml(element.find("place-type"), place.place_type) else: place.place_type.text = element.get("place_type", "") # Backward compatability if element.find("init") is not None: canvastext_from_xml(element.find("init"), place.init) else: place.init.text = element.get("init_string", "") # Backward compatability place.set_code(load_code(element)) load_place_tracing(element.find("trace"), place) interface = element.find("interface") if interface is not None: place.interface.set_position((xml_int(interface, "x"), xml_int(interface, "y"))) place.interface.interface_in = interface.get("in") place.interface.interface_out = interface.get("out") place.interface.update() e = element.find("verif-final-marking") if e is not None: place.final_marking = bool(e.text)
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 get_id(self, element): id = utils.xml_int(element, "id", 0) self.project.id_counter = max(self.project.id_counter, id) return id
def get_id(self, element): id = utils.xml_int(element, "id", 0) new_id = self.project.new_id() self.idtable[id] = new_id return new_id
def read_header(self, stream): header = xml.fromstring(stream.readline()) self.process_count = utils.xml_int(header, "process-count") lines_count = utils.xml_int(header, "description-lines") project_string = "\n".join((stream.readline() for i in xrange(lines_count))) self.project = load_project_from_xml(xml.fromstring(project_string), "")