📄 matcomplotshowview.cpp
字号:
// matcomplotshowView.cpp : implementation of the CMatcomplotshowView class
//
#include "stdafx.h"
#include "matcomplotshow.h"
#include "matcomplotshowDoc.h"
#include "matcomplotshowView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView
IMPLEMENT_DYNCREATE(CMatcomplotshowView, CView)
BEGIN_MESSAGE_MAP(CMatcomplotshowView, CView)
//{{AFX_MSG_MAP(CMatcomplotshowView)
ON_WM_SIZE()
ON_COMMAND(ID_2DBAR, On2dbar)
ON_COMMAND(ID_3DBAR, On3dbar)
ON_COMMAND(ID_2DAREA, On2darea)
ON_COMMAND(ID_2DCOMPASS, On2dcompass)
ON_COMMAND(ID_3DCONTOUR, On3dcontour)
//}}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)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView construction/destruction
CMatcomplotshowView::CMatcomplotshowView()
{
// TODO: add construction code here
isInit = false;
isTwoPlot=false;
if(!isInit)
{
initM(MATCOM_VERSION);
isInit = true;
}
}
CMatcomplotshowView::~CMatcomplotshowView()
{
}
BOOL CMatcomplotshowView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView drawing
void CMatcomplotshowView::OnDraw(CDC* pDC)
{
CMatcomplotshowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView printing
BOOL CMatcomplotshowView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMatcomplotshowView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMatcomplotshowView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView diagnostics
#ifdef _DEBUG
void CMatcomplotshowView::AssertValid() const
{
CView::AssertValid();
}
void CMatcomplotshowView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMatcomplotshowDoc* CMatcomplotshowView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMatcomplotshowDoc)));
return (CMatcomplotshowDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMatcomplotshowView message handlers
bool CMatcomplotshowView::IsMatcomHandleValid(Mm handle)
{
if(this->isInit)
{
Mm len,isH;
isH = ishandle(handle);
len = length(isH);
if(((int)(len.r(1)))&&((int)(isH.r(1))))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
void CMatcomplotshowView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(isInit)
{
if(!isTwoPlot)
{
if(this->IsMatcomHandleValid(m_h))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = cx;
position.r(4) = cy;
set(m_h,TM("RealPosition"),position);
}
if(this->IsMatcomHandleValid(m_h1))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = 0;
position.r(4) = 0;
set(m_h1,TM("RealPosition"),position);
}
}
else
{
if(this->IsMatcomHandleValid(m_h))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = cx;
position.r(4) = cy/2;
set(m_h,TM("RealPosition"),position);
}
if(this->IsMatcomHandleValid(m_h1))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = cy/2;
position.r(3) = cx;
position.r(4) = cy/2;
set(m_h1,TM("RealPosition"),position);
}
}
}
}
void CMatcomplotshowView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_h1 = winaxes(this ->m_hWnd);
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = 0;
position.r(4) = 0;
set(m_h1,TM("RealPosition"),position);
m_h = winaxes(this->m_hWnd);
m_2ddatax = linspace(0,2*pi,100);
m_2ddata = msin(m_2ddatax);
m_hplot = plot((CL(m_2ddatax),m_2ddata));
axes(CL(m_h1));
m_hplot1 = plot((CL(m_2ddatax),m_2ddata));
set(m_h,TM("NextPlot"),TM("replace"));
set(m_h1,TM("NextPlot"),TM("replace"));
}
/*测试二维数据条形图显示*/
void CMatcomplotshowView::On2dbar()
{
// TODO: Add your command handler code here
if(isInit)
{
if(this->IsMatcomHandleValid(m_h))
{
axes(CL(m_h));
Mm color = zeros(1,3);
color.r(1)=0;
color.r(2)=1;
color.r(2)=1;
ClearData(m_hplot);
m_hplot = bar(m_2ddatax,m_2ddata);
set(m_hplot,TM("color"),color);
axes(CL(m_h1));
ClearData(m_hplot1);
//m_hplot1 = barh(m_2ddatax,m_2ddata,TM("b"));
m_2ddatax = linspace(0,2*pi,50);
m_2ddata = msin(m_2ddatax);
m_hplot1 = barh(m_2ddatax,m_2ddata,TM("b"));
//set(m_hplot1,(CL(TM("FaceColor")),color));
this->isTwoPlot = true;
ResizePlot();
}
}
}
/*测试三维数据条形图显示*/
void CMatcomplotshowView::On3dbar()
{
// TODO: Add your command handler code here
if(isInit)
{
if(this->IsMatcomHandleValid(m_h))
{
axes(CL(m_h));
Mm color = zeros(1,3);
color.r(1)=0;
color.r(2)=1;
color.r(2)=1;
ClearData(m_hplot);
m_hplot = bar3(m_2ddatax,m_2ddata);
set(m_hplot,TM("color"),color);
axes(CL(m_h1));
ClearData(m_hplot1);
set(m_hplot1,TM("color"),color);
m_2ddatax = linspace(0,2*pi,50);
m_2ddata = msin(m_2ddatax);
m_hplot1 = bar3h(m_2ddatax,m_2ddata,TM("b"));
this->isTwoPlot = true;
ResizePlot();
}
}
}
/*重新布置当前MATCOM的图形窗口*/
void CMatcomplotshowView::ResizePlot()
{
if(isInit)
{
CRect rect;
GetClientRect(&rect);
int cx=rect.Width();
int cy=rect.Height();
if(!isTwoPlot)
{
if(this->IsMatcomHandleValid(m_h))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = cx;
position.r(4) = cy;
set(m_h,TM("RealPosition"),position);
}
if(this->IsMatcomHandleValid(m_h1))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = 0;
position.r(4) = 0;
set(m_h1,TM("RealPosition"),position);
}
}
else
{
if(this->IsMatcomHandleValid(m_h))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = 0;
position.r(3) = cx;
position.r(4) = cy/2;
set(m_h,TM("RealPosition"),position);
}
if(this->IsMatcomHandleValid(m_h1))
{
Mm position=zeros(1,4);
position.r(1) = 0;
position.r(2) = cy/2;
position.r(3) = cx;
position.r(4) = cy/2;
set(m_h1,TM("RealPosition"),position);
}
}
}
}
/*清空当前图形窗口缓冲区的数据*/
void CMatcomplotshowView::ClearData(Mm handle)
{
if(isInit)
{
if(this->IsMatcomHandleValid(handle))
{
Mm temp;
set(handle,TM("Xdata"),temp);
set(handle,TM("Ydata"),temp);
set(handle,TM("Zdata"),temp);
}
}
}
/*二维数据阴影显示*/
void CMatcomplotshowView::On2darea()
{
// TODO: Add your command handler code here
if(isInit)
{
if(this->IsMatcomHandleValid(m_h))
{
axes(CL(m_h));
Mm color = zeros(1,3);
color.r(1)=0;
color.r(2)=1;
color.r(2)=1;
ClearData(m_hplot);
m_hplot = area((CL(m_2ddatax),m_2ddata));
set(m_hplot,TM("color"),color);
this->isTwoPlot = false;
ResizePlot();
}
}
}
/*二维数据极坐标显示*/
void CMatcomplotshowView::On2dcompass()
{
// TODO: Add your command handler code here
if(isInit)
{
if(this->IsMatcomHandleValid(m_h))
{
axes(CL(m_h));
Mm color = zeros(1,3);
color.r(1)=1;
color.r(2)=0;
color.r(3)=0;
ClearData(m_hplot);
Mm xdata,ydata;
xdata = zeros(1,4);
ydata = zeros(1,4);
xdata.r(1) = 1;
xdata.r(2) = -2;
xdata.r(3) = 3;
xdata.r(4) = 4;
ydata.r(1) = 4;
ydata.r(2) = -3;
ydata.r(3) = 2;
ydata.r(4) = -1;
//ydata.
m_hplot = compass(xdata,ydata);
set(m_hplot,TM("color"),color);
this->isTwoPlot = false;
ResizePlot();
}
}
}
/*三维数据网格及等高线显示*/
void CMatcomplotshowView::On3dcontour()
{
// TODO: Add your command handler code here
if(isInit)
{
if(this->IsMatcomHandleValid(m_h))
{
axes(CL(m_h));
ClearData(m_hplot);
Mm data=peaks();
m_hplot = mesh(CL(data));
view(10, 0);
this->isTwoPlot = true;
Mm color;
color = zeros(1,3);
color.r(1) = 0;
color.r(2) = 0;
color.r(3) = 1;
set(m_hplot,TM("color"),color);
axes(CL(m_h1));
ClearData(m_hplot1);
m_hplot1 = contour(CL(data));
ResizePlot();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -