123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
- #pragma once
- #include "DllToolCommon.h"
- #include "H_DLL.h"
- #include <unordered_map>
- #pragma warning( disable : 4996)
- //输出窗口打印信息
- #define OUTPUT_STRING WM_USER + 1000
- //由mainfrm将信息打印到输出窗口
- #define WNDOUTPUT WM_USER + 1001
- //文件数据发生变化
- #define DOC_CHANGE WM_USER + 1002
- //////////////////////////////////////////////////////////////////////////
- // 默认显示的任务窗体的序号
- #define DEFAULT_TASK_WINDOW 0
- #define EXECUTE_TIMEOUT 1
- #define NumberOfIcons 4
- #define LOGO_VIEW 0
- #define RUNTIME_VIEW 1
- #define TASK_VIEW 2
- #define OUTPUT_VIEW 3
- #define PORT_WIDTH 15
- #define HOT_REGION 4// link线条的触发区域矩形宽度
- #define First_Line_Interval 25 //首行间隔
- #define Prot_First_Line_Interval 9 //Prot首行间隔
- #define Trailing_Interval 1 //尾行间隔
- #define PROT_REGION 10// Prot的触发区域矩形宽度
- #define APP_INIT 0
- #define APP_LOAD 1
- #define APP_RUN 2
- #define APP_CLOS 3
- //////////////////////////////////////////////////////////////////////////
- #define RESSTRIDTYPE UINT
- #define IDS2RESIDTYPE(id) id
- #define _GetResString(id) GetResString(id)
- //////////////////////////////////////////////////////////////////////////
- // 释放内存
- #define RELEASE_BUFFER(x) {if(x!=NULL) {delete x;x=NULL;}}
- #define FREE_BUFFER(x) {if(x!=NULL) {free(x);x=NULL;}}
- #define RELEASE_HANDLE(x) {if(x!=NULL) {CloseHandle(x);x=NULL;}}
- #define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))
- /////////////////////////////////////////////////////////////////
- // 工具的默认保存路径
- #define DEFAULT_TOOL_PATH _T("\\toolbox\\")
- #define CONFIGFOLDER _T("config\\")
- //定义输出窗口类型
- enum OUTPUT_WND
- {
- RESULT, //结果窗口
- VALUE, //变量窗口
- LOG //日志窗口
- };
- // 拖动的模式,有两种:移动模式和连线模式
- typedef enum _tagDragMode
- {
- DRAG_MOVE, // 移动模式
- DRAG_LINK, // 连线模式
- DRAG_NONE // 没有拖动
- } DRAG_MODE;
- // //定义输出消息
- typedef struct _tagOutPutMsg
- {
- MSG_WAY bWay = MSG_WAY::_INFO; // 消息类型
- CString strMsg = _T("NULL"); // 消息
- CString strSource = _T("System"); // 消息来源可以是系统,也可以是某个工具
- CString strUser = _T("Root"); // 当前用户名
- } OUTPUT_MSG;
- typedef enum _tagOperatingMode
- {
- CUSTOMER_MODE = 0, //客户模式 Customer mode
- DEVELOP_MODE = 1, //开发模式 Develop mode
- ENGINEERING_MODE = 2 //工程模式 Engineering mode
- }OPERATING_MODE;
- //定义任务执行模式
- typedef enum _tagTaskMode
- {
- MAIN_TASK = 1, // 主任务
- EVEN_TASK = 2, // 事件任务
- RUN_TASK = 3, // 运行时(运行按钮)行的任务
- STOP_TASK = 4 // 停止时(停止按钮)执行的任务
- }TASK_MODE;
- typedef enum _tagInterfaceDispType
- {
- IVDT_CSTRING = 1, // CString
- IVDT_HIMAGE = 2, // Hobject Image
- IVDT_OBJECT = 3,
- IVDT_REG = 4,
- IVDT_XLD = 5,
- IVDT_NONE
- }INTERFACE_DISP_TYPE;
- //任务
- typedef struct _tagTaskInfo
- {
- TASK_MODE bTaskMode = MAIN_TASK; // 任务模式
- CString strTaskName = _T("检测任务"); // 任务的名称
- int nSleepTime = 0; // 每个循环周期的任务间隔
- } TASK_INFO;
- // 工具的公共基类
- typedef struct _tagToolBase
- {
- CString strName; // 名称
- CString strAliasName; // 工具别名
- HTREEITEM hHandle; // 控件句柄
- CRect rect;
- _tagToolBase()
- {
- hHandle = NULL;
- rect.SetRectEmpty();
- }
- } TOOL_BASE;
- // 工具接口信息
- typedef struct _tagToolInterface : public TOOL_BASE
- {
- CString strParentName; // 接口父节点的名称
- CString strInfo; // 接口的描述信息
- INF_DIRECTION InfDirection; // 接口输入输出(输入、输出)
-
- INF_TYPE InfType; // 控件类型还是值类型
- INF_WAY InfWay; // 传值还是传引用(2019-5-3增加)
- VAR_TYPE VarType; // 接口的参数类型
- LPVOID* pValue; // 接口的值指针(除全局变量外其它工具不使用)
- int nIndex = 0; // 接口的序号
- bool bMonitor = false; // 是否启用变量监控,默认不启用,可在工具中配置默认状态
- bool bShow = true; // 2019-3-26 是否隐藏此接口
- bool bSmartLink = false; // 智能链接(添加工具到任务栏的时候,工具的输入接口自动向上搜素可用的输出端口.序列化的时候该功能不适用)
- int nUseCount = 0; // 工具被使用调用后,不允许删除,否则其它调用会出错
- _tagToolInterface()
- {
- Reset();
- }
- void Reset()
- {
- InfDirection = INF_NONE;
- strParentName.Empty();
- VarType = VAR_TYPE::ALL_Var;
- InfType = INF_TYPE_NONE;
- InfWay = INF_BY_VALUE;
- pValue = NULL;
- bMonitor = false;
- nIndex = -1;
- bShow = true;
- nUseCount = 0;
- }
- // 重载 =
- _tagToolInterface& operator =(const _tagToolInterface& inf)
- {
- if (this != &inf)
- {
- this->strParentName = inf.strParentName;
- this->strInfo = inf.strInfo;
- this->strName = inf.strName;
- this->strAliasName = inf.strAliasName;
- this->InfDirection = inf.InfDirection;
- this->hHandle = inf.hHandle;
- this->nIndex = inf.nIndex;
- this->rect = inf.rect;
- // 2018.6.4增加
- this->VarType = inf.VarType;
- this->InfType = inf.InfType;
- this->InfWay = inf.InfWay;
- this->bMonitor = inf.bMonitor;
- this->bShow = inf.bShow;
- this->nUseCount = inf.nUseCount;
- this->pValue = inf.pValue;
- }
- return *this;
- }
- // 重载 ==
- bool operator == (const _tagToolInterface& inf)
- {
- return this->strParentName == inf.strParentName
- && this->strName == inf.strName
- && this->InfDirection == inf.InfDirection
- && this->InfWay == inf.InfWay
- && this->nIndex == inf.nIndex
- && this->VarType == inf.VarType
- && this->InfType == inf.InfType;
- ;
- }
- // 重载 !=
- bool operator != (const _tagToolInterface& inf)
- {
- return this->strParentName != inf.strParentName
- || this->strName != inf.strName
- || this->InfDirection != inf.InfDirection
- || this->InfWay != inf.InfWay
- || this->nIndex != inf.nIndex
- || this->VarType != inf.VarType
- || this->InfType != inf.InfType;
- ;
- }
- //// 重载 <
- //bool operator<(const _tagToolInterface& other) const
- //{
- // if (this->strName.Compare(other.strName) < 0)
- // {
- // return true;
- // }
- // else
- // {
- // return false;
- // }
- //}
- } TOOL_INTERFACE, *LPTOOL_INTERFACE;
- //////////////////////////////////////////////////////////////////////////
- typedef struct _tagToolName
- {
- int nToolID = 0;
- CString strName;
- CString strAliasName;//曾用名或者别名
- CString strShowName;
- // 重载 =
- _tagToolName& operator =(const _tagToolName& tool)
- {
- if (this != &tool)
- {
- this->nToolID = tool.nToolID;
- this->strName = tool.strName;
- this->strAliasName = tool.strAliasName;
- this->strShowName = tool.strShowName;
- }
- return *this;
- }
- void Reset()
- {
- nToolID = 0;
- strName.Empty();
- strShowName.Empty();
- }
- }TOOLNAME;
- ////////////////////////////////////////////////////////
- // 工具信息结构体
- typedef struct _tagTool : public TOOL_BASE
- {
- TOOL_TYPE Type;
- CString strShowName; // 工具在界面中显示出来的名字(可能会有重名、重命名等等)
- CString strVersion; // 2018.6.4增加:工具的版本
- CString strDll; // 2018.6.4增加:实现本工具的dll
- CString strInfo; // 2018.6.26增加:工具的Info
- CString strLinkName; //
- //CString strFunction; // 2018.6.4增加:实现本工具的函数
- HINSTANCE hDllTool = NULL; // 2018.7.17增加: 保存了加载到系统的dll句柄
- CDllTool* pDllPtr = NULL; // 绑定的工具Dll的句柄
- vector<TOOL_INTERFACE> Interfaces; // 接口
- HICON hIcon;
- TOOLNAME hNextTool; // 下一个工具
- int nImageID = 0; // 保存当前工具图标在全局图标列表中的序号
- int nToolState = 0; // 工具的状态,指示工具是否可用(工具初始化错误时候,状态为不可用)
- int nInSleep = 0; // 进入函数时候延时
- int nOutSleep = 0; // 执行完函数时候延时
- int nExecCode = RT_NONE; // 2018.10.14修改 工具的执行返回值(默认为未执行状态)
- int nAbnormalCount = 0; // 异常计数,用来统计非正常的执行次数
- int nToolID = 0;
- double dFrequency = 0; // 工具执行的帧率
- double dRunTime = 0; // 工具运行时间
- double dTraggerTime = 0; // 工具触发的时间
- bool bIsExpand = true; // 默认展开工具
- bool bEnable = true; // 工具启用(不启用的工具,执行的时候会跳过)
-
- int nUseCount = 0; // 工具被使用调用后,不允许删除,否则其它调用会出错
- _tagTool()
- {
- Reset();
- }
- void Reset()
- {
- Type = TOOL_BY_TOOL;
- strShowName.Empty();
- strVersion.Empty();
- strDll.Empty();
- strInfo.Empty();
- hDllTool = NULL;
- pDllPtr = NULL;
- Interfaces.clear();
- hNextTool.Reset();
- nImageID = 0;
- nInSleep = 0;
- nOutSleep = 0;
- nExecCode = RT_NONE;
- nAbnormalCount = 0;
- nToolID = 0;
- dFrequency = 0;
- dRunTime = 0;
- dTraggerTime = 0;
- nToolState = TOOL_SUCCESS;
- bIsExpand = TRUE;
- bEnable = TRUE;
- nUseCount = 0;
- strLinkName.Empty();
- }
- // 重载 =
- _tagTool& operator =(const _tagTool& tool)
- {
- if (this != &tool)
- {
- this->Type = tool.Type;
- this->strName = tool.strName;
- this->strAliasName = tool.strAliasName;
- this->strShowName = tool.strShowName;
- this->hHandle = tool.hHandle;
- this->Interfaces = tool.Interfaces;
- this->strLinkName = tool.strLinkName;
- this->strDll = tool.strInfo;
- this->rect = tool.rect;
- // 2018.6.4增加
- this->strVersion = tool.strVersion;
- this->strDll = tool.strDll;
- this->strInfo = tool.strInfo;
- this->pDllPtr = tool.pDllPtr;
- this->hDllTool = tool.hDllTool;
- this->hIcon = tool.hIcon;
- this->hNextTool = tool.hNextTool;
- this->nImageID = tool.nImageID;
- this->nInSleep = tool.nInSleep;
- this->nOutSleep = tool.nOutSleep;
- this->nExecCode = tool.nExecCode;
- this->nAbnormalCount = tool.nAbnormalCount;
- this->nToolID = tool.nToolID;
- //this->nNextToolID = tool.nNextToolID;
- this->dFrequency = tool.dFrequency;
- this->dRunTime = tool.dRunTime;
- this->dTraggerTime = tool.dTraggerTime;
- this->bIsExpand = tool.bIsExpand;
- this->bEnable = tool.bEnable;
- this->nUseCount = tool.nUseCount;
- }
- return *this;
- }
- } TOOL, *LPTOOL;
- ////////////////////////////////////////////////////////
- // 工具类别信息结构体
- typedef struct _tagToolCategory
- {
- CString strName; // 分类的名称(如果没有名称,则说明本工具不从属于任何分类)
- vector<TOOL> Tools; // 本分类下的所有工具
- _tagToolCategory()
- {
- }
- } TOOL_CATEGORY, *LPTOOL_CATEGORY;
- ////////////////////////////////////////////////////////
- // Link的对应关系
- typedef struct _tagLinkMap
- {
- TOOL_INTERFACE source; // 连接的起点
- TOOL_INTERFACE dest; // 连接的终点
- bool bActive; // 这个连线是否被激活
- bool bShow; // 这个连线是否显示,默认显示(特殊工具可能不需要显示,目前是端口的输入不需要显示)
- // 重载 ==
- bool operator == (const _tagLinkMap& linkmap)
- {
- return this->source == linkmap.source
- && this->dest == linkmap.dest
- && this->bActive == linkmap.bActive;
- }
- // 重载 !=
- bool operator != (const _tagLinkMap& linkmap)
- {
- return this->source != linkmap.source
- || this->dest != linkmap.dest
- || this->bActive != linkmap.bActive;
- }
- _tagLinkMap()
- {
- bActive = false;
- bShow = true;
- }
- } LINK, *LPLINK;
- typedef vector<LINK> LINK_MAP;
- ////////////////////////////////////////////////////////
- // Link的4个点坐标(用于绘图)
- typedef struct _tagLinkPoints
- {
- CPoint ptStart;
- CPoint ptCorner1;
- CPoint ptCorner2;
- CPoint ptCorner3;
- CPoint ptCorner4;
- CPoint ptEnd;
- int nMode;
- } LINK_POINTS, *LPLINK_POINTS;
- ////////////////////////////////////////////////////////
- // Link的鼠标触发区域(判定鼠标命中)
- typedef struct _tagLinkRects
- {
- CRect rcStart;
- CRect rcCorner1;
- CRect rcCorner2;
- CRect rcCorner3;
- CRect rcEnd;
- } LINK_RECTS, *LPLINK_RECTS;
- //////////////////////////////////////////////////////////////////////////
- // 全局变量的数据结构
- typedef struct _tagGlobalLink
- {
- TOOL_INTERFACE source; // 连接的起点
- TOOL_INTERFACE dest; // 连接的终点
- int nSourecTaskIndex;
- int nDestTaskIndex;
- _tagGlobalLink()
- {
- nSourecTaskIndex = -1;
- nDestTaskIndex = -1;
- source.Reset();
- dest.Reset();
- }
- ~_tagGlobalLink()
- {
- nSourecTaskIndex = -1;
- nDestTaskIndex = -1;
- source.Reset();
- dest.Reset();
- }
- }GLOBALLINK;
- typedef vector<GLOBALLINK> GLOBALLINK_MAP;
- typedef struct _tagGlobaVar
- {
- int nTaskIndex;
- int nGVnIndex;
- CString strShowName;
- VAR_TYPE VarType;
-
- _tagGlobaVar()
- {
- Reset();
- }
- ~_tagGlobaVar()
- {
- Reset();
- }
- void Reset()
- {
- nTaskIndex = 0;
- nGVnIndex = 0;
- strShowName.Empty();
- VarType = VAR_TYPE::ALL_Var;
- }
- }GLOBALVAR;
- // Diagram的控件类型
- // 绑定的系统命令名称
- #define SYSTEM_ROOT _T("CMainFrame")
- #define SYSTEM_CMD_RUN _T("CMainFrame.OnSystemRun")
- #define SYSTEM_CMD_RUNONCE _T("CMainFrame.OnSystemRunOnce")
- #define SYSTEM_CMD_STOP _T("CMainFrame.OnSystemStop")
- #define SYSTEM_CMD_SAVE _T("CMainFrame.OnSystemSave")
- #define TASK_SYSTEM_COM 99 // 任务窗体序号(如果是系统命令,则对应窗体为99)
- #define TASK_SYSTEM_GV 98 // 全局变量序号(如果是系统命令,则对应窗体为98)
- #define TASK_INVALID -1
- // 各个控件采用的ID号起始编号(每增加一种控件都要增加一项)
- #define RESOURCE_ID_BUTTON 0x100
- #define RESOURCE_ID_EDITBOX 0x200
- #define RESOURCE_ID_LISTBOX 0x300
- #define RESOURCE_ID_COMBOBOX 0x400
- #define RESOURCE_ID_CHECKBOX 0x500
- #define RESOURCE_ID_INMAGE 0x600
- #define RESOURCE_ID_TEXT 0x700
- #define RESOURCE_ID_GROUPBOX 0x800
- #define RESOURCE_ID_STATIC 0x900
- // 每种类型的控件最大支持的数量(用于控件批量响应消息)
- #define MAX_CONTROL_COUNT 0x100
- // 各个控件的枚举值(每增加一种控件都要增加一项)
- typedef enum _tagControlTypeID
- {
- TYPE_ID_BUTTON,
- TYPE_ID_COMBOBOX,
- TYPE_ID_EDITBOX,
- TYPE_ID_LISTBOX,
- TYPE_ID_CHECKBOX,
- TYPE_ID_IMAGE,
- TYPE_ID_TEXT,
- TYPE_ID_GROUPBOX,
- TYPE_ID_STATIC,
- TYPE_ID_COUNT//此行永远为最后一行
- } CONTROL_TYPE_ID;
- // 控件的关联种类
- typedef enum _tagControlRefType
- {
- REF_INTERFACE, // 控件关联接口
- REF_TOOL, // 控件关联工具
- REF_COMMAND, // 控件关联命令
- REF_GV,
- REF_NONE, // 未绑定任何接口
- REF_COUNT
- } CONTROL_REF_TYPE;
- //// 控件的关联信息
- //typedef struct _tagControlRefInfo
- //{
- // CString strInfParentName; // 接口的父节点名称
- // CString strName; // 控件的名称
- // INF_WAY bWay; // 控件的输入输出类型
- // int nInfIndex; // 接口的序号
- //
- // int nRefTaskIndex; // 关联的TaskWindow的序号
- //
- // CONTROL_REF_TYPE type; // 关联的类型
- //
- // _tagControlRefInfo()
- // {
- // bWay = INF_CONTROL;
- // type = REF_NONE;
- // nInfIndex = -1;
- // nRefTaskIndex = TASK_INVALID;
- // }
- //
- // // 重载 =
- // _tagControlRefInfo& operator =(const _tagControlRefInfo& info)
- // {
- // if (this != &info)
- // {
- // this->strInfParentName = info.strInfParentName;
- // this->strName = info.strName;
- // this->bWay = info.bWay;
- // this->nInfIndex = info.nInfIndex;
- // this->nRefTaskIndex = info.nRefTaskIndex;
- // type = info.type;
- // }
- // return *this;
- // }
- //
- //} CONTROL_REF_INFO;
- ///////////////////////////////////////////////////////
- //控件字体
- typedef struct _tagControlProperty
- {
- COLORREF crText; //字体的颜色
- COLORREF crBackGnd; //字体的背景颜色
- LOGFONT lf;
- CString strFontName;
- int nNoInput; //禁止输入
- _tagControlProperty()
- {
- crText = RGB(0, 0, 0);
- crBackGnd = RGB(255, 255, 255);
- memset(&lf, 0, sizeof(LOGFONT));
- lf.lfHeight = 18;
- _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("宋体"));// 将lf中的元素字体名设为“宋体”
-
- strFontName = _T("宋体");
- nNoInput = false;
- }
- ~_tagControlProperty()
- {
- }
- } CONTROL_PROPERTY;
- // 界面中要添加的控件信息
- typedef struct _tagControl
- {
- CString strEntityID; // 控件在Entity中的编号
- VAR_TYPE strType; // 控件类型
- CString strText; // 控件上的文字
- CONTROL_TYPE_ID nTypeID; // 控件TypeID序号
- CWnd* pWnd; // 控件指针
- CWnd* pInfWnd; // 关联的接口控件指针
- CRect rcRect; // 控件的尺寸
- TOOL_INTERFACE RefInterface; // 关联的Interface信息
- int nRefTaskIndex; // 关联的TaskWindow的序号
- CONTROL_REF_TYPE RefType; // 关联的类型(有三种)
- CONTROL_PROPERTY ControlProperty; // 控件属性
- CString strLinkName; // 链接信息
- CString strTooltip; // Tooltip
- _tagControl()
- {
- pWnd = nullptr;
- pInfWnd = nullptr;
- rcRect.SetRectEmpty();
- nRefTaskIndex = TASK_INVALID;
- RefType = REF_NONE;
- strLinkName.Empty();
- strTooltip.Empty();
- strType = VAR_TYPE::ALL_Var;
- }
- } CONTROL, *LPCONTROL;
- typedef unordered_map<UINT, CONTROL> CONTROLS;
- // 2018-7-30增加,显示日志信息
- //#define SHOWLOG(str) {((CMainFrame*)AfxGetMainWnd())->ShowOutputInfo(str, LOG);}
|