// workspace2.cpp : implementation of the CWorkSpaceBar2 class // #include "stdafx.h" #include "VisionPlus.h" #include "TaskWindow.h" #include "ToolWindow.h" #include "MainFrm.h" #include "GlobalSetting.h" #include "Utility.h" #include "ToolRenameDlg.h" #include "NodeWatchDlg.h" #include "Preferences.h" #include "TaskSettings.h" #include "Draw\DialogLink.h" #include "Draw\DialogLink.h" #include "HWindow.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const int nBorderSize = 1; #define HTBUTTON_CUSTOM_1 HTHELP + 12 #define HTBUTTON_CUSTOM_2 HTHELP + 13 #define HTBUTTON_CUSTOM_3 HTHELP + 14 // 绘制相关的参数 #define COLOR_BLUE RGB(0,0,255) #define COLOR_BLUE_TEST RGB(255,0,0) #define LINK_WIDTH 1 #define LINK_WIDTH_BOLD 3 #define ARROW_LENGTH 5 // 箭头长度 extern UINT Process(LPVOID lpParam); ///////////////////////////////////////////////////////////////////////////// // CWorkSpaceBar2 IMPLEMENT_DYNAMIC(CTaskWindow, CBCGPStatic) BEGIN_MESSAGE_MAP(CTaskWindow, CBCGPStatic) ON_WM_CREATE() ON_WM_SIZE() ON_WM_PAINT() ON_WM_LBUTTONDOWN() ON_WM_CONTEXTMENU() ON_WM_SETFOCUS() ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_IN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_OUT, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_NULL, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_SETTINGS, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_SNAP_TO_GRID, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_LEFT_ALIGN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_RIGHT_ALIGN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_TOP_ALIGN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM_ALIGN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_UP, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_FRONT, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_DOWN, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_MAKE_SAME_SIZE, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_DRAW_DELETE, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_TASK_SETTING, OnUpdate) ON_UPDATE_COMMAND_UI(IDC_TASK_RUNONCE, OnUpdate) ON_BN_CLICKED(IDC_DRAW_UP, &CTaskWindow::OnBnClickedUp) ON_BN_CLICKED(IDC_DRAW_DOWN, &CTaskWindow::OnBnClickedDown) ON_BN_CLICKED(IDC_DRAW_FRONT, &CTaskWindow::OnBnClickedFront) ON_BN_CLICKED(IDC_DRAW_BOTTOM, &CTaskWindow::OnBnClickedBottom) ON_BN_CLICKED(IDC_DRAW_LEFT_ALIGN, &CTaskWindow::OnBnClickedLeftAlign) ON_BN_CLICKED(IDC_DRAW_RIGHT_ALIGN, &CTaskWindow::OnBnClickedRightAlign) ON_BN_CLICKED(IDC_DRAW_TOP_ALIGN, &CTaskWindow::OnBnClickedTopAlign) ON_BN_CLICKED(IDC_DRAW_BOTTOM_ALIGN, &CTaskWindow::OnBnClickedBottomAlign) ON_BN_CLICKED(IDC_DRAW_ZOOM_IN, &CTaskWindow::OnBnClickedZoomIn) ON_BN_CLICKED(IDC_DRAW_ZOOM_OUT, &CTaskWindow::OnBnClickedZoomOut) ON_BN_CLICKED(IDC_DRAW_ZOOM_NULL, &CTaskWindow::OnBnClickedZoomZero) ON_BN_CLICKED(IDC_TASK_SETTING, &CTaskWindow::OnBnClickedSettings) ON_BN_CLICKED(IDC_TASK_RUNONCE, &CTaskWindow::OnBnClickedRunOnce) END_MESSAGE_MAP() // void CTaskWindow::OnDraw(CDC* pDC) // { // CDocument* pDoc = GetDocument(); // // TODO: 在此添加绘制代码 // } // CTakView 诊断 #ifdef _DEBUG void CTaskWindow::AssertValid() const { CBCGPStatic::AssertValid(); } #ifndef _WIN32_WCE void CTaskWindow::Dump(CDumpContext& dc) const { CBCGPStatic::Dump(dc); } #endif #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CWorkSpaceBar2 construction/destruction CTaskWindow::CTaskWindow() { g_VatTypeMap.InitVarTypeMap(); m_penLink.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE); m_penLinkBold.CreatePen(PS_SOLID, LINK_WIDTH_BOLD, COLOR_BLUE); m_penLinkTest.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE_TEST); g_pToolManager = CToolManager::GetInstance(); m_TaskMode = TASK_MODE::MAIN_TASK; // 第一个参数, TRUE,需要手动复位。 //第二个参数,默认状态初始状态,true,有信号,false无信号 //(ResetEvent()恢复为无信号,无信号时会挂起) //如果设置为FALSE,当一个线程等待到事件信号后系统会自动将事件状态复原为无信号状态 m_hExecuteEven = CreateEventW(NULL, TRUE, FALSE, NULL); // m_hBusyEven = CreateEventW(NULL, FALSE, TRUE, NULL);// 初始为有信号状态 m_hDoneEven = CreateEventW(NULL, TRUE, FALSE, NULL);// 需要ResetEvent(),初始为有信号状态 m_Links.clear(); m_RunningTime = 0; m_dRunningCount = 0; m_hThread = NULL; m_nIndex = DEFAULT_TASK_WINDOW; m_bExitThread = false; m_nSleepTime = 1; m_ToolTip = NULL; m_nMarginLeft = 0; m_nMarginTop = 0; m_nMarginBottom = 0; m_nMarginRight = 0; } CTaskWindow::~CTaskWindow() { // m_SelTools.clear(); // m_Links.clear(); // m_TsetLinks.clear(); // m_wndTree.DestroyWindow(); //为了使线程退出 m_bExitThread = true; SetEvent(m_hExecuteEven); SetEvent(m_hDoneEven); //// 2019-3-23 释放选择的工具 //for (unsigned int i = 0; i < m_SelTools.size(); i++) //{ // // 调用Release // if (m_SelTools[i].hDllTool) // { // // 调用Release接口 // typedef void(*RELEASE)(); // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE); // if (Release) // { // Release(); // } // FreeLibrary(m_SelTools[i].hDllTool); // } //} for (size_t i = 0; i < m_SelTools.size(); i++) { RELEASE_BUFFER(m_SelTools.at(i).pDllPtr); FreeLibrary(m_SelTools[i].hDllTool); } m_SelTools.clear(); RELEASE_HANDLE(m_hExecuteEven); // RELEASE_HANDLE(m_hBusyEven); RELEASE_HANDLE(m_hDoneEven); RELEASE_BUFFER(m_ToolTip); // 绘图清理 m_Bitmap[0].DeleteObject(); m_Bitmap[1].DeleteObject(); m_Bitmap[2].DeleteObject(); WatchClear(); m_wndToolBar.DestroyWindow(); } ///////////////////////////////////////////////////////////////////////////// // CWorkSpaceBar2 message handlers int CTaskWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CBCGPStatic::OnCreate(lpCreateStruct) == -1) return -1; CRect rectDummy; rectDummy.SetRectEmpty(); // Create tree control: const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS; // m_wndTree.m_bVisualManagerStyle = TRUE; // // if (!m_wndTree.Create(dwViewStyle, rectDummy, this, 1)) // { // TRACE0("Failed to create workspace view\n"); // return -1; // fail to create // } //CBCGPToolBar::AddToolBarForImageCollection(IDR_TASKFRAME, IDB_TASKTOOLS); // Create toolbar: m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(1, 1, 1, 1), AFX_IDW_DIALOGBAR + 6 + m_nIndex); // 以上增加的数字 6 是在 3 个 MainFrm 中添加的ToolBarID (1-3),Draw中添加的ToolBar ID (4-5) // 如果不设置ID,会造成多个对象使用一个ID,异常现象为图标显示不正确 //m_wndToolBar.SetControlVisualMode(this); m_wndToolBar.LoadToolBar(IDR_TASKFRAME, 0, 0, TRUE /* Locked bar */, 0, 0, IDB_TASKTOOLS); // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY); // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() & // ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT)); m_wndToolBar.SetOwner(this); // 所有命令都将通过此对话框而不是父框架进行路由: m_wndToolBar.SetRouteCommandsViaFrame(FALSE); // 设置工具栏的名称 m_wndToolBar.SetWindowText(m_strTaskName); GetClientRect(rectDummy); m_editor.Create(dwViewStyle, rectDummy, (CWnd*)this, NULL); //m_editor.SetVirtualSize(CSize(1800, 600)); m_editor.SetModified(FALSE); m_editor.SetBackgroundColor(globalData.clrBarHilite); m_editor.SetSnapToGrid(FALSE); m_editor.SetRestraints(RESTRAINT_VIRTUAL); m_editor.ShowGrid(false); m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom); // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式 m_editor.m_pBindTaskWnd = this; m_Bitmap[0].LoadBitmap(IDB_BITMAP_INVALID); m_Bitmap[1].LoadBitmap(IDB_BITMAP_EERROR); m_Bitmap[2].LoadBitmap(IDB_BITMAP_OK); // Load caption icons: m_CaptionIcons.SetImageSize(CSize(24, 24)); m_CaptionIcons.Load(IDR_CAPTION_ICONS); globalUtils.ScaleByDPI(m_CaptionIcons); m_ToolTip = new CCustomToolTipCtrl; m_ToolTip->CreateEx(this, TTS_ALWAYSTIP); m_ToolTip->Activate(TRUE);//使活跃 CRect rect; m_editor.GetClientRect(&rect); //获取树控件的客户区矩形 m_ToolTip->AddTool(CWnd::FromHandle(m_editor.m_hWnd), _T("我的树")); m_ToolTip->SetDelayTime(500); // m_hThread = AfxBeginThread(Process, this); ; // // // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式 //m_wndTree.m_pBindTaskWnd = this; return 0; } void CTaskWindow::OnSize(UINT nType, int cx, int cy) { CBCGPStatic::OnSize(nType, cx, cy); // Tree control should cover a whole client area: // m_wndTree.SetWindowPos(NULL, nBorderSize, nBorderSize, // cx - 2 * nBorderSize, cy - 2 * nBorderSize, // SWP_NOACTIVATE | SWP_NOZORDER); int nToobarHeidit = 25; if (m_wndToolBar.m_hWnd) { m_wndToolBar.SetWindowPos(NULL, 0, 0, cx, nToobarHeidit, SWP_NOACTIVATE | SWP_NOZORDER); } if (m_editor.m_hWnd) { m_editor.MoveWindow(0, nToobarHeidit, cx, cy - nToobarHeidit); m_editor.RedrawWindow(); } } BOOL CTaskWindow::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_MOUSEMOVE) { CPoint pt = pMsg->pt; m_editor.ScreenToVirtual(pt); HTREEITEM item = m_editor.GetCursorItem(); if (m_Item != item) { m_Item = item; if (item != NULL) { CString str; //TOOL_INTERFACE* pInf = this->GetInterfaceByHandle(item); TOOL* pTool = this->GetToolByHandle(item); if (pTool != NULL) { CString strName; CString strShowName; CString strAliasName; CString strStatus; CString strInfo; CString strEven; TOOL* pActiveTool = GetToolByHandle(item); if (pActiveTool != NULL && TOOL_ERROR == pActiveTool->nToolState) { strStatus = _T("工具状态:初始化错误!"); } if (pActiveTool != NULL && TOOL_SUCCESS == pActiveTool->nToolState) { if (RT_ERROR == pActiveTool->nExecCode) { strStatus = _T("工具状态: 执行错误!"); } else if (RT_TIMEOUT == pActiveTool->nExecCode) { strStatus = _T("工具状态: 执行超时!"); } else if (RT_NONE == pActiveTool->nExecCode) { strStatus = _T("工具状态: 未执行!"); } else if (RT_SUCCESS == pActiveTool->nExecCode) { strStatus = _T("工具状态: 执行正确!"); } else if (RT_GOTO == pActiveTool->nExecCode) { strStatus = _T("工具状态: 执行跳转!"); } else { strStatus = _T("工具状态: 未知状态!"); } } CString strInSleep; if (pActiveTool->nInSleep > 0) { strInSleep.Format(_T("入口延时: %d ms\n"), pActiveTool->nInSleep); } CString strOutSleep; if (pActiveTool->nOutSleep > 0) { strOutSleep.Format(_T("出口延时: %d ms\n"), pActiveTool->nOutSleep); } if (pActiveTool->pDllPtr->m_Even.hEvenHandle != NULL) { strEven.Format(_T("触发模式: Even\n")); } strName.Format(_T("工具名称: %s \n"), pActiveTool->strName); strAliasName.Format(_T("工具别名: %s \n"), pActiveTool->strAliasName); strShowName.Format(_T("显示名称: %s \n"), pActiveTool->strShowName); strInfo.Format(_T("工具信息: %s \n"), pActiveTool->strInfo); str.Format(_T("%s%s%s%s%s%s%s%s"), strName, strAliasName, strShowName, strInSleep, strOutSleep, strEven, strInfo, strStatus); m_ToolTip->m_InterfaceDispType = INTERFACE_DISP_TYPE::IVDT_CSTRING; } else { m_ToolTip->m_hvObj.Clear(); m_ToolTip->m_Image.Clear(); //ClearWindow(m_ToolTip->m_HTWindow); CString strProtName; CString strProtType; CString strProtInfo; CString strProtVilue; TOOL_INTERFACE* pInf = GetInterfaceByHandle(item); if (pInf != NULL) { CString strValue; m_ToolTip->m_InterfaceDispType = UpdateUIValue(strValue, &m_ToolTip->m_Image, &m_ToolTip->m_hvObj, pInf); if (strValue.IsEmpty()) { strValue = _T("NULL"); } strProtName.Format(_T("ProtName: [ %s ]\n"), pInf->strName); strProtType.Format(_T("ProtType : [ %s ]\n"), g_VatTypeMap.GetVarTypeName(pInf->VarType)); strProtInfo.Format(_T("ProtInfo : [ %s ]\n"), pInf->strInfo); strProtVilue.Format(_T(" __Vilue : [ %s ]"), strValue); } str.Format(_T("%s%s%s%s"), strProtName, strProtType, strProtInfo, strProtVilue); if (str.IsEmpty()) { str = _T("NULL"); } } m_ToolTip->UpdateTipText(str, CWnd::FromHandle(m_editor.m_hWnd)); m_ToolTip->RelayEvent(pMsg); } } } if (pMsg->message == WM_KEYDOWN) { if (GetKeyState(VK_CONTROL) & 0x80) if (pMsg->wParam == 'c' || pMsg->wParam == 'C') { OnBnClickedButtonCopy(); } if (pMsg->wParam == 'v' || pMsg->wParam == 'V') { OnBnClickedButtonPaste(); } } return CBCGPStatic::PreTranslateMessage(pMsg); } void CTaskWindow::OnPaint() { CPaintDC dc(this); // device context for painting CRect rectTree; // m_wndTree.GetWindowRect(rectTree); // ScreenToClient(rectTree); // // rectTree.InflateRect(nBorderSize, nBorderSize); // GetClientRect(rectTree); dc.Draw3dRect(rectTree, globalData.clrBarShadow, globalData.clrBarShadow); // m_wndTree.SetBkColor(globalData.clrBarHilite); } /////////////////////////////////////////////////// // 从工具箱中添加新的工具到任务栏 void CTaskWindow::AddNewTools(CString strToolName, HTREEITEM hPrevItem) { // 处理重名问题 CString strToolShowName = strToolName; // // 遍历所有节点,查找是否有重名节点,并且找一下序号 int nRepeat = 1; vector ShowNameLink; for (int i = 0; i < m_SelTools.size(); i++) { CString strName = m_SelTools[i].strName; CString strShow = m_SelTools[i].strShowName; if (strName.Find(strToolName) >= 0) { nRepeat++; ShowNameLink.push_back(strShow); } } // 生成界面中的名字 if (nRepeat > 0) { strToolShowName.AppendFormat(_T(" %d"), nRepeat); int xxx = 0; for (int j = 0; j < ShowNameLink.size(); j++) { if (strToolShowName.Compare(ShowNameLink[j]) == 0) { xxx++; strToolShowName.AppendFormat(_T("-%d"), xxx); } } //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 ); m_RenameList.insert(pair(strToolShowName, strToolName)); } // 依次将对应的工具信息添加到界面中 for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++) { TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i]; // 如果拖拽过来的是一个分类,则不处理 if (cate.strName.Compare(strToolName) == 0) { return; } // 遍历本分类中的所有信息 for (unsigned int j = 0; j < cate.Tools.size(); j++) { TOOL& tool = cate.Tools[j]; // 如果找到了对应的工具 if (tool.strName.Compare(strToolName) == 0 || tool.strAliasName.Compare(strToolName) == 0 ) { // 则把本工具,以及下面的所有接口,都添加到界面中 tool.strShowName = strToolShowName; CFunctionBlock* obj = new CFunctionBlock(tool, m_nIndex); CString strTitle; strTitle.Format(_T("%d"), m_SelTools.size()); obj->SetTitle(strTitle); m_editor.StartDrawingObject(obj); this->UpdateTools(); } } } CString str; str.Format(_T("Task[%d] Add:%s"), m_nIndex, strToolShowName); USES_CONVERSION; char * s_str = T2A(str); g_Logger.Info(0, __FILE__, __LINE__, s_str);; } //////////////////////////////////////////////////////////////////// // 从工具箱中添加新的工具到任务栏(用于反序列化使用) BOOL CTaskWindow::AddNewTools(const TOOL& newTool) { CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer(); // 如果两个名字不同,则需要加到重命名列表中 if (newTool.strShowName.Compare(newTool.strName) != 0) { m_RenameList.insert(pair(newTool.strShowName, newTool.strName)); } // 依次将对应的工具信息添加到界面中 for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++) { TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i]; // 遍历本分类中的所有信息 for (unsigned int j = 0; j < cate.Tools.size(); j++) { TOOL tool = cate.Tools[j]; // 如果找到了对应的工具 if (tool.strName.Compare(newTool.strName) == 0 || tool.strAliasName.Compare(newTool.strName) == 0 ) { for (int k = 0; k < tool.Interfaces.size(); k++) { // 此处添加的判断,是为了应对工具端口的增加。 if (k < newTool.Interfaces.size()) { if (tool.Interfaces[k].VarType == (newTool.Interfaces[k].VarType)) { bool bShow = newTool.Interfaces[k].bShow; tool.Interfaces[k].bShow = bShow; tool.Interfaces[k].nUseCount = newTool.Interfaces[k].nUseCount; } } } // 则把本工具,以及下面的所有接口,都添加到界面中 CFunctionBlock* obj; obj = new CFunctionBlock(tool, m_nIndex); CString strTitle; strTitle.Format(_T("--%d"), m_SelTools.size()); obj->SetTitle(strTitle); // 在此添加其它属性 obj->Tools.strShowName = newTool.strShowName; obj->Tools.rect = newTool.rect; obj->Tools.strLinkName = newTool.strLinkName; obj->Tools.nInSleep = newTool.nInSleep; obj->Tools.nOutSleep = newTool.nOutSleep; obj->Tools.strInfo = newTool.strInfo; obj->Tools.nUseCount = newTool.nUseCount; obj->SetRect(newTool.rect); pContainer->Add(obj); return TRUE; } } } return FALSE; } //////////////////////////////////////////////////////////////////// // 从工具箱中添加新的工具到任务栏 BOOL CTaskWindow::AddNewTools2(const TOOL& newTool, CString* p_strShowName) { CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer(); CString strToolName = newTool.strShowName; // 处理重名问题 CString strToolShowName = strToolName; // // 遍历所有节点,查找是否有重名节点,并且找一下序号 int nRepeat = 1; vector ShowNameLink; for (int i = 0; i < m_SelTools.size(); i++) { CString strName = m_SelTools[i].strName; CString strShow = m_SelTools[i].strShowName; if (strName.Find(strToolName) >= 0) { nRepeat++; ShowNameLink.push_back(strShow); } } // 生成界面中的名字 if (nRepeat > 0) { strToolShowName.AppendFormat(_T(" %d"), nRepeat); int xxx = 0; for (int j = 0; j < ShowNameLink.size(); j++) { if (strToolShowName.Compare(ShowNameLink[j]) == 0) { xxx++; strToolShowName.AppendFormat(_T("-%d"), xxx); } } //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 ); m_RenameList.insert(pair(strToolShowName, strToolName)); } *p_strShowName = strToolShowName; // 依次将对应的工具信息添加到界面中 for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++) { TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i]; // 遍历本分类中的所有信息 for (unsigned int j = 0; j < cate.Tools.size(); j++) { TOOL tool = cate.Tools[j]; // 如果找到了对应的工具 if (tool.strName.Compare(newTool.strName) == 0 || tool.strAliasName.Compare(newTool.strName) == 0 ) { // 把本工具,以及下面的所有接口,都添加到界面中 CFunctionBlock* obj; obj = new CFunctionBlock(tool, m_nIndex); CString strTitle; strTitle.Format(_T("--%d"), m_SelTools.size()); obj->SetTitle(strTitle); // 在此添加其它属性 obj->Tools.strShowName = strToolShowName; obj->Tools.rect = newTool.rect; obj->Tools.strLinkName = tool.strLinkName; obj->Tools.nInSleep = tool.nInSleep; obj->Tools.nOutSleep = tool.nOutSleep; obj->Tools.strInfo = tool.strInfo; obj->Tools.nUseCount = tool.nUseCount; obj->SetRect(newTool.rect); pContainer->Add(obj); return TRUE; } } } return FALSE; } //////////////////////////////////////////////////////////////////// // 根据用户拖动的内容添加接口连线 BOOL CTaskWindow::AddLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD) { TOOL_INTERFACE* pInfStart = NULL; TOOL_INTERFACE* pInfEnd = NULL; // 首先搜索到起点和终点 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; for (unsigned int j = 0; j < tool.Interfaces.size(); j++) { TOOL_INTERFACE inf = tool.Interfaces[j]; if (inf.hHandle == m_hItemDragS) { pInfStart = &tool.Interfaces[j]; pInfStart->nUseCount++; break; } else if (inf.hHandle == m_hItemDragD) { pInfEnd = &tool.Interfaces[j]; pInfEnd->nUseCount++; break; } } } if (pInfStart == NULL || pInfEnd == NULL) { return FALSE; } // 建立关联 MakeLink(*pInfStart, *pInfEnd); return TRUE; } //////////////////////////////////////////////////////////////////// // 根据用户拖动的内容添加接口连线 BOOL CTaskWindow::AddLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bIsLoad) { TOOL_INTERFACE* pInfStart = NULL; TOOL_INTERFACE* pInfEnd = NULL; // 首先搜索到起点和终点 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; for (unsigned int j = 0; j < tool.Interfaces.size(); j++) { TOOL_INTERFACE inf = tool.Interfaces[j]; if (inf == source/* && inf.InfDirection == INF_DIRECTION::INF_OUT && inf.strParentName != dest.strParentName*/) { pInfStart = &tool.Interfaces[source.nIndex - 1]; if (!bIsLoad) pInfStart->nUseCount++; //break; } if (inf == dest /* && inf.InfDirection == INF_DIRECTION::INF_IN && inf.strParentName != source.strParentName*/) { pInfEnd = &tool.Interfaces[dest.nIndex - 1]; if (!bIsLoad) pInfEnd->nUseCount++; //break; } } } if (pInfStart == NULL || pInfEnd == NULL) { if (pInfStart == NULL) { CString strMsg; strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, source.strParentName, source.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } if (pInfEnd == NULL) { CString strMsg; strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, dest.strParentName, dest.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } CString strMsg; strMsg.Format(_T("Task[%d] Make link Error: %s-%s to %s-%s"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } if (pInfStart->strParentName == pInfEnd->strParentName) { return FALSE; } BOOL status = MakeLink(*pInfStart, *pInfEnd);// 建立关联 return status; return TRUE; } /////////////////////////////////////////////////////////////////////////// // 根据用户拖动的内容添加接口连线 BOOL CTaskWindow::AddTestLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD) { TOOL_INTERFACE* pInfStart = NULL; TOOL_INTERFACE* pInfEnd = NULL; // 首先搜索到起点和终点 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; for (unsigned int j = 0; j < tool.Interfaces.size(); j++) { TOOL_INTERFACE inf = tool.Interfaces[j]; if (inf.hHandle == m_hItemDragS) { pInfStart = &tool.Interfaces[j]; break; } else if (inf.hHandle == m_hItemDragD) { pInfEnd = &tool.Interfaces[j]; break; } } } if (pInfStart == NULL || pInfEnd == NULL) { return FALSE; } // 建立关联 MakeTestLink(*pInfStart, *pInfEnd); return TRUE; } /////////////////////////////////////////////////////////////////////////// // 添加工具到任务栏的时候智能链接 void CTaskWindow::SmartLink() { int nIndex = (int)m_SelTools.size() - 1; if (nIndex < 1) { return; } //获取最后一个添加的工具 TOOL tool = m_SelTools[nIndex]; for (unsigned int i = 0; i < tool.Interfaces.size(); i++) { const TOOL_INTERFACE& DestInf = tool.Interfaces[i]; // 如果当前接口设置了不显示,则不显示该接口 if ((DestInf.InfType == INF_VALUE_1 || DestInf.InfType == INF_VALUE_2 || DestInf.InfType == INF_VALUE_3 || DestInf.InfType == INF_VALUE_4) && (DestInf.InfDirection == INF_IN)) { if (DestInf.bSmartLink && DestInf.bShow) { ToSmartLink(DestInf); } } } } /////////////////////////////////////////////////////////////////////////// //通过输入的目标端口执行智能链接动作 void CTaskWindow::ToSmartLink(const TOOL_INTERFACE& DestInf) { //遍历现有工具(逆序),找最近的端口链接 //遍历的时候跳过了工具自身,所以下面下面的初始值为 2 for (int j = (int)m_SelTools.size() - 2; j >= 0; j--) { TOOL toolTemp = m_SelTools[j]; //目前执行的智能链接策略为,逆序找最近的同属性端口,可能不是客户最终需要的端口,所以需要优化 for (unsigned int k = 0; k < toolTemp.Interfaces.size(); k++) { const TOOL_INTERFACE& SourceInf = toolTemp.Interfaces[k]; if ((SourceInf.InfType == INF_VALUE_1 || SourceInf.InfType == INF_VALUE_2 || SourceInf.InfType == INF_VALUE_3 || SourceInf.InfType == INF_VALUE_4) && (SourceInf.InfDirection == INF_OUT)) { if (DestInf.VarType == SourceInf.VarType) { if (DestInf.bSmartLink && SourceInf.bSmartLink) { AddLink(SourceInf, DestInf); return; } } } } } } // /////////////////////////////////////////////////////////////// //// 判断一个节点是否是输入节点 //BOOL CTaskWindow::IsInputNode(const HTREEITEM& handle) //{ // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle); // if (pInf == NULL) // { // return FALSE; // } // ASSERT(pInf != NULL); // // if (pInf->bWay == INF_IN) // { // return TRUE; // } // else // { // return FALSE; // } //} // /////////////////////////////////////////////////////////////// //// 判断一个节点是否是输出节点 //BOOL CTaskWindow::IsOutputNode(const HTREEITEM& handle) //{ // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle); // if (pInf == NULL) // { // return FALSE; // } // ASSERT(pInf != NULL); // // if (pInf->bWay == INF_OUT) // { // return TRUE; // } // else // { // return FALSE; // } //} ////////////////////////////////////////////////////////////////// // 计算连线的绘制坐标 LINK_POINTS CTaskWindow::CalcLinkPoints(const LINK& lnk) { LINK_POINTS lp; TOOL_INTERFACE toolStart = lnk.source; TOOL_INTERFACE toolEnd = lnk.dest; // 根据对应的矩形区域进行绘制 CRect rcStart, rcEnd; TOOL_INTERFACE* pInfStart = GetInterfaceByHandle(toolStart.hHandle); TOOL_INTERFACE* pInfEnd = GetInterfaceByHandle(toolEnd.hHandle); if (pInfStart && pInfEnd) { rcStart = pInfStart->rect; rcEnd = pInfEnd->rect; } // TRACE(_T("Start: %d %d %d %d - rcEnd: %d %d %d %d\n"), // /*m_wndTree.GetItemText(toolStart.hHandle), m_wndTree.GetItemText(toolEnd.hHandle),*/ // rcStart.left, rcStart.top, rcStart.right, rcStart.bottom, // rcEnd.left, rcEnd.top, rcEnd.right, rcEnd.bottom); lp.ptStart.x = rcStart.right; lp.ptStart.y = rcStart.top + rcStart.Height() / 2; lp.ptEnd.x = rcEnd.right; lp.ptEnd.y = rcEnd.top + rcEnd.Height() / 2; lp.ptEnd.x = lp.ptEnd.x - PORT_WIDTH; if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//1 lp.nMode = 1; else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//2 lp.nMode = 2; else if ((lp.ptStart.x <= lp.ptEnd.x) && (lp.ptStart.y >= lp.ptEnd.y))//3 lp.nMode = 3; else if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y < lp.ptEnd.y))//4 lp.nMode = 4; else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y <= lp.ptEnd.y))//5 lp.nMode = 5; else if ((lp.ptStart.y > lp.ptEnd.y) && (lp.ptStart.x > lp.ptEnd.x))//6 lp.nMode = 6; switch (lp.nMode) { case 1: { lp.ptCorner1 = lp.ptStart; lp.ptCorner2 = lp.ptStart; lp.ptCorner3 = lp.ptEnd; lp.ptCorner4 = lp.ptEnd; } break; case 2: { lp.ptCorner1.x = lp.ptStart.x + 10; lp.ptCorner1.y = lp.ptStart.y; lp.ptCorner4.x = lp.ptEnd.x - 10; lp.ptCorner4.y = lp.ptEnd.y; lp.ptCorner2.x = lp.ptCorner1.x; lp.ptCorner2.y = lp.ptCorner1.y + 10; lp.ptCorner3.x = lp.ptCorner4.x; lp.ptCorner3.y = lp.ptCorner2.y; } break; case 3: case 4: { lp.ptCorner1.x = (long)((lp.ptEnd.x - lp.ptStart.x) * 0.1) + lp.ptStart.x; lp.ptCorner1.y = (long)lp.ptStart.y; lp.ptCorner2.x = (long)lp.ptCorner1.x; lp.ptCorner2.y = lp.ptEnd.y; lp.ptCorner3 = lp.ptCorner2; lp.ptCorner4 = lp.ptCorner2; } break; case 5: { lp.ptCorner1.x = lp.ptStart.x + 10; lp.ptCorner1.y = lp.ptStart.y; lp.ptCorner4.x = lp.ptEnd.x - 10; lp.ptCorner4.y = lp.ptEnd.y; lp.ptCorner2.x = lp.ptCorner1.x; lp.ptCorner2.y = (long)((lp.ptCorner4.y - lp.ptCorner1.y) * 0.1) + lp.ptCorner1.y; lp.ptCorner3.x = lp.ptCorner4.x; lp.ptCorner3.y = lp.ptCorner2.y; } break; case 6: { lp.ptCorner1.x = lp.ptStart.x + 10; lp.ptCorner1.y = lp.ptStart.y; lp.ptCorner4.x = lp.ptEnd.x - 10; lp.ptCorner4.y = lp.ptEnd.y; lp.ptCorner2.x = lp.ptCorner1.x; lp.ptCorner2.y = (long)((lp.ptCorner1.y - lp.ptCorner4.y) * 0.1) + lp.ptCorner4.y; lp.ptCorner3.x = lp.ptCorner4.x; lp.ptCorner3.y = lp.ptCorner2.y; } break; default: break; } return lp; } //////////////////////////////////////////////////////////// // 绘制链接 void CTaskWindow::DrawLink(CDC* pDC) { if (m_Links.size() <= 0) { return; } LINK_MAP::iterator iter; for (iter = m_Links.begin(); iter != m_Links.end(); iter++) { // 计算需要绘制link的联线坐标位置 LINK_POINTS lps = CalcLinkPoints(*iter); // 选择画笔 CPen *pOldPen = NULL; // 根据线条的命中与否选择不同的画笔 if (iter->bShow) { if (iter->bActive) { pOldPen = pDC->SelectObject(&m_penLinkBold); } else { pOldPen = pDC->SelectObject(&m_penLink); } pDC->MoveTo(lps.ptStart); pDC->LineTo(lps.ptCorner1); pDC->LineTo(lps.ptCorner2); pDC->LineTo(lps.ptCorner3); pDC->LineTo(lps.ptCorner4); pDC->LineTo(lps.ptEnd); // 绘制箭头 CPoint ptArrowTop, ptArrowBottom; ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH; ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH; ptArrowBottom.x = ptArrowTop.x; ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH; pDC->LineTo(ptArrowTop); pDC->MoveTo(lps.ptEnd); pDC->LineTo(ptArrowBottom); pDC->SelectObject(pOldPen); } } } //////////////////////////////////////////////////////////// // 绘制预览链接 void CTaskWindow::DrawPreviewLink(CDC* pDC) { if (m_TsetLinks.size() <= 0) { return; } LINK_MAP::iterator iter; for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++) { LINK_POINTS lps = CalcLinkPoints(*iter); // 选择画笔 CPen *pOldPen = NULL; pOldPen = pDC->SelectObject(&m_penLinkTest); pDC->MoveTo(lps.ptStart); pDC->LineTo(lps.ptCorner1); pDC->LineTo(lps.ptCorner2); pDC->LineTo(lps.ptCorner3); pDC->LineTo(lps.ptCorner4); pDC->LineTo(lps.ptEnd); // 绘制箭头 CPoint ptArrowTop, ptArrowBottom; ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH; ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH; ptArrowBottom.x = ptArrowTop.x; ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH; pDC->LineTo(ptArrowTop); pDC->MoveTo(lps.ptEnd); pDC->LineTo(ptArrowBottom); pDC->SelectObject(pOldPen); } } ///////////////////////////////////////////////////////////////////// // 更新节点数据结构 void CTaskWindow::UpdateTools(bool bIsLoad ) { CDiagramEntityContainer* objs = static_cast (m_editor.GetDiagramEntityContainer()); if (objs) { UINT nIndex = 0; for (UINT u = 0; u < objs->GetSize(); u++) { // if (objs->GetAt(u)->GetType() != _T("Tool")) // { // continue; // } CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(u); CString strTitle; strTitle.Format(_T("%d"), nIndex); obj->Tools.nToolID = nIndex; obj->SetTitle(strTitle); CString strToolShowName = obj->Tools.strShowName; BOOL bFind = FALSE; UINT i = 0; HTREEITEM hParent = obj->Tools.hHandle; // 查找当前选中的工具集合中是否有当前的工具 for (; i < m_SelTools.size(); i++) { if (m_SelTools[i].strShowName.Compare(strToolShowName) == 0) { bFind = TRUE; break; } } // 如果找到了这个工具,只需要调整一下顺序,然后更新句柄 if (bFind) { if (i > nIndex) { TOOL toolTemp = m_SelTools[i]; m_SelTools[i] = m_SelTools[nIndex]; m_SelTools[nIndex] = toolTemp; } else if (i < nIndex) { hParent = obj->Tools.hHandle; continue; } UpdateExistTool(m_SelTools[nIndex], obj->Tools); //用来在页面上显示工具是否需要触发 TOOL tool = m_SelTools[nIndex]; EVEN m_hEven = tool.pDllPtr->m_Even; obj->SetToolMode(m_hEven.hEvenHandle); nIndex++; } // 否则是一个新的工具 else { UpdateNewTool(strToolShowName, obj->Tools, bIsLoad); } } this->UpdateLink(); } } ////////////////////////////////////////////////////////////////// // 更新现有工具 void CTaskWindow::UpdateExistTool(TOOL& tool, TOOL& tool_Info) { // 获取句柄 tool.hHandle = tool_Info.hHandle; tool.rect = tool_Info.rect; tool.nToolID = tool_Info.nToolID; tool_Info.nInSleep = tool.nInSleep; tool_Info.nOutSleep = tool.nOutSleep; tool_Info.strLinkName = tool.strLinkName; for (unsigned int j = 0; j < tool.Interfaces.size(); j++) { TOOL_INTERFACE& inf = tool.Interfaces[j]; { inf.hHandle = tool_Info.Interfaces[j].hHandle; CRect rect = tool_Info.Interfaces[j].rect; if (!rect.IsRectEmpty()) { inf.rect = tool_Info.Interfaces[j].rect; } if (tool.Type == TOOL_TYPE::TOOL_BY_PROT) { tool_Info.Interfaces[j].bShow = inf.bShow; } else { inf.bShow = tool_Info.Interfaces[j].bShow; } tool_Info.Interfaces[j].strName = inf.strName; tool_Info.Interfaces[j].nUseCount = inf.nUseCount; tool_Info.Interfaces[j].strParentName = inf.strParentName; } } } ///////////////////////////////////////////////////////////////// // 更新新工具 void CTaskWindow::UpdateNewTool(const CString& strToolShowName, TOOL tool_Info, bool bIsLoad ) { CString strToolRealName = GetToolRealname(strToolShowName); // 查询对应的工具 TOOL newTool = g_pTaskView->m_wndTool.GetToolByName(strToolRealName); newTool.strShowName = strToolShowName; // 获取句柄 newTool.hHandle = tool_Info.hHandle; newTool.rect = tool_Info.rect; newTool.strInfo = tool_Info.strInfo; newTool.strLinkName = tool_Info.strLinkName; newTool.nUseCount = tool_Info.nUseCount; for (unsigned int j = 0; j < newTool.Interfaces.size(); j++) { TOOL_INTERFACE& inf = newTool.Interfaces[j]; inf.strParentName = strToolShowName; inf.hHandle = tool_Info.Interfaces[j].hHandle; inf.rect = tool_Info.Interfaces[j].rect; inf.nUseCount = tool_Info.Interfaces[j].nUseCount; } USES_CONVERSION; char * s_str = T2A(strToolShowName); g_Logger.Info(0, __FILE__, __LINE__, "Task[%d] Add Tool: %s ",m_nIndex, s_str); // 从dll获取工具指针 if (!GetToolPtrByDll(newTool)) { CString strMsg; strMsg.Format(_T("Task[%d] %s 工具加载dll工具失败!"),m_nIndex, newTool.strShowName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return; } if (newTool.pDllPtr != NULL) { //首先注册日志回调,以便在主框架中显示所有的工具日志 newTool.pDllPtr->setReceLogCallBack(ToolLogCallback, (long long)g_pMainFrame); //注册工具状态回调,以便在主框架中显示工具状态 newTool.pDllPtr->setReceToolStateCallBack(ToolStateCallback, (long long)this); //注册工具中的执行回调,以便在工具中执行当前工具 newTool.pDllPtr->setOnExecuteCallBack(ToolOnExecuteCallback, (long long)this); //注册工具中的执行回调,以便在工具中执行当前工具 newTool.pDllPtr->setToolBusyCallBack(ToolBusyCallback, (long long)this); m_SelTools.push_back(newTool); //初始化工具 newTool.pDllPtr->InitTool(g_pMainFrame->GetActiveView(), m_strTaskName, newTool.strShowName); } if (! bIsLoad) { if (BCGPMessageBox(_T("是否执行自动数据链接 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("SmartLink .....")) == IDYES) SmartLink(); } Invalidate(TRUE); } ///////////////////////////////////////////////////////////////// // 更新所有节点的连接信息 void CTaskWindow::UpdateLink() { // 遍历所有节点,更新对应的句柄信息 for (unsigned int i = 0; i < m_Links.size(); i++) { LINK& lnk = m_Links[i]; for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& tool = m_SelTools[m]; for (unsigned int n = 0; n < tool.Interfaces.size(); n++) { TOOL_INTERFACE& inf = tool.Interfaces[n]; if (IsSameInterface(lnk.source, inf)) { lnk.source = inf; break; } else if (IsSameInterface(lnk.dest, inf)) { lnk.dest = inf; break; } } } } } ///////////////////////////////////////////////////////////////// // 建立连接 bool CTaskWindow::MakeLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bShow) { // 首先检查一下是否有key相同的接口 LINK_MAP::iterator iter; for (iter = m_Links.begin(); iter != m_Links.end(); iter++) { if (IsSameInterface(dest, iter->dest)) { // 替换现有link iter->source = source; CString str; str.Format(_T("Task[%d] Update link: %s-%s to %s-%s"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); USES_CONVERSION; char * s_str = T2A(str); g_Logger.Debug(0, __FILE__, __LINE__, s_str); return TRUE; } } // 否则添加一个新的link LINK newLink; newLink.source = source; newLink.dest = dest; newLink.bShow = bShow; m_Links.push_back(newLink); CString strMsg; strMsg.Format(_T("Task[%d] Make link: %s-%s to %s-%s"),m_nIndex, newLink.source.strParentName, newLink.source.strName, newLink.dest.strParentName, newLink.dest.strName); //TRACE(str); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Info(0, __FILE__, __LINE__, s_str); return TRUE; } // 建立连接 bool CTaskWindow::MakeTestLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest) { // 首先检查一下是否有key相同的接口 LINK_MAP::iterator iter; for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++) { if (IsSameInterface(dest, iter->dest)) { // 替换现有link iter->source = source; TRACE(_T("Update link: %s-%s to %s-%s\n"), source.strParentName, source.strName, dest.strParentName, dest.strName); return TRUE; } } // 否则添加一个新的link LINK newLink; newLink.source = source; newLink.dest = dest; m_TsetLinks.clear(); m_TsetLinks.push_back(newLink); TRACE(_T("Make link: %s-%s to %s-%s\n"), newLink.source.strParentName, newLink.source.strName, newLink.dest.strParentName, newLink.dest.strName); return TRUE; } ///////////////////////////////////////////////////////////////// // 根据句柄转换成对应的TOOL TOOL* CTaskWindow::GetToolByHandle(const HTREEITEM& handle) { for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; if (tool.hHandle == handle) { return &m_SelTools[i]; } } return NULL; } ////////////////////////////////////////////////////////////////////////// // 根据显示的名称转换乘对应的TOOL TOOL* CTaskWindow::GetToolByShowName(const CString strName) { for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; if (tool.strShowName == strName) { return &m_SelTools[i]; } } return NULL; } //////////////////////////////////////////////////////////////// // 根据句柄转换成对应的Interface TOOL_INTERFACE* CTaskWindow::GetInterfaceByHandle(const HTREEITEM& handle) { for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (infSearch.hHandle == handle) { return &m_SelTools[m].Interfaces[n]; } } } return NULL; } //////////////////////////////////////////////////////////////// // 根据 名字 转换成对应的Interface TOOL_INTERFACE* CTaskWindow::GetInterfaceByName(const CString strParentName, const CString strName) { for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; if (toolSearch.strShowName.Compare(strParentName) == 0) { for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (infSearch.strName.Compare(strName) == 0) { return &m_SelTools[m].Interfaces[n]; } } } } return NULL; } ///////////////////////////////////////////////////////////////// // 重置整个TaskWindow的相关数据 void CTaskWindow::Reset() { // 清空数据结构 //m_SelTools.clear(); m_Links.clear(); m_RenameList.clear(); m_TsetLinks.clear(); // 清空树形控件 // m_wndTree.Clear(); // m_wndTree.Invalidate(TRUE); m_editor.DeleteAll(); m_editor.Clear(); m_editor.Invalidate(TRUE); // TODO:清空多线程任务相关的状态 // 第一个线程不退出,需要优化 if (m_nIndex != 0) { // 为了使线程退出 m_bExitThread = true; // 为了可使挂起的现场继续执行下去 SetEvent(m_hExecuteEven); SetEvent(m_hDoneEven); //释放线程相关的句柄 RELEASE_HANDLE(m_hDoneEven); RELEASE_HANDLE(m_hExecuteEven); } // 一定要记得清理 dll 指针,否则持续退出会崩溃在系统dll里 for (size_t i = 0; i < m_SelTools.size(); i++) { RELEASE_BUFFER(m_SelTools.at(i).pDllPtr); FreeLibrary(m_SelTools[i].hDllTool); } //// 2019-3-23 释放选择的工具 //for (unsigned int i = 0; i < m_SelTools.size(); i++) //{ // // 调用Release // if (m_SelTools[i].hDllTool) // { // // 调用Release接口 // typedef void(*RELEASE)(); // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE); // if (Release) // { // Release(); // } // FreeLibrary(m_SelTools[i].hDllTool); // } //} m_SelTools.clear(); } //////////////////////////////////////////////////////////////// // 获取某个Interface相连的接口 TOOL_INTERFACE* CTaskWindow::GetHigherLinkInterface(const TOOL_INTERFACE& inf) { // 遍历所有Link for (unsigned int j = 0; j < m_Links.size(); j++) { LINK& lnk = m_Links[j]; if (IsSameInterface(lnk.dest, inf)) { return &lnk.source; } } return NULL; } /////////////////////////////////////////////////////////////// // 根据Interface获取Tool TOOL* CTaskWindow::GetToolByInterface(TOOL_INTERFACE& inf) { for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (IsSameInterface(inf, infSearch)) { return &toolSearch; } } } // 查找全局变量 TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (IsSameInterface(inf, infSearch)) { return &toolSearch; } } return NULL; } /////////////////////////////////////////////////////////////// // 根据Interface获取Interface TOOL_INTERFACE* CTaskWindow::GetInterfaceByInterface(TOOL_INTERFACE& inf) { for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (IsSameInterface(inf, infSearch)) { return &infSearch; } } } // 查找全局变量 TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (IsSameInterface(inf, infSearch)) { return &infSearch; } } return NULL; } ////////////////////////////////////////////////////////////////////////// // 根据Tool获取Tool TOOL* CTaskWindow::GetToolByTool(TOOL& tool) { for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; if (tool.strShowName == toolSearch.strShowName && tool.strName == toolSearch.strName ) { return &toolSearch; } } return NULL; } //////////////////////////////////////////////////////////////////// // 判断是否是同一个接口 bool CTaskWindow::IsSameInterface(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest) { return source.strParentName == dest.strParentName && source.strName == dest.strName && source.InfDirection == dest.InfDirection && source.InfWay == dest.InfWay; } /////////////////////////////////////////////////////////// // 计算连接线的长度 int CTaskWindow::CalcLinkLineLength(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest) { int nLength = 0; bool bSearch = false; /* CString strName = m_wndTree.GetItemText(source.hHandle); // TRACE(_T("strName: %s\n"), strName); for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; // CString strName1 = m_wndTree.GetItemText(infSearch.hHandle); // TRACE(_T("strName1: %s\n"), strName1); if (bSearch) { CRect rc; m_wndTree.GetItemRect(infSearch.hHandle, &rc, TRUE); if (rc.right > nLength) { nLength = rc.right; } if (IsSameInterface(dest, infSearch)) { return nLength; } } else { if (IsSameInterface(source, infSearch)) { CRect rc; m_wndTree.GetItemRect(source.hHandle, &rc, TRUE); nLength = rc.right; bSearch = true; } } } } */ return nLength; } ///////////////////////////////////////////////////// // 通过工具显示的名字查询工具真正的名字 CString CTaskWindow::GetToolRealname(const CString& strShowName) { CString strRealName; map::iterator iter; for (iter = m_RenameList.begin(); iter != m_RenameList.end(); iter++) { if (strShowName.Compare(iter->first) == 0) { strRealName = iter->second; return strRealName; } } return strShowName; } ///////////////////////////////////////////////////////////// // 计算连线的触发区域 LINK_RECTS CTaskWindow::CalcLinkRects(const LINK_POINTS& lps) { LINK_RECTS lrs; lrs.rcStart.left = lps.ptStart.x - PORT_WIDTH; lrs.rcStart.right = lps.ptCorner1.x; lrs.rcStart.top = lps.ptStart.y - HOT_REGION; lrs.rcStart.bottom = lps.ptStart.y + HOT_REGION; lrs.rcEnd.left = lps.ptCorner4.x; lrs.rcEnd.right = lps.ptEnd.x + PORT_WIDTH; lrs.rcEnd.top = lps.ptEnd.y - HOT_REGION; lrs.rcEnd.bottom = lps.ptEnd.y + HOT_REGION; lrs.rcCorner1.left = lps.ptCorner1.x - HOT_REGION; lrs.rcCorner1.right = lps.ptCorner1.x + HOT_REGION; switch (lps.nMode) { case 1: case 2: case 3: case 4: lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top; lrs.rcCorner1.bottom = lrs.rcStart.bottom > lrs.rcEnd.bottom ? lrs.rcStart.bottom : lrs.rcEnd.bottom; break; case 5: lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top; lrs.rcCorner1.bottom = lps.ptCorner2.y; break; case 6: lrs.rcCorner1.top = lps.ptCorner2.y; lrs.rcCorner1.bottom = lps.ptStart.y; break; default: break; } lrs.rcCorner3.left = lps.ptCorner3.x - HOT_REGION; lrs.rcCorner3.right = lps.ptCorner3.x + HOT_REGION; if (lps.nMode == 5) { lrs.rcCorner3.top = lps.ptCorner3.y; lrs.rcCorner3.bottom = lps.ptEnd.y; }if (lps.nMode == 6) { lrs.rcCorner3.top = lps.ptEnd.y; lrs.rcCorner3.bottom = lps.ptCorner3.y; } lrs.rcCorner2.left = lps.ptCorner3.x; lrs.rcCorner2.right = lps.ptCorner1.x; lrs.rcCorner2.top = lps.ptCorner3.y - HOT_REGION; lrs.rcCorner2.bottom = lps.ptCorner3.y + HOT_REGION; return lrs; } /////////////////////////////////////////////////////// // 鼠标左键按下时,激活连线 void CTaskWindow::OnLButtonDown(UINT nFlags, CPoint point) { // 循环遍历所有连线区域,查找是否有命中的 CPoint pt = point; m_editor.ScreenToVirtual(pt); LINK_MAP::iterator iter; // 然后查找命中 for (iter = m_Links.begin(); iter != m_Links.end(); iter++) { // 计算这个连线的矩形区域 LINK_POINTS lps = CalcLinkPoints(*iter); LINK_RECTS lrs = CalcLinkRects(lps); // 判断鼠标是否命中 if (PtInRect(&lrs.rcStart, pt) || PtInRect(&lrs.rcEnd, pt) || PtInRect(&lrs.rcCorner1, pt) || PtInRect(&lrs.rcCorner2, pt) || PtInRect(&lrs.rcCorner3, pt) ) { // 如果命中,则把这条线设置为命中状态 iter->bActive = TRUE; // 然后把其他连接设置为未命中状态 for (unsigned int i = 0; i < m_Links.size(); i++) { if (*iter != m_Links[i]) { m_Links[i].bActive = FALSE; } } // Invalidate(TRUE); break; } else { //点击空白处,将所有连线设置为未选中状态 for (unsigned int i = 0; i < m_Links.size(); i++) { m_Links[i].bActive = FALSE; } } } CBCGPStatic::OnLButtonDown(nFlags, point); } ////////////////////////////////////////////////////////////////////////// // 当 Item单击时候 void CTaskWindow::OnItemLButtonDown(const HTREEITEM& handle) { TOOL* pActiveTool = GetToolByHandle(handle); if (pActiveTool == NULL) { return; } // 根据Tool的指针调用函数 if (pActiveTool != NULL) { DEUBGOBJ obj = pActiveTool->pDllPtr->GetDeubgDispObj(); g_pTaskView->m_wndDisp.AddImage(obj.mImage); g_pTaskView->m_wndDisp.AddOjb(obj.mObj); g_pTaskView->m_wndDisp.Refresh(); } } //////////////////////////////////////////////////////// // 当Item双击时 void CTaskWindow::OnItemDblclk(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pActiveTool = GetToolByHandle(handle); if (pActiveTool == NULL) { return; } if (pActiveTool->Type == TOOL_TYPE::TOOL_BY_PROT && pActiveTool->strLinkName.IsEmpty() ) { CDialogLink dlgLink; dlgLink.m_InfType = INF_TYPE::INF_VALUE_1; dlgLink.m_LinkVarType = VAR_TYPE::ALL_Var; dlgLink.m_Direction = INF_DIRECTION::INF_OUT; for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++) { TOOL_INTERFACE inf = pActiveTool->Interfaces[i]; if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.bShow == true) { dlgLink.m_LinkVarType = inf.VarType; } } if (dlgLink.DoModal() == IDOK) { for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++) { TOOL_INTERFACE inf = pActiveTool->Interfaces[i]; if (inf.InfDirection == INF_DIRECTION::INF_IN && inf.VarType == dlgLink.m_SelInterface.VarType) { TOOL_INTERFACE* pInfSource = GetInterfaceByInterface(dlgLink.m_SelInterface); TOOL_INTERFACE* pInfDest = GetInterfaceByInterface(inf); ASSERT(pInfDest != NULL); if (pInfDest != NULL && pInfSource != NULL /*&& dlgLink.m_nTaskIndex != TASK_SYSTEM_GV*/) { if (dlgLink.m_nTaskIndex == TASK_SYSTEM_GV) { pInfSource = g_pMainFrame->m_GlobalValueDlg.GetInterfaceByInterface(dlgLink.m_SelInterface); for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++) { TOOL_INTERFACE& inf = pActiveTool->Interfaces[i]; if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.VarType == dlgLink.m_SelInterface.VarType) { inf.bShow = true; } } } // 内部引用计数加一 pInfSource->nUseCount ++; pInfDest->nUseCount++; const TOOL_INTERFACE source = *pInfSource; const TOOL_INTERFACE dest = *pInfDest; MakeLink(source, dest, false); pInfDest->bShow = true; CString strLink; strLink.Format(_T("%s.%s.Q"), dlgLink.m_SelInterface.strParentName, dlgLink.m_SelInterface.strName); pActiveTool->strLinkName = strLink; UpdateTools(); } else { CString strMsg; strMsg.Format(_T("Task[%d] Link Error %s.%s --> %s.%s "), m_nIndex, dlgLink.m_SelInterface.strParentName, dlgLink.m_SelInterface.strName, inf.strParentName, inf.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } } } } } // 根据Tool的指针调用函数 if (pActiveTool != NULL) { if (pActiveTool->bEnable == false) { g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作.....")); return; } pActiveTool->pDllPtr->ShowDialog(m_strTaskName, pActiveTool->strShowName); } } //////////////////////////////////////////////////////// // 当Item双击时 子节点 void CTaskWindow::OnItemNodeDblclk(const HTREEITEM& handle) { TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle); if (pInf != NULL) { if (pInf->InfDirection == INF_DIRECTION::INF_IN && pInf->nUseCount == 0) { if (BCGPMessageBox(_T("是否添加 Prot 端口"), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Add Prot .....")) == IDYES) { TOOL* pDestTool = GetToolByShowName(pInf->strParentName);// 点击的模块(工具实体模块) pInf->rect.TopLeft().x -= 150; pInf->rect.TopLeft().y -= 5; TOOL newTool; newTool.strName = _T("InPutProt"); newTool.strShowName = _T("InPutProt"); newTool.rect = pInf->rect; CString strShowName; AddNewTools2(newTool, &strShowName); UpdateTools(); TOOL* pSourceTool = GetToolByShowName(strShowName); if (pSourceTool != NULL) { bool bFindStatus = false; ////////////////////////////////////////////////////////////////////////// // 此处搜索的是Prot模块 for (UINT i = 0; i < pSourceTool->Interfaces.size(); i++) { TOOL_INTERFACE& inf = pSourceTool->Interfaces[i]; if (inf.InfDirection == INF_DIRECTION::INF_OUT) { TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle); if (inf.VarType == pDestInf->VarType && inf.strParentName != pDestInf->strParentName) { // 如果再prot模块里能找到对应的数据类型,就可以创建数据链接(源数据) bFindStatus = true; inf.bShow = true; BOOL status = AddLink(inf, *pDestInf); if (!status) { g_Logger.Error(0, NULL, NULL, "Task[%d] Link Error %s.%s --> %s.%s ",m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName); } CString strMsg; strMsg.Format(_T("Task[%d] Link OK %s.%s --> %s.%s "),m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Debug(0, __FILE__, __LINE__, s_str); } } } if (!bFindStatus) { TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle); if (pDestInf) { g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error %s.%s --> %s.%s [%d]",m_nIndex, pDestInf->strParentName, pDestInf->strName, pDestInf->VarType); } else { g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error",m_nIndex); } } UpdateTools(); //重新排序too的序号,使Prot序号 小于当前工具的序号 SortProtToolID (pSourceTool,pDestTool); } } } if (pInf->InfDirection == INF_DIRECTION::INF_OUT) { ShowNodeWatch(pInf); } } } //////////////////////////////////////////////////////////// // 鼠标右键删除的时候 bool CTaskWindow::OnItemEnable(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pActiveTool = GetToolByHandle(handle); ASSERT(pActiveTool != NULL); if (pActiveTool == NULL) { return false; } CString strToolName = pActiveTool->strShowName; // BCGPMessageBox(strToolName); pActiveTool->bEnable = !pActiveTool->bEnable; return pActiveTool->bEnable; } //////////////////////////////////////////////////////////// // 鼠标右键删除的时候 void CTaskWindow::OnItemDelete(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pActiveTool = GetToolByHandle(handle); ASSERT(pActiveTool != NULL); if (pActiveTool == NULL) { return; } CString strToolName = pActiveTool->strShowName; // 删除选择工具集中的信息 vector::iterator itTool; for (itTool = m_SelTools.begin(); itTool != m_SelTools.end(); ) { if (itTool->strShowName.Compare(strToolName) == 0) { RELEASE_BUFFER(itTool->pDllPtr); FreeLibrary(itTool->hDllTool); itTool = m_SelTools.erase(itTool); break; } else { ++itTool; } } // 删除重命名列表中的信息 m_RenameList.erase(strToolName); m_editor.RedrawWindow(); Invalidate(TRUE); CString strMsg; strMsg.Format(_T("Task[%d] Delete Tools:%s ") ,m_nIndex, strToolName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Warn(0, __FILE__, __LINE__, s_str); } bool CTaskWindow::IsLink(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pActiveTool = GetToolByHandle(handle); //ASSERT(pActiveTool != NULL); if (pActiveTool == NULL) { return false; } CString strToolName = pActiveTool->strShowName; bool bIsLink = false; vector::iterator itLink; for (itLink = m_Links.begin(); itLink != m_Links.end(); ) { if ((itLink->source.strParentName.Compare(strToolName) == 0) || (itLink->dest.strParentName.Compare(strToolName) == 0)) { //itLink = m_Links.erase(itLink); CString strMsg; strMsg.Format(_T("Task[%d] Link Protected %s.%s ---> %s.%s"),m_nIndex, itLink->source.strParentName, itLink->source.strName, itLink->dest.strParentName, itLink->dest.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Debug(0, __FILE__, __LINE__, s_str); bIsLink = true; break; } else { ++itLink; } } return bIsLink; } // 判断是否受保护 bool CTaskWindow::IsProtected(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pTool = GetToolByHandle(handle); ASSERT(pTool != NULL); if (pTool == NULL) { return true; } if (pTool->nUseCount) { CString strMsg; strMsg.Format(_T("Task[%d] Tool Protected %s UseCount[ %d ]"),m_nIndex, pTool->strShowName, pTool->nUseCount); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Debug(0, __FILE__, __LINE__, s_str); return true; } // 遍历本工具下的所有接口 bool bIsProtected = false; for (unsigned int k = 0; k < pTool->Interfaces.size(); k++) { const TOOL_INTERFACE& inf = pTool->Interfaces[k]; if (inf.nUseCount) { CString strMsg; strMsg.Format(_T("Task[%d] Prot Protected %s.%s UseCount[ %d ]"),m_nIndex, inf.strParentName, inf.strName, inf.nUseCount); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Debug(0, __FILE__, __LINE__, s_str); bIsProtected = true; } } return bIsProtected; } //////////////////////////////////////////////////////////////// // 用户右键菜单选择了工具重命名 void CTaskWindow::OnItemToolRename(const HTREEITEM& handle) { // 根据句柄查询到工具 TOOL* pActiveTool = GetToolByHandle(handle); CString strOldName = pActiveTool->strShowName; if (pActiveTool->bEnable == false) { g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作.....")); return; } //修改处理模块名称 CToolRenameDlg ToolRename; ToolRename.SetToolName(strOldName); if (ToolRename.DoModal() == IDOK) { CString strNewName = ToolRename.GetToolName(); CString strInfo; strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName); // 修改界面显示的名字 pActiveTool->strShowName = strNewName; CDiagramEntityContainer* objs = static_cast (m_editor.GetDiagramEntityContainer()); if (objs) { for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++) { CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex); if (obj.Tools.strShowName.Compare(strOldName) == 0) { obj.Tools.strShowName = strNewName; break; } } } // 界面重绘 Invalidate(TRUE); OUTPUT_MSG msg; msg.strMsg = strInfo; USES_CONVERSION; char * s_str = T2A(msg.strMsg); g_Logger.Debug(0, __FILE__, __LINE__, s_str); //g_pMainFrame->SendMessage(DOC_CHANGE); // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步) for (UINT i = 0; i < m_SelTools.size(); i++) { for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++) { TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j]; if (inf.strParentName.Compare(strOldName) == 0) { inf.strParentName = strNewName; } } } // 修改重命名链表 m_RenameList.erase(strOldName); m_RenameList.insert(pair(strNewName, pActiveTool->strName)); // 修改Link信息 for (UINT i = 0; i < m_Links.size(); i++) { LINK& link = m_Links[i]; if (link.source.strParentName.Compare(strOldName) == 0) { link.source.strParentName = strNewName; } else if (link.dest.strParentName.Compare(strOldName) == 0) { link.dest.strParentName = strNewName; } } } } ////////////////////////////////////////////////////////////////////////// // 编辑工具名称 void CTaskWindow::ToolRename(TOOL* pTool, const CString strNewName) { CString strOldName = pTool->strShowName; if (pTool->bEnable == false) { g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作.....")); return; } // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步) for (UINT i = 0; i < m_SelTools.size(); i++) { TOOL & tool = m_SelTools[i]; if (tool.strShowName == strNewName) { CString strMsg; strMsg.Format(_T("Task[%d] 修改工具名称( %s )为( %s) 失败"),m_nIndex, strOldName, strNewName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return; } } //修改处理模块名称 { CString strInfo; strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName); // 修改界面显示的名字 pTool->strShowName = strNewName; CDiagramEntityContainer* objs = static_cast (m_editor.GetDiagramEntityContainer()); if (objs) { for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++) { CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex); if (obj.Tools.strShowName.Compare(strOldName) == 0) { obj.Tools.strShowName = strNewName; break; } } } // 界面重绘 Invalidate(TRUE); USES_CONVERSION; char * s_str = T2A(strInfo); g_Logger.Debug(0, __FILE__, __LINE__, s_str); //g_pMainFrame->SendMessage(DOC_CHANGE); // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步) for (UINT i = 0; i < m_SelTools.size(); i++) { for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++) { TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j]; if (inf.strParentName.Compare(strOldName) == 0) { inf.strParentName = strNewName; } } } // 修改重命名链表 m_RenameList.erase(strOldName); m_RenameList.insert(pair(strNewName, pTool->strName)); // 修改Link信息 for (UINT i = 0; i < m_Links.size(); i++) { LINK& link = m_Links[i]; if (link.source.strParentName.Compare(strOldName) == 0) { link.source.strParentName = strNewName; } else if (link.dest.strParentName.Compare(strOldName) == 0) { link.dest.strParentName = strNewName; } } } } ////////////////////////////////////////////////////////// // 右键菜单Link to/from ... void CTaskWindow::OnItemLink(const HTREEITEM& source, UINT nLinkDestIndex) { ASSERT(nLinkDestIndex >= 0); TOOL_INTERFACE* pInfSource = GetInterfaceByHandle(source); TOOL_INTERFACE* pInfDest = &m_PopLinkNodes.at(nLinkDestIndex); // 建立连接 if (pInfSource->InfDirection == INF_IN) { AddLink(*pInfDest, *pInfSource); } else { AddLink(*pInfSource, *pInfDest); } // 清空右键link链表 m_PopLinkNodes.clear(); } ///////////////////////////////////////////////////////// // 右键菜单UnLink void CTaskWindow::OnItemUnLink(HTREEITEM hSelItem) { // 查找当前的link信息,取消与之相关的连接 bool bUnLink = false; vector::iterator it; for (it = m_Links.begin(); it != m_Links.end(); ) { LINK& link = *it; if (link.source.hHandle == hSelItem || link.dest.hHandle == hSelItem) { TOOL_INTERFACE* pSourceInf = GetInterfaceByInterface(link.source); ASSERT(pSourceInf != NULL); pSourceInf->nUseCount--; TOOL_INTERFACE* pDestInf = GetInterfaceByInterface(link.dest); ASSERT(pDestInf != NULL); pDestInf->nUseCount--; it = m_Links.erase(it); bUnLink = true; } else { it++; } } if (!bUnLink) { TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem); if (pInf != NULL) { pInf->nUseCount = 0; } } } //////////////////////////////////////////////////////// // 根据右键菜单获取可以link的接口 INF_DIRECTION CTaskWindow::GetPopLinkNodes(std::vector& PopLinkNodes, HTREEITEM hSelItem) { m_PopLinkNodes.clear(); INF_DIRECTION dir = INF_NONE; // 首先找到用户选中的接口 TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem); if (pInf == NULL) { return dir; } dir = pInf->InfDirection; // 然后继续寻找所有的本接口可以关联的接口 for (unsigned int m = 0; m < m_SelTools.size(); m++) { TOOL& toolSearch = m_SelTools[m]; for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++) { TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n]; if (IsSameInterface(*pInf, infSearch)) { continue; } // IN/OUT匹配,并且数据类型一致,并且不从属于同一个Tool // 则认为是可以link的接口 if (pInf->VarType == (infSearch.VarType) && pInf->InfDirection != infSearch.InfDirection && pInf->strParentName.Compare(infSearch.strParentName) != 0 ) { m_PopLinkNodes.push_back(infSearch); } } } PopLinkNodes = m_PopLinkNodes; return dir; } ////////////////////////////////////////////////// // 为Tool添加执行结果的图标 void CTaskWindow::DrawToolColour(NMLVCUSTOMDRAW* pLVCD) { pLVCD->clrText = globalData.clrBarText; // 这样设置文字颜色 HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec; LPTOOL pTool = GetToolByHandle(hItem); if ((pTool == NULL) || ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR))) { return; } // 用于在当前工具返回错误时候,用不同颜色标记 if (pTool->nToolState == TOOL_ERROR) { pLVCD->clrTextBk = RGB(255, 0, 0); // 设置文字背景颜色 } else { pLVCD->clrTextBk = globalData.clrBarHilite; // 设置文字背景颜色 pLVCD->clrText = globalData.clrBarText; // ::GetSysColor(COLOR_HIGHLIGHT); // ::GetSysColorBrush(COLOR_HIGHLIGHT); } } ////////////////////////////////////////////////// // 为Tool添加执行结果的图标 void CTaskWindow::DrawToolResult(NMLVCUSTOMDRAW* pLVCD) { /* HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec; LPTOOL pTool = GetToolByHandle(hItem); if ((pTool == NULL) || ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR))) { return; } CRect textRect; m_wndTree.GetItemRect(hItem, &textRect, TRUE); CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc); // 画图采用双缓冲 CDC memDC; memDC.CreateCompatibleDC(pDC); // 选择图片对象 CBitmap *pOldBitmap = NULL; // 位图长宽获取 BITMAP bmInfo; if (pTool->nToolState == TOOL_ERROR) { memDC.SelectObject(&m_Bitmap[0]); m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo); } else if (pTool->bEnable == false)//如果工具未启用,图标设置为新的 { memDC.SelectObject(&m_Bitmap[0]); m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo); } else if (pTool->nExecCode == RT_SUCCESS) { memDC.SelectObject(&m_Bitmap[2]); m_Bitmap[2].GetObject(sizeof(BITMAP), &bmInfo); } else { memDC.SelectObject(&m_Bitmap[1]); m_Bitmap[1].GetObject(sizeof(BITMAP), &bmInfo); } // 输出图片 pDC->BitBlt(textRect.right, textRect.top, bmInfo.bmWidth, bmInfo.bmHeight, &memDC, 0, 0, SRCCOPY); // 删除DC memDC.SelectObject(pOldBitmap); memDC.DeleteDC(); */ } ////////////////////////////////////////////////////////// // 任务窗口序列化 BOOL CTaskWindow::DoSerialize(CArchive& ar) { // 保存工具 if (ar.IsStoring()) { if (!SaveToFile(ar)) { return FALSE; } } // 读取工具信息 else { theApp.UpdateSplash(_T("CTaskWindow::DoSerialize()")); // 重置链表 m_RenameList.clear(); // 2019-3-23 释放选择的工具 for (unsigned int i = 0; i < m_SelTools.size(); i++) { // 调用Release if (m_SelTools[i].hDllTool) { // 调用Release接口 typedef void(*RELEASE)(); RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE); if (Release) { Release(); } FreeLibrary(m_SelTools[i].hDllTool); } } m_SelTools.clear(); if (!LoadFromFile(ar)) { return FALSE; } } // 这段代码之前需要保存流程栏的工具和连线 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; USES_CONVERSION; char * s_str = T2A(tool.strShowName); try { theApp.UpdateSplash(tool.strShowName + _T("DoSerialize()")); tool.pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion); } catch (...) { // CString strMsg; // strMsg.Format(_T("%s Tool Serialize Error"), tool.strShowName); // // OUTPUT_MSG msg; // msg.bWay = MSG_WAY::_ERROR; // msg.strMsg = strMsg; g_Logger.Error(0, __FILE__, __LINE__, ("%s Tool Serialize Error"), s_str); } } m_editor.RedrawWindow(); return TRUE; } // 保存工具信息到文件中 BOOL CTaskWindow::SaveToFile(CArchive& ar) { int nParanum;//参数数量 nParanum = 8;//以下参数的数量 ar << nParanum; ar << (int)1 << (int)m_editor.GetVirtualSize().cx; ar << (int)2 << (int)m_editor.GetVirtualSize().cy; ar << (int)3 << (int)m_editor.GetGridSize().cx; ar << (int)4 << (int)m_editor.GetGridSize().cy; ar << (int)5 << (int)m_nMarginLeft; ar << (int)6 << (int)m_nMarginTop; ar << (int)7 << (int)m_nMarginBottom; ar << (int)8 << (int)m_nMarginRight; nParanum = 16;//以下参数的数量 ar << nParanum;//先保存参数数量 ar << (UINT)m_SelTools.size(); for (UINT i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; // 版本 ar << (int)1 << tool.strVersion; // 名称 ar << (int)2 << tool.strName; // 显示名称 ar << (int)3 << tool.strShowName; // dll路径 ar << (int)4 << tool.strDll; // 是否展开 ar << (int)5 << tool.bIsExpand; // 是否启用 ar << (int)6 << tool.bEnable; // ar << (int)7 << (int)tool.Type; // 区域 ar << (int)8 << tool.rect; ar << (int)9 << tool.strLinkName; ar << (int)10 << tool.nInSleep; ar << (int)11 << tool.nOutSleep; ar << (int)12 << tool.strInfo; ar << (int)13 << tool.hNextTool.nToolID; ar << (int)14 << tool.hNextTool.strName; ar << (int)15 << tool.hNextTool.strShowName; ar << (int)16 << tool.nUseCount; ////////////////////////////////////////////////////////////////////////// int nParanum_Inf = 9; ar << nParanum_Inf;//先保存参数数量 ar << (UINT)tool.Interfaces.size(); for (UINT i = 0; i < tool.Interfaces.size(); i++) { TOOL_INTERFACE inf = tool.Interfaces[i]; ar << (int)1 << inf.strParentName; ar << (int)2 << inf.bShow; ar << (int)3 << inf.strName; ar << (int)4 << (int)inf.VarType; ar << (int)5 << (int)inf.InfDirection; ar << (int)6 << inf.rect; ar << (int)7 << (int)inf.InfType; ar << (int)8 << (int)inf.InfWay; ar << (int)9 << inf.nUseCount; } } // 保存link nParanum = 15;//以下参数的数量 ar << nParanum;//先保存参数数量 ar << (UINT)m_Links.size(); LINK_MAP::iterator iter; for (iter = m_Links.begin(); iter != m_Links.end(); iter++) { ar << (int)1 << iter->source.strParentName; ar << (int)2 << iter->source.nIndex; ar << (int)3 << iter->dest.strParentName; ar << (int)4 << iter->dest.nIndex; ar << (int)5 << (int)iter->source.VarType; ar << (int)6 << (int)iter->dest.VarType; ar << (int)7 << iter->source.InfDirection; ar << (int)8 << iter->dest.InfDirection; ar << (int)9 << iter->source.strName; ar << (int)10 << iter->dest.strName; ar << (int)11 << (int)iter->source.InfType; ar << (int)12 << (int)iter->dest.InfType; ar << (int)13 << (int)iter->source.InfWay; ar << (int)14 << (int)iter->dest.InfWay; ar << (int)15 << (int)iter->bShow; } // 保存监控列表 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; nParanum = 2;//以下参数的数量 ar << nParanum;//先保存参数数量 ar << (UINT)tool.Interfaces.size(); for (unsigned int j = 0; j < tool.Interfaces.size(); j++) { TOOL_INTERFACE& inf = tool.Interfaces[j]; ar << (int)1 << inf.nIndex; ar << (int)2 << inf.bMonitor; } } return TRUE; } ////////////////////////////////////////////////// // 从文件中加载工具信息 BOOL CTaskWindow::LoadFromFile(CArchive& ar) { UINT nSize = 0; vector newTools; int nParanum = 0;//参数数量 int nPpara = 0; //初始文件版本号从 101 开始添加,以前文件无版本号 if (g_nDocVersion > 101) { int m_nWindowHeight = 0; int m_nWindowWidth = 0; int m_gridHeight = 0; int m_gridWidth = 0; int m_marginLeft = 0; int m_marginTop = 0; int m_marginBottom = 0; int m_marginRight = 0; ar >> nParanum; // 读取窗体信息 for (int i = 0; i < nParanum; i++) { ar >> nPpara; switch (nPpara) { case 1: ar >> m_nWindowWidth; break; case 2: ar >> m_nWindowHeight; break; case 3: ar >> m_gridWidth; break; case 4: ar >> m_gridHeight; break; case 5: ar >> m_marginLeft; break; case 6: ar >> m_marginTop; break; case 7: ar >> m_marginBottom; break; case 8: ar >> m_marginRight; break; default: CString strMsg; strMsg.Format(_T("Task[%d] 加载失败!配置文档错误! "),m_nIndex); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } } m_editor.SetVirtualSize(CSize(m_nWindowWidth, m_nWindowHeight)); m_editor.SetGridSize(CSize(m_gridWidth, m_gridHeight)); m_editor.SetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom); m_editor.RedrawWindow(); } ar >> nParanum;//读取参数数量 ar >> nSize; for (UINT i = 0; i < nSize; i++) { TOOL newTool; for (int j = 0; j < nParanum; j++) { ar >> nPpara; switch (nPpara) { case 1: ar >> newTool.strVersion; break;// 版本 case 2: ar >> newTool.strName; break;// 显示名称 case 3: ar >> newTool.strShowName; break;// 名称 case 4: ar >> newTool.strDll; break;// dll 路径 case 5: ar >> newTool.bIsExpand; break;// 是否展开 case 6: ar >> newTool.bEnable; break;// 是否启用 case 7: ar >> (int&)newTool.Type; break;// Type case 8: ar >> newTool.rect; break;// 区域 case 9: ar >> newTool.strLinkName; break;// case 10: ar >> newTool.nInSleep; break;// case 11: ar >> newTool.nOutSleep; break;// case 12: ar >> newTool.strInfo; break;// case 13: ar >> newTool.hNextTool.nToolID; break;// case 14: ar >> newTool.hNextTool.strName; break;// case 15: ar >> newTool.hNextTool.strShowName; break;// case 16: { if (g_nDocVersion > 106) ar >> newTool.nUseCount; else ar >> (bool&)newTool.nUseCount;// 106之前,此变量为bool类型 }break;;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll); //CUtility::CriticalBCGPMessageBox(strMsg); OUTPUT_MSG msg; msg.bWay = MSG_WAY::_ERROR; msg.strMsg = strMsg; USES_CONVERSION; char * s_str = T2A(msg.strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; break; } } //初始文件版本号从 101 开始添加,以前文件无版本号 if (thePrefs.m_nDocHistoricVersion > 100) { if ((g_nDocVersion <= 105))// 106之前的版本 { ////////////////////////////////////////////////////////////////////////// CString strType; int nParanum_Inf = 0; int nSize_Inf = 0; ar >> nParanum_Inf;//读取参数数量 ar >> nSize_Inf; for (int j = 0; j < nSize_Inf; j++) { TOOL_INTERFACE inf; for (int k = 0; k < nParanum_Inf; k++) { ar >> nPpara; switch (nPpara) { case 1: ar >> inf.strParentName; break; case 2: ar >> inf.bShow; break;// case 3: ar >> inf.strName; break;// case 4: ar >> strType; break;// case 5: ar >> (int&)inf.InfDirection; break;// case 6: ar >> inf.rect; break;// case 7: ar >> (int&)inf.InfType; break;// case 8: ar >> (int&)inf.InfWay; break;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } } if (strType == _T("int")) { inf.VarType = VAR_TYPE::Int_Var; } else if (strType == _T("CString")) { inf.VarType = VAR_TYPE::CString_Var; } else if (strType == _T("HImage")) { inf.VarType = VAR_TYPE::HImage_Var; } newTool.Interfaces.push_back(inf); } } if (g_nDocVersion > 105)// 105之后的版本 { ////////////////////////////////////////////////////////////////////////// int nParanum_Inf = 0; int nSize_Inf = 0; ar >> nParanum_Inf;//读取参数数量 ar >> nSize_Inf; for (int j = 0; j < nSize_Inf; j++) { TOOL_INTERFACE inf; for (int k = 0; k < nParanum_Inf; k++) { ar >> nPpara; switch (nPpara) { case 1: ar >> inf.strParentName; break; case 2: ar >> inf.bShow; break;// case 3: ar >> inf.strName; break;// case 4: ar >> (int&)inf.VarType; break;// case 5: ar >> (int&)inf.InfDirection; break;// case 6: ar >> inf.rect; break;// case 7: ar >> (int&)inf.InfType; break;// case 8: ar >> (int&)inf.InfWay; break;// case 9: ar >> inf.nUseCount; break;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } } newTool.Interfaces.push_back(inf); } } } // 首先校验工具版本号以及存在与否 // if (!g_pToolManager->ValidateTool(newTool)) // { // return FALSE; // } if (newTool.rect.IsRectEmpty()) { CPoint pt; pt.x = 25 * i + 1; pt.y = 25 * i + 1; CRect rect(pt.x, pt.y, pt.x + 100, pt.y + 100); newTool.rect = rect; } newTools.push_back(newTool); } // 如果校验通过,则添加工具 for (UINT i = 0; i < newTools.size(); i++) { if (!AddNewTools(newTools[i])) { CString strMsg; strMsg.Format(_T("Task[%d] 在工具箱里未找到工具 %s ! "),m_nIndex, newTools[i].strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } // 2018.10.16增加,手工调用Update // 否则当前未激活的任务栏由于界面没有刷新,所以不会自动更新SelTool信息 UpdateTools( true ); if (newTools[i].Type == TOOL_TYPE::TOOL_BY_PROT) { for (size_t j = 0; j < newTools[i].Interfaces.size(); j++) { TOOL_INTERFACE newInf = newTools[i].Interfaces[j]; TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j]; inf.bShow = newInf.bShow; inf.rect = newInf.rect; } } m_SelTools[i].nInSleep = newTools[i].nInSleep; m_SelTools[i].nOutSleep = newTools[i].nOutSleep; m_SelTools[i].hNextTool = newTools[i].hNextTool; UpdateTools( true); } if (g_nDocVersion > 105) { // 加载link nParanum = 0;//参数数量 nSize = 0; m_Links.clear(); nSize = 0; //LINK newLink; ar >> nParanum;//读取参数数量 ar >> nSize; for (UINT i = 0; i < nSize; i++) { TOOL_INTERFACE source; // 连接的起点 TOOL_INTERFACE dest; // 连接的终点 bool bShow = true; for (int i = 0; i < nParanum; i++) { nPpara = 0; ar >> nPpara; switch (nPpara) { case 1: ar >> source.strParentName; break;// case 2: ar >> source.nIndex; break;// case 3: ar >> dest.strParentName; break;// case 4: ar >> dest.nIndex; break;// case 5: ar >> (int&)source.VarType; break;// case 6: ar >> (int&)dest.VarType; break;// case 7: ar >> (int&)source.InfDirection; break;// case 8: ar >> (int&)dest.InfDirection; break;// case 9: ar >> source.strName; break;// case 10: ar >> dest.strName; break;// case 11: ar >> (int&)source.InfType; break;// case 12: ar >> (int&)dest.InfType; break;// case 13: ar >> (int&)source.InfWay; break;// case 14: ar >> (int&)dest.InfWay; break;// case 15: ar >> (int&)bShow; break;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex ); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } } TOOL_INTERFACE* pS = GetInterfaceByInterface(source); TOOL_INTERFACE* pD = GetInterfaceByInterface(dest); BOOL bStatus = FALSE; if (pS != NULL && pD != NULL && (source.InfDirection == INF_DIRECTION::INF_OUT || source.InfDirection == INF_DIRECTION::INF_INOUT) && dest.InfDirection == INF_DIRECTION::INF_IN && source.VarType == dest.VarType) { bStatus = MakeLink(source, dest, bShow); } if (!bStatus) { CString strMsg; strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); USES_CONVERSION; char * s_str = T2A(strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } } } else { // 加载link nParanum = 0;//参数数量 nSize = 0; m_Links.clear(); nSize = 0; //LINK newLink; CString strType; ar >> nParanum;//读取参数数量 ar >> nSize; for (UINT i = 0; i < nSize; i++) { TOOL_INTERFACE source; // 连接的起点 TOOL_INTERFACE dest; // 连接的终点 for (int i = 0; i < nParanum; i++) { nPpara = 0; ar >> nPpara; switch (nPpara) { case 1: ar >> source.strParentName; break;// case 2: ar >> source.nIndex; break;// case 3: ar >> dest.strParentName; break;// case 4: ar >> dest.nIndex; break;// case 5: ar >> strType; break;// case 6: ar >> strType; break;// case 7: ar >> (int&)source.InfDirection; break;// case 8: ar >> (int&)dest.InfDirection; break;// case 9: ar >> source.strName; break;// case 10: ar >> dest.strName; break;// case 11: ar >> (int&)source.InfType; break;// case 12: ar >> (int&)dest.InfType; break;// case 13: ar >> (int&)source.InfWay; break;// case 14: ar >> (int&)dest.InfWay; break;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex); //CUtility::CriticalBCGPMessageBox(strMsg); OUTPUT_MSG msg; msg.bWay = MSG_WAY::_ERROR; msg.strMsg = strMsg; USES_CONVERSION; char * s_str = T2A(msg.strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE; } } TOOL_INTERFACE* pS = GetInterfaceByInterface(source); TOOL_INTERFACE* pD = GetInterfaceByInterface(dest); BOOL bStatus = FALSE; if (pS != NULL && pD != NULL && source.InfDirection == INF_DIRECTION::INF_OUT && dest.InfDirection == INF_DIRECTION::INF_IN && source.VarType == dest.VarType) { bStatus = AddLink(source, dest, true); } if (!bStatus) { CString strMsg; strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); OUTPUT_MSG msg; msg.bWay = MSG_WAY::_ERROR; msg.strMsg = strMsg; USES_CONVERSION; char * s_str = T2A(msg.strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); } } } // 加载监控列表 for (unsigned int i = 0; i < m_SelTools.size(); i++) { nParanum = 0;//参数数量 nSize = 0; TOOL& tool = m_SelTools[i]; ar >> nParanum;//读取参数数量 ar >> nSize; for (unsigned int j = 0; j < nSize; j++) { for (int i = 0; i < nParanum; i++) { nPpara = 0; TOOL_INTERFACE tmpInf; TOOL_INTERFACE& inf = tmpInf; if (nSize == tool.Interfaces.size()) { inf = tool.Interfaces[j]; } ar >> nPpara; switch (nPpara) { case 1: ar >> inf.nIndex; break;// case 2: ar >> inf.bMonitor;; break;// default: CString strMsg; strMsg.Format(_T("Task[%d] 加载工具监控信息失败!配置文档错误!"),m_nIndex); OUTPUT_MSG msg; msg.bWay = MSG_WAY::_ERROR; msg.strMsg = strMsg; USES_CONVERSION; char * s_str = T2A(msg.strMsg); g_Logger.Error(0, __FILE__, __LINE__, s_str); return FALSE;; } } } } UpdateTools( true); return TRUE; } ////////////////////////////////////////////////////// // 当窗体激活时触发,变更当前工作窗体 void CTaskWindow::OnSetFocus(CWnd* pOldWnd) { CBCGPStatic::OnSetFocus(pOldWnd); g_pTaskView->SetActiveTaskWindow(this, m_nIndex); } /////////////////////////////////////////////////////// // 重置所有工具执行状态 void CTaskWindow::ResetToolExecCode() { for (unsigned int i = 0; i < m_SelTools.size(); i++) { m_SelTools[i].nExecCode = RT_NONE; } } //设置接收 工具状态 数据回调函数 void CTaskWindow::ToolStateCallback(CString strToolName, int nState, long long userParam) { CTaskWindow *pParam = (CTaskWindow*)(userParam); if (pParam != NULL) { pParam->OnUpdateToolState(strToolName, nState); } } /////////////////////////////////////////////////////// // Tool Log 回调 void CTaskWindow::ToolLogCallback(CString strToolName, MSG_WAY nType, CString strMassage, long long userParam) { CMainFrame *pParam = (CMainFrame*)(userParam); if (pParam != NULL) { OUTPUT_MSG msg; msg.bWay = nType; msg.strMsg = strToolName + _T(" ") + strMassage; // pParam->ShowOutputInfo(msg, LOG); USES_CONVERSION; char * s_str = T2A(msg.strMsg); switch (nType) { case MSG_WAY::_INFO: g_Logger.Info(1, __FILE__, __LINE__, s_str); break; case MSG_WAY::_WARNING: g_Logger.Warn(1, __FILE__, __LINE__, s_str); break; case MSG_WAY::_ERROR: g_Logger.Error(1, __FILE__, __LINE__, s_str); break; default: g_Logger.Error(1, __FILE__, __LINE__, s_str); break; break; } } } /////////////////////////////////////////////////////// // Tool OnExecute 回调 void CTaskWindow::ToolOnExecuteCallback(CString strToolName, long long userParam) { CTaskWindow *pParam = (CTaskWindow*)(userParam); if (pParam != NULL) { if (!strToolName.IsEmpty()) { pParam->OnExecuteTool(strToolName); } } } /////////////////////////////////////////////////////// // ToolBusy 回调 void CTaskWindow::ToolBusyCallback(CString strToolName, int nState, CString strMassage, long long userParam) { CTaskWindow *pParam = (CTaskWindow*)(userParam); if (pParam != NULL) { if (!strToolName.IsEmpty()) { } } } ////////////////////////////////////////////////////////////// // 清空Watch void CTaskWindow::WatchClear() { WATCH::iterator it = mWatch.begin(); for (; it != mWatch.end(); it++) { if (it->second != NULL) { it->second->DestroyWindow(); RELEASE_BUFFER(it->second); } } mWatch.clear(); } ///////////////////////////////////////////////////////// // 更新工具状态 void CTaskWindow::OnUpdateToolState(CString strToolName, int nState) { // 重置所有工具执行状态 ResetToolExecCode(); // 查找工具 for (unsigned int i = 0; i < m_SelTools.size(); i++) { TOOL& tool = m_SelTools[i]; if (tool.strShowName == strToolName) { tool.nToolState = nState; //m_wndTree.Invalidate(TRUE); } } } void CTaskWindow::OnUpdate(CCmdUI* pCmdUI) { if (g_nRunningState != 0) { //g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("运行中,禁止该操作.....")); pCmdUI->Enable(false); return; } pCmdUI->Enable(true); } void CTaskWindow::OnBnClickedUp() { m_editor.Down(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedDown() { m_editor.Up(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedFront() { m_editor.Bottom(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedBottom() { m_editor.Front(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedLeftAlign() { m_editor.LeftAlignSelected(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedRightAlign() { m_editor.RightAlignSelected(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedTopAlign() { m_editor.TopAlignSelected(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedBottomAlign() { m_editor.BottomAlignSelected(); UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedZoomIn() { // m_editor.SetZoom(m_editor.GetZoom() + m_editor.GetZoomFactor() * 10); } void CTaskWindow::OnBnClickedZoomOut() { // m_editor.SetZoom(m_editor.GetZoom() - m_editor.GetZoomFactor() * 10); } void CTaskWindow::OnBnClickedZoomZero() { m_editor.SetZoom(1.0); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedSettings() { CString str; this->GetWindowText(str); CTaskSettings dlg; dlg.m_TaskInfo.bTaskMode = m_TaskMode; dlg.m_TaskInfo.nSleepTime = m_nSleepTime; dlg.m_TaskInfo.strTaskName = m_strTaskName; dlg.m_nWindowWidth = m_editor.GetVirtualSize().cx; dlg.m_nWindowHeight = m_editor.GetVirtualSize().cy; dlg.m_gridWidth = m_editor.GetGridSize().cx; dlg.m_gridHeight = m_editor.GetGridSize().cy; m_editor.GetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom); dlg.m_pTaskWindow = (LPVOID)this; if (dlg.DoModal() == IDOK) { m_TaskMode = dlg.m_TaskInfo.bTaskMode; m_nSleepTime = dlg.m_TaskInfo.nSleepTime; m_strTaskName = dlg.m_TaskInfo.strTaskName; m_editor.SetGridSize(CSize(dlg.m_gridWidth, dlg.m_gridHeight)); m_editor.SetVirtualSize(CSize(dlg.m_nWindowWidth, dlg.m_nWindowHeight)); m_editor.SetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom); m_editor.RedrawWindow(); //保存配置好的参数到本地 m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom); g_pTaskView->SetTabText(m_nIndex, m_strTaskName); } UpdateTools(); m_editor.RedrawWindow(); } void CTaskWindow::OnBnClickedRunOnce() { DWORD id; HANDLE hTread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CTaskWindow::SysRunOce, this, 0, &id); CloseHandle(hTread); } void CTaskWindow::SysRunOce(LPVOID pParam) { CTaskWindow* pThis = (CTaskWindow*)pParam; if (g_nRunningState != 0) { g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Error [State:%d]", g_nRunningState); return; } g_nRunningState = 2; // 清空当前任务栏中所有任务的执行状态 pThis->ResetToolExecCode(); SetEvent(pThis->m_hExecuteEven); ResetEvent(pThis->m_hExecuteEven); g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Start [%d]", g_nRunningState); WaitForSingleObject(pThis->m_hDoneEven, INFINITE); ResetEvent(pThis->m_hDoneEven); g_nRunningState = 0; g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Done [%d]", g_nRunningState); } void CTaskWindow::OnBnClickedButtonCopy() { // TODO: 在此添加控件通知处理程序代码 TOOL* pTool = this->GetToolByHandle(m_Item); if (pTool != NULL) { CSharedFile memFile; CArchive ar(&memFile, CArchive::store | CArchive::bNoFlushOnDelete); ar << pTool->strName; ar << pTool->strShowName; pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion); ar << pTool->strName; ar.Flush(); HGLOBAL hData = memFile.Detach(); if (OpenClipboard()) { ::SetClipboardData(g_cfObjectFormat, hData); CloseClipboard(); USES_CONVERSION; CString str; str.Format(_T("Task[%d] Cope %s Data OK "),m_nIndex, pTool->strShowName); char * s_str = T2A(str); g_Logger.Info(0, __FILE__, __LINE__, s_str); } } } void CTaskWindow::OnBnClickedButtonPaste() { // TODO: 在此添加控件通知处理程序代码 if (OpenClipboard()) { HANDLE hData = ::GetClipboardData(g_cfObjectFormat); if (hData != NULL) { //if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES) { CSharedFile memFile; memFile.SetHandle(hData, FALSE); CArchive ar(&memFile, CArchive::load); CString str, strToolName, strShowName; ar >> strToolName; ar >> strShowName; TOOL* pSourceTool = GetToolByShowName(strShowName);// 先择的模块(工具实体模块) if (pSourceTool != NULL) { TOOL newTool; newTool.strName = strToolName; newTool.strShowName = strToolName/* + _T("Copy")*/; newTool.rect = pSourceTool->rect; newTool.rect.TopLeft().x += 10; newTool.rect.TopLeft().y -= 30; CString strShowName; AddNewTools2(newTool, &strShowName); UpdateTools(); TOOL* pNewTool = GetToolByShowName(strShowName); if (pNewTool != NULL) { pNewTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion); ar >> strToolName; USES_CONVERSION; str.Format(_T("Paste %s Data OK [%s]"), pNewTool->strShowName, strToolName); char * s_str = T2A(str); g_Logger.Info(0, __FILE__, __LINE__, s_str); } } ar.Close(); memFile.Detach(); EmptyClipboard();// 清空粘贴板 } } CloseClipboard(); } // TOOL* pTool = this->GetToolByHandle(m_Item); // if (pTool != NULL) // { // if (OpenClipboard()) // { // HANDLE hData = ::GetClipboardData(g_cfObjectFormat); // if (hData != NULL) // { // // CSharedFile memFile; // memFile.SetHandle(hData, FALSE); // CArchive ar(&memFile, CArchive::load); // CString str, strToolName; // ar >> strToolName; // if (strToolName == pTool->strName) // { // if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES) // { // pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion); // // ar >> strToolName; // // USES_CONVERSION; // str.Format(_T("Paste %s Data OK [%s]"), pTool->strShowName , strToolName); // char * s_str = T2A(str); // g_Logger.Info(0, __FILE__, __LINE__, s_str); // } // } // else // { // USES_CONVERSION; // str.Format(_T("Paste %s Data Error SourceTool [%s]"), pTool->strShowName, strToolName); // char * s_str = T2A(str); // g_Logger.Error(0, __FILE__, __LINE__, s_str); // } // ar.Close(); // memFile.Detach(); // EmptyClipboard();// 清空粘贴板 // } // else // { // USES_CONVERSION; // CString str; // str.Format(_T("Paste %s Data Error Dara isNULL"), pTool->strShowName); // char * s_str = T2A(str); // g_Logger.Error(0, __FILE__, __LINE__, s_str); // } // CloseClipboard(); // } // } } void CTaskWindow::SortProtToolID(const TOOL* pSourceTool, const TOOL* pDestTool) { if (pDestTool != NULL && pSourceTool != NULL) { CDiagramEntityContainer* objs = static_cast (m_editor.GetDiagramEntityContainer()); if (objs) { UINT nIndex = 0; for (UINT i = 0; i < objs->GetSize(); i++) { CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(i); if (obj->Tools.strShowName == pSourceTool->strShowName) { m_editor.SetSelectedObject(obj); } } } { int nToolID = pDestTool->nToolID; int nProtID = pSourceTool->nToolID; if (nProtID > nToolID) { for (int j = 0; j < (nProtID - nToolID); j++) { OnBnClickedUp(); } } } } } void CTaskWindow::ShowNodeWatch(/*const*/ TOOL_INTERFACE* pInf) { if ( pInf != NULL ) { WATCH::iterator it = mWatch.begin(); //先遍历,看该节点是否创建过 BOOL bFind = FALSE; for (; it != mWatch.end(); ) { if (it->first == pInf) { bFind = TRUE; break; } ++it; } if (!bFind) { CNodeWatchDlg* pDlg = NULL; pDlg = new CNodeWatchDlg(this); pDlg->Create(IDD_NODEWATCHDLG, g_pMainFrame->GetActiveView()); pDlg->strName = pInf->strName; pDlg->strParentName = pInf->strParentName; mWatch[pInf] = pDlg; } if (mWatch[pInf] != NULL) { mWatch[pInf]->ShowWindow(SW_SHOW); CString str; str.Format(_T("监视:%s [ %s ]"), pInf->strParentName, pInf->strName); mWatch[pInf]->SetWindowTextW(str); } } }