using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace HansAdvInterfaceCSharpTest
{
    static public class CSharpInterface
    {
        public static string g_strPathName = "";

        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public delegate void MsgFlyMarkCall(uint nCard, int nID, UInt64 nMarkTime);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void T_HS_USERDEFINE_MSG_CALLBACK(uint nCard, uint dwCode, Int64 value);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetCustomMsgCall",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetCustomMsgCall(uint uCard, T_HS_USERDEFINE_MSG_CALLBACK CustomMsgCallBack);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetDllVersion",
         CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetDllVersion(ref ushort pMainVer, ref ushort pDllVer);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetLastError",
         CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetLastError(uint uCard,ref int nError,StringBuilder lpszMsg,int nSize);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_InitialMachine",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_InitialMachine(string strPath);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_LoadMarkFile",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_LoadMarkFile(uint uCard,string strFileName);
        
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_Mark",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_Mark(uint uCard,int nType, bool bWaitTouch, bool bWaitEnd, int nOverTime, bool bMarkAll);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_MarkFlyIOStart",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_MarkFlyIOStart(uint uCard);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_CloseMachine",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_CloseMachine();

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_FreeStrokeList",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_FreeStrokeList(uint uCard,CInterStroke [] m_listCustom);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetMarkRange",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetMarkRange(uint uCard,ref double pX,ref double pY);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_CloseMarkFile",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_CloseMarkFile(uint uCard,string szFileName,bool bSave);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_IsTouch",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_IsTouch(uint uCard,ref int nTouchFlag);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_CheckTouch",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_CheckTouch(uint uCard,IntPtr hWnd, bool bActive);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_ReadPort",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_ReadPort(uint uCard,ref UInt16 nValue);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_WritePort",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        
        public static extern int HS_WritePort(uint uCard,uint dbValue, int dbMask);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_IsMarkEnd",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_IsMarkEnd(uint uCard,ref int pFlag);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetMarkTime",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetMarkTime(uint uCard,ref int nMarkTime);
        
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_MarkStop",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_MarkStop(uint uCard);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_ChangeTextByNameW",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_ChangeTextByNameW(uint uCard,string strName, byte [] strText);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetObjProperty",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetObjProperty(uint uCard ,ref double dbLeft,ref double dbTop, ref double dbRight, ref double dbBottom);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetTextByName",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetTextByName(uint uCard,string szTextName, StringBuilder szText, ref int nMaxCount);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetTextByNameW",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetTextByNameW(uint uCard,string szTextName, byte [] szText, ref int nMaxCount);
        
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_PreviewGraph",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_PreviewGraph(uint uCard,IntPtr hWnd, double dbCenterX, double dbCenterY, double dbScale);

//         [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_PreviewGraphEx",
//         CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
//         public static extern int HS_PreviewGraphEx(uint uCard, IntPtr hWnd, int bAll, string strObjName, int nWidth, int nHeight);
        
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_Move",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_Move(uint uCard,double dbMoveX, double dbMoveY);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_Rotate",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_Rotate(uint uCard,double x, double y, double dbRotate);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_ChangeTextByName",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_ChangeTextByName(uint uCard,string lpszTextName, string lpszText);

        //add 2022/2/28
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_ReadOutPort",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_ReadOutPort(uint uCard, ref ushort nReadPort);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetTimeDogInfoID",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern bool HS_GetTimeDogInfoID(byte [] id, byte [] compid, byte [] devid);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetCurDoc",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetCurDoc(uint uCard,string strFile);
        
        //iBit:   输出口号
        //bState :true    高电平
        //		  false   低电平
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_WriteOutPortBit",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern bool HS_WriteOutPortBit(uint uCard,int iBit,bool bState);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetCardNumber",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetCardNumber(ref uint uCardNum);

        //add 2022/05/16
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_MarkStorke",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_MarkStorke(uint uCard,int nType,tgStroke [] pStroke,int nNum);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetMarkModel",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetMarkModel(uint uCard, int nMarkModel, int nFlyType, bool bFlyReveral, double dbSpeed, double dbInterval, /*[MarshalAs(UnmanagedType.FunctionPtr)]*/MsgFlyMarkCall flyMarkCall);

        //替换位图对象
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_ChangeBitmap",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_ChangeBitmap(uint uCard, string strObjName, string strPath);


        // by 2024/07/01 测试多轴同时运动
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_MoveMotorVEx",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_MoveMotorVEx(uint uCard,int nAxisNoEx,double [] dbMoveValue,int nMoveModel,int nMoveType);
        // 多轴同时回零
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_HomeMoveVEx",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_HomeMoveVEx(uint uCard, int nAxisNoEx, bool bSoftHome);
        // 多轴同时停止
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_StopRunEx",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_StopRunEx(uint uCard, int nAxisNoEx);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetFontPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetFontPara(uint uCard, ref FONTPARA_EX pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetFontPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetFontPara(uint uCard, ref FONTPARA_EX pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_PickObjectByPoint",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_PickObjectByPoint(uint uCard,double x, double y, bool bShift, double dbCenterX, double dbCenterY, double dbScale);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_PickObjectByRect",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_PickObjectByRect(uint uCard, double dbLeft,double dbRight,double dbTop, double dbBottom, bool bShift, double dbCenterX, double dbCenterY, double dbScale);

        // 设置旋转打标参数
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetRotateMarkPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetRotateMarkPara(uint uCard, double dbDimeter, double dnAngle, int nNum, bool bSave);
        // 圆周旋转打标数据预处理 
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_PreprocessRotateData",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_PreprocessRotateData(uint uCard, int nProcessType);
        // 圆周旋转打标数据预处理 
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_RotateMark",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_RotateMark(uint uCard, int nType, bool nWaitTouch, bool bWaitEnd, int nOverTime);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetMotionSysPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetMotionSysPara(uint uCard, int nAxis, int nPPR, double dbPitch, int nDelay, int nAxisType,
            int nMotorDire, double dbEmptySpeed, double dbWorkSpeed, double dbEmptyTAcc,
            double dbWorkTAcc, bool bHardOrgEnable, bool bAutoHome, bool bEnabled);
											 
        // 自定义命令发送
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SendCustomCmd",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SendCustomCmd(uint uCard, Int64 inCmd, Int64 outCmd);

        // 获取填充
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetFillParaByObjName",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetFillParaByObjName(uint uCard, string strName, ref HATCHPARAU pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetHatchPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetHatchPara(uint uCard, ref HATCHPARAU pPara);

        // 设定填充
        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetFillParaByObjName",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetFillParaByObjName(uint uCard, string strName, ref HATCHPARAU pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_GetLayerPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_GetLayerPara(uint uCard, long nLayer, ref LAYERPARA pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_SetLayerPara",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_SetLayerPara(uint uCard, long nLayer, ref LAYERPARA pPara);

        [DllImport("HansAdvInterfaceU.dll", EntryPoint = "HS_AddText",
        CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
        public static extern int HS_AddText(uint uCard
                                        , string szStr
                                        , double dbHeight
                                        , double dbWidthRatio
                                        , int bModel
                                        , string szTextName
                                        , double dbPosX
                                        , double dbPosY
                                        , int nAlign
                                        , double dbAngle
                                        , int nLayer
                                        , int bHatch
                                        , int nHatchLayer
                                        , string szObjName);

        /*
                    // 示例：发送自定义命令实现

                    // 下发的数据
                    USERCMD_PARA cmd_down = new USERCMD_PARA();
                    cmd_down.wPara = new UInt16[16];
                    cmd_down.wPara[0] = 6; // 固定值
                    cmd_down.wPara[1] = 39024; // 命令号
                    //cmd_down.wPara[2] = 1111; // 其他数据位

                    // 接收的数据
                    USERCMD_PARA cmd_ret = new USERCMD_PARA();
                    cmd_ret.wPara = new UInt16[16];

                    // 下发数据格式转换
                    int size1 = Marshal.SizeOf(typeof(USERCMD_PARA));
                    byte[] bytes1 = new byte[size1];
                    IntPtr pBuff1 = Marshal.AllocHGlobal(size1);
                    Marshal.StructureToPtr(cmd_down, pBuff1, true);
                    Marshal.Copy(pBuff1, bytes1, 0, size1);
                    Int64 p1 = pBuff1.ToInt64();

                    // 接收数据格式转换
                    int size2 = Marshal.SizeOf(typeof(USERCMD_PARA));
                    byte[] bytes2 = new byte[size2];
                    IntPtr pBuff2 = Marshal.AllocHGlobal(size2);
                    Marshal.StructureToPtr(cmd_ret, pBuff2, true);
                    Marshal.Copy(pBuff2, bytes2, 0, size1);
                    Int64 p2 = pBuff2.ToInt64();

                    // 发送
                    int ret = CSharpInterface.HS_SendCustomCmd(g_uCard, p1, p2);

                    // 数据回转
                    USERCMD_PARA r1 = (USERCMD_PARA)Marshal.PtrToStructure(pBuff1, typeof(USERCMD_PARA));
                    USERCMD_PARA r2 = (USERCMD_PARA)Marshal.PtrToStructure(pBuff2, typeof(USERCMD_PARA));
        */

        public static string GetError()
        {
            uint uCard = 0;
            int nEror = 0;
            StringBuilder szBuff = new StringBuilder(200);
            HS_GetLastError(uCard,ref nEror,szBuff,200);
            return szBuff.ToString();
        }

        //将一个包含ASCII编码字符的Byte数组转化为一个完整的String
        public static string FromASCIIByteArray(byte[] characters)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();
            string constructedString = encoding.GetString(characters);
            return (constructedString);
        }
        //将一个包含Unicode编码字符的Byte数组转化为一个完整的String
        public static string FromUnicodeByteArray(byte[] characters)
        {
            UnicodeEncoding encoding = new UnicodeEncoding();
            string constructedString = encoding.GetString(characters);
            return (constructedString);
        } 
    }
   
    //对外接口数据结构
    [StructLayout(LayoutKind.Sequential)]
    public struct CInterStroke
    {
        [MarshalAs(UnmanagedType.ByValArray)]
        public CInterDoc[] m_dotArray;

        [MarshalAs(UnmanagedType.U4)]
        public int m_nLayer;
    };

    //对外接口线条数据类
    [StructLayout(LayoutKind.Sequential)]
    public struct CInterDoc
    {
        [MarshalAs(UnmanagedType.R8)]
        public double x;
        [MarshalAs(UnmanagedType.R8)]
        public double y;
        [MarshalAs(UnmanagedType.R8)]
        public double z;
    };

    // 对外接口自定义命令结构
    [StructLayout(LayoutKind.Sequential)]
    public struct USERCMD_PARA
    {
        [MarshalAs(UnmanagedType.U2)]
        public UInt16 nVer;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public UInt16[] wPara;
    };

    [StructLayout(LayoutKind.Sequential)]
    public struct tgDot
    {
        [MarshalAs(UnmanagedType.R8)]
        public double x;
        [MarshalAs(UnmanagedType.R8)]
        public double y;
        [MarshalAs(UnmanagedType.R8)]
        public double z;
    };

    [StructLayout(LayoutKind.Sequential)]
    public struct tgStroke
    {
        [MarshalAs(UnmanagedType.U4)]
        public UInt32 nCount;
        [MarshalAs(UnmanagedType.I4)]
        public int nLayer;
        [MarshalAs(UnmanagedType.ByValArray)]
        public tgDot[] pDot;
    };

    //字体参数结构体定义
//     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
//     public struct FONTPARA
//     {
//         [MarshalAs(UnmanagedType.U4)]
//         public int nFontType;			            //字体类型 0-TTF，1-SHX，2-HANS，3-DOT
//         [MarshalAs(UnmanagedType.U1)]
//         public Byte nCharSet;			//字符集,Unicode编码时用
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
//         public char[] szFontName;              //TTF、HANS字体用
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
//         public char[] szShxCN;                   //SHX、DOT字中文字体用
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
//         public char[] szShxEN;                   // SHX、DOT字英文字体用
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
//         public char[] szShxNum;
//     }

    // Test by 2022/12/15 字体参数结构体定义重新封送
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct FONTPARA_EX
    {
        public int nFontType;			            //字体类型 0-TTF，1-SHX，2-HANS，3-DOT
        public Byte nCharSet;			//字符集,Unicode编码时用
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string szFontName;              //TTF、HANS字体用
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string szShxCN;                   //SHX、DOT字中文字体用
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string szShxEN;                   // SHX、DOT字英文字体用
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string szShxNum;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct LOGFONT
    {
        [MarshalAs(UnmanagedType.U4)]
        public int lfHeight;
        [MarshalAs(UnmanagedType.U4)]
        public int llfWidth;
        [MarshalAs(UnmanagedType.U4)]
        public int llfEscapement;
        [MarshalAs(UnmanagedType.U4)]
        public int llfOrientation;
        [MarshalAs(UnmanagedType.U4)]
        public int llfWeight;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfItalic;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfUnderline;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfStrikeOut;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfCharSet;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfOutPrecision;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfClipPrecision;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfQuality;
        [MarshalAs(UnmanagedType.U1)]
        public System.Byte lfPitchAndFamily;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public byte[] lfFaceName;
    };

    [StructLayout(LayoutKind.Sequential)]
    public struct BaseHatchU
    {
        [MarshalAs(UnmanagedType.Bool)]
        public bool bEnable;	//填充使能
        [MarshalAs(UnmanagedType.Bool)]
        public bool bEquaDist;	//等间距使能
        [MarshalAs(UnmanagedType.Bool)]
        public bool bKeepAngle;	//填充线绕轮廓旋转
        [MarshalAs(UnmanagedType.U4)]
        public int nFillStyle;	//填充类型
        [MarshalAs(UnmanagedType.R8)]
        public double dbSpace;	//填充间距
        [MarshalAs(UnmanagedType.R8)]
        public double dbAngle;	//填充角度
        [MarshalAs(UnmanagedType.R8)]
        public double dbBeamComp;	//光栅大小
        [MarshalAs(UnmanagedType.R8)]
        public double dbLineReduce;   //线缩进量
        [MarshalAs(UnmanagedType.R8)]
        public double dbStartOffset;  //起始缩进量
        [MarshalAs(UnmanagedType.R8)]
        public double dbEndOffset;	//末尾缩进量
        [MarshalAs(UnmanagedType.R8)]
        public double dbMinJump;	//最小跳转间距
        [MarshalAs(UnmanagedType.Bool)]
        public bool bLoop;	//缩扩使能
        [MarshalAs(UnmanagedType.U4)]
        public int nLoopNum;	//缩扩圈数
        [MarshalAs(UnmanagedType.R8)]
        public double dbLoopDist;	//缩扩间距
        [MarshalAs(UnmanagedType.Bool)]
        public bool bRemoveLine;	//缩扩后去掉填充线
        [MarshalAs(UnmanagedType.Bool)]
        public bool bRemoveOrg;	//缩扩后去掉原始轮廓
        [MarshalAs(UnmanagedType.U4)]
        public int nFillNum;	//填充次数
        [MarshalAs(UnmanagedType.R8)]
        public double ProAngle;	//累进角度
        [MarshalAs(UnmanagedType.R8)]
        public double AddDis;	//累进间距
        [MarshalAs(UnmanagedType.Bool)]
        public bool bSaveCountour;	//填充后保留外框
        [MarshalAs(UnmanagedType.R8)]
        public double dbLineReduceEnd;	//线尾点缩进量
        [MarshalAs(UnmanagedType.U4)]
        public int nLoopFillOuter;	//环形填充向外标志,0为向内填,1为向外填
        [MarshalAs(UnmanagedType.U4)]
        public int nLoopRandFirst;	//环形填充首点打乱标志,0为不打乱,1需要打乱
        [MarshalAs(UnmanagedType.Bool)]
        public bool bFillSameSideFirst;	//先填充同一边
    };

    [StructLayout(LayoutKind.Sequential)]
    public struct HATCHPARAU
    {
        [MarshalAs(UnmanagedType.Struct)]
        public BaseHatchU newFileData1;
        
        [MarshalAs(UnmanagedType.Struct)]
        public BaseHatchU newFileData2;
        
        [MarshalAs(UnmanagedType.Struct)]
        public BaseHatchU newFileData3;

        [MarshalAs(UnmanagedType.Bool)]
        public bool bFillFirst;	//先打填充

        [MarshalAs(UnmanagedType.Bool)]
        public bool bFillAlign; //打标时填充线对齐

        [MarshalAs(UnmanagedType.Bool)]
        public bool bMarkFillOnly; // 只打填充
    };

    //层参数结构体定义
    [StructLayout(LayoutKind.Sequential)]
    public struct LAYERPARA
    {
        [MarshalAs(UnmanagedType.U4)]
        public int nCount;		    //打标次数
        [MarshalAs(UnmanagedType.R8)]
        public double dbMarkV;		//矢量打标速度(mm/s)
        [MarshalAs(UnmanagedType.R8)]
        public double dbJumpV;		//矢量空跳速度(mm/s)
        [MarshalAs(UnmanagedType.R8)]
        public double dbQFre;			//Q频(KHz)
        [MarshalAs(UnmanagedType.R8)]
        public double dbQRls;			//Q释放(us)
        [MarshalAs(UnmanagedType.R8)]
        public double dbCurrent;		//电流(A)
        [MarshalAs(UnmanagedType.U4)]
        public int nFpkTime;		//首脉冲抑制时间	
        [MarshalAs(UnmanagedType.R8)]
        public double dbFPKInitRate;	//首点比例(0.0~1.0)	
        [MarshalAs(UnmanagedType.R8)]
        public double dbFPKLenRate;	//抑制长度系数(0.0~0.999)
        [MarshalAs(UnmanagedType.R8)]
        public double dbFPKMaxPRate;	//峰值能量比例(0.0~1.0)
        [MarshalAs(UnmanagedType.R8)]
        public double dbFPKCurRate;	//首脉冲电流系数(0.0~1.0)
        [MarshalAs(UnmanagedType.U4)]
        public int nQuality;		//打标质量系数
        [MarshalAs(UnmanagedType.U4)]
        public int nLayerDelay;	//层延时
        [MarshalAs(UnmanagedType.U4)]
        public int nLaserOnDelay;	//激光开延时(us)
        [MarshalAs(UnmanagedType.U4)]
        public int nLaserOffDelay;	//激光关延时(us)
        [MarshalAs(UnmanagedType.U4)]
        public int nMoveLineDelay;	//走笔延时(us)
        [MarshalAs(UnmanagedType.U4)]
        public int nJumpDelay;		//跳转延时(us)
        [MarshalAs(UnmanagedType.U4)]
        public int nRoundDelay;	//拐弯延时(us)
        [MarshalAs(UnmanagedType.R8)]
        public double dbCurrentR;		//电流(%)
        [MarshalAs(UnmanagedType.R8)]
        public double dbSimmerCur;	//维持电流(%)
        [MarshalAs(UnmanagedType.U4)]
        public int nWaveForm;		//波形
        [MarshalAs(UnmanagedType.R8)]
        public double dbPowerR;		//功率(%)
        [MarshalAs(UnmanagedType.U4)]
        public int nLaserPulse;		//激光脉宽
    };
}