From 4eaefee05c987e352dd6d761e601aa450f7f92b4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 21 三月 2025 14:41:46 +0800
Subject: [PATCH] 1.添加其它机器并连接,显示连接图;

---
 SourceCode/Bond/Servo/CPageGraph2.cpp |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CPageGraph2.cpp b/SourceCode/Bond/Servo/CPageGraph2.cpp
index aa1cd73..83c2471 100644
--- a/SourceCode/Bond/Servo/CPageGraph2.cpp
+++ b/SourceCode/Bond/Servo/CPageGraph2.cpp
@@ -133,6 +133,7 @@
 void CPageGraph2::OnDestroy()
 {
 	CDialogEx::OnDestroy();
+	SaveEqsGraphData();
 
 	if (m_hbrBkgnd != nullptr) {
 		::DeleteObject(m_hbrBkgnd);
@@ -154,8 +155,15 @@
 #define OUTPIN		2
 void CPageGraph2::AddEqToGraphWnd(SERVO::CEquipment* pEquipment)
 {
+	int x, y;
+	GetItemDataFormIni(pEquipment->getName().c_str(), x, y);
+
 	EQITEM* pItem = m_pEqsGraphWnd->AddItem(0, pEquipment->getName().c_str(), (DWORD_PTR)pEquipment);
 	m_pEqsGraphWnd->SetItemType(pItem, ITEM_SMALL);
+	if (x > 0 && y > 0) {
+		m_pEqsGraphWnd->SetItemPos(pItem, x, y);
+	}
+
 	std::vector<SERVO::CPin*>& inPins = pEquipment->getInputPins();
 	for (auto inPin : inPins) {
 		m_pEqsGraphWnd->AddPin(pItem, INPIN, inPin->getName().c_str(), (DWORD_PTR)inPin);
@@ -172,10 +180,47 @@
 	if (1 == nIDEvent) {
 		KillTimer(1);
 		std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
-		for (auto item : eqs) {
-			AddEqToGraphWnd(item);
+		for (auto eq : eqs) {
+			AddEqToGraphWnd(eq);
+		}
+
+		for (auto eq : eqs) {
+			auto& pins = eq->getOutputPins();
+			for (auto pin : pins) {
+				SERVO::CPin* pPin2 = pin->getConnectedPin();
+				if (pPin2 != nullptr) {
+					m_pEqsGraphWnd->ConnectPin((DWORD_PTR)eq, (DWORD_PTR)pin, (DWORD_PTR)pPin2->getEquipment(), (DWORD_PTR)pPin2);
+				}
+			}
 		}
 	}
 
 	CDialogEx::OnTimer(nIDEvent);
 }
+
+void CPageGraph2::SaveEqsGraphData()
+{
+	char szFilepath[MAX_PATH];
+	CString strValue;
+	sprintf_s(szFilepath, MAX_PATH, "%s\\EqsGraph.ini", (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
+	for (auto item : eqs) {
+		EQITEM* pEqItem = m_pEqsGraphWnd->GetItem((DWORD_PTR)item);
+
+		strValue.Format(_T("%d"), pEqItem->rect.left);
+		WritePrivateProfileString(item->getName().c_str(), _T("Left"),
+			(LPTSTR)(LPCTSTR)strValue, szFilepath);
+		strValue.Format(_T("%d"), pEqItem->rect.top);
+		WritePrivateProfileString(item->getName().c_str(), _T("Top"),
+			(LPTSTR)(LPCTSTR)strValue, szFilepath);
+	}
+}
+
+void CPageGraph2::GetItemDataFormIni(const char* pszItemName, int& left, int& top)
+{
+	char szFilepath[MAX_PATH];
+	CString strValue;
+	sprintf_s(szFilepath, MAX_PATH, "%s\\EqsGraph.ini", (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	left = GetPrivateProfileInt(pszItemName, _T("Left"), 0, szFilepath);
+	top = GetPrivateProfileInt(pszItemName, _T("Top"), 0, szFilepath);
+}
\ No newline at end of file

--
Gitblit v1.9.3