📄 interpolationview.cpp
字号:
// InterpolationView.cpp : implementation of the CInterpolationView class
//
#include "stdafx.h"
#include "Interpolation.h"
#include "InterpolationDoc.h"
#include "InterpolationView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView
IMPLEMENT_DYNCREATE(CInterpolationView, CView)
BEGIN_MESSAGE_MAP(CInterpolationView, CView)
//{{AFX_MSG_MAP(CInterpolationView)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_X, OnUpdateIndicatorX)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_Y, OnUpdateIndicatorY)
ON_COMMAND(ID_FUNCTION_F, OnFunctionF)
ON_UPDATE_COMMAND_UI(ID_FUNCTION_F, OnUpdateFunctionF)
ON_COMMAND(ID_FUNCTION_L, OnFunctionL)
ON_UPDATE_COMMAND_UI(ID_FUNCTION_L, OnUpdateFunctionL)
ON_COMMAND(ID_FUNCTION_S, OnFunctionS)
ON_UPDATE_COMMAND_UI(ID_FUNCTION_S, OnUpdateFunctionS)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView construction/destruction
CInterpolationView::CInterpolationView()
{
// TODO: add construction code here
m_bF = TRUE;
m_bL = FALSE;
m_bS = TRUE;
m_dblPosX = 0.0;
m_dblPosY = 0.0;
}
CInterpolationView::~CInterpolationView()
{
}
BOOL CInterpolationView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView drawing
void CInterpolationView::OnDraw(CDC* pDC)
{
pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
double dblMaxX = 0;
double dblMaxY = 0;
for(int i=0; i<pDoc->m_nNumDraw; i++)
{
if(fabs(pDoc->m_dblX[i]) > dblMaxX)
dblMaxX = fabs(pDoc->m_dblX[i]);
if(fabs(pDoc->m_dblF[i]) > dblMaxY)
dblMaxY = fabs(pDoc->m_dblF[i]);
if(fabs(pDoc->m_dblL[i]) > dblMaxY)
dblMaxY = fabs(pDoc->m_dblL[i]);
if(fabs(pDoc->m_dblS[i]) > dblMaxY)
dblMaxY = fabs(pDoc->m_dblS[i]);
}
GetClientRect(m_Rect);
m_dblScaleX = m_Rect.Width()/2/dblMaxX;
m_dblScaleY = m_Rect.Height()/2/dblMaxY;
// 绘制坐标轴
DrawCoordinate();
// 绘制曲线
if(m_bF)
DrawLine(pDoc->m_dblX, pDoc->m_dblF, RGB(255, 0, 0));
if(m_bL)
DrawLine(pDoc->m_dblX, pDoc->m_dblL, RGB(0, 255, 0));
if(m_bS)
DrawLine(pDoc->m_dblX, pDoc->m_dblS, RGB(0, 0, 255));
}
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView printing
BOOL CInterpolationView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CInterpolationView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CInterpolationView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView diagnostics
#ifdef _DEBUG
void CInterpolationView::AssertValid() const
{
CView::AssertValid();
}
void CInterpolationView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CInterpolationDoc* CInterpolationView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInterpolationDoc)));
return (CInterpolationDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CInterpolationView message handlers
void CInterpolationView::OnUpdateIndicatorX(CCmdUI* pCmdUI)
{
CString str;
str.Format(_T("X=%f"), m_dblPosX);
pCmdUI->SetText(str);
}
void CInterpolationView::OnUpdateIndicatorY(CCmdUI* pCmdUI)
{
CString str;
str.Format(_T("Y=%f"), m_dblPosY);
pCmdUI->SetText(str);
}
void CInterpolationView::OnFunctionF()
{
// TODO: Add your command handler code here
m_bF = !m_bF;
InvalidateRect(NULL);
}
void CInterpolationView::OnUpdateFunctionF(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bF);
}
void CInterpolationView::OnFunctionL()
{
// TODO: Add your command handler code here
m_bL = !m_bL;
InvalidateRect(NULL);
}
void CInterpolationView::OnUpdateFunctionL(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bL);
}
void CInterpolationView::OnFunctionS()
{
// TODO: Add your command handler code here
m_bS = !m_bS;
InvalidateRect(NULL);
}
void CInterpolationView::OnUpdateFunctionS(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bS);
}
void CInterpolationView::DrawCoordinate()
{
CDC* pDC = GetDC();
pDC->MoveTo(m_Rect.Width()/2, 0);
pDC->LineTo(m_Rect.Width()/2, m_Rect.Height());
pDC->MoveTo(0, m_Rect.Height()/2);
pDC->LineTo(m_Rect.Width(), m_Rect.Height()/2);
ReleaseDC(pDC);
}
void CInterpolationView::DrawLine(double* X, double* Y, COLORREF colorLine)
{
CDC* pDC = GetDC();
CPen Pen(PS_SOLID, 2, colorLine);
CPen *oldPen = pDC->SelectObject(&Pen);
pDC->MoveTo(PhysicsToClient(X[0], Y[0]).x, PhysicsToClient(X[0], Y[0]).y);
for(int i=1; i<=pDoc->m_nNumDraw; i++)
{
pDC->LineTo(PhysicsToClient(X[i], Y[i]).x, PhysicsToClient(X[i], Y[i]).y);
}
pDC->SelectObject(oldPen);
ReleaseDC(pDC);
}
CPoint CInterpolationView::PhysicsToClient(double x, double y)
{
CPoint pt;
pt.x = int(m_Rect.Width()/2.0 + x*m_dblScaleX);
pt.y = int(m_Rect.Height()/2.0 - y*m_dblScaleY);
return pt;
}
void CInterpolationView::ClientToPhysics(CPoint pt)
{
m_dblPosX = (pt.x - m_Rect.Width()/2)/m_dblScaleX;
m_dblPosY = (m_Rect.Height()/2 - pt.y)/m_dblScaleY;
}
void CInterpolationView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ClientToPhysics(point);
CView::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -