Ejemplo n.º 1
0
    def load_item_from_xml(self, xml_tag: ET.Element,
                           message_types) -> SimulatorItem:
        if xml_tag.tag == "simulator_message":
            item = SimulatorMessage.new_from_xml(
                xml_tag, self.participants, self.project_manager.decodings,
                message_types)
        elif xml_tag.tag == "simulator_label":
            item = SimulatorProtocolLabel.from_xml(
                xml_tag, self.project_manager.field_types_by_caption)
        elif xml_tag.tag == "simulator_trigger_command_action":
            item = SimulatorTriggerCommandAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_sleep_action":
            item = SimulatorSleepAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_counter_action":
            item = SimulatorCounterAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_rule":
            item = SimulatorRule.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_rule_condition":
            item = SimulatorRuleCondition.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_goto_action":
            item = SimulatorGotoAction.from_xml(xml_tag)
        elif xml_tag.tag in ("message", "label", "checksum_label"):
            return None
        else:
            raise ValueError("Unknown simulator item tag: {}".format(
                xml_tag.tag))

        for child_tag in xml_tag:
            child = self.load_item_from_xml(child_tag, message_types)
            if child is not None:
                item.add_child(child)

        return item
Ejemplo n.º 2
0
    def load_item_from_xml(self, xml_tag: ET.Element, message_types) -> SimulatorItem:
        if xml_tag.tag == "simulator_message":
            item = SimulatorMessage.new_from_xml(xml_tag, self.participants, self.project_manager.decodings,
                                                 message_types)
        elif xml_tag.tag == "simulator_label":
            item = SimulatorProtocolLabel.from_xml(xml_tag, self.project_manager.field_types_by_caption)
        elif xml_tag.tag == "simulator_trigger_command_action":
            item = SimulatorTriggerCommandAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_sleep_action":
            item = SimulatorSleepAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_counter_action":
            item = SimulatorCounterAction.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_rule":
            item = SimulatorRule.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_rule_condition":
            item = SimulatorRuleCondition.from_xml(xml_tag)
        elif xml_tag.tag == "simulator_goto_action":
            item = SimulatorGotoAction.from_xml(xml_tag)
        elif xml_tag.tag in ("message", "label", "checksum_label"):
            return None
        else:
            raise ValueError("Unknown simulator item tag: {}".format(xml_tag.tag))

        for child_tag in xml_tag:
            child = self.load_item_from_xml(child_tag, message_types)
            if child is not None:
                item.add_child(child)

        return item
Ejemplo n.º 3
0
    def add_rule_condition(self, rule: SimulatorRule, type: ConditionType):
        rule_condition = SimulatorRuleCondition(type)

        pos = rule.child_count()

        if type is ConditionType.ELSE_IF and rule.has_else_condition:
            pos -= 1

        self.simulator_config.add_items([rule_condition], pos, rule)
        return rule_condition