Exemple #1
0
        void DrawEdge(Graphics g, Edge item, PointF p1, PointF p2)
        {
            string distance = item.weight.ToString();

            p1.X += NODE_RADIUS;
            p1.Y += NODE_RADIUS;
            p2.X += NODE_RADIUS;
            p2.Y += NODE_RADIUS;

            Vector2D v1 = new Vector2D(p1.X - p2.X, p1.Y - p2.Y);

            if (v1.Length - NODE_RADIUS > 0)
            {
                v1.Contract(NODE_RADIUS);
                p1.X = p2.X + v1.X;
                p1.Y = p2.Y + v1.Y;
            }
            Vector2D v = new Vector2D(p2.X - p1.X, p2.Y - p1.Y);

            if (v.Length - NODE_RADIUS > 0)
            {
                v.Contract(NODE_RADIUS);
                p2.X = p1.X + v.X;
                p2.Y = p1.Y + v.Y;
            }
            if (!IsUndirectedGraph && item.IsUndirected)
            {
                _penEdge.StartCap = LineCap.ArrowAnchor;
            }
            else
            {
                _penEdge.StartCap = LineCap.NoAnchor;
            }

            if (item.IsRemoving)
            {
                Pen p = new Pen(Color.Red, 4);
                g.DrawLine(p, p1, p2);
            }
            else
            {
                if (_list != null && (_list.Contains(item)))
                {
                    if (item.IsSelected)
                    {
                        var p = (Pen)_penEdge.Clone();
                        p.Color     = Color.Red;
                        p.DashStyle = DashStyle.Dash;
                        g.DrawLine(p, p1, p2);
                    }
                    else
                    {
                        Pen p = (Pen)_penEdge.Clone();
                        p.Color     = Color.Green;
                        p.DashStyle = DashStyle.Dash;
                        g.DrawLine(p, p1, p2);
                    }
                }
                else
                if (item.IsSelected)
                {
                    var hPen = (Pen)_penEdge.Clone();
                    hPen.Color = Color.Red;
                    g.DrawLine(hPen, p1, p2);
                }
                else
                {
                    g.DrawLine(_penEdge, p1, p2);
                }
            }


            // draw distance
            SizeF  size = g.MeasureString(distance, this.Font);
            PointF pp   = p1;

            pp.X += p2.X;
            pp.Y += p2.Y;
            pp.X /= 2;
            pp.Y /= 2;
            pp.X -= size.Width / 2;
            pp.Y -= size.Height / 2;
            g.FillEllipse(Brushes.Yellow, pp.X - 5, pp.Y - 5, size.Width + 10, size.Height + 5);
            g.DrawString(distance.ToString(), this.Font, Brushes.Blue, pp);
        }
Exemple #2
0
 public void DeleteEdge(Edge edge)
 {
     edge.IsRemoving = true;
     _graph.DeleteEdeg(edge);
     Invalidate();
 }