📄 curvehistflow.cpp
字号:
// CurveHistFlow.cpp : implementation file
//
#include "stdafx.h"
#include "CurveHistFlow.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCurveHistFlow
long nCountx,nBegin;
CCurveHistFlow::CCurveHistFlow()
{
}
CCurveHistFlow::~CCurveHistFlow()
{
if (m_MemDC.GetSafeHdc()!=NULL) m_MemDC.SelectObject(m_preBitmap);
if (m_nGridMemDC.GetSafeHdc()!=NULL) m_nGridMemDC.SelectObject(m_pPreGridBitmap);
int nIndex=m_nItems.GetSize();
for(int i=0;i<nIndex;i++)
{
delete m_nItems.GetAt(i);
}
m_nItems.RemoveAll();
}
BEGIN_MESSAGE_MAP(CCurveHistFlow, CWnd)
//{{AFX_MSG_MAP(CCurveHistFlow)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_LBUTTONUP()
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCurveHistFlow message handlers
void CCurveHistFlow::SetBkFrameColor(long BkColor, long FrameColor)
{
// TODO: Add your dispatch handler code here
m_nBkColor=(BkColor);
m_nFrameColor=(FrameColor);
}
void CCurveHistFlow::SetPrimCompart(short xSum, short ySum, short PenWidth, short PenStyle, long PenColor)
{
// TODO: Add your dispatch handler code here
if (xSum>5) xSum=5;
if (xSum<0) xSum=0;
if (ySum>5) ySum=5;
if (xSum<0) xSum=0;
m_xPrimLineSum=xSum;
m_yPrimLineSum=ySum;
m_PrimPenWidth=PenWidth;
m_PrimPenStyle=PenStyle;
m_PrimPenColor=(PenColor);
if (m_xPrimLineSum<0) m_xPrimLineSum=0;
if (m_yPrimLineSum<0) m_yPrimLineSum=0;
}
void CCurveHistFlow::SetSecCompart(short xSum, short ySum, short PenWidth, short PenStyle, long PenColor)
{
// TODO: Add your dispatch handler code here
if (xSum>5) xSum=5;
if (xSum<0) xSum=0;
if (ySum>5) ySum=5;
if (xSum<0) xSum=0;
m_xSecLineSum=xSum;
m_ySecLineSum=ySum;
m_SecPenWidth=PenWidth;
m_SecPenStyle=PenStyle;
m_SecPenColor=(PenColor);
if (m_xSecLineSum<0) m_xSecLineSum=0;
if (m_ySecLineSum<0) m_ySecLineSum=0;
}
void CCurveHistFlow::SetXId(short xCount, long nColor,short nFontSize,char *nFontName)
{
// TODO: Add your dispatch handler code here
m_xIdentifySum=xCount;
if (m_xIdentifySum<0) m_xIdentifySum=0;
if (m_xIdentifySum>6) m_xIdentifySum=6;
m_xIdentifyColor=(nColor);
m_nTimeCoordFontSize=nFontSize;
strcpy(m_nTimeCoordFontName,nFontName);
}
void CCurveHistFlow::SetSplitLine(short nPenStyle, short nPenWidth, long nPenColor)
{
// TODO: Add your dispatch handler code here
m_nSplitPenStyle=nPenStyle;
m_nSplitPenWidth=nPenWidth;
m_nSplitPenColor=(nPenColor);
}
void CCurveHistFlow::InitCtrl(short nHeight,short nWidth,short nFrameTopH,short nFrameLeftW,short nFrameRightW,short nFrameBottomH)
{
// TODO: Add your dispatch handler code here
if (m_MemDC.GetSafeHdc()==NULL)
{
CClientDC dc(this);
m_nHeight=nHeight-20;
m_nWidth=nWidth;
m_nFrameTopH=nFrameTopH;
m_nFrameLeftW=nFrameLeftW;
m_nFrameRightW=nFrameRightW;
m_nFrameBottomH=nFrameBottomH;
m_nPtInSplitLine=FALSE;
m_MemDC.CreateCompatibleDC(&dc);
m_Bitmap.CreateCompatibleBitmap(&dc,m_nWidth,m_nHeight);
m_preBitmap=m_MemDC.SelectObject(&m_Bitmap);
m_nGridMemDC.CreateCompatibleDC(&dc);
m_nGridBitmap.CreateCompatibleBitmap(&dc,m_nFrameLeftW+m_nWidth+m_nFrameRightW,m_nHeight+m_nFrameBottomH+m_nFrameTopH);
m_pPreGridBitmap=m_nGridMemDC.SelectObject(&m_nGridBitmap);
}
}
void CCurveHistFlow::InvalidateCtrl(long nCurrentTime)
{
// TODO: Add your dispatch handler code here
if (m_MemDC.GetSafeHdc()==NULL) return;
m_nEndTime=nCurrentTime;
m_nStartTime=nCurrentTime-m_nTimer*m_nWidth/m_nPigment;
m_nCurrentSplitTime=m_nStartTime;
m_nLineX=0;
CRect nRect;
CBrush nBkBrush(m_nBkColor);
CBrush nFrameBrush(m_nFrameColor);
nRect.SetRect(0,0,m_nFrameLeftW+m_nWidth+m_nFrameRightW,m_nHeight+m_nFrameBottomH+m_nFrameTopH);
m_nGridMemDC.FillRect(&nRect,&nFrameBrush);
nRect.SetRect(0,0,m_nWidth,m_nHeight);
m_MemDC.FillRect(&nRect,&nBkBrush);
Invalidate(FALSE);
}
void CCurveHistFlow::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
OnDraw(&dc);
// Do not call CWnd::OnPaint() for painting messages
}
void CCurveHistFlow::SetTimePigment(short nTime, short nPigment)
{
// TODO: Add your dispatch handler code here
// (0<pigment<6)
if(nPigment<1) nPigment=1;
//if(nPigment>6) nPigment=6;
m_nTimer=nTime;
m_nPigment=nPigment;
}
BOOL CCurveHistFlow::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_pParentWnd=pParentWnd;
if (CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
{
ResetScrollBars();
return TRUE;
}
else
{
return FALSE;
}
}
void CCurveHistFlow::OnDraw(CDC* pDC)
{
if (m_nGridMemDC.GetSafeHdc()!=NULL)
{
// pDC->SetBkMode(TRANSPARENT);
m_nGridMemDC.BitBlt(m_nFrameLeftW,m_nFrameTopH,m_nWidth+m_nFrameLeftW,m_nHeight+m_nFrameTopH,&m_MemDC,0,0,SRCCOPY);
DrawGrid(&m_nGridMemDC);
pDC->BitBlt(0,0,m_nWidth+m_nFrameLeftW+m_nFrameRightW,m_nHeight+m_nFrameBottomH+m_nFrameTopH,&m_nGridMemDC,0,0,SRCCOPY);
CPen nPen(m_nSplitPenStyle,m_nSplitPenWidth,m_nSplitPenColor);
CPen *prePen=pDC->SelectObject(&nPen);
pDC->MoveTo(m_nLineX+m_nFrameLeftW,m_nFrameTopH);
pDC->LineTo(m_nLineX+m_nFrameLeftW,m_nHeight+m_nFrameTopH);
pDC->SelectObject(prePen);
m_nCurrentSplitTime=m_nStartTime+(m_nLineX/m_nPigment)*m_nTimer;
if (m_nLineX%m_nPigment!=0)
if (m_nLineX%m_nPigment>(float)m_nPigment/2)m_nCurrentSplitTime+=m_nTimer;
}
}
void CCurveHistFlow::DrawSpike(BOOL bForward)
{
// TODO: Add your dispatch handler code here
if (m_MemDC.GetSafeHdc()!=NULL)
{
if (bForward)
{
int nPels=m_nPigment;
CRect nRect;
nRect.SetRect(0,0,m_nWidth,m_nHeight+m_nFrameBottomH);
m_MemDC.BitBlt(0,0,nRect.right,nRect.bottom,&m_MemDC,nPels,0,SRCCOPY); //Moving
CBrush nBkBrush(m_nBkColor);
CBrush nFrameBrush(m_nFrameColor);
//nBkBrush.CreateSolidBrush(m_nBkColor);
// nFrameBrush.CreateSolidBrush;
nRect.left=nRect.right-nPels;
nRect.top=m_nHeight;
m_MemDC.FillRect(&nRect,&nFrameBrush); //Fill Frame;
m_nStartTime+=m_nTimer;
m_nEndTime+=m_nTimer;
nRect.top=0;
nRect.bottom=m_nHeight;
m_MemDC.FillRect(&nRect,&nBkBrush); //Fill Curve BkColor;
//***********begin draw curve*******
int nCount=m_nItems.GetSize();
CHistChartItem* pItem;
CPoint nOldPoint,nNewPoint;
float nRange;
for (int i=0;i<nCount;i++)
{
pItem=m_nItems.GetAt(i);
if ((pItem->m_nPointState==NORMAL_POINT)&&(pItem->m_nEndState==NORMAL_POINT))
{
nRange=pItem->m_nUpper-pItem->m_nLower;
nOldPoint.x=nRect.right-m_nPigment;
nNewPoint.x=nRect.right;
nOldPoint.y=m_nHeight-(int)((pItem->m_nEndPos-pItem->m_nLower)*m_nHeight/nRange);
nNewPoint.y=m_nHeight-(int)((pItem->m_nPos-pItem->m_nLower)*m_nHeight/nRange);
CPen nPen(pItem->m_nPenStyle,pItem->m_nPenWidth,pItem->m_nPenColor);
CPen *pOldPen=m_MemDC.SelectObject(&nPen);
m_MemDC.MoveTo(nOldPoint);
m_MemDC.LineTo(nNewPoint);
m_MemDC.SelectObject(pOldPen);
}
pItem->m_nEndPos=pItem->m_nPos;
pItem->m_nEndState=pItem->m_nPointState;
}
}
else
{
int nPels=m_nPigment;
CRect nRect;
nRect.SetRect(0,0,m_nWidth,m_nHeight+m_nFrameBottomH);
m_MemDC.BitBlt(nPels,0,nRect.right,nRect.bottom,&m_MemDC,0,0,SRCCOPY); //Moving
CBrush nBkBrush(m_nBkColor);
CBrush nFrameBrush(m_nFrameColor);
//nBkBrush.CreateSolidBrush(m_nBkColor);
// nFrameBrush.CreateSolidBrush;
nRect.right=nRect.left+nPels;
nRect.top=m_nHeight;
m_MemDC.FillRect(&nRect,&nFrameBrush); //Fill Frame;
m_nStartTime-=m_nTimer;
m_nEndTime-=m_nTimer;
nRect.top=0;
nRect.bottom=m_nHeight;
m_MemDC.FillRect(&nRect,&nBkBrush); //Fill Curve BkColor;
//***********begin draw curve*******
int nCount=m_nItems.GetSize();
CHistChartItem* pItem;
CPoint nOldPoint,nNewPoint;
float nRange;
for (int i=0;i<nCount;i++)
{
pItem=m_nItems.GetAt(i);
if ((pItem->m_nPointState==NORMAL_POINT)&&(pItem->m_nBeginState==NORMAL_POINT))
{
nRange=pItem->m_nUpper-pItem->m_nLower;
nOldPoint.x=nRect.right;
nNewPoint.x=nRect.left;
nOldPoint.y=m_nHeight-(int)((pItem->m_nBeginPos-pItem->m_nLower)*m_nHeight/nRange);
nNewPoint.y=m_nHeight-(int)((pItem->m_nPos-pItem->m_nLower)*m_nHeight/nRange);
CPen nPen(pItem->m_nPenStyle,pItem->m_nPenWidth,pItem->m_nPenColor);
CPen *pOldPen=m_MemDC.SelectObject(&nPen);
m_MemDC.MoveTo(nOldPoint);
m_MemDC.LineTo(nNewPoint);
m_MemDC.SelectObject(pOldPen);
}
pItem->m_nBeginPos=pItem->m_nPos;
pItem->m_nBeginState=pItem->m_nPointState;
}
//***********Draw Curve end**********
}
}
}
void CCurveHistFlow::Go(BOOL bForward)
{
// TODO: Add your dispatch handler code here
DrawSpike(bForward);
//Invalidate(FALSE);
}
void CCurveHistFlow::AddLine(long nPenColor, short nPenStyle, short nPenWidth, float nLower, float nUpper)
{
// TODO: Add your dispatch handler code here
CHistChartItem *pItem=new CHistChartItem;
pItem->m_nPenColor=(nPenColor);
pItem->m_nPenStyle=nPenStyle;
pItem->m_nPenWidth=nPenWidth;
pItem->m_nUpper=nUpper;
pItem->m_nLower=nLower;
if ((pItem->m_nUpper-pItem->m_nLower)<1e-5) pItem->m_nUpper=pItem->m_nLower+1;
pItem->m_nBeginPos=0;
pItem->m_nEndPos=0;
pItem->m_nPos=0;
pItem->m_nPointState=NORMAL_POINT;
pItem->m_nBeginPos=NORMAL_POINT;
pItem->m_nEndPos=NORMAL_POINT;
pItem->m_nHistCount=0;
try
{
m_nItems.Add(pItem);
}
catch(CMemoryException *e)
{
if (pItem!=NULL) delete pItem;
e->Delete();
AfxMessageBox("Add Curve Error");
}
}
void CCurveHistFlow::DeleteAllLine()
{
int nIndex=m_nItems.GetSize();
for(int i=0;i<nIndex;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -