Files
geomative/GeomativeStudio/cpp/Views/disptdrecsplinesgrapview.cpp
coco df489d5640 a
2026-07-03 16:05:30 +08:00

252 lines
5.7 KiB
C++

// disptdrecsplinesgrapview.cpp : implementation file
//
#include "stdafx.h"
#include "geomative.h"
#include "disptdrecsplinesgrapview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDispTdRecSplinesGrapView
IMPLEMENT_DYNCREATE(CDispTdRecSplinesGrapView, CView)
CDispTdRecSplinesGrapView::CDispTdRecSplinesGrapView()
{
m_fMaxAbsV = 0.0;
m_iCXOffset = 55;
m_iCYOffset = 35;
m_pPoint = NULL;
m_iPtNum = 0;
}
CDispTdRecSplinesGrapView::~CDispTdRecSplinesGrapView()
{
ClearPoint();
}
BEGIN_MESSAGE_MAP(CDispTdRecSplinesGrapView, CView)
//{{AFX_MSG_MAP(CDispTdRecSplinesGrapView)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_MOUSEACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDispTdRecSplinesGrapView drawing
void CDispTdRecSplinesGrapView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
if (0 != m_iPtNum)
{
DrawEX(pDC);
DrawLY(pDC);
DrawLine(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDispTdRecSplinesGrapView diagnostics
#ifdef _DEBUG
void CDispTdRecSplinesGrapView::AssertValid() const
{
CView::AssertValid();
}
void CDispTdRecSplinesGrapView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDispTdRecSplinesGrapView message handlers
int CDispTdRecSplinesGrapView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
{
return APP_SUCCESS;
}
void CDispTdRecSplinesGrapView::DrawLine(CDC* const pDC)
{
CPen lPen(PS_SOLID, 1, RGB(30, 200, 30));
CPen* pOldLPen = NULL;
pOldLPen = pDC->SelectObject(&lPen);
int iIndex = (int)VAL_ZERO;
iIndex = (int)VAL_ZERO;
pDC->MoveTo(*(m_pPoint + iIndex));
while (iIndex < this->m_iPtNum)
{
pDC->LineTo(*(m_pPoint + iIndex));
pDC->SetPixel(*(m_pPoint+iIndex), RGB(0xFF, 0x00, 0x00));
iIndex++;
}
}
void CDispTdRecSplinesGrapView::DrawEX(CDC* const pDC)
{
CString szLabel = _T("");
pDC->MoveTo(m_iCXOffset - 1, m_iCYOffset + 150);
pDC->LineTo(m_iCXOffset + 410, m_iCYOffset + 150);
pDC->MoveTo(m_iCXOffset + 408, m_iCYOffset + 150);
pDC->LineTo(m_iCXOffset + 403, m_iCYOffset + 147);
pDC->MoveTo(m_iCXOffset + 408, m_iCYOffset + 150);
pDC->LineTo(m_iCXOffset + 403, m_iCYOffset + 153);
szLabel.Empty();
szLabel = _T("T");
pDC->DrawText(szLabel, CRect(m_iCXOffset + 415, m_iCYOffset + 143, m_iCXOffset + 445, m_iCYOffset + 157), DT_SINGLELINE | DT_VCENTER | DT_LEFT);
// pDC->LineTo(m_iCXOffset + 400 + 10, m_iCYOffset + 300 / 2 - 5);
}
void CDispTdRecSplinesGrapView::DrawLY(CDC* const pDC)
{
CPen penDot(PS_DOT, 1, RGB(180, 180, 180));
CPen* pPenOld = NULL;
CFont fontEX;
CFont* pFontOldEX = NULL;
CString szLabel = _T("");
int iIndex = (int)VAL_ZERO;
szLabel.Empty();
szLabel = _T("V(mV)");
pDC->DrawText(szLabel, CRect(m_iCXOffset - 20, m_iCYOffset - 28, m_iCXOffset + 20, m_iCYOffset - 8), DT_SINGLELINE | DT_VCENTER | DT_CENTER);
pDC->MoveTo(m_iCXOffset - 1, m_iCYOffset);
pDC->LineTo(m_iCXOffset - 1, m_iCYOffset + 300);
fontEX.CreatePointFont(80, _T("Tahoma"));
pFontOldEX = pDC->SelectObject(&fontEX);
iIndex = (int)VAL_ZERO;
while (iIndex < 11)
{
pDC->MoveTo(m_iCXOffset - 1, m_iCYOffset + 30 * iIndex);
pDC->LineTo(m_iCXOffset - 6, m_iCYOffset + 30 * iIndex);
if (5 != iIndex)
{
pPenOld = pDC->SelectObject(&penDot);
pDC->MoveTo(m_iCXOffset - 1, m_iCYOffset + 30 * iIndex);
pDC->LineTo(m_iCXOffset + 400, m_iCYOffset + 30 * iIndex);
pDC->SelectObject(pPenOld);
}
szLabel.Empty();
szLabel.Format(_T("%d"), m_iMaxYScale - (m_iMaxYScale / 5) * iIndex);
pDC->DrawText(szLabel, CRect(m_iCXOffset - 35, m_iCYOffset + iIndex * 30 - 5, m_iCXOffset - 5, m_iCYOffset + iIndex * 30 + 5), DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
iIndex++;
}
fontEX.DeleteObject();
pDC->SelectObject(pFontOldEX);
}
int CDispTdRecSplinesGrapView::CoordinateMapping(float fValue, float fMappingRange, int MappingFactor)
{
float fUnit = 0.0;
float fMValue = 0.0;
fUnit = (float)(fMappingRange / MappingFactor);
fMValue = fValue / fUnit;
return (int)ceilf(fMValue);
}
void CDispTdRecSplinesGrapView::CalculatePointCoo()
{
CPoint* pPoint = NULL;
float fXValue = 0.0;
float fYValue = 0.0;
CString szValue = _T("");
int iIndex = (int)VAL_ZERO;
CalculateMaxScale();
ClearPoint();
if (m_saOrgData.GetSize() > 4)
{
m_iPtNum = this->m_saOrgData.GetSize() - 4;
m_pPoint = new POINT[m_iPtNum];
iIndex = (int)0;
while (iIndex < m_iPtNum)
{
szValue.Empty();
szValue = this->m_saOrgData.GetAt(iIndex + 4);
fXValue = (float)iIndex;
(m_pPoint+iIndex)->x = m_iCXOffset + this->CoordinateMapping(fXValue, (float)this->m_iMaxXScale, 400);
fYValue = (float)this->m_iMaxYScale - (float)atof(szValue);
(m_pPoint+iIndex)->y = m_iCYOffset + this->CoordinateMapping(fYValue, (float)2 * m_iMaxYScale, 300);
iIndex++;
}
}
}
void CDispTdRecSplinesGrapView::CalculateMaxScale()
{
int iFill = (int)VAL_ZERO;
m_iMaxYScale = (int)ceil(this->m_fMaxAbsV);
iFill = (int)VAL_ZERO;
while (TRUE)
{
if (0.0 == ((m_iMaxYScale + iFill) * 2) % 10)
{
m_iMaxYScale = m_iMaxYScale + iFill;
break;
}
iFill++;
}
if (this->m_saOrgData.GetSize() > 4)
{
m_iMaxXScale = this->m_saOrgData.GetSize() - 4;
}
}
void CDispTdRecSplinesGrapView::ClearPoint()
{
int iIndex = (int)VAL_ZERO;
delete[] this->m_pPoint;
}
void CDispTdRecSplinesGrapView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CalculatePointCoo();
}