protected int GetArrowIndex(List <Point> points, Placemement end) { int index = points.Count; for (int i = points.Count - 1; i > 0; i--) { if (end == Placemement.Bottom || end == Placemement.Top) { if (points[i].X == EndPoint.X) { index = i; } else { break; } } else { if (points[i].Y == EndPoint.Y) { index = i; } else { break; } } } return(index); }
public override void CalculatePath() { List <Point> points = PathCreator.GetConnectionLine(_start, EndPoint, Placemement.None); StartPoint = points[1]; EndPlacemement = PathCreator.GetOpositeOrientation(_start.Placemement); int idx = GetArrowIndex(points, EndPlacemement); ArrowPoint = points[idx]; Points = new PointCollection(points.Take(idx + 1)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Placemement placemement = (Placemement)value; HorizontalAlignment result = HorizontalAlignment.Center; if (placemement == Placemement.Left) { result = HorizontalAlignment.Left; } else if (placemement == Placemement.Right) { result = HorizontalAlignment.Right; } return(result); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Placemement placemement = (Placemement)value; VerticalAlignment result = VerticalAlignment.Center; if (placemement == Placemement.Top) { result = VerticalAlignment.Top; } else if (placemement == Placemement.Bottom) { result = VerticalAlignment.Bottom; } return(result); }
public static Placemement GetOpositeOrientation(Placemement connectorOrientation) { switch (connectorOrientation) { case Placemement.Left: return(Placemement.Right); case Placemement.Top: return(Placemement.Bottom); case Placemement.Right: return(Placemement.Left); case Placemement.Bottom: return(Placemement.Top); default: return(Placemement.Top); } }
private static Orientation GetOrientation(Placemement sourceOrientation) { switch (sourceOrientation) { case Placemement.Left: return(Orientation.Horizontal); case Placemement.Top: return(Orientation.Vertical); case Placemement.Right: return(Orientation.Horizontal); case Placemement.Bottom: return(Orientation.Vertical); default: throw new Exception("Unknown ConnectorOrientation"); } }
private static void GetNeighborCorners(Placemement orientation, Rect rect, out Point n1, out Point n2) { switch (orientation) { case Placemement.Left: n1 = rect.TopLeft; n2 = rect.BottomLeft; break; case Placemement.Top: n1 = rect.TopLeft; n2 = rect.TopRight; break; case Placemement.Right: n1 = rect.TopRight; n2 = rect.BottomRight; break; case Placemement.Bottom: n1 = rect.BottomLeft; n2 = rect.BottomRight; break; default: throw new Exception("No neighour corners found!"); } }
protected ConnectorBase(Placemement placemement) { Placemement = placemement; }
public ConnectorViewModel(BaseElementViewModel baseElementViewModel, Placemement placemement) : base(placemement) { _parentViewModel = baseElementViewModel; }
private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, Placemement sourceOrientation, Placemement sinkOrientation) { List <Point> points = new List <Point>(); int cut = 0; for (int i = 0; i < linePoints.Count; i++) { if (i >= cut) { for (int k = linePoints.Count - 1; k > i; k--) { if (IsPointVisible(linePoints[i], linePoints[k], rectangles)) { cut = k; break; } } points.Add(linePoints[i]); } } #region Line for (int j = 0; j < points.Count - 1; j++) { if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y) { Placemement orientationFrom; Placemement orientationTo; // orientation from point if (j == 0) { orientationFrom = sourceOrientation; } else { orientationFrom = GetOrientation(points[j], points[j - 1]); } // orientation to pint if (j == points.Count - 2) { orientationTo = sinkOrientation; } else { orientationTo = GetOrientation(points[j + 1], points[j + 2]); } if ((orientationFrom == Placemement.Left || orientationFrom == Placemement.Right) && (orientationTo == Placemement.Left || orientationTo == Placemement.Right)) { double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2; points.Insert(j + 1, new Point(centerX, points[j].Y)); points.Insert(j + 2, new Point(centerX, points[j + 2].Y)); if (points.Count - 1 > j + 3) { points.RemoveAt(j + 3); } return(points); } if ((orientationFrom == Placemement.Top || orientationFrom == Placemement.Bottom) && (orientationTo == Placemement.Top || orientationTo == Placemement.Bottom)) { double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2; points.Insert(j + 1, new Point(points[j].X, centerY)); points.Insert(j + 2, new Point(points[j + 2].X, centerY)); if (points.Count - 1 > j + 3) { points.RemoveAt(j + 3); } return(points); } if ((orientationFrom == Placemement.Left || orientationFrom == Placemement.Right) && (orientationTo == Placemement.Top || orientationTo == Placemement.Bottom)) { points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y)); return(points); } if ((orientationFrom == Placemement.Top || orientationFrom == Placemement.Bottom) && (orientationTo == Placemement.Left || orientationTo == Placemement.Right)) { points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y)); return(points); } } } #endregion return(points); }
internal static List <Point> GetConnectionLine(ConnectorViewModel source, Point sinkPoint, Placemement preferredOrientation) { List <Point> linePoints = new List <Point>(); Rect rectSource = source.GetParentRectWithMargin(10); Point startPoint = GetOffsetPoint(source, rectSource); Point endPoint = sinkPoint; linePoints.Add(startPoint); Point currentPoint = startPoint; if (!rectSource.Contains(endPoint)) { while (true) { if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource })) { linePoints.Add(endPoint); break; } bool sideFlag; Point n = GetNearestNeighborSource(source, endPoint, rectSource, out sideFlag); linePoints.Add(n); currentPoint = n; if (IsPointVisible(currentPoint, endPoint, new Rect[] { rectSource })) { linePoints.Add(endPoint); break; } else { Point n1, n2; GetOppositeCorners(source.Placemement, rectSource, out n1, out n2); if (sideFlag) { linePoints.Add(n1); } else { linePoints.Add(n2); } linePoints.Add(endPoint); break; } } } else { linePoints.Add(endPoint); } if (preferredOrientation != Placemement.None) { linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Placemement, preferredOrientation); } else { linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, source.Placemement, GetOpositeOrientation(source.Placemement)); } return(linePoints); }