⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histwaveview.cpp

📁 AD 数据采集卡基本的采集界面
💻 CPP
字号:
// HistWaveView.cpp : implementation file
//

#include "stdafx.h"
#include "Sys.h"
#include "HistDataFrm.h"
#include "HistWaveView.h"
#include "HistDigitView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHistWaveView

IMPLEMENT_DYNCREATE(CHistWaveView, CScrollView)

CHistWaveView::CHistWaveView()
{

	Index=0;
	m_ScreenVolume=(int)VOLT_RANGE;  // 定义量程为10V
	m_MiddleLsb=0;   // 偏移0个LSB
}

CHistWaveView::~CHistWaveView()
{
}


BEGIN_MESSAGE_MAP(CHistWaveView, CScrollView)
	//{{AFX_MSG_MAP(CHistWaveView)
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHistWaveView drawing

void CHistWaveView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
    CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument(); 
	sizeTotal.cx = (int)(8192/pDoc->m_ChannelCount)-pDoc->m_ChannelCount;
	sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);

	m_oldScroll=pDoc->m_ScreenOffset;

	pDoc->m_hWndWave=m_hWnd; 

}

void CHistWaveView::OnDraw(CDC* pDC)
{
	// CHistDigitView* pDoc =(CHistDigitView*)GetDocument();
	// TODO: add draw code here	
	ShowWave(pDC);

}

/////////////////////////////////////////////////////////////////////////////
// CShowWaveView message handlers
void CHistWaveView::ShowWave(CDC *pDC)//绘制波形
{
    CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument(); 

    int i,j,y1, y2;                     // 循环变量,用于轮换显示数据	      
    int x;
	
	int m_Height;
    CPen Pen;
	CPen CenterPen;
    CPen BackGroundPen;
	int DataOffset;
	CPen* OldPen;

	Pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
    CenterPen.CreatePen(PS_SOLID,1,RGB(255,255,0));
	BackGroundPen.CreatePen(PS_SOLID,1,RGB(0,255,255));
	CRect rect;
	GetClientRect(&rect);
    OnPrepareDC(pDC);
    pDC->DPtoLP(&rect);
    m_Height=rect.Height()/10;
	OldPen=pDC->SelectObject(&BackGroundPen);
	for(int h=0 ;h<rect.bottom;h=h+m_Height)
	{
		pDC->MoveTo(0,h);
        pDC->LineTo(rect.right,h);
     }
    for(int k=0;k<rect.right;k=k+m_Height)
    {
      pDC->MoveTo(k,0);
      pDC->LineTo(k,rect.bottom);	
	}

    
	PerY= rect.Height()/pDoc->m_ChannelCount;
	center=(int)(PerY/2.0);
	Offset = rect.left;  // 保存窗口最左边的位置
	middle1=(float)((((m_ScreenVolume)/VOLT_RANGE)*LSB_COUNT)/(PerY-5));//每像素对应的码值
	x=rect.left;
	y1=PerY;		
	for(i=0; i<pDoc->m_ChannelCount; i++)
	{
		pDC->SelectObject(&CenterPen);
		pDC->MoveTo(0,PerY*i+PerY/2);
		pDC->LineTo(rect.right, PerY*i+PerY/2);
		pDC->SelectObject(OldPen);
		pDC->MoveTo(0, y1);
		pDC->LineTo(rect.right, y1);
		y1+=PerY;
	} 
	
	pDC->SelectObject(&Pen);
	x=rect.left;	
	DataOffset=rect.left*pDoc->m_ChannelCount;  // 当前屏幕的始点相对于ADBuffer的偏移位置
	CString str;
	for(i=0; (i<(rect.Width()*pDoc->m_ChannelCount))&&(i<(int)pDoc->m_ReadDataSize); i+=pDoc->m_ChannelCount)
	{
		center=(int)(PerY/2.0);		
		for(j=0; j<pDoc->m_ChannelCount; j++)
		{ 		
			y1=(int)((center)-(int)(((((pDoc->m_ADBuffer[DataOffset+i+j]^0x2000)&0x3fff)-LSB_HALF-m_MiddleLsb))/middle1));
			y2=(int)((center)-(int)(((((pDoc->m_ADBuffer[DataOffset+i+j+pDoc->m_ChannelCount]^0x2000)&0x3fff)-LSB_HALF-m_MiddleLsb))/middle1));
			pDC->MoveTo(x,y1);  pDC->LineTo(x+1, y2);
			center+=PerY;				
		}
		x++;
	} 

	pDC->SelectObject(OldPen);   // 恢复原笔
}


/////////////////////////////////////////////////////////////////////////////
// CHistWaveView diagnostics

#ifdef _DEBUG
void CHistWaveView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CHistWaveView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHistWaveView message handlers

void CHistWaveView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    CHistDataFrm* pFrame=(CHistDataFrm*)GetParentFrame();

	CEdit* pPos=(CEdit*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_EDIT_ScreenPos));
	CClientDC dc(this);
	OnPrepareDC(&dc);
	dc.DPtoLP(&point);    
    CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument(); 

	CString str;
	pDoc->m_ScreenOffset=pDoc->m_Offset+point.x;
	str.Format("%d", pDoc->m_ScreenOffset);

    pPos->SetWindowText(str);	
	CScrollView::OnMouseMove(nFlags, point);
}


void CHistWaveView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	OnPrepareDC(&dc);
	dc.DPtoLP(&point);

	CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument(); 
	CHistDigitView* pDigit=(CHistDigitView* )CWnd::FromHandle(pDoc->m_hWndDigit );

	pDigit->GetListCtrl().Scroll(CSize(0,-13*m_oldScroll));

	m_oldScroll=point.x ;

	pDigit->GetListCtrl().Scroll(CSize(0,13*m_oldScroll));

	CScrollView::OnRButtonDown(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -