def create_processed_nodes_lists(self, graph, image_nodes):
        """Creates the initial Processed Image Nodes (PIN) lists

        PIN_ID contains the id numbers of the already processed image nodes.
        PIN_FORMAT contains the corresponding image format of the already processed
        image nodes contained in PIN_ID (with the same indexing)
        """
        PIN_ID = []
        PIN_FORMAT = []
        for item in image_nodes.input_nodes_indexed_names:
            node = self.get_node_with_id(graph, item)
            datatext = parse_common.get_node_datatext(node)
            image_format = self.get_image_format_from_datatext(datatext)
            parse_common.set_text_on_node(self.validation_output_graph, node,
                                          image_format, 'Green', False)
            PIN_ID.append(item)
            PIN_FORMAT.append(image_format)
            PFN = []

        for item in image_nodes.uniform_input_image_indexed_names:
            node = self.get_node_with_id(graph, item)
            datatext = parse_common.get_node_datatext(node)
            image_format = self.get_image_format_from_datatext(datatext)
            parse_common.set_text_on_node(self.validation_output_graph, node,
                                          image_format, 'Green', False)
            PIN_ID.append(item)
            PIN_FORMAT.append(image_format)
            PFN = []

        return [PIN_ID, PIN_FORMAT, PFN]
Example #2
0
    def populate_image_attributes(self, graph, userdata,
                                  validation_output_graph):
        """Populates the image_attributes list.
        All image nodes will get an ImageAttributes instance even if they have no explicitly set attributes. """
        graph_has_errors = False

        for node in graph.getElementsByTagName('node'):
            image_attributes = ImageAttributes(node.attributes["id"].value)
            datatext = parse_common.get_node_datatext(node)
            for attribute in IMAGE_ATTRIBUTES_VALID:
                values = re.findall('\[' + attribute + ' (.+)\]', datatext)
                if len(values) > 1:
                    graph_has_errors = True
                    parse_common.set_text_on_node(
                        validation_output_graph, node,
                        "Image\nattribute\nnot unique", 'Red', False)
                elif len(values) == 1:
                    (valid, err_string) = image_attributes.is_valid_attribute(
                        userdata, attribute, values[0])
                    if valid:
                        image_attributes.attributes[attribute] = values[0]
                    else:
                        graph_has_errors = True
                        parse_common.set_text_on_node(validation_output_graph,
                                                      node, err_string, 'Red',
                                                      False)

            self.image_attributes.append(image_attributes)

        return graph_has_errors
Example #3
0
    def populate_uniform_input_image_names_list(self, graph,
                                                validation_output_graph):
        """Populates the uniform_input_image_names list with the graph uniform input images.

        Ordered in increasing array index for the indeed input images in the graph.
        """
        graph_has_errors = False
        for node in graph.getElementsByTagName('node'):
            datatext = parse_common.get_node_datatext(node)
            if "uniform_input_image" in datatext:
                if "[vx_df_image_e" in datatext and "[uniform_value" in datatext:
                    node_id = node.attributes["id"].value
                    self.uniform_input_image_indexed_names.append(node_id)

                    image_attributes = self.get_image_attributes(node_id)
                    self.uniform_input_image_indexed_values.append(
                        image_attributes.attributes.get(
                            "uniform_value", "VALUE_ERROR"))
                    self.uniform_input_image_indexed_formats.append(
                        image_attributes.attributes.get(
                            "vx_df_image_e", "ERROR"))

                else:
                    graph_has_errors = True
                    parse_common.set_text_on_node(
                        validation_output_graph, node,
                        "Uniform input\nimage\nformat\nmissing", 'Red', False)

        return graph_has_errors
Example #4
0
    def populate_input_nodes_indexed_names_list(self, graph,
                                                validation_output_graph):
        """Populates the input_nodes_indexed_names list with the graph input images.

        Ordered in increasing array index for the indexed input images in the graph.
        """
        graph_has_errors = False
        current_index = 0
        found = 1
        while found:
            found = 0

            for node in graph.getElementsByTagName('node'):
                datatext = parse_common.get_node_datatext(node)
                # Check for input image with array index = current_index
                if "input_image[" + str(current_index) + "]" in datatext:
                    if "[vx_df_image_e" in datatext:
                        self.input_nodes_indexed_names.append(
                            node.attributes["id"].value)
                    else:
                        graph_has_errors = True
                        parse_common.set_text_on_node(
                            validation_output_graph, node,
                            "Input\nimage\nformat\nmissing", 'Red', False)
                    current_index = current_index + 1
                    found = 1

        return graph_has_errors
    def create_compatible_io_lists(self, node, valid_input_formats,
                                   valid_output_formats,
                                   input_image_format_list):
        """Creates the compatible io lists from the input_image_format_list

        It takes the list named valid_input_formats and picks out the compatible format list entries,
        meaning all the format entries that are identical to the input_image_format_list that
        contains the specified input image formats, either from the graph, or from parsing the previous nodes in the graph.
        The valid input formats are put in the list named compatible_input_formats.

        Then it selects the corresponding output format list entries from the list named valid_output_formats,
        and puts them in the list named compatible_output_formats. The indexing between the ntwo output lists is synched.

        There should only be one unique candidate if the graph is correct,
        or no candidate if the graph is inconsistent with respect to image formatting.

        TODO: Need to check order in1/in2? So far no nodes are like that. maybe need to order node info somehow?
        This will get more complicated if there are other node inputs than images.
        """
        dim_check_ok = True
        compatible_input_formats = []
        compatible_output_formats = []
        for idx, item in enumerate(valid_input_formats):
            if self.equal_ignore_order(input_image_format_list, item):
                compatible_input_formats.append(input_image_format_list)
                compatible_output_formats.append(valid_output_formats[idx])

        #Length checks for io image formats. output must have at least two entries, one explicit and one virtual.
        if len(compatible_input_formats) < 1:
            parse_common.set_text_on_node(self.validation_output_graph, node,
                                          "Input image format not valid.",
                                          'Red', True)
            dim_check_ok = False
        elif len(compatible_output_formats) < 2:
            parse_common.set_text_on_node(
                self.validation_output_graph, node,
                "No compatible output image format found.", 'Red', True)
            dim_check_ok = False

        return [
            compatible_input_formats, compatible_output_formats, dim_check_ok
        ]
    def set_unique_output_image_format_list(self, graph, node_info,
                                            output_image_specified_format_list,
                                            virt_format_list,
                                            explicit_format_list, PIN_ID,
                                            PIN_FORMAT):
        """Sets the final unique output image format for each output image node of the node that generated 'node_info'

        The id's of the output images and their corresponding formats are stored
        in the Processed Imaged Nodes ID list (PIN_ID) and
        in the Processed Imaged Nodes format list (PIN_FORMAT) respectively.
        """
        success = True
        for idx, specified_image_format in enumerate(
                output_image_specified_format_list):
            image_node = self.get_node_with_id(
                graph, node_info.output_image_node_ids[idx])
            output_image_format = self.get_valid_output_format(
                idx, virt_format_list, explicit_format_list,
                specified_image_format)
            if output_image_format == "":
                parse_common.set_text_on_node(
                    self.validation_output_graph, image_node,
                    "Output image\nformat\n" + specified_image_format +
                    "\nerror.", 'Red', False)
                success = False
            else:
                parse_common.set_text_on_node(self.validation_output_graph,
                                              image_node, output_image_format,
                                              'Green', False)

            #Add format and image node id to processed lists.(indexing is the same as for the node_info still)
            if node_info.output_image_node_ids[idx] not in PIN_ID:
                PIN_ID.append(node_info.output_image_node_ids[idx])
                PIN_FORMAT.append(output_image_format)
            else:
                raise NameError('Duplicate ids in PIN_ID list.')

        return success
Example #7
0
    def populate_userdata(self, graph, validation_output_graph):
        """ Populates the userdata attributes dictionary """
        graph_has_errors = False

        userdata_node = None
        datatext = ""
        for node in graph.getElementsByTagName('node'):
            for nodeAppearance in node.getElementsByTagName('y:GenericNode'):
                if nodeAppearance.attributes[
                        "configuration"].value == "com.yworks.flowchart.userMessage":
                    if self.has_userdata:
                        print "ERROR: Found multiple userdata nodes, only one is allowed"
                        graph_has_errors = True
                        parse_common.set_text_on_node(
                            validation_output_graph, node,
                            "Userdata\nis not\nunique", 'Red', True)
                    else:
                        self.has_userdata = True
                        userdata_node = node
                        datatext = parse_common.get_node_datatext(node)

        if self.debug_mode:
            print "userdata node contains data:\n", datatext, "\n"

        for attribute in datatext.splitlines():
            try:
                data_type, attribute_name = attribute.lstrip('[').rstrip(
                    ']').split()
            except ValueError:
                print "ERROR: userdata node data is not formatted correctly at: {}".format(
                    attribute)
                graph_has_errors = True
                parse_common.set_text_on_node(
                    validation_output_graph, userdata_node,
                    "Userdata\nnot\nformatted\ncorrectly", 'Red', True)
            else:
                if attribute_name in self.attributes:
                    print "ERROR: userdata cannot contain several entries with same name"
                    graph_has_errors = True
                    parse_common.set_text_on_node(
                        validation_output_graph, userdata_node,
                        "Userdata\nhas\nnon-unique\nentries", 'Red', True)
                else:  # Add attribute to userdata
                    # TODO: Should add check that attribute_name is valid C-variable name
                    self.attributes[attribute_name] = data_type

        self.attributes_populated = True
        return graph_has_errors