Пример #1
0
        public Point GetPointOfIntersection(Point beginPoint, Point endPoint, DirectionMoveType type)
        {
            double endPointRadius   = 4;
            double beginPointRadius = 4;
            Point  p = new Point();

            //if (Type == FlowNodeType.INTERACTION
            //     || Type == FlowNodeType.AND_MERGE
            //    || Type == FlowNodeType.OR_MERGE
            //    || Type == FlowNodeType.VOTE_MERGE
            //    )
            //{

            #region


            if (Math.Abs(endPoint.X - beginPoint.X) <= PictureWidth / 2 &&
                Math.Abs(endPoint.Y - beginPoint.Y) <= PictureHeight / 2)
            {
                p = endPoint;
            }
            else
            {
                //起始点坐标和终点坐标之间的夹角(相对于Y轴坐标系)
                double angle = Math.Abs(Math.Atan((endPoint.X - beginPoint.X) / (endPoint.Y - beginPoint.Y)) * 180.0 / Math.PI);
                //节点的长和宽之间的夹角(相对于Y轴坐标系)
                double angel2 = Math.Abs(Math.Atan(PictureWidth / PictureHeight) * 180.0 / Math.PI);
                //半径
                double radio = PictureHeight < PictureWidth ? PictureHeight / 2 : PictureWidth / 2;

                if (angle <= angel2)               //起始点坐标在终点坐标的上方,或者下方
                {
                    if (endPoint.Y < beginPoint.Y) //在上方
                    {
                        if (endPoint.X < beginPoint.X)
                        {
                            p.X = endPoint.X + Math.Tan(Math.PI * angle / 180.0) * radio;
                        }
                        else
                        {
                            p.X = endPoint.X - Math.Tan(Math.PI * angle / 180.0) * radio;
                        }

                        p.Y = endPoint.Y + PictureHeight / 2;
                    }
                    else//在下方
                    {
                        if (endPoint.X < beginPoint.X)
                        {
                            p.X = endPoint.X + Math.Tan(Math.PI * angle / 180.0) * radio;
                        }
                        else
                        {
                            p.X = endPoint.X - Math.Tan(Math.PI * angle / 180.0) * radio;
                        }

                        p.Y = endPoint.Y - PictureHeight / 2;
                    }
                }

                else//左方或者右方
                {
                    if (endPoint.X < beginPoint.X)//在右方
                    {
                        p.X = endPoint.X + PictureWidth / 2;
                        if (endPoint.Y < beginPoint.Y)
                        {
                            p.Y = endPoint.Y + Math.Tan(Math.PI * (90 - angle) / 180.0) * radio;
                        }
                        else
                        {
                            p.Y = endPoint.Y - Math.Tan(Math.PI * (90 - angle) / 180.0) * radio;
                        }
                    }
                    else//在左方
                    {
                        p.X = endPoint.X - PictureWidth / 2;
                        if (endPoint.Y < beginPoint.Y)
                        {
                            p.Y = endPoint.Y + Math.Tan(Math.PI * (90 - angle) / 180.0) * radio;
                        }
                        else
                        {
                            p.Y = endPoint.Y - Math.Tan(Math.PI * (90 - angle) / 180.0) * radio;
                        }
                    }
                }
            }

            if (type == DirectionMoveType.End)
            {
                p.X -= endPointRadius;
                p.Y -= endPointRadius;
            }
            if (type == DirectionMoveType.Begin)
            {
                p.X -= beginPointRadius;
                p.Y -= beginPointRadius;
            }

            #endregion
            //  }

            //else if (Type == FlowNodeType.INITIAL
            //  || Type == FlowNodeType.COMPLETION
            //  || Type == FlowNodeType.AUTOMATION
            //   || Type == FlowNodeType.DUMMY
            //    || Type == FlowNodeType.SUBPROCESS || Type == FlowNodeType.STATIONODE)
            //{
            //    #region
            //    if (Math.Abs(endPoint.X - beginPoint.X) <= PictureWidth / 2
            //        && Math.Abs(endPoint.Y - beginPoint.Y) <= PictureHeight / 2)
            //    {
            //        p = endPoint;
            //    }
            //    else
            //    {
            //        double radial = (PictureWidth < PictureHeight ? PictureWidth : PictureHeight) / 2;
            //        double bc = Math.Sqrt((endPoint.X - beginPoint.X) * (endPoint.X - beginPoint.X) + (endPoint.Y - beginPoint.Y) * (endPoint.Y - beginPoint.Y));
            //        p.X = endPoint.X - (endPoint.X - beginPoint.X) * radial / bc;
            //        p.Y = endPoint.Y - (endPoint.Y - beginPoint.Y) * radial / bc;


            //    }
            //    if (type == DirectionMoveType.End)
            //    {
            //        p.X -= endPointRadius;
            //        p.Y -= endPointRadius;
            //    }
            //    if (type == DirectionMoveType.Begin)
            //    {
            //        p.X -= beginPointRadius;
            //        p.Y -= beginPointRadius;
            //    }
            //    #endregion
            //}

            //else if (Type == FlowNodeType.AND_BRANCH
            //     || Type == FlowNodeType.OR_BRANCH
            //   )
            //{
            //    if (Math.Abs(endPoint.X - beginPoint.X) <= PictureWidth / 2
            //        && Math.Abs(endPoint.Y - beginPoint.Y) <= PictureHeight / 2)
            //    {
            //        p = endPoint;

            //        if (type == DirectionMoveType.End)
            //        {
            //            p.X -= endPointRadius;
            //            p.Y -= endPointRadius;
            //        }
            //        if (type == DirectionMoveType.Begin)
            //        {
            //            p.X -= beginPointRadius;
            //            p.Y -= beginPointRadius;
            //        }
            //    }
            //    else
            //    {

            //        //double angle = Math.Abs(Math.Atan((endPoint.X - beginPoint.X) / (endPoint.Y - beginPoint.Y)) * 180.0 / Math.PI);
            //        //if (angle < 45)
            //        //{
            //        //    if (endPoint.Y < beginPoint.Y)
            //        //    {
            //        //        p = ThisPointCollection[2];
            //        //    }
            //        //    else
            //        //    {
            //        //        p = ThisPointCollection[0];

            //        //    }

            //        //}

            //        //else
            //        //{
            //        //    if (endPoint.X < beginPoint.X)
            //        //    {
            //        //        p = ThisPointCollection[1];

            //        //    }
            //        //    else
            //        //    {
            //        //        p = ThisPointCollection[3];

            //        //    }
            //        //}


            //        double x = 0, y = 0;
            //        double tan = Math.Abs((endPoint.Y - beginPoint.Y) / (beginPoint.X - endPoint.X));

            //        if (endPoint.X <= beginPoint.X && endPoint.Y >= beginPoint.Y)//右上
            //        {
            //            y = (endPoint.Y + (ThisPointCollection[0].Y + (double)GetValue(Canvas.TopProperty)) * tan) / (1 + tan);

            //            x = (endPoint.Y - y) / tan + endPoint.X;
            //        }
            //        else if (this.CenterPoint.X <= beginPoint.X && this.CenterPoint.Y <= beginPoint.Y)//右下
            //        {
            //            y = (endPoint.Y + (ThisPointCollection[2].Y + (double)GetValue(Canvas.TopProperty)) * tan) / (1 + tan);
            //            x = (y - endPoint.Y) / tan + endPoint.X;
            //        }
            //        else if (this.CenterPoint.X >= beginPoint.X && this.CenterPoint.Y >= beginPoint.Y)//左上
            //        {
            //            y = (endPoint.Y + (ThisPointCollection[0].Y + (double)GetValue(Canvas.TopProperty)) * tan) / (1 + tan);
            //            x = (y - endPoint.Y) / tan + endPoint.X;

            //        }
            //        else if (this.CenterPoint.X >= beginPoint.X && this.CenterPoint.Y <= beginPoint.Y)//左下
            //        {
            //            y = (endPoint.Y + (ThisPointCollection[2].Y + (double)GetValue(Canvas.TopProperty)) * tan) / (1 + tan);
            //            x = (endPoint.Y - y) / tan + endPoint.X;
            //        }
            //        p.Y = y;
            //        p.X = x;
            //        if (type == DirectionMoveType.End)
            //        {
            //            p.X += -endPointRadius;
            //            p.Y += -endPointRadius;
            //        }
            //        if (type == DirectionMoveType.Begin)
            //        {
            //            p.X += -beginPointRadius;
            //            p.Y += -beginPointRadius;
            //        }
            //    }
            //}

            return(p);
        }
 public Point GetPointOfIntersection(Point beginPoint, Point endPoint, DirectionMoveType type)
 {
     return(new Point(0, 0));
 }