Beispiel #1
0
    def create(self, the_parsed_topology_xml, generate_list_file=True):
        """
        Create a topology model here.
        """
        # Instance a list of model.Component classes that are all the instanced items from parsed xml.
        x = the_parsed_topology_xml

        componentXMLNameToComponent = {
        }  #Dictionary maps XML names to processes component objects so redundant processing is avoided
        components = []
        for comp_xml_path in x.get_comp_type_file_header_dict():
            for possible in [
                    os.environ.get("BUILD_ROOT"),
                    os.environ.get("FPRIME_CORE_DIR")
            ]:
                file_path = os.path.join(possible, comp_xml_path)
                if os.path.exists(file_path):
                    break
            processedXML = XmlComponentParser.XmlComponentParser(file_path)
            comp_name = processedXML.get_component().get_name()
            componentXMLNameToComponent[comp_name] = processedXML

        for instance in x.get_instances():
            if instance.get_type() not in list(
                    componentXMLNameToComponent.keys()):
                PRINT.info(
                    "Component XML file type {} was not specified in the topology XML. Please specify the path using <import_component_type> tags."
                    .format(instance.get_type()))
            else:
                instance.set_component_object(
                    componentXMLNameToComponent[instance.get_type()])
            components.append(
                Component.Component(instance.get_namespace(),
                                    instance.get_name(),
                                    instance.get_type(),
                                    xml_filename=x.get_xml_filename(),
                                    kind2=instance.get_kind()))

        #print "Assembly name: " + x.get_name(), x.get_base_id(), x.get_base_id_window()
        #for component in components:
        #    print component.get_name(), component.get_base_id(), component.get_base_id_window()

        if self.__generate_new_IDS:
            # Iterate over all the model.Component classes and...
            instance_name_base_id_list = self.__compute_base_ids(
                x.get_base_id(), x.get_base_id_window(), x.get_instances(),
                x.get_xml_filename(), generate_list_file)
        else:
            instance_name_base_id_list = []

        # Iterate over all the model.Component classes and then...
        # Iterate over all the connection sources and assigned output ports to each Component..
        # For each output port you want to assign the connect comment, target component name, target port and type...
        #    (Requires adding to the model.Port class ether members or a memeber called of type TargetConnection)
        for component in components:
            port_obj_list = []
            for connection in x.get_connections():
                if component.get_name() == connection.get_source()[0]:
                    port = Port.Port(connection.get_source()[1],
                                     connection.get_source()[2],
                                     None,
                                     None,
                                     comment=connection.get_comment(),
                                     xml_filename=x.get_xml_filename)
                    port.set_source_num(connection.get_source()[3])
                    port.set_target_comp(connection.get_target()[0])
                    port.set_target_port(connection.get_target()[1])
                    port.set_target_type(connection.get_target()[2])
                    port.set_target_num(connection.get_target()[3])
                    if connection.get_source()[1].startswith("i"):
                        port.set_direction("input")
                    else:
                        port.set_direction("output")
                    if connection.get_target()[1].startswith("i"):
                        port.set_target_direction("input")
                    else:
                        port.set_target_direction("output")

                    port_obj_list.append(port)
            component.set_ports(port_obj_list)

        # Instance a Topology class and give it namespace, comment and list of components.
        the_topology = Topology.Topology(x.get_namespace(), x.get_comment(),
                                         components, x.get_name(),
                                         instance_name_base_id_list,
                                         x.get_prepend_instance_name())
        the_topology.set_instance_header_dict(
            x.get_comp_type_file_header_dict())

        return the_topology
Beispiel #2
0
    def create(self, the_parsed_topology_xml, generate_list_file=True):
        """
        Create a topology model here.
        """
        # Instance a list of model.Component classes that are all the instanced items from parsed xml.
        x = the_parsed_topology_xml

        componentXMLNameToComponent = (
            {}
        )  # Dictionary maps XML names to processes component objects so redundant processing is avoided
        components = []
        for comp_xml_path in x.get_comp_type_file_header_dict():
            try:
                file_path = locate_build_root(comp_xml_path)
            except (BuildRootMissingException,
                    BuildRootCollisionException) as bre:
                stri = "ERROR: Could not find XML file {}. {}".format(
                    comp_xml_path,
                    str(bre),
                )
                raise OSError(stri)
            processedXML = XmlComponentParser.XmlComponentParser(file_path)
            comp_name = processedXML.get_component().get_name()
            componentXMLNameToComponent[comp_name] = processedXML

        for instance in x.get_instances():
            if instance.get_type() not in list(
                    componentXMLNameToComponent.keys()):
                PRINT.info(
                    "Component XML file type {} was not specified in the topology XML. Please specify the path using <import_component_type> tags."
                    .format(instance.get_type()))
            else:
                instance.set_component_object(
                    componentXMLNameToComponent[instance.get_type()])
            components.append(
                Component.Component(
                    instance.get_namespace(),
                    instance.get_name(),
                    instance.get_type(),
                    xml_filename=x.get_xml_filename(),
                    kind2=instance.get_kind(),
                ))

        # print "Assembly name: " + x.get_name(), x.get_base_id(), x.get_base_id_window()
        # for component in components:
        #    print component.get_name(), component.get_base_id(), component.get_base_id_window()

        if self.__generate_new_IDS:
            # Iterate over all the model.Component classes and...
            instance_name_base_id_list = self.__compute_base_ids(
                x.get_base_id(),
                x.get_base_id_window(),
                x.get_instances(),
                x.get_xml_filename(),
                generate_list_file,
            )
        else:
            instance_name_base_id_list = []

        # Iterate over all the model.Component classes and then...
        # Iterate over all the connection sources and assigned output ports to each Component..
        # For each output port you want to assign the connect comment, target component name, target port and type...
        #    (Requires adding to the model.Port class ether members or a member called of type TargetConnection)
        for component in components:
            port_obj_list = []
            for connection in x.get_connections():
                if component.get_name() == connection.get_source()[0]:
                    port = Port.Port(
                        connection.get_source()[1],
                        connection.get_source()[2],
                        None,
                        None,
                        comment=connection.get_comment(),
                        xml_filename=x.get_xml_filename,
                    )
                    port.set_source_num(connection.get_source()[3])
                    port.set_target_comp(connection.get_target()[0])
                    port.set_target_port(connection.get_target()[1])
                    port.set_target_type(connection.get_target()[2])
                    port.set_target_num(connection.get_target()[3])
                    if connection.get_source()[1].startswith("i"):
                        port.set_direction("input")
                    else:
                        port.set_direction("output")
                    if connection.get_target()[1].startswith("i"):
                        port.set_target_direction("input")
                    else:
                        port.set_target_direction("output")

                    port_obj_list.append(port)
            component.set_ports(port_obj_list)

        # Instance a Topology class and give it namespace, comment and list of components.
        the_topology = Topology.Topology(
            x.get_namespace(),
            x.get_comment(),
            components,
            x.get_name(),
            instance_name_base_id_list,
            x.get_prepend_instance_name(),
        )
        the_topology.set_instance_header_dict(
            x.get_comp_type_file_header_dict())

        return the_topology