Пример #1
0
        public void AddNode(GraphNode node)
        {
            if (Nodes.Contains(node) || Nodes.Any(n => n.Label == node.Label))
                throw new Exception();

            Nodes.Add(node);
        }
Пример #2
0
        private void AddEdge(GraphNode src, GraphNode dest, string label)
        {
            if (!Nodes.Contains(src))
                AddNode(src);

            if (!Nodes.Contains(dest))
                AddNode(dest);

            src.Connect(dest, label);
        }
Пример #3
0
 internal void Disconnect(GraphNode fromNode)
 {
     ToNodes.Remove(fromNode);
 }
Пример #4
0
 internal void Connect(GraphNode toNode, string label)
 {
     ToNodes.Add(toNode, label);
 }
Пример #5
0
 public void AddEdge(GraphNode src, GraphNode dest)
 {
     AddEdge(src, dest, "");
 }
Пример #6
0
        private LineCoordinate CalculateEdgeCoordintes(GraphNode node1, GraphNode node2, int size)
        {
            double r = size / 2.0;
            int x1 = node1.X, x2 = node2.X, y1 = node1.Y, y2 = node2.Y;

            switch (EdgeConnectionStyle)
            {
                case EdgeConnectionStyle.FreeStyle:
                    int dx1 = (int)Math.Round(Math.Abs(x2 - x1) / Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)) * r);
                    int dy1 = (int)Math.Round(Math.Abs(y2 - y1) / Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)) * r);

                    if (node2.X > node1.X)
                    {
                        x1 += dx1;
                        x2 -= dx1;
                    }
                    else
                    {
                        x1 -= dx1;
                        x2 += dx1;
                    }
                    if (node2.Y > node1.Y)
                    {
                        y1 += dy1;
                        y2 -= dy1;
                    }
                    else
                    {
                        y1 -= dy1;
                        y2 += dy1;
                    }
                    break;

                case EdgeConnectionStyle.TopBottom:
                    if (node2.Y > node1.Y)
                    {
                        y1 = (int)Math.Ceiling(y1 + r);
                        y2 = (int)Math.Ceiling(y2 - r);
                    }
                    else
                    {
                        y1 = (int)Math.Ceiling(y1 - r);
                        y2 = (int)Math.Ceiling(y2 + r);
                    }
                    break;

                case EdgeConnectionStyle.LeftRight:
                    if (node2.X > node1.X)
                    {
                        x1 = (int)Math.Ceiling(x1 + r);
                        x2 = (int)Math.Ceiling(x2 - r);
                    }
                    else
                    {
                        x1 = (int)Math.Ceiling(x1 - r);
                        x2 = (int)Math.Ceiling(x2 + r) + 1;
                    }
                    break;

                default:
                    throw new NotSupportedException();
            }

            return new LineCoordinate(x1, y1, x2, y2);
        }
Пример #7
0
 private void DrawSingleEdge(Graphics g, GraphNode node1, GraphNode node2, string label, int size)
 {
     var edge = CalculateEdgeCoordintes(node1, node2, size);
     DrawEdge(g, label, edge.X1, edge.Y1, edge.X2, edge.Y2, size, false);
 }
Пример #8
0
        private void DrawDoubleEdge(Graphics g, GraphNode node1, GraphNode node2, string label1, string label2, int size)
        {
            // todo: incomplete implementation!
            var edge = CalculateEdgeCoordintes(node1, node2, size);
            DrawEdge(g, label1, edge.X1, edge.Y1, edge.X2, edge.Y2, size, true);

            //var edge1 = CalculateEdgeCoordintes(node1, node2, size);
            //var edge2 = CalculateEdgeCoordintes(node2, node1, size);

            //var dx = 0.015 * size - 0.32;
            //var dy = (edge1.X2 - edge1.X1) / (edge1.Y2 - edge1.Y1) * dx;
            //edge1.X1 += (int) Math.Round(dx);
            //edge1.Y1 += (int) Math.Round(dy);
            //edge1.X2 += (int) Math.Round(dx);
            //edge1.Y2 += (int) Math.Round(dy);
            //edge2.X1 -= (int) Math.Round(dx);
            //edge2.Y1 -= (int) Math.Round(dy);
            //edge2.X2 -= (int) Math.Round(dx);
            //edge2.Y2 -= (int) Math.Round(dy);

            //DrawEdge(g, label1, edge1.X1, edge1.Y1, edge1.X2, edge1.Y2, size);
            //DrawEdge(g, label2, edge2.X1, edge2.Y1, edge2.X2, edge2.Y2, size);
        }