richtestdoc.cpp
来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 609 行
CPP
609 行
// richtestDoc.cpp : implementation of the CRichtestDoc class
//
#include "stdafx.h"
#include "richtest.h"
#include "richtestDoc.h"
#include "CntrItem.h"
#include "SrvrItem.h"
#include "Cadview.h"
#define MAXEMBEDCMD 100
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "richtestView.h"
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc
extern CRichtestDoc* thedoc;
extern Imyplot* iplot;
extern int current_line;
extern UINT g_nCurTask;
IMPLEMENT_DYNCREATE(CRichtestDoc, CRichEditDoc)
BEGIN_MESSAGE_MAP(CRichtestDoc, CRichEditDoc)
//{{AFX_MSG_MAP(CRichtestDoc)
ON_COMMAND(ID_DATA_INPUT, OnDataInput)
ON_COMMAND(ID_CALCULATOR, OnCalculator)
ON_COMMAND(ID_DATA_EXPLORE, OnDataExplore)
ON_UPDATE_COMMAND_UI(ID_DATA_EXPLORE, OnUpdateDataExplore)
ON_COMMAND(ID_BP_EXCERCIZE, OnBpExcercize)
ON_UPDATE_COMMAND_UI(ID_BP_EXCERCIZE, OnUpdateBpExcercize)
ON_COMMAND(ID_M_DIAGNOSE, OnMDiagnose)
ON_UPDATE_COMMAND_UI(ID_M_DIAGNOSE, OnUpdateMDiagnose)
ON_COMMAND(ID_BP_CREATE, OnBpCreate)
ON_UPDATE_COMMAND_UI(ID_BP_CREATE, OnUpdateBpCreate)
ON_COMMAND(ID_REEXCERSIZE, OnReexcersize)
ON_UPDATE_COMMAND_UI(ID_REEXCERSIZE, OnUpdateReexcersize)
ON_COMMAND(ID_GRAPH_CREATE, OnGraphCreate)
ON_UPDATE_COMMAND_UI(ID_GRAPH_CREATE, OnUpdateGraphCreate)
ON_COMMAND(ID_GRAPH_TEST, OnGraphTest)
ON_UPDATE_COMMAND_UI(ID_GRAPH_TEST, OnUpdateGraphTest)
ON_COMMAND(ID_GRAPH_RUN, OnGraphRun)
ON_UPDATE_COMMAND_UI(ID_GRAPH_RUN, OnUpdateGraphRun)
//}}AFX_MSG_MAP
// Enable default OLE container implementation
ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, CRichEditDoc::OnUpdateEditLinksMenu)
ON_COMMAND(ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks)
ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc construction/destruction
CRichtestDoc::CRichtestDoc()
{
// Use OLE compound files
EnableCompoundFile();
// TODO: add one-time construction code here
cnt=0;
current_task=calt;
error=none;
b_from_file=TRUE;
count_limit=COUNT_LIMIT;
pdata=new mydata[COUNT_LIMIT];
result=new mydata[PROCESS_CNT+1];
total_count=0;
streamline=mydata(PROCESS_CNT,type_com,NULL);
bgraph=0;
bbpnet=0;
}
CRichtestDoc::~CRichtestDoc()
{if(pdata!=NULL)
delete[] pdata;
pdata=0;
delete[] result;
result=0;
pcmd=0;
}
BOOL CRichtestDoc::OnNewDocument()
{
if (!CRichEditDoc::OnNewDocument())
return FALSE;
//if(!find_attach_moudle())
//AfxMessageBox("错误的模块定义文件");
thedoc=this;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
CRichEditCntrItem* CRichtestDoc::CreateClientItem(REOBJECT* preo) const
{
// cast away constness of this
return new CRichtestCntrItem(preo, (CRichtestDoc*) this);
}
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc server implementation
COleServerItem* CRichtestDoc::OnGetEmbeddedItem()
{
// OnGetEmbeddedItem is called by the framework to get the COleServerItem
// that is associated with the document. It is only called when necessary.
CRichtestSrvrItem* pItem = new CRichtestSrvrItem(this);
ASSERT_VALID(pItem);
return pItem;
}
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc serialization
void CRichtestDoc::Serialize(CArchive& ar)
{ CString docname(lpszPathName);
streamline.Serialize(ar);
docname+=".mat";
char* head=docname.GetBuffer(4);
if (ar.IsStoring())
{ ar<<bgraph;
ar<<bbpnet;
if(bbpnet)
{ofstream os(head,ios::out);
for(int i=0;i<PROCESS_CNT+1;i++)//输出诊断结果
{ result[i].os=os;
result[i].Serialize(ar);
}
ar<<total_count;
for(i=0;i<total_count;i++)//输出输入数据
{pdata[i].os=os;
pdata[i].Serialize(ar);
};
bpnet.os=os;//输出bp网络数据
bpnet.Serialize(ar);
mwArray ENDS;
os<<ENDS<<ends;
os.close();
}
// TODO: add storing code here
}
else
{ ar>>bgraph;
ar>>bbpnet;
if(bbpnet)
{ifstream is(head,ios::in);
for(int i=0;i<PROCESS_CNT+1;i++)
{ result[i].is=is;
result[i].Serialize(ar);
}
ar>>total_count;
for(i=0;i<total_count;i++)
{pdata[i].is=is;
pdata[i].Serialize(ar);
}
bpnet.is=is;//输入bp网络数据
bpnet.Serialize(ar);
bpnet0=bpnet;
is.close();
}
// TODO: add loading code here
}
if(bgraph)
graph.Serialize(ar);
int cccc=0;
// Calling the base class CRichEditDoc enables serialization
// of the container document's COleClientItem objects.
// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
//CRichEditDoc::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc diagnostics
#ifdef _DEBUG
void CRichtestDoc::AssertValid() const
{
CRichEditDoc::AssertValid();
}
void CRichtestDoc::Dump(CDumpContext& dc) const
{
CRichEditDoc::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRichtestDoc commands
CRichEditView* CRichtestDoc::geteditor()
{
POSITION head=this->GetFirstViewPosition();
CRichEditView* editor=(CRichEditView*)this->GetNextView(head);
editor=(CRichEditView*)this->GetNextView(head);
editor=(CRichEditView*)this->GetNextView(head);
return editor;
}
int myitoa(char* bag,int in)
{int i=1000,j,k,l=0;
for(j=0;j<4;j++)
{
k=in/i;
if(k>0)
*(bag+l++)=k+'0';
in=in-in/i*i;
i/=10;
}
return l;
}
void CRichtestDoc::OnDataInput()
{ current_task=in_data;
CRichEditView* editor=(CRichEditView*)geteditor();
editor2numric one(pdata,editor);
total_count=one.InputData();
// viberation vvv1(pdata,pdata+1,pdata+2,pdata+3,4);
//static mydata bag;
//viberation vvv(pdata,&bag);
// if(!vvv.go())
// AfxMessageBox("输入数据数量错误");
// this->attach(bag);
this->UpdateAllViews(0);
//current_task=calt;
// double r[5],im[5];
//bag.ExtractData(r,im);
// vvv1.go(&bag);
// bag.mw->ExtractData(r,im);
int i;
i=0;
error=none;
}
mydata* CRichtestDoc::sendbag() const
{
return pdata;
}
//DEL void CRichtestDoc::setcount(int in_count)
//DEL {
//DEL total_count=in_count;
//DEL }
void CRichtestDoc::OnCalculator()
{
// TODO: Add your command handler code here
calculatordlg dlg(NULL,pdata,total_count);
dlg.DoModal();
}
//DEL void CRichtestDoc::send(mydata *pdata, int count)
//DEL {
//DEL
//DEL }
myform* CRichtestDoc::getform()
{
POSITION head=this->GetFirstViewPosition();
myform* editor=(myform*)this->GetNextView(head);
editor=(myform*)this->GetNextView(head);
return editor;
}
LRESULT CRichtestDoc::runcmd(unsigned int* cnt)
{
//CString info;
for(int i=0;i<PROCESS_CNT;i++)
{
if(SUCCEEDED(streamline.pcom[i].go(result+i,conector_id+i,1)))
{ run_info[i].Empty();
run_info[i]+='0'+i;
run_info[i]+="级模块: ";
// run_info[i]+=streamline.pcom[i].get_run_info();
//AfxMessageBox(info);
//info.Empty();
*cnt=i+1;
int kkk=0;
}
else
return S_FALSE;
}
return S_OK;
}
void CRichtestDoc::attach(mydata in)
{
*(pdata+(total_count++)+MAXEMBEDCMD)=in;
}
//DEL void CRichtestDoc::add_moudle(char* name,int name_length,char* info,int info_length,char* where,int size)
//DEL {
//DEL (pcmd+cmd_count)->attach(cmd_count,name,name_length,info,info_length,where,size);
//DEL cmd_count++;
//DEL }
//DEL BOOL CRichtestDoc::find_attach_moudle()
//DEL {readmoduleinfo item(pcmd+cmd_count,cmd_count++);
//DEL return(item.InputData());
//DEL }
BOOL CRichtestDoc::OnSaveDocument(LPCTSTR lpszPathName)
{ cmd_text=CString(lpszPathName);
this->lpszPathName=cmd_text;
CRichtestView* editor=(CRichtestView*)geteditor();
// TODO: Add your specialized code here and/or call the base class
CString cmd_text_name=cmd_text+".txt";
CFile* filebin=new CFile(cmd_text_name,CFile::modeCreate|CFile::modeWrite);
CArchive ar1(filebin,CArchive::store);
if(editor)
editor->Serialize(ar1);
ar1.Close();
filebin->Close();
if (!CRichEditDoc::OnSaveDocument(lpszPathName))
return FALSE;
return TRUE;
}
BOOL CRichtestDoc::OnOpenDocument(LPCTSTR lpszPathName)
{ CRichtestView* editor=(CRichtestView*)geteditor();
cmd_text=CString(lpszPathName);
this->lpszPathName=cmd_text;
CString cmd_text_name=cmd_text+".txt";
CFile* filebin=new CFile(cmd_text_name,CFile::modeRead);
int lth=filebin->GetLength();
CArchive ar1(filebin,CArchive::load);
if (!CRichEditDoc::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
if(editor)
editor->Serialize(ar1);
ar1.Close();
filebin->Close();// loading code
return TRUE;
}
BOOL CRichtestDoc::get_cmd()
{
CRichEditView* editor=(CRichEditView*)geteditor();
readcommand item(&streamline,editor,PROCESS_CNT);
unsigned int* temp=item.get_conector();
if(!item.input())
return FALSE;
for(int i=0;i<PROCESS_CNT;i++)
conector_id[i]=temp[i];
b_from_file=item.is_from_file();
return TRUE;
}
void CRichtestDoc::OnDataExplore()
{ // TODO: Add your command handler code here
current_task=dig_data;
if(get_cmd())
{
if(b_from_file)
{
if(read_data())
{
if(runcmd(&cnt)==0)
{ int i=0;
this->UpdateAllViews(0);
}
else
{
error=run_error;
}
}
else
error=in_data_error;
}
else
{
if(get_data())
{
if(runcmd(&cnt)==0)
{ int i=0;
this->UpdateAllViews(0);
}
else
error=run_error;
}
else
error=in_data_error;
}
}
else
error=cmdl_error;
this->UpdateAllViews(0);
// current_task=calt;
}
void CRichtestDoc::OnUpdateDataExplore(CCmdUI* pCmdUI)
{
CDocument it;
// TODO: Add your command update UI handler code here
}
BOOL CRichtestDoc::read_data()
{
readdata item(result,lpszPathName);
return item.input();
}
//DEL BOOL CRichtestDoc::is_from_file()
//DEL {
//DEL return TRUE;
//DEL }
BOOL CRichtestDoc::get_data()
{
CRichEditView* editor=(CRichEditView*)geteditor();
editor2numric one(result,editor);
total_count=one.InputData();
return TRUE;
}
BOOL CRichtestDoc::create(int net_type,unsigned int type, double stderror,unsigned int info[])//创建BP或小波网络
{
if(type==0)
{
if(bpnet.create((bp_net_type)net_type,info[0],info[1],info[2],(bp_node_type)info[3],\
stderror,info+4))
{
bpnet0=bpnet;
bbpnet=TRUE;
}
return TRUE;
}
else
return FALSE;
}
void CRichtestDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)
{
// TODO: Add your specialized code here and/or call the base class
CRichEditDoc::SetPathName(lpszPathName, bAddToMRU);
}
void CRichtestDoc::OnBpExcercize()
{
// TODO: Add your command handler code here
// bpnet=bpnet0;
bpnet.excersize();
}
void CRichtestDoc::OnUpdateBpExcercize(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bpnet.isvalid())
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CRichtestDoc::OnMDiagnose()
{
// TODO: Add your command handler code here
current_task=bp_diagnose;
const CString* result;
CString* info;
int ginfo_lth;
unsigned int cnt,index[100];
double error[100];
char bag[]={0,0,0};
char dbag[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
if(bpnet.diagnose(&result,&cnt,index,error))
{CString ginfo="待诊断数据共计";
gcvt(cnt,2,bag);
ginfo+=bag[0];
if(cnt>9)
ginfo+=bag[1];
ginfo+="组,诊断结果如下:\n";
ginfo_lth=ginfo.GetLength();
info=new CString[cnt];
for(unsigned int i=0;i<cnt;i++)
{info[i].Empty();
unsigned int lth=(result+index[i])->GetLength();
for(unsigned int j=0;j<lth;j++)
info[i]+=(result+index[i])->GetAt(j);
info[i]+="诊断误差:";
double it=int(error[i]*10000)/10000.0;
gcvt(it,15,dbag);
for(unsigned int c=0;c<14;c++)
info[i]+=dbag[c];
info[i]+='\n';
memset(dbag,0,15);
}
bp_diagnose_result=mydata(ginfo.GetBuffer(1),ginfo_lth,info,cnt);
this->UpdateAllViews(0);
}
}
void CRichtestDoc::OnUpdateMDiagnose(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bpnet.istrained())
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CRichtestDoc::OnBpCreate()
{
// TODO: Add your command handler code here
CCadView* pcad=getcad();
pcad->create_bp_net(0,CPoint(0,0));
}
void CRichtestDoc::OnUpdateBpCreate(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
CCadView* CRichtestDoc::getcad()
{
POSITION head=this->GetFirstViewPosition();
CCadView* editor=(CCadView*)this->GetNextView(head);
editor=(CCadView*)this->GetNextView(head);
return editor;
}
myview* CRichtestDoc::getview()
{
POSITION head=this->GetFirstViewPosition();
myview* editor=(myview*)this->GetNextView(head);
return editor;
}
void CRichtestDoc::OnReexcersize()
{
// TODO: Add your command handler code here
bpnet.excersize();
}
void CRichtestDoc::OnUpdateReexcersize(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bpnet.istrained())
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CRichtestDoc::OnGraphCreate()
{
// TODO: Add your command handler code here
g_nCurTask=ID_DRAW_CIRCLE;
}
void CRichtestDoc::OnUpdateGraphCreate(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CRichtestDoc::OnGraphTest()
{
// TODO: Add your command handler code here
graph.test();
}
void CRichtestDoc::OnUpdateGraphTest(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(!graph.empty)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CRichtestDoc::OnGraphRun()
{
// TODO: Add your command handler code here
graph.run();
}
void CRichtestDoc::OnUpdateGraphRun(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(graph.bvalid)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?