新增 LoadAndProcessImages 函数,封装图像加载、界面初始化、处理线程启动流程
已修改2个文件
83 ■■■■ 文件已修改
ENRIT/View/ViewScanImage.cpp 82 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ENRIT/View/ViewScanImage.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ENRIT/View/ViewScanImage.cpp
@@ -1045,20 +1045,39 @@
BOOL CViewScanImage::ManualThreadStart(int nCmd,int nIndex /*= -1*/)
{
    if(m_pManualProcess)
    {
    if (m_pManualProcess) {
        DWORD dwWait = ::WaitForSingleObject(m_pManualProcess->m_hThread, 3000);
        if (dwWait == WAIT_TIMEOUT) {
        DWORD dwExitCode;
        dwExitCode=::WaitForSingleObject(m_pManualProcess->m_hThread, 1000);
        if((::GetExitCodeThread(m_pManualProcess->m_hThread ,&dwExitCode))&& (dwExitCode == STILL_ACTIVE))
        {
            if ((::GetExitCodeThread(m_pManualProcess->m_hThread, &dwExitCode)) && (dwExitCode == STILL_ACTIVE)) {
            ::TerminateThread(m_pManualProcess->m_hThread, dwExitCode);  
            m_pManualProcess = NULL;
                g_pLog->DisplayMessage(_T("Previous manual process was terminated due to timeout."));
        }
    }
        else {
            m_pManualProcess = NULL;
            if (dwWait == WAIT_OBJECT_0) {
                g_pLog->DisplayMessage(_T("Previous manual process completed successfully."));
            }
            else {
                g_pLog->DisplayMessage(_T("Previous manual process was terminated or failed."));
            }
        }
    }
    if (m_pManualProcess != NULL) {
        g_pLog->DisplayMessage(_T("Manual Process is already running. Please wait until it finishes."));
        return FALSE;
    }
    m_nIndex        = nIndex;
    m_nThreadCmd    = nCmd;
    m_pManualProcess = AfxBeginThread(ManualProcessAll,this);
    if (!m_pManualProcess) {
        g_pLog->DisplayMessage(_T("Failed to start manual process thread."));
        return FALSE;
    }
    return TRUE;
}
@@ -1260,8 +1279,46 @@
        g_pLog->DisplayMessage(_T("%s %d Save Completed : %s"),PANEL_SIDE[iSide],nFrame,strPath);
    }
}
void CViewScanImage::LoadAndProcessImages(const CString& strFolderPath)
{
    if (m_IV2M != NULL) {
        // 加载图像
        m_IV2M->IV2M_LoadImageFromFolder(-1, strFolderPath, m_pGlassData, [&](BYTE iSide) {
            int iView = GetViewIndex(iSide);
            InitScrollInfo(iSide, 0);
            m_frameImg[iView].Invalidate(FALSE);
            m_frameImg[iView].Invalidate();
        });
        for (int i = 0; i < 8; i++) {
            InitScrollInfo(i, 0);
            int nSide = GetSideIdx(i);
            m_frameImg[i].SetSide(nSide);
            m_frameImg[i].SetImage(GetBufferPoint(i, 0));
            m_frameImg[i].ViewUpdate();
        }
        if (m_IV2M != NULL) {
            m_IV2M->IV2M_InitView(VIEW_SCANIMAGE);
        }
        // 执行处理线程
        switch (m_nShowSelect)
        {
        case 0:
            m_IV2M->IV2M_InspectionProcessAll(M_CMD_PROC_ALL_START);
            break;
        case 1:
            m_IV2M->IV2M_InspectionProcessAll(M_CMD_PROC_LONG_START);
            break;
        case 2:
            m_IV2M->IV2M_InspectionProcessAll(M_CMD_PROC_SHORT_START);
            break;
        }
    }
}
UINT CViewScanImage::ManualProcessAll(LPVOID pParam)
@@ -1286,14 +1343,6 @@
            pDlg->m_frameImg[iView].Invalidate(FALSE);
            pDlg->m_frameImg[iView].Invalidate();
        });
        //CString strFolderPath = _T("D:\\备份\\光检机\\EI、Rcut\\RCUT\\图片\\n8_NG");
        //pDlg->m_IV2M->IV2M_LoadImageFromFolder(-1, strFolderPath, pDlg->m_pGlassData, [&](BYTE iSide) {
        //    int iView = pDlg->GetViewIndex(iSide);
        //    pDlg->InitScrollInfo(iSide, 0);
        //    pDlg->m_frameImg[iView].Invalidate(FALSE);
        //    pDlg->m_frameImg[iView].Invalidate();
        //});
    }
    else if(pDlg->m_nThreadCmd == M_CMD_IMG_SAVE_ALL)
    {
@@ -1385,15 +1434,16 @@
    case 0: 
        ManualThreadStart(M_CMD_PROC_ALL_START    );
        break;
    case 1: 
        ManualThreadStart(M_CMD_PROC_LONG_START    );     
        break;
    case 2:
        ManualThreadStart(M_CMD_PROC_SHORT_START);  
        break;
    }
    //CString strFolderPath = _T("D:\\备份\\光检机\\EI、Rcut\\RCUT\\图片\\n8_NG");
    //LoadAndProcessImages(strFolderPath);
}
void CViewScanImage::OnBnClickedCheckAutoSize()
ENRIT/View/ViewScanImage.h
@@ -90,6 +90,7 @@
    static UINT        ManualProcessAll(LPVOID pParam);
    void            SaveFullImage(int nViewIndex);
    void            SaveFullImageAll();    
    void            LoadAndProcessImages(const CString& strFolderPath);
protected:
    CMFCButton        m_btnLoad[MAX_PANEL_SIDE * UPDN_TYPE];