From 102c26b397f7466779f712c31752973e17a195f6 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 04 三月 2025 14:56:15 +0800
Subject: [PATCH] 1.增加属性值列表展示面板。
---
SourceCode/Bond/Servo/Servo.vcxproj | 2
SourceCode/Bond/Servo/Servo.vcxproj.filters | 2
SourceCode/Bond/Servo/resource.h | 0
SourceCode/Bond/Servo/CPanelMaster.h | 5 +
SourceCode/Bond/Servo/Servo.rc | 0
SourceCode/Bond/Servo/CPanelMaster.cpp | 27 +++++
SourceCode/Bond/Servo/CPanelAttributes.h | 38 +++++++
SourceCode/Bond/Servo/ServoDlg.cpp | 24 ++++
SourceCode/Bond/Servo/CPanelAttributes.cpp | 165 +++++++++++++++++++++++++++++++++
SourceCode/Bond/Servo/Common.h | 9 +
SourceCode/Bond/Servo/ServoDlg.h | 2
11 files changed, 271 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPanelAttributes.cpp b/SourceCode/Bond/Servo/CPanelAttributes.cpp
new file mode 100644
index 0000000..ef815ae
--- /dev/null
+++ b/SourceCode/Bond/Servo/CPanelAttributes.cpp
@@ -0,0 +1,165 @@
+锘�// CPanelAttributes.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "CPanelAttributes.h"
+#include "afxdialogex.h"
+#include "common.h"
+#include "VerticalLine.h"
+
+
+// CPanelAttributes 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CPanelAttributes, CDialogEx)
+
+CPanelAttributes::CPanelAttributes(CWnd* pParent /*=nullptr*/)
+ : CDialogEx(IDD_PANEL_ATTRIBUTES, pParent)
+{
+ m_crBkgnd = PANEL_ATTRIBUTES_BACKGROUND_COLOR;
+ m_hbrBkgnd = nullptr;
+ m_nPanelWidth = 188;
+}
+
+CPanelAttributes::~CPanelAttributes()
+{
+}
+
+void CPanelAttributes::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_MFCPROPERTYGRID1, m_gridCtrl);
+}
+
+
+BEGIN_MESSAGE_MAP(CPanelAttributes, CDialogEx)
+ ON_WM_CTLCOLOR()
+ ON_WM_DESTROY()
+ ON_WM_SIZE()
+ ON_NOTIFY(BYVERTICALLINE_MOVEX, IDC_LINE1, &CPanelAttributes::OnVLineMoveX)
+END_MESSAGE_MAP()
+
+
+// CPanelAttributes 娑堟伅澶勭悊绋嬪簭
+
+
+int CPanelAttributes::getPanelWidth()
+{
+ return m_nPanelWidth;
+}
+
+void CPanelAttributes::loadDataFromStep(SERVO::CStep* pStep)
+{
+ // 鍏堟竻绌烘墍鏈�
+ m_gridCtrl.RemoveAll();
+
+
+ // 鍔犺浇鏁版嵁
+ SetDlgItemText(IDC_LABEL_TITLE, pStep->getName().c_str());
+ SERVO::CAttributeVector attrubutes;
+ pStep->getAttributeVector(attrubutes);
+ unsigned int nSize = attrubutes.size();
+ for (unsigned int i = 0; i < nSize; i++) {
+ SERVO::CAttribute* pAttribute = attrubutes.getAttribute(i);
+
+ CMFCPropertyGridProperty* pProp1 = new CMFCPropertyGridProperty(
+ pAttribute->getName().c_str(),
+ pAttribute->getValue().c_str(),
+ pAttribute->getDescription().c_str());
+ m_gridCtrl.AddProperty(pProp1);
+ }
+}
+
+BOOL CPanelAttributes::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+
+
+ CVerticalLine* pLine1 = CVerticalLine::Hook(GetDlgItem(IDC_LINE1)->GetSafeHwnd());
+ pLine1->SetBkgndColor(RGB(225, 225, 225));
+ pLine1->SetLineColor(RGB(198, 198, 198));
+ pLine1->EnableResize();
+
+
+ // 璇诲彇闈㈡澘瀹�
+ CString strIniFile;
+ strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile);
+ m_nPanelWidth = GetPrivateProfileInt(_T("App"), _T("AttributesPanelWidth"),
+ int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25), (LPTSTR)(LPCTSTR)strIniFile);
+
+
+
+
+ return TRUE; // return TRUE unless you set the focus to a control
+ // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+
+HBRUSH CPanelAttributes::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+ HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
+
+ if (nCtlColor == CTLCOLOR_STATIC) {
+ pDC->SetBkColor(m_crBkgnd);
+ pDC->SetTextColor(RGB(0, 0, 0));
+ }
+
+ if (m_hbrBkgnd == nullptr) {
+ m_hbrBkgnd = CreateSolidBrush(m_crBkgnd);
+ }
+
+ return m_hbrBkgnd;
+}
+
+void CPanelAttributes::OnDestroy()
+{
+ CDialogEx::OnDestroy();
+
+ if (m_hbrBkgnd != nullptr) {
+ ::DeleteObject(m_hbrBkgnd);
+ }
+}
+
+void CPanelAttributes::OnSize(UINT nType, int cx, int cy)
+{
+ CDialogEx::OnSize(nType, cx, cy);
+ CDialogEx::OnSize(nType, cx, cy);
+ if (GetDlgItem(IDC_LINE1) == nullptr) return;
+
+ CWnd* pItem;
+ CRect rcClient, rcItem;
+
+ GetClientRect(&rcClient);
+ pItem = GetDlgItem(IDC_LINE1);
+ pItem->MoveWindow(rcClient.right - 3, 0, 3, rcClient.Height());
+
+ int y = 3;
+ pItem = GetDlgItem(IDC_LABEL_TITLE);
+ pItem->GetWindowRect(&rcItem);
+ pItem->MoveWindow(5, y, rcClient.Width() - 8, rcItem.Height());
+ y += rcItem.Height();
+ y += 3;
+
+ GetDlgItem(IDC_MFCPROPERTYGRID1)->MoveWindow(5, y, rcClient.Width() - 13, rcClient.Height() - 3 - y);
+}
+
+#define MASTER_PANEL_MIN_WIDTH 88
+#define MASTER_PANEL_MAX_WIDTH 588
+void CPanelAttributes::OnVLineMoveX(NMHDR* nmhdr, LRESULT* result)
+{
+ BYVERTICALLINE_NMHDR* pNmhdrex = (BYVERTICALLINE_NMHDR*)nmhdr;
+ int x = pNmhdrex->dwData;
+ m_nPanelWidth += x;
+ m_nPanelWidth = max(m_nPanelWidth, MASTER_PANEL_MIN_WIDTH);
+ m_nPanelWidth = min(m_nPanelWidth, MASTER_PANEL_MAX_WIDTH);
+ GetParent()->SendMessage(ID_MSG_PANEL_RESIZE, m_nPanelWidth, 0);
+
+ CString strIniFile, strValue;
+ strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile);
+ strValue.Format(_T("%d"), m_nPanelWidth);
+ WritePrivateProfileString(_T("App"), _T("AttributesPanelWidth"),
+ (LPTSTR)(LPCTSTR)strValue, (LPTSTR)(LPCTSTR)strIniFile);
+ OnSize(0, 0, 0);
+
+ *result = 0;
+}
diff --git a/SourceCode/Bond/Servo/CPanelAttributes.h b/SourceCode/Bond/Servo/CPanelAttributes.h
new file mode 100644
index 0000000..3616a8e
--- /dev/null
+++ b/SourceCode/Bond/Servo/CPanelAttributes.h
@@ -0,0 +1,38 @@
+锘�#pragma once
+
+
+// CPanelAttributes 瀵硅瘽妗�
+
+class CPanelAttributes : public CDialogEx
+{
+ DECLARE_DYNAMIC(CPanelAttributes)
+
+public:
+ CPanelAttributes(CWnd* pParent = nullptr); // 鏍囧噯鏋勯�犲嚱鏁�
+ virtual ~CPanelAttributes();
+ int getPanelWidth();
+ void loadDataFromStep(SERVO::CStep* pStep);
+
+private:
+ COLORREF m_crBkgnd;
+ HBRUSH m_hbrBkgnd;
+ int m_nPanelWidth;
+ CMFCPropertyGridCtrl m_gridCtrl;
+
+
+// 瀵硅瘽妗嗘暟鎹�
+#ifdef AFX_DESIGN_TIME
+ enum { IDD = IDD_PANEL_ATTRIBUTES };
+#endif
+
+protected:
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
+
+ DECLARE_MESSAGE_MAP()
+public:
+ virtual BOOL OnInitDialog();
+ afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
+ afx_msg void OnDestroy();
+ afx_msg void OnSize(UINT nType, int cx, int cy);
+ afx_msg void OnVLineMoveX(NMHDR* nmhdr, LRESULT* result);
+};
diff --git a/SourceCode/Bond/Servo/CPanelMaster.cpp b/SourceCode/Bond/Servo/CPanelMaster.cpp
index 7991ae7..a4233f6 100644
--- a/SourceCode/Bond/Servo/CPanelMaster.cpp
+++ b/SourceCode/Bond/Servo/CPanelMaster.cpp
@@ -38,6 +38,7 @@
ON_WM_SIZE()
ON_NOTIFY(BYVERTICALLINE_MOVEX, IDC_LINE1, &CPanelMaster::OnVLineMoveX)
ON_WM_TIMER()
+ ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, &CPanelMaster::OnTvnSelchangedTree1)
END_MESSAGE_MAP()
@@ -174,3 +175,29 @@
}
}
+void CPanelMaster::OnTvnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
+{
+ LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
+ HTREEITEM hItem = pNMTreeView->itemNew.hItem;
+ int nLevel = GetTreeItemLevel(hItem);
+ if (nLevel == 3) {
+ SERVO::CStep* pStep = (SERVO::CStep*)m_treeCtrl.GetItemData(hItem);
+ theApp.m_model.notifyPtr(RX_CODE_SELECT_STEP, pStep);
+ }
+
+
+
+ *pResult = 0;
+}
+
+int CPanelMaster::GetTreeItemLevel(HTREEITEM hItem)
+{
+ int nLevel = 0;
+ HTREEITEM hTemp = hItem;
+ while (hTemp != nullptr) {
+ hTemp = m_treeCtrl.GetParentItem(hTemp);
+ nLevel++;
+ }
+
+ return nLevel;
+}
diff --git a/SourceCode/Bond/Servo/CPanelMaster.h b/SourceCode/Bond/Servo/CPanelMaster.h
index 50f44e3..bea8068 100644
--- a/SourceCode/Bond/Servo/CPanelMaster.h
+++ b/SourceCode/Bond/Servo/CPanelMaster.h
@@ -17,6 +17,10 @@
private:
+ int GetTreeItemLevel(HTREEITEM hItem);
+
+
+private:
COLORREF m_crBkgnd;
HBRUSH m_hbrBkgnd;
CApredTreeCtrl2 m_treeCtrl;
@@ -39,4 +43,5 @@
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnVLineMoveX(NMHDR* nmhdr, LRESULT* result);
afx_msg void OnTimer(UINT_PTR nIDEvent);
+ afx_msg void OnTvnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult);
};
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index 39897aa..3b33cd4 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -9,15 +9,18 @@
#define RX_HSMS_TERMINAL_TEXT 1003
#define RX_CODE_EQ_ALIVE 1004
#define RX_CODE_STEP_EVENT_READDATA 1005
+#define RX_CODE_SELECT_STEP 1006
+
/* Channel Name */
#define MC_CHANNEL1_NAME "McChannel1"
/* 颜色 */
-#define APPDLG_BACKGROUND_COLOR RGB(255, 255, 255)
-#define LOGDLG_BACKGROUND_COLOR RGB(255, 255, 255)
-#define PANEL_MASTER_BACKGROUND_COLOR RGB(255, 255, 255)
+#define APPDLG_BACKGROUND_COLOR RGB(255, 255, 255)
+#define LOGDLG_BACKGROUND_COLOR RGB(255, 255, 255)
+#define PANEL_MASTER_BACKGROUND_COLOR RGB(255, 255, 255)
+#define PANEL_ATTRIBUTES_BACKGROUND_COLOR RGB(255, 255, 255)
/* LOG BTN */
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index 36b313b..b1bbb7e 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
Binary files differ
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 74d6e70..454ab67 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -208,6 +208,7 @@
<ClInclude Include="CEqModeStep.h" />
<ClInclude Include="CEqProcessStep.h" />
<ClInclude Include="CEqStatusStep.h" />
+ <ClInclude Include="CPanelAttributes.h" />
<ClInclude Include="CPanelMaster.h" />
<ClInclude Include="CStep.h" />
<ClInclude Include="DevicePropertyDlg.h" />
@@ -249,6 +250,7 @@
<ClCompile Include="CEqModeStep.cpp" />
<ClCompile Include="CEqProcessStep.cpp" />
<ClCompile Include="CEqStatusStep.cpp" />
+ <ClCompile Include="CPanelAttributes.cpp" />
<ClCompile Include="CPanelMaster.cpp" />
<ClCompile Include="CStep.cpp" />
<ClCompile Include="DevicePropertyDlg.cpp" />
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index 5988a2a..0f465c7 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -47,6 +47,7 @@
<ClCompile Include="CPanelMaster.cpp" />
<ClCompile Include="VerticalLine.cpp" />
<ClCompile Include="ApredTreeCtrl2.cpp" />
+ <ClCompile Include="CPanelAttributes.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AlarmManager.h" />
@@ -92,6 +93,7 @@
<ClInclude Include="CPanelMaster.h" />
<ClInclude Include="VerticalLine.h" />
<ClInclude Include="ApredTreeCtrl2.h" />
+ <ClInclude Include="CPanelAttributes.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Servo.rc" />
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 4217090..f3d2cd5 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -167,6 +167,15 @@
}
}
}
+ else if (RX_CODE_SELECT_STEP == code) {
+ SERVO::CStep* pStep = nullptr;
+ if (pAny->getPtrValue("ptr", (void*&)pStep)) {
+ ASSERT(pStep);
+ ASSERT(m_pPanelAttributes);
+ m_pPanelAttributes->loadDataFromStep(pStep);
+ }
+ }
+
pAny->release();
}, [&]() -> void {
// onComplete
@@ -305,6 +314,10 @@
m_pPanelMaster = new CPanelMaster();
m_pPanelMaster->Create(IDD_PANEL_MASTER, this);
m_pPanelMaster->ShowWindow(SW_SHOW);
+ m_pPanelAttributes = new CPanelAttributes();
+ m_pPanelAttributes->Create(IDD_PANEL_ATTRIBUTES, this);
+ m_pPanelAttributes->ShowWindow(SW_SHOW);
+
// 调整初始窗口位置
@@ -558,6 +571,12 @@
m_pPanelMaster = nullptr;
}
+ if (m_pPanelAttributes != nullptr) {
+ m_pPanelAttributes->DestroyWindow();
+ delete m_pPanelAttributes;
+ m_pPanelAttributes = nullptr;
+ }
+
if (m_hbrBkgnd != nullptr) {
::DeleteObject(m_hbrBkgnd);
}
@@ -763,6 +782,11 @@
x += nPanelWidth;
}
+ if (m_pPanelAttributes != nullptr) {
+ nPanelWidth = m_pPanelAttributes->getPanelWidth();
+ m_pPanelAttributes->MoveWindow(x, y, nPanelWidth, rcClient.Height());
+ x += nPanelWidth;
+ }
pItem = GetDlgItem(IDC_SERVO_GRAPH1);
pItem->GetClientRect(&rcItem);
diff --git a/SourceCode/Bond/Servo/ServoDlg.h b/SourceCode/Bond/Servo/ServoDlg.h
index b3f4cca..9fd1dbc 100644
--- a/SourceCode/Bond/Servo/ServoDlg.h
+++ b/SourceCode/Bond/Servo/ServoDlg.h
@@ -8,6 +8,7 @@
#include "LogDlg.h"
#include "TerminalDisplayDlg.h"
#include "CPanelMaster.h"
+#include "CPanelAttributes.h"
enum DeviceStatus {
@@ -65,6 +66,7 @@
CBlButton m_btnLog;
CBlButton m_btnAlarm;
CPanelMaster* m_pPanelMaster;
+ CPanelAttributes* m_pPanelAttributes;
// 生成的消息映射函数
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index c96ed4e..593c8be 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
Binary files differ
--
Gitblit v1.9.3