using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLY.Thick.Base.Common;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Misc;

namespace FLY.Thick.Base.IService
{
    public delegate void ActiveEventHandler(object sender);
    public interface IBoltMapService : INotifyPropertyChanged
    {
        /// <summary>
        /// 第1个分区号
        /// </summary>
        int FirstBoltNo { get; set; }
        /// <summary>
        /// 分区表
        /// </summary>
        ObservableCollection<Range> Bolts { get; }

        /// <summary>
        /// 修改完上面的参数后，应用！！
        /// </summary>
        void Apply();

        #region 只用于描述 Bolts，没什么用 
        /// <summary>
        /// 最后一个分区号
        /// </summary>
        int LastBoltNo { get; }
        /// <summary>
        /// 平均分区间隔
        /// </summary>
        int BoltInterval { get; }
        /// <summary>
        /// 平均分区宽度
        /// </summary>
        int BoltWidth { get; }
        /// <summary>
        /// 脉冲范围 开始
        /// </summary>
        int PosBegin { get; }
        /// <summary>
        /// 脉冲范围 结束
        /// </summary>
        int PosEnd { get; }
        #endregion

        /// <summary>
        /// 查找边界类型
        /// </summary>
        BORDER_TYPE BorderType { get; set; }
        /// <summary>
        /// 开始边界分区号
        /// </summary>
        int BorderBoltNo_B { get; set; }
        /// <summary>
        /// 结束边界分区号
        /// </summary>
        int BorderBoltNo_E { get; set; }

        /// <summary>
        /// 平滑，以前后分区平均滤波 ，=0，只有自己，1，左右各一个
        /// </summary>
        int Smooth { get; set; }
        /// <summary>
        /// 修正完边界分区后应用。
        /// </summary>
        void ApplyBorder();

        event ActiveEventHandler ActiveEvent;
    }

    public interface IBoltMapBase
    {
        /// <summary>
        /// 第1分区号
        /// </summary>
        int FirstBoltNo { get; }
        /// <summary>
        /// 当前总分区数
        /// </summary>
        int NBolts { get; }
        /// <summary>
        /// 平滑
        /// </summary>
        int Smooth { set; get; }
        /// <summary>
        /// 边界对齐方式，只能是中间对齐
        /// </summary>
        BORDER_TYPE BorderType { get; }
        /// <summary>
        /// 获取当前使用分区表
        /// </summary>
        /// <param name="boltno1st"></param>
        /// <param name="bolts"></param>
        void GetBolts(out int boltno1st, out IEnumerable<Range> bolts);
        /// <summary>
        /// 给定分区号，获取扫描范围
        /// </summary>
        /// <param name="boltno"></param>
        /// <param name="posBegin"></param>
        /// <param name="posEnd"></param>
        void GetScanRange(Range boltno, out int posBegin, out int posEnd);
        /// <summary>
        /// 脉冲转获取分区序号
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        int GetBoltIndex_fromPos(int pos);
        #region 边界修正
        void InitExChange();

        void CalExChange(Misc.DIRECTION direction, Range bolt_r);

        int PositionExchange(Misc.DIRECTION direction, int position);

        int BoltExchange(Misc.DIRECTION direction, int bolt_pos);
        #endregion

        #region 用于动态生成分区数据

        void InitBoltAD();

        bool UpdateBoltAD(int[] data, int start_pos, int posOfGrid, Misc.DIRECTION direction, out int start_boltIndex, out int[] boltAD);

        #endregion


        int[] Map(Misc.DIRECTION direction, int posBegin, int posOfGrid, int[] dat);
    }
    
}
