private static Rect CorrectRect(Rect rect, LinkPlacement placement, double margin)
        {
            switch (placement)
            {
            case LinkPlacement.Left:
                rect.X -= DistanceToElement;
                break;

            case LinkPlacement.Top:
                rect.Y -= DistanceToElement;
                break;

            case LinkPlacement.Right:
                rect.Width += DistanceToElement;
                break;

            case LinkPlacement.Bottom:
                rect.Height += DistanceToElement;
                break;

            default:
                break;
            }

            return(rect);
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> GetByTree(int type)
        {
            LinkPlacement placement = (LinkPlacement)type;
            var           result    = await _service.GetByPlacementAsTree(placement);

            return(Ok(result));
        }
        private static Point GetNearestNeighborSource(LinkPlacement placement, Point endPoint, Rect rectSource, Rect rectSink, out bool flag)
        {
            Point n1, n2; // neighbors

            GetNeighborCorners(placement, rectSource, out n1, out n2);

            if (rectSink.Contains(n1))
            {
                flag = false;
                return(n2);
            }

            if (rectSink.Contains(n2))
            {
                flag = true;
                return(n1);
            }

            if ((Distance(n1, endPoint) <= Distance(n2, endPoint)))
            {
                flag = true;
                return(n1);
            }
            else
            {
                flag = false;
                return(n2);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Calculates the start point for this edge.
        /// </summary>
        /// <returns>Start point.</returns>
        public virtual PointD CalculateStartPoint()
        {
            #region Check Variables
            if (SourceAnchor == null)
            {
                throw new ArgumentNullException("SourceAnchor");
            }

            if (SourceAnchor.FromShape == null)
            {
                throw new ArgumentNullException("SourceAnchor.FromShape");
            }
            #endregion

            RectangleD sourceBounds = this.SourceAnchor.FromShape.AbsoluteBounds;

            LinkPlacement placement = GetLinkPlacement(true);
            switch (placement)
            {
            case LinkPlacement.Left:
                return(new PointD(sourceBounds.Left, sourceBounds.Center.Y));

            case LinkPlacement.Right:
                return(new PointD(sourceBounds.Right, sourceBounds.Center.Y));

            case LinkPlacement.Bottom:
                return(new PointD(sourceBounds.Center.X, sourceBounds.Bottom));

            case LinkPlacement.Top:
                return(new PointD(sourceBounds.Center.X, sourceBounds.Top));

            default:
                throw new NotSupportedException("placement");
            }
        }
        private static Point GetOffsetPoint(LinkPlacement placement, PointD absoluteLocation, Rect rect)
        {
            Point offsetPoint = new Point();

            switch (placement)
            {
            case LinkPlacement.Left:
                offsetPoint = new Point(rect.Left, absoluteLocation.Y);
                break;

            case LinkPlacement.Top:
                offsetPoint = new Point(absoluteLocation.X, rect.Top);
                break;

            case LinkPlacement.Right:
                offsetPoint = new Point(rect.Right, absoluteLocation.Y);
                break;

            case LinkPlacement.Bottom:
                offsetPoint = new Point(absoluteLocation.X, rect.Bottom);
                break;

            default:
                break;
            }

            return(offsetPoint);
        }
Esempio n. 6
0
        public async Task <List <LinkDto> > GetByPlacementAsTree(LinkPlacement placement)
        {
            var entityList = await UnitOfWork.LinkRepository.GetByPlcement(placement);

            var parentEntities = entityList.Where(x => !x.ParentId.HasValue);

            return(parentEntities.MapTo <List <LinkDto> >());
        }
        private static Rect GetRectWithMargin(LinkPlacement placement, NodeShape sourceShape, double margin)
        {
            Rect rect = new Rect(sourceShape.AbsoluteLocation.X,
                                 sourceShape.AbsoluteLocation.Y,
                                 sourceShape.Bounds.Width,
                                 sourceShape.Bounds.Height);

            rect.Inflate(margin, margin);

            return(rect);
        }
Esempio n. 8
0
        /// <summary>
        /// Calculates the end point for this edge.
        /// </summary>
        /// <returns>End point.</returns>
        public virtual PointD CalculateEndPoint()
        {
            #region Check Variables
            if (TargetAnchor == null)
            {
                throw new ArgumentNullException("TargetAnchor");
            }

            if (TargetAnchor.ToShape == null)
            {
                throw new ArgumentNullException("TargetAnchor.ToShape");
            }
            #endregion

            LinkPlacement placement;

            if (this.FromShape == this.ToShape)
            {
                LinkPlacement pStart = GetLinkPlacement(true);
                if (pStart == LinkPlacement.Bottom || pStart == LinkPlacement.Top)
                {
                    placement = LinkPlacement.Right;
                }
                else
                {
                    placement = LinkPlacement.Top;
                }
            }
            else
            {
                placement = GetLinkPlacement(false);
            }

            RectangleD targetBounds = this.TargetAnchor.ToShape.AbsoluteBounds;
            switch (placement)
            {
            case LinkPlacement.Left:
                return(new PointD(targetBounds.Left, targetBounds.Center.Y));

            case LinkPlacement.Right:
                return(new PointD(targetBounds.Right, targetBounds.Center.Y));

            case LinkPlacement.Bottom:
                return(new PointD(targetBounds.Center.X, targetBounds.Bottom));

            case LinkPlacement.Top:
                return(new PointD(targetBounds.Center.X, targetBounds.Top));

            default:
                throw new NotSupportedException("placement");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Set an anchor position based on a horizontal and verical changes proposed.
        /// </summary>
        /// <param name="horizontalChange">Horizontal change.</param>
        /// <param name="verticalChange">Vertical change.</param>
        /// <returns>Calculated position.</returns>
        public virtual void SetToAnchorPosition(double horizontalChange, double verticalChange)
        {
            PointD        proposedPoint = new PointD(this.EndEdgePoint.X + horizontalChange, this.EndEdgePoint.Y + verticalChange);
            LinkPlacement placement     = LinkShape.GetLinkPlacement(this.ShapeElement.ToShape.AbsoluteBounds, proposedPoint);

            PointD calculatedLocation = LinkShape.CalculateLocation(placement, this.ShapeElement.ToShape.AbsoluteBounds, proposedPoint);

            if (this.ShapeElement.EndPoint != calculatedLocation)
            {
                using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Move To Anchor"))
                {
                    this.ShapeElement.LinkPlacementEnd = placement;
                    this.ShapeElement.SetEndPoint(calculatedLocation);
                    this.ShapeElement.Layout(FixedGeometryPoints.Target);

                    transaction.Commit();
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Update link placement end.
        /// </summary>
        public void UpdateLinkPlacementTarget()
        {
            if (this.TargetAnchor != null)
            {
                if (this.TargetAnchor.ToShape != null)
                {
                    LinkPlacementEnd = GetLinkPlacement(this.TargetAnchor.ToShape.AbsoluteBounds, this.EndPoint);
                }

                if (this.TargetAnchor.AbsoluteLocation != this.EndPoint)
                {
                    if (!this.Store.InSerializationTransaction)
                    {
                        this.TargetAnchor.DiscardLocationChange = true;
                    }
                    this.TargetAnchor.AbsoluteLocation = this.EndPoint;
                }
            }
        }
Esempio n. 11
0
        private static Orientation GetOrientation(LinkPlacement sourceOrientation)
        {
            switch (sourceOrientation)
            {
            case LinkPlacement.Left:
                return(Orientation.Horizontal);

            case LinkPlacement.Top:
                return(Orientation.Vertical);

            case LinkPlacement.Right:
                return(Orientation.Horizontal);

            case LinkPlacement.Bottom:
                return(Orientation.Vertical);

            default:
                throw new Exception("Unknown ConnectorOrientation");
            }
        }
Esempio n. 12
0
        private static LinkPlacement GetOpositeOrientation(LinkPlacement connectorOrientation)
        {
            switch (connectorOrientation)
            {
            case LinkPlacement.Left:
                return(LinkPlacement.Right);

            case LinkPlacement.Top:
                return(LinkPlacement.Bottom);

            case LinkPlacement.Right:
                return(LinkPlacement.Left);

            case LinkPlacement.Bottom:
                return(LinkPlacement.Top);

            default:
                return(LinkPlacement.Top);
            }
        }
Esempio n. 13
0
        private static void GetNeighborCorners(LinkPlacement orientation, Rect rect, out Point n1, out Point n2)
        {
            switch (orientation)
            {
            case LinkPlacement.Left:
                n1 = rect.TopLeft; n2 = rect.BottomLeft;
                break;

            case LinkPlacement.Top:
                n1 = rect.TopLeft; n2 = rect.TopRight;
                break;

            case LinkPlacement.Right:
                n1 = rect.TopRight; n2 = rect.BottomRight;
                break;

            case LinkPlacement.Bottom:
                n1 = rect.BottomLeft; n2 = rect.BottomRight;
                break;

            default:
                throw new Exception("No neighour corners found!");
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Calculates a location based on the shape dimensions as well as the proposed location.
        /// </summary>
        /// <param name="shapeDimensions">Dimensions of the shape, this link start/end is created at.</param>
        /// <param name="proposedLocation">Proposed location of the link start/end.</param>
        /// <returns>Calculated location.</returns>
        public static PointD CalculateLocation(RectangleD shapeDimensions, PointD proposedLocation)
        {
            LinkPlacement placement = GetLinkPlacement(shapeDimensions, proposedLocation);

            return(CalculateLocation(placement, shapeDimensions, proposedLocation));
        }
Esempio n. 15
0
        internal static List <PointD> GetConnectionLineSimple(LinkShape linkShape, NodeShape source, PointD startPointE, NodeShape target, PointD endPointE, LinkPlacement targetPlacement)
        {
            List <PointD> linePointsRet = new List <PointD>();
            List <Point>  linePoints    = new List <Point>();

            Rect rectSource = GetRectWithMargin(linkShape.LinkPlacementStart, source, 7.0);

            Point startPoint = GetOffsetPoint(linkShape.LinkPlacementStart, startPointE, rectSource);
            Point endPoint   = endPointE.ToPoint();

            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(linkShape.LinkPlacementStart, 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(linkShape.LinkPlacementStart, rectSource, out n1, out n2);
                        if (sideFlag)
                        {
                            linePoints.Add(n1);
                        }
                        else
                        {
                            linePoints.Add(n2);
                        }

                        linePoints.Add(endPoint);
                        break;
                    }
                }
            }
            else
            {
                linePoints.Add(endPoint);
            }

            linePoints = OptimizeLinePoints(linePoints, new Rect[] { rectSource }, linkShape.LinkPlacementStart, targetPlacement);

            foreach (Point p in linePoints)
            {
                linePointsRet.Add(new PointD(p));
            }

            return(linePointsRet);
        }
Esempio n. 16
0
        private static List <Point> OptimizeLinePoints(List <Point> linePoints, Rect[] rectangles, LinkPlacement sourceOrientation, LinkPlacement 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)
                {
                    LinkPlacement orientationFrom;
                    LinkPlacement 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 == LinkPlacement.Left || orientationFrom == LinkPlacement.Right) &&
                        (orientationTo == LinkPlacement.Left || orientationTo == LinkPlacement.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 == LinkPlacement.Top || orientationFrom == LinkPlacement.Bottom) &&
                        (orientationTo == LinkPlacement.Top || orientationTo == LinkPlacement.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 == LinkPlacement.Left || orientationFrom == LinkPlacement.Right) &&
                        (orientationTo == LinkPlacement.Top || orientationTo == LinkPlacement.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == LinkPlacement.Top || orientationFrom == LinkPlacement.Bottom) &&
                        (orientationTo == LinkPlacement.Left || orientationTo == LinkPlacement.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
Esempio n. 17
0
        public async Task <List <LinkDto> > GetByPlacement(LinkPlacement placement)
        {
            var entityList = await UnitOfWork.LinkRepository.GetByPlcement(placement);

            return(entityList.MapTo <List <LinkDto> >());
        }
        public async Task <List <Link> > GetByPlcement(LinkPlacement placement)
        {
            var result = await GetQueryable().Where(x => x.LinkPlacement == placement).ToListAsync();

            return(result);
        }
Esempio n. 19
0
        /// <summary>
        /// Calculates a location based on the shape dimensions as well as the proposed location.
        /// </summary>
        /// <param name="placement">Link placement.</param>
        /// <param name="shapeDimensions">Dimensions of the shape, this link start/end is created at.</param>
        /// <param name="proposedLocation">Proposed location of the link start/end.</param>
        /// <returns>Calculated location.</returns>
        public static PointD CalculateLocation(LinkPlacement placement, RectangleD shapeDimensions, PointD proposedLocation)
        {
            double x = proposedLocation.X;
            double y = proposedLocation.Y;

            double itemWidth = 7;
            double itemHeight = 7;

            switch (placement)
            {
                case LinkPlacement.Left:
                    x = shapeDimensions.Left - itemWidth;
                    if (y <= (shapeDimensions.Top - itemHeight))
                        y = shapeDimensions.Top - itemHeight;
                    else if (y > shapeDimensions.Bottom)
                        y = shapeDimensions.Bottom;
                    break;

                case LinkPlacement.Top:
                    y = shapeDimensions.Top - itemHeight;
                    if (x <= (shapeDimensions.Left - itemWidth))
                        x = shapeDimensions.Left - itemWidth;
                    else if (x > shapeDimensions.Right)
                        x = shapeDimensions.Right;
                    break;

                case LinkPlacement.Right:
                    x = shapeDimensions.Right + 3.4 * 2;
                    if (y <= (shapeDimensions.Top - itemHeight))
                        y = shapeDimensions.Top - itemHeight;
                    else if (y > shapeDimensions.Bottom)
                        y = shapeDimensions.Bottom;
                    break;

                case LinkPlacement.Bottom:
                    y = shapeDimensions.Bottom + 3.4 * 2;
                    if (x <= (shapeDimensions.Left - itemWidth))
                        x = shapeDimensions.Left - itemWidth;
                    else if (x > shapeDimensions.Right)
                        x = shapeDimensions.Right;
                    break;
            }

            return new PointD(x, y);
        }
Esempio n. 20
0
        /// <summary>
        /// Calculates a location based on the shape dimensions as well as the proposed location.
        /// </summary>
        /// <param name="placement">Link placement.</param>
        /// <param name="shapeDimensions">Dimensions of the shape, this link start/end is created at.</param>
        /// <param name="proposedLocation">Proposed location of the link start/end.</param>
        /// <returns>Calculated location.</returns>
        public static PointD CalculateLocation(LinkPlacement placement, RectangleD shapeDimensions, PointD proposedLocation)
        {
            double x = proposedLocation.X;
            double y = proposedLocation.Y;

            double itemWidth  = 7;
            double itemHeight = 7;

            switch (placement)
            {
            case LinkPlacement.Left:
                x = shapeDimensions.Left - itemWidth;
                if (y <= (shapeDimensions.Top - itemHeight))
                {
                    y = shapeDimensions.Top - itemHeight;
                }
                else if (y > shapeDimensions.Bottom)
                {
                    y = shapeDimensions.Bottom;
                }
                break;

            case LinkPlacement.Top:
                y = shapeDimensions.Top - itemHeight;
                if (x <= (shapeDimensions.Left - itemWidth))
                {
                    x = shapeDimensions.Left - itemWidth;
                }
                else if (x > shapeDimensions.Right)
                {
                    x = shapeDimensions.Right;
                }
                break;

            case LinkPlacement.Right:
                x = shapeDimensions.Right + 3.4 * 2;
                if (y <= (shapeDimensions.Top - itemHeight))
                {
                    y = shapeDimensions.Top - itemHeight;
                }
                else if (y > shapeDimensions.Bottom)
                {
                    y = shapeDimensions.Bottom;
                }
                break;

            case LinkPlacement.Bottom:
                y = shapeDimensions.Bottom + 3.4 * 2;
                if (x <= (shapeDimensions.Left - itemWidth))
                {
                    x = shapeDimensions.Left - itemWidth;
                }
                else if (x > shapeDimensions.Right)
                {
                    x = shapeDimensions.Right;
                }
                break;
            }

            return(new PointD(x, y));
        }
Esempio n. 21
0
        private static Point GetNearestVisibleNeighborTarget(Point currentPoint, Point endPoint, Anchor target, LinkPlacement placement, Rect rectSource, Rect rectSink)
        {
            Point s1, s2; // neighbors on sink side

            GetNeighborCorners(placement, rectSink, out s1, out s2);

            bool flag1 = IsPointVisible(currentPoint, s1, new Rect[] { rectSource, rectSink });
            bool flag2 = IsPointVisible(currentPoint, s2, new Rect[] { rectSource, rectSink });

            if (flag1)     // s1 visible
            {
                if (flag2) // s1 and s2 visible
                {
                    if (rectSink.Contains(s1))
                    {
                        return(s2);
                    }

                    if (rectSink.Contains(s2))
                    {
                        return(s1);
                    }

                    if ((Distance(s1, endPoint) <= Distance(s2, endPoint)))
                    {
                        return(s1);
                    }
                    else
                    {
                        return(s2);
                    }
                }
                else
                {
                    return(s1);
                }
            }
            else // s1 not visible
            {
                if (flag2) // only s2 visible
                {
                    return(s2);
                }
                else // s1 and s2 not visible
                {
                    return(new Point(double.NaN, double.NaN));
                }
            }
        }
Esempio n. 22
0
        protected virtual void UpdateEdgePoints()
        {
            if (EdgePoints == null)
            {
                this.edgePointsVM = new ObservableCollection <EdgePointViewModel>();
            }

            EdgePoints.Clear();
            for (int i = 0; i < this.ShapeElement.EdgePoints.Count; i++)
            {
                EdgePointVMType t = EdgePointVMType.Normal;
                if (i == 0)
                {
                    t = EdgePointVMType.Start;
                }
                else if (i == this.ShapeElement.EdgePoints.Count - 1)
                {
                    t = EdgePointVMType.End;
                }
                else
                {
                    continue;   // TODO
                }
                EdgePointViewModel vm = new EdgePointViewModel(this.ViewModelStore, this.ShapeElement.EdgePoints[i], t);
                if (i > 0 && i < this.ShapeElement.EdgePoints.Count - 1)
                {
                    //vm.EdgePointOperation = EdgePointVMOperation.m
                }
                else
                {
                    RectangleD bounds;
                    if (t == EdgePointVMType.Start)
                    {
                        bounds = this.ShapeElement.FromShape.AbsoluteBounds;
                    }
                    else
                    {
                        bounds = this.ShapeElement.ToShape.AbsoluteBounds;
                    }

                    EdgePoint     p         = this.ShapeElement.EdgePoints[i];
                    LinkPlacement placement = LinkShape.GetLinkPlacement(bounds, new PointD(p.X, p.Y));
                    switch (placement)
                    {
                    case LinkPlacement.Bottom:
                        vm.EdgePointSide = EdgePointVMSide.Bottom;
                        break;

                    case LinkPlacement.Left:
                        vm.EdgePointSide = EdgePointVMSide.Left;
                        break;

                    case LinkPlacement.Right:
                        vm.EdgePointSide = EdgePointVMSide.Right;
                        break;

                    case LinkPlacement.Top:
                        vm.EdgePointSide = EdgePointVMSide.Top;
                        break;
                    }
                }
                EdgePoints.Add(vm);
            }

            OnPropertyChanged("EdgePoints");
            OnPropertyChanged("StartEdgePoint");
            OnPropertyChanged("EndEdgePoint");
            OnPropertyChanged("MiddleEdgePoint");
        }
Esempio n. 23
0
        /// <summary>
        /// Update link placement end.
        /// </summary>
        public void UpdateLinkPlacementTarget()
        {
            if (this.TargetAnchor != null)
            {
                if (this.TargetAnchor.ToShape != null)
                    LinkPlacementEnd = GetLinkPlacement(this.TargetAnchor.ToShape.AbsoluteBounds, this.EndPoint);

                if (this.TargetAnchor.AbsoluteLocation != this.EndPoint)
                {
                    if (!this.Store.InSerializationTransaction)
                        this.TargetAnchor.DiscardLocationChange = true;
                    this.TargetAnchor.AbsoluteLocation = this.EndPoint;
                }
            }
        }