/// <summary> /// Dumps the given matches. /// </summary> /// <param name="dumper">The graph dumper to be used.</param> /// <param name="dumpInfo">Specifies how the graph shall be dumped.</param> /// <param name="matches">An IMatches object containing the matches.</param> /// <param name="which">Which match to dump, or AllMatches for dumping all matches /// adding connections between them, or OnlyMatches to dump the matches only</param> public static void DumpMatchOnly(IDumper dumper, DumpInfo dumpInfo, IMatches matches, DumpMatchSpecial which, ref Set <INode> matchedNodes, ref Set <INode> multiMatchedNodes, ref Set <IEdge> matchedEdges, ref Set <IEdge> multiMatchedEdges) { matchedNodes = new Set <INode>(); matchedEdges = new Set <IEdge>(); if ((int)which >= 0 && (int)which < matches.Count) { // Show exactly one match IMatch match = matches.GetMatch((int)which); matchedNodes.Add(match.Nodes); matchedEdges.Add(match.Edges); } else { GrColor vnodeColor = dumpInfo.GetNodeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vedgeColor = dumpInfo.GetEdgeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vnodeBorderColor = dumpInfo.GetNodeDumpTypeBorderColor(GrElemDumpType.VirtualMatch); GrColor vnodeTextColor = dumpInfo.GetNodeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrColor vedgeTextColor = dumpInfo.GetEdgeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrNodeShape vnodeShape = dumpInfo.GetNodeDumpTypeShape(GrElemDumpType.VirtualMatch); GrLineStyle vedgeLineStyle = dumpInfo.GetEdgeDumpTypeLineStyle(GrElemDumpType.VirtualMatch); int vedgeThickness = dumpInfo.GetEdgeDumpTypeThickness(GrElemDumpType.VirtualMatch); multiMatchedNodes = new Set <INode>(); multiMatchedEdges = new Set <IEdge>(); // TODO: May edges to nodes be dumped before those nodes exist?? // TODO: Should indices in strings start at 0 or 1? (original: 0) // Dump all matches with virtual nodes int i = 0; foreach (IMatch match in matches) { VirtualNode virtNode = new VirtualNode(-i - 1); dumper.DumpNode(virtNode, String.Format("{0}. match of {1}", i + 1, matches.Producer.Name), null, vnodeTextColor, vnodeColor, vnodeBorderColor, vnodeShape); int j = 1; foreach (INode node in match.Nodes) { dumper.DumpEdge(virtNode, node, String.Format("node {0}", ++j), null, vedgeTextColor, vedgeColor, vedgeLineStyle, vedgeThickness); if (matchedNodes.Contains(node)) { multiMatchedNodes.Add(node); } else { matchedNodes.Add(node); } } // Collect matched edges foreach (IEdge edge in match.Edges) { if (matchedEdges.Contains(edge)) { multiMatchedEdges.Add(edge); } else { matchedEdges.Add(edge); } } ++i; } if (which == DumpMatchSpecial.OnlyMatches) { // Dump the matches only // First dump the matched nodes foreach (INode node in matchedNodes) { GrElemDumpType dumpType; if (multiMatchedNodes.Contains(node)) { dumpType = GrElemDumpType.MultiMatched; } else { dumpType = GrElemDumpType.SingleMatched; } DumpNode(node, dumpInfo.GetNodeDumpTypeTextColor(dumpType), dumpInfo.GetNodeDumpTypeColor(dumpType), dumpInfo.GetNodeDumpTypeBorderColor(dumpType), dumpInfo.GetNodeDumpTypeShape(dumpType), dumper, dumpInfo); } // Now add the matched edges (possibly including "Not matched" nodes) foreach (IEdge edge in matchedEdges) { if (!matchedNodes.Contains(edge.Source)) { DumpNode(edge.Source, dumpInfo.GetNodeTypeTextColor(edge.Source.Type), dumpInfo.GetNodeTypeColor(edge.Source.Type), dumpInfo.GetNodeTypeBorderColor(edge.Source.Type), dumpInfo.GetNodeTypeShape(edge.Source.Type), dumper, dumpInfo); } if (!matchedNodes.Contains(edge.Target)) { DumpNode(edge.Target, dumpInfo.GetNodeTypeTextColor(edge.Target.Type), dumpInfo.GetNodeTypeColor(edge.Target.Type), dumpInfo.GetNodeTypeBorderColor(edge.Target.Type), dumpInfo.GetNodeTypeShape(edge.Target.Type), dumper, dumpInfo); } GrElemDumpType dumpType; if (multiMatchedEdges.Contains(edge)) { dumpType = GrElemDumpType.MultiMatched; } else { dumpType = GrElemDumpType.SingleMatched; } DumpEdge(edge, dumpInfo.GetEdgeDumpTypeTextColor(dumpType), dumpInfo.GetEdgeDumpTypeColor(dumpType), dumpInfo.GetEdgeDumpTypeLineStyle(dumpType), dumpInfo.GetEdgeDumpTypeThickness(dumpType), dumper, dumpInfo); } return; } } }
/// <summary> /// Dumps the given matches. /// </summary> /// <param name="dumper">The graph dumper to be used.</param> /// <param name="dumpInfo">Specifies how the graph shall be dumped.</param> /// <param name="matches">An IMatches object containing the matches.</param> /// <param name="which">Which match to dump, or AllMatches for dumping all matches /// adding connections between them, or OnlyMatches to dump the matches only</param> public static void DumpMatchOnly(IDumper dumper, DumpInfo dumpInfo, IMatches matches, DumpMatchSpecial which, ref Set<INode> matchedNodes, ref Set<INode> multiMatchedNodes, ref Set<IEdge> matchedEdges, ref Set<IEdge> multiMatchedEdges) { matchedNodes = new Set<INode>(); matchedEdges = new Set<IEdge>(); if((int)which >= 0 && (int)which < matches.Count) { // Show exactly one match IMatch match = matches.GetMatch((int)which); matchedNodes.Add(match.Nodes); matchedEdges.Add(match.Edges); } else { GrColor vnodeColor = dumpInfo.GetNodeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vedgeColor = dumpInfo.GetEdgeDumpTypeColor(GrElemDumpType.VirtualMatch); GrColor vnodeBorderColor = dumpInfo.GetNodeDumpTypeBorderColor(GrElemDumpType.VirtualMatch); GrColor vnodeTextColor = dumpInfo.GetNodeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrColor vedgeTextColor = dumpInfo.GetEdgeDumpTypeTextColor(GrElemDumpType.VirtualMatch); GrNodeShape vnodeShape = dumpInfo.GetNodeDumpTypeShape(GrElemDumpType.VirtualMatch); GrLineStyle vedgeLineStyle = dumpInfo.GetEdgeDumpTypeLineStyle(GrElemDumpType.VirtualMatch); int vedgeThickness = dumpInfo.GetEdgeDumpTypeThickness(GrElemDumpType.VirtualMatch); multiMatchedNodes = new Set<INode>(); multiMatchedEdges = new Set<IEdge>(); // TODO: May edges to nodes be dumped before those nodes exist?? // TODO: Should indices in strings start at 0 or 1? (original: 0) // Dump all matches with virtual nodes int i = 0; foreach(IMatch match in matches) { VirtualNode virtNode = new VirtualNode(-i - 1); dumper.DumpNode(virtNode, String.Format("{0}. match of {1}", i + 1, matches.Producer.Name), null, vnodeTextColor, vnodeColor, vnodeBorderColor, vnodeShape); int j = 1; foreach(INode node in match.Nodes) { dumper.DumpEdge(virtNode, node, String.Format("node {0}", j++), null, vedgeTextColor, vedgeColor, vedgeLineStyle, vedgeThickness); if(matchedNodes.Contains(node)) multiMatchedNodes.Add(node); else matchedNodes.Add(node); } // Collect matched edges foreach(IEdge edge in match.Edges) { if(matchedEdges.Contains(edge)) multiMatchedEdges.Add(edge); else matchedEdges.Add(edge); } i++; } if(which == DumpMatchSpecial.OnlyMatches) { // Dump the matches only // First dump the matched nodes foreach(INode node in matchedNodes) { GrElemDumpType dumpType; if(multiMatchedNodes.Contains(node)) dumpType = GrElemDumpType.MultiMatched; else dumpType = GrElemDumpType.SingleMatched; DumpNode(node, dumpInfo.GetNodeDumpTypeTextColor(dumpType), dumpInfo.GetNodeDumpTypeColor(dumpType), dumpInfo.GetNodeDumpTypeBorderColor(dumpType), dumpInfo.GetNodeDumpTypeShape(dumpType), dumper, dumpInfo); } // Now add the matched edges (possibly including "Not matched" nodes) foreach(IEdge edge in matchedEdges) { if(!matchedNodes.Contains(edge.Source)) DumpNode(edge.Source, dumpInfo.GetNodeTypeTextColor(edge.Source.Type), dumpInfo.GetNodeTypeColor(edge.Source.Type), dumpInfo.GetNodeTypeBorderColor(edge.Source.Type), dumpInfo.GetNodeTypeShape(edge.Source.Type), dumper, dumpInfo); if(!matchedNodes.Contains(edge.Target)) DumpNode(edge.Target, dumpInfo.GetNodeTypeTextColor(edge.Target.Type), dumpInfo.GetNodeTypeColor(edge.Target.Type), dumpInfo.GetNodeTypeBorderColor(edge.Target.Type), dumpInfo.GetNodeTypeShape(edge.Target.Type), dumper, dumpInfo); GrElemDumpType dumpType; if(multiMatchedEdges.Contains(edge)) dumpType = GrElemDumpType.MultiMatched; else dumpType = GrElemDumpType.SingleMatched; DumpEdge(edge, dumpInfo.GetEdgeDumpTypeTextColor(dumpType), dumpInfo.GetEdgeDumpTypeColor(dumpType), dumpInfo.GetEdgeDumpTypeLineStyle(dumpType), dumpInfo.GetEdgeDumpTypeThickness(dumpType), dumper, dumpInfo); } return; } } }
private static void DumpNode(INode node, GrColor textColor, GrColor color, GrColor borderColor, GrNodeShape shape, IDumper dumper, DumpInfo dumpInfo) { dumper.DumpNode(node, GetElemLabel(node, dumpInfo), DumpAttributes(node), textColor, color, borderColor, shape); }