internal static List <ObjectWithBox> TessellateCurve(DEdge dedge, double radiusForUnderlyingPolylineCorners)
        {
            DrawingEdge          edge      = dedge.DrawingEdge;
            ICurve               bc        = edge.EdgeCurve;
            double               lineWidth = edge.Attr.LineWidth;
            List <ObjectWithBox> ret       = new List <ObjectWithBox>();
            int  n = 1;
            bool done;

            do
            {
                double d = (bc.ParEnd - bc.ParStart) / (double)n;
                done = true;
                if (n <= 64)//don't break a segment into more than 64 parts
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (!WithinEpsilon(bc, d * i, d * (i + 1)))
                        {
                            n   *= 2;
                            done = false;
                            break;
                        }
                    }
                }
            }while (!done);

            double del = (bc.ParEnd - bc.ParStart) / n;

            for (int j = 0; j < n; j++)
            {
                Line line = new Line(dedge, bc[del * (double)j], bc[del * (double)(j + 1)], lineWidth);
                ret.Add(line);
            }

            //if (dedge.Label != null)
            //    pf.Add(new LabelGeometry(dedge.Label, edge.Label.Left,
            //                              edge.Label.Bottom, new MsaglPoint(edge.Label.Size.Width, edge.Label.Size.Height)));


            if (edge.Attr.ArrowAtTarget)
            {
                ret.Add(new Line(dedge, (MsaglPoint)edge.EdgeCurve.End, edge.ArrowAtTargetPosition, edge.Attr.LineWidth));
            }



            if (edge.Attr.ArrowAtSource)
            {
                ret.Add(
                    new Line(dedge, edge.EdgeCurve.Start, edge.ArrowAtSourcePosition, edge.Attr.LineWidth));
            }

            if (radiusForUnderlyingPolylineCorners > 0)
            {
                AddUnderlyingPolylineTessellation(ret, dedge, radiusForUnderlyingPolylineCorners);
            }

            return(ret);
        }
Esempio n. 2
0
 private static void ArrowAtTheEnd(Graphics g, DrawingEdge edge, System.Drawing.Color edgeColor, Pen myPen)
 {
     if (edge.Attr.GeometryEdge != null && edge.Attr.ArrowAtTarget)
     {
         DrawArrowAtTheEndWithControlPoints(g, edge, edgeColor, myPen);
     }
 }
 private static void ArrowAtTheEnd(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.GeometryEdge != null && edge.Attr.ArrowAtTarget)
     {
         DrawArrowAtTheEndWithControlPoints(pg, edge, fill);
     }
 }
Esempio n. 4
0
 internal void SetDrawingEdge(DrawingEdge edge)
 {
     drawingEdge          = edge;
     drawingEdge.Attr     = CreateEdgeAttr();
     drawingEdge.UserData = this;
     RenameEdge();
 }
        public VEdge(Edge edge, FrameworkElement labelFrameworkElement) {
            Edge = edge;
            CurvePath = new Path {
                Data = GetICurveWpfGeometry(edge.GeometryEdge.Curve),
                Tag = this
            };

            EdgeAttrClone = edge.Attr.Clone();

            if (edge.Attr.ArrowAtSource)
                SourceArrowHeadPath = new Path {
                    Data = DefiningSourceArrowHead(),
                    Tag = this
                };
            if (edge.Attr.ArrowAtTarget)
                TargetArrowHeadPath = new Path {
                    Data = DefiningTargetArrowHead(Edge.GeometryEdge.EdgeGeometry, PathStrokeThickness),
                    Tag = this
                };

            SetPathStroke();

            if (labelFrameworkElement != null) {
                LabelFrameworkElement = labelFrameworkElement;
                Common.PositionFrameworkElement(LabelFrameworkElement, edge.Label.Center, 1);
            }
            edge.Attr.VisualsChanged += (a, b) => Invalidate();

            edge.IsVisibleChanged += obj => {
                foreach (var frameworkElement in FrameworkElements) {
                    frameworkElement.Visibility = edge.IsVisible ? Visibility.Visible : Visibility.Hidden;
                }
            };
        }
 private static void ArrowAtTheBeginning(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.GeometryEdge != null && edge.Attr.ArrowAtSource)
     {
         DrawArrowAtTheBeginningWithControlPoints(pg, edge, fill);
     }
 }
Esempio n. 7
0
 private void BypassTree(ParsingTreeNode node, ParsingTreeNode parentNode)
 {
     Microsoft.Msagl.Drawing.Edge graphEdge = null;
     if (parentNode != null)
     {
         graphEdge = Graph.AddEdge(parentNode.GetHashCode().ToString(), node.GetHashCode().ToString());
         graphEdge.SourceNode.Attr.Id = parentNode.Value;
         graphEdge.TargetNode.Attr.Id = node.Value;
     }
     else
     {
         var graphNode = Graph.AddNode(node.GetHashCode().ToString());
         graphNode.Attr.Id        = node.Value;
         graphNode.Attr.FillColor = Color.MediumSeaGreen;
     }
     if (node.Childrens.Count == 0)
     {
         if (graphEdge != null)
         {
             graphEdge.TargetNode.Attr.FillColor = new Color(0xFF, 0xFF, 0x99);                     // draw leafs;
         }
     }
     else
     {
         foreach (var child in node.Childrens)
         {
             BypassTree(child, node);
         }
     }
 }
Esempio n. 8
0
        void LoadData(string DatFile)
        {
            uniqD = new Dictionary <long, long>();

            using (var fs = File.OpenRead(DatFile))
            {
                using (var br = new BinaryReader(fs))
                {
                    graphViewer = new GraphViewer();
                    graphViewer.LayoutEditingEnabled = false;
                    graphViewer.BindToPanel(gvPanel);

                    var          dgraph = new Drawing.Graph();
                    Drawing.Edge edg    = null;

                    while (fs.Position < fs.Length - 128)
                    {
                        var tid      = br.ReadInt32();
                        var flags    = br.ReadInt32();
                        var rip      = br.ReadInt64();
                        var rsp      = br.ReadInt64();
                        var from_rip = br.ReadInt64();

                        if (!uniqD.ContainsKey(from_rip))
                        {
                            uniqD.Add(from_rip, rip);
                            edg = dgraph.AddEdge(from_rip.ToString("X"), rip.ToString("X"), rip.ToString("X"));
                        }
                    }

                    graphViewer.Graph = dgraph;
                }
            }
        }
Esempio n. 9
0
        private void ModulesGraph()
        {
            Graph g = new Graph();

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select name from modules";

                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    g.AddNode(DataReader["name"].ToString());
                }
            }

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select * from moddeps";
                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
                    e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
                    //e.Attr.Color = Microsoft.Msagl.Drawing.Color.Yellow;
                    e.LabelText = DataReader["rate"].ToString();
                }
            }
            gViewer.Graph = g;
        }
Esempio n. 10
0
        /// <summary>
        /// Function to Add and Edge to the Graph (Only if it doesn't already Exist)
        /// Assigns to user Data and Attributes to Target
        /// </summary>
        /// <param name="sourceID"></param>
        /// <param name="targetID"></param>
        /// <param name="nodeColor"></param>
        /// <param name="userData"></param>
        private Boolean AE(Graph g, List <DrawingEdge> edgeList, String sourceID, String targetID, DrawingColor nodeColor, object userData)
        {                         //Search for Edge in allEdgesMaster before adding it.
            bool isUnique = true; // Add by default

            foreach (DrawingEdge item in edgeList)
            {
                if (item.Source == sourceID && item.Target == targetID)
                {
                    isUnique = false;
                    break;
                }
            }
            if (isUnique)
            {
                //Create an edge
                DrawingEdge edge = new DrawingEdge(sourceID, null, targetID);
                edgeList.Add(edge);                                   // Add edge to list for keeping Unique Edges

                g.AddEdge(sourceID, targetID).Attr.Color = nodeColor; //Add Edge

                //FN(g, sourceID).Attr.FillColor = nodeColor;
                //FN(g, sourceID).UserData = userData;


                FN(g, targetID).Attr.FillColor = nodeColor;
                FN(g, targetID).UserData       = userData;
            }
            return(isUnique);
        }
Esempio n. 11
0
        internal DEdge(DNode source, DNode target, DrawingEdge drawingEdgeParam, ConnectionToGraph connection,
                       GViewer gviewer) : base(gviewer)
        {
            DrawingEdge = drawingEdgeParam;
            Source      = source;
            Target      = target;

            if (connection == ConnectionToGraph.Connected)
            {
                if (source == target)
                {
                    source.AddSelfEdge(this);
                }
                else
                {
                    source.AddOutEdge(this);
                    target.AddInEdge(this);
                }
            }

            if (drawingEdgeParam.Label != null)
            {
                Label = new DLabel(this, drawingEdge.Label, gviewer);
            }
        }
Esempio n. 12
0
 private void UpdateMsaglEdge(MsaglGraphs.Edge msaglEdge, SgvlGraphs.Edge sgvlEdge)
 {
     // Метка ребра
     UpdateMsaglEdgeLabel(msaglEdge, sgvlEdge);
     // Цвет ребра
     UpdateMsaglEdgeColor(msaglEdge, sgvlEdge);
 }
Esempio n. 13
0
        static internal void DrawEdge(Graphics graphics, DEdge dEdge, bool drawLabel)
        {
            DrawingEdge drawingEdge = dEdge.DrawingEdge;

            if (drawingEdge.Attr.GeometryEdge == null)
            {
                return;
            }

            if (dEdge.GraphicsPath == null)
            {
                Draw.CreateGraphicsPath(dEdge);
            }

            EdgeAttr attr = drawingEdge.Attr;

            using (Pen myPen = new Pen(dEdge.Color, attr.LineWidth)) {
                foreach (Style style in attr.Styles)
                {
                    Draw.AddStyleForPen(dEdge, myPen, style);
                }

                try {
                    graphics.DrawPath(myPen, dEdge.GraphicsPath);
                } catch {
                    //  sometimes on Vista it's just throws an out of memory exception without any obvious reason
                }
                Draw.DrawEdgeArrows(graphics, drawingEdge, dEdge.Color, myPen);
            }
            if (drawLabel)
            {
                Draw.DrawLabel(graphics, dEdge.Label);
            }
        }
Esempio n. 14
0
        private KosmographViewerEdge CreateEdge(DrawingEdge edge, LgLayoutSettings lgSettings)
        {
            lock (this.syncRoot)
            {
                if (drawingObjectsToIViewerObjects.ContainsKey(edge))
                {
                    return((KosmographViewerEdge)drawingObjectsToIViewerObjects[edge]);
                }
                if (lgSettings != null)
                {
                    return(CreateEdgeForLgCase(lgSettings, edge));
                }

                FrameworkElement labelTextBox;
                drawingObjectsToFrameworkElements.TryGetValue(edge, out labelTextBox);
                var vEdge = new KosmographViewerEdge(edge, labelTextBox);

                var zIndex = ZIndexOfEdge(edge);
                drawingObjectsToIViewerObjects[edge] = vEdge;

                if (edge.Label != null)
                {
                    SetVEdgeLabel(edge, vEdge, zIndex);
                }

                Panel.SetZIndex(vEdge.EdgePath, zIndex);
                GraphCanvas.Children.Add(vEdge.EdgePath);
                SetVEdgeArrowheads(vEdge, zIndex);

                return(vEdge);
            }
        }
Esempio n. 15
0
        internal static DGraph CreateDGraphAndGeometryInfo(DrawingGraph drawingGraph, GeometryGraph gleeGraph)
        {
            DGraph ret = new DGraph(drawingGraph);

            //create dnodes and glee node boundary curves
            foreach (GeometryNode geomNode in gleeGraph.NodeMap.Values)
            {
                DrawingNode drawingNode = geomNode.UserData as DrawingNode;
                CreateDNodeAndSetNodeBoundaryCurve(drawingGraph, ret, geomNode, drawingNode);
            }

            foreach (GeometryEdge gleeEdge in gleeGraph.Edges)
            {
                DEdge dEdge = new DEdge(ret.GetNode(gleeEdge.Source), ret.GetNode(gleeEdge.Target), gleeEdge.UserData as DrawingEdge, Connection.Connected);
                ret.AddEdge(dEdge);
                DrawingEdge drawingEdge             = dEdge.Edge;
                Microsoft.Msagl.Drawing.Label label = drawingEdge.Label;

                if (label != null)
                {
                    double width, height;
                    CreateDLabel(dEdge, label, out width, out height);
                }
            }

            return(ret);
        }
        internal DEdge(DNode source, DNode target, DrawingEdge drawingEdgeParam, ConnectionToGraph connection)
            : base(source.ParentObject)
        {
            this.DrawingEdge = drawingEdgeParam;
            this.Source      = source;
            this.Target      = target;

            if (connection == ConnectionToGraph.Connected)
            {
                if (source == target)
                {
                    source.AddSelfEdge(this);
                }
                else
                {
                    source.AddOutEdge(this);
                    target.AddInEdge(this);
                }
            }

            if (drawingEdgeParam.Label != null)
            {
                this.Label = new DTextLabel(this, DrawingEdge.Label);
            }
        }
        public GraphmapsEdge(Edge edge, FrameworkElement labelFrameworkElement) {
            Edge = edge;
            CurvePath = new Path {
                Data = GetICurveWpfGeometry(edge.GeometryEdge.Curve),
                Tag = this
            };

            EdgeAttrClone = edge.Attr.Clone();

            if (edge.Attr.ArrowAtSource)
                SourceArrowHeadPath = new Path {
                    Data = DefiningSourceArrowHead(),
                    Tag = this
                };
            if (edge.Attr.ArrowAtTarget)
                TargetArrowHeadPath = new Path {
                    Data = DefiningTargetArrowHead(Edge.GeometryEdge.EdgeGeometry, PathStrokeThickness),
                    Tag = this
                };

            SetPathStroke();

            if (labelFrameworkElement != null) {
                LabelFrameworkElement = labelFrameworkElement;
                Common.PositionFrameworkElement(LabelFrameworkElement, edge.Label.Center, 1);
            }
            edge.Attr.VisualsChanged += (a, b) => Invalidate();
            
        }
Esempio n. 18
0
        public IViewerEdge RouteEdge(DrawingEdge drawingEdge)
        {
            var geomEdge  = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
            var geomGraph = drawingGraph.GeometryGraph;

            LayoutHelpers.RouteAndLabelEdges(geomGraph, drawingGraph.LayoutAlgorithmSettings, new[] { geomEdge });
            return(CreateEdge(drawingEdge, drawingGraph.LayoutAlgorithmSettings as LgLayoutSettings));
        }
Esempio n. 19
0
        internal void CreateEdge()
        {
            if (Model == null)
            {
                return;
            }

            if (this.Source.Label == null || this.Target.Label == null)
            {
                return;
            }

            Dictionary <string, Entity> entitiesLookup = Model.DisplayedSubmodel.Entities.ToDictionary(x => x.Label, y => y);

            if ((entitiesLookup.ContainsKey(Source.Label) || entitiesLookup.ContainsKey(Target.Label)) == false)
            {
                return;
            }

            if (drawingEdge != null)
            {
                DeleteDrawingEdge(false);
            }

            if (Model.Graph != null)
            {
                drawingEdge       = Model.Graph.AddEdge(Source.Label, Target.Label);
                drawingEdge.Attr  = CreateEdgeAttr();
                drawingEdge.Label = CreateLabel(drawingEdge, Model.ShowRelationshipLabels ? Type : "");

                LayoutEdge coreEdge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
                CreateEdgeCurve(drawingEdge, coreEdge);

                Model.GeometryGraph.Edges.Add(coreEdge);
                drawingEdge.GeometryEdge = coreEdge;
                drawingEdge.UserData     = this;
            }
            else
            {
                if (IsAddedOnViewGraph)
                {
                    IsAddedOnViewGraph = false;
                    return;
                }

                DrawingNode source = Model.GraphEditor.Graph.FindNode(Source.Label);
                DrawingNode target = Model.GraphEditor.Graph.FindNode(Target.Label);

                if (target != null)
                {
                    drawingEdge = Model.GraphEditor.Viewer.AddEdge(source, target, false);

                    drawingEdge.Attr     = CreateEdgeAttr();
                    drawingEdge.UserData = this;
                }
                RenameEdge();
            }
        }
Esempio n. 20
0
        private void btnRender_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(SymFile) || string.IsNullOrWhiteSpace(TraceFile))
            {
                return;
            }

            string source, target;

            graphViewer = new GraphViewer();
            graphViewer.LayoutEditingEnabled = false;
            graphViewer.BindToPanel(gvPanel);
            Drawing.Edge edg              = null;
            var          dgraph           = new Drawing.Graph();
            var          sugiyamaSettings = (SugiyamaLayoutSettings)dgraph.LayoutAlgorithmSettings;

            sugiyamaSettings.NodeSeparation *= 2;
            sugiyamaSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear;

            var tot = new totts(SymFile, TraceFile);

            var blocks = tot.GetBlocks();

            foreach (var block in blocks)
            {
                if (block == null)
                {
                    break;
                }
                source = block.StepEvent.FROM_RIP.ToString("X");
                target = block.StepEvent.RIP.ToString("X");

                //var edge = new Drawing.Edge(source, "", target);
                edg = dgraph.AddEdge(source, target);
            }
            foreach (var block in blocks)
            {
                var blockLabel = new StringBuilder();
                foreach (var line in block.Lines.Values)
                {
                    blockLabel.Append($"{line.Address:X} \t + {line.NasmDisLine}");
                }

                var node = dgraph.FindNode(block.StepEvent.FROM_RIP.ToString("X"));
                if (node == null)
                {
                    continue;
                }

                node.LabelText       = blockLabel.ToString();
                node.Label.FontSize  = 10;
                node.Label.FontName  = "New Courier";
                node.Label.FontColor = Drawing.Color.Blue;
            }
            dgraph.Attr.LayerDirection         = Drawing.LayerDirection.TB;
            dgraph.Attr.OptimizeLabelPositions = false;
            graphViewer.Graph = dgraph;
        }
Esempio n. 21
0
        private int ZIndexOfEdge(DrawingEdge edge)
        {
            var source = (KosmographViewerNode)drawingObjectsToIViewerObjects[edge.SourceNode];
            var target = (KosmographViewerNode)drawingObjectsToIViewerObjects[edge.TargetNode];

            var zIndex = Math.Max(source.ZIndex, target.ZIndex) + 1;

            return(zIndex);
        }
Esempio n. 22
0
 private void UpdateMsaglEdge(MsaglGraphs.Edge msaglEdge, SgvlGraphs.Edge sgvlEdge)
 {
     // Метка ребра
     UpdateMsaglEdgeLabel(msaglEdge, sgvlEdge);
     // Цвет ребра
     UpdateMsaglEdgeColor(msaglEdge, sgvlEdge);
     // Выделение жирным
     UpdateMsaglEdgeBold(msaglEdge, sgvlEdge);
 }
        public static void ParseFields(this Graph graph, User user, Func <User, List <string> > dataType, double threshold, Color edgeColor, int possibleReplaces = 0)
        {
            foreach (User friend in user.Friends)
            {
                var fieldValues = friend.Friends
                                  .SelectMany(dataType)
                                  .GroupBy(x => x)
                                  .Select(g => new { Name = g.Key, Count = g.Count() })
                                  .OrderByDescending(x => x.Count)
                                  .ToList();
                if (!fieldValues.Any())
                {
                    continue;
                }
                int sum = fieldValues.Select(x => x.Count).Sum();
                if (dataType(friend).Count <= possibleReplaces && fieldValues.First().Count > sum * threshold)
                {
                    friend.WasEdited = true;
                    dataType(friend).Add(fieldValues.First().Name);
                }
            }

            AddNode(graph, user);
            foreach (User friend in user.Friends)
            {
                Node   node             = AddNode(graph, friend);
                string theirCommonField = dataType(friend).Intersect(dataType(user)).LastOrDefault();
                if (theirCommonField != null)
                {
                    Edge edge = graph.AddEdge(user.Name, friend.Name);
                    edge.Attr.ArrowheadAtTarget = ArrowStyle.None;
                    edge.Attr.LineWidth         = 3;
                    edge.Attr.Color             = edgeColor;
                    ++friend.Multiplexity;
                }
            }

            foreach (User friend in user.Friends)
            {
                foreach (User friendsFriend in friend.Friends)
                {
                    Node node = graph.FindNode(friendsFriend.Name);
                    if (!node.InEdges.Any(x => x.Source == friend.Name && x.Attr.Color == edgeColor))
                    {
                        string theirCommonField = dataType(friend).Intersect(dataType(friendsFriend)).LastOrDefault();
                        if (theirCommonField != null)
                        {
                            Edge edge = graph.AddEdge(friendsFriend.Name, friend.Name);
                            edge.Attr.LineWidth         = 3;
                            edge.Attr.ArrowheadAtTarget = ArrowStyle.None;
                            edge.Attr.Color             = edgeColor;
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        private void AddTreeNode(Graph graph, BiNode biNode, string nodeName)
        {
            string sourceName = null;

            if (biNode.Value != -1)
            {
                sourceName = mNodeList[biNode.Value - 1].Name;
            }
            else
            {
                sourceName = nodeName;
            }

            if (biNode.Left != null)
            {
                string targetName = null;
                if (biNode.Left.Value != -1)
                {
                    targetName = mNodeList[biNode.Left.Value - 1].Name;
                    Edge edge = graph.AddEdge(sourceName, targetName);
                    edge.TargetNode.Attr.LabelMargin = 5;
                }
                else
                {
                    targetName = nodeName + "0";
                    Edge edge = graph.AddEdge(sourceName, targetName);
                    edge.TargetNode.LabelText      = "";
                    edge.TargetNode.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.Circle;
                    edge.TargetNode.Attr.FillColor = Color.LightGray;
                }

                AddTreeNode(graph, biNode.Left, targetName);
            }

            if (biNode.Right != null)
            {
                string targetName = null;
                if (biNode.Right.Value != -1)
                {
                    targetName = mNodeList[biNode.Right.Value - 1].Name;
                    Edge edge = graph.AddEdge(sourceName, targetName);
                    edge.TargetNode.Attr.LabelMargin = 5;
                }
                else
                {
                    targetName = nodeName + "1";
                    Edge edge = graph.AddEdge(sourceName, targetName);
                    edge.TargetNode.LabelText      = "";
                    edge.TargetNode.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.Circle;
                    edge.TargetNode.Attr.FillColor = Color.LightGray;
                }

                AddTreeNode(graph, biNode.Right, targetName);
            }
        }
Esempio n. 25
0
        public void AddEdge(Edge edge)
        {
            var map = new Map();

            document.Transact((transaction) =>
            {
                edges.InsertFunc(edges.length, map, transaction);
                map.SetFunc("from", new ContentString(edge.Source), transaction);
                map.SetFunc("to", new ContentString(edge.Target), transaction);
            });
        }
Esempio n. 26
0
 private void UpdateMsaglEdgeBold(MsaglGraphs.Edge msaglEdge, SgvlGraphs.Edge sgvlEdge)
 {
     if (sgvlEdge.Bold)
     {
         msaglEdge.Attr.LineWidth = defaultLineWidth * boldCoefficient;
     }
     else
     {
         msaglEdge.Attr.LineWidth = defaultLineWidth;
     }
 }
Esempio n. 27
0
        public void AddTable(DbTable t)
        {
            int ct = 0;

            foreach (DbTableConstraint constraint in t.references.Each())
            {
                if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey))
                {
                    ct++;
                }
            }

            foreach (DbTableConstraint constraint in t.constraints.Values)
            {
                if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey))
                {
                    ct++;
                }
            }

            if (ct == 0)
            {
                return;
            }

            string leftTable = T.AppendTo(t.name, t.GetAlias(true), " ");

            Microsoft.Msagl.Drawing.Shape shape = Microsoft.Msagl.Drawing.Shape.Box;
            Color       backColor   = Color.DarkKhaki;
            Color       borderColor = backColor;
            int         radius      = 20;
            DrawingNode node        = drawingGraph.AddNode(leftTable);

            node.Attr.FillColor   = node.Attr.FillColor = GraphColor(backColor);
            node.Attr.Color       = GraphColor(borderColor);
            node.Attr.LabelMargin = 10;
            node.Attr.Shape       = shape;
            node.Attr.XRadius     = radius;
            node.Attr.YRadius     = radius;
            node.LabelText        = leftTable;
            foreach (DbTableConstraint constraint in t.constraints.Values)
            {
                if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey))
                {
                    string rightTable = T.AppendTo(constraint.referencedTable.name, constraint.referencedTable.GetAlias(true), " ");
                    string edgeInfo   = constraint.RenderJoinCols(true);
                    Microsoft.Msagl.Drawing.Edge e = drawingGraph.AddEdge(leftTable, edgeInfo, rightTable);
                    e.Attr.Weight = 6;
                    paths.Add(t.name + "." + constraint.referencedTable.name);
                }
            }
        }
Esempio n. 28
0
        private void CreateGraph()
        {
            Graph graph = new Graph();

            if (mNodeList.Count == 0 || mEdgeList.Count == 0)
            {
                return;
            }

            for (int index = 0; index < mNodeList.Count; index++)
            {
                if (IsNeedShow(mNodeList[index].Weight))
                {
                    Node node = new Node(mNodeList[index].Name);
                    node.Attr.LabelMargin = (int)(mNodeList[index].Weight / mMinNodeWeight * 2);//node size
                    node.Attr.Shape       = Microsoft.Msagl.Drawing.Shape.Circle;
                    graph.AddNode(node);
                }
            }

            double maxWeight     = 0;
            Edge   maxWeightEdge = null;

            for (int indexX = 0; indexX < mNodeList.Count - 1; indexX++)
            {
                for (int indexY = indexX + 1; indexY < mNodeList.Count; indexY++)
                {
                    if (IsNeedShow(mNodeList[indexX].Weight) && IsNeedShow(mNodeList[indexY].Weight))
                    {
                        double edgeWeight = mEdgeList[indexX][indexY];
                        //if (edgeWeight > mEdgeWeightThreshold)
                        {
                            Edge edge = graph.AddEdge(mNodeList[indexX].Name, mNodeList[indexY].Name) as Edge;
                            edge.Attr.ArrowheadLength = 1;
                            if (edgeWeight > maxWeight)
                            {
                                maxWeight     = edgeWeight;
                                maxWeightEdge = edge;
                            }
                        }
                    }
                }
            }

            if (maxWeightEdge != null)
            {
                maxWeightEdge.Attr.LineWidth = 3;
            }

            gViewer.Graph = graph;
        }
Esempio n. 29
0
 private static void DrawArrowAtTheBeginningWithControlPoints(Graphics g, DrawingEdge edge, System.Drawing.Color edgeColor, Pen myPen)
 {
     if (edge.Attr.ArrowheadAtSource == ArrowStyle.None)
     {
         DrawLine(g, myPen, edge.Attr.EdgeCurve.Start,
                  edge.Attr.ArrowAtSourcePosition);
     }
     else
     {
         using (SolidBrush sb = new SolidBrush(edgeColor))
             DrawArrow(g, sb, edge.Attr.EdgeCurve.Start,
                       edge.Attr.ArrowAtSourcePosition, edge.Attr.LineWidth, edge.Attr.ArrowheadAtSource);
     }
 }
Esempio n. 30
0
 private static void DrawArrowAtTheEndWithControlPoints(Graphics g, DrawingEdge edge, System.Drawing.Color edgeColor, Pen myPen)
 {
     if (edge.Attr.ArrowheadAtTarget == ArrowStyle.None)
     {
         DrawLine(g, myPen, (P2)edge.Attr.EdgeCurve.End,
                  edge.Attr.ArrowAtTargetPosition);
     }
     else
     {
         using (SolidBrush sb = new SolidBrush(edgeColor))
             DrawArrow(g, sb, (P2)edge.Attr.EdgeCurve.End,
                       edge.Attr.ArrowAtTargetPosition, edge.Attr.LineWidth, edge.Attr.ArrowheadAtTarget);
     }
 }
Esempio n. 31
0
        void gViewer_ObjectUnderMouseCursorChanged(object sender, ObjectUnderMouseCursorChangedEventArgs e)
        {
            selectedObject = e.OldObject != null ? e.OldObject.DrawingObject : null;

            if (selectedObject != null)
            {
                if (selectedObject is Edge)
                {
                    (selectedObject as Edge).Attr = selectedObjectAttr as EdgeAttr;
                }
                else if (selectedObject is Node)
                {
                    (selectedObject as Node).Attr = selectedObjectAttr as NodeAttr;
                }

                selectedObject = null;
            }

            if (gViewer.SelectedObject == null)
            {
                label1.Text = "No object under the mouse";
                this.gViewer.SetToolTip(toolTip1, "");
            }
            else
            {
                selectedObject = gViewer.SelectedObject;
                Edge edge = selectedObject as Edge;
                if (edge != null)
                {
                    selectedObjectAttr = edge.Attr.Clone();
                    edge.Attr.Color    = Microsoft.Msagl.Drawing.Color.Magenta;

                    //here we can use e.Attr.Id or e.UserData to get back to the user data
                    this.gViewer.SetToolTip(this.toolTip1, String.Format("edge from {0} {1}", edge.Source, edge.Target));
                }
                else if (selectedObject is Node)
                {
                    selectedObjectAttr = (gViewer.SelectedObject as Node).Attr.Clone();
                    (selectedObject as Node).Attr.Color = Microsoft.Msagl.Drawing.Color.Magenta;
                    //here you can use e.Attr.Id to get back to your data
                    this.gViewer.SetToolTip(toolTip1, String.Format("node {0}", (selectedObject as Node).Attr.Id));
                }
                label1.Text = selectedObject.ToString();
            }

            label1.Refresh();
            gViewer.Invalidate();
        }
Esempio n. 32
0
 void RestoreSelectedObjAttr()
 {
     if (selectedObject is DrawingEdge && selectedObjectAttr != null && selectedObjectAttr is EdgeAttr)
     {
         DrawingEdge edge = selectedObject as DrawingEdge;
         edge.Attr = ((EdgeAttr)selectedObjectAttr).Clone();
     }
     if (selectedObject is DrawingNode && selectedObjectAttr != null && selectedObjectAttr is NodeAttr)
     {
         DrawingNode node = selectedObject as DrawingNode;
         node.Attr           = ((NodeAttr)selectedObjectAttr).Clone();
         node.Attr.LineWidth = 1; // Fix bug
     }
     selectedObjectAttr = null;
     selectedObject     = null;
 }
        internal DEdge(DNode source, DNode target, DrawingEdge drawingEdgeParam, ConnectionToGraph connection,
                       GViewer gviewer) : base(gviewer) {
            DrawingEdge = drawingEdgeParam;
            Source = source;
            Target = target;

            if (connection == ConnectionToGraph.Connected) {
                if (source == target)
                    source.AddSelfEdge(this);
                else {
                    source.AddOutEdge(this);
                    target.AddInEdge(this);
                }
            }

            if (drawingEdgeParam.Label != null)
                Label = new DLabel(this, drawingEdge.Label, gviewer);
        }
Esempio n. 34
0
        internal DEdge(DNode source, DNode target, DrawingEdge drawingEdgeParam, ConnectionToGraph connection)
            : base(source.ParentObject)
        {
            this.DrawingEdge = drawingEdgeParam;
            this.Source = source;
            this.Target = target;

            if (connection == ConnectionToGraph.Connected)
            {
                if (source == target)
                    source.AddSelfEdge(this);
                else
                {
                    source.AddOutEdge(this);
                    target.AddInEdge(this);
                }
            }

            if (drawingEdgeParam.Label != null)
                this.Label = new DTextLabel(this, DrawingEdge.Label);
        }
        static void ProcessLinks(DgmlGraph g,
                                 Dictionary<string, Subgraph> subgraphTable, Microsoft.Msagl.Drawing.Graph drawingGraph) {
            foreach (GraphLink gl in g.Links) {
                var sourceId = gl.Source.Id.LiteralValue;
                var targetId = gl.Target.Id.LiteralValue;

                Subgraph sourceSubgraph;
                Node source = !subgraphTable.TryGetValue(sourceId, out sourceSubgraph)
                                  ? drawingGraph.FindNode(sourceId)
                                  : sourceSubgraph;

                Subgraph targetSubgraph;
                Node target = !subgraphTable.TryGetValue(targetId, out targetSubgraph)
                                  ? drawingGraph.FindNode(targetId)
                                  : targetSubgraph;

                bool containment=false;
                foreach (GraphCategory gc in gl.Categories) {
                    string c = gc.ToString().Replace("CodeSchema_", "");
                    if (c == "Contains") {
                        
                        if (targetSubgraph != null)
                            sourceSubgraph.AddSubgraph(targetSubgraph);
                        else
                            sourceSubgraph.AddNode(target);
                        containment = true;
                    }

                }
                if (!containment) {
                    Edge edge = new Edge(source, target, ConnectionToGraph.Connected);
                   // edge.Label = new Label(c);
                   
                }
            }
        }
Esempio n. 36
0
 public IViewerEdge RouteEdge(DrawingEdge edgeToRoute)
 {
     throw new NotImplementedException();
 }
Esempio n. 37
0
 public IViewerEdge CreateEdgeWithGivenGeometry(DrawingEdge drawingEdge)
 {
     throw new NotImplementedException();
 }
Esempio n. 38
0
        void RemoveVEdge(DrawingEdge drawingEdge)
        {
            //            graph.Edges.Remove(drawingEdge);
            //            var source = drawingEdge.SourceNode;
            //            var target = drawingEdge.TargetNode;
            //            if (source != target) {
            //                source.RemoveOutEdge(drawingEdge);
            //                target.RemoveInEdge(drawingEdge);
            //            }
            //            else
            //                source.RemoveSelfEdge(drawingEdge);

            IViewerObjectX vgedge;
            if (drawingObjectsToIViewerObjects.TryGetValue(drawingEdge, out vgedge)) {
                graphCanvas.Children.Remove(((XEdge) vgedge).Path);
                drawingObjectsToIViewerObjects.Remove(drawingEdge);
            }
        }
 public IViewerEdge RouteEdge(DrawingEdge drawingEdge) {
     var geomEdge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
     var geomGraph = _drawingGraph.GeometryGraph;
     LayoutHelpers.RouteAndLabelEdges(geomGraph, _drawingGraph.LayoutAlgorithmSettings, new[] {geomEdge});
     return CreateEdge(drawingEdge);
 }
 public IViewerEdge CreateEdgeWithGivenGeometry(DrawingEdge drawingEdge) {
     return CreateEdge(drawingEdge);
 }
Esempio n. 41
0
 private static void ArrowAtTheEnd(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.GeometryEdge != null && edge.Attr.ArrowAtTarget)
         DrawArrowAtTheEndWithControlPoints(pg, edge, fill);
 }
Esempio n. 42
0
 internal static void DrawEdgeArrows(PathGeometry pg, DrawingEdge edge, bool fillAtSource, bool fillAtTarget)
 {
     ArrowAtTheEnd(pg, edge, fillAtTarget);
     ArrowAtTheBeginning(pg, edge, fillAtSource);
 }
Esempio n. 43
0
 private static void DrawArrowAtTheBeginningWithControlPoints(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.EdgeCurve != null)
         if (edge.Attr.ArrowheadAtSource == ArrowStyle.None)
             DrawLine(pg, edge.EdgeCurve.Start, edge.ArrowAtSourcePosition);
         else
             DrawArrow(pg, edge.EdgeCurve.Start, edge.ArrowAtSourcePosition, edge.Attr.LineWidth, edge.Attr.ArrowheadAtSource, fill);
 }
 public GraphmapsEdge(Edge edge, LgLayoutSettings lgSettings) {
     Edge = edge;
     EdgeAttrClone = edge.Attr.Clone();
     this.lgSettings = lgSettings;
 }
Esempio n. 45
0
 public void SetEdgeLabel(DrawingEdge edge, Drawing.Label label)
 {
     //find the edge first
     DEdge de = null;
     foreach (DEdge dEdge in Edges)
         if (dEdge.DrawingEdge == edge)
         {
             de = dEdge;
             break;
         }
     edge.Label = label;
     de.Label = new DTextLabel(de, label);
     edge.GeometryEdge.Label = label.GeometryLabel;
     ICurve curve = edge.GeometryEdge.Curve;
     label.GeometryLabel.Center = curve[(curve.ParStart + curve.ParEnd) / 2];
     label.GeometryLabel.GeometryParent = edge.GeometryEdge;
 }
Esempio n. 46
0
 public IViewerEdge RouteEdge(DrawingEdge edgeToRoute)
 {
     edgeToRoute.Label = new Drawing.Label();
     GeometryEdge geometryEdge = edgeToRoute.GeometryEdge = new GeometryEdge();
     geometryEdge.GeometryParent = Graph.GeometryGraph;
     geometryEdge.Source = edgeToRoute.SourceNode.GeometryNode;
     geometryEdge.Target = edgeToRoute.TargetNode.GeometryNode;
     //geometryEdge.ArrowheadLength = edgeToRoute.Attr.ArrowheadLength;
     geometryEdge.SourcePort = edgeToRoute.SourcePort;
     geometryEdge.TargetPort = edgeToRoute.TargetPort;
     if (edgeToRoute.Source == edgeToRoute.Target)
     {
         RectilinearInteractiveEditor.CreateSimpleEdgeCurve(geometryEdge);
     }
     else
     {
         RouteEdge(geometryEdge);
         Arrowheads.TrimSplineAndCalculateArrowheads(geometryEdge, geometryEdge.Curve, false, true);
         //Arrowheads.FixArrowheadAtSource(geometryEdge.EdgeGeometry, edgeToRoute.SourcePort);
         //Arrowheads.FixArrowheadAtTarget(geometryEdge.EdgeGeometry, edgeToRoute.TargetPort);
     }
     var dEdge = new DEdge(NodeMap[edgeToRoute.SourceNode.Id], NodeMap[edgeToRoute.TargetNode.Id],
                           edgeToRoute, ConnectionToGraph.Disconnected);
     dEdge.Label = new DTextLabel(dEdge, new Drawing.Label());
     return dEdge;
 }
Esempio n. 47
0
        public IViewerEdge CreateEdgeWithGivenGeometry(DrawingEdge drawingEdge)
        {
            GeometryEdge geometryEdge = drawingEdge.GeometryEdge;
            geometryEdge.GeometryParent = Graph.GeometryGraph;

            var dEdge = new DEdge(NodeMap[drawingEdge.SourceNode.Id], NodeMap[drawingEdge.TargetNode.Id], drawingEdge, ConnectionToGraph.Disconnected);
            if (drawingEdge.Label != null)
                dEdge.Label = new DTextLabel(dEdge, new Drawing.Label());

            dEdge.MakeVisual();
            return dEdge;
        }
Esempio n. 48
0
 private static void ArrowAtTheBeginning(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.GeometryEdge != null && edge.Attr.ArrowAtSource)
         DrawArrowAtTheBeginningWithControlPoints(pg, edge, fill);
 }
Esempio n. 49
0
        void CreateEdge(DrawingEdge edge)
        {
            if (drawingObjectsToIViewerObjects.ContainsKey(edge)) return;

            XEdge xEdge;
            if (vObjectsMapping.ContainsKey(edge))
            {
                xEdge = (XEdge)vObjectsMapping[edge];
            }
            else
            {
                xEdge = new XEdge(edge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;

            if (edge.Source == edge.Target)
                ((XNode) drawingObjectsToIViewerObjects[edge.SourceNode]).selfEdges.Add(xEdge);
            else {
                ((XNode) drawingObjectsToIViewerObjects[edge.SourceNode]).outEdges.Add(xEdge);
                ((XNode) drawingObjectsToIViewerObjects[edge.TargetNode]).inEdges.Add(xEdge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;

            FrameworkElement _visuals = xEdge.VisualObject;
            if (_visuals != null)
            {
                graphObjectsToFrameworkElements[edge] = _visuals;
                if (_visuals.Parent == null)
                    graphCanvas.Children.Add(_visuals);
            }
            graphCanvas.Children.Add(xEdge.Path);
        }
        void SetVEdgeLabel(DrawingEdge edge, VEdge vEdge, int zIndex) {
            FrameworkElement frameworkElementForEdgeLabel;
            if (!drawingObjectsToFrameworkElements.TryGetValue(edge, out frameworkElementForEdgeLabel)) {
                drawingObjectsToFrameworkElements[edge] =
                    frameworkElementForEdgeLabel = CreateTextBlockForDrawingObj(edge);
                frameworkElementForEdgeLabel.Tag = new VLabel(edge, frameworkElementForEdgeLabel);
            }

            vEdge.VLabel = (VLabel) frameworkElementForEdgeLabel.Tag;
            if (frameworkElementForEdgeLabel.Parent == null) {
                _graphCanvas.Children.Add(frameworkElementForEdgeLabel);
                Panel.SetZIndex(frameworkElementForEdgeLabel, zIndex);
            }
        }
Esempio n. 51
0
        /// <summary>
        /// routes an edge and returns the corresponding edge of the viewer
        /// </summary>
        /// <returns></returns>
        public IViewerEdge RouteEdge(DrawingEdge drawingEdge)
        {
            drawingEdge.Label = new Label();
            Edge geometryEdge = drawingEdge.GeometryEdge = new Edge();
            if (drawingEdge.Attr.ArrowheadAtSource != ArrowStyle.NonSpecified &&
                drawingEdge.Attr.ArrowheadAtSource != ArrowStyle.None)
                geometryEdge.EdgeGeometry.SourceArrowhead = new Arrowhead {Length = drawingEdge.Attr.ArrowheadLength};
            if (drawingEdge.Attr.ArrowheadAtSource != ArrowStyle.None)
                geometryEdge.EdgeGeometry.TargetArrowhead = new Arrowhead {Length = drawingEdge.Attr.ArrowheadLength};

            geometryEdge.GeometryParent = Graph.GeometryGraph;
            geometryEdge.Source = drawingEdge.SourceNode.GeometryNode;
            geometryEdge.Target = drawingEdge.TargetNode.GeometryNode;
            geometryEdge.SourcePort = drawingEdge.SourcePort;
            geometryEdge.TargetPort = drawingEdge.TargetPort;
            LayoutHelpers.RouteAndLabelEdges(this.Graph.GeometryGraph, Graph.LayoutAlgorithmSettings,
                                             new[] {geometryEdge});

            var dEdge = new DEdge(DGraph.FindDNode(drawingEdge.SourceNode.Id), DGraph.FindDNode(drawingEdge.TargetNode.Id),
                                  drawingEdge, ConnectionToGraph.Disconnected, this);
            dEdge.Label = new DLabel(dEdge, new Label(), this);
            return dEdge;
        }
Esempio n. 52
0
 static void DrawArrowAtTheEndWithControlPoints(PathGeometry pg, DrawingEdge edge, bool fill)
 {
     if (edge.EdgeCurve != null)
         if (edge.Attr.ArrowheadAtTarget == ArrowStyle.None)
             DrawLine(pg, edge.EdgeCurve.End,
                      edge.ArrowAtTargetPosition);
         else
             DrawArrow(pg, edge.EdgeCurve.End,
                       edge.ArrowAtTargetPosition, edge.Attr.LineWidth, edge.Attr.ArrowheadAtTarget, fill);
 }
Esempio n. 53
0
        /// <summary>
        /// Changes an edge's label and updates the display
        /// </summary>
        /// <param name="e">The edge whose label has to be changed</param>
        /// <param name="newLabel">The new label</param>
        internal void RelabelEdge(Edge e, string newLabel) {
            if (e.Label == null)
                e.Label = new Label(newLabel);
            else

                e.Label.Text = newLabel;


            gViewer.SetEdgeLabel(e, e.Label);
            e.Label.GeometryLabel.InnerPoints = new List<Point>();
            var ep = new EdgeLabelPlacement(gViewer.Graph.GeometryGraph);
            ep.Run();
            gViewer.Graph.GeometryGraph.UpdateBoundingBox();
            gViewer.Invalidate();   
        }
Esempio n. 54
0
 /// <summary>
 /// sets the edge label
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="label"></param>
 public void SetEdgeLabel(DrawingEdge edge, Label label)
 {
     //find the edge first
     DEdge de = null;
     foreach (DEdge dEdge in DGraph.Edges)
         if (dEdge.DrawingEdge == edge) {
             de = dEdge;
             break;
         }
     Debug.Assert(de != null);
     edge.Label = label;
     double w, h;
     DGraph.CreateDLabel(de, label, out w, out h, this);
     edge.GeometryEdge.Label = label.GeometryLabel;
     ICurve curve = edge.GeometryEdge.Curve;
     label.GeometryLabel.Center = curve[(curve.ParStart + curve.ParEnd)/2];
     label.GeometryLabel.GeometryParent = edge.GeometryEdge;
     BbNode = DGraph.BbNode = null;
     Invalidate();
 }
        GraphmapsEdge UnhideEdge(DrawingEdge edge) {
            IViewerObject iedge;
            if (!_drawingObjectsToIViewerObjects.TryGetValue(edge, out iedge)) {
                return CreateEdge(edge);
            }

            var vEdge = (GraphmapsEdge) iedge;
            if (vEdge.CurvePath != null)
                GraphCanvasChildrenAdd(vEdge.CurvePath);
            return vEdge;
        }
        void HideVEdge(DrawingEdge edge) {
            IViewerObject iedge;
            if (!_drawingObjectsToIViewerObjects.TryGetValue(edge, out iedge)) {
                return;
            }

            var vEdge = (GraphmapsEdge) iedge;
            if (vEdge.CurvePath != null) {
                _graphCanvas.Children.Remove(vEdge.CurvePath);
            }
            _drawingObjectsToIViewerObjects.Remove(edge);
        }
 public IViewerEdge CreateEdgeWithGivenGeometry(DrawingEdge drawingEdge) {
     return CreateEdge(drawingEdge, _drawingGraph.LayoutAlgorithmSettings as LgLayoutSettings);
 }
 GraphmapsEdge CreateEdgeForLgCase(DrawingEdge edge) {
     return (GraphmapsEdge) (_drawingObjectsToIViewerObjects[edge] = new GraphmapsEdge(edge, _lgLayoutSettings)
     {
         PathStrokeThicknessFunc = () => GetBorderPathThickness()*edge.Attr.LineWidth
     });
 }
 GraphmapsEdge CreateEdge(DrawingEdge edge) {
     lock (this) {
         IViewerObject iedge;
         if (_drawingObjectsToIViewerObjects.TryGetValue(edge, out iedge))
             return (GraphmapsEdge) iedge;
         return CreateEdgeForLgCase(edge);
     }
 }
Esempio n. 60
0
        /// <summary>
        /// drawing edge already has its geometry in place
        /// </summary>
        /// <param name="drawingEdge"></param>
        /// <returns></returns>
        public IViewerEdge CreateEdgeWithGivenGeometry(DrawingEdge drawingEdge)
        {
            drawingEdge.Label = new Label();
            Edge geometryEdge = drawingEdge.GeometryEdge;
            Debug.Assert(geometryEdge != null);
            geometryEdge.GeometryParent = Graph.GeometryGraph;

            var dEdge = new DEdge(DGraph.FindDNode(drawingEdge.SourceNode.Id), DGraph.FindDNode(drawingEdge.TargetNode.Id),
                                  drawingEdge, ConnectionToGraph.Disconnected, this);
            dEdge.Label = new DLabel(dEdge, new Label(), this);
            return dEdge;
        }