using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace Txgy.EWS.Client.Models
{
    public class CadText : BindableBase
    {
        private bool visible = true;

        public bool Visible
        {
            get { return visible; }
            set
            {
                SetProperty(ref visible, value);
            }
        }

        public FormattedText formattedText { get; set; }
        public Point origin { get; set; }
        public Point drawPoint { get; set; }
        public CadText()
        {

        }
        public CadText(FormattedText formattedText, Point origin, bool visible = true)
        {
            this.Visible = visible;
            this.formattedText = formattedText;
            this.origin = origin;
        }
    }
    public class CadLine : BindableBase
    {
        private bool visible = true;

        public bool Visible
        {
            get { return visible; }
            set
            {
                SetProperty(ref visible, value);
            }
        }

        public Pen pen { get; set; }
        public Point originPoint0 { get; set; }
        public Point originPoint1 { get; set; }
        public Point drawPoint0 { get; set; }
        public Point drawPoint1 { get; set; }
        public CadLine()
        {

        }

        public CadLine(Pen pen, Point point0, Point point1, bool visible = true)
        {
            this.Visible = visible;
            this.pen = pen;
            this.originPoint0 = point0;
            this.originPoint1 = point1;
        }
    }
    public class CadGeometry : BindableBase
    {
        //public PathGeometry DrawGeometry { get; set; }
        public bool IsClose { get; set; }
        public bool IsFill { get; set; }
        private bool visible = true;

        public bool Visible
        {
            get { return visible; }
            set
            {
                SetProperty(ref visible, value);
            }
        }
        public List<Point> originPoints { get; set; }
        public Point[] drawPoints { get; set; }
        //public void SetDrawGeometry()
        //{
        //    PolyLineSegment lineSegment = new PolyLineSegment();

        //    foreach (var item in this.originPoints)
        //    {
        //        lineSegment.Points.Add(item);
        //    }
        //    PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
        //    myPathSegmentCollection.Add(lineSegment);

        //    PathFigure pathFigure = new PathFigure();
        //    pathFigure.IsClosed = this.IsClose;
        //    pathFigure.IsFilled = this.IsFill;
        //    pathFigure.StartPoint = this.originPoints[0];
        //    pathFigure.Segments = myPathSegmentCollection;

        //    PathFigureCollection pthFigureCollection = new PathFigureCollection();
        //    pthFigureCollection.Add(pathFigure);

        //    this.DrawGeometry = new PathGeometry();
        //    this.DrawGeometry.Figures = pthFigureCollection;
        //}
        public static PathGeometry CreateCadGeometry(Point[] points, bool isClose, bool isFill)
        {
            PolyLineSegment lineSegment = new PolyLineSegment();

            foreach (var item in points)
            {
                lineSegment.Points.Add(item);
            }
            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(lineSegment);

            PathFigure pathFigure = new PathFigure();
            pathFigure.IsClosed = isClose;
            pathFigure.IsFilled = isFill;
            pathFigure.StartPoint = points[0];
            pathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection pthFigureCollection = new PathFigureCollection();
            pthFigureCollection.Add(pathFigure);

            PathGeometry pthGeometry = new PathGeometry();
            pthGeometry.Figures = pthFigureCollection;
            return pthGeometry;
        }
    }
}
