agv-control/Plugin/Driver/PositionView.cpp
2025-06-09 09:09:25 +08:00

88 lines
1.6 KiB
C++

// PositionView.cpp : 实现文件
//
#include "stdafx.h"
#include "PositionView.h"
#include "PluginDriver.h"
// CPositionView
IMPLEMENT_DYNAMIC(CPositionView, CStatic)
CPositionView::CPositionView()
{
m_nLabelCount = 0;
//m_nPosition = 6000;
m_nChannelLen = 12000;
}
CPositionView::~CPositionView()
{
}
BEGIN_MESSAGE_MAP(CPositionView, CStatic)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CPositionView::Update()
{
m_nLabelCount = theApp.m_nLabelCount;
m_nChannelLen = theApp.m_nRoadwayLen;
}
// CPositionView 消息处理程序
void CPositionView::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
int nWidth = rect.Width();
int nPosCnt = m_nLabelCount;
//dc.Rectangle(0, 0, nWidth, 60); // 10cm长的刻度尺
CFont font;
font.CreatePointFont(60, "Arial");
for (int i = 0; i < nPosCnt; i++)
{
int nLabelPos = nWidth * theApp.m_GuideLabels[i].nOffset *1.0 / m_nChannelLen;
dc.MoveTo(nLabelPos, 15); // 位置刻度
dc.LineTo(nLabelPos, 0);
CString str;
str.Format(_T("%d"), theApp.m_GuideLabels[i].nIndex);
dc.TextOut(nLabelPos - 10, -25, str);
CFont* pOldFont = dc.SelectObject(&font);
str.Format(_T("%d"), theApp.m_GuideLabels[i].nTag);
dc.TextOut(nLabelPos - 10, 15, str);
dc.SelectObject(pOldFont);
if (i > 0)
{
str.Format(_T("%d"), theApp.m_GuideLabels[i].nOffset);
dc.TextOut(nLabelPos - 10, 35, str);
}
}
dc.MoveTo(nWidth, 15);
dc.LineTo(nWidth, 0);
int nAgvPos = m_nPosition * nWidth *1.0 / m_nChannelLen; //AGV相对位置
CBrush brushRed(RGB(255, 0, 0));
CBrush* pOldBrush = dc.SelectObject(&brushRed);
dc.Ellipse(nAgvPos - 6, 10 - 6, nAgvPos + 6, 10 + 6);
dc.SelectObject(pOldBrush);
}