using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Extender
{
    public sealed class ExtenderInterface
    {
        //只读的静态成员
        private static readonly ExtenderInterface instance = new ExtenderInterface();

        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        //C#的静态构造函数只有在当其类的实例被创建或者有静态成员被引用时执行，
        //在整个应用程序域中只会被执行一次。
        static ExtenderInterface()
        {
        }
        private ExtenderInterface()
        {
        }

        //使用这个实例
        public static ExtenderInterface Instance
        {
            get
            {
                return instance;
            }
        }

        //其他使用的成员变量
        private  IExtenderControl m_iExtender = null; //成员变量
        //private readonly IExtenderControl m_iExtender = new Extender(); //成员变量

        public IExtenderControl IExtender
        {
            get {
                if (m_iExtender == null)
                {
                    m_iExtender = new ExtenderWrapper();
                }
                return m_iExtender;

            }
        } //属性,只能当前类创建 
        ~ExtenderInterface()
        {

            if (m_iExtender!=null)
            {
                m_iExtender.CloseExtender();
            }
           
        }
    }

    public class Segment
    {
        private int m_nX;
        private int m_nY;
        private int m_nLength;

        public int X
        {
            get { return m_nX; }
            set {
                if (value > 0)
                {
                    m_nX = value;
                }
            }
        }

        public int Y
        {
            get { return m_nY; }
            set
            {
                if (value > 0)
                {
                    m_nY = value;
                }
            }
        }

        public int Length
        {
            get { return m_nLength; }
            set
            {
                if (value > 0)
                {
                    m_nLength = value;
                }
            }
        }
    };


    //Extender控制
    public interface IExtenderControl
    {

        //缩放
        float GetMagnification();
        Boolean SetMagnification(float set);

        //焦距
        float GetWorkingDistance();
        Boolean SetWorkingDistance(float set);
        
        //亮度
        float GetBrightness();
        Boolean SetBrightness(float set);

        //对比度
        float GetContrast();
        Boolean SetContrast(float set);

        //SEM电压
        float GetSEMVoltage();
        Boolean SetSEMVoltage(float set);

        //样品台        
        float[] GetStagePosition();
        Boolean SetStagePosition(float[] set);
        float GetStageAtX();
        float GetStageAtY();
        float GetStageAtZ();
        float GetStageAtT();
        float GetStageAtR();        
        Boolean SetStageGotoX(float set);
        Boolean SetStageGotoY(float set);
        Boolean SetStageGotoZ(float set);
        Boolean SetStageGotoT(float set);
        Boolean SetStageGotoR(float set);
        Boolean MoveStageXY(float x, float y);

        //拍图
        Boolean GrabImage(String filename, short xoff, short yoff, short width, short height, short type);
        //采集参数设置
        Boolean SetImageAcquistionSetting(double a_dDwellTime, int a_nImageType, double a_dImageScanSize);

        //获取分辨率
        int[] GetImageStore();
        //设置分辨率
        Boolean SetImageStore(float set);
        //获取bitmap
        Bitmap GetBitmap();

        bool IsAcquiringSpectrum();

        //X-ray
        //点采集
        Boolean XrayPointCollecting(double dMilliSecondsTime, double x, double y, out long[] XrayData, out Dictionary<string, double> a_listElement);
        //Boolean XrayPointCollectiong1(double dMilliSecondsTime, int x, int y, out long[] XrayData, out Dictionary<string, double> a_listElement);
        //面采集
        Boolean XrayAreaCollectiong( double dMilliSecondsTime, List<Segment> a_listChord, out long[] XrayData, out Dictionary<string, double> a_listElement);
        void CloseExtender();
        void BeginMultipleAquisition();
        void EndMultipleAquisition();
    }
}
