📄 globaldisp.cpp
字号:
// GlobalDisp.cpp : implementation file
//
#include "stdafx.h"
#include "mcds.h"
#include "GlobalDisp.h"
#include "mcdsDoc.h"
#include "GlobalVar.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGlobalDisp
IMPLEMENT_DYNCREATE(CGlobalDisp, CView)
CGlobalDisp::CGlobalDisp()
{
}
CGlobalDisp::~CGlobalDisp()
{
}
BEGIN_MESSAGE_MAP(CGlobalDisp, CView)
//{{AFX_MSG_MAP(CGlobalDisp)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGlobalDisp drawing
void CGlobalDisp::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CGlobalDisp diagnostics
#ifdef _DEBUG
void CGlobalDisp::AssertValid() const
{
CView::AssertValid();
}
void CGlobalDisp::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMcdsDoc* CGlobalDisp::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMcdsDoc)));
return (CMcdsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGlobalDisp message handlers
void CGlobalDisp::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
CDC memDC;
CBitmap memBit;
CPen Pen;
memDC.CreateCompatibleDC(&dc);
memBit.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
CBitmap *pOldBit = memDC.SelectObject(&memBit);
memDC.FillSolidRect(0,0,rect.Width(),
rect.Height(),RGB(128,128,128)); //绘制背景
if(lsSetROILeft==false&&lsSetROIRight==true)//处理正在绘制ROI区时的情况
{
memDC.FillSolidRect(leftPoint.x,0,
rightPoint.x-leftPoint.x,
rect.Height(),RGB(20,100,200));//绘制ROI区
CPen ROIPen;
ROIPen.CreatePen(PS_SOLID,1,RGB(200,0,0));//ROI区两边的线
CPen * pROIPen=memDC.SelectObject(&ROIPen);
memDC.MoveTo(leftPoint.x,0);
memDC.LineTo(leftPoint.x,rect.Height());
memDC.MoveTo(rightPoint.x,0);
memDC.LineTo(rightPoint.x,rect.Height());
pROIPen->DeleteObject();
ROIPen.DeleteObject();
}
else if(nNumInfo[20]!="0"||nNumInfo[21]!="255")//处理没有正在绘制ROI区,但是含有ROI的情况
{
memDC.FillSolidRect(Channel2Point(rect,nNumInfo[20]).x,0,
Channel2Point(rect,nNumInfo[21]).x-Channel2Point(rect,nNumInfo[20]).x,
rect.Height(),RGB(20,100,200));//绘制ROI区
CPen ROIPen;
ROIPen.CreatePen(PS_SOLID,1,RGB(200,0,0));//ROI区两边的线
CPen * pROIPen=memDC.SelectObject(&ROIPen);
memDC.MoveTo(Channel2Point(rect,nNumInfo[20]).x,0);
memDC.LineTo(Channel2Point(rect,nNumInfo[20]).x,rect.Height());
memDC.MoveTo(Channel2Point(rect,nNumInfo[21]).x,0);
memDC.LineTo(Channel2Point(rect,nNumInfo[21]).x,rect.Height());
pROIPen->DeleteObject();
ROIPen.DeleteObject();
}
Pen.CreatePen(PS_SOLID,1,RGB(255,255,0));
CPen * pPen=memDC.SelectObject(&Pen);
int i;
for(i=0;i<=255;i++)
{
memDC.MoveTo(Data2Point(rect,i).x-(int)(scalex(rect)/2),Data2Point(rect,i).y);
memDC.LineTo(Data2Point(rect,i).x+(int)(scalex(rect)/2),Data2Point(rect,i).y);
}
pPen->DeleteObject();
Pen.DeleteObject();
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),
&memDC,rect.left,rect.top,SRCCOPY);
memDC.DeleteDC();
// Do not call CView::OnPaint() for painting messages
}
void CGlobalDisp::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CView::OnTimer(nIDEvent);
}
void CGlobalDisp::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
//刷新下拉菜单显示
if(nNumInfo[15]=="256")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(0);
else if(nNumInfo[15]=="512")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(1);
else if(nNumInfo[15]=="1K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(2);
else if(nNumInfo[15]=="2K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(3);
else if(nNumInfo[15]=="4K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(4);
else if(nNumInfo[15]=="8K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(5);
else if(nNumInfo[15]=="16K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(6);
else if(nNumInfo[15]=="32K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(7);
else if(nNumInfo[15]=="64K")((CMainFrame *)AfxGetApp()->m_pMainWnd)->m_wndToolBar.m_wndZoom.SetCurSel(8);
Invalidate(FALSE);
}
void CGlobalDisp::OnInitialUpdate()
{
CView::OnInitialUpdate();
if(!(lsSetROILeft||lsSetROIRight))
{
for(int i=0;i<=255;i++)
{
cs.Lock();
m_data[i]=data[i];
cs.Unlock();
}
}
if(nNumInfo[16]=="自动")
{
nNumInfo[15]=AutoSetRange();
lsUpdate[15]=true;
}
int m=PickMaxChannel();
char temp[15];
_itoa(m,temp,10);
nNumInfo[18]=temp;
_itoa(m_data[m],temp,10);
nNumInfo[17]=temp;
lsUpdate[18]=true;
lsUpdate[17]=true;
nNumInfo[8]="0";
lsUpdate[8]=true;
//光标位置置于ROI区的中心道
_itoa((int)((atoi(nNumInfo[21])+atoi(nNumInfo[20]))/2),temp,10);
nNumInfo[12]=temp;
lsUpdate[12]=true;
_itoa(m_data[(int)((atoi(nNumInfo[21])+atoi(nNumInfo[20]))/2)],temp,10);
nNumInfo[13]=temp;
lsUpdate[13]=true;
GetDocument()->UpdateAllViews(NULL);
// TODO: Add your specialized code here and/or call the base class
}
void CGlobalDisp::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(lsSetROILeft==true&&lsSetROIRight==false)
{
lsSetROILeft=false;
lsSetROIRight=true;
leftPoint=point;
}
else if(lsSetROILeft==false&&lsSetROIRight==true)
{
CRect rect;
GetClientRect(&rect);
lsSetROILeft=false;
lsSetROIRight=false;
lsUpdate[20]=true;
lsUpdate[21]=true;
lsUpdate[22]=true;
if(atoi(Point2Channel(rect,leftPoint))<=atoi(Point2Channel(rect,rightPoint)))
{
nNumInfo[20]=Point2Channel(rect,leftPoint);
nNumInfo[21]=Point2Channel(rect,rightPoint);
}
else
{
nNumInfo[21]=Point2Channel(rect,leftPoint);
nNumInfo[20]=Point2Channel(rect,rightPoint);
}
char temp[15];
_itoa(atoi(nNumInfo[21])-atoi(nNumInfo[20])+1,temp,10);
nNumInfo[22]=temp;
if(nNumInfo[16]=="自动")
{
nNumInfo[15]=AutoSetRange();
lsUpdate[15]=true;
}
//光标位置置于ROI区的中心道
_itoa((int)((atoi(nNumInfo[21])+atoi(nNumInfo[20]))/2),temp,10);
nNumInfo[12]=temp;
lsUpdate[12]=true;
_itoa(m_data[(int)((atoi(nNumInfo[21])+atoi(nNumInfo[20]))/2)],temp,10);
nNumInfo[13]=temp;
lsUpdate[13]=true;
GetDocument()->UpdateAllViews(NULL);
}
CView::OnLButtonDown(nFlags, point);
}
double CGlobalDisp::scalex(CRect rect)//每道多少像素
{
return rect.Width()/(double)256;
}
double CGlobalDisp::scaley(CRect rect)//每计数多少像素
{
if(nNumInfo[15]=="256")return rect.Height()/(double)256;
else if(nNumInfo[15]=="512")return rect.Height()/(double)512;
else if(nNumInfo[15]=="1K")return rect.Height()/(double)1024;
else if(nNumInfo[15]=="2K")return rect.Height()/(double)2048;
else if(nNumInfo[15]=="4K")return rect.Height()/(double)4096;
else if(nNumInfo[15]=="8K")return rect.Height()/(double)8192;
else if(nNumInfo[15]=="16K")return rect.Height()/(double)16384;
else if(nNumInfo[15]=="32K")return rect.Height()/(double)32786;
else if(nNumInfo[15]=="64K")return rect.Height()/(double)65536;
return 0;
}
void CGlobalDisp::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(lsSetROILeft==false&&lsSetROIRight==true)
{
rightPoint=point;
Invalidate(FALSE);
}
CView::OnMouseMove(nFlags, point);
}
CString CGlobalDisp::Point2Channel(CRect rect,CPoint point)
{
int c=(int)((point.x-scalex(rect)/2)/scalex(rect));
char temp[15];
_itoa(c,temp,10);
CString str=temp;
return str;
}
CPoint CGlobalDisp::Channel2Point(CRect rect,CString channel)
{
CPoint point;
point.x=(int)(atoi(channel)*scalex(rect)+scalex(rect)/2);
point.y=0;
return point;
}
CPoint CGlobalDisp::Data2Point(CRect rect,int i)
{
CPoint point;
point.x=(int)(i*scalex(rect)+scalex(rect)/2);
point.y=(int)(rect.Height()-m_data[i]*scaley(rect));
return point;
}
int CGlobalDisp::PickMaxChannel()
{
unsigned int temp=0;
int che=0;
for(int i=atoi(nNumInfo[20]);i<=atoi(nNumInfo[21]);i++)
{
if(temp<m_data[i])
{
che=i;
temp=m_data[i];
}
}
return che;
}
CString CGlobalDisp::AutoSetRange()
{
CString ret;
unsigned int a=m_data[PickMaxChannel()];
if(a<=256)ret="256";
else if(256<a&&a<=512)ret="512";
else if(512<a&&a<=1024)ret="1K";
else if(1024<a&&a<=2048)ret="2K";
else if(2048<a&&a<=4096)ret="4K";
else if(4096<a&&a<=8192)ret="8K";
else if(8192<a&&a<=16384)ret="16K";
else if(16384<a&&a<=32768)ret="32K";
else if(32768<a&&a<=65536)ret="64K";
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -