using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Misc;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace FLY.Thick.Base.Common
{
    /// <summary>
    /// 动态数据,推送当前所有状态
    /// </summary>
    public class DynArea : INotifyPropertyChanged
    {
        public DynArea() 
        {
            this.PropertyChanged += new PropertyChangedEventHandler(DynArea_PropertyChanged);
        }

        void DynArea_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Hrs") 
            {
                if (Hrs == 0)
                {
                    SecuteLock = true;
                }
                else 
                {
                    SecuteLock = false;
                }
            }
        }

        #region BASE

        /// <summary>
        /// x100
        /// </summary>
        public int Thick { get; set; } = 3210;

        
        /// <summary>
        /// 编码器1 位置 脉冲
        /// </summary>
        public int Position { get; set; }


        /// <summary>
        /// 分区序号
        /// </summary>
        public int BoltIndex { get; set; }
        /// <summary>
        /// 分区号
        /// </summary>
        public int BoltNo
        {
            get { return BoltIndex + FirstBoltNo; }
        }
        /// <summary>
        /// AD值
        /// </summary>
        public int AD { get; set; } = 12345;
        /// <summary>
        /// 最大AD值
        /// </summary>
        public int ADMax { get; set; } = 65535;
        #endregion

        #region POSITION2

        /// <summary>
        /// 编码器2 位置 脉冲
        /// </summary>
        public int Position2 { get; set; }
        #endregion
        #region 扫描

        /// <summary>
        /// 最新样品AD
        /// </summary>
        [PropertyChanged.DoNotCheckEquality]
        public int[] SampleAD { get; set; }
 
        /// <summary>
        /// 数据是否有效, 当膜没有动时,为无效。 通过PLC获取,或编码器判断
        /// </summary>
        public bool DataValid { get; set; }

        /// <summary>
        /// 扫描方向
        /// </summary>
        public Misc.DIRECTION Direction { get; set; } = DIRECTION.FIX;

        /// <summary>
        /// 膜宽 mm
        /// </summary>
        public double Width { get; set; } = 600;
        /// <summary>
        /// 生产速度 m/min
        /// </summary>
        public double FilmVelocity { get; set; }
        /// <summary>
        /// 膜生产位置 m
        /// </summary>
        public double FilmPosition { get; set; }
        /// <summary>
        /// 测厚仪速度 m/min
        /// </summary>
        public double Velocity { get; set; }
        #endregion

        #region 运行状态
        /// <summary>
        /// 运行状态
        /// </summary>
        public CTRL_STATE ControllerState { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int AutoScanCounter { get; set; } = 5;

        #endregion

        #region IO

        public UInt16 IStatus { get; set; } = 0xffff;

        public UInt16 OStatus { get; set; } = 0xffff;

        #endregion

        #region 系统
        /// <summary>
        /// 系统剩余小时数
        /// </summary>
        public int Hrs { get; set; } = 3;

        /// <summary>
        /// FLYAD 连接状态
        /// </summary>
        public bool FLYADIsConnect { get; set; }



        /// <summary>
        /// 过期, 锁ing
        /// </summary>
        public bool SecuteLock { get; set; }

        /// <summary>
        /// 服务器连接断开
        /// </summary>
        public bool ServerIsConnected { get; set; }


        #endregion

        #region PROFILE 运行参数

        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; } = "default";


        /// <summary>
        /// 目标值 x100
        /// </summary>
        public int Target { get; set; } = 3000;



        /// <summary>
        /// 报警值 x100
        /// </summary>
        public int Alarm { get; set; } = 100;

        /// <summary>
        /// Y轴范围
        /// </summary>
        public int YRange 
        {
            get { return Alarm * 3; }
        }
        /// <summary>
        /// 斜率补偿
        /// </summary>
        public double Comp { get; set; } = 1;

        /// <summary>
        /// 平移补偿
        /// </summary>
        public int Shift { get; set; } = 0;


        /// <summary>
        /// 数据开始分区号
        /// </summary>
        public int DataBoltNoBegin { get; set; } = 0;


        /// <summary>
        /// 数据结束分区号
        /// </summary>
        public int DataBoltNoEnd { get; set; } = 30;

        /// <summary>
        /// 扫描范围 开始
        /// </summary>
        public int ScanBoltNoBegin { get; set; } = 0;

        /// <summary>
        /// 扫描范围 结束
        /// </summary>
        public int ScanBoltNoEnd { get; set; } = 30;

        #endregion

        #region BOLTMAP 分区信息

        /// <summary>
        /// 总分区数
        /// </summary>
        public int NBolts { get; set; } = 50;

        /// <summary>
        /// 开始分区号
        /// </summary>
        public int FirstBoltNo { get; set; }

        #endregion


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}