Esempio n. 1
0
        /// <summary>
        /// 绘制选择状态;
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="canvasProxy"></param>
        private void DrawSelectedState(ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            if (!IsSelected)
            {
                return;
            }

            if (Rectangle2D == null)
            {
                return;
            }

            //绘制四边的中点;
            var lines = Rectangle2D.GetLines();

            var rectLength = TolerantedScreenLength;

            foreach (var line in lines)
            {
                var point = line.MiddlePoint;
                var rect  = NativeGeometryExtensions.GetNativeSuroundingScreenRect(canvasProxy.ToScreen(point), rectLength, rectLength);
                canvas.NativeDrawRectangle(rect, HighLightEllipseColorBrush, HighLightLinePen);
            }

            //绘制中心;
            var centerPointX = Rectangle2D.GetVertexes().Average(p => p.X);
            var centerPointY = Rectangle2D.GetVertexes().Average(p => p.Y);

            var centerScreenPoint = canvasProxy.ToScreen(new Vector2D(centerPointX, centerPointY));
            var centerRect        = NativeGeometryExtensions.GetNativeSuroundingScreenRect(centerScreenPoint, rectLength, rectLength);

            canvas.NativeDrawRectangle(centerRect, HighLightEllipseColorBrush, HighLightLinePen);
        }
Esempio n. 2
0
        public override bool PointInObject(Vector2D point, ICanvasScreenConvertable canvasProxy)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            if (Ellipse2D == null)
            {
                return(false);
            }

#if DEBUG
#endif

            //判断是否与圆心有关系;
            var centerScreenPosition = canvasProxy.ToScreen(Ellipse2D.Center);
            var centerScreenRect     = NativeGeometryExtensions.GetNativeSuroundingScreenRect(
                centerScreenPosition,
                TolerantedScreenLength,
                TolerantedScreenLength
                );
            if (centerScreenRect.Contains(canvasProxy.ToScreen(point)))
            {
                return(true);
            }

            //若是圆,则通过点到圆心的距离判断;
            if (Ellipse2D.RadiusX == Ellipse2D.RadiusY)
            {
                var screenDis    = canvasProxy.ToScreen(Ellipse2D.Center.Distance(point));
                var screenRadius = canvasProxy.ToScreen(Ellipse2D.RadiusX);

                //若半径小于误差值,则判断距离是否小于误差值;
                if (screenRadius < TolerantedScreenLength)
                {
                    return(screenDis < TolerantedScreenLength);
                }
                //判断是否处于圆周上;
                else
                {
                    return(screenDis > screenRadius - TolerantedScreenLength &&
                           screenDis < screenRadius + TolerantedScreenLength);
                }
            }
            //To-Do,椭圆,未完成;
            else
            {
                return(Ellipse2D.Contains(point));
            }
        }
Esempio n. 3
0
        public override bool PointInObject(Vector2D point, ICanvasScreenConvertable canvasProxy)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            if (Rectangle2D == null)
            {
                return(false);
            }

            var screenPoint = canvasProxy.ToScreen(point);

            //判断与中心的关系;
            var centerScreenPoint = canvasProxy.ToScreen(Rectangle2D.Center);
            var screenRect        = Tida.Canvas.Infrastructure.Utils.NativeGeometryExtensions.GetNativeSuroundingScreenRect(
                centerScreenPoint,
                TolerantedScreenLength,
                TolerantedScreenLength
                );

            if (screenRect.Contains(screenPoint))
            {
                return(true);
            }

            //判断与四边的关系;
            var lines            = Rectangle2D.GetLines();
            var screenStartPoint = new Vector2D();
            var screenEndPoint   = new Vector2D();

            foreach (var line in lines)
            {
                canvasProxy.ToScreen(line.Start, screenStartPoint);
                canvasProxy.ToScreen(line.End, screenEndPoint);
                var screenLine2D = new Line2D(
                    screenStartPoint, screenEndPoint
                    );
                if (screenLine2D.Distance(screenPoint) < TolerantedScreenLength)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// 绘制某位置的选中状态(使用一个矩形);
        /// </summary>
        /// <param name="point"></param>
        public static void DrawSelectedPointState(Vector2D point, ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            if (canvas == null)
            {
                throw new ArgumentNullException(nameof(canvas));
            }

            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }


            //得到以某点为中心的视图矩形;
            var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(
                canvasProxy.ToScreen(point),
                TolerantedScreenLength,
                TolerantedScreenLength
                );

            canvas.NativeDrawRectangle(
                rect,
                HighLightRectColorBrush,
                HighLightLinePen
                );
        }
Esempio n. 5
0
        /// <summary>
        /// 交点绘制;
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="canvasProxy"></param>
        public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            if (canvas == null)
            {
                throw new ArgumentNullException(nameof(canvas));
            }

            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            //画叉;
            var screenPosition = canvasProxy.ToScreen(Position);
            var rectLength     = HighLightRectLength;
            //从左上到右下;
            var line1 = new Line2D(
                new Vector2D(screenPosition.X - rectLength, screenPosition.Y - rectLength),
                new Vector2D(screenPosition.X + rectLength, screenPosition.Y + rectLength)
                );
            //从左下到右上;
            var line2 = new Line2D(
                new Vector2D(screenPosition.X - rectLength, screenPosition.Y + rectLength),
                new Vector2D(screenPosition.X + rectLength, screenPosition.Y - rectLength)
                );

            canvas.NativeDrawLine(IntersectPen, line1);
            canvas.NativeDrawLine(IntersectPen, line2);
        }
Esempio n. 6
0
        public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            var screenPosition = canvasProxy.ToScreen(Position);
            var rectLength     = HighLightRectLength;
            var rect           = NativeGeometryExtensions.GetNativeSuroundingScreenRect(screenPosition, rectLength, rectLength);

            canvas.NativeDrawRectangle(rect, Background, LinePen);
        }
Esempio n. 7
0
        /// <summary>
        /// 判断画布中某个位置是否在某个圆弧附近;
        /// </summary>
        /// <param name="arc2D"></param>
        /// <param name="point"></param>
        /// <param name="canvasProxy"></param>
        /// <returns></returns>
        public static bool PointInArc(Arc2D arc2D, Vector2D point, ICanvasScreenConvertable canvasProxy)
        {
            if (canvasProxy == null)
            {
                return(false);
            }

            if (arc2D == null)
            {
                return(false);
            }

            //以视图单位为标准进行判断;
            var screenPoint          = canvasProxy.ToScreen(point);
            var arcCenterScreenPoint = canvasProxy.ToScreen(arc2D.Center);
            var screenRadius         = canvasProxy.ToScreen(arc2D.Radius);

            if (Math.Abs(arcCenterScreenPoint.Distance(screenPoint) - screenRadius) > TolerantedScreenLength)
            {
                return(false);
            }

            var centerToPointDirection = new Line2D(arc2D.Center, point).Direction;

            if (Extension.AreEqual(centerToPointDirection.Modulus(), 0))
            {
                return(false);
            }

            var centerToPointAngle = Extension.AngleFrom(
                new Vector3D(centerToPointDirection.X, centerToPointDirection.Y, 0),
                Vector3D.BasisX
                );

            if (arc2D.Angle > 0)
            {
                return(centerToPointAngle < arc2D.StartAngle + arc2D.Angle && centerToPointAngle > arc2D.StartAngle);
            }
            else
            {
                return(centerToPointAngle < arc2D.StartAngle && centerToPointAngle > arc2D.StartAngle + arc2D.Angle);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 判断画布中某个位置是否在某个线段附近;
        /// </summary>
        /// <param name="line2D"></param>
        /// <param name="point"></param>
        /// <param name="canvasProxy"></param>
        /// <returns></returns>
        public static bool PointInLine(Line2D line2D, Vector2D point, ICanvasScreenConvertable canvasProxy)
        {
            if (canvasProxy == null)
            {
                return(false);
            }

            if (line2D == null)
            {
                return(false);
            }

            //以视图单位为标准进行判断;
            var screenPoint  = canvasProxy.ToScreen(point);
            var screenLine2D = new Line2D(
                canvasProxy.ToScreen(line2D.Start),
                canvasProxy.ToScreen(line2D.End)
                );

            return(screenLine2D.Distance(screenPoint) < TolerantedScreenLength);
        }
Esempio n. 9
0
        /// <summary>
        /// 判断数学坐标中某个位置是否在另一个位置的附近;
        /// </summary>
        /// <param name="screenPosition0"></param>
        /// <param name="screenPosition1"></param>
        /// <returns></returns>
        public static bool GetIsSurround(Vector2D position0, Vector2D position1, ICanvasScreenConvertable canvasProxy)
        {
            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }


            if (position0 == null)
            {
                throw new ArgumentNullException(nameof(position0));
            }


            if (position1 == null)
            {
                throw new ArgumentNullException(nameof(position1));
            }

            return(GetIsSurround(canvasProxy.ToScreen(position0), canvasProxy.ToScreen(position1)));
        }
Esempio n. 10
0
        /// <summary>
        /// 绘制选择状态;
        /// </summary>
        /// <param name="canvas"></param>
        private void DrawSelectedState(ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            if (!IsSelected)
            {
                return;
            }

            if (Ellipse2D == null)
            {
                return;
            }

            if (Ellipse2D.Center == null)
            {
                return;
            }

            var centerScreenPoint = canvasProxy.ToScreen(Ellipse2D.Center);
            var screenRadiusX     = canvasProxy.ToScreen(Ellipse2D.RadiusX);
            var screenRadiusY     = canvasProxy.ToScreen(Ellipse2D.RadiusY);
            var rectLength        = TolerantedScreenLength;

            //依次绘制左、下、右、上、圆心的矩形;
            var points = new Vector2D[] {
                new Vector2D(centerScreenPoint.X - screenRadiusX, centerScreenPoint.Y),
                new Vector2D(centerScreenPoint.X, centerScreenPoint.Y - screenRadiusY),
                new Vector2D(centerScreenPoint.X + screenRadiusX, centerScreenPoint.Y),
                new Vector2D(centerScreenPoint.X, centerScreenPoint.Y + screenRadiusY),
                new Vector2D(centerScreenPoint.X, centerScreenPoint.Y),
            };


            foreach (var point in points)
            {
                var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(point, rectLength, rectLength);
                canvas.NativeDrawRectangle(rect, HighLightEllipseColorBrush, HighLightLinePen);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 将工程数学坐标转化为视图(以左上为原点)坐标;
        /// </summary>
        /// <param name="unitPoint"></param>
        /// <returns></returns>
        public static Vector2D ToScreen(this ICanvasScreenConvertable canvasProxy, Vector2D unitPoint)
        {
            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            if (unitPoint == null)
            {
                throw new ArgumentNullException(nameof(unitPoint));
            }

            var screenPoint = new Vector2D();

            canvasProxy.ToScreen(unitPoint, screenPoint);
            return(screenPoint);
        }
Esempio n. 12
0
        public override Rectangle2D2 GetNativeBoundingRect(ICanvasScreenConvertable canvasProxy)
        {
            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }


            var screenPosition = canvasProxy.ToScreen(Position);
            var rect           = NativeGeometryExtensions.GetNativeSuroundingScreenRect(
                screenPosition,
                HighLightRectLength,
                HighLightRectLength
                );


            return(rect);
        }
Esempio n. 13
0
        public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy)
        {
            base.Draw(canvas, canvasProxy);

            //检查两个关键位置是否为空;
            if (MousePositionTracker.LastMouseDownPosition == null || MousePositionTracker.CurrentHoverPosition == null)
            {
                return;
            }

            //绘制当前随鼠标位置移动的编辑线段;
            //绘制本次尚未完成的线段的起始点小正方形;
            var lastMouseDownScreenPosition = canvasProxy.ToScreen(MousePositionTracker.LastMouseDownPosition);
            var sideLength = HighLightRectLength;

            var startEditRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(lastMouseDownScreenPosition, sideLength, sideLength);

            canvas.NativeDrawRectangle(startEditRect, HighLightRectColorBrush, LinePen);

            //在外部加入了动态输入,此时显示线段编辑状态多余;
            //DrawEditingLineState(canvas, canvasProxy);
        }
Esempio n. 14
0
        /// <summary>
        /// 绘制线段;
        /// </summary>
        /// <param name="pen"></param>
        /// <param name="line"></param>
        public void DrawLine(Pen pen, Line2D line)
        {
            if (pen == null)
            {
                return;
            }

            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            ValidateDrawingContext();

            var screenPoint1 = _canvasProxy.ToScreen(line.Start);
            var screenPoint2 = _canvasProxy.ToScreen(line.End);

            //平台转换后再进行绘制;
            DrawingContext.DrawLine(
                PenAdapter.ConverterToSystemPen(pen),
                Vector2DAdapter.ConvertToSystemPoint(screenPoint1),
                Vector2DAdapter.ConvertToSystemPoint(screenPoint2)
                );
        }
Esempio n. 15
0
        /// <summary>
        /// 线段的辅助判断;
        /// 依次判断以下情况:1.中点 2.端点
        /// </summary>
        public static ISnapShape GetLine2DSnapShape(Line2D line2D, Vector2D position, ICanvasScreenConvertable canvasProxy)
        {
            if (line2D == null)
            {
                throw new ArgumentNullException(nameof(line2D));
            }


            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }


            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            /*判断是否是三点中一个附近的点*/

            var startPoint = line2D.Start;
            var endPoint   = line2D.End;

            if (startPoint == null)
            {
                throw new ArgumentNullException(nameof(startPoint));
            }

            if (endPoint == null)
            {
                throw new ArgumentNullException(nameof(endPoint));
            }

            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }

            if (canvasProxy == null)
            {
                throw new ArgumentNullException(nameof(canvasProxy));
            }

            var middlePoint = (startPoint + endPoint) / 2;

            Vector2D[] points = { startPoint, endPoint, middlePoint };

            var screenPoint = new Vector2D();
            var screenStart = new Vector2D();
            var screenEnd   = new Vector2D();

            var lineDir        = (endPoint - startPoint).Normalize();
            var verticalVector = new Vector2D(-lineDir.Y, lineDir.X);

            var screenPosition = canvasProxy.ToScreen(position);

            foreach (var point in points)
            {
                canvasProxy.ToScreen(point, screenPoint);
                if (!GetIsSurround(screenPosition, screenPoint))
                {
                    continue;
                }

                var unitLineLength = canvasProxy.ToUnit(4 * TolerantedScreenLength);

                var start = point - verticalVector * unitLineLength;
                var end   = point + verticalVector * unitLineLength;

                //作垂直于原线段的垂线;
                canvasProxy.ToScreen(start, screenStart);
                canvasProxy.ToScreen(end, screenEnd);

                var lineSnapShape = new ScreenLineSnapShape(new Line2D(screenStart, screenEnd), point);
                //若命中点为中点,则该垂线为中垂线,则修改颜色;
                if (point == middlePoint)
                {
                    lineSnapShape.LinePen = MiddleLinePen;
                }

                return(lineSnapShape);
            }

            return(null);
        }