📄 crossdisplay.cpp
字号:
// Copyright (C) 1991 - 1999 Rational Software Corporation
#include "stdafx.h"
#include "CrossDisplay.h"
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::DrawX_Axl(CDC *pDC)
{
// TODO: Add your specialized code here.
RECT rc;
GetClientRect(&rc);
int ShortUnitLen = (m_ShortUnitScale * y_length)/rc.bottom;
int LongUnitLen = (m_LongUnitScale * y_length)/rc.bottom;
TRACE("short unit lengh is %d,long unit length is %d\n",ShortUnitLen,LongUnitLen);
SetOrgAndExt(pDC);
CPen pen (PS_SOLID, 0, RGB(0, 0, 0)); // red pen
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(x_AxlBegin, 0);
pDC->LineTo(x_AxlEnd,0);
int xNumRectLogLen = NumRectLenWidth * x_length/ rc.right;
int yNumRectLogLen = NumRectLenLength * y_length/ rc.bottom;
for(int i = x_AxlBegin; i <= x_AxlEnd; i = i + x_unit)
{
pDC->MoveTo(i,0);
if( i%(x_unit*10) == 0)
{
pDC->LineTo(i,LongUnitLen);
CRect NumRect;
if(i == 0)
NumRect.SetRect(i - 2 * xNumRectLogLen, 0, i + xNumRectLogLen, -yNumRectLogLen);
else
NumRect.SetRect(i - 2 * xNumRectLogLen, 0, i + 2 * xNumRectLogLen, -yNumRectLogLen);
CString numtxt;
numtxt.Format("%d",i/x_scale);
TRACE("the number along x axl is %s\n",numtxt);
pDC->DrawText(numtxt, &NumRect, DT_CENTER | DT_WORDBREAK);
}
else
pDC->LineTo(i,ShortUnitLen);
}
pDC->SelectObject(pOldPen);
}
////////////////////////////////////////////////////////////////// ///
void CCrossDisplay::DrawY_Axl(CDC *pDC)
{
// TODO: Add your specialized code here.
SetOrgAndExt(pDC);
CPen pen (PS_SOLID, 0, RGB(0, 0, 0)); // red pen
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(0, y_AxlBegin);
pDC->LineTo(0,y_AxlEnd);
RECT rc;
GetClientRect(&rc);
int ShortUnitLen = (m_ShortUnitScale * x_length)/rc.right;
int LongUnitLen = (m_LongUnitScale * x_length)/rc.right;
TRACE("short unit lengh is %d,long unit length is %d\n",ShortUnitLen,LongUnitLen);
int xNumRectLogLen = NumRectLenWidth * x_length/ rc.right;
int yNumRectLogLen = NumRectLenLength * y_length/ rc.bottom;
for(int i = y_AxlBegin; i <= y_AxlEnd; i = i + y_unit)
{
pDC->MoveTo(0,i);
if(i%(y_unit * 10) == 0)
{
pDC->LineTo(LongUnitLen,i);
if(i != 0)
{
CRect NumRect(- 3 * xNumRectLogLen, i + yNumRectLogLen/2, xNumRectLogLen, i - 4 * yNumRectLogLen);
CString numtxt;
numtxt.Format("%d",i/y_scale);
pDC->DrawText(numtxt, &NumRect, DT_CENTER | DT_WORDBREAK);
}
}
else
pDC->LineTo(ShortUnitLen,i);
}
}
BEGIN_MESSAGE_MAP(CCrossDisplay, CDisplay)
//{{AFX_MSG_MAP(CCrossDisplay)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::SetXUnit(int NPixes)
{
x_unit = NPixes;
// TODO: Add your specialized code here.
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::SetYUnit(int NPixes)
{
// TODO: Add your specialized code here.
y_unit = NPixes;
}
/////////////////////////////////////////////////////////////////////
CCrossDisplay::CCrossDisplay() : x_unit(5), y_unit(5), x_length(500), y_length(100)
{
m_xAxl_Txt = "位移mm";
m_yAxl_Txt = "时间(s)";
cen_pos = LEFT_BOTTOM;
x_scale = 100; //等于x_length/表达的长度
y_scale = 100;
m_ShortUnitScale = 7;
m_LongUnitScale = 15;
NumRectLenWidth = 15; //坐标数值的设备单位大小
NumRectLenLength = 25;
/////////2003.12.01
x_AxlBegin = 0;
x_AxlEnd = x_length;
y_AxlBegin = 0;
y_AxlEnd = y_length;
////
// ToDo: Add your specialized code here and/or call the base class
}
/////////////////////////////////////////////////////////////////////
CCrossDisplay::~CCrossDisplay()
{
// ToDo: Add your specialized code here and/or call the base class
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDisplay::OnPaint();
DrawAxlText(&dc);
DrawX_Axl(&dc);
DrawY_Axl(&dc);
DrawData(&dc);
// TODO: Add your message handler code here
// Do not call CDisplay::OnPaint() for painting messages
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::SetOrgAndExt(CDC* pDC)
{
// ToDo: Add your specialized code here or after the call to base class
RECT rc;
GetClientRect(&rc);
TRACE("display hight is %d,width is %d\n",rc.bottom,rc.right);
pDC->SetMapMode(MM_ANISOTROPIC);
if(cen_pos == LEFT_BOTTOM)
{
pDC->SetWindowOrg(0, 0);
pDC->SetViewportOrg(28, rc.bottom-20);//22,20//20031201,15,15
pDC->SetWindowExt(x_length, y_length);
pDC->SetViewportExt(rc.right-42, -(rc.bottom-42));//35,35 //20031201,25,25
x_AxlBegin = 0;
x_AxlEnd = x_length;
y_AxlBegin =0;
y_AxlEnd = y_length;
}
else if(cen_pos == CENTER)
{
pDC->SetWindowOrg(0, 0);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SetWindowExt(x_length, y_length);
pDC->SetViewportExt((rc.bottom-20)/2, -(rc.bottom-20)/2);
x_AxlBegin = -x_length;
x_AxlEnd = x_length;
y_AxlBegin = -y_length;
y_AxlEnd = y_length;
}
pDC->SetBkMode(TRANSPARENT);
CDisplay::SetOrgAndExt(pDC);
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::DrawAxlText(CDC *pDC)
{
pDC->SetMapMode(MM_TEXT);
CRect rc;
GetClientRect(rc);
pDC->SetBkMode(TRANSPARENT);
CRect TxtRect;
if(cen_pos == CENTER)
TxtRect.SetRect(rc.Width()/2,20,rc.Width()/2 + 70,40);////20031201
else if(cen_pos == LEFT_BOTTOM)
TxtRect.SetRect(35,10,100,50);
pDC->DrawText(m_xAxl_Txt, &TxtRect, DT_CENTER | DT_WORDBREAK);
if(cen_pos == CENTER)
TxtRect.SetRect(rc.Width() - 100, rc.Height()/2 - 20,
rc.Width() - 5 , rc.Height()/2);
else if(cen_pos == LEFT_BOTTOM)
TxtRect.SetRect(rc.Width() - 50, rc.Height() - 50,////20031201
rc.Width() - 5 , rc.Height() - 30);
pDC->DrawText(m_yAxl_Txt, &TxtRect, DT_CENTER | DT_WORDBREAK);
DRAWITEMLIST::iterator it_list;
int txt_hor = 10;
for (it_list = m_Itemlist.begin(); it_list != m_Itemlist.end(); ++it_list)
{
if(it_list->bRedraw == FALSE || it_list->DataName == "")
continue;
CPen pen (PS_SOLID, 3, it_list->DrawClr); // red pen
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(rc.Width()/2 + 80,txt_hor);
pDC->LineTo(rc.Width()/2 + 120,txt_hor);
TxtRect.SetRect(rc.Width()/2 + 125,txt_hor - 10,rc.Width(),txt_hor + 20);
pDC->DrawText(it_list->DataName, &TxtRect, DT_LEFT | DT_WORDBREAK);
txt_hor = txt_hor + 20;
pDC->SelectObject(pOldPen);
}
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::AddDrawItem(DRAWITEM &item)
{
item.bRedraw = TRUE;
m_Itemlist.push_back(item);
Invalidate();
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::DrawData(CDC* pDC)
{
// ToDo: Add your specialized code here or after the call to base class
SetOrgAndExt(pDC);
DRAWITEMLIST::iterator it_list;
for (it_list = m_Itemlist.begin(); it_list != m_Itemlist.end(); ++it_list)
{
if(it_list->bRedraw == FALSE)
continue;
CPen pen (PS_SOLID, 0, it_list->DrawClr); // red pen //it_list->nPen
CPen* pOldPen = pDC->SelectObject(&pen);
if(it_list->dtype == YDATA)
{
for(int j = 0, data_index = 0; data_index < it_list->nData;
j = j + x_length/it_list->nData,data_index++)
{
if(j == 0)
pDC->MoveTo(j,(int)(it_list->pData[data_index].y));
else
pDC->LineTo(j,(int)(it_list->pData[data_index].y));
}
}
else
{
for(int data_index = 0; data_index < it_list->nData;data_index++)
{
if(data_index == 0)
pDC->MoveTo(it_list->pData[data_index].x, it_list->pData[data_index].y);
else
pDC->LineTo(it_list->pData[data_index].x, it_list->pData[data_index].y);
}
}
pDC->SelectObject(pOldPen);
}
CDisplay::DrawData(pDC);
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::setx_Axl_Txt(CString& value)
{
m_xAxl_Txt = value;
return;
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::sety_Axl_Txt(CString& value)
{
m_yAxl_Txt = value;
return;
}
/////////////////////////////////////////////////////////////////////
void CCrossDisplay::RemoveAllItem()
{
//DRAWITEMLIST::iterator it;
//while((it = m_Itemlist.front()) ! = m_Itemlist.end())
m_Itemlist.erase(m_Itemlist.begin(),m_Itemlist.end());
// TODO: Add your specialized code here.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -