private void createDOTRecurse(DependencyNode node, GraphNode grNodeParent, ref Dictionary <string, GraphNode> graphNodeTable, ref List <GraphEdge> graphEdgeList) { GraphNode grNode; bool nodeFound = graphNodeTable.TryGetValue(node.filename, out grNode); if (nodeFound) { // Since the node is found just add an edge // // Create edge GraphEdge grEdge = new GraphEdge(); grEdge.parentNode = grNodeParent; grEdge.childNode = grNode; grEdge.bFileExists = grNode.bFileExists; graphEdgeList.Add(grEdge); } else { // The node is not found, so we must create a new node, // add the edge and recurse into the node. // // Skip dep nodes since they add confusion. if (String.Compare(Path.GetExtension(node.mFileInfo.mFilename), ".dep", true) == 0) { // Recurse with children int numChildren = node.getNumChildren(); for (int i = 0; i < numChildren; i++) { DependencyNode childNode = node.getChild(i); createDOTRecurse(childNode, grNodeParent, ref graphNodeTable, ref graphEdgeList); } } else { // Create new GraphNode grNode = new GraphNode(); grNode.label = node.filename; grNode.name = "node" + graphNodeTable.Count; grNode.bFileExists = node.mFileInfo.bExists; graphNodeTable.Add(node.filename, grNode); // Create edge GraphEdge grEdge = new GraphEdge(); grEdge.parentNode = grNodeParent; grEdge.childNode = grNode; grEdge.bFileExists = node.mFileInfo.bExists; graphEdgeList.Add(grEdge); // Recurse with children int numChildren = node.getNumChildren(); for (int i = 0; i < numChildren; i++) { DependencyNode childNode = node.getChild(i); createDOTRecurse(childNode, grNode, ref graphNodeTable, ref graphEdgeList); } } } }
private void writeGraphDOT(string outputFilenameDOT) { Dictionary <string, GraphNode> graphNodeTable = new Dictionary <string, GraphNode>(); List <GraphEdge> graphEdgeList = new List <GraphEdge>(); int numChildren = mRootNode.getNumChildren(); for (int i = 0; i < numChildren; i++) { DependencyNode childNode = mRootNode.getChild(i); // Recurse child createDOTRecurse(childNode, null, ref graphNodeTable, ref graphEdgeList); } // Write out file using (StreamWriter sw = File.CreateText(outputFilenameDOT)) { sw.WriteLine("digraph g {"); sw.WriteLine("\trankdir = LR;"); sw.WriteLine("\tranksep = \"8.0\""); sw.WriteLine("\tnodesep = \"0.05\""); // write nodes list and their labels // all texture nodes in the same rank sw.WriteLine("\t{"); sw.WriteLine("\t\trank = same;"); foreach (KeyValuePair <string, GraphNode> nodePair in graphNodeTable) { switch (Path.GetExtension(nodePair.Value.label)) { case ".ddx": { string labelDoubleSlash = nodePair.Value.label.Replace("\\", "\\\\"); string shape = ",shape=box"; string color = nodePair.Value.bFileExists ? "" : ",color=red"; string style = nodePair.Value.bFileExists ? "" : ",style=filled"; sw.WriteLine("\t\t{0} [label=\"{1}\"{2}{3}{4}];", nodePair.Value.name, labelDoubleSlash, shape, color, style); } break; } } sw.WriteLine("\t}"); foreach (KeyValuePair <string, GraphNode> nodePair in graphNodeTable) { string shape = ""; switch (Path.GetExtension(nodePair.Value.label)) { case ".ddx": continue; case ".scn": case ".sc2": case ".sc3": { shape = ",shape=doublecircle"; } break; default: { } break; } string labelDoubleSlash = nodePair.Value.label.Replace("\\", "\\\\"); string color = nodePair.Value.bFileExists ? "" : ",color=red"; string style = nodePair.Value.bFileExists ? "" : ",style=filled"; sw.WriteLine("\t{0} [label=\"{1}\"{2}{3}{4}];", nodePair.Value.name, labelDoubleSlash, color, style, shape); } // write edges foreach (GraphEdge edge in graphEdgeList) { if (edge.parentNode == null) { continue; } string style = edge.bFileExists ? "style=solid" : "style=dashed"; string color = edge.bFileExists ? "" : ",color=red"; sw.WriteLine("\t{0} -> {1} [{2}{3}];", edge.parentNode.name, edge.childNode.name, style, color); } sw.WriteLine("}"); sw.Close(); } }