From f4e3d35dd0f912c303b13b48a4a3fc09ccb0a845 Mon Sep 17 00:00:00 2001
From: darker <mr.darker@163.com>
Date: 星期二, 18 二月 2025 17:57:40 +0800
Subject: [PATCH] 1. 遍历设备类的属性,并显示在界面上

---
 SourceCode/Bond/Servo/DevicePropertyDlg.h   |   28 ++++++++++++++
 SourceCode/Bond/Servo/DevicePropertyDlg.cpp |   79 +++++++++++++++++++++++++++++++++++++++
 SourceCode/Bond/Servo/CEquipment.cpp        |    9 ++++
 SourceCode/Bond/Servo/CEquipment.h          |    1 
 4 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 2101fc0..b18b34b 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -24,6 +24,15 @@
 		m_listener.onCimStateChanged = listener.onCimStateChanged;
 	}
 
+	void CEquipment::getProperties(std::vector<std::pair<std::string, std::string>>& container)
+	{
+		container.clear();
+		// 示例:将一些属性添加到容器
+		container.push_back(std::make_pair("DeviceName", "ServoMotor"));
+		container.push_back(std::make_pair("SerialNumber", "123456789"));
+		container.push_back(std::make_pair("Version", "1.0"));
+	}
+
 	void CEquipment::init()
 	{
 
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 3799c16..7c699e3 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -51,6 +51,7 @@
 		MemoryBlock& getReadBitBlock();
 		void setWriteBitBlock(unsigned int start, unsigned int end);
 		MemoryBlock& getWriteBitBlock();
+		void getProperties(std::vector<std::pair<std::string, std::string>>& container);
 		virtual void init();
 		virtual void term();
 		virtual void onTimer(UINT nTimerid);
diff --git a/SourceCode/Bond/Servo/DevicePropertyDlg.cpp b/SourceCode/Bond/Servo/DevicePropertyDlg.cpp
new file mode 100644
index 0000000..82f4c6f
--- /dev/null
+++ b/SourceCode/Bond/Servo/DevicePropertyDlg.cpp
@@ -0,0 +1,79 @@
+锘�// CDevicePropertyDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "afxdialogex.h"
+#include "DevicePropertyDlg.h"
+
+// CDevicePropertyDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CDevicePropertyDlg, CDialogEx)
+
+CDevicePropertyDlg::CDevicePropertyDlg(CWnd* pParent /*=nullptr*/, int nDeviceID /*=0*/)
+	: CDialogEx(IDD_DIALOG_DEVICE_PROPERTY, pParent), m_nDeviceID(nDeviceID)
+{
+
+}
+
+CDevicePropertyDlg::~CDevicePropertyDlg()
+{
+}
+
+void CDevicePropertyDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CDialogEx::DoDataExchange(pDX);
+	DDX_Control(pDX, IDC_LIST_DEVICE_PROPERTY, m_listDeviceProperties);
+}
+
+
+BEGIN_MESSAGE_MAP(CDevicePropertyDlg, CDialogEx)
+END_MESSAGE_MAP()
+
+
+// CDevicePropertyDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CDevicePropertyDlg::OnInitDialog()
+{
+	CDialogEx::OnInitDialog();
+
+	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+	SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(m_nDeviceID);
+	if (nullptr == pEquipment) {
+		LOGI("<璁惧ID锛�%d>鑾峰彇璁惧灞炴�уけ璐ャ��", m_nDeviceID);
+		return FALSE;
+	}
+
+	// 淇敼瀵硅瘽妗嗘爣棰�
+	std::string strDeviceName = pEquipment->getName();
+	SetWindowText(CString(strDeviceName.c_str()));
+
+	// 鑾峰彇鎵�鏈夎澶囧睘鎬�
+	std::vector<std::pair<std::string, std::string>> properties;
+	pEquipment->getProperties(properties);
+
+	// 鑾峰彇ListCtrl鐨勫鎴峰尯鍩�
+	CRect rect;
+	m_listDeviceProperties.GetClientRect(&rect);  
+	int nTotalWidth = rect.Width();
+
+	int nColumnWidth = 150;
+	m_listDeviceProperties.InsertColumn(0, _T("鍚嶇О"), LVCFMT_LEFT, nColumnWidth);
+	m_listDeviceProperties.InsertColumn(1, _T("鍊�"), LVCFMT_LEFT, nColumnWidth);
+
+	// 閬嶅巻瀹瑰櫒涓殑鎵�鏈夊睘鎬у苟杈撳嚭
+	int nItem = 0;
+	for (const auto& property : properties) {
+		// 鎻掑叆璁惧灞炴��
+		m_listDeviceProperties.InsertItem(nItem, property.first.c_str());
+		m_listDeviceProperties.SetItemText(nItem, 1, property.second.c_str());
+		++nItem;
+	}
+
+	// 璁剧疆绗簩鍒楀搴�
+	m_listDeviceProperties.SetColumnWidth(1, nTotalWidth - nColumnWidth);
+
+	return TRUE;  // return TRUE unless you set the focus to a control
+	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
diff --git a/SourceCode/Bond/Servo/DevicePropertyDlg.h b/SourceCode/Bond/Servo/DevicePropertyDlg.h
new file mode 100644
index 0000000..39bdec3
--- /dev/null
+++ b/SourceCode/Bond/Servo/DevicePropertyDlg.h
@@ -0,0 +1,28 @@
+锘�#pragma once
+#include "afxdialogex.h"
+
+
+// CDevicePropertyDlg 瀵硅瘽妗�
+
+class CDevicePropertyDlg : public CDialogEx
+{
+	DECLARE_DYNAMIC(CDevicePropertyDlg)
+
+public:
+	CDevicePropertyDlg(CWnd* pParent = nullptr, int nDeviceID = 0);   // 鏍囧噯鏋勯�犲嚱鏁�
+	virtual ~CDevicePropertyDlg();
+
+// 瀵硅瘽妗嗘暟鎹�
+#ifdef AFX_DESIGN_TIME
+	enum { IDD = IDD_DIALOG_DEVICE_PROPERTY };
+#endif
+
+protected:
+	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 鏀寔
+	virtual BOOL OnInitDialog();
+	DECLARE_MESSAGE_MAP()
+
+private:
+	int m_nDeviceID;
+	CListCtrl m_listDeviceProperties;
+};

--
Gitblit v1.9.3