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.h | 14 ++
SourceCode/Bond/BondEq/BondEq.rc | 0
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++++
SourceCode/Bond/BondEq/stdafx.h | 1
SourceCode/Bond/BondEq/BondEqDlg.cpp | 27 +++++
SourceCode/Bond/x64/Debug/Config/BondEq.db | 0
SourceCode/Bond/BondEq/BondEq.vcxproj | 2
7 files changed, 265 insertions(+), 2 deletions(-)
diff --git a/SourceCode/Bond/BondEq/BondEq.rc b/SourceCode/Bond/BondEq/BondEq.rc
index 6d09a5f..156b4c1 100644
--- a/SourceCode/Bond/BondEq/BondEq.rc
+++ b/SourceCode/Bond/BondEq/BondEq.rc
Binary files differ
diff --git a/SourceCode/Bond/BondEq/BondEq.vcxproj b/SourceCode/Bond/BondEq/BondEq.vcxproj
index 1cc2cf9..dbd0af1 100644
--- a/SourceCode/Bond/BondEq/BondEq.vcxproj
+++ b/SourceCode/Bond/BondEq/BondEq.vcxproj
@@ -217,6 +217,7 @@
<ClInclude Include="Common.h" />
<ClInclude Include="Configuration.h" />
<ClInclude Include="CPanelProject.h" />
+ <ClInclude Include="DBManager\AxisManager.h" />
<ClInclude Include="DBManager\SystemLogManager.h" />
<ClInclude Include="DBManager\UserManager.h" />
<ClInclude Include="EQState.h" />
@@ -280,6 +281,7 @@
<ClCompile Include="CProjectPageRemoteEqs.cpp" />
<ClCompile Include="Configuration.cpp" />
<ClCompile Include="CPanelProject.cpp" />
+ <ClCompile Include="DBManager\AxisManager.cpp" />
<ClCompile Include="DBManager\SystemLogManager.cpp" />
<ClCompile Include="DBManager\UserManager.cpp" />
<ClCompile Include="EQState.cpp" />
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index c9a019f..0fb1060 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -191,13 +191,36 @@
// 初始化运行日志表
try {
if (!logManager.initializeLogTable()) {
- AfxMessageBox("初始化系统日志表失败!");
+ AfxMessageBox("初始化系统日志模块失败!");
return FALSE;
}
}
catch (const std::exception& ex) {
CString errorMsg;
- errorMsg.Format(_T("初始化系统日志表失败:%s"), CString(ex.what()));
+ errorMsg.Format(_T("初始化系统日志模块失败:%s"), CString(ex.what()));
+ AfxMessageBox(errorMsg, MB_ICONERROR);
+ return FALSE;
+ }
+
+ // 设置轴设定模块的数据库连接
+ AxisManager& axisManager = AxisManager::getInstance();
+ axisManager.setDatabase(db.get());
+
+ // 初始化轴设定表
+ try {
+ if (!axisManager.initializeTables()) {
+ AfxMessageBox("创建轴设定表失败!");
+ return FALSE;
+ }
+
+ if (!axisManager.initializeDefaultData()) {
+ AfxMessageBox("初始化轴设定默认数据失败!");
+ return FALSE;
+ }
+ }
+ catch (const std::exception& ex) {
+ CString errorMsg;
+ errorMsg.Format(_T("初始化轴设定模块失败:%s"), CString(ex.what()));
AfxMessageBox(errorMsg, MB_ICONERROR);
return FALSE;
}
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) {
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
index d8bb7f4..6948423 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
@@ -22,12 +22,16 @@
#endif
private:
+ UINT FindIDByName(const CString& strControlID);
CFont* GetOrCreateFont(int nFontSize);
void SetDefaultFont();
void AdjustControls(float dScaleX, float dScaleY);
void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight);
void AdjustLabelFont(CBLLabel& label);
void SetStatusColor(CBLLabel& label, BOOL bStatus);
+ void initializeAxisIDCombo();
+ void refreshAxisDetails();
+ void refreshPositionDetails(int pageNumber);
private:
CPLC* m_pPLC;
@@ -41,6 +45,15 @@
CBLLabel m_staticReady;
CBLLabel m_staticBusy;
CBLLabel m_staticErr;
+ CComboBox m_comboAxisNO;
+ CStatic m_staticAxisNO;
+ CStatic m_staticAxisDescription;
+ CStatic m_staticStartAddress;
+ CEdit m_editManualSpeed;
+ CEdit m_editAutoSpeed;
+ CEdit m_editAccelerationTime;
+ CEdit m_editDecelerationTime;
+ CEdit m_editJogDistance;
std::map<int, CRect> m_mapCtrlLayouts;
std::map<int, CFont*> m_mapFonts;
@@ -66,6 +79,7 @@
afx_msg void OnBnClickedButtonAxisTestJogAdd();
afx_msg void OnBnClickedButtonAxisTestJogSub();
afx_msg void OnBnClickedButtonAxisTestStop();
+ afx_msg void OnSelchangeComboAxisName();
afx_msg void OnTimer(UINT_PTR nIDEvent);
DECLARE_MESSAGE_MAP()
};
diff --git a/SourceCode/Bond/BondEq/stdafx.h b/SourceCode/Bond/BondEq/stdafx.h
index c82164e..4dfdbf0 100644
--- a/SourceCode/Bond/BondEq/stdafx.h
+++ b/SourceCode/Bond/BondEq/stdafx.h
@@ -49,6 +49,7 @@
// 单例模式的数据库管理类
#include "UserManager.h"
+#include "AxisManager.h"
#include "SystemLogManager.h"
// 控件样式
diff --git a/SourceCode/Bond/x64/Debug/Config/BondEq.db b/SourceCode/Bond/x64/Debug/Config/BondEq.db
index 0f9a419..8c0d81b 100644
--- a/SourceCode/Bond/x64/Debug/Config/BondEq.db
+++ b/SourceCode/Bond/x64/Debug/Config/BondEq.db
Binary files differ
--
Gitblit v1.9.3