// workspace2.h : interface of the CWorkSpaceBar2 class // ///////////////////////////////////////////////////////////////////////////// #pragma once #include "TaskTreeCtrl.h" #include "ToolManager.h" #include "CustomToolTipCtrl.h" #include "NodeWatchDlg.h" #include "HWindow.h" #include "FunctionBlock.h" #include "TaskCtrl.h" typedef unordered_map WATCH; class CTaskWindow : public CBCGPStatic { DECLARE_DYNAMIC(CTaskWindow) public: CTaskWindow(); // Attributes protected: // Operations public: // Overrides // Implementation public: virtual ~CTaskWindow(); virtual BOOL PreTranslateMessage(MSG* pMsg); // 序列化 BOOL DoSerialize(CArchive& ar); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); // Generated message map functions protected: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); // afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); afx_msg void OnPaint(); // 当窗体激活时触发,变更当前工作窗体 afx_msg void OnSetFocus(CWnd* pOldWnd); // public: // virtual void OnDraw(CDC* pDC); // 重写以绘制该视图 #ifdef _DEBUG virtual void AssertValid() const; #ifndef _WIN32_WCE virtual void Dump(CDumpContext& dc) const; #endif #endif protected: DECLARE_MESSAGE_MAP() public: CBCGPToolBarImages& GetCaptionIcons() { return m_CaptionIcons; } protected: CBCGPToolBarImages m_CaptionIcons; // 加载.bmp格式图片 CBitmap m_Bitmap[3]; int m_nMarginLeft; int m_nMarginTop; int m_nMarginBottom; int m_nMarginRight; afx_msg void OnUpdate(CCmdUI* pCmdUI); afx_msg void OnBnClickedUp(); afx_msg void OnBnClickedDown(); afx_msg void OnBnClickedFront(); afx_msg void OnBnClickedBottom(); afx_msg void OnBnClickedLeftAlign(); afx_msg void OnBnClickedRightAlign(); afx_msg void OnBnClickedTopAlign(); afx_msg void OnBnClickedBottomAlign(); afx_msg void OnBnClickedZoomIn(); afx_msg void OnBnClickedZoomOut(); afx_msg void OnBnClickedZoomZero(); afx_msg void OnBnClickedSettings(); afx_msg void OnBnClickedRunOnce(); static void WINAPI SysRunOce(LPVOID pParam); public: vector m_SelTools; // 当前任务栏中选择的工具 public: // 从工具箱中添加新的工具到任务栏 void AddNewTools(CString strToolName, HTREEITEM hPrevItem = NULL); // 从工具箱中添加新的工具到任务栏(用于反序列化使用) BOOL AddNewTools(const TOOL& newTool); // 从工具箱中添加新的工具到任务栏 BOOL AddNewTools2(const TOOL& newTool, CString* p_strShowName); // 根据用户拖动的内容添加接口连线 BOOL AddLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD); // 根据用户拖动的内容添加接口连线 // 连接的起点 // 连接的终点 BOOL AddLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bIsLoad = false); // 根据用户拖动的内容添加接口连线 BOOL AddTestLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD); // 添加工具到任务栏的时候智能链接 void SmartLink(); // 通过输入的目标端口执行智能链接动作 void ToSmartLink(const TOOL_INTERFACE& DestInf); //// 判断一个节点是否是输入节点 //BOOL IsInputNode(const HTREEITEM& handle); //// 判断一个节点是否是输出节点 //BOOL IsOutputNode(const HTREEITEM& handle); //// 获取接口的输入输出方式 //INF_WAY GetInterfaceByHandle(const HTREEITEM& handle); // 绘制链接 void DrawLink(CDC* pDC); // 绘制预览链接 void DrawPreviewLink(CDC* pDC); // 更新节点数据结构 void UpdateTools(bool bIsLoad = false ); // 更新现有工具 void UpdateExistTool(TOOL& tool, TOOL& tool_Info); // 更新新工具 void UpdateNewTool(const CString& strToolShowName,TOOL tool_Info, bool bIsLoad = false); // 根据句柄转换成对应的TOOL TOOL* GetToolByHandle(const HTREEITEM& handle); // 根据显示的名称转换乘对应的TOOL TOOL* GetToolByShowName(const CString strName); // 根据句柄转换成对应的Interface TOOL_INTERFACE* GetInterfaceByHandle(const HTREEITEM& handle); // 根据 名字 转换成对应的Interface TOOL_INTERFACE* GetInterfaceByName(const CString strParentName, const CString strName); //// 更新节点存储数据结构 //void UpdateTools(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD); //// 更新所有节点的句柄 //void UpdateHandles(); //// 更新所有节点的连接信息 //void UpdateLink(); // 重置整个TaskWindow的相关数据 void Reset(); // CTaskTreeCtrl m_wndTree; // 树形控件 CTaskCtrl m_editor; LINK_MAP m_TsetLinks; protected: // 更新所有节点的连接信息 void UpdateLink(); // 具体的进行连线绘制 //void DrawLinkLine(CDC* pDC, const CRect& rcStart , const CRect& rcEnd); //BOOL UpdateLinkInfo(TOOL_INTERFACE& info); // 建立连接 bool MakeLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bShow = true); // 建立Test连接 bool MakeTestLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest); // 判断是否是同一个接口 bool IsSameInterface(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest); // 计算连接线的长度 int CalcLinkLineLength(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest); // 通过工具显示的名字查询工具真正的名字 CString GetToolRealname(const CString& strShowName); // 计算连线的绘制坐标 LINK_POINTS CalcLinkPoints(const LINK& lnk); // 计算连线的触发区域 LINK_RECTS CalcLinkRects(const LINK_POINTS& lps); // 获取某个Interface相连的接口 TOOL_INTERFACE* GetHigherLinkInterface(const TOOL_INTERFACE& inf); // 根据Interface获取Tool // TOOL* GetToolByInterface(TOOL_INTERFACE& inf); //// 为节点的参数拷贝值 //void AssignParamValue(PARAM& dest, const PARAM& source); //// 为节点的参数赋值(模板) //template //void AssignParamValue(PARAM& dest, const T& value); // 从dll中获取工具指针 BOOL GetToolPtrByDll( TOOL& tool ); // 保存工具信息到文件中 BOOL SaveToFile(CArchive& ar); // 从文件中加载工具信息 BOOL LoadFromFile(CArchive& ar); void OnBnClickedButtonCopy(); void OnBnClickedButtonPaste(); void SortProtToolID(const TOOL* pSourceTool, const TOOL* pDestTool); void ShowNodeWatch(/*const*/ TOOL_INTERFACE* pInf); void ValueLink(/*const */TOOL_INTERFACE* pLinkInf,/* const*/ TOOL_INTERFACE& inf); public: // 调用dll中的Input template void CallInputByDll(T& t, TOOL_INTERFACE& inf); public: template void CallInputByDllAddress(T& t, TOOL_INTERFACE& inf); // 根据Interface获取Tool TOOL* GetToolByInterface(TOOL_INTERFACE& inf); // 根据Interface获取Interface TOOL_INTERFACE* GetInterfaceByInterface(TOOL_INTERFACE& inf); // 根据Tool获取Tool TOOL* GetToolByTool(TOOL& tool); public: // 调用dll中的Output template T& CallOutputByDll(TOOL_INTERFACE& inf); // 执行Dll的Input操作(根据不同类型,不同的处理) bool DoDllInput(/*TOOL& tool,*/ TOOL_INTERFACE& inf); bool DoDllProt(TOOL& tool, TOOL_INTERFACE& inf); //// 执行Dll的Output操作(根据不同类型,不同的处理) //BOOL DoDllOutput(TOOL_INTERFACE& inf); // 执行Dll的Execute操作(根据不同类型,不同的处理) int DoDllExecute(TOOL& tool); // 专门用来获取Dll中绑定控件的接口 CWnd* DoDllControlOutputWnd(TOOL_INTERFACE& inf); QHalconWindow*& DoDllControlOutputImage(TOOL_INTERFACE& inf); // 执行任务 2018.10.15 void RunProcess(); void ExProt(/*const*/ TOOL& tool); // 当 Item单击时候 void OnItemLButtonDown(const HTREEITEM& handle); // 当Item双击时 根节点 void OnItemDblclk(const HTREEITEM& handle); // 当Item双击时 子节点 void OnItemNodeDblclk(const HTREEITEM& handle); // EnableItem bool OnItemEnable(const HTREEITEM& handle); // 删除Item void OnItemDelete(const HTREEITEM& handle); // 判断有无链接 bool IsLink(const HTREEITEM& handle); // 判断是否受保护 bool IsProtected(const HTREEITEM& handle); // 编辑工具名称 void OnItemToolRename(const HTREEITEM& handle); // 编辑工具名称 void ToolRename(TOOL* pTool, const CString strNewName); // 当Item执行时 void OnItemExecute(const HTREEITEM& handle); // Execute All void OnItemExecuteAll(); // OnExecuteT ool void OnExecuteTool(CString strToolName); void OnUpdateToolState(CString strToolName, int nState); // 右键菜单Link to... void OnItemLink(const HTREEITEM& source, UINT nLinkDestIndex); //// 右键菜单Link from... //void OnItemLinkFrom(HTREEITEM hSelItem); // 右键菜单UnLink void OnItemUnLink(HTREEITEM hSelItem); // 根据右键菜单获取可以link的接口,并且返回本接口是输入还是输出 INF_DIRECTION GetPopLinkNodes(vector&, HTREEITEM hSelItem); // 动态隐藏接口 void OnItemHideInterface(const HTREEITEM& handle); // 添加一个新的输入接口到所选的工具中,返回插入的索引值 int AddDynamicInterface(TOOL& activeTool, const DLL_INF& newInf, const HTREEITEM& handle); // 添加一个新的接口到界面中 void AddNewInterfaceToTree(const HTREEITEM& handle, TOOL_INTERFACE& newInf, const int& nPos); //获取端口的UI值 INTERFACE_DISP_TYPE UpdateUIValue(CString& str, HImage* hv_Image, HObject* hv_Obj, TOOL_INTERFACE* pInf); // 为Tool添加执行结果的图标 void DrawToolResult(NMLVCUSTOMDRAW* pLVCD); // 为Tool添加执行结果的 Colour void DrawToolColour(NMLVCUSTOMDRAW* pLVCD); // 重置所有工具执行状态 void ResetToolExecCode(); // 重绘Tool的返回值状态 void RedrawToolExecCode(const TOOL& tool); // static void CALLBACK ToolStateCallback(CString strToolName, int nState, long long userParam);// Log 回调 // static void CALLBACK ToolLogCallback(CString strToolName, MSG_WAY nType, CString strMassage, long long userParam);// Log 回调 // // static void CALLBACK ToolOnExecuteCallback(CString strToolName, long long userParam);// Log 回调 // static void CALLBACK ToolBusyCallback(CString strToolName, int nState, CString strMassage, long long userParam);// ToolBusy 回调 protected: // 绘制使用的画笔 CPen m_penLink; // 绘制连接 CPen m_penLinkBold; // 绘制连接(粗线) CPen m_penLinkTest; // 绘制连接(虚线) map m_RenameList; // 工具重命名的字典表 vector m_PopLinkNodes; // 右键菜单弹出的Link to列表 CCustomToolTipCtrl* m_ToolTip; HTREEITEM m_Item; CBCGPToolBar m_wndToolBar; public: //主任务:即该任务线程不论任何时候,都一直循环运行。点击了主页上的运行按钮后,一直循环运行 //事件任务: 该任务线程不能主动运行。(不参与循环运行),只在某个事件发生时候执行,并且只执行一次,事件由工具产生 TASK_MODE m_TaskMode; // 工具的运行模式。主任务 或事件任务 LINK_MAP m_Links; // 接口之间的连接信息(key为输入接口,唯一) HANDLE m_hExecuteEven; // 管理当前任务的执行 // HANDLE m_hBusyEven; // 当前任务执行完成的事件 HANDLE m_hDoneEven; // 当前任务执行完成的事件 int m_RunningTime; // 当前任务的执行时间 double m_dRunningCount; // 执行计数 CWinThread* m_hThread; // 线程句柄 bool m_bExitThread; // 用于退出线程 int m_nIndex; // 当前任务窗体的索引号 int m_nSleepTime; // 任务执行间隔时间 CString m_strTaskName; // 任务窗体的名称 protected: public: void WatchClear(); // WATCH mWatch; // }; // 调用dll中的Input template void CTaskWindow::CallInputByDllAddress(T& t, TOOL_INTERFACE& inf) { // 由于该模板函数没有在该类中实例化,所以编译器无法知道模板的定义,将该模板函数的定义放在头文件中是个不错的选择 TOOL* pTool = GetToolByInterface(inf); if (pTool != NULL) { ASSERT(pTool != NULL); CDllTool* pPtr = pTool->pDllPtr; ASSERT(pPtr != NULL); pPtr->SetValue(inf.nIndex - 1, t, INF_BY_ADDRESS); } else { CString strMsg; strMsg.Format(_T("%s.%s"), inf.strParentName, inf.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } } /////////////////////////////////////////////////////////////////////////////