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

namespace SmartSEMControl
{
    //sealed, 避免继承出新类造成重构
    public sealed class FactoryHardware
    {
        //只读的静态成员
        private static readonly FactoryHardware instance = new FactoryHardware();

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

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

        //其他使用的成员变量
        private readonly ISEMControl m_iSEM = new SmartSEM(); //成员变量

        public ISEMControl ISEM
        {
            get { return m_iSEM; }
        } //属性,只能当前类创建         

    }
    //SEM控制
    public interface ISEMControl
    {
        Boolean CmdLineScan();
        Boolean CmdPixelScan();

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

        //FIB缩放
        float GetFIBMagnification();
        Boolean SetFIBMagnification(float set);

        //焦距
        float GetWorkingDistance();
        Boolean SetWorkingDistance(float set);

        //FIB焦距
        float GetFIBObjectivePotential();
        Boolean SetFIBObjectivePotential(float set);

        //自动对焦
        Boolean CmdAutoFocusCoarse();
        Boolean CmdAutoFocusFine();

        //亮度
        float GetBrightness();
        Boolean SetBrightness(float set);

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

        //自动亮度
        float GetAutoVideo();
        Boolean SetAutoVideoOff();
        Boolean SetAutoVideoBrightness();
        Boolean SetAutoVideoContrast();
        Boolean SetAutoVideoBrightnessAndContrast();
        Boolean SetAutoBright(float set);
        Boolean SetAutoContrast(float set);

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

        //SEM电流
        float GetSEMIPROBE();
        Boolean SetSEMIPROBE(float set);

        //消像散
        float GetAstigmatismX();
        float GetAstigmatismY();
        Boolean SetAstigmatismX(float set);
        Boolean SetAstigmatismY(float set);

        //FIB消像散
        float GetFIBAstigmatismX();
        float GetFIBAstigmatismY();
        Boolean SetFIBAstigmatismX(float set);
        Boolean SetFIBAstigmatismY(float set);

        //自动消像散
        Boolean CmdAutoStig();

        //角度补偿
        float GetTiltAngle();
        Boolean SetTiltAngleOn();
        Boolean SetTiltAngleOff();
        Boolean SetTiltAngle(float set);

        //抓图
        Boolean GrabImage(String filename, short xoff, short yoff, short width, short height, short type);
        //扫描周期
        float GetCycleTime();
        //读取图像冻结状态
        float GetImageFrozen();
        //冻结
        Boolean ImageFrozen();
        //解冻
        Boolean ImageLive();
        //获取分辨率
        int[] GetImageStore();
        //设置分辨率
        Boolean SetImageStore(float set);

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

        //Scan Rotate角度接口
        float GetScanRotation();
        Boolean SetScanRotationOn();
        Boolean SetScanRotationOff();
        Boolean SetScanRotation(float set);

        //像素读取PixelSize
        float GetPixelSize();

        //电子束移动接口
        float GetBeamShiftX();
        float GetBeamShiftY();
        Boolean SetBeamShiftX(float set);
        Boolean SetBeamShiftY(float set);

        //电子束移动距离接口
        float GetBeamOffsetX();
        float GetBeamOffsetY();
        Boolean SetBeamOffsetX(float set);
        Boolean SetBeamOffsetY(float set);

        //FIB电子束移动接口
        float GetFIBBeamShiftX();
        float GetFIBBeamShiftY();
        Boolean SetFIBBeamShiftX(float set);
        Boolean SetFIBBeamShiftY(float set);

        //电子束校正设置
        float GetTiltCorrection();
        Boolean SetTiltCorrectionOff();
        Boolean SetTiltCorrectionOn();

        //读取FIB模式
        float GetFIBMode();

        //工作状态读取
        float GetFIBIMAGING();
        //工作状态选择
        Boolean CmdFIBModeSEM();    //SEM模式
        Boolean CmdFIBModeFIB();    //FIB模式
        Boolean CmdFIBModeMILL();   //MILL模式


        //开启电压
        Boolean CmdOpenVoltage();

        //关闭电压
        Boolean CmdCloseVoltage();

        //图像类型切换
        Boolean DetectorType(float set);

        //执行宏文件
        Boolean CMDMCFFilename(String _MLFFullFileName);

        //样品台状态
        float GetStageIs();

        //自动函数状态
        float GetAutoFunction();

        //连接状态
        Boolean ConnectStatus();

        //FIB API工作状态
        float GetFIBApiStatus();

        //加载执行.ely文件
        Boolean CmdFIBLoadELY(String _ELYFullFileName);
        //FIB确认.ely文件
        Boolean CmdFIBEXPOSUREELY();
        //FIB执行.ely文件
        Boolean CmdFIBSTARTELY();
        //add by sun 2020-12-15 拍截面图调用蔡司接口时，要保证扫描速度5以上，自动亮度对比度功能关闭
        Boolean CmdFocusRate(int mFocusSpeed);
        Boolean CmdFocusScanSpeed(String mFocusSpeed);
        //add by sun 2020-12-15 拍截面图调用蔡司接口时，要保证扫描速度5以上，自动亮度对比度功能关闭 end
        Boolean CmdSaveRate();
        Boolean CmdSaveBestRate();

        Boolean SetStageDeltaR(float set);

        void SetRemoteELYPath(String path);
        void SetRemoteMLFPath(String path);

        void SetReduced(int x, int y, int W, int H);
        void CloseReduced();
        void SetReduced1(int x, int y, int W, int H);
        Boolean GrabZoneImage(String filename, short xoff, short yoff, short width, short height, short type);

        //清除控件
        Boolean Dispose();

    }
}
