From 66786f85648c3c81b932decba339ffb359a7bf25 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期一, 25 十一月 2024 17:46:56 +0800
Subject: [PATCH] 1.完成初版轴管理类 2.实现基本的轴设定界面的交互

---
 SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 223 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index e83a616..2079bf2 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -48,6 +48,41 @@
 	DDX_Control(pDX, IDC_STATIC_AXIS_TEST_READY, m_staticReady);
 	DDX_Control(pDX, IDC_STATIC_AXIS_TEST_BUSY, m_staticBusy);
 	DDX_Control(pDX, IDC_STATIC_AXIS_TEST_ERR, m_staticErr);
+	DDX_Control(pDX, IDC_COMBO_AXIS_NAME, m_comboAxisNO);
+	DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO);
+	DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription);
+	DDX_Control(pDX, IDC_STATIC_START_ADDRESS, m_staticStartAddress);
+	DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_POS, m_editManualSpeed);
+	DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_AUTO_SPEED, m_editAutoSpeed);
+	DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_ACCE_TIME, m_editAccelerationTime);
+	DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_DECE_TIME, m_editDecelerationTime);
+	DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_MICROMENTUM, m_editJogDistance);
+}
+
+UINT CAxisSettingsDlg::FindIDByName(const CString& strControlID)
+{
+	// 灏嗚祫婧愭枃浠朵腑瀹氫箟鐨勬帶浠跺悕绉板拰 ID 鍔犺浇鍒颁竴涓槧灏勪腑
+	static const std::map<CString, UINT> controlIdMap = {
+		{"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP1", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP1},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP2", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP2},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP3", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP3},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP4", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP4},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP5", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP5},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT1", IDC_EDIT_AXIS_ANCHOR_POINT1},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT2", IDC_EDIT_AXIS_ANCHOR_POINT2},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT3", IDC_EDIT_AXIS_ANCHOR_POINT3},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT4", IDC_EDIT_AXIS_ANCHOR_POINT4},
+		{"IDC_EDIT_AXIS_ANCHOR_POINT5", IDC_EDIT_AXIS_ANCHOR_POINT5}
+		// 鍙互缁х画娣诲姞鍏朵粬鎺т欢鍚嶇О鍜� ID
+	};
+
+	// 鏌ユ壘鎺т欢鍚嶇О鏄惁鍦ㄦ槧灏勪腑
+	auto it = controlIdMap.find(strControlID);
+	if (it != controlIdMap.end()) {
+		return it->second;
+	}
+
+	return 0;
 }
 
 CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize)
@@ -155,6 +190,128 @@
 	label.UpdateWindow();            // 绔嬪嵆鍒锋柊
 }
 
+void CAxisSettingsDlg::initializeAxisIDCombo()
+{
+	// 鑾峰彇鎵�鏈夎酱鐨勮酱NO
+	auto axisNumbers = AxisManager::getInstance().getUsedAxisIds();
+
+	// 娓呯┖涓嬫媺妗�
+	m_comboAxisNO.ResetContent();
+
+	// 濉厖鏁版嵁鍒颁笅鎷夋
+	for (const auto& axisID : axisNumbers) {
+		CString axisCString;
+		axisCString.Format(_T("%d"), axisID);
+		m_comboAxisNO.AddString(axisCString);
+	}
+
+	// 榛樿閫夋嫨绗竴椤�
+	if (m_comboAxisNO.GetCount() > 0) {
+		m_comboAxisNO.SetCurSel(0);
+	}
+}
+
+void CAxisSettingsDlg::refreshAxisDetails()
+{
+	// 鑾峰彇褰撳墠閫変腑鐨勮酱ID
+	int currentIndex = m_comboAxisNO.GetCurSel();
+	if (currentIndex == CB_ERR) {
+		AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
+		return;
+	}
+
+	CString axisIDStr;
+	m_comboAxisNO.GetLBText(currentIndex, axisIDStr);
+	int axisId = _ttoi(axisIDStr);
+
+	// 鑾峰彇杞翠俊鎭�
+	auto axisDetails = AxisManager::getInstance().getAxis(axisId);
+	if (axisDetails.empty()) {
+		AfxMessageBox(_T("鏈壘鍒拌酱淇℃伅锛�"));
+		return;
+	}
+
+	// 鏍煎紡鍖栨诞鐐规暟涓� 3 浣嶅皬鏁扮殑 CString
+	auto formatDouble = [](const std::string& value) -> CString {
+		char buffer[32];
+		snprintf(buffer, sizeof(buffer), "%.3f", std::stod(value));
+		return CString(buffer);
+	};
+
+	// 鍒锋柊鐣岄潰鎺т欢鏁版嵁
+	m_staticAxisNO.SetWindowText(CString(axisDetails[1].c_str()));			// 杞碞O
+	m_staticAxisDescription.SetWindowText(CString(axisDetails[2].c_str())); // 杞存弿杩�
+	m_staticStartAddress.SetWindowText(CString(axisDetails[3].c_str()));	// 璧峰鍦板潃
+	m_editJogDistance.SetWindowText(formatDouble(axisDetails[4]));			// 寰姩閲�
+	m_editManualSpeed.SetWindowText(formatDouble(axisDetails[5]));			// 鎵嬪姩閫熷害
+	m_editAutoSpeed.SetWindowText(formatDouble(axisDetails[8]));			// 鑷姩閫熷害
+	m_editAccelerationTime.SetWindowText(formatDouble(axisDetails[11]));	// 鍔犻�熸椂闂�
+	m_editDecelerationTime.SetWindowText(formatDouble(axisDetails[12]));	// 鍑忛�熸椂闂�
+}
+
+void CAxisSettingsDlg::refreshPositionDetails(int pageNumber)
+{
+	// 姣忛〉鏄剧ず鐨勫畾浣嶇偣鏁伴噺
+	const int pageSize = 5;
+
+	// 鑾峰彇褰撳墠閫変腑鐨勮酱ID
+	int currentIndex = m_comboAxisNO.GetCurSel();
+	if (currentIndex == CB_ERR) {
+		AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
+		return;
+	}
+
+	CString axisIDStr;
+	m_comboAxisNO.GetLBText(currentIndex, axisIDStr);
+	int axisId = _ttoi(axisIDStr);
+
+	// 鑾峰彇瀹氫綅鐐规暟鎹�
+	auto positions = AxisManager::getInstance().getPositions(axisId, pageNumber, pageSize);
+
+	for (int i = 0; i < pageSize; ++i) {
+		// 鍔ㄦ�佹瀯閫犳帶浠跺悕绉�
+		CString descriptionName;
+		CString positionName;
+
+		// IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP1;
+		// IDC_EDIT_AXIS_ANCHOR_POINT1;
+		descriptionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
+		positionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
+
+		// 鑾峰彇鎺т欢鎸囬拡
+		UINT unDescription = FindIDByName(descriptionName);
+		UINT unPosition = FindIDByName(positionName);
+
+		TRACE("CAxisSettingsDlg::refreshPositionDetails %unDescription[%d], unPosition[%d]\n", unDescription, unPosition);
+		if (unDescription == 0 || unPosition == 0) {
+			continue;
+		}
+
+		CWnd* pDescription = GetDlgItem(unDescription);
+		CWnd* pPosition = GetDlgItem(unPosition);
+
+		if (i < positions.size() 
+			&& !positions[i][2].empty()
+			&& !positions[i][3].empty()) {
+			// 鏈夋暟鎹紝鍒锋柊鎻忚堪鍜屼綅缃�
+			CString description = CString(positions[i][2].c_str()); // 瀹氫綅鐐规弿杩�
+			CString positionValue;
+
+			// 淇濈暀3浣嶅皬鏁�
+			char buffer[32];
+			snprintf(buffer, sizeof(buffer), "%.3f", std::stod(positions[i][3]));
+			positionValue = CString(buffer);
+
+			if (pDescription) pDescription->SetWindowText(description);
+			if (pPosition) pPosition->SetWindowText(positionValue);
+		}
+		else {
+			// 鏃犳暟鎹紝娓呯┖鎺т欢鍐呭
+			if (pDescription) pDescription->SetWindowText(_T(""));
+			if (pPosition) pPosition->SetWindowText(_T(""));
+		}
+	}
+}
 
 BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx)
 	ON_BN_CLICKED(IDC_BUTTON_AXIS_LAST, &CAxisSettingsDlg::OnBnClickedButtonAxisLast)
@@ -173,6 +330,7 @@
 	ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_JOG_ADD, &CAxisSettingsDlg::OnBnClickedButtonAxisTestJogAdd)
 	ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_JOG_SUB, &CAxisSettingsDlg::OnBnClickedButtonAxisTestJogSub)
 	ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_STOP, &CAxisSettingsDlg::OnBnClickedButtonAxisTestStop)
+	ON_CBN_SELCHANGE(IDC_COMBO_AXIS_NAME, &CAxisSettingsDlg::OnSelchangeComboAxisName)
 	ON_WM_SIZE()
 	ON_WM_CTLCOLOR()
 	ON_WM_SIZING()
@@ -198,6 +356,17 @@
 		pLabel->SetTextColor(RGB(255, 255, 255));
 		pLabel->SetAlignment(AlignCenter);
 		pLabel->SetDynamicFont(TRUE);
+	}
+
+	try {
+		initializeAxisIDCombo();
+		refreshAxisDetails();
+		refreshPositionDetails(1);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒濆鍖栨帶浠跺け璐ワ細%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
 	}
 
 	CRect screenRect, dlgRect, clientRect;
@@ -306,26 +475,66 @@
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshPositionDetails(1);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊瀹氫綅缁�1澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshPositionDetails(2);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊瀹氫綅缁�2澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshPositionDetails(3);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊瀹氫綅缁�3澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup4()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshPositionDetails(4);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊瀹氫綅缁�4澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup5()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshPositionDetails(5);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊瀹氫綅缁�5澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint1()
@@ -373,6 +582,20 @@
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 }
 
+void CAxisSettingsDlg::OnSelchangeComboAxisName()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	try {
+		refreshAxisDetails();
+		refreshPositionDetails(1);
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("鍒锋柊鎺т欢澶辫触锛�%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+	}
+}
+
 void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent)
 {
 	if (TIMER_READ_PLC_DATA == nIDEvent) {

--
Gitblit v1.9.3