EdgeInspector_App/MainFrm.cpp
@@ -1,5 +1,5 @@
// MainFrm.cpp : CMainFrame 努贰胶狼 备泅

// MainFrm.cpp : CMainFrame 努贰胶狼 备泅
//
#include "stdafx.h"
@@ -29,7 +29,7 @@
   ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
// CMainFrame 积己/家戈
// CMainFrame 积己/家戈
CMainFrame::CMainFrame()
{
@@ -77,10 +77,10 @@
   return TRUE;
}
// CMainFrame 皋矫瘤 贸府扁
// CMainFrame 皋矫瘤 贸府扁
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
   // TODO: 咯扁俊 皋矫瘤 贸府扁 内靛甫 眠啊 棺/肚绰 扁夯蔼阑 龋免钦聪促.
   // TODO: 咯扁俊 皋矫瘤 贸府扁 内靛甫 眠啊 棺/肚绰 扁夯蔼阑 龋免钦聪促.
   //CFrameWndEx::OnGetMinMaxInfo(lpMMI);
   lpMMI->ptMinTrackSize.x = TOTAL_WINDOW_SIZE_X;
@@ -90,7 +90,7 @@
   lpMMI->ptMaxTrackSize.y = TOTAL_WINDOW_SIZE_Y;
}
// CMainFrame 柳窜
// CMainFrame 柳窜
#ifdef _DEBUG
void CMainFrame::AssertValid() const
@@ -105,7 +105,7 @@
#endif //_DEBUG
// CMainFrame 皋矫瘤 贸府扁
// CMainFrame 皋矫瘤 贸府扁
void CMainFrame::SetView(CEdgeInspector_AppView   *pView)
{
   m_pView = pView;
@@ -200,7 +200,7 @@
   if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) {
      LPCTSTR pszExeName = PathFindFileName(strExePath);
      // 去掉 .exe,并杀死进程
      // 去掉 .exe,并杀死进程
      TCHAR szNameWithoutExt[MAX_PATH] = { 0 };
      _tcscpy_s(szNameWithoutExt, pszExeName);
      PathRemoveExtension(szNameWithoutExt);
@@ -220,7 +220,7 @@
   if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) {
      LPCTSTR pszExeName = PathFindFileName(strExePath);
      // 去掉 .exe,并杀死进程
      // 去掉 .exe,并杀死进程
      TCHAR szNameWithoutExt[MAX_PATH] = { 0 };
      _tcscpy_s(szNameWithoutExt, pszExeName);
      PathRemoveExtension(szNameWithoutExt);
@@ -307,7 +307,7 @@
{
   m_strReserveRecipe.Empty();
   if(!IsScanNow())      // 八荤 吝
   if(!IsScanNow())      // 八荤 吝
   {            
      if(LoadGlassRecipe(strRecipe,TRUE) == TRUE)
      {
@@ -331,17 +331,14 @@
BOOL CMainFrame::IV2M_SaveFullImage(CString strPath,int iSide,CPoint ptStart,int nLength)
{
   if(IsScanNow())
   {
   if(IsScanNow()) {
      g_pLog->DisplayMessage(_T("Doing Inspection"));
      return TRUE;
   }
   SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0));
   //SetSlashText(GLOBAL_DEFINE::emText, _T("Image Save Start"), RGB(0,0,0));
   BOOL bRet = SaveFullImage(strPath,iSide,ptStart,nLength);
   BOOL bRet = SaveFullImage(strPath, iSide, ptStart, nLength);
   SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0));
@@ -360,9 +357,10 @@
   switch(iProceMode)
   {
   case 0: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDELONG; break;
   case 0: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDERIP; break;
   case 1: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDESHORT; break;
   case 2: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ALL; break;
   case 2: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDELONG; break;
   case 3: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ALL; break;
   }
   AfxBeginThread(ManualInspectProcess,this);
@@ -372,7 +370,7 @@
UINT CMainFrame::ManualInspectProcess(LPVOID pParam)
{
   CMainFrame      *pMain = (CMainFrame *)pParam;
   CMainFrame *pMain = (CMainFrame *)pParam;
   pMain->SetInspectionEnd();
@@ -400,11 +398,11 @@
      return 0;
   }
   DWORD      tTime = GetTickCount();
   int         iScan = 0;
   int         iScanEnd = 0;
   int         iCam = 0;
   double      dOneScanTime = pMain->m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;
   DWORD   tTime = GetTickCount();
   int      iScan = 0;
   int      iScanEnd = 0;
   int      iCam = 0;
   double   dOneScanTime = pMain->m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;
   
   pMain->InitLoadingProcess();   
   pMain->m_GlassData.SetScanStart(TRUE);
@@ -430,69 +428,47 @@
          pMain->ScanStartManual(iCam,iScan, TRUE);   
      }
      break;
   case PROC_MODE_SIMULATION_SIDERIP:
      {
         std::vector<DimensionDir> vecDirs = {
            DIMENSION_A_RIP, DIMENSION_B_RIP, DIMENSION_C_RIP, DIMENSION_D_RIP
         };
         pMain->Simulate2PhaseScanByDirs(vecDirs);
      }
      break;
   case PROC_MODE_SIMULATION_SIDESHORT:
      {         
         pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT);
         pMain->SendGlassRecipe();
         for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
         {
            pMain->ScanStartGrabManual(iCam,0);
            pMain->ScanStartManual(iCam,0);
         }
         std::vector<DimensionDir> vecDirs = {
            DIMENSION_B, DIMENSION_D, DIMENSION_B_DN, DIMENSION_D_DN
         };
         pMain->Simulate2PhaseScanByDirs(vecDirs);
      }
      break;
   case PROC_MODE_SIMULATION_SIDELONG:
      {            
         pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT);
         pMain->SendGlassRecipe();
         for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
         {
            pMain->ScanStartGrabManual(iCam,1);
            pMain->ScanStartManual(iCam,1);
         }
         std::vector<DimensionDir> vecDirs = {
            DIMENSION_A, DIMENSION_C, DIMENSION_A_DN, DIMENSION_C_DN
         };
         pMain->Simulate2PhaseScanByDirs(vecDirs);
      }
      break;
   case PROC_MODE_SIMULATION_ALL:
      {
         g_pLog->DisplayMessage(_T("Simulation Full "));
         pMain->m_GlassData.SetScanStartCount(MAX_DIMENSION_COUNT);
         pMain->SendGlassRecipe();
         for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
         {
            pMain->ScanStartGrabManual(iCam,0);
            pMain->ScanStartGrabManual(iCam,1);
         if (pMain->m_HardwareRecipe.m_bUseRipInspection) {
            std::vector<DimensionDir> vecDirs = {
               DIMENSION_A, DIMENSION_B, DIMENSION_C, DIMENSION_D,
               DIMENSION_A_DN, DIMENSION_B_DN, DIMENSION_C_DN, DIMENSION_D_DN,
               DIMENSION_A_RIP, DIMENSION_B_RIP, DIMENSION_C_RIP, DIMENSION_D_RIP
            };
            pMain->Simulate2PhaseScanByDirs(vecDirs);
         }
         if(pMain->m_pThread_CheckSequence != NULL)
         {
            double dOneScanTime = pMain->m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;
            pMain->m_pThread_CheckSequence->AddCheckSeqMSG(CHECKSEQ_GLASS_INSPECTION_OVERTIME,(int)(dOneScanTime* 1000.),pMain->m_HardwareRecipe.GetScanCount()-1);
            g_pLog->DisplayMessage(_T("Simulation Time Out Set : %.1f"),dOneScanTime);
         else {
            std::vector<DimensionDir> vecDirs = {
               DIMENSION_A, DIMENSION_B, DIMENSION_C, DIMENSION_D,
               DIMENSION_A_DN, DIMENSION_B_DN, DIMENSION_C_DN, DIMENSION_D_DN
            };
            pMain->Simulate2PhaseScanByDirs(vecDirs);
         }
         for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
         {
            pMain->ScanStartManual(iCam,0);
         }
         DWORD      sTime = GetTickCount();
         while(TRUE)
         {
            if(pMain->m_GlassData.GetScanEnd(0) == TRUE)
               break;
            if(GetTickCount() - sTime >= 5000)
               break;
            Sleep(10);
         }
         for(iCam=0;iCam<MAX_CAMERA_COUNT;iCam++)
         {
            pMain->ScanStartManual(iCam,1);
         }
      }
      break;
   }
@@ -502,17 +478,13 @@
BOOL CMainFrame::IV2M_InspectionProcess(DimensionDir eDim)
{
   if(IsScanNow())
   {
   if(IsScanNow()) {
      g_pLog->DisplayMessage(_T("Doing Inspection"));
      return FALSE;
   }
   g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ONESIDE;
   m_eManualInspectSide = eDim;
   // 烙矫肺 阜澜
   //return TRUE;
   AfxBeginThread(ManualInspectProcess,this);
@@ -521,50 +493,38 @@
void CMainFrame::MLight_OnOff(int iCon,int iCh,BOOL bValue)
{
   //    if(IsScanNow())
   //    {
   //       g_pLog->DisplayMessage(_T("Doing Inspection"));
   //       return;
   //    }
   if(m_pLightManager == NULL)
   if (m_pLightManager == NULL) {
      return;
   }
   m_pLightManager->LampTurnOnOff(iCon, iCh, bValue);
}
BOOL CMainFrame::MLight_SetLightControlValue(int iCon,int iCh, int nValue, BOOL bRef, int nScanIdx, BOOL bAdjLight)
{
   //    if(IsScanNow())
   //    {
   //       g_pLog->DisplayMessage(_T("Doing Inspection"));
   //       return TRUE;
   //    }
   if(m_pLightManager == NULL)
   if (m_pLightManager == NULL) {
      return FALSE;
   }
   BOOL   bRet = m_pLightManager->SetLightControlValue(iCon, iCh, nValue);
   BOOL bRet = m_pLightManager->SetLightControlValue(iCon, iCh, nValue);
   return bRet;
}
BOOL CMainFrame::IV2M_SetLiveGrabCommand(DimensionDir eDim,BOOL bStop)
{
   if (IsScanNow())
   {
   if (IsScanNow()) {
      g_pLog->DisplayMessage(_T("Doing Inspection"));
      return TRUE;
   }
   // 4/13 MiniLED
   if(eDim < DIMENSION_A || eDim > DIMENSION_D)
   if (eDim < DIMENSION_A || eDim > DIMENSION_D_RIP) {
      return FALSE;
   }
   g_pLog->DisplayMessage(_T("Live Cam %d Start : Main"),(int)eDim);   
   BOOL bRet = SetLiveGrabCommand(eDim,bStop);
   g_pLog->DisplayMessage(_T("Live Cam %d End : Main"),(int)eDim);
   return bRet;
@@ -572,16 +532,18 @@
LPBYTE CMainFrame::IV2M_GetGrabBufferByDimension(DimensionDir eDim,int iVline)
{
   //    if(IsScanNow())
   //    {
   //       g_pLog->DisplayMessage(_T("Doing Inspection"));
   //       return NULL;
   //    }
   //if (IsScanNow()) {
   //   g_pLog->DisplayMessage(_T("Doing Inspection"));
   //   return NULL;
   //}
   if(eDim < DIMENSION_A || eDim > DIMENSION_D_DN)
   if (eDim < DIMENSION_A || eDim > DIMENSION_D_RIP) {
      return NULL;
   if(iVline < 0)
   }
   if (iVline < 0) {
      return NULL;
   }
   return GetGrabBuffer(eDim,iVline);
}
@@ -613,7 +575,6 @@
#ifndef _DEBUG
      SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0));
#endif
      SetSlashText(GLOBAL_DEFINE::emText, _T("Image Loading Start"), RGB(0,0,0));
      if(iSide > -1)
@@ -724,4 +685,103 @@
void CMainFrame::DisplayMessage(TCHAR* str)
{
   WriteLogManager(str);
}
void CMainFrame::Simulate2PhaseScanByDirs(const std::vector<DimensionDir>& vDirs)
{
   struct SCamScan { int cam; int scan; };
   if (vDirs.empty()) {
      g_pLog->DisplayMessage(_T("No valid directions provided for simulation."));
      return;
   }
   if (m_pView == NULL) {
      g_pLog->DisplayMessage(_T("View is not initialized."));
      return;
   }
   if (m_bManualProcessStart) {
      g_pLog->DisplayMessage(_T("Manual process is already running."));
      return;
   }
   std::vector<SCamScan> phase0; // scan == 0
   std::vector<SCamScan> phase1; // scan == 1
   for (DimensionDir dir : vDirs) {
      int nCam = m_HardwareRecipe.GetCameraIndexToDimension(dir);
      if (nCam < 0) {
         continue; // 未配置该方向
      }
      int nScan = m_HardwareRecipe.GetScanToDimension(dir);
      if (nScan != 0 && nScan != 1) {
         continue; // 只支持两相扫描
      }
      if (nScan == 0) {
         phase0.push_back({ nCam, 0 });
      }
      else if (nScan == 1) {
         phase1.push_back({ nCam, 1 });
      }
   }
   SendGlassRecipe();
   m_GlassData.SetScanStartCount((int)vDirs.size());
   if (!phase0.empty() && !phase1.empty()) {
      for (const auto& cs : phase0) {
         ScanStartGrabManual(cs.cam, 0);
      }
      for (const auto& cs : phase1) {
         ScanStartGrabManual(cs.cam, 1);
      }
      if (m_pThread_CheckSequence != NULL) {
         double dOneScanTime = m_GlassRecipe.m_RecieParm.m_dOneScanTime_sec;
         m_pThread_CheckSequence->AddCheckSeqMSG(CHECKSEQ_GLASS_INSPECTION_OVERTIME, (int)(dOneScanTime * 1000), m_HardwareRecipe.GetScanCount() - 1);
         g_pLog->DisplayMessage(_T("Simulation Time Out Set : %.1f"), dOneScanTime);
      }
      // nScan == 0
      for (const auto& cs : phase0) {
         ScanStartManual(cs.cam, 0);
      }
      DWORD sTime = GetTickCount();
      while (TRUE) {
         if (m_GlassData.GetScanEnd(0) == TRUE) {
            break;
         }
         if (GetTickCount() - sTime > 5000) {
            break;
         }
         Sleep(10);
      }
      for (const auto& cs : phase1) {
         ScanStartManual(cs.cam, 1);
      }
   }
   else {
      // nScan == 0
      if (!phase0.empty()) {
         for (const auto& cs : phase0) {
            ScanStartGrabManual(cs.cam, cs.scan);
            ScanStartManual(cs.cam, cs.scan);
         }
      }
      // nScan == 1
      if (!phase1.empty()) {
         for (const auto& cs : phase1) {
            ScanStartGrabManual(cs.cam, cs.scan);
            ScanStartManual(cs.cam, cs.scan);
         }
      }
   }
}