LAPTOP-SNT8I5JK\Boounion
2025-03-04 102c26b397f7466779f712c31752973e17a195f6
1.增加属性值列表展示面板。
已添加2个文件
已修改9个文件
274 ■■■■■ 文件已修改
SourceCode/Bond/Servo/CPanelAttributes.cpp 165 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPanelAttributes.h 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPanelMaster.cpp 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPanelMaster.h 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Common.h 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.rc 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj.filters 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ServoDlg.cpp 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ServoDlg.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/resource.h 补丁 | 查看 | 原始文档 | blame | 历史
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;
}
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);
};
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;
}
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);
};
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 */
SourceCode/Bond/Servo/Servo.rc
Binary files differ
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" />
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" />
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);
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;
    // ç”Ÿæˆçš„æ¶ˆæ¯æ˜ å°„函数
SourceCode/Bond/Servo/resource.h
Binary files differ