// MainFrm.cpp : CMainFrame Ŭ·¡½ºÀÇ ±¸Çö // #include "stdafx.h" #include "EdgeInspector_App.h" #include "MainFrm.h" #include "HardwareSettings.h" #include "io.h" #include "MulticamControl.h" #include #include #ifdef _DEBUG #define new DEBUG_NEW #endif // CMainFrame #define TOTAL_WINDOW_SIZE_X 1920 #define TOTAL_WINDOW_SIZE_Y 1040 #define ID_TIMER_INITDONE 1001 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) ON_WM_CREATE() ON_WM_TIMER() ON_WM_GETMINMAXINFO() END_MESSAGE_MAP() // CMainFrame »ý¼º/¼Ò¸ê CMainFrame::CMainFrame() { m_pView = NULL; m_bManualProcessStart = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; //new CDisplayMessage(static_cast(this)); //new CStatusMonitor(); g_pLog->SetDM2P(static_cast(this)); ModifyStyle(WS_CAPTION, NULL); SetMenu(NULL); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE; cs.style = cs.style & ~FWS_ADDTOTITLE; cs.x = 0; cs.y = 0; cs.cx = TOTAL_WINDOW_SIZE_X; cs.cy = TOTAL_WINDOW_SIZE_Y; cs.lpszName = _T("EdgeInspector"); this->SetTitle(_T("EdgeInspector")); return TRUE; } // CMainFrame ¸Þ½ÃÁö 󸮱â void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. //CFrameWndEx::OnGetMinMaxInfo(lpMMI); lpMMI->ptMinTrackSize.x = TOTAL_WINDOW_SIZE_X; lpMMI->ptMinTrackSize.y = TOTAL_WINDOW_SIZE_Y; lpMMI->ptMaxTrackSize.x = TOTAL_WINDOW_SIZE_X; lpMMI->ptMaxTrackSize.y = TOTAL_WINDOW_SIZE_Y; } // CMainFrame Áø´Ü #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG // CMainFrame ¸Þ½ÃÁö 󸮱â void CMainFrame::SetView(CEdgeInspector_AppView *pView) { m_pView = pView; if(NULL != m_pView) { m_pView->CreateChildView(); m_pView->SetV2M(static_cast(this)); } m_splash.SetBitmap(IDB_SPLASH); m_splash.SetTransparentColor(RGB(128,128,128)); SetTimer(ID_TIMER_INITDONE, 500, NULL); } void CMainFrame::OnTimer(UINT_PTR nIDEvent) { switch(nIDEvent) { case ID_TIMER_INITDONE: KillTimer(ID_TIMER_INITDONE); Timer_InitDone(); break; } CFrameWnd::OnTimer(nIDEvent); } void CMainFrame::KillProcessByName(LPCTSTR lpProcessName) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return; PROCESSENTRY32 pe = { sizeof(PROCESSENTRY32) }; if (Process32First(hSnapshot, &pe)) { do { if (_tcsstr(_tcslwr(pe.szExeFile), _tcslwr(_tcsdup(lpProcessName))) != NULL) { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID); if (hProcess) { TerminateProcess(hProcess, 0); CloseHandle(hProcess); } } } while (Process32Next(hSnapshot, &pe)); } CloseHandle(hSnapshot); } void CMainFrame::Timer_InitDone() { g_pLog->DisplayMessage(_T("** Run Inspector **[%s %s]"), _T(__DATE__), _T(__TIME__)); #ifndef _DEBUG SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0,0,0)); #endif // _DEBUG SetSlashText(GLOBAL_DEFINE::emText, _T("System Initializing .."), RGB(0,0,0)); ReadHardwareSetting(); SetSlashText(GLOBAL_DEFINE::emText, _T("Read Hardware Setting Complete"), RGB(0,0,0)); g_pBase->ReadInspectConfigFile(INSPECTBASE_FILENAME,m_HardwareRecipe.GetCameraCount()); SetSlashText(GLOBAL_DEFINE::emText, _T("Read Inspect Confie Complete"), RGB(0,0,0)); InterfaceInit(); CString strRecipeName; GetRegistryRcpName(strRecipeName); if(LoadGlassRecipe(strRecipeName,TRUE) == TRUE) { SetRegistryRcpName(strRecipeName); } ApplyViewRecipeSettingss(); SetSlashText(GLOBAL_DEFINE::emText, _T("Read Recipe Complete"), RGB(0,0,0)); g_pLog->DisplayMessage(_T("Start Process Completed")); Sleep(1000); HINSTANCE hViewer = ShellExecute(NULL, _T("open"), _T("C:\\EdgeInspector_App\\LogView.exe"), NULL, NULL, SW_SHOWNORMAL); hViewer = ShellExecute(NULL, _T("open"), _T("C:\\EdgeInspector_App\\PLCConnector.exe"), NULL, NULL, SW_SHOWNORMAL); // ly, 2025.07.07 CString strExePath = m_HardwareRecipe.m_strCopyToolExePath; CString strConfigPath = m_HardwareRecipe.m_strCopyToolConfigPath; if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) { LPCTSTR pszExeName = PathFindFileName(strExePath); // È¥µô .exe£¬²¢É±ËÀ½ø³Ì TCHAR szNameWithoutExt[MAX_PATH] = { 0 }; _tcscpy_s(szNameWithoutExt, pszExeName); PathRemoveExtension(szNameWithoutExt); KillProcessByName(szNameWithoutExt); if (TRUE == m_HardwareRecipe.m_bEnableAutoCopy) { ShellExecute(NULL, _T("open"), strExePath, strConfigPath, NULL, SW_SHOWNORMAL); g_pLog->DisplayMessage(_T("Started Copy Tool process.")); } } else { g_pLog->DisplayMessage(_T("Copy Tool executable or config file not found.")); } strExePath = m_HardwareRecipe.m_strDeleteToolExePath; strConfigPath = m_HardwareRecipe.m_strDeleteToolConfigPath; if (PathFileExists(strExePath) && PathFileExists(strConfigPath)) { LPCTSTR pszExeName = PathFindFileName(strExePath); // È¥µô .exe£¬²¢É±ËÀ½ø³Ì TCHAR szNameWithoutExt[MAX_PATH] = { 0 }; _tcscpy_s(szNameWithoutExt, pszExeName); PathRemoveExtension(szNameWithoutExt); KillProcessByName(szNameWithoutExt); if (TRUE == m_HardwareRecipe.m_bEnableAutoDelete) { ShellExecute(NULL, _T("open"), strExePath, strConfigPath, NULL, SW_SHOWNORMAL); g_pLog->DisplayMessage(_T("Started Delete Tool process.")); } } else { g_pLog->DisplayMessage(_T("Delete Tool executable not found.")); } SetSlashText(GLOBAL_DEFINE::emHide, _T(""), RGB(0,0,0)); } BOOL CMainFrame::GetRegistryRcpName(CString& strRecipe) { CConfig RegiSetting; RegiSetting.SetRegiConfig(SHCU, KEY_BASIC, NULL, Registery_mode); RegiSetting.GetItemValue(_T("RECIPE_CURRENT"), strRecipe); return TRUE; } void CMainFrame::SetRegistryRcpName(CString strRecipe) { CConfig RegiSetting; RegiSetting.SetRegiConfig(SHCU, KEY_BASIC, NULL, Registery_mode); RegiSetting.SetItemValue(_T("RECIPE_CURRENT"), (TCHAR*)(LPCTSTR)strRecipe); } void CMainFrame::CommandExitButtonClick() { DestroyThread(); AfxGetMainWnd()->PostMessage(WM_COMMAND,ID_APP_EXIT,0); } void CMainFrame::MapDefect_ReqDefectImage(CDefect* pDefect,int nGlassDefectIdx) { } CDefect *CMainFrame::ListDefect_ReqDefectImage(CDefect* pDefect,int nGlassDefectIdx) { if(pDefect == NULL || nGlassDefectIdx < 0) { g_pLog->DisplayMessage(_T("List Request Defect Image Fail : Data is Null")); return NULL; } if(pDefect->m_DefectInfo.m_nCamID < 0 || pDefect->m_DefectInfo.m_nCamID >= m_HardwareRecipe.GetCameraCount()) return NULL; //return m_pInspectSequence->GetDefectData(pDefect->m_nCameraID,pDefect->m_nDefectIdx); return NULL; } void CMainFrame::IV2M_InitView(Init_View_Command eVew) { m_GlassData.ResetGlass(); m_pView->InitView(eVew); } void CMainFrame::ApplyViewRecipeSettingss() { if(m_pView == NULL) return; m_pView->SetHardwareSetting(&m_HardwareRecipe); m_pView->SetRecipeSettings(&m_GlassRecipe); m_pView->SetGlassData(&m_GlassData); m_pView->SetTransferData(&m_TransferData); } BOOL CMainFrame::IV2M_RecipeChange(CString strRecipe) { m_strReserveRecipe.Empty(); if(!IsScanNow()) // °Ë»ç Áß { if(LoadGlassRecipe(strRecipe,TRUE) == TRUE) { SetRegistryRcpName(strRecipe); g_pLog->DisplayMessage(_T("Apply Recipe by RecipeView Success : [%s]"), strRecipe); //ApplyViewRecipeSettingss(); } else { g_pLog->DisplayMessage(_T("Apply Recipe by RecipeView Fail: [%s]"), strRecipe); } } else { g_pLog->DisplayMessage(_T("Reserve Recipe application by RecipeView : [%s]"), strRecipe); m_strReserveRecipe = strRecipe; } return TRUE; } BOOL CMainFrame::IV2M_SaveFullImage(CString strPath,int iSide,CPoint ptStart,int nLength) { 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); SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0)); SetSlashText(GLOBAL_DEFINE::emHide, _T(""), RGB(0,0,0)); return bRet; } BOOL CMainFrame::IV2M_InspectionProcessAll(int iProceMode) { if(IsScanNow()) { g_pLog->DisplayMessage(_T("Doing Inspection")); return FALSE; } switch(iProceMode) { case 0: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDELONG; break; case 1: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_SIDESHORT; break; case 2: g_pBase->m_eProcessMode = PROC_MODE_SIMULATION_ALL; break; } AfxBeginThread(ManualInspectProcess,this); return TRUE; } UINT CMainFrame::ManualInspectProcess(LPVOID pParam) { CMainFrame *pMain = (CMainFrame *)pParam; pMain->SetInspectionEnd(); DWORD dwTick = GetTickCount(); DWORD dwWaitTick; DWORD dwWaitTime = 3000; while(TRUE) { Sleep(0); dwWaitTick = GetTickCount() - dwTick; if(dwWaitTime < dwWaitTick) break; if(pMain->IsScanNow()) continue; else break; } if(pMain->IsScanNow()) { g_pLog->DisplayMessage(_T("Doing Inspection")); return 0; } 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); pMain->m_GlassData.SetLoadingTime(); pMain->m_GlassData.SetScanStartTime(); g_pBase->m_strRecipeName = pMain->m_GlassRecipe.GetRecipeName(); g_pBase->m_strLoadingDay = pMain->m_GlassData.GetLoadingDayFileName(); g_pBase->m_strLoadingTime = pMain->m_GlassData.GetLoadingTimeFileName(); g_pBase->m_strHPanelID = _T("Manual"); switch(g_pBase->m_eProcessMode) { case PROC_MODE_SIMULATION_ONESIDE: { pMain->m_GlassData.SetScanStartCount(1); int iCam = pMain->m_HardwareRecipe.GetCameraIndexToDimension(pMain->m_eManualInspectSide); int iScan = pMain->m_HardwareRecipe.GetScanToDimension(pMain->m_eManualInspectSide); pMain->SendGlassRecipe(); pMain->ScanStartGrabManual(iCam,iScan); pMain->ScanStartManual(iCam,iScan, TRUE); } break; case PROC_MODE_SIMULATION_SIDESHORT: { pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT); pMain->SendGlassRecipe(); for(iCam=0;iCamScanStartGrabManual(iCam,0); pMain->ScanStartManual(iCam,0); } } break; case PROC_MODE_SIMULATION_SIDELONG: { pMain->m_GlassData.SetScanStartCount(MAX_CAMERA_COUNT); pMain->SendGlassRecipe(); for(iCam=0;iCamScanStartGrabManual(iCam,1); pMain->ScanStartManual(iCam,1); } } break; case PROC_MODE_SIMULATION_ALL: { g_pLog->DisplayMessage(_T("Simulation Full ")); pMain->m_GlassData.SetScanStartCount(MAX_DIMENSION_COUNT); pMain->SendGlassRecipe(); for(iCam=0;iCamScanStartGrabManual(iCam,0); pMain->ScanStartGrabManual(iCam,1); } 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); } for(iCam=0;iCamScanStartManual(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;iCamScanStartManual(iCam,1); } } break; } return 0; } BOOL CMainFrame::IV2M_InspectionProcess(DimensionDir eDim) { 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); return TRUE; } void CMainFrame::MLight_OnOff(int iCon,int iCh,BOOL bValue) { // if(IsScanNow()) // { // g_pLog->DisplayMessage(_T("Doing Inspection")); // return; // } 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) return FALSE; BOOL bRet = m_pLightManager->SetLightControlValue(iCon, iCh, nValue); return bRet; } BOOL CMainFrame::IV2M_SetLiveGrabCommand(DimensionDir eDim,BOOL bStop) { if (IsScanNow()) { g_pLog->DisplayMessage(_T("Doing Inspection")); return TRUE; } // 4/13 MiniLED if(eDim < DIMENSION_A || eDim > DIMENSION_D) 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; } LPBYTE CMainFrame::IV2M_GetGrabBufferByDimension(DimensionDir eDim,int iVline) { // if(IsScanNow()) // { // g_pLog->DisplayMessage(_T("Doing Inspection")); // return NULL; // } if(eDim < DIMENSION_A || eDim > DIMENSION_D_DN) return NULL; if(iVline < 0) return NULL; return GetGrabBuffer(eDim,iVline); } void CMainFrame::IV2M_LoadImageFullFile(int iSide, CGlass_Data *pGlassData, std::function _Func) { if(IsScanNow()) { g_pLog->DisplayMessage(_T("Doing Inspection")); return; } if(m_bManualProcessStart == TRUE) { g_pLog->DisplayMessage(_T("Doing Manual Process")); return; } m_bManualProcessStart = TRUE; CString strPath,strGlassID; TCHAR szFilter[] = _T("Image Files(*.bmp;,*.jpg) |*.bmp;*.jpg;|All File (*.*)| *.*||"); CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,AfxGetMainWnd()); int nStartY = 0, nHeight = 0; if(dlg.DoModal() == IDOK) { #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) { CString strGlsID, strTmp , strExt; strExt = dlg.GetFileExt(); strGlsID = dlg.GetFileName(); strGlsID = strGlsID.Left(strGlsID.Find(_T("__"))); g_pBase->m_strHPanelID = strGlsID; strTmp = dlg.GetPathName(); strTmp = strTmp.Left( strTmp.ReverseFind(_T('\\'))); char str_filename[200]; for(int i = 0 ; i < 6 ; i++) { strPath.Format(_T("%s\\%s__%s_%d.%s"),strTmp,strGlsID,PANEL_SIDE[iSide],i,strExt); USES_CONVERSION; sprintf_s(str_filename, "%s", W2A(strPath)); if(access(str_filename, 0) == 0) { nHeight = LoadFullImage(strPath,iSide,nStartY); if(nHeight == -1) break; nStartY += nHeight; } else break; } if(pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)iSide); if(pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = nStartY; } } if(_Func != nullptr) { _Func(iSide); } } else { CString strGlsID, strTmp , strExt; strExt = dlg.GetFileExt(); strGlsID =dlg.GetFileName(); strGlsID = strGlsID.Left(strGlsID.Find(_T("__"))); g_pBase->m_strHPanelID = strGlsID; char str_filename[200]; for(int i = 0; i < MAX_PANEL_SIDE * UPDN_TYPE; i++) { strTmp = dlg.GetPathName(); strTmp = strTmp.Left( strTmp.ReverseFind(_T('\\'))); nStartY = 0, nHeight = 0; for(int j = 0 ; j < 6 ; j++) { strPath.Format(_T("%s\\%s__%s_%d.%s"),strTmp,strGlsID,PANEL_SIDE[i],j,strExt); USES_CONVERSION; sprintf_s(str_filename, "%s", W2A(strPath)); if(access(str_filename, 0) == 0) { nHeight = LoadFullImage(strPath,i,nStartY); if(nHeight == -1) break; nStartY += nHeight; } else break; } if(pGlassData != NULL) { CSide_Data* pSideData = pGlassData->GetSideData((DimensionDir)i); if(pSideData != NULL) { pSideData->m_nGlassStartLine = 0; pSideData->m_nGlassEndLine = nStartY; } } if(_Func != nullptr) { _Func(i); } } } SetSlashText(GLOBAL_DEFINE::emHide, _T("Loading Full Image Completed"), RGB(0,0,0)); } m_bManualProcessStart = FALSE; g_pLog->DisplayMessage(_T("Loading Full Image Completed")); } void CMainFrame::DisplayMessage(TCHAR* str) { WriteLogManager(str); }