Example #1
0
 public abstract void BuildSubGraph(
     double leftX,
     double upperY,
     double rightX,
     double lowerY,
     ISubGraph originalSubGraph,
     DotSubGraph <int> subGraph);
Example #2
0
        private IList <NodePort> HandleSubgraph(DotGrammarParser.SubgraphContext context)
        {
            var nodeList = new List <NodePort>();

            if (context == null)
            {
                return(nodeList);
            }
            var id = context.id() == null
                ? string.Format(CultureInfo.InvariantCulture, ModelHelper.NewSubGraphFormat,
                                ParsedGraph.GetSubGraphs().Count() + 1)
                : context.id().GetText();

            var graphAttrs = GetGraphAttributes(context.stmt_list().stmt());
            var nodeAttrs  = GetNodeAttributes(context.stmt_list().stmt());
            var edgeAttrs  = GetEdgeAttributes(context.stmt_list().stmt());

            CurrentSubGraph = CurrentSubGraph.CreateSubGraph(id, graphAttrs, nodeAttrs, edgeAttrs);
            foreach (var stmtContext in context.stmt_list().stmt())
            {
                nodeList.AddRange(HandleNode(stmtContext.node_stmt()));
                nodeList.AddRange(HandleEdgeLine(stmtContext.edge_stmt()));
                nodeList.AddRange(HandleSubgraph(stmtContext.subgraph()));
                HandleExitSubgraph(stmtContext.subgraph());
            }
            return(nodeList);
        }
Example #3
0
        public override IGraph VisitGraph(DotGrammarParser.GraphContext context)
        {
            if ((context == null) || (ParsedGraph != null))
            {
                throw new NotImplementedException();
            }
            var id         = context.id()?.GetText() ?? ModelHelper.DefaultGraphId;
            var isDirected = context.DIGRAPH() != null;
            var isStrict   = context.STRICT() != null;

            ParsedGraph     = Graph.CreateGraph(id, isDirected, isStrict);
            CurrentSubGraph = ParsedGraph;

            ParsedGraph.SetAttributes(GetGraphAttributes(context.stmt_list().stmt()));
            ParsedGraph.SetNodeAttributes(GetNodeAttributes(context.stmt_list().stmt()));
            ParsedGraph.SetEdgeAttributes(GetEdgeAttributes(context.stmt_list().stmt()));

            foreach (var stmtContext in context.stmt_list().stmt())
            {
                HandleNode(stmtContext.node_stmt());
                HandleEdgeLine(stmtContext.edge_stmt());
                HandleSubgraph(stmtContext.subgraph());
                HandleExitSubgraph(stmtContext.subgraph());
            }

            return(ParsedGraph);
        }
Example #4
0
 public BorderViewModel(string label, ISubGraph subGraph)
 {
     this.Label      = label;
     this.SubGraph   = subGraph;
     borderColor     = subGraph.borderColor;
     borderThickness = subGraph.borderThickness;
 }
Example #5
0
 private void HandleExitSubgraph(DotGrammarParser.SubgraphContext context)
 {
     if (context == null)
     {
         return;
     }
     CurrentSubGraph = CurrentSubGraph.Parent;
 }
Example #6
0
 private void CloneAndAddAllSubgraphs(IGraph root, ISubGraph currentSubgraph,
                                      IDictionary <ISubGraph, ISubGraph> subgraphDictionary)
 {
     foreach (var subgraph in currentSubgraph.GetSubGraphSubGraphs())
     {
         var clonedSubgraph = new SubGraph(subgraphDictionary[currentSubgraph], subgraph.Id);
         clonedSubgraph.SetAttributes(subgraph.GetAttributes());
         clonedSubgraph.SetNodeAttributes(subgraph.GetNodeAttributes());
         clonedSubgraph.SetEdgeAttributes(subgraph.GetEdgeAttributes());
         var addedSubgraph = root.AddSubGraph(clonedSubgraph);
         subgraphDictionary[subgraph] = addedSubgraph;
         CloneAndAddAllSubgraphs(root, subgraph, subgraphDictionary);
     }
 }
Example #7
0
        /// <inheritdoc />
        public IDictionary <string, string> GetSubGraphAttributes(ISubGraph subGraph)
        {
            if (!(subGraph is IControlFlowRegion <TInstruction> region))
            {
                return(null);
            }

            var(style, label) = GetSubGraphStyle(region);

            return(new Dictionary <string, string>
            {
                ["color"] = style.Color,
                ["style"] = style.Style,
                ["label"] = label
            });
        }
Example #8
0
        private void WriteSubGraph(ISubGraph subGraph, HashSet <INode> scope)
        {
            if (SubGraphAdorner is null)
            {
                WriteHeader("subgraph", null);
                Writer.Indent++;
            }
            else
            {
                WriteHeader("subgraph", SubGraphAdorner.GetSubGraphName(subGraph));
                Writer.Indent++;

                var attributes = SubGraphAdorner.GetSubGraphAttributes(subGraph);
                if (attributes?.Count > 0)
                {
                    string delimeter = IncludeSemicolons
                        ? ";"
                        : string.Empty;

                    WriteAttributes(attributes, delimeter, true);
                    Writer.WriteLine(delimeter);
                    Writer.WriteLine();
                }
            }

            foreach (var nested in subGraph.GetSubGraphs())
            {
                WriteSubGraph(nested, scope);
            }

            foreach (var node in subGraph.GetNodes())
            {
                if (scope.Remove(node))
                {
                    WriteNode(node);
                }
            }

            Writer.Indent--;
            WriteFooter();

            Writer.WriteLine();
        }
Example #9
0
        /// <inheritdoc />
        public string GetSubGraphName(ISubGraph subGraph)
        {
            if (!(subGraph is IControlFlowRegion <TInstruction> region))
            {
                return(null);
            }

            string prefix = DetermineRegionPrefix(region);

            long min = long.MaxValue;
            long max = long.MinValue;

            foreach (var node in region.GetNodes())
            {
                min = Math.Min(min, node.Offset);
                max = Math.Max(max, node.Offset);
            }

            return($"{prefix}_{min:X}_{max:X}");
        }
Example #10
0
        public ISubGraph AddSubGraph(ISubGraph subgraph)
        {
            if (subgraph == null)
            {
                throw new ArgumentNullException(nameof(subgraph));
            }
            if (!Equals(subgraph.Parent) && !SubGraphs.ContainsKey(subgraph.Parent))
            {
                throw new ArgumentException(
                          FormattableString.Invariant($"Parent of SubGraph {subgraph.Id} not within Graph!"));
            }
            if (!SubGraphs.ContainsKey(subgraph))
            {
                SubGraphs[subgraph] = subgraph;
            }
            var addedSubGraph = SubGraphs[subgraph];

            addedSubGraph.SetAttributes(subgraph.GetAttributes());
            return(addedSubGraph);
        }
Example #11
0
 public void RemoveSubGraph(ISubGraph subgraph)
 {
     if ((subgraph != null) && SubGraphs.ContainsKey(subgraph))
     {
         var subgraphs = SubGraphs[subgraph].GetSubGraphSubGraphs().ToList();
         foreach (var sg in subgraphs)
         {
             RemoveSubGraph(sg);
         }
         var edges = SubGraphs[subgraph].GetSubGraphEdges().ToList();
         foreach (var edge in edges)
         {
             RemoveEdge(edge);
         }
         var nodes = SubGraphs[subgraph].GetSubGraphNodes().ToList();
         foreach (var node in nodes)
         {
             RemoveNode(node);
         }
     }
 }
Example #12
0
 public Edge(ISubGraph parentGraph, INode sourceNode, INode endNode, IPort sourcePort = null,
             IPort endPort = null)
     : base(parentGraph, GetNodeIdFromParameters(parentGraph, sourceNode, endNode))
 {
     if (parentGraph == null)
     {
         throw new ArgumentNullException(nameof(parentGraph));
     }
     if (sourceNode == null)
     {
         throw new ArgumentNullException(nameof(sourceNode));
     }
     if (endNode == null)
     {
         throw new ArgumentNullException(nameof(endNode));
     }
     IsDirected = parentGraph.Root.IsDirected;
     if (IsDirected)
     {
         SourceNode = sourceNode;
         EndNode    = endNode;
         SourcePort = sourcePort;
         EndPort    = endPort;
     }
     else if (sourceNode.CompareTo(endNode) > 0)
     {
         SourceNode = endNode;
         EndNode    = sourceNode;
         SourcePort = sourcePort;
         EndPort    = endPort;
     }
     else
     {
         SourceNode = sourceNode;
         EndNode    = endNode;
         SourcePort = sourcePort;
         EndPort    = endPort;
     }
 }
Example #13
0
        public override void BuildSubGraph(
            double leftX,
            double upperY,
            double rightX,
            double lowerY,
            ISubGraph originalSubGraph,
            DotSubGraph <int> subGraph)
        {
            var element = this.elementsFactory.CreateSubGraphBorder(new BorderViewModel(subGraph.Label, originalSubGraph));

            canvas.Children.Add(element);
            element.Width  = rightX - leftX;
            element.Height = upperY - lowerY;
            var orig = new Primitives.Point(leftX, upperY);
            var p    = TransformCoordinates(orig, canvas);

            Canvas.SetLeft(element, p.X);
            Canvas.SetTop(element, p.Y);

            Panel.SetZIndex(element, -1);
            this.verticesElements.Add(originalSubGraph, element);
        }
Example #14
0
        /// <inheritdoc />
        public IDictionary <string, string> GetSubGraphAttributes(ISubGraph subGraph)
        {
            if (!(subGraph is IControlFlowRegion <TInstruction> region))
            {
                return(null);
            }

            var regionStyle = DefaultRegionColor;

            switch (region)
            {
            case BasicControlFlowRegion <TInstruction> basicRegion:
                if (basicRegion.ParentRegion is ExceptionHandlerRegion <TInstruction> parentEh)
                {
                    if (parentEh.ProtectedRegion == basicRegion)
                    {
                        regionStyle = ProtectedRegionColor;
                    }
                    else if (parentEh.HandlerRegions.Contains(basicRegion))
                    {
                        regionStyle = HandlerRegionColor;
                    }
                }

                break;

            case ExceptionHandlerRegion <TInstruction> _:
                regionStyle = ExceptionHandlerStyle;
                break;
            }

            return(new Dictionary <string, string>
            {
                ["color"] = regionStyle.Color,
                ["style"] = regionStyle.Style
            });
        }
Example #15
0
        public override void BuildSubGraph(
            double leftX,
            double upperY,
            double rightX,
            double lowerY,
            ISubGraph originalSubGraph,
            DotSubGraph <int> subGraph)
        {
            var element = this.elementsFactory.CreateSubGraphBorder(new BorderViewModel(subGraph.Label, originalSubGraph));

            canvas.Children.Add(element);
            element.Width  = rightX - leftX;
            element.Height = upperY - lowerY;
            Point orig = new Point(leftX, upperY);
            Point p    = TransformCoordinates(orig, canvas);

            Canvas.SetLeft(element, p.X);
            Canvas.SetTop(element, p.Y);

#if !SILVERLIGHT
            Panel.SetZIndex(element, -1);   // TODO: implement this functionality for silverlight
#endif
            this.verticesElements.Add(originalSubGraph, element);
        }
Example #16
0
 // ReSharper disable once MemberCanBeProtected.Global
 public SubGraph(ISubGraph parentGraph, string id) : base(parentGraph, id)
 {
     NodeAttributes = new AttributeDictionary();
     EdgeAttributes = new AttributeDictionary();
 }
Example #17
0
 public BorderViewModel(string label, ISubGraph subGraph)
 {
     Label    = label;
     SubGraph = subGraph;
 }
Example #18
0
 /// <summary>
 /// Adds the sub graph to the graph.
 /// </summary>
 /// <param name="subGraph">The sub graph to add.</param>
 public void AddSubGraph(ISubGraph subGraph)
 {
     subGraphTracker.AddSubGraph(subGraph);
 }
Example #19
0
 public BorderViewModel(string label, ISubGraph subGraph)
 {
     this.Label    = label;
     this.SubGraph = subGraph;
 }
Example #20
0
 /// <summary>
 /// Adds the cluster to the collection of clusters.
 /// </summary>
 /// <param name="cluster">The cluster to add to the collection.</param>
 public void AddSubGraph(ISubGraph cluster)
 {
     subGraphs.Add(cluster.Name, cluster);
 }
Example #21
0
 public WpfSubGraph(ISubGraph subGraphBehind)
 {
     SubGraphBehind = subGraphBehind;
     UpdatePropertyValues();
 }
Example #22
0
 protected BaseObject(ISubGraph parentGraph, string id)
 {
     Parent     = parentGraph;
     Id         = ModelHelper.ReduceId(id);
     Attributes = new AttributeDictionary();
 }
Example #23
0
 public BorderViewModel(string label, ISubGraph subGraph)
 {
     this.Label = label;
     this.SubGraph = subGraph;
 }
Example #24
0
 public Node(ISubGraph parentGraph, string id) : base(parentGraph, id)
 {
 }