def plotModel(self, graph): xmldoc = xmlparser.parse(self.set.inPathAndFile) if not xmldoc.childNodes[0].nodeValue == ' Automatically generated by ForSyDe ': self.logger.error('File is not ForSyDe-IR! Re-run f2dot with the proper -t command.') os._exit(1) bgColor = utils.computeBackground(utils.splitBy(self.set['COMPOSITE_BACKGROUND_COLOR_COEFFICIENTS'], ','),1) frame = graph.subgraph( \ name="cluster_" + self.set.inFile, \ label = self.rootProcess, \ style = 'filled, rounded', \ color = bgColor, \ fontsize = '13') self.logger.info('Starting the parser on process network "' + self.rootProcess + '"...') self.__parseXmlFile(xmldoc, frame, self.rootProcess, 2)
def __parseXmlFile(self, root, graph, parentId, level): self.logger.debug("Parsing <"+ parentId + ">") graph.add_node('dummy',style='invisible') # add clusters clusterNames = [] if self.set['CLUSTER_SOURCES']: clusterNames.append('sources') if self.set['CLUSTER_SINKS']: clusterNames.append('sinks') if self.set['CLUSTER_INPUT_PORTS']: clusterNames.append('inps') if self.set['CLUSTER_OUTPUT_PORTS']: clusterNames.append('outps') if self.set['CLUSTER_OTHERS']: clusterNames.append('others') clusters = Clusters(self.set,graph,clusterNames) self.logger.debug("Added clusters: "+ str(clusterNames) ) # process network node for pn in root.getElementsByTagName('process_network'): list_of_leaves = [] # child composite processes for composite in pn.getElementsByTagName('composite_process'): compositeInfo = getBasicCompositeInfo(composite, parentId, self.set) # if max level has been reached, transform composite into leaf if (level>= int(self.set['DETAIL_LEVEL'])): list_of_leaves.append(compositeInfo.ID) #build composite process information list_of_ports = getCompositePortList(composite, self.set) processLabel = buildRecord(compositeInfo.label, list_of_ports) if not list_of_ports.in_ports and self.set['CLUSTER_SOURCES']: clusterName = 'sources' elif not list_of_ports.out_ports and self.set['CLUSTER_SINKS']: clusterName = 'sinks' elif self.set['CLUSTER_OTHERS']: clusterName = 'others' else : clusterName = 'parent' # add "black box" node to the appropriate cluster clusters.add_node(clusterName, \ node = compositeInfo.ID, label = processLabel, \ fillcolor = self.set['COMPOSITE_BOX_COLOR']) self.logger.debug( 'Converted composite process ' + compositeInfo.ID + ' to "black box" node' + ' in <' + parentId + '>, clustered in ' + clusterName) continue #else #build composite process information xmlRoot = xmlparser.parse(os.path.join(self.set.inPath, compositeInfo.component_name) + '.xml') bgColor = utils.computeBackground(utils.splitBy(self.set['COMPOSITE_BACKGROUND_COLOR_COEFFICIENTS'], ','),level) if self.set['CLUSTER_OTHERS']: clusterName = 'others' else: clusterName = 'parent' #add composite process subgraph and proceed with #parsing its respective XML file and adding elements #to this subgraph frame = clusters.subgraph( clusterName = clusterName, name = "cluster_" + compositeInfo.ID, \ label = prettyPrintLables(compositeInfo.label), style = 'filled, rounded', color = bgColor) self.logger.debug( 'Found composite process ' + compositeInfo.ID + ' in <' + parentId + '>. Building a subgraph in cluster ' + clusterName) self.__parseXmlFile(xmlRoot, frame, compositeInfo.ID, level + 1) #child leaf processes for leaf in pn.getElementsByTagName('leaf_process'): # build leaf process info leafInfo = getBasicLeafInfo(leaf, parentId, self.set) list_of_leaves.append(leafInfo.ID) list_of_ports = getLeafPortList(leaf, self.set) processLabel = buildRecord(leafInfo.label, list_of_ports) if not list_of_ports.in_ports and self.set['CLUSTER_SOURCES']: clusterName = 'sources' elif not list_of_ports.out_ports and self.set['CLUSTER_SINKS']: clusterName = 'sinks' elif self.set['CLUSTER_OTHERS']: clusterName = 'others' else: clusterName = 'parent' # add leaf process node to the appropriate cluster clusters.add_node(clusterName, \ node = leafInfo.ID, label = processLabel, \ fillcolor = self.set['LEAF_BASE_COLOR']) self.logger.debug( 'Found ' + str(len(list_of_leaves)) + ' leaf processes' + ' in <' + parentId + '>\n\t' + str(list_of_leaves)) #child (composite process) ports for port in utils.getChildrenByTag(pn, 'port'): portInfo = getBasicPortInfo(port, parentId, self.set) # build port info info portType = port.getAttribute('type') if any(vtype in portType for vtype in ["vector","array"]): style = 'bold' penwidth = 2 else: style = '' penwidth = 1 if self.vertical: rotation_angle = '0' port_height = '0.3' port_width = '0.5' compassIn='n' compassOut='s' else: rotation_angle = '90' port_height = '0.3' port_width = '0.5' compassIn='w' compassOut='e' if portInfo.direction == 'in' and self.set['CLUSTER_INPUT_PORTS']: clusterName = 'inps' elif portInfo.direction == 'out' and self.set['CLUSTER_OUTPUT_PORTS']: clusterName = 'outps' elif self.set['CLUSTER_OTHERS']: clusterName = 'others' else: clusterName = 'parent' # add port node to the appropriate cluster clusters.add_node(clusterName, node = portInfo.ID, label = prettyPrintLables(portInfo.label), shape = 'invhouse', width=port_width , height=port_height , style=style, orientation = rotation_angle) # connect the ports to their appropriate end if portInfo.direction == 'in': if portInfo.bound_process in list_of_leaves: src = portInfo.ID dst = portInfo.bound_process src_p = '' + compassOut dst_p = portInfo.bound_port + ':' + compassIn else: src = portInfo.ID dst = portInfo.bound_process + ID_SEP + portInfo.bound_port src_p = '' + compassOut dst_p = '' + compassIn if portInfo.direction == 'out': if portInfo.bound_process in list_of_leaves: src = portInfo.bound_process dst = portInfo.ID src_p = portInfo.bound_port + ':' + compassOut dst_p = '' + compassIn else: src = portInfo.bound_process + ID_SEP + portInfo.bound_port dst = portInfo.ID src_p = '' + compassOut dst_p = '' + compassIn #add edge graph.add_edge(src, dst, tailport=src_p, headport=dst_p, \ style=style, penwidth=penwidth) self.logger.debug( 'Added signal %s:%s->%s:%s',src, src_p, dst, dst_p ) #signal child nodes for signal in pn.getElementsByTagName('signal'): signalInfo = getBasicSignalInfo(signal, parentId, self.set) #build signal info signalType = signal.getAttribute('type') if any(vtype in signalType for vtype in ["vector","array"]): style = 'bold' penwidth = 2 else: style = '' penwidth = 1 if self.vertical: compassIn='n' compassOut='s' else: compassIn='w' compassOut='e' if signalInfo.source in list_of_leaves: # source is a leaf process if signalInfo.target in list_of_leaves: # target is a leaf process src = signalInfo.source dst = signalInfo.target src_p = signalInfo.source_port + ':' + compassOut dst_p = signalInfo.target_port + ':' + compassIn else: # target is a composite process src = signalInfo.source dst = signalInfo.target + ID_SEP + signalInfo.target_port src_p = signalInfo.source_port + ':' + compassOut dst_p = '' + compassIn else: # source is a composite process if signalInfo.target in list_of_leaves: # target is a leaf process src = signalInfo.source + ID_SEP + signalInfo.source_port dst = signalInfo.target src_p = '' + compassOut dst_p = signalInfo.target_port + ':' + compassIn else: # target is a composite process src = signalInfo.source + ID_SEP + signalInfo.source_port dst = signalInfo.target + ID_SEP + signalInfo.target_port src_p = '' + compassOut dst_p = '' + compassIn #add edge graph.add_edge(src, dst, tailport=src_p, headport=dst_p, \ style=style, penwidth=penwidth, label=prettyPrintLables(signalInfo.label)) self.logger.debug( 'Added signal %s:%s->%s:%s',src, src_p, dst, dst_p ) # flush the root node del root