From 1aa192eb15c86740acf54cc3c8a6c0aeb5be22cd Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 10 七月 2025 11:08:19 +0800
Subject: [PATCH] 重构:移除文件保存中的班别逻辑,改为基于玻璃Loading Time的按小时/按天保存 优化:缺陷图片中的标注文本,针对Notch Dimension和Notch Chamfer类型,增加特殊标记,便于区分

---
 EdgeInspector_App/Recipe/HardwareSettings.h   |    3 
 EdgeInspector_App/View/ViewMain_HWSetting.cpp |    2 
 EdgeInspector_App/Data/DefectStorage.cpp      |    2 
 EdgeInspector_App/EdgeInspector_App.rc        |    0 
 EdgeInspector_App/Recipe/HardwareSettings.cpp |   39 ++++++++-
 EdgeInspector_App/resource.h                  |    0 
 EdgeInspector_App/Defect.h                    |    4 +
 EdgeInspector_App/Data/PostProcess.cpp        |  180 ++++++++++++++------------------------------
 8 files changed, 103 insertions(+), 127 deletions(-)

diff --git a/EdgeInspector_App/Data/DefectStorage.cpp b/EdgeInspector_App/Data/DefectStorage.cpp
index 65fa59d..6656b1a 100644
--- a/EdgeInspector_App/Data/DefectStorage.cpp
+++ b/EdgeInspector_App/Data/DefectStorage.cpp
@@ -309,6 +309,8 @@
 	pDefect->m_bJudge_NG = TRUE;
 	pDefect->m_dSizeX_um = dMeasureResult_um;
 	pDefect->m_dSizeY_um = dMeasureDiff_um;
+	pDefect->m_dChamfer_um = dMeasureResult_um;
+	pDefect->m_dChamferOff_um = dMeasureDiff_um;
 	pDefect->m_DefectInfo = defect;
 
 	if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
diff --git a/EdgeInspector_App/Data/PostProcess.cpp b/EdgeInspector_App/Data/PostProcess.cpp
index a1e66bc..9eb0bd8 100644
--- a/EdgeInspector_App/Data/PostProcess.cpp
+++ b/EdgeInspector_App/Data/PostProcess.cpp
@@ -180,6 +180,9 @@
 	if (glass_id.IsEmpty() == TRUE)
 		glass_id.Format(_T("MANUAL_ID"));
 
+	// 获取当前产品加载时间
+	CTime tGlassLoading = m_pGlassData->GetLoadingTime();
+
 	CString measure_data;
 	CString chip_data;
 	CString defect_data;
@@ -241,42 +244,19 @@
 		m_pGlassData->GetSideData(DIMENSION_C)->m_nTopCornerHeight,
 		m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerWidth,
 		m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerHeight
-		);
+	);
 	measure_data.Append(_T("\r\n"));
 
 	CString measure_file_path;
+	if (m_pHardware->m_bSaveResultByHour) {
+		// 按小时保存结果
+		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
+	}
+	else {
+		// 不按小时保存结果
+		measure_file_path.Format(_T("%s\\%s_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
+	}
 
-	// 获取当前时间
-	std::time_t m_now = std::time(nullptr);
-	// 使用localtime_s代替localtime
-	std::tm m_nowTm;
-	localtime_s(&m_nowTm, &m_now);
-	if (m_nowTm.tm_hour < 4)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay,24);
-	}
-	else if(m_nowTm.tm_hour > 3 && m_nowTm.tm_hour < 9)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 4);
-	}
-	else if (m_nowTm.tm_hour > 7 && m_nowTm.tm_hour < 13)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 8);
-	}
-	else if (m_nowTm.tm_hour > 11 && m_nowTm.tm_hour < 17)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 12);
-	}
-	else if (m_nowTm.tm_hour > 15 && m_nowTm.tm_hour < 21)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 16);
-	}
-	else if (m_nowTm.tm_hour > 19)
-	{
-		measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 20);
-	}
-	
-	
 	CheckDirectory(measure_file_path);
 
 	CFile measure_module;
@@ -434,31 +414,13 @@
 	}
 
 	CString Chip_file_path;
-	
-	localtime_s(&m_nowTm, &m_now);
-	if (m_nowTm.tm_hour < 4)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay,24);
+	if (m_pHardware->m_bSaveResultByHour) {
+		// 按小时保存结果
+		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
 	}
-	else if (m_nowTm.tm_hour > 3 && m_nowTm.tm_hour < 9)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 4);
-	}
-	else if (m_nowTm.tm_hour > 7 && m_nowTm.tm_hour < 13)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 8);
-	}
-	else if (m_nowTm.tm_hour > 11 && m_nowTm.tm_hour < 17)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 12);
-	}
-	else if (m_nowTm.tm_hour > 15 && m_nowTm.tm_hour < 21)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 16);
-	}
-	else if (m_nowTm.tm_hour > 19)
-	{
-		Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 20);
+	else {
+		// 不按小时保存结果
+		Chip_file_path.Format(_T("%s\\%s_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
 	}
 	
 	CheckDirectory(Chip_file_path);
@@ -481,32 +443,15 @@
 	}
 
 	CString Defect_file_path;
+	if (m_pHardware->m_bSaveResultByHour) {
+		// 按小时保存结果
+		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
+	}
+	else {
+		// 不按小时保存结果
+		Defect_file_path.Format(_T("%s\\%s_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
+	}
 
-	
-	if (m_nowTm.tm_hour < 4)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 24);
-	}
-	else if (m_nowTm.tm_hour > 3 && m_nowTm.tm_hour < 9)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 4);
-	}
-	else if (m_nowTm.tm_hour > 7 && m_nowTm.tm_hour < 13)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 8);
-	}
-	else if (m_nowTm.tm_hour > 11 && m_nowTm.tm_hour < 17)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 12);
-	}
-	else if (m_nowTm.tm_hour > 15 && m_nowTm.tm_hour < 21)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 16);
-	}
-	else if (m_nowTm.tm_hour > 19)
-	{
-		Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, 20);
-	}
 	CheckDirectory(Defect_file_path);
 
 	CFile defect_module;
@@ -642,14 +587,22 @@
 BOOL CPostProcess::SaveDefectImage_with_Title(CDefect* pDefect, CSize szImage,CRect rectDefect,CString strFile, CvScalar color)
 {
 	Lock();
-	if(pDefect == NULL || pDefect->m_Image == NULL)
+	if (pDefect == NULL || pDefect->m_Image == NULL) {
 		return FALSE;
+	}
 
 	// 标题文本
 	CString strTitle;
 	int nSideIdx = (0 <= pDefect->m_DefectInfo.m_nSideIdx && pDefect->m_DefectInfo.m_nSideIdx < MAX_SIDE_COUNT) ? pDefect->m_DefectInfo.m_nSideIdx : MAX_SIDE_COUNT;
 	int nCategoryIdx = (0 <= pDefect->m_DefectInfo.m_DefectLoc && pDefect->m_DefectInfo.m_DefectLoc < DefectLoc_None) ? pDefect->m_DefectInfo.m_DefectLoc : DefectLoc_Unknown;
-	strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d]"), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int)pDefect->m_dSizeX_um, (int)pDefect->m_dSizeY_um);
+	
+	DefectLocation eCategory = pDefect->m_DefectInfo.m_DefectLoc;
+	if (eCategory == DefectLoc_Notch_Dimension || eCategory == DefectLoc_Notch_Chamfer) {
+		strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d] distance[%d,%d] "), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int)pDefect->m_dSizeX_um, (int)pDefect->m_dSizeY_um, (int)pDefect->m_dChamfer_um, (int)pDefect->m_dChamferOff_um);
+	}
+	else {
+		strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d]"), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int)pDefect->m_dSizeX_um, (int)pDefect->m_dSizeY_um);
+	}
 	Unlock();
 
 	// 成功标志
@@ -1052,47 +1005,28 @@
 
 	// Save Path
 	CString strFilePath;
-	// 获取当前时间
-	std::time_t m_now = std::time(nullptr);
-	// 使用localtime_s代替localtime
-	std::tm m_nowTm;
-	localtime_s(&m_nowTm, &m_now);
-	if (m_nowTm.tm_hour < 4)
-	{
-		
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")),24 );
+	if (m_pHardware->m_bSaveResultByHour) {
+		// 按小时保存,绑定玻璃 Loading Time
+		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"),
+			m_pHardware->GetMachineName(),
+			m_pHardware->GetLineID(),
+			tLoadingTime.GetYear(),
+			tLoadingTime.GetMonth(),
+			tLoadingTime.GetDay(),
+			g_pBase->m_strRecipeName,
+			g_pBase->m_strLoadingDay,
+			tLoadingTime.GetHour());
 	}
-	else if (m_nowTm.tm_hour > 3 && m_nowTm.tm_hour < 8)
-	{
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")), 4);
-	}
-	else if (m_nowTm.tm_hour > 7 && m_nowTm.tm_hour < 12)
-	{
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")), 8);
-	}
-	else if (m_nowTm.tm_hour > 11 && m_nowTm.tm_hour < 16)
-	{
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")), 12);
-	}
-	else if (m_nowTm.tm_hour > 15 && m_nowTm.tm_hour < 20)
-	{
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")), 16);
-	}
-	else if (m_nowTm.tm_hour > 19)
-	{
-		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
-			, tLoadingTime.GetYear(), tLoadingTime.GetMonth(), tLoadingTime.GetDay()
-			, m_pGlassData->GetGlassRecipe()->GetRecipeName(), tLoadingTime.Format(_T("%Y%m%d")), 20);
+	else {
+		// 按天保存,绑定玻璃 Loading Time
+		strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s.csv"),
+			m_pHardware->GetMachineName(),
+			m_pHardware->GetLineID(),
+			tLoadingTime.GetYear(),
+			tLoadingTime.GetMonth(),
+			tLoadingTime.GetDay(),
+			g_pBase->m_strRecipeName,
+			g_pBase->m_strLoadingDay);
 	}
 
 	CheckDirectory(strFilePath);
diff --git a/EdgeInspector_App/Defect.h b/EdgeInspector_App/Defect.h
index 7e2a743..026e37a 100644
--- a/EdgeInspector_App/Defect.h
+++ b/EdgeInspector_App/Defect.h
@@ -148,6 +148,8 @@
 
 		m_dSizeX_um = 0.0;
 		m_dSizeY_um = 0.0;
+		m_dChamfer_um = 0.0;
+		m_dChamferOff_um = 0.0;
 
 		m_nDefectMergeCount = 0;
 		m_bDefectMergeRemoved = FALSE;
@@ -174,6 +176,8 @@
 
 	double			m_dSizeX_um;
 	double			m_dSizeY_um;
+	double			m_dChamfer_um;
+	double			m_dChamferOff_um;
 
 	// Merge
 	int				m_nDefectMergeCount;
diff --git a/EdgeInspector_App/EdgeInspector_App.rc b/EdgeInspector_App/EdgeInspector_App.rc
index 7220037..14866ad 100644
--- a/EdgeInspector_App/EdgeInspector_App.rc
+++ b/EdgeInspector_App/EdgeInspector_App.rc
Binary files differ
diff --git a/EdgeInspector_App/Recipe/HardwareSettings.cpp b/EdgeInspector_App/Recipe/HardwareSettings.cpp
index 46ce242..2a5f35c 100644
--- a/EdgeInspector_App/Recipe/HardwareSettings.cpp
+++ b/EdgeInspector_App/Recipe/HardwareSettings.cpp
@@ -1031,6 +1031,9 @@
 
 		m_bUse_SaveDebugImage = rhs.m_bUse_SaveDebugImage;
 
+		// ly,2025.07.10
+		m_bSaveResultByHour = rhs.m_bSaveResultByHour;
+
 		// ly,2025.07.07
 		m_bEnableAutoCopy = rhs.m_bEnableAutoCopy;
 		m_strCopyToolExePath = rhs.m_strCopyToolExePath;
@@ -1262,6 +1265,10 @@
 	else if((void *)&m_nSaveImageQuality == pValue)
 		str = _T("SAVEIMAGE_QUALITY");
 
+	// ly,2025.07.10
+	else if ((void*)&m_bSaveResultByHour == pValue)
+		str = _T("SAVE_RESULT_BY_HOUR");
+
 	// ly,2025.07.07
 	else if ((void*)&m_bEnableAutoCopy == pValue)
 		str = _T("ENABLE_AUTOCOPY");
@@ -1426,7 +1433,13 @@
 	BasicInfoFile.GetItemValue((TCHAR*)(LPCTSTR)str,nTemp);
 	m_bUse_SaveDebugImage = (BOOL) nTemp;
 
-	// ly.2025.07.07
+	// ly,2025.07.10
+	str = GetFileString((void*)&m_bSaveResultByHour);
+	if (str.IsEmpty() == TRUE)
+		return FALSE;
+	BasicInfoFile.GetItemValue((TCHAR*)(LPCTSTR)str, m_bSaveResultByHour, FALSE);
+
+	// ly,2025.07.07
 	str = GetFileString((void*)&m_bEnableAutoCopy);
 	if (str.IsEmpty() == TRUE)
 		return FALSE;
@@ -1600,7 +1613,13 @@
 	Register.GetItemValue((TCHAR*)(LPCTSTR)str,nTemp);
 	m_bUse_SaveDebugImage = (BOOL) nTemp;
 
-	// ly.2025.07.07
+	// ly,2025.07.10
+	str = GetFileString((void*)&m_bSaveResultByHour);
+	if (str.IsEmpty() == TRUE)
+		return FALSE;
+	Register.GetItemValue((TCHAR*)(LPCTSTR)str, m_bSaveResultByHour, FALSE);
+
+	// ly,2025.07.07
 	str = GetFileString((void*)&m_bEnableAutoCopy);
 	if (str.IsEmpty() == TRUE)
 		return FALSE;
@@ -1757,7 +1776,13 @@
 		return FALSE;
 	Register.SetItemValue((TCHAR*)(LPCTSTR)str,(int) m_bUse_SaveDebugImage);
 
-	// ly.2025.07.07
+	// ly,2025.07.10
+	str = GetFileString((void*)&m_bSaveResultByHour);
+	if (str.IsEmpty() == TRUE)
+		return FALSE;
+	Register.SetItemValue((TCHAR*)(LPCTSTR)str, (int)m_bSaveResultByHour);
+
+	// ly,2025.07.07
 	str = GetFileString((void*)&m_bEnableAutoCopy);
 	if (str.IsEmpty() == TRUE)
 		return FALSE;
@@ -1923,7 +1948,13 @@
 		return FALSE;
 	BasicInfoFile.SetItemValue((TCHAR*)(LPCTSTR)str,m_bUse_SaveDebugImage);
 
-	// ly.2025.07.07
+	// ly,2025.07.10
+	str = GetFileString((void*)&m_bSaveResultByHour);
+	if (str.IsEmpty() == TRUE)
+		return FALSE;
+	BasicInfoFile.SetItemValue((TCHAR*)(LPCTSTR)str, (int)m_bSaveResultByHour);
+
+	// ly,2025.07.07
 	str = GetFileString((void*)&m_bEnableAutoCopy);
 	if (str.IsEmpty() == TRUE)
 		return FALSE;
diff --git a/EdgeInspector_App/Recipe/HardwareSettings.h b/EdgeInspector_App/Recipe/HardwareSettings.h
index 374bd26..1343696 100644
--- a/EdgeInspector_App/Recipe/HardwareSettings.h
+++ b/EdgeInspector_App/Recipe/HardwareSettings.h
@@ -204,6 +204,9 @@
 	BOOL						m_bUse_SaveDebugImage;
 
 public:
+	BOOL						m_bSaveResultByHour;
+
+public:
 	BOOL						m_bEnableAutoCopy;
 	CString						m_strCopyToolExePath;
 	CString						m_strCopyToolConfigPath;
diff --git a/EdgeInspector_App/View/ViewMain_HWSetting.cpp b/EdgeInspector_App/View/ViewMain_HWSetting.cpp
index 9b51a4e..cff989c 100644
--- a/EdgeInspector_App/View/ViewMain_HWSetting.cpp
+++ b/EdgeInspector_App/View/ViewMain_HWSetting.cpp
@@ -83,6 +83,8 @@
 	DDX_Check(pDX,IDC_CHECK_USE_SAVE_DEBUG_IMAGE,m_pDlgHDSettingParm->m_bUse_SaveDebugImage);	
 	DDX_Check(pDX, IDC_CHECK_USE_SAVE_ALL_DMP, g_bUse_SaveAllDMP);
 
+	DDX_Check(pDX, IDC_CHECK_SAVE_RESULT_BY_HOUR, m_pDlgHDSettingParm->m_bSaveResultByHour);		// ly,2025.07.10
+
 	DDX_Check(pDX, IDC_CHECK_ENABLE_AUTO_COPY, m_pDlgHDSettingParm->m_bEnableAutoCopy);				// ly,2025.07.07
 	DDX_Text(pDX, IDC_EDIT_COPY_TOOL_EXE_PATH, m_pDlgHDSettingParm->m_strCopyToolExePath);
 	DDX_Text(pDX, IDC_EDIT_COPY_TOOL_CONFIG_PATH, m_pDlgHDSettingParm->m_strCopyToolConfigPath);
diff --git a/EdgeInspector_App/resource.h b/EdgeInspector_App/resource.h
index e8239d8..1c78a92 100644
--- a/EdgeInspector_App/resource.h
+++ b/EdgeInspector_App/resource.h
Binary files differ

--
Gitblit v1.9.3