Beispiel #1
0
 /// <summary>Constrcutor</summary>
 /// <param name="directedGraphArc">The arc information to use</param>
 /// <param name="allNodes">A list of all nodes</param>
 public DGArc(Arc directedGraphArc, List <DGNode> allNodes)
 {
     Location   = new PointD(directedGraphArc.Location.X, directedGraphArc.Location.Y);
     SourceNode = allNodes.Find(node => node.Name == directedGraphArc.SourceName);
     TargetNode = allNodes.Find(node => node.Name == directedGraphArc.DestinationName);
     Colour     = OxyColor.FromRgb(directedGraphArc.Colour.R, directedGraphArc.Colour.G, directedGraphArc.Colour.B);
     Name       = directedGraphArc.Text;
 }
Beispiel #2
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(Cairo.Context context)
        {
            CalcBezPoints();

            if (BezPoints.Count != 0)
            {
                // Create point for upper-left corner of drawing.
                context.NewPath();
                if (Selected)
                {
                    context.SetSourceColor(OxyColors.Blue);
                }
                else
                {
                    context.SetSourceColor(Colour);
                }

                // Draw text if necessary
                if (Name != null)
                {
                    DGNode.DrawCentredText(context, Name, Location);
                }

                context.MoveTo(BezPoints[0]);
                PointD controlPoint = new PointD(Location.X, Location.Y);
                context.CurveTo(controlPoint, controlPoint, BezPoints[BezPoints.Count - 1]);
                context.Stroke();

                // find closest point in the bezPoints to the intersection point that is outside the target
                // work backwards through BezPoints array and use the first one that is outside the target
                for (int i = BezPoints.Count - 1; i >= 0; i--)
                {
                    PointD arrowHead;
                    if (!TargetNode.HitTest(BezPoints[i]))
                    {
                        arrowHead = BezPoints[i];
                        i--;
                        //keep moving along the line until distance = target radius
                        double targetRadius = TargetNode.Width / 2;
                        while (i >= 0)
                        {
                            double dist = GetDistance(BezPoints[i], arrowHead);
                            if (dist >= 20)
                            {
                                DrawArrow(context, BezPoints[i], arrowHead);
                                break;
                            }

                            i--;
                        }
                        break;
                    }
                }
            }
        }