From 4b7616f61a6a37cc917cdbcb131f91272ab2e6fb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 06 二月 2026 16:03:05 +0800
Subject: [PATCH] 1.修复MSGDLg跨线程更新界面闪退问题; 2.完善拔片存片日志;

---
 SourceCode/Bond/Servo/MsgDlg.h       |   15 +++++
 SourceCode/Bond/Servo/CArm.cpp       |   17 +++++
 SourceCode/Bond/Servo/MsgDlg.cpp     |   84 ++++++++++++++++++++++++++++
 SourceCode/Bond/Servo/CEquipment.cpp |   14 ++++
 4 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/SourceCode/Bond/Servo/CArm.cpp b/SourceCode/Bond/Servo/CArm.cpp
index c257753..7f76c49 100644
--- a/SourceCode/Bond/Servo/CArm.cpp
+++ b/SourceCode/Bond/Servo/CArm.cpp
@@ -71,10 +71,21 @@
 		CGlass* pPreviousGlass;
 		pPreviousGlass = (CGlass*)m_slot[0].getContext();
 		if (pPreviousGlass != nullptr) {
+			LOGE("<CArm>tempStore, overwrite previous glass: %s (%d,%d)",
+				pPreviousGlass->getID().c_str(),
+				pPreviousGlass->getCassetteSequenceNo(),
+				pPreviousGlass->getJobSequenceNo());
 			pPreviousGlass->release();
 		}
 		m_slot[0].setContext(pGlass);
 		Unlock();
+
+		if (pGlass != nullptr) {
+			LOGI("<CArm>tempStore: GlassId:%s, Cassette:%d, Job:%d",
+				pGlass->getID().c_str(),
+				pGlass->getCassetteSequenceNo(),
+				pGlass->getJobSequenceNo());
+		}
 
 		if (m_listener.onDataChanged != nullptr) {
 			m_listener.onDataChanged(this, 0);
@@ -89,6 +100,7 @@
 		CGlass* pPreviousGlass = (CGlass*)m_slot[0].getContext();
 		if (pPreviousGlass == nullptr) {
 			Unlock();
+			LOGE("<CArm>tempFetchOut failed: arm slot empty.");
 			return -1;
 		}
 		pGlass = pPreviousGlass;
@@ -96,6 +108,11 @@
 		m_slot[0].setContext(nullptr);
 		Unlock();
 
+		LOGI("<CArm>tempFetchOut: GlassId:%s, Cassette:%d, Job:%d",
+			pGlass->getID().c_str(),
+			pGlass->getCassetteSequenceNo(),
+			pGlass->getJobSequenceNo());
+
 		if (m_listener.onDataChanged != nullptr) {
 			m_listener.onDataChanged(this, 0);
 		}
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 599a79c..0668179 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -934,9 +934,13 @@
 			}
 		}
 		if (pContext == nullptr) {
+			LOGE("<CEquipment-%s>fetchedOutJob, no glass for JobDataB(%d, %d)", m_strName.c_str(),
+				pJobDataB->getCassetteSequenceNo(), pJobDataB->getJobSequenceNo());
 			Unlock();
 			return -3;
 		}
+		LOGI("<CEquipment-%s>fetchedOutJob -> Arm: GlassId:%s, Cassette:%d, Job:%d", m_strName.c_str(),
+			pContext->getID().c_str(), pJobDataB->getCassetteSequenceNo(), pJobDataB->getJobSequenceNo());
 
 		((CArm*)m_pArm)->tempStore(pContext);
 		pContext->release();
@@ -962,11 +966,14 @@
 
 		CGlass* pGlass = nullptr;
 		if (((CArm*)m_pArm)->tempFetchOut(pGlass) != 0) {
+			LOGE("<CEquipment-%s>storedJob, tempFetchOut failed (arm empty).", m_strName.c_str());
 			return -2;
 		}
 
 
 		ASSERT(pGlass);
+		LOGI("<CEquipment-%s>storedJob <- Arm: GlassId:%s, Cassette:%d, Job:%d", m_strName.c_str(),
+			pGlass->getID().c_str(), pJobDataB->getCassetteSequenceNo(), pJobDataB->getJobSequenceNo());
 		Lock();
 		pGlass->addPath(m_nID, getSlotUnit(putSlot), putSlot);
 		CGlass* pBuddy = pGlass->getBuddy();
@@ -2109,13 +2116,18 @@
 		// 褰撳墠瑕佸瓨鐗囷紝涔嬪墠鑲畾鏈夋嫈鐗囷紝鍥犳鐗囧瓙鍦ˋrm閭i噷
 		CGlass* pGlass = ((CArm*)m_pArm)->getGlassFromSlot(1);
 		if (pGlass == nullptr) {
-			LOGE("<CFliper-%s>onPreStoredJob,缂撳瓨涓病鏈夋壘鍒板搴旂殑Glass(CassetteSequenceNo:%d, JobSequenceNo:%d)锛岃妫�鏌ユ暟鎹紝娉ㄦ剰椋庨櫓銆�", m_strName.c_str(),
+			LOGE("<CEquipment-%s>onPreStoredJob,缂撳瓨涓病鏈夋壘鍒板搴旂殑Glass(CassetteSequenceNo:%d, JobSequenceNo:%d)锛岃妫�鏌ユ暟鎹紝娉ㄦ剰椋庨櫓銆�", m_strName.c_str(),
 				pJobDataB->getCassetteSequenceNo(), pJobDataB->getJobSequenceNo());
+			LOGE("<CEquipment-%s>onPreStoredJob, arm temp empty (arm:%s).", m_strName.c_str(),
+				(m_pArm != nullptr) ? ((CEquipment*)m_pArm)->getName().c_str() : "null");
 			return FALSE;
 		}
 
 		CJobDataS* pJobDataS = pGlass->getJobDataS();
 		ASSERT(pJobDataS);
+		LOGI("<CEquipment-%s>onPreStoredJob, Arm has GlassId:%s, Cassette:%d, Job:%d",
+			m_strName.c_str(), pGlass->getID().c_str(),
+			pJobDataS->getCassetteSequenceNo(), pJobDataS->getJobSequenceNo());
 		if (!compareJobData(pJobDataB, pJobDataS)) {
 			LOGE("<CEquipemnt-%s>onPreStoredJob,JobData鏁版嵁涓嶅尮閰�(JobDataB(%d, %d),JobDataS(%d, %d)), 娉ㄦ剰鎺掓煡椋庨櫓!", m_strName.c_str(),
 				pJobDataB->getCassetteSequenceNo(), pJobDataB->getJobSequenceNo(),
diff --git a/SourceCode/Bond/Servo/MsgDlg.cpp b/SourceCode/Bond/Servo/MsgDlg.cpp
index 05faa18..8d72438 100644
--- a/SourceCode/Bond/Servo/MsgDlg.cpp
+++ b/SourceCode/Bond/Servo/MsgDlg.cpp
@@ -5,6 +5,7 @@
 #include "Servo.h"
 #include "MsgDlg.h"
 #include "afxdialogex.h"
+#include <memory>
 
 
 // CMsgDlg 瀵硅瘽妗�
@@ -14,6 +15,7 @@
 CMsgDlg::CMsgDlg(CWnd* pParent /*=nullptr*/)
 	: CDialogEx(IDD_DIALOG_MSG, pParent)
 {
+	m_uiThreadId = ::GetCurrentThreadId();
 	m_nCompleteCode = 0;
 	m_dwData = 0;
 	m_dwDataEx = 0;
@@ -28,6 +30,7 @@
 CMsgDlg::CMsgDlg(CString strTitle, CString strMessage)
 	: CDialogEx(IDD_DIALOG_MSG, NULL)
 {
+	m_uiThreadId = ::GetCurrentThreadId();
 	m_strTitle = strTitle;
 	m_strMessage = strMessage;
 	m_crBkgnd = CR_MSGBOX_BKGND;
@@ -40,6 +43,7 @@
 CMsgDlg::CMsgDlg(int nIcon, CString strTitle, CString strMessage)
 	: CDialogEx(IDD_DIALOG_MSG, NULL)
 {
+	m_uiThreadId = ::GetCurrentThreadId();
 	m_strTitle = strTitle;
 	m_strMessage = strMessage;
 	m_crBkgnd = CR_MSGBOX_BKGND;
@@ -58,11 +62,60 @@
 	CDialogEx::DoDataExchange(pDX);
 }
 
+bool CMsgDlg::IsUiThread() const
+{
+	return ::GetCurrentThreadId() == m_uiThreadId;
+}
+
+LRESULT CMsgDlg::OnMsgSetTitle(WPARAM wParam, LPARAM lParam)
+{
+	std::unique_ptr<CString> str(reinterpret_cast<CString*>(lParam));
+	SetTitle(*str);
+	return 0;
+}
+
+LRESULT CMsgDlg::OnMsgSetMessage(WPARAM wParam, LPARAM lParam)
+{
+	std::unique_ptr<CString> str(reinterpret_cast<CString*>(lParam));
+	SetMessage(*str);
+	return 0;
+}
+
+LRESULT CMsgDlg::OnMsgSetIcon(WPARAM wParam, LPARAM lParam)
+{
+	SetIcon(static_cast<int>(wParam));
+	return 0;
+}
+
+LRESULT CMsgDlg::OnMsgSetMarquee(WPARAM wParam, LPARAM lParam)
+{
+	SetMarquee((BOOL)wParam, (int)lParam);
+	return 0;
+}
+
+LRESULT CMsgDlg::OnMsgDelayClose(WPARAM wParam, LPARAM lParam)
+{
+	DelayClose((int)wParam);
+	return 0;
+}
+
+LRESULT CMsgDlg::OnMsgSetComplete(WPARAM wParam, LPARAM lParam)
+{
+	SetCompleteCode((int)wParam);
+	return 0;
+}
+
 
 BEGIN_MESSAGE_MAP(CMsgDlg, CDialogEx)
 	ON_WM_TIMER()
 	ON_WM_CTLCOLOR()
 	ON_WM_SIZE()
+	ON_MESSAGE(WM_MSGDLG_SET_TITLE, &CMsgDlg::OnMsgSetTitle)
+	ON_MESSAGE(WM_MSGDLG_SET_MESSAGE, &CMsgDlg::OnMsgSetMessage)
+	ON_MESSAGE(WM_MSGDLG_SET_ICON, &CMsgDlg::OnMsgSetIcon)
+	ON_MESSAGE(WM_MSGDLG_SET_MARQUEE, &CMsgDlg::OnMsgSetMarquee)
+	ON_MESSAGE(WM_MSGDLG_DELAY_CLOSE, &CMsgDlg::OnMsgDelayClose)
+	ON_MESSAGE(WM_MSGDLG_SET_COMPLETE, &CMsgDlg::OnMsgSetComplete)
 END_MESSAGE_MAP()
 
 
@@ -70,6 +123,10 @@
 
 void CMsgDlg::SetCompleteCode(int code)
 {
+	if (!IsUiThread()) {
+		PostMessage(WM_MSGDLG_SET_COMPLETE, (WPARAM)code, 0);
+		return;
+	}
 	m_nCompleteCode = code;
 	CWnd* pProgressCtrl = GetDlgItem(IDC_PROGRESS1);
 	if(pProgressCtrl != nullptr) pProgressCtrl->ShowWindow(SW_HIDE);
@@ -102,6 +159,10 @@
 
 void CMsgDlg::SetIcon(int nIcon)
 {
+	if (!IsUiThread()) {
+		PostMessage(WM_MSGDLG_SET_ICON, (WPARAM)nIcon, 0);
+		return;
+	}
 	m_nIcon = nIcon;
 	if (::IsWindow(m_hWnd)) {
 		UpdateIcon();
@@ -127,6 +188,13 @@
 
 void CMsgDlg::SetTitle(CString strTitle)
 {
+	if (!IsUiThread()) {
+		CString* pStr = new CString(strTitle);
+		if (!PostMessage(WM_MSGDLG_SET_TITLE, 0, (LPARAM)pStr)) {
+			delete pStr;
+		}
+		return;
+	}
 	m_strTitle = strTitle;
 	if (::IsWindow(m_hWnd) && GetDlgItem(IDC_LABEL_TITLE) != NULL) {
 		SetWindowText(m_strTitle);
@@ -136,6 +204,13 @@
 
 void CMsgDlg::SetMessage(CString strMessage)
 {
+	if (!IsUiThread()) {
+		CString* pStr = new CString(strMessage);
+		if (!PostMessage(WM_MSGDLG_SET_MESSAGE, 0, (LPARAM)pStr)) {
+			delete pStr;
+		}
+		return;
+	}
 	m_strMessage = strMessage;
 	if (::IsWindow(m_hWnd) && GetDlgItem(IDC_LABEL_MSG) != NULL) {
 		SetDlgItemText(IDC_LABEL_MSG, m_strMessage);
@@ -144,6 +219,10 @@
 
 void CMsgDlg::SetMarquee(_In_ BOOL fMarqueeMode, _In_ int nInterval)
 {
+	if (!IsUiThread()) {
+		PostMessage(WM_MSGDLG_SET_MARQUEE, (WPARAM)fMarqueeMode, (LPARAM)nInterval);
+		return;
+	}
 	if (!::IsWindow(m_hWnd)) {
 		return;
 	}
@@ -170,6 +249,10 @@
 
 void CMsgDlg::DelayClose(int nDelay)
 {
+	if (!IsUiThread()) {
+		PostMessage(WM_MSGDLG_DELAY_CLOSE, (WPARAM)nDelay, 0);
+		return;
+	}
 	if (!m_bDelayClose) {
 		m_bDelayClose = TRUE;
 		SetTimer(1, nDelay, NULL);
@@ -186,6 +269,7 @@
 BOOL CMsgDlg::OnInitDialog()
 {
 	CDialogEx::OnInitDialog();
+	m_uiThreadId = ::GetCurrentThreadId();
 
 	SetWindowText(m_strTitle);
 	SetDlgItemText(IDC_LABEL_TITLE, m_strTitle);
diff --git a/SourceCode/Bond/Servo/MsgDlg.h b/SourceCode/Bond/Servo/MsgDlg.h
index 3e97d8b..020eba1 100644
--- a/SourceCode/Bond/Servo/MsgDlg.h
+++ b/SourceCode/Bond/Servo/MsgDlg.h
@@ -9,6 +9,13 @@
 #define MSG_BOX_ERROR		0x03
 #define MSG_BOX_SUCCEED		0x04
 
+#define WM_MSGDLG_SET_TITLE		(WM_APP + 400)
+#define WM_MSGDLG_SET_MESSAGE	(WM_APP + 401)
+#define WM_MSGDLG_SET_ICON		(WM_APP + 402)
+#define WM_MSGDLG_SET_MARQUEE	(WM_APP + 403)
+#define WM_MSGDLG_DELAY_CLOSE	(WM_APP + 404)
+#define WM_MSGDLG_SET_COMPLETE	(WM_APP + 405)
+
 class CMsgDlg : public CDialogEx
 {
 	DECLARE_DYNAMIC(CMsgDlg)
@@ -38,6 +45,13 @@
 private:
 	void Resize();
 	void UpdateIcon();
+	bool IsUiThread() const;
+	LRESULT OnMsgSetTitle(WPARAM wParam, LPARAM lParam);
+	LRESULT OnMsgSetMessage(WPARAM wParam, LPARAM lParam);
+	LRESULT OnMsgSetIcon(WPARAM wParam, LPARAM lParam);
+	LRESULT OnMsgSetMarquee(WPARAM wParam, LPARAM lParam);
+	LRESULT OnMsgDelayClose(WPARAM wParam, LPARAM lParam);
+	LRESULT OnMsgSetComplete(WPARAM wParam, LPARAM lParam);
 
 private:
 	COLORREF m_crBkgnd;
@@ -53,6 +67,7 @@
 	DWORD_PTR m_dwData;
 	DWORD_PTR m_dwDataEx;
 	BOOL m_bDelayClose;
+	DWORD m_uiThreadId;
 
 
 // 瀵硅瘽妗嗘暟鎹�

--
Gitblit v1.9.3