📄 fibertestclientview.cpp
字号:
// FiberTestClientView.cpp : implementation of the CFiberTestClientView class
//
#include "stdafx.h"
#include "FiberTestClient.h"
#include "FiberTestClientDoc.h"
#include "FiberTestClientView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFiberTestClientApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CFiberTestClientView
IMPLEMENT_DYNCREATE(CFiberTestClientView, CFormView)
BEGIN_MESSAGE_MAP(CFiberTestClientView, CFormView)
//{{AFX_MSG_MAP(CFiberTestClientView)
ON_EN_CHANGE(IDC_Ymin, OnChangeYmin)
ON_EN_CHANGE(IDC_Ymax, OnChangeYmax)
ON_WM_PAINT()
ON_EN_CHANGE(IDC_TestTime, OnChangeTestTime)
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFiberTestClientView construction/destruction
CFiberTestClientView::CFiberTestClientView()
: CFormView(CFiberTestClientView::IDD)
{
//{{AFX_DATA_INIT(CFiberTestClientView)
m_xtime1 = 30;
m_ymax = 10;
m_ymin = -10;
m_Coord = _T("");
m_datatime = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_iPointCount = 0;
m_bIsSetDrawPoint = false;
m_bIsSetReadPoint = false;
m_bIsReTest = false;
m_xtime = 0;
m_bIsFinishDraw = false;
m_uPointA = NULL;
m_uPointB = NULL;
m_uPointC = NULL;
m_uDrawedPointA = NULL;
m_uDrawedPointB = NULL;
m_uDrawedPointC = NULL;
}
UINT CFiberTestClientView::m_uTempPointA = POINT_NULL;
UINT CFiberTestClientView::m_uTempPointB = POINT_NULL;
UINT CFiberTestClientView::m_uTempPointC = POINT_NULL;
CFiberTestClientView::~CFiberTestClientView()
{
if(NULL != m_uPointA)
{
delete []m_uPointA;
m_uPointA = NULL;
}
if(NULL != m_uPointB)
{
delete []m_uPointB;
m_uPointB = NULL;
}
if(NULL != m_uPointC)
{
delete []m_uPointC;
m_uPointC = NULL;
}
if(NULL != m_uDrawedPointA)
{
delete []m_uDrawedPointA;
m_uDrawedPointA = NULL;
}
if(NULL != m_uDrawedPointB)
{
delete []m_uDrawedPointB;
m_uDrawedPointB = NULL;
}
if(NULL != m_uDrawedPointC)
{
delete []m_uDrawedPointC;
m_uDrawedPointC = NULL;
}
}
void CFiberTestClientView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFiberTestClientView)
DDX_Text(pDX, IDC_TestTime, m_xtime1);
DDX_Text(pDX, IDC_Ymax, m_ymax);
DDX_Text(pDX, IDC_Ymin, m_ymin);
DDX_Text(pDX, IDC_COORD, m_Coord);
DDX_Text(pDX, IDC_time, m_datatime);
//}}AFX_DATA_MAP
}
BOOL CFiberTestClientView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CFiberTestClientView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CFiberTestClientView printing
BOOL CFiberTestClientView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFiberTestClientView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFiberTestClientView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CFiberTestClientView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CFiberTestClientView diagnostics
#ifdef _DEBUG
void CFiberTestClientView::AssertValid() const
{
CFormView::AssertValid();
}
void CFiberTestClientView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFiberTestClientDoc* CFiberTestClientView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFiberTestClientDoc)));
return (CFiberTestClientDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
LRESULT CFiberTestClientView::OnComm(WPARAM wParam, LPARAM lParam)
{
char buf[MAXBLOCK/4];
CString str;
CFiberTestClientDoc* pDoc=GetDocument();
if(!pDoc->m_bConnected || (wParam & EV_RXCHAR)!=EV_RXCHAR) // 是否是EV_RXCHAR事件?
{
SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
return 0L;
}
pDoc->ReadComm(buf,6);
if(128==buf[0])
{
#ifdef INPUT_DATA
//080412_ReadData
//数据放入暂存,待程序根据定值的采样周期取走;
m_uTempPointA =(buf[1]<<25+buf[2]<<17+buf[3]<<9+buf[4]<<1)>>1; //如果从串口读到数据A的话,放入A点的暂存
m_uTempPointB = (buf[1]<<25+buf[2]<<17+buf[3]<<9+buf[4]<<1)>>1;//如果从串口读到数据B的话,放入B点的暂存
m_uTempPointC = (buf[1]<<25+buf[2]<<17+buf[3]<<9+buf[4]<<1)>>1;//如果从串口读到数据C的话,放入C点的暂存
#endif
}
// m_pRecordset->Update();
SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
return 0L;
}
void CFiberTestClientView::DrawWave(CDC *pDC)
{
CRect rect;
CString str;
int i,j;
// 获取绘制坐标的文本框
CWnd* pWnd = GetDlgItem(IDC_COORD);
pWnd->GetClientRect(&rect);
pDC->Rectangle(&rect);
m_left = rect.left+50;
m_top = rect.top+10;
m_right = rect.right-10;
m_bottom = rect.bottom-100;
int m_IntervalPan = (m_right-20 - m_left)/20;
//UpdateData(false);
if (m_IntervalPan < 1 ) m_IntervalPan =1;
int m_Interval = (m_bottom - m_top-20)/10;
if (m_Interval < 1) m_Interval = 1;
double m_Interval1=(m_ymax-m_ymin)/10.0;
double m_Interval2=m_xtime1/20.0;
// 创建画笔对象
CPen* pPenRed = new CPen;
// 红色画笔
pPenRed->CreatePen(PS_SOLID,1,RGB(255,0,0));
// 创建画笔对象
CPen* pPenBlue = new CPen;
// 蓝色画笔
pPenBlue->CreatePen(PS_SOLID,1,RGB(0,0, 255));
// 创建画笔对象
CPen* pPenGreen = new CPen;
// 绿色画笔
pPenGreen->CreatePen(PS_DOT,1,RGB(0,255,0));
// 选中当前红色画笔,并保存以前的画笔
CGdiObject* pOldPen = pDC->SelectObject(pPenRed);
pDC->MoveTo(rect.Width()*2/3-20,10);
pDC->LineTo(rect.Width()*2/3-5,10);
pDC->TextOut(rect.Width()*2/3-0,5,"A");
pDC->SelectObject(pPenBlue);
pDC->MoveTo(rect.Width()*2/3+45,10);
pDC->LineTo(rect.Width()*2/3+60,10);
pDC->TextOut(rect.Width()*2/3+65,5,"B");
CPen* pPenC = new CPen;
pPenC->CreatePen(PS_SOLID,1,RGB(0,0,0));
pDC->SelectObject(pPenC);
pDC->MoveTo(rect.Width()*2/3+110,10);
pDC->LineTo(rect.Width()*2/3+125,10);
pDC->TextOut(rect.Width()*2/3+130,5,"C");
pDC->SelectObject(pPenRed);
// 绘制坐标轴
pDC->MoveTo(m_left,m_top);
// 垂直轴
pDC->LineTo(m_left,m_bottom);
// 水平轴
pDC->LineTo(m_right,m_bottom);
// 绘制X轴箭头
pDC->MoveTo(m_right-5,m_bottom-5);
pDC->LineTo(m_right,m_bottom);
pDC->LineTo(m_right-5,m_bottom+5);
// 绘制Y轴箭头
pDC->MoveTo(m_left-5,m_top+5);
pDC->LineTo(m_left,m_top);
pDC->LineTo(m_left+5,m_top+5);
pDC->SelectObject(pPenGreen);
for( i=0;i<21;i++)
{
pDC->MoveTo(m_left+i*m_IntervalPan,m_top);
pDC->LineTo(m_left+i*m_IntervalPan,m_bottom+1);
CString s;
CTime time=CTime::GetCurrentTime();
// int t;
// t=time.GetSecond();
s.Format("%.1f",i*m_Interval2);
pDC->TextOut(m_left+i*m_IntervalPan,m_bottom+2,s);
}
for( j=0;j<11;j++)
{
pDC->MoveTo(m_left,m_bottom-j*m_Interval);
pDC->LineTo(m_right,m_bottom-j*m_Interval);
double temp=m_ymin+j*m_Interval1;
CString s;
s.Format("%.1f",temp);
if (m_ymax>100&&m_ymin<-100)
{
pDC->TextOut(m_left-45,m_bottom-j*m_Interval,s);
}
else
{
pDC->TextOut(m_left-35,m_bottom-j*m_Interval,s);
}
}
// pDC->SelectObject(pPenRed);
CRect t_rect(rect.left,rect.top,rect.right,20);
pDC->DrawText("陀螺测试",8,t_rect,DT_CENTER );
//重绘已经画过的点
int iTimes=0;
if(NULL != m_uDrawedPointA)
{
if(POINT_NULL != m_uDrawedPointA[iTimes])
{
m_IntervalPan = (m_right-20 - m_left)/20;
if (m_IntervalPan < 1 ) m_IntervalPan =1;
m_Interval = (m_bottom - m_top-20)/10;
int iBaseX = m_left;
int iBaseY = (m_bottom - m_top +2)/2 + m_Interval/2;
int iAx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
//int iAy = iBaseY - m_uDrawedPointA[iTimes]*m_Interval/2;
int iAy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointA[iTimes] - m_ymin);
int iOldAX = iAx;
int iOldAY = iAy;
int iBx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
//int iBy = iBaseY - m_uDrawedPointB[iTimes]*m_Interval/2;
int iBy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointB[iTimes] - m_ymin);
int iOldBX = iBx;
int iOldBY = iBy;
int iCx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
//int iCy = iBaseY - m_uDrawedPointC[iTimes]*m_Interval/2;
int iCy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointC[iTimes] - m_ymin);
int iOldCX = iCx;
int iOldCY = iCy;
while(POINT_NULL != m_uDrawedPointA[iTimes] && (iTimes< m_iPointCount))
{
pDC->SelectObject(pPenRed);
iAx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
// iAy = iBaseY - m_uDrawedPointA[iTimes]*m_Interval/2;
iAy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointA[iTimes] - m_ymin);
pDC->MoveTo(iOldAX,iOldAY);
pDC->LineTo(iAx,iAy);
iOldAX =iAx;
iOldAY = iAy;
pDC->SelectObject(pPenBlue);
iBx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
// iBy = iBaseY - m_uDrawedPointB[iTimes]*m_Interval/2;
iBy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointB[iTimes] - m_ymin);
pDC->MoveTo(iOldBX,iOldBY);
pDC->LineTo(iBx,iBy);
iOldBX =iBx;
iOldBY = iBy;
pDC->SelectObject(pPenC);
iCx = iBaseX + iTimes*m_IntervalPan*10/150*TIME_DRAW/TIME_BASE*300/m_iPointCount;
// iCy = iBaseY - m_uDrawedPointC[iTimes]*m_Interval/2;
iCy = m_bottom - m_Interval/4 - (m_bottom - m_top-20)/(m_ymax - m_ymin)*(m_uPointC[iTimes] - m_ymin);
pDC->MoveTo(iOldCX,iOldCY);
pDC->LineTo(iCx,iCy);
iOldCX =iCx;
iOldCY = iCy;
iTimes++;
}
}
}
// 恢复以前的画笔
pDC->SelectObject(pOldPen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -