Esempio n. 1
0
        /// <summary>
        /// Dumps one or more matches with a given graph dumper.
        /// </summary>
        /// <param name="graph">The graph to be dumped.</param>
        /// <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 DumpMatch(IGraph graph, IDumper dumper, DumpInfo dumpInfo, IMatches matches, DumpMatchSpecial which)
        {
            Set <INode> matchedNodes      = null;
            Set <INode> multiMatchedNodes = null;
            Set <IEdge> matchedEdges      = null;
            Set <IEdge> multiMatchedEdges = null;

            if (matches != null)
            {
                DumpMatchOnly(dumper, dumpInfo, matches, which,
                              ref matchedNodes, ref multiMatchedNodes, ref matchedEdges, ref multiMatchedEdges);
            }

            // Dump the graph, but color the matches if any exist

            DumpContext dc = new DumpContext(dumper, dumpInfo,
                                             matchedNodes, multiMatchedNodes, matchedEdges, multiMatchedEdges);

            foreach (NodeType nodeType in graph.Model.NodeModel.Types)
            {
                if (dumpInfo.IsExcludedNodeType(nodeType))
                {
                    continue;
                }
                dc.Nodes.Add(graph.GetExactNodes(nodeType));
            }

            dc.InitialNodes = new Set <INode>(dc.Nodes);
            Set <INode> nodes = new Set <INode>(dc.Nodes);

            DumpGroups(graph, nodes, dc);
        }
Esempio n. 2
0
 public DumpContext(IDumper dumper, DumpInfo dumpInfo, Set <INode> matchedNodes, Set <INode> multiMatchedNodes,
                    Set <IEdge> matchedEdges, Set <IEdge> multiMatchedEdges)
 {
     Dumper            = dumper;
     DumpInfo          = dumpInfo;
     MatchedNodes      = matchedNodes;
     MultiMatchedNodes = multiMatchedNodes;
     MatchedEdges      = matchedEdges;
     MultiMatchedEdges = multiMatchedEdges;
 }
Esempio n. 3
0
        private static String GetElemLabel(IGraphElement elem, DumpInfo dumpInfo)
        {
            List <InfoTag> infoTagTypes = dumpInfo.GetTypeInfoTags(elem.Type);
            String         label        = dumpInfo.GetElemTypeLabel(elem.Type);
            bool           first        = true;

            if (label == null)
            {
                label = dumpInfo.GetElementName(elem) + ":" + elem.Type.Name;
                first = false;
            }

            if (infoTagTypes != null)
            {
                foreach (InfoTag infoTag in infoTagTypes)
                {
                    object attr = elem.GetAttribute(infoTag.AttributeType.Name);
                    if (attr == null)
                    {
                        continue;
                    }

                    if (!first)
                    {
                        label += "\n";
                    }
                    else
                    {
                        first = false;
                    }

                    if (infoTag.ShortInfoTag)
                    {
                        label += attr.ToString();
                    }
                    else
                    {
                        label += infoTag.AttributeType.Name + " = " + attr.ToString();
                    }
                }
            }

            return(label);
        }
Esempio n. 4
0
 /// <summary>
 /// Dumps the graph with a given graph dumper.
 /// </summary>
 /// <param name="graph">The graph to be dumped.</param>
 /// <param name="dumper">The graph dumper to be used.</param>
 /// <param name="dumpInfo">Specifies how the graph shall be dumped.</param>
 public static void Dump(IGraph graph, IDumper dumper, DumpInfo dumpInfo)
 {
     DumpMatch(graph, dumper, dumpInfo, null, 0);
 }
Esempio n. 5
0
        /// <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;
                }
            }
        }
Esempio n. 6
0
 private static void DumpEdge(IEdge edge, GrColor textColor, GrColor color, GrLineStyle style,
                              int thickness, IDumper dumper, DumpInfo dumpInfo)
 {
     dumper.DumpEdge(edge.Source, edge.Target, GetElemLabel(edge, dumpInfo), DumpAttributes(edge),
                     textColor, color, style, thickness);
 }
Esempio n. 7
0
 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);
 }