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]
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
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
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 populate_virtual_nodes_indexed_names_list(self, graph): """Populates the virtual_nodes_indexed_names list with the internal graph images.""" graph_has_errors = False for node in graph.getElementsByTagName('node'): for nodeAppearance in node.getElementsByTagName('y:GenericNode'): if nodeAppearance.attributes[ "configuration"].value == "com.yworks.flowchart.process": datatext = parse_common.get_node_datatext(node) if not "input_image[" in datatext and not "output_image[" in datatext: self.virtual_nodes_indexed_names.append( node.attributes["id"].value) return graph_has_errors
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
def get_image_format_from_image_node_id(self, graph, image_nodes, node_id): """Returns the image format of the node specified by 'node_id'.""" node = self.get_node_with_id(graph, node_id) datatext = parse_common.get_node_datatext(node) return self.get_image_format_from_datatext(datatext)