From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/CPageDataVarialbles.cpp | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 220 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPageDataVarialbles.cpp b/SourceCode/Bond/Servo/CPageDataVarialbles.cpp
new file mode 100644
index 0000000..cd68a1b
--- /dev/null
+++ b/SourceCode/Bond/Servo/CPageDataVarialbles.cpp
@@ -0,0 +1,220 @@
+锘�// CPageDataVarialbles.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "CPageDataVarialbles.h"
+#include "afxdialogex.h"
+#include "CVariableEditDlg2.h"
+
+IMPLEMENT_DYNAMIC(CPageDataVarialbles, CHMPropertyPage)
+
+CPageDataVarialbles::CPageDataVarialbles(CWnd* pParent /*=nullptr*/)
+ : CHMPropertyPage(IDD_PAGE_VARIABLE, pParent)
+{
+}
+
+CPageDataVarialbles::~CPageDataVarialbles()
+{
+}
+
+void CPageDataVarialbles::DoDataExchange(CDataExchange* pDX)
+{
+ CHMPropertyPage::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_LIST1, m_listCtrl);
+}
+
+BEGIN_MESSAGE_MAP(CPageDataVarialbles, CHMPropertyPage)
+ ON_WM_CTLCOLOR()
+ ON_WM_DESTROY()
+ ON_WM_SIZE()
+ ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CPageDataVarialbles::OnLvnItemchangedList1)
+END_MESSAGE_MAP()
+
+BOOL CPageDataVarialbles::OnInitDialog()
+{
+ CHMPropertyPage::OnInitDialog();
+
+ // 璇诲嚭鍒楀锛堢嫭绔嬬殑 ini 鍒嗚妭锛岄伩鍏嶄笌 SVID 椤甸潰鍐茬獊锛�
+ CString strIniFile, strItem;
+ strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ int width[8] = { 0, 218, 180, 180, 180, 180, 180, 180 };
+ for (int i = 0; i < 8; i++) {
+ strItem.Format(_T("Col_%d_Width"), i);
+ width[i] = GetPrivateProfileInt("PageDataVariableListCtrl", strItem, width[i], strIniFile);
+ }
+
+ DWORD dwStyle = m_listCtrl.GetExtendedStyle();
+ dwStyle |= LVS_EX_FULLROWSELECT;
+ dwStyle |= LVS_EX_GRIDLINES;
+ m_listCtrl.SetExtendedStyle(dwStyle);
+
+ HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
+ ListView_SetImageList(m_listCtrl.GetSafeHwnd(), imageList, LVSIL_SMALL);
+ m_listCtrl.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
+ m_listCtrl.InsertColumn(1, _T("DV ID"), LVCFMT_LEFT, width[1]);
+ m_listCtrl.InsertColumn(2, _T("DV Name"), LVCFMT_LEFT, width[2]);
+ m_listCtrl.InsertColumn(3, _T("DV Format"), LVCFMT_LEFT, width[3]);
+ m_listCtrl.InsertColumn(4, _T("DV Remark"), LVCFMT_LEFT, width[4]);
+
+ loadDataVariables();
+
+ return TRUE;
+}
+
+HBRUSH CPageDataVarialbles::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+ return CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
+}
+
+void CPageDataVarialbles::OnDestroy()
+{
+ CHMPropertyPage::OnDestroy();
+
+ // 淇濆瓨鍒楀
+ CString strIniFile, strItem, strTemp;
+ strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
+ for (int i = 0; i < pHeader->GetItemCount(); i++) {
+ RECT rect;
+ pHeader->GetItemRect(i, &rect);
+ strItem.Format(_T("Col_%d_Width"), i);
+ strTemp.Format(_T("%d"), rect.right - rect.left);
+ WritePrivateProfileString("PageDataVariableListCtrl", strItem, strTemp, strIniFile);
+ }
+}
+
+void CPageDataVarialbles::OnSize(UINT nType, int cx, int cy)
+{
+ CHMPropertyPage::OnSize(nType, cx, cy);
+ if (GetDlgItem(IDC_LIST1) == nullptr) return;
+
+ CRect rcClient;
+ GetClientRect(&rcClient);
+ m_listCtrl.MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24);
+}
+
+void CPageDataVarialbles::OnApply()
+{
+ __super::OnApply();
+}
+
+void CPageDataVarialbles::loadDataVariables()
+{
+ auto& dvars = theApp.m_model.m_hsmsPassive.getDataVariables();
+ for (auto item : dvars) {
+ int index = m_listCtrl.InsertItem(m_listCtrl.GetItemCount(), _T(""));
+ m_listCtrl.SetItemData(index, (DWORD_PTR)item);
+ m_listCtrl.SetItemText(index, 1, std::to_string(item->getVarialbleId()).c_str());
+ m_listCtrl.SetItemText(index, 2, item->getName().c_str());
+ m_listCtrl.SetItemText(index, 3, SERVO::CVariable::formatToString(item->getFormat()).c_str());
+ m_listCtrl.SetItemText(index, 4, item->getRemark().c_str());
+ }
+}
+
+void CPageDataVarialbles::OnCreateBtns()
+{
+ const int BTN_W = 80;
+ const int BTN_H = 28;
+ CreateBtn(_T("鏂板"), BTN_W, BTN_H, 1001);
+ CreateBtn(_T("鍒犻櫎"), BTN_W, BTN_H, 1002)->EnableWindow(FALSE);
+ CreateBtn(_T("缂栬緫"), BTN_W, BTN_H, 1003)->EnableWindow(FALSE);
+}
+
+void CPageDataVarialbles::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
+{
+ LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
+ int nSelCount = m_listCtrl.GetSelectedCount();
+
+ if (CButton* pDel = GetBtnByName("鍒犻櫎")) {
+ pDel->EnableWindow(nSelCount > 0);
+ }
+ if (CButton* pEdit = GetBtnByName("缂栬緫")) {
+ pEdit->EnableWindow(nSelCount > 0);
+ }
+
+ *pResult = 0;
+}
+
+void CPageDataVarialbles::OnClickedBtn(const char* btnName)
+{
+ ASSERT(btnName);
+ if (_strcmpi(btnName, "鏂板") == 0) {
+ int rc = UX_CanExecute(L"addVarialbles");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+ unsigned int newId = theApp.m_model.m_hsmsPassive.getMaxDataVariableId();
+ int newIdInt = static_cast<int>(newId + 1);
+ CVariableEditDlg2 dlg(_T("鏂板鏁版嵁鍙橀噺"), newIdInt, _T("U1"), _T(""), _T(""), this);
+ if (dlg.DoModal() != IDOK) return;
+ CString name = dlg.GetNameText();
+ CString fmt = dlg.GetTypeText();
+ CString remark = dlg.GetRemark();
+
+ int ret = theApp.m_model.m_hsmsPassive.addDataVariable(CT2A(name), CT2A(fmt), CT2A(remark), newIdInt);
+ if (ret == 0) {
+ UX_RecordAction(L"addVarialbles");
+ m_listCtrl.DeleteAllItems();
+ loadDataVariables();
+ }
+ else {
+ AfxMessageBox(_T("鏂板鏁版嵁鍙橀噺澶辫触锛屾牸寮忔槸鍚︽纭紵(U1/U2/I2/A20/A50/L)"));
+ }
+ }
+ else if (_strcmpi(btnName, "鍒犻櫎") == 0) {
+ POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+ if (pos == nullptr) return;
+ int nItem = m_listCtrl.GetNextSelectedItem(pos);
+ auto pVar = reinterpret_cast<SERVO::CDataVariable*>(m_listCtrl.GetItemData(nItem));
+ if (pVar == nullptr) return;
+
+ int rc = UX_CanExecute(L"delVarialbles");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+ int ret = theApp.m_model.m_hsmsPassive.deleteDataVariable(static_cast<int>(pVar->getVarialbleId()));
+ if (ret == 0) {
+ UX_RecordAction(L"delVarialbles");
+ m_listCtrl.DeleteAllItems();
+ loadDataVariables();
+ if (CButton* pDel = GetBtnByName("鍒犻櫎")) pDel->EnableWindow(FALSE);
+ if (CButton* pEdit = GetBtnByName("缂栬緫")) pEdit->EnableWindow(FALSE);
+ }
+ }
+ else if (_strcmpi(btnName, "缂栬緫") == 0) {
+ POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+ if (pos == nullptr) return;
+ int nItem = m_listCtrl.GetNextSelectedItem(pos);
+ auto pVar = reinterpret_cast<SERVO::CDataVariable*>(m_listCtrl.GetItemData(nItem));
+ if (pVar == nullptr) return;
+
+ int rc = UX_CanExecute(L"editVarialbles");
+ if (rc != 1) {
+ AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+ return;
+ }
+ CVariableEditDlg2 dlg(_T("缂栬緫鏁版嵁鍙橀噺"),
+ pVar->getVarialbleId(),
+ CString(CA2T(SERVO::CVariable::formatToString(pVar->getFormat()).c_str())),
+ CString(CA2T(pVar->getName().c_str())),
+ CString(CA2T(pVar->getRemark().c_str())),
+ this);
+ if (dlg.DoModal() != IDOK) return;
+ CString name = dlg.GetNameText();
+ CString fmt = dlg.GetTypeText();
+ CString remark = dlg.GetRemark();
+
+ int ret = theApp.m_model.m_hsmsPassive.updateDataVariable(static_cast<int>(pVar->getVarialbleId()), CT2A(name), CT2A(fmt), CT2A(remark));
+ if (ret == 0) {
+ UX_RecordAction(L"editVarialbles");
+ m_listCtrl.DeleteAllItems();
+ loadDataVariables();
+ }
+ else {
+ AfxMessageBox(_T("缂栬緫鏁版嵁鍙橀噺澶辫触锛屾牸寮忔槸鍚︽纭紵(U1/U2/I2/A20/A50/L)"));
+ }
+ }
+}
--
Gitblit v1.9.3