def update(self): '''Update the coordinates of the line.''' # Get the two shapes of each node sourceShape = self.source.mapToScene(self.source.shape()) destShape = self.dest.mapToScene(self.dest.shape()) # Compute the closest points between the two shapes pSource = EdgeUtils.closestPointTo(destShape.boundingRect().center(), sourceShape) pDest = EdgeUtils.closestPointTo(sourceShape.boundingRect().center(), destShape) # Draw a line between source and dest self.setLine(pSource.x(), pSource.y(), pDest.x(), pDest.y())
def rebuildTextModel(self, text, pydotG): '''rebuild self.nodes and self.edges from text. Argument(s): text (str): Textual representation of the graph pydotGraph (PydotGraph): pydotGraph from text ''' # Get name of the graph self.graphName = pydotG.get_name() graphs = [] graphs.append(pydotG) # Get all item in graph or subgraph while len(graphs) > 0: G = graphs[0] for node in G.get_nodes(): if node.get_name() not in self.nodes: self.nodes[node.get_name()] = node.get_attributes() for edge in G.get_edges(): idEdge = EdgeUtils.createEdgeId(edge.get_source(), edge.get_destination()) if idEdge not in self.edges: self.edges[idEdge] = { EdgeArgs.sourceId: edge.get_source(), EdgeArgs.destId: edge.get_destination() } for subG in G.get_subgraphs(): graphs.append(subG) graphs.pop(0)
def update(self, source): '''Update the coordinates of the line. Argument(s): source (QPointF): Source point ''' destShape = self.dest.mapToScene(self.dest.shape()) p = EdgeUtils.closestPointTo(source, destShape) self.setLine(source.x(), source.y(), p.x(), p.y())
def addEdge(self, idSourceNode, idDestNode): '''Add an Edge to the graph and notify this. Argument(s): idSourceNode (str): ID of the source node idDestNode (str): ID of the destination node ''' # Add the two nodes self.addNode(idSourceNode) self.addNode(idDestNode) # Only create the edge if it doesn't exist if not self.edgeExists(idSourceNode, idDestNode): edge = Edge(self.nodes[idSourceNode], self.nodes[idDestNode], EdgeUtils.createEdgeId(idSourceNode, idDestNode)) self.edges[edge.id] = edge self.notify(None, edge.getArgs(), UpdateModeView.add)
def findPosItem(self, id): '''return index of start and end of the item's declaration Argument(s): id (str): ID of the item we want to find ''' index = 0 text = self.toPlainText() text = [e + '{' for e in text.split('{') if e != ""] index += len(text[0]) + 1 text.pop(0) text = ''.join(text) text = [e + '}' for e in text.split('}') if e != ""] text.pop(len(text) - 1) stats = re.split(';', ''.join(text)) # Use pydot to get all statements of the graph (in order) for s in stats: # Parse current statement pydotG = graph_from_dot_data("graph {" + s + "}") if pydotG: # Ignore subgraph s2 = s while (re.match("\s*(subgraph)*\s*.*\{", s2) or re.match("\s*\}.*", s2)): if re.match("\s*(subgraph)*\s*.*\{", s2): s2 = re.split('{', s2, 1)[1] pydotG = graph_from_dot_data("graph {" + s2 + "}") elif re.match("\s*\}.*", s2): s2 = re.split('}', s2, 1)[1] pydotG = graph_from_dot_data("graph {" + s2 + "}") for node in pydotG.get_nodes(): if node.get_name() == id: return([index, index + len(s)]) for edge in pydotG.get_edges(): if EdgeUtils.createEdgeId(edge.get_source(), edge.get_destination()) == id: return([index, index + len(s)]) index += len(s) + 1