myview.cpp
来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 341 行
CPP
341 行
// myview.cpp : implementation file
//
#include "stdafx.h"
#include "richtest.h"
#include "myview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// myview
IMPLEMENT_DYNCREATE(myview, CScrollView)
int atoi16(char*,int);
int current_line=8;
myview::myview()
{//::hight=0;
}
myview::~myview()
{
}
BEGIN_MESSAGE_MAP(myview, CScrollView)
//{{AFX_MSG_MAP(myview)
ON_WM_LBUTTONDBLCLK()
ON_WM_VSCROLL()
ON_WM_MOUSEWHEEL()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// myview drawing
void myview::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 5000;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void myview::OnDraw(CDC* pDC)
{
char bag[3]="12";
int u=atoi16(bag,sizeof(bag));
u=u;
int hight=0;
const CRichtestDoc* pDoc =(CRichtestDoc*) GetDocument();
// TODO: add draw code here
static BOOL b_first=TRUE;
if(b_first)
{
// using namespace Gdiplus;//缺GDIPLUS.*,无法实现
// Graphics graphics(pDC->m_hDC);
// Image image(L"sunset.jpg");
// graphics.DrawImage(&image,0,0,image.GetWidth(),image.GetHeight());
// graphics.ReleaseHDC();
b_first=FALSE;
}
else
{
if(pDoc->current_task==in_data)//当前任务位输入数据
{
if(pDoc->total_count!=0)
{int i;
for(i=0;i<pDoc->total_count;i++)
{
hight=mydata_draw(pDC,pDoc->pdata+i,hight);
}
}
};
if(pDoc->current_task==dig_data)//当前任务位数据挖掘
{ hight=mydata_draw(pDC,pDoc->result,hight);
for(int i=0;i<pDoc->cnt;i++)
{ //pDoc->run_info[i]=pDoc->result[i+1];
pDC->TextOut(0,hight,pDoc->run_info[i]);
hight+=32;
hight=mydata_draw(pDC,pDoc->result+i+1,hight);
}
if(pDoc->error==none)
{
pDC->TextOut(0,hight,"命令执行完毕,无错误发生");
}
else
{
if(pDoc->error==cmdl_error)
pDC->TextOut(0,hight,"命令行错误");
else if(pDoc->error==in_data_error)
pDC->TextOut(0,hight,"输入格式数据错误");
else if(pDoc->error==data_error)
pDC->TextOut(0,hight,"输入数据错误");
else if(pDoc->error==run_error)
{
CString info="致命错误:";
info+=pDoc->cnt+'0';
pDC->TextOut(0,hight,info+" 级模块无效或者不存在");
}
}
}
if(pDoc->current_task==bp_diagnose)//当前任务是bp网络故障诊断
{
hight=mydata_draw(pDC,(mydata*)&(pDoc->bp_diagnose_result),hight);
}
//this->hight=hight;
// if(pDoc->current_task==graph)//当前任务是bp网络故障诊断
// {
// hight=mydata_draw(pDC,(mydata*)&(pDoc->bp_diagnose_result),hight);
// }
}
// double h[9]={1,2,3,4,5,6,7,8,9};
// mwArray q(3,3,h);
// hight=matrix_draw(pDC,&q,hight);
}
int myview::mydata_draw(CDC *pDC, mydata *data,int hight)
{if(data->empty==TRUE)
return hight;
CString info="信息 :";
CString content(data->buffer);
info+=content;
char* buf=info.GetBuffer(4);
pDC->TextOut(0,hight,info);
hight+=16;
info="类型:";
if(data->the_type==type_char)
{ content="字符";
}
else if(data->the_type==type_short)
{ content="双字";
}
else if(data->the_type==type_int)
{ content="整数";
}
else if(data->the_type==type_dou)
{ content="小数";
}
else if(data->the_type==type_mw)
{ content="矩阵";
}
else if(data->the_type==type_info)
{
for(unsigned int i=0;i<data->the_length;i++)
{
pDC->TextOut(0,hight,*(data->info+i));
hight+=16;
}
goto endp;
}
info+=content;
pDC->TextOut(0,hight,info);
hight+=16;
info="数量:";
content.Format("%d",data->the_length);
info+=content;
pDC->TextOut(0,hight,info);
hight+=16;
if(data->the_type==type_mw)
{int i;
for(i=0;i<data->the_length;i++)
{
hight= matrix_draw(pDC,i+1,data->pdata.mw+i,hight,data->matrix_name[i],data->name_length[i]);
}
//return hight;
}
else{info="数据:";
for(int i=0;i<data->the_length;i++)
{ if(data->the_type==type_char)
content.Format("%d,",*(data->pdata.ch+i));
else if(data->the_type==type_short)
content.Format("%d,",*(data->pdata.sh+i));
else if(data->the_type==type_int)
content.Format("%d,",*(data->pdata.in+i));
else if(data->the_type==type_dou)
content.Format("%f,",*(data->pdata.dou+i));
info+=content;
}
pDC->TextOut(0,hight,info);
hight+=16;
}
endp:
return hight+32;
}
int myview::matrix_draw(CDC* pDC,int num,mwArray* in,int hight,char *name,int length)
{CString line,theone;
int i,j,l;
//CRunTimeClass obx=RUNTIME_CLASS(mxArray),obw=RUNTIME_CLASS(mwArray),obdata=RUNTIME_CLASS(mydata);
// if(RUNTIME_CLASS(T)==obx) ;
// else(RUNTIME_CLASS(T)==obw) ;
// else(RUNTIME_CLASS(T)==obdata)
// else;
CString info="矩阵";
CString snum;
snum.Format("%d",num);
info+=snum;
info+=":";
CString content(name,length);
info+=content;
pDC->TextOut(0,hight,info);
info+=' ';
hight+=16;
info.Empty();
int dim_count=in->Size();
if(dim_count>3)
{AfxMessageBox("矩阵最大三维");
return hight;
};
int* dim=new int[3];
for(i=1;i<=dim_count;i++)
*(dim+i-1)=in->Size(i);
if(dim_count<=2)
*(dim+2)=1;
info+="行列: ";
content.Format("%d,",*dim);
info+=content;
content.Format("%d",*(dim+1));
info+=content;
pDC->TextOut(0,hight,info);
hight+=16;
info.Empty();
double* bagr=new double[*dim*(*(dim+1))*(*(dim+1))];
double* bagi=new double[*dim*(*(dim+1))*(*(dim+1))];
in->ExtractData(bagr,bagi);
for(l=1;l<=*(dim+2);l++)
for(i=1;i<=*dim;i++)
{line.Empty();
for(j=1;j<=*(dim+1);j++)
{theone.Empty();
theone.Format("%f",*(bagr+(l-1)*(*(dim+1))*(*(dim+1))+(i-1)*(*(dim+1))+j-1));
line+=theone;
if(*(bagi+(l-1)*(*(dim+1))*(*(dim+1))+(i-1)*(*(dim+1))+j-1)!=0.0)
{theone.Format("%f",*(bagi+(l-1)*(*(dim+1))*(*(dim+1))+(i-1)*(*(dim+1))+j-1));
if(*(bagi+(l-1)*(*(dim+1))*(*(dim+1))+(i-1)*(*(dim+1))+j-1)<0)
line+='-';
else
line+='+';
line+=theone;
line+='i';
}
theone.Format(" ");
line+=theone;
}
pDC->TextOut(0,hight,line);
hight+=16;
}
delete[] dim;
delete[] bagr;
delete[] bagi;
return hight+16;
}
/////////////////////////////////////////////////////////////////////////////
// myview diagnostics
#ifdef _DEBUG
void myview::AssertValid() const
{
CScrollView::AssertValid();
}
void myview::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// myview message handlers
void myview::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnLButtonDblClk(nFlags, point);
}
void myview::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}
BOOL myview::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
return CScrollView::OnMouseWheel(nFlags, zDelta, pt);
}
void myview::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnRButtonDown(nFlags, point);
}
void myview::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnRButtonUp(nFlags, point);
}
void myview::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CScrollView::OnMouseMove(nFlags, point);
}
void myview::node_info_out(char *info)
{static int hight=0;
CDC* pDC=this->GetDC();
pDC->TextOut(0,hight,info);
hight+=16;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?