From c6e24163c3c852b4ac3e45d100b9253b3db0e182 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 15 八月 2025 16:59:00 +0800
Subject: [PATCH] 1. 保存数据优化,提取公共区域,方便后期修改和扩展

---
 EdgeInspector_App/View/ViewMain_ScanImage.cpp |  124 ++++++++++++++++++-----------------------
 1 files changed, 54 insertions(+), 70 deletions(-)

diff --git a/EdgeInspector_App/View/ViewMain_ScanImage.cpp b/EdgeInspector_App/View/ViewMain_ScanImage.cpp
index 7587647..874a1ef 100644
--- a/EdgeInspector_App/View/ViewMain_ScanImage.cpp
+++ b/EdgeInspector_App/View/ViewMain_ScanImage.cpp
@@ -10,7 +10,8 @@
 
 enum TYPE_MANUAL_CMD
 {
-	M_CMD_PROC_SHORT_START = 0,
+	M_CMD_PROC_RIP_START = 0,
+	M_CMD_PROC_SHORT_START,
 	M_CMD_PROC_LONG_START,
 	M_CMD_PROC_ALL_START,
 	M_CMD_IMG_LOAD_ALL,
@@ -263,12 +264,10 @@
 
 void CViewMain_ScanImage::OnShowWindow(BOOL bShow, UINT nStatus)
 {
-	if(bShow == TRUE)
-	{
+	if(bShow == TRUE) {
 		int nSide;		
 		CString	strTitle;
-		for(int i = 0 ; i < MAX_PANEL_SIDE * UPDN_TYPE; i++)
-		{
+		for(int i = 0 ; i < MAX_PANEL_SIDE * UPDN_TYPE; i++) {
 			nSide = GetSideIdx(i);
 			m_frameImg[i].SetSideIdx(nSide);			
 			m_frameImg[i].SetGlassData(m_pGlassData);
@@ -278,16 +277,20 @@
 			m_frameImg[i].Invalidate();
 
 			if(m_pHardware != NULL) {
-				CCameraSettings *pCamera = LiveGetSideIdx(i);
+				CCameraSettings *pCamera = GetCameraSettingsByViewIndex(i);
 				if(pCamera != NULL) {
 					double dPixelSizeX = pCamera->m_dConvResolution[0];
 					double dPixelSizeY = pCamera->m_dScanResolution[0];
 					m_frameImg[i].SetPixelSize(dPixelSizeX, dPixelSizeY);
+
+					strTitle.Format(_T("BORD[%d]  CHANNEL[%d]"), pCamera->m_iCamera, 0);
+					m_staticCamInfo[i].SetWindowText(strTitle);
 				}
-				
-				strTitle.Format(_T("BORD[%d]  CHANNEL[%d]"),pCamera->m_iCamera, 0);
-				m_staticCamInfo[i].SetWindowText(strTitle);
-			}			
+			}
+
+			if (m_pGlassData != nullptr) {
+				m_frameImg[i].SetRecipe(m_pGlassData->GetGlassRecipe());
+			}
 		}
 
 		m_bInitDlg = TRUE;
@@ -317,12 +320,13 @@
 BYTE* CViewMain_ScanImage::GetBufferPoint(int nViewIndex,int nPos /*= 0*/)
 {
 	BYTE *add = NULL;
-	int nIdx_Side	 = GetSideIdx(nViewIndex);
+	int nIdx_Side = GetSideIdx(nViewIndex);
 
 	LPBYTE plpBuf = NULL;
-	if(m_IV2M != NULL)
-		plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)nIdx_Side,nPos);
-	
+	if (m_IV2M != NULL) {
+		plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)nIdx_Side, nPos);
+	}
+
 	return plpBuf;
 }
 
@@ -331,8 +335,7 @@
 	PROG_MSG MsgJob = *((PROG_MSG*)wParam);	
 
 	int nIndex = GetViewIndex(MsgJob.nSide);
-	if(MsgJob.nState == 2)
-	{
+	if(MsgJob.nState == 2) {
 		InitScrollInfo(MsgJob.nSide,1);
 
 		m_ctrlScrollV[nIndex].EnableWindow(TRUE);
@@ -356,23 +359,7 @@
 		m_frameImg[nIndex].SetGlassData(m_pGlassData);
 		m_frameImg[nIndex].Invalidate();
 	}
-	else
-	{
-		/*
-		if(fabs(m_dZoom - 1.) > 0.01)
-		{
-			m_dZoom = 0.2;		
-			m_sliderZoom.SetPos(0);
-
-			CString strTmp;
-			strTmp.Format(_T("X %.2f"),m_dZoom);
-			GetDlgItem(IDC_ST_ZOOM)->SetWindowText(strTmp);
-
-			UpdateZoom();
-		}
-		*/
-
-		//g_pLog->DisplayMessage(_T("Frame Display %d"),nIndex);
+	else {
 		CPoint ptOrg = m_frameImg[nIndex].GetDisplayPos();
 		ptOrg.y = MsgJob.nDispLine;
 
@@ -386,7 +373,7 @@
 
 void CViewMain_ScanImage::SetupImageSave()
 {
-	ManualThreadStart(M_CMD_IMG_SAVE_ALL,-1);
+	ManualThreadStart(M_CMD_IMG_SAVE_ALL, -1);
 }
 
 void CViewMain_ScanImage::SetRecipe(CHardwareSettings *pHW)
@@ -396,10 +383,9 @@
 
 void CViewMain_ScanImage::ResetView()
 {
-	for(int i = 0; i < MAX_PANEL_SIDE * UPDN_TYPE; i++)
-	{
+	for(int i = 0; i < MAX_PANEL_SIDE * UPDN_TYPE; i++) {
 		m_ctrlScrollV[i].EnableWindow(FALSE);
-	}	
+	}
 }
 
 void CViewMain_ScanImage::ViewRefresh(PROG_MSG ProcMsg)
@@ -1031,8 +1017,8 @@
 	if (NULL == pGlassRcp) return;
 #endif
 
-	CString			strRcpName = pGlassRcp->GetRecipeName();
-	CString			strGlassID = g_pBase->m_strHPanelID;
+	CString	strRcpName = pGlassRcp->GetRecipeName();
+	CString	strGlassID = g_pBase->m_strHPanelID;
 
 	if(strGlassID.IsEmpty() == TRUE) {
 		strGlassID = _T("Manual_ID");
@@ -1100,11 +1086,10 @@
 		if(nLength > 10) {		
 			if(ptStart.y+nLength < nMaxSize) {
 				strPath.Format(_T("%s\\DebugFullImage\\%s\\%s\\%s\\%s\\%s__%s_%d"),PATH_INSPECTION_DATA,strDate,strRcpName,strGlassID,strTime,strGlassID,PANEL_SIDE[iSide],nFrame);		
-				m_IV2M->IV2M_SaveFullImage(strPath,iSide,ptStart,nLength);		
+				m_IV2M->IV2M_SaveFullImage(strPath,iSide,ptStart,nLength);
+				g_pLog->DisplayMessage(_T("%s %d Save Completed : %s"), PANEL_SIDE[iSide], nFrame, strPath);
 			}			
 		}
-
-		g_pLog->DisplayMessage(_T("%s %d Save Completed : %s"),PANEL_SIDE[iSide],nFrame,strPath);
 	}
 }
 
@@ -1189,8 +1174,9 @@
 	CViewMain_ScanImage *pDlg = (CViewMain_ScanImage*)pParam;
 	int i =0;
 	if(pDlg->m_nThreadCmd == M_CMD_PROC_ALL_START
+		|| pDlg->m_nThreadCmd == M_CMD_PROC_LONG_START
 		|| pDlg->m_nThreadCmd == M_CMD_PROC_SHORT_START
-		|| pDlg->m_nThreadCmd == M_CMD_PROC_LONG_START)
+		|| pDlg->m_nThreadCmd == M_CMD_PROC_RIP_START)
 	{
 		pDlg->m_IV2M->IV2M_InspectionProcessAll(pDlg->m_nThreadCmd);
 	}
@@ -1303,9 +1289,9 @@
 		ManualThreadStart(M_CMD_PROC_SHORT_START);  
 		break;
 
-	//case 3:
-	//	ManualThreadStart(M_CMD_PROC_RIP_START);
-	//	break;
+	case 3:
+		ManualThreadStart(M_CMD_PROC_RIP_START);
+		break;
 	}
 }
 
@@ -1364,32 +1350,30 @@
 	}
 }
 
-CCameraSettings* CViewMain_ScanImage::LiveGetSideIdx(int nViewIndex)
+CCameraSettings* CViewMain_ScanImage::GetCameraSettingsByViewIndex(int nViewIndex)
 {
 	CCameraSettings* pCamera = NULL;
-	if (m_pHardware != nullptr) {
-		int nSide = GetSideIdx(nViewIndex);
-		int nCamera = m_pHardware->GetCameraIndexToDimension((DimensionDir)nSide);
-		if (nViewIndex < MAX_PANEL_SIDE) {
-			// Long side
-			pCamera = m_pHardware->GetCameraSettings(nCamera, 0);
-		}
-		else if (nViewIndex < 2 * MAX_PANEL_SIDE) {
-			// Short side
-			pCamera = m_pHardware->GetCameraSettings(nCamera, 1);
-		}
-		else {
-			// Rip side
-			int nRipIndex = nViewIndex - 2 * MAX_PANEL_SIDE;
-			int nRipCamera = nRipIndex / 2 + MAX_PANEL_SIDE;
-			if (nRipIndex % 2 != 0) {
-				pCamera = m_pHardware->GetCameraSettings(nCamera, 0);
-			}
-			else {
-				pCamera = m_pHardware->GetCameraSettings(nCamera, 1);
-			}
-		}
+	if (nullptr == m_pHardware) {
+		return pCamera;
 	}
 
-	return pCamera;
+	// ViewIndex -> DimensionDir
+	static const DimensionDir SIDE_MAP[] = {
+		DIMENSION_C, DIMENSION_C_DN,
+		DIMENSION_A, DIMENSION_A_DN,
+		DIMENSION_D, DIMENSION_D_DN,
+		DIMENSION_B, DIMENSION_B_DN,
+		DIMENSION_A_RIP, DIMENSION_B_RIP,
+		DIMENSION_C_RIP, DIMENSION_D_RIP
+	};
+
+	if (nViewIndex < 0 || nViewIndex >= _countof(SIDE_MAP)) {
+		AfxMessageBox(_T("GetCameraSettingsByViewIndex: Invalid view index"));
+		return nullptr;
+	}
+
+	DimensionDir eSide = SIDE_MAP[nViewIndex];
+	int nScan = m_pHardware->GetScanToDimension(eSide);
+	int nCamera = m_pHardware->GetCameraIndexToDimension(eSide);
+	return pCamera = m_pHardware->GetCameraSettings(nCamera, nScan);
 }
\ No newline at end of file

--
Gitblit v1.9.3