Example #1
0
        private GraphicsPath CalculateJumpPath(PointF a, PointF b)
        {
            GraphicsPath  path  = new GraphicsPath();
            List <PointF> jumps = new List <PointF>();

            float diameter = 10F;

            if (Rounded)
            {
                diameter = 15F;
            }

            //Loop through all connectors in the renderlist
            foreach (Element element in Model.Elements)
            {
                //Check if connector lower down then this connector and overlaps this connector
                if (element is Connector && element.ZOrder > ZOrder && element.Bounds.IntersectsWith(Bounds))
                {
                    Connector connector = (Connector)element;
                    PointF    prev      = PointF.Empty;

                    //Get the intersection of the line between the points provided and this connector
                    foreach (PointF point in connector.Points)
                    {
                        if (!prev.IsEmpty)
                        {
                            PointF intersection = PointF.Empty;

                            //Return the line intersection (if any) and add to jumps list
                            if (Geometry.LineIntersection(a, b, prev, point, ref intersection))
                            {
                                //Check the intersection doesnt overlap with the point
                                if (ValidateJump(intersection, b, diameter))
                                {
                                    jumps.Add(intersection);
                                }
                            }
                        }
                        prev = point;
                    }
                }
            }

            //Sort the arraylist from smallest to biggest
            if (jumps.Count > 1)
            {
                PointFComparer comparer = new PointFComparer();

                if (a.X == b.X)
                {
                    comparer.Horizontal = false;
                    comparer.Ascending  = (a.Y < b.Y);
                }
                else
                {
                    comparer.Horizontal = true;
                    comparer.Ascending  = (a.X < b.X);
                }

                jumps.Sort(comparer);
            }

            float angle;
            float sweep = 180;

            //Set up the correct starting angle
            if (a.X == b.X)
            {
                if (a.Y < b.Y)
                {
                    angle = -90;
                }
                else
                {
                    angle = 90;
                }
            }
            else
            {
                if (a.X < b.X)
                {
                    angle = 180;
                }
                else
                {
                    angle = 0;
                }
            }

            //Loop through adding arcs for jump points
            if (jumps.Count == 0)
            {
                path.AddLine(a, b);
            }
            else
            {
                PointF     last  = a;
                PointF     start = PointF.Empty;
                PointF     end   = PointF.Empty;
                RectangleF bound = RectangleF.Empty;

                foreach (PointF point in jumps)
                {
                    //Determine start and end points for the arc
                    if (a.X == b.X)
                    {
                        if (a.Y < b.Y)
                        {
                            start = new PointF(point.X, point.Y - 5F);
                            end   = new PointF(point.X, point.Y + 5F);
                        }
                        else
                        {
                            start = new PointF(point.X, point.Y + 5F);
                            end   = new PointF(point.X, point.Y - 5F);
                        }
                    }
                    else
                    {
                        if (a.X < b.X)
                        {
                            start = new PointF(point.X - 5F, point.Y);
                            end   = new PointF(point.X + 5F, point.Y);
                        }
                        else
                        {
                            start = new PointF(point.X + 5F, point.Y);
                            end   = new PointF(point.X - 5F, point.Y);
                        }
                    }

                    //Calculate the bounds of the arc
                    bound = new RectangleF(point, new SizeF(10F, 10F));
                    bound.Offset(-5F, -5F);

                    path.AddLine(last, start);
                    path.AddArc(bound, angle, sweep);
                    path.StartFigure();

                    last = end;
                }
                path.AddLine(last, b);
            }

            return(path);
        }
Example #2
0
		private GraphicsPath CalculateJumpPath(PointF a, PointF b)
		{
			GraphicsPath path = new GraphicsPath();
			ArrayList jumps = new ArrayList();

			float diameter = 10F;
			if (Rounded) diameter = 15F;

			//Loop through all connectors in the renderlist 
			foreach (Element element in Container.RenderList)
			{
				//Check if connector lower down then this connector and overlaps this connector
				if (element is Connector && element.ZOrder > ZOrder && element.Rectangle.IntersectsWith(Rectangle))
				{
					Connector connector = (Connector) element;
					PointF prev = PointF.Empty;

					//Get the intersection of the line between the points provided and this connector
					foreach (PointF point in connector.Points)
					{
						if (!prev.IsEmpty)
						{	
							PointF intersection = PointF.Empty;

							//Return the line intersection (if any) and add to jumps arraylist
							if (Geometry.LineIntersection(a, b, prev, point,ref intersection))
							{
								//Check the intersection doesnt overlap with the point
								if (ValidateJump(intersection, b, diameter)) jumps.Add(intersection);
							}
						}
						prev = point;
					}
				}
			}

			//Sort the arraylist from smallest to biggest
			if (jumps.Count > 1)
			{
				PointFComparer comparer = new PointFComparer();
				
				if (a.X == b.X)
				{
					comparer.Horizontal = false;
					comparer.Ascending = (a.Y < b.Y);
				}
				else
				{
					comparer.Horizontal = true;
					comparer.Ascending = (a.X < b.X);
				}
				
				jumps.Sort(comparer);
			}

			float angle;
			float sweep = 180;

			//Set up the correct starting angle
			if (a.X == b.X)
			{
				if (a.Y < b.Y) 
				{
					angle = -90;
				}
				else
				{
					angle = 90;
				}
			}
			else
			{
				if (a.X < b.X)
				{
					angle = 180;
				}
				else
				{
					angle = 0;
				}
			}

			//Loop through adding arcs for jump points
			if (jumps.Count == 0)
			{
				path.AddLine(a,b);
			}
			else
			{
				PointF last = a;
				PointF start = PointF.Empty;
				PointF end = PointF.Empty;
				RectangleF bound = RectangleF.Empty;
				
				foreach (PointF point in jumps)
				{
					//Determine start and end points for the arc
					if (a.X == b.X)
					{
						if (a.Y < b.Y)
						{
							start = new PointF(point.X, point.Y - 5F);
							end = new PointF(point.X, point.Y + 5F);
						}
						else
						{
							start = new PointF(point.X, point.Y + 5F);
							end = new PointF(point.X, point.Y - 5F);
						}
					}
					else
					{
						if (a.X < b.X)
						{
							start = new PointF(point.X - 5F, point.Y);
							end = new PointF(point.X + 5F, point.Y);
						}
						else
						{
							start = new PointF(point.X + 5F, point.Y);
							end = new PointF(point.X - 5F, point.Y);
						}
					}

					//Calculate the bounds of the arc
					bound = new RectangleF(point,new SizeF(10F,10F));
					bound.Offset(-5F,-5F);

					path.AddLine(last, start);
					path.AddArc(bound, angle, sweep);
					path.StartFigure();					

					last = end;
				}
				path.AddLine(last, b);
			}

			return path;
		}