From 22f2984276ff75433ebeab877c96b48905826e6c Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 06 二月 2026 16:51:25 +0800
Subject: [PATCH] 1.Slot防护

---
 SourceCode/Bond/Servo/CPageGraph2.cpp |  282 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 262 insertions(+), 20 deletions(-)

diff --git a/SourceCode/Bond/Servo/CPageGraph2.cpp b/SourceCode/Bond/Servo/CPageGraph2.cpp
index 00e7b4c..d1da54d 100644
--- a/SourceCode/Bond/Servo/CPageGraph2.cpp
+++ b/SourceCode/Bond/Servo/CPageGraph2.cpp
@@ -5,6 +5,17 @@
 #include "Servo.h"
 #include "CPageGraph2.h"
 #include "afxdialogex.h"
+#include "CHMPropertyDlg.h"
+#include "CEquipmentPage1.h"
+#include "CEquipmentPage2.h"
+#include "CEquipmentPage3.h"
+#include "CPageLinkSignal.h"
+#include "CPagePortProperty.h"
+#include "CPagePortStatus.h"
+#include "CPageCassetteCtrlCmd.h"
+#include "CJobDataB.h"
+
+#define WM_MANUAL_ROUTE_REAPPLY (WM_APP + 105)
 
 
 // CPageGraph2 瀵硅瘽妗�
@@ -17,6 +28,7 @@
 	m_pEqsGraphWnd = nullptr;
 	m_crBkgnd = PAGE_GRPAH2_BACKGROUND_COLOR;
 	m_hbrBkgnd = nullptr;
+	m_pObserver = nullptr;
 }
 
 CPageGraph2::~CPageGraph2()
@@ -34,15 +46,49 @@
 	ON_WM_DESTROY()
 	ON_WM_SIZE()
 	ON_WM_TIMER()
+	ON_MESSAGE(WM_MANUAL_ROUTE_REAPPLY, &CPageGraph2::OnManualRouteMsg)
 END_MESSAGE_MAP()
 
 
 // CPageGraph2 娑堟伅澶勭悊绋嬪簭
 
 
+void CPageGraph2::InitRxWindows()
+{
+	/* code */
+	// 璁㈤槄鏁版嵁
+	IRxWindows* pRxWindows = RX_GetRxWindows();
+	pRxWindows->enableLog(5);
+	if (m_pObserver == NULL) {
+		m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void {
+			// onNext
+			pAny->addRef();
+			int code = pAny->getCode();
+			if (RX_CODE_EQ_DATA_CHANGED == code) {
+				// 閫氱煡璁惧鐘舵��
+				SERVO::CEquipment* pEquipment = nullptr;
+				if (pAny->getPtrValue("ptr", (void*&)pEquipment) && pEquipment != nullptr) {
+					UpdateItemIndicators(pEquipment);
+				}
+			}
+
+			pAny->release();
+			}, [&]() -> void {
+				// onComplete
+			}, [&](IThrowable* pThrowable) -> void {
+				// onErrorm
+				pThrowable->printf();
+			});
+
+		theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
+			->subscribe(m_pObserver);
+	}
+}
+
 BOOL CPageGraph2::OnInitDialog()
 {
 	CDialogEx::OnInitDialog();
+	InitRxWindows();
 	SetTimer(1, 2000, nullptr);
 
 
@@ -54,11 +100,6 @@
 		ASSERT(pPin1->pData);
 		ASSERT(pPin2->pData);
 
-		//int nRet = ((IPin*)pPin1->pData)->checkConnectPin((IPin*)pPin2->pData);
-		//if (nRet >= 0) {
-		//	return true;
-		//}
-
 		return false;
 	};
 	listener.onConnectPin = [](PIN* pPin1, PIN* pPin2) -> bool {
@@ -67,35 +108,69 @@
 		ASSERT(pPin1->pData);
 		ASSERT(pPin2->pData);
 
-		//int nRet = ((IPin*)pPin1->pData)->connectPin((IPin*)pPin2->pData);
-		//if (nRet >= 0) {
-		//	return true;
-		//}
-
 		return false;
 	};
 	listener.onDisconnectPin = [](PIN* pPin) -> bool {
 		ASSERT(pPin);
 		ASSERT(pPin->pData);
 
-		//int nRet = ((IPin*)pPin->pData)->disconnect();
-		//if (nRet >= 0) {
-		//	return true;
-		//}
-
 		return false;
 	};
 	listener.onDeleteEqItem = [&](EQITEM* pItem) -> bool {
 		ASSERT(pItem);
 		ASSERT(pItem->pData);
-		return true;
-		// return _filterManager.unload((CFilter*)pFilter->pData) >= 0;
+		return false;
 	};
 	listener.onEqItemPosChanged = [&](EQITEM* pItem, int x, int y) -> void {
 		ASSERT(pItem);
+		PostMessage(WM_MANUAL_ROUTE_REAPPLY, 0, 0);
 	};
 	listener.onDblckEqItem = [&](EQITEM* pItem) -> bool {
 		ASSERT(pItem);
+		SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)pItem->pData;
+
+		CHMPropertyDlg dlg(pEquipment->getName().c_str(), 1258, 788);
+
+		CPageLinkSignal* pPage1 = new CPageLinkSignal();
+		pPage1->setEquipment(pEquipment);
+		pPage1->Create(IDD_PAGE_LINK_SIGNAL);
+		dlg.addPage(pPage1, "Link Signal");
+
+		if (_strcmpi(pEquipment->getClassName(), "CLoadPort") == 0) {
+			CPagePortProperty* pPageA = new CPagePortProperty();
+			pPageA->setLoadPort((SERVO::CLoadPort*)pEquipment);
+			pPageA->Create(IDD_PAGE_PORT_PROPERTY);
+			dlg.addPage(pPageA, "灞炴��");
+
+			CPagePortStatus* pPageB = new CPagePortStatus();
+			pPageB->setLoadPort((SERVO::CLoadPort*)pEquipment);
+			pPageB->Create(IDD_PAGE_PORT_STATUS);
+			dlg.addPage(pPageB, "Status");
+		}
+
+		CEquipmentPage2* pPage2 = new CEquipmentPage2();
+		pPage2->setEquipment(pEquipment);
+		pPage2->Create(IDD_PAGE_EQUIPMENT2);
+		dlg.addPage(pPage2, "Slots");
+
+		if (pEquipment->getID() == EQ_ID_EFEM) {
+			CEquipmentPage3* pPage3 = new CEquipmentPage3();
+			pPage3->setEquipment(pEquipment);
+			pPage3->Create(IDD_PAGE_EQUIPMENT3);
+			dlg.addPage(pPage3, "Dispatching Mode");
+		}
+
+		if (pEquipment->getID() == EQ_ID_LOADPORT1
+			|| pEquipment->getID() == EQ_ID_LOADPORT2
+			|| pEquipment->getID() == EQ_ID_LOADPORT3
+			|| pEquipment->getID() == EQ_ID_LOADPORT4) {
+			CPageCassetteCtrlCmd* pPage = new CPageCassetteCtrlCmd();
+			pPage->setEquipment(pEquipment);
+			pPage->Create(IDD_PAGE_CASSETTE_CTRL_CMD);
+			dlg.addPage(pPage, "Cassette control command");
+		}
+
+		dlg.DoModal();
 		return true;
 	};
 	listener.onRclickEqItem = [&](EQITEM* pItem) -> bool {
@@ -139,14 +214,91 @@
 
 		// 娴嬭瘯
 		else if (nCmd == ID_EQSGRAPHITEM_TEST1) {
-			SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)pItem->pData;
-			pEquipment->outputGlass(0);
 		}
 		else if (nCmd == ID_EQSGRAPHITEM_TEST2) {
+		}
+		else if (nCmd == ID_EQSGRAPHITEM_TEST3) {
+		}
+		else if (nCmd == ID_EQSGRAPHITEM_TEST4) {
+		}
+		else if (nCmd == ID_EQSGRAPHITEM_TEST5) {
+		}
+		else if (nCmd == ID_EQSGRAPHITEM_TEST6) {
 			SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)pItem->pData;
-			pEquipment->outputGlass(1);
+
+
+			// 娴嬭瘯涓嬪彂Cim Message
+			/*
+			if (pEquipment->getID() == EQ_ID_Bonder1
+				|| pEquipment->getID() == EQ_ID_Bonder2) {
+				static int msgId = 0; msgId++;
+				if (msgId % 2 == 0) {
+					pEquipment->setCimMessage("Hello!", msgId, 1);
+				}
+				else {
+					pEquipment->setCimMessage("ABC0123456789", msgId, 2);
+				}
+			}
+			*/
+
+
+			// 娴嬭瘯娓呴櫎Cim Message
+			/*
+			if (pEquipment->getID() == EQ_ID_Bonder1
+				|| pEquipment->getID() == EQ_ID_Bonder2) {
+				static int msgId = 0; msgId++;
+				if (msgId % 2 == 0) {
+					pEquipment->clearCimMessage(msgId, 1);
+				}
+				else {
+					pEquipment->clearCimMessage(msgId, 2);
+				}
+			}
+			*/
+
+			// 娴嬭瘯璁剧疆鏃堕棿
+			/*
+			if (pEquipment->getID() == EQ_ID_EFEM) {
+				CTime time = CTime::GetCurrentTime();
+				pEquipment->setDateTime((short)time.GetYear(),
+					(short)time.GetMonth(),
+					(short)time.GetDay(),
+					(short)time.GetHour(),
+					(short)time.GetMinute(),
+					(short)time.GetSecond());
+			}
+			*/
+			
+			// 娴嬭瘯璁剧疆cim mode
+			/*
+			if (pEquipment->getID() == EQ_ID_Bonder1
+				|| pEquipment->getID() == EQ_ID_Bonder2) {
+				static int ii = 0; ii++;
+				pEquipment->setCimMode(ii % 2 == 0);
+			}
+			*/
+			
+			/*
+			if (pEquipment->getID() == EQ_ID_Bonder1
+				|| pEquipment->getID() == EQ_ID_Bonder2) {
+				static int ii = 0; ii++;
+				pEquipment->setEqMode((ii % 5) + 1);
+			}
+			*/
+
+			static int i = 0;
+			i++;
+			static char* pszText[] = {"123", "456", "789", "abc", "def"};
+			theApp.m_model.m_hsmsPassive.requestAlarmReport(i%3, i, pszText[i%5]);
 		}
 
+
+		return true;
+	};
+	listener.onSelectEqItem = [&](EQITEM* pItem) -> bool {
+		ASSERT(pItem);
+		SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)pItem->pData;
+		theApp.m_model.notifyPtr(RX_CODE_SELECT_EQUIPMENT, pEquipment);
 
 		return true;
 	};
@@ -155,6 +307,12 @@
 	m_pEqsGraphWnd->SetBkgndColor(m_crBkgnd);
 	m_pEqsGraphWnd->SetOnListener(listener);
 
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	int nIndicatorSize = GetPrivateProfileInt("PageGraph2", _T("IndicatorSize"), 10, strIniFile);
+	int nIndicatorMargin = GetPrivateProfileInt("PageGraph2", _T("IndicatorMargin"), 0, strIniFile);
+	m_pEqsGraphWnd->SetIndicatorSize(nIndicatorSize);
+	m_pEqsGraphWnd->SetIndicatorMargin(nIndicatorMargin);
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
@@ -185,6 +343,11 @@
 
 	if (m_hbrBkgnd != nullptr) {
 		::DeleteObject(m_hbrBkgnd);
+	}
+
+	if (m_pObserver != nullptr) {
+		m_pObserver->unsubscribe();
+		m_pObserver = NULL;
 	}
 }
 
@@ -221,6 +384,70 @@
 	for (auto outPin : outPins) {
 		m_pEqsGraphWnd->AddPin(pItem, OUTPIN, outPin->getName().c_str(), (DWORD_PTR)outPin);
 	}
+
+	UpdateItemIndicators(pEquipment);
+}
+
+void CPageGraph2::UpdateItemIndicators(SERVO::CEquipment* pEquipment)
+{
+	for (int i = 0; i < SLOT_MAX; i++) {
+		auto pSlot = pEquipment->getSlot(i);
+
+		int state = 0;
+		if (pSlot->isEnable()) {
+			state = pSlot->getContext() != nullptr ? 1 : 2;
+		}
+		m_pEqsGraphWnd->ShowItemIndicator((DWORD_PTR)pEquipment, state, i);
+	}
+}
+
+void CPageGraph2::ApplyManualRoutes()
+{
+	if (m_pEqsGraphWnd == nullptr) {
+		return;
+	}
+
+	auto pMeasurement = (SERVO::CEquipment*)theApp.m_model.m_master.getEquipment(EQ_ID_MEASUREMENT);
+	auto pLoadPort1 = (SERVO::CEquipment*)theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT1);
+	auto pLoadPort3 = (SERVO::CEquipment*)theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT3);
+	auto pLoadPort4 = (SERVO::CEquipment*)theApp.m_model.m_master.getEquipment(EQ_ID_LOADPORT4);
+	if (pMeasurement == nullptr || pLoadPort1 == nullptr || pLoadPort3 == nullptr) {
+		return;
+	}
+
+	SERVO::CPin* pOut1 = pMeasurement->getPin("Out1");
+	SERVO::CPin* pOut2 = pMeasurement->getPin("Out2");
+	SERVO::CPin* pIn1 = pLoadPort1->getPin("In");
+	SERVO::CPin* pIn3 = pLoadPort3->getPin("In");
+	if (pOut1 == nullptr || pOut2 == nullptr || pIn1 == nullptr || pIn3 == nullptr) {
+		return;
+	}
+
+	if (pOut1->getConnectedPin() == pIn1) {
+		PIN* pGraphOut1 = m_pEqsGraphWnd->GetPin((DWORD_PTR)pMeasurement, (DWORD_PTR)pOut1);
+		PIN* pGraphIn1 = m_pEqsGraphWnd->GetPin((DWORD_PTR)pLoadPort1, (DWORD_PTR)pIn1);
+		if (pGraphOut1 != nullptr && pGraphIn1 != nullptr) {
+			m_pEqsGraphWnd->SetManualRoute(pGraphOut1, pGraphIn1, TRUE);
+		}
+	}
+
+	if (pOut2->getConnectedPin() == pIn3) {
+		PIN* pGraphOut2 = m_pEqsGraphWnd->GetPin((DWORD_PTR)pMeasurement, (DWORD_PTR)pOut2);
+		PIN* pGraphIn3 = m_pEqsGraphWnd->GetPin((DWORD_PTR)pLoadPort3, (DWORD_PTR)pIn3);
+		if (pGraphOut2 != nullptr && pGraphIn3 != nullptr) {
+			m_pEqsGraphWnd->SetManualRoute(pGraphOut2, pGraphIn3, FALSE);
+			if (pLoadPort4 != nullptr && pGraphOut2->nLinePtCount >= 6) {
+				EQITEM* pGraphPort4 = m_pEqsGraphWnd->GetItem((DWORD_PTR)pLoadPort4);
+				if (pGraphPort4 != nullptr) {
+					int yTarget = pGraphPort4->rect.bottom + 20;
+					if (pGraphOut2->ptConnectedLine[2].y < yTarget) {
+						pGraphOut2->ptConnectedLine[2].y = yTarget;
+						pGraphOut2->ptConnectedLine[3].y = yTarget;
+					}
+				}
+			}
+		}
+	}
 }
 
 void CPageGraph2::OnTimer(UINT_PTR nIDEvent)
@@ -241,9 +468,21 @@
 				}
 			}
 		}
+
+		ApplyManualRoutes();
 	}
 
 	CDialogEx::OnTimer(nIDEvent);
+}
+
+LRESULT CPageGraph2::OnManualRouteMsg(WPARAM wParam, LPARAM lParam)
+{
+	ApplyManualRoutes();
+	CWnd* pGraphWnd = GetDlgItem(IDC_EQSGRAPHWND1);
+	if (pGraphWnd != nullptr) {
+		pGraphWnd->Invalidate(FALSE);
+	}
+	return 0;
 }
 
 void CPageGraph2::SaveEqsGraphData()
@@ -254,6 +493,9 @@
 	std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
 	for (auto item : eqs) {
 		EQITEM* pEqItem = m_pEqsGraphWnd->GetItem((DWORD_PTR)item);
+		if (nullptr == pEqItem) {
+			continue;
+		}
 
 		strValue.Format(_T("%d"), pEqItem->rect.left);
 		WritePrivateProfileString(item->getName().c_str(), _T("Left"),

--
Gitblit v1.9.3