From 19261d011387ec57d646decc945aadaf8913eeab Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 10 三月 2025 09:05:54 +0800
Subject: [PATCH] Merge branch 'clh'
---
SourceCode/Bond/Servo/CPanelMaster.cpp | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 207 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPanelMaster.cpp b/SourceCode/Bond/Servo/CPanelMaster.cpp
new file mode 100644
index 0000000..014819d
--- /dev/null
+++ b/SourceCode/Bond/Servo/CPanelMaster.cpp
@@ -0,0 +1,207 @@
+锘�// CPanelMaster.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "CPanelMaster.h"
+#include "afxdialogex.h"
+#include "Common.h"
+#include "VerticalLine.h"
+
+
+// CPanelMaster 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CPanelMaster, CDialogEx)
+
+CPanelMaster::CPanelMaster(CWnd* pParent /*=nullptr*/)
+ : CDialogEx(IDD_PANEL_MASTER, pParent)
+{
+ m_crBkgnd = PANEL_MASTER_BACKGROUND_COLOR;
+ m_hbrBkgnd = nullptr;
+ m_nPanelWidth = 388;
+}
+
+CPanelMaster::~CPanelMaster()
+{
+}
+
+void CPanelMaster::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_TREE1, m_treeCtrl);
+}
+
+
+BEGIN_MESSAGE_MAP(CPanelMaster, CDialogEx)
+ ON_WM_CTLCOLOR()
+ ON_WM_DESTROY()
+ 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()
+
+
+// CPanelMaster 娑堟伅澶勭悊绋嬪簭
+
+
+int CPanelMaster::getPanelWidth()
+{
+ return m_nPanelWidth;
+}
+
+BOOL CPanelMaster::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("MasterPanelWidth"),
+ int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25), (LPTSTR)(LPCTSTR)strIniFile);
+
+
+ // treectrl
+ m_treeCtrl.SetBkColor(PANEL_MASTER_BACKGROUND_COLOR);
+ m_treeCtrl.SetItemHeight(28);
+ SetTimer(1, 2000, nullptr);
+
+ return TRUE; // return TRUE unless you set the focus to a control
+ // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+HBRUSH CPanelMaster::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 CPanelMaster::OnDestroy()
+{
+ CDialogEx::OnDestroy();
+
+ if (m_hbrBkgnd != nullptr) {
+ ::DeleteObject(m_hbrBkgnd);
+ }
+}
+
+void CPanelMaster::OnSize(UINT nType, int cx, int cy)
+{
+ CDialogEx::OnSize(nType, cx, cy);
+ if (GetDlgItem(IDC_LINE1) == nullptr) return;
+
+ CWnd* pItem;
+ CRect rcClient;
+
+ GetClientRect(&rcClient);
+ pItem = GetDlgItem(IDC_LINE1);
+ pItem->MoveWindow(rcClient.right - 3, 0, 3, rcClient.Height());
+
+ m_treeCtrl.MoveWindow(5, 5, rcClient.Width() - 13, rcClient.Height() - 10);
+}
+
+
+#define MASTER_PANEL_MIN_WIDTH 88
+#define MASTER_PANEL_MAX_WIDTH 588
+void CPanelMaster::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("MasterPanelWidth"),
+ (LPTSTR)(LPCTSTR)strValue, (LPTSTR)(LPCTSTR)strIniFile);
+ OnSize(0, 0, 0);
+
+ * result = 0;
+}
+
+void CPanelMaster::OnTimer(UINT_PTR nIDEvent)
+{
+ if (1 == nIDEvent) {
+ KillTimer(1);
+ loadEquipmentList();
+ }
+
+ CDialogEx::OnTimer(nIDEvent);
+}
+
+void CPanelMaster::loadEquipmentList()
+{
+ HTREEITEM hItemMaster = m_treeCtrl.InsertItem("Master");
+
+ std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
+ for (auto item : eqs) {
+ HTREEITEM hItemEq = m_treeCtrl.InsertItem(item->getName().c_str(), hItemMaster);
+ m_treeCtrl.SetItemData(hItemEq, (DWORD_PTR)item);
+ loadSteps(item, hItemEq);
+ m_treeCtrl.Expand(hItemEq, TVE_EXPAND);
+ }
+
+
+ m_treeCtrl.Expand(hItemMaster, TVE_EXPAND);
+}
+
+void CPanelMaster::loadSteps(SERVO::CEquipment* pEquipment, HTREEITEM hItemEq)
+{
+ std::map<unsigned int, SERVO::CStep*>& steps = pEquipment->getSteps();
+
+ for (auto item : steps) {
+ HTREEITEM hStep = m_treeCtrl.InsertItem(item.second->getName().c_str(), hItemEq);
+ m_treeCtrl.SetItemData(hStep, (DWORD_PTR)item.second);
+ }
+}
+
+void CPanelMaster::OnTvnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
+{
+ LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
+ HTREEITEM hItem = pNMTreeView->itemNew.hItem;
+ int nLevel = GetTreeItemLevel(hItem);
+ if (nLevel == 2) {
+ SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)m_treeCtrl.GetItemData(hItem);
+ theApp.m_model.notifyPtr(RX_CODE_SELECT_EQUIPMENT, pEquipment);
+ }
+ else 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;
+}
--
Gitblit v1.9.3