From 893975d8197b1ed7241ca630490f8f6b3f7d32ea Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期二, 26 十一月 2024 14:54:28 +0800
Subject: [PATCH] 1. 轴设定界面基本完成 2.轴设定不保存数据库,而是保存.xml文件
---
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 275 +++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 216 insertions(+), 59 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index 5cdc22f..9f17adf 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -39,6 +39,11 @@
m_pPLC = pPLC;
}
+void CAxisSettingsDlg::SetRecipeName(const CString& strRecipeName)
+{
+ m_strRecipeName = strRecipeName;
+}
+
void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
@@ -57,6 +62,11 @@
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);
+ DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, m_pageButtons[0]);
+ DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, m_pageButtons[1]);
+ DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, m_pageButtons[2]);
+ DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, m_pageButtons[3]);
+ DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, m_pageButtons[4]);
}
UINT CAxisSettingsDlg::FindIDByName(const CString& strControlID)
@@ -190,6 +200,20 @@
label.UpdateWindow(); // 绔嬪嵆鍒锋柊
}
+void CAxisSettingsDlg::updatePageButtonStates()
+{
+ for (int i = 0; i < 5; ++i) {
+ if (i + 1 == m_currentPage) {
+ m_pageButtons[i].SetFaceColor(RGB(0, 122, 204)); // 閫変腑鑳屾櫙鑹诧紙钃濊壊锛�
+ }
+ else {
+ m_pageButtons[i].SetFaceColor(RGB(240, 240, 240)); // 榛樿鑳屾櫙鑹�
+ }
+
+ m_pageButtons[i].Invalidate();
+ }
+}
+
int CAxisSettingsDlg::getCurrentSelectedAxisID()
{
int currentIndex = m_comboAxisNO.GetCurSel();
@@ -205,8 +229,15 @@
void CAxisSettingsDlg::initializeAxisIDCombo()
{
- // 鑾峰彇鎵�鏈夎酱鐨勮酱NO
- auto axisNumbers = AxisManager::getInstance().getUsedAxisIds();
+ // 妫�鏌ラ厤鏂规槸鍚﹀姞杞芥垚鍔�
+ RecipeManager& recipeManager = RecipeManager::getInstance();
+ if (m_strRecipeName.IsEmpty() || !recipeManager.loadRecipe(std::string(CT2A(m_strRecipeName)))) {
+ AfxMessageBox(_T("鍔犺浇閰嶆柟澶辫触锛�"));
+ return;
+ }
+
+ // 鑾峰彇鎵�鏈夎酱鐨勭紪鍙�
+ auto axisNumbers = recipeManager.getAllAxisID();
// 娓呯┖涓嬫媺妗�
m_comboAxisNO.ResetContent();
@@ -227,85 +258,70 @@
void CAxisSettingsDlg::refreshAxisDetails()
{
// 鑾峰彇褰撳墠閫変腑鐨勮酱ID
+ RecipeManager& recipeManager = RecipeManager::getInstance();
int axisId = getCurrentSelectedAxisID();
- // 鑾峰彇杞翠俊鎭�
- auto axisDetails = AxisManager::getInstance().getAxis(axisId);
- if (axisDetails.empty()) {
+ auto axisDetails = recipeManager.getAxis(axisId);
+ if (axisDetails.id == -1 || axisDetails.startAddress.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);
- };
+ auto formatDouble = [](double value) -> CString {
+ CString str;
+ str.Format(_T("%.3f"), value);
+ return str;
+ };
- // 鍒锋柊鐣岄潰鎺т欢鏁版嵁
- 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])); // 鍑忛�熸椂闂�
+ // 鏇存柊鎺т欢鏄剧ず
+ m_staticAxisNO.SetWindowText(CString(axisDetails.number.c_str())); // 杞寸紪鍙�
+ m_staticAxisDescription.SetWindowText(CString(axisDetails.description.c_str())); // 杞存弿杩�
+ m_staticStartAddress.SetWindowText(CString(axisDetails.startAddress.c_str())); // 璧峰鍦板潃
+ m_editJogDistance.SetWindowText(formatDouble(axisDetails.jogDistance)); // 寰姩閲�
+ m_editManualSpeed.SetWindowText(formatDouble(axisDetails.manualSpeed)); // 鎵嬪姩閫熷害
+ m_editAutoSpeed.SetWindowText(formatDouble(axisDetails.autoSpeed)); // 鑷姩閫熷害
+ m_editAccelerationTime.SetWindowText(formatDouble(axisDetails.accelerationTime)); // 鍔犻�熸椂闂�
+ m_editDecelerationTime.SetWindowText(formatDouble(axisDetails.decelerationTime)); // 鍑忛�熸椂闂�
}
void CAxisSettingsDlg::refreshPositionDetails(int pageNumber)
{
+ RecipeManager& recipeManager = RecipeManager::getInstance();
// 姣忛〉鏄剧ず鐨勫畾浣嶇偣鏁伴噺
const int pageSize = 5;
// 鑾峰彇褰撳墠閫変腑鐨勮酱ID
int axisId = getCurrentSelectedAxisID();
+ if (axisId == -1) {
+ return;
+ }
// 鑾峰彇瀹氫綅鐐规暟鎹�
- auto positions = AxisManager::getInstance().getPositions(axisId, pageNumber, pageSize);
+ auto positions = recipeManager.getPositions(axisId, pageNumber, pageSize);
+ // 鍒锋柊 UI
for (int i = 0; i < pageSize; ++i) {
- // 鍔ㄦ�佹瀯閫犳帶浠跺悕绉�
- CString descriptionName;
- CString positionName;
+ CString descriptionCtrlName, positionCtrlName;
+ descriptionCtrlName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
+ positionCtrlName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
- // 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 descriptionCtrlId = FindIDByName(descriptionCtrlName);
+ UINT positionCtrlId = FindIDByName(positionCtrlName);
- // 鑾峰彇鎺т欢鎸囬拡
- UINT unDescription = FindIDByName(descriptionName);
- UINT unPosition = FindIDByName(positionName);
+ CWnd* pDescriptionCtrl = GetDlgItem(descriptionCtrlId);
+ CWnd* pPositionCtrl = GetDlgItem(positionCtrlId);
- TRACE("CAxisSettingsDlg::refreshPositionDetails %unDescription[%d], unPosition[%d]\n", unDescription, unPosition);
- if (unDescription == 0 || unPosition == 0) {
- continue;
- }
+ if (i < positions.size()) {
+ CString description = CString(positions[i].first.c_str());
+ CString value;
+ value.Format(_T("%.3f"), positions[i].second);
- 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);
+ if (pDescriptionCtrl) pDescriptionCtrl->SetWindowText(description);
+ if (pPositionCtrl) pPositionCtrl->SetWindowText(value);
}
else {
- // 鏃犳暟鎹紝娓呯┖鎺т欢鍐呭
- if (pDescription) pDescription->SetWindowText(_T(""));
- if (pPosition) pPosition->SetWindowText(_T(""));
+ if (pDescriptionCtrl) pDescriptionCtrl->SetWindowText(_T(""));
+ if (pPositionCtrl) pPositionCtrl->SetWindowText(_T(""));
}
}
}
@@ -328,7 +344,64 @@
m_comboAxisNO.SetCurSel(newIndex);
refreshAxisDetails();
- refreshPositionDetails(1);
+ refreshPositionDetails(m_currentPage);
+ updatePageButtonStates();
+}
+
+void CAxisSettingsDlg::updateDataFromUI()
+{
+ const int pageSize = 5; // 姣忛〉鏄剧ず 5 涓畾浣嶇偣
+
+ // 鑾峰彇褰撳墠閫変腑鐨勮酱 ID
+ int axisId = getCurrentSelectedAxisID();
+ if (axisId == -1) return;
+
+ RecipeManager& recipeManager = RecipeManager::getInstance();
+ auto axisData = recipeManager.getAxis(axisId);
+
+ // 鑾峰彇鐣岄潰涓婄殑淇敼鍙傛暟
+ CString text;
+ m_editManualSpeed.GetWindowText(text);
+ axisData.manualSpeed = _ttof(text);
+
+ m_editAutoSpeed.GetWindowText(text);
+ axisData.autoSpeed = _ttof(text);
+
+ m_editAccelerationTime.GetWindowText(text);
+ axisData.accelerationTime = _ttof(text);
+
+ m_editDecelerationTime.GetWindowText(text);
+ axisData.decelerationTime = _ttof(text);
+
+ m_editJogDistance.GetWindowText(text);
+ axisData.jogDistance = _ttof(text);
+
+ // 鏇存柊瀹氫綅鐐规暟鎹�
+ for (int i = 0; i < pageSize; ++i) {
+ int index = (m_currentPage - 1) * pageSize + i;
+
+ if (index < axisData.positions.size()) {
+ CString descriptionName, positionName;
+ descriptionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
+ positionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
+
+ CEdit* pDescriptionEdit = (CEdit*)GetDlgItem(FindIDByName(descriptionName));
+ CEdit* pPositionEdit = (CEdit*)GetDlgItem(FindIDByName(positionName));
+
+ if (pDescriptionEdit && pPositionEdit) {
+ CString description, positionValue;
+ pDescriptionEdit->GetWindowText(description);
+ pPositionEdit->GetWindowText(positionValue);
+
+ // 鏇存柊 RecipeManager 涓殑鏁版嵁
+ axisData.positions[index].first = CT2A(description);
+ axisData.positions[index].second = _ttof(positionValue);
+ }
+ }
+ }
+
+ // 淇濆瓨鍥� RecipeManager
+ recipeManager.updateAxis(axisData);
}
BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx)
@@ -349,6 +422,7 @@
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_BN_CLICKED(IDC_BUTTON_AXIS_SAVE, &CAxisSettingsDlg::OnBnClickedButtonAxisSave)
ON_WM_SIZE()
ON_WM_CTLCOLOR()
ON_WM_SIZING()
@@ -364,7 +438,9 @@
CDialogEx::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
- SetWindowText(_T("Axis璁惧畾"));
+ CString strTitle;
+ strTitle.Format(_T("Axis璁惧畾(閰嶆柟: %s)"), m_strRecipeName);
+ SetWindowText(strTitle);
// 璁剧疆娴嬭瘯鐘舵��
CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr };
@@ -376,10 +452,14 @@
pLabel->SetDynamicFont(TRUE);
}
+ // 鍒濆鍖栧綋鍓嶉〉闈负绗竴椤�
+ m_currentPage = 1;
+ updatePageButtonStates();
+
try {
initializeAxisIDCombo();
refreshAxisDetails();
- refreshPositionDetails(1);
+ refreshPositionDetails(m_currentPage);
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -454,6 +534,28 @@
for (auto pLabel : pLabels) {
AdjustLabelFont(*pLabel);
}
+
+ // 璋冩暣涓嬫媺妗嗛珮搴�
+ CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_AXIS_NAME);
+ CButton* pButtonLeft = (CButton*)GetDlgItem(IDC_BUTTON_AXIS_LAST);
+ CButton* pButtonRight = (CButton*)GetDlgItem(IDC_BUTTON_AXIS_NEXT);
+
+ if (pComboBox && pButtonLeft && pButtonRight) {
+ CRect rectButton;
+ pButtonLeft->GetWindowRect(&rectButton); // 鑾峰彇鎸夐挳灏哄
+ ScreenToClient(&rectButton); // 杞崲涓哄鎴风鍧愭爣
+
+ CRect rectComboBox;
+ pComboBox->GetWindowRect(&rectComboBox);
+ ScreenToClient(&rectComboBox);
+
+ // 璋冩暣涓嬫媺妗嗛珮搴�
+ int heightAdjustment = 2;
+ rectComboBox.top = rectButton.top;
+ rectComboBox.bottom = rectButton.bottom + heightAdjustment;
+ pComboBox->MoveWindow(&rectComboBox);
+ pComboBox->SetItemHeight(-1, rectButton.Height() - 6);
+ }
}
void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect)
@@ -510,7 +612,14 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
+ if (m_currentPage == 1) {
+ return;
+ }
+ updateDataFromUI();
+
+ m_currentPage = 1;
refreshPositionDetails(1);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -523,7 +632,14 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
+ if (m_currentPage == 2) {
+ return;
+ }
+ updateDataFromUI();
+
+ m_currentPage = 2;
refreshPositionDetails(2);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -536,7 +652,14 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
+ if (m_currentPage == 3) {
+ return;
+ }
+ updateDataFromUI();
+
+ m_currentPage = 3;
refreshPositionDetails(3);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -549,7 +672,14 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
+ if (m_currentPage == 4) {
+ return;
+ }
+ updateDataFromUI();
+
+ m_currentPage = 4;
refreshPositionDetails(4);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -562,7 +692,14 @@
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
+ if (m_currentPage == 5) {
+ return;
+ }
+ updateDataFromUI();
+
+ m_currentPage = 5;
refreshPositionDetails(5);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -621,7 +758,8 @@
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
try {
refreshAxisDetails();
- refreshPositionDetails(1);
+ refreshPositionDetails(m_currentPage);
+ updatePageButtonStates();
}
catch (const std::exception& ex) {
CString errorMsg;
@@ -630,6 +768,25 @@
}
}
+void CAxisSettingsDlg::OnBnClickedButtonAxisSave()
+{
+ // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+ CString cstrMessage;
+ cstrMessage.Format(_T("鏄惁淇濆瓨杞� [%d] 鍙傛暟锛�"), getCurrentSelectedAxisID());
+ int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION);
+ if (ret != IDOK) {
+ return;
+ }
+
+ updateDataFromUI();
+ if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) {
+ AfxMessageBox(_T("淇濆瓨鎴愬姛锛�"));
+ }
+ else {
+ AfxMessageBox(_T("淇濆瓨澶辫触锛�"));
+ }
+}
+
void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent)
{
if (TIMER_READ_PLC_DATA == nIDEvent) {
--
Gitblit v1.9.3