Beispiel #1
0
 internal void ChangeNodeShape(ElementMode mode, GrNodeShape shape)
 {
     nodeRealizers[(int)mode] = GetNodeRealizer(
         nodeRealizers[(int)mode].Color,
         nodeRealizers[(int)mode].BorderColor,
         nodeRealizers[(int)mode].TextColor,
         shape);
 }
Beispiel #2
0
 public NodeRealizer(String name, GrColor color, GrColor borderColor, GrColor textColor, GrNodeShape shape)
 {
     Name        = name;
     Color       = color;
     BorderColor = borderColor;
     TextColor   = textColor;
     Shape       = shape;
 }
Beispiel #3
0
 /// <summary>
 /// Gets the VCG string representation of a GrNodeShape object.
 /// </summary>
 /// <param name="shape">The GrNodeShape object.</param>
 /// <returns>The VCG string representation of <c>shape</c>.</returns>
 public static String GetNodeShape(GrNodeShape shape)
 {
     if ((uint)shape >= nodeShapes.Length)
     {
         return(nodeShapes[0]);
     }
     else
     {
         return(nodeShapes[(int)shape]);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Dump a node to the VCG graph.
 /// </summary>
 /// <param name="node">The node to be dumped.</param>
 /// <param name="label">The label to use for the node.</param>
 /// <param name="attributes">An enumerable of attribute strings.</param>
 /// <param name="textColor">The color of the text.</param>
 /// <param name="nodeColor">The color of the node border.</param>
 /// <param name="borderColor">The color of the node.</param>
 /// <param name="nodeShape">The shape of the node.</param>
 ///
 /// TODO: Check whether GetHashCode should really be used or better Graph.GetElementName()
 ///
 public void DumpNode(INode node, String label, IEnumerable <String> attributes, GrColor textColor,
                      GrColor nodeColor, GrColor borderColor, GrNodeShape nodeShape)
 {
     Indent();
     sw.Write("node:{{title:\"n{0}\"", node.GetHashCode());
     if (label != null)
     {
         sw.Write(" label:\"{0}\"", label);
     }
     if (textColor != GrColor.Default)
     {
         sw.Write(" textcolor:" + GetColor(textColor));
     }
     if (nodeColor != GrColor.White)
     {
         sw.Write(" color:" + GetColor(nodeColor));
     }
     if (borderColor != textColor)
     {
         sw.Write(" bordercolor:" + GetColor(borderColor));
     }
     if (nodeShape != GrNodeShape.Default)
     {
         sw.Write(" shape:" + GetNodeShape(nodeShape));
     }
     if (attributes != null)
     {
         sw.Write(" info1: \"");
         bool first = true;
         indent++;
         foreach (String attr in attributes)
         {
             if (first)
             {
                 first = false;
             }
             else
             {
                 sw.WriteLine();
                 Indent();
             }
             sw.Write(EncodeString(attr));
         }
         indent--;
         sw.Write('\"');
     }
     sw.WriteLine('}');
 }
Beispiel #5
0
 public void SetNodeDumpTypeShape(GrElemDumpType type, GrNodeShape shape)
 {
     nodeShapes[(int)type] = shape;
 }
Beispiel #6
0
 public void SetNodeTypeShape(NodeType nodeType, GrNodeShape shape)
 {
     nodeTypeShapes[nodeType] = shape;               // overwrites existing mapping
     NodeTypeAppearanceChanged(nodeType);
 }
Beispiel #7
0
        String GetNodeRealizer(GrColor nodeColor, GrColor borderColor, GrColor textColor, GrNodeShape shape)
        {
            NodeRealizer newNr = new NodeRealizer("nr" + nextNodeRealizerID, nodeColor, borderColor, textColor, shape);

            NodeRealizer nr;

            if (!nodeRealizers.TryGetValue(newNr, out nr))
            {
                ycompStream.Write("addNodeRealizer \"" + newNr.Name + "\" \""
                                  + VCGDumper.GetColor(borderColor) + "\" \""
                                  + VCGDumper.GetColor(nodeColor) + "\" \""
                                  + VCGDumper.GetColor(textColor) + "\" \""
                                  + VCGDumper.GetNodeShape(shape) + "\"\n");
                nodeRealizers.Add(newNr, newNr);
                nextNodeRealizerID++;
                nr = newNr;
            }
            return(nr.Name);
        }
        private NodeRealizer GetNodeRealizer(GrColor nodeColor, GrColor borderColor, GrColor textColor, GrNodeShape shape)
        {
            NodeRealizer newNr = new NodeRealizer("nr" + nextNodeRealizerID, nodeColor, borderColor, textColor, shape);

            NodeRealizer nr;

            if (!registeredNodeRealizers.TryGetValue(newNr, out nr))
            {
                if (ycompStream != null)
                {
                    ycompStream.Write("addNodeRealizer \"" + newNr.Name + "\" \""
                                      + VCGDumper.GetColor(borderColor) + "\" \""
                                      + VCGDumper.GetColor(nodeColor) + "\" \""
                                      + VCGDumper.GetColor(textColor) + "\" \""
                                      + VCGDumper.GetNodeShape(shape) + "\"\n");
                }
                registeredNodeRealizers.Add(newNr, newNr);
                ++nextNodeRealizerID;
                nr = newNr;
            }
            return(nr);
        }
Beispiel #9
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;
                }
            }
        }
Beispiel #10
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);
 }
Beispiel #11
0
        /// <summary>
        /// Dump a node to the DOT language graph.
        /// </summary>
        /// <param name="node">The node to be dumped.</param>
        /// <param name="label">The label to use for the node.</param>
        /// <param name="attributes">An enumerable of attribute strings.</param>
        /// <param name="textColor">The color of the text.</param>
        /// <param name="nodeColor">The color of the node.</param>
        /// <param name="borderColor">The color of the node border.</param>
        /// <param name="nodeShape">The shape of the node.</param>
        /// TODO: Check whether GetHashCode should really be used or better Graph.GetElementName()
        public void DumpNode(INode node, String label, IEnumerable <String> attributes, GrColor textColor,
                             GrColor nodeColor, GrColor borderColor, GrNodeShape nodeShape)
        {
            if (groupNesting.Count > 0)
            {
                // edges coming from or going to subgraph nodes require plain nodes as source or target in the DOT format,
                // so if a characteristic node of a group is enlarged itself to a subgraph, we have to choose another - hopefully plain node - as contained characteristic node
                // otherwise we stick to the first node picked as characteristic node (first node added after group opening)
                if (groupNodesToCharacteristicContainedNode[groupNesting.Peek()] == null ||
                    groupNodesToCharacteristicContainedNode.ContainsKey(groupNodesToCharacteristicContainedNode[groupNesting.Peek()]))
                {
                    groupNodesToCharacteristicContainedNode[groupNesting.Peek()] = node;
                }
            }

            WriteIndentation();
            sw.Write("n{0} [", node.GetHashCode());

            if (label != null)
            {
                sw.Write(" label=\"{0}\"", label);
            }
            if (textColor != GrColor.Default)
            {
                sw.Write(" fontcolor=" + GetColor(textColor));
            }
            if (nodeColor != GrColor.Default)
            {
                sw.Write(" fillcolor=" + GetColor(nodeColor) + " style=filled");
            }
            if (borderColor != textColor)
            {
                sw.Write(" color=" + GetColor(borderColor));
            }
            if (nodeShape != GrNodeShape.Default)
            {
                sw.Write(" shape=" + GetNodeShape(nodeShape));
            }
            if (attributes != null)
            {
                sw.Write(" tooltip=\"");
                bool first = true;
                Indent();
                foreach (String attr in attributes)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sw.WriteLine();
                        WriteIndentation();
                    }
                    sw.Write(EncodeString(attr));
                }
                Unindent();
                sw.Write('\"');
            }

            sw.WriteLine(']');
        }
Beispiel #12
0
 /// <summary>
 /// Dump a node to the VCG graph.
 /// </summary>
 /// <param name="node">The node to be dumped.</param>
 /// <param name="label">The label to use for the node.</param>
 /// <param name="attributes">An enumerable of attribute strings.</param>
 /// <param name="textColor">The color of the text.</param>
 /// <param name="nodeColor">The color of the node border.</param>
 /// <param name="borderColor">The color of the node.</param>
 /// <param name="nodeShape">The shape of the node.</param>
 ///
 /// TODO: Check whether GetHashCode should really be used or better Graph.GetElementName()
 ///
 public void DumpNode(INode node, String label, IEnumerable<String> attributes, GrColor textColor,
     GrColor nodeColor, GrColor borderColor, GrNodeShape nodeShape)
 {
     Indent();
     sw.Write("node:{{title:\"n{0}\"", node.GetHashCode());
     if(label != null) sw.Write(" label:\"{0}\"", label);
     if(textColor != GrColor.Default) sw.Write(" textcolor:" + GetColor(textColor));
     if(nodeColor != GrColor.White) sw.Write(" color:" + GetColor(nodeColor));
     if(borderColor != textColor) sw.Write(" bordercolor:" + GetColor(borderColor));
     if(nodeShape != GrNodeShape.Default) sw.Write(" shape:" + GetNodeShape(nodeShape));
     if(attributes != null)
     {
         sw.Write(" info1: \"");
         bool first = true;
         indent++;
         foreach(String attr in attributes)
         {
             if(first) first = false;
             else
             {
                 sw.WriteLine();
                 Indent();
             }
             sw.Write(EncodeString(attr));
         }
         indent--;
         sw.Write('\"');
     }
     sw.WriteLine('}');
 }
Beispiel #13
0
 /// <summary>
 /// Gets the VCG string representation of a GrNodeShape object.
 /// </summary>
 /// <param name="shape">The GrNodeShape object.</param>
 /// <returns>The VCG string representation of <c>shape</c>.</returns>
 public static String GetNodeShape(GrNodeShape shape)
 {
     if((uint) shape >= nodeShapes.Length) return nodeShapes[0];
     else return nodeShapes[(int) shape];
 }
Beispiel #14
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);
 }