From 4e3e35378d8c677397ece01378582b89869b572a Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 09 七月 2025 17:25:00 +0800
Subject: [PATCH] 创建 IV2M_LoadImageFromFolder 函数,提取重复代码,新增产品ID自动提取

---
 ENRIT/MainFrm.cpp |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 1 deletions(-)

diff --git a/ENRIT/MainFrm.cpp b/ENRIT/MainFrm.cpp
index 1db8ef5..d7a1197 100644
--- a/ENRIT/MainFrm.cpp
+++ b/ENRIT/MainFrm.cpp
@@ -243,6 +243,73 @@
 	m_pView->SetTransferData(&m_TransferData);
 }
 
+CString CMainFrame::GetGlassIDFromFolder(const CString& strFolderPath)
+{
+	// 查找图像文件
+	CFileFind finder;
+	BOOL bWorking = finder.FindFile(strFolderPath + _T("\\*.jpg"));
+	if (!bWorking) {
+		g_pLog->DisplayMessage(_T("No image files found in folder!"));
+		return _T("");
+	}
+
+	// 找到第一个有效文件
+	CString strGlassID;
+	while (bWorking) {
+		bWorking = finder.FindNextFile();
+		if (!finder.IsDots()) {
+			CString strFileName = finder.GetFileName();
+			int nPos = strFileName.Find(_T("__"));
+			if (nPos > 0)
+			{
+				strGlassID = strFileName.Left(nPos);
+				break;
+			}
+		}
+	}
+
+	if (strGlassID.IsEmpty()) {
+		g_pLog->DisplayMessage(_T("No valid image files found!"));
+	}
+
+	return strGlassID;
+}
+
+void CMainFrame::LoadImageSetFromFolder(const CString& strFolderPath, const CString& strGlsID, int iSide, CGlass_Data* pGlassData, std::function<void(BYTE)> _Func)
+{
+	char str_filename[200];
+	int nStartY = 0, nHeight = 0;
+	for (int j = 0; j < 6; j++) {
+		CString strPath;
+		strPath.Format(_T("%s\\%s__%s_%d.jpg"), strFolderPath, strGlsID, PANEL_SIDE[iSide], j);
+
+		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) {
+		INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
+		if (pResInfo != NULL) {
+			pResInfo->nGlassStartLine = 0;
+			pResInfo->nGlassEndLine = nStartY;
+		}
+	}
+
+	if (_Func != nullptr) {
+		_Func(iSide);
+	}
+}
+
 BOOL CMainFrame::IV2M_RecipeChange(CString strRecipe)
 {
 	m_strReserveRecipe.Empty();
@@ -669,7 +736,7 @@
 			CString strGlsID, strTmp , strExt;
 
 			strExt	 = dlg.GetFileExt();
-			strGlsID =dlg.GetFileName();
+			strGlsID = dlg.GetFileName();
 			strGlsID = strGlsID.Left(strGlsID.Find(_T("__")));
 			g_pBase->m_strHPanelID = strGlsID;
 
@@ -721,6 +788,50 @@
 	g_pLog->DisplayMessage(_T("Loading Full Image Completed"));	
 }
 
+void CMainFrame::IV2M_LoadImageFromFolder(int iSide, const CString& strFolderPath, CGlass_Data* pGlassData, std::function<void(BYTE)> _Func)
+{
+	if (IsScanNow()) {
+		g_pLog->DisplayMessage(_T("Doing Inspection"));
+		return;
+	}
+
+	if (m_bManualProcessStart == TRUE) {
+		g_pLog->DisplayMessage(_T("Doing Manual Process"));
+		return;
+	}
+
+	CFileFind finder;
+	BOOL bWorking = finder.FindFile(strFolderPath + _T("\\*.jpg"));
+	if (!bWorking) {
+		g_pLog->DisplayMessage(_T("No image files found in folder!"));
+		return;
+	}
+
+	m_bManualProcessStart = TRUE;
+	SetSlashText(GLOBAL_DEFINE::emShow, _T(""), RGB(0, 0, 0));
+	SetSlashText(GLOBAL_DEFINE::emText, _T("Image Loading Start"), RGB(0, 0, 0));
+
+	// 提取产品ID
+	CString strGlsID = GetGlassIDFromFolder(strFolderPath);
+	g_pBase->m_strHPanelID = strGlsID;
+
+	if (iSide > -1) {
+		// 单侧加载
+		LoadImageSetFromFolder(strFolderPath, strGlsID, iSide, pGlassData, _Func);
+	}
+	else {
+		// 全侧加载
+		for (int i = 0; i < MAX_PANEL_SIDE * UPDN_TYPE; i++) {
+			LoadImageSetFromFolder(strFolderPath, strGlsID, i, pGlassData, _Func);
+		}
+	}
+
+	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);

--
Gitblit v1.9.3