From bc7f1c4e028e69be51079b59dae4ae5c4d43f5bb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 31 一月 2026 21:54:56 +0800
Subject: [PATCH] 1.状态指示图,目前灰色表示掉线,绿色表示在线。增加Slot的小点表示有没有料,及加工状态 。 2.增加图示
---
SourceCode/Bond/Servo/ServoGraph.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 92 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/Servo/ServoGraph.cpp b/SourceCode/Bond/Servo/ServoGraph.cpp
index daf274a..b14ed32 100644
--- a/SourceCode/Bond/Servo/ServoGraph.cpp
+++ b/SourceCode/Bond/Servo/ServoGraph.cpp
@@ -21,6 +21,7 @@
m_crBkgnd = RGB(255,255,255);
m_pHighItem = nullptr;
m_hWndTooltip = nullptr;
+ m_slotBarSize = 0;
}
CServoGraph::~CServoGraph()
@@ -124,6 +125,9 @@
case WM_LBUTTONDOWN:
return pServoGraph->OnLButtonDown(wParam, lParam);
+
+ case WM_SIZE:
+ return pServoGraph->OnSize(wParam, lParam);
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;
@@ -273,6 +277,14 @@
return ::DefWindowProc(m_hWnd, WM_LBUTTONDOWN, wParam, lParam);
}
+/*
+ * WM_SIZE
+ */
+LRESULT CServoGraph::OnSize(WPARAM wParam, LPARAM lParam)
+{
+ return ::DefWindowProc(m_hWnd, WM_SIZE, wParam, lParam);
+}
+
///////////////////////////////
// WM_PAINT
LRESULT CServoGraph::OnPaint(WPARAM wParam, LPARAM lParam)
@@ -350,6 +362,37 @@
// text
::DrawText(hMemDC, item.szText, static_cast<int>(strlen(item.szText)),
&rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+
+ // slot bar
+ if (item.slotBarPos != SlotBarPos::None && !item.slotColors.empty()) {
+ const int slotCount = static_cast<int>(item.slotColors.size());
+ const int gap = 1;
+ int slotSize = 4;
+ if (slotCount > 0) {
+ const int maxSize = (item.box1Width - gap * (slotCount - 1)) / slotCount;
+ slotSize = (m_slotBarSize > 0) ? m_slotBarSize : maxSize;
+ if (slotSize < 2) slotSize = 2;
+ }
+ const int barWidth = slotCount * slotSize + gap * (slotCount - 1);
+ const int startX = item.x - barWidth / 2;
+ const int baseTop = (item.slotBarPos == SlotBarPos::Top)
+ ? (item.y - item.box1Width / 2 - slotSize - 2)
+ : (item.y + item.box1Width / 2 + 2);
+
+ HBRUSH hbrBorder = CreateSolidBrush(RGB(100, 100, 100));
+ for (int i = 0; i < slotCount; ++i) {
+ RECT rcSlot;
+ rcSlot.left = startX + i * (slotSize + gap);
+ rcSlot.top = baseTop;
+ rcSlot.right = rcSlot.left + slotSize;
+ rcSlot.bottom = rcSlot.top + slotSize;
+ HBRUSH hbrSlot = CreateSolidBrush(item.slotColors[i]);
+ ::FillRect(hMemDC, &rcSlot, hbrSlot);
+ ::FrameRect(hMemDC, &rcSlot, hbrBorder);
+ ::DeleteObject(hbrSlot);
+ }
+ ::DeleteObject(hbrBorder);
+ }
}
@@ -653,6 +696,31 @@
}
}
+void CServoGraph::SetIndicateBoxSlotBarPosition(int id, SlotBarPos pos)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->slotBarPos = pos;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+ }
+}
+
+void CServoGraph::SetIndicateBoxSlotColors(int id, const std::vector<COLORREF>& colors)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->slotColors = colors;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+ }
+}
+
+void CServoGraph::SetSlotBarSize(int size)
+{
+ if (size < 0) size = 0;
+ m_slotBarSize = size;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+}
+
void CServoGraph::DrawImage(HDC hMemDC, IMAGE& item)
{
// 载入BMP
@@ -693,4 +761,27 @@
graphics.DrawImage(&bitmap, item.x, item.y);
graphics.ResetTransform();
}
-}
\ No newline at end of file
+}
+
+void CServoGraph::SetIndicateBoxData(int id, void* pData)
+{
+ INDICATEBOX* pib = GetIndicateBox(id);
+ if (pib != nullptr) {
+ pib->m_pData = pData;
+ }
+}
+
+void* CServoGraph::GetIndicateBoxData(int id)
+{
+ INDICATEBOX* pib = GetIndicateBox(id);
+ if (pib != nullptr) {
+ return pib->m_pData;
+ }
+
+ return nullptr;
+}
+
+void CServoGraph::Invalidata()
+{
+ ::InvalidateRect(m_hWnd, NULL, TRUE);
+}
--
Gitblit v1.9.3