示例#1
0
        internal static PathGeometry GetPathGeometry(ConnectorInfo source, ConnectorInfo sink)
        {
            var rectSource = GetRectWithMargin(source, 0);
            var rectSink = GetRectWithMargin(sink, 13);

            var startPoint = GetOffsetPoint(source, rectSource);
            var endPoint = GetOffsetPoint(sink, rectSink);

            var midpoint = CalculateMidpoint(startPoint, new Point(endPoint.X, startPoint.Y));
            var distance = CalculateDistance(startPoint, midpoint);

            var p1 = CalculateEndpoint(startPoint, distance, GetAngel(source.Orientation));
            var p2 = CalculateEndpoint(endPoint, distance, GetAngel(sink.Orientation));
            var p3 = endPoint;

            var geometry = new PathGeometry();

            var pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;
            geometry.Figures.Add(pathFigure);

            var bs = new BezierSegment(p1, p2, p3, true);
            pathFigure.Segments.Add(bs);

            return geometry;
        }
示例#2
0
        private static Point GetOffsetPoint(ConnectorInfo connector, Rect rect)
        {
            Point offsetPoint = new Point();

            switch (connector.Orientation)
            {
                case ConnectorOrientation.Left:
                    offsetPoint = new Point(rect.Left, connector.Position.Y);
                    break;
                case ConnectorOrientation.Top:
                    offsetPoint = new Point(connector.Position.X, rect.Top);
                    break;
                case ConnectorOrientation.Right:
                    offsetPoint = new Point(rect.Right, connector.Position.Y);
                    break;
                case ConnectorOrientation.Bottom:
                    offsetPoint = new Point(connector.Position.X, rect.Bottom);
                    break;
                default:
                    break;
            }

            return offsetPoint;
        }
示例#3
0
        private static Rect GetRectWithMargin(ConnectorInfo connectorThumb, double margin)
        {
            Rect rect = new Rect(connectorThumb.DesignerItemLeft,
                                 connectorThumb.DesignerItemTop,
                                 connectorThumb.DesignerItemSize.Width,
                                 connectorThumb.DesignerItemSize.Height);

            rect.Inflate(margin, margin);

            return rect;
        }
示例#4
0
 internal ConnectorInfo GetInfo()
 {
     ConnectorInfo info = new ConnectorInfo();
     info.DesignerItemLeft = DesignerCanvas.GetLeft(this.ParentDesignerItem);
     info.DesignerItemTop = DesignerCanvas.GetTop(this.ParentDesignerItem);
     info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight);
     info.Orientation = this.Orientation;
     info.Position = this.Position;
     return info;
 }