showdataview.cpp

来自「某个实验事编写粗糙集智能信息处理的程序」· C++ 代码 · 共 467 行

CPP
467
字号
 // ShowDataView.cpp : implementation file
//

#include "stdafx.h"
#include "RSet.h"
#include "ShowDataView.h"

#include "showprogressdlg.h"

//#include "showdatadoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CShowDataView

IMPLEMENT_DYNCREATE(CShowDataView, CView)

CShowDataView::CShowDataView()
{
	m_pShowProgressDlg=new CShowProgressDlg(this);
}

CShowDataView::~CShowDataView()
{
	delete m_pShowProgressDlg;
}


BEGIN_MESSAGE_MAP(CShowDataView, CView)
	//{{AFX_MSG_MAP(CShowDataView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowDataView drawing

void CShowDataView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CShowDataView diagnostics

#ifdef _DEBUG
void CShowDataView::AssertValid() const
{
	CView::AssertValid();
}


void CShowDataView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG
CShowDataDoc* CShowDataView::GetDocument()
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShowDataDoc)));
	return (CShowDataDoc*)m_pDocument;
}

/////////////////////////////////////////////////////////////////////////////
// CShowDataView message handlers


int CShowDataView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	CRect rect(0,0,0,0);
	if(m_grid.Create(NULL,WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW,rect,this,IDC_GRID)==FALSE)
	{
		MessageBox("Can't create flexgrid!");
		return -1;
	}
	m_grid.SetColAlignment(0,4);
   	m_grid.SetAllowUserResizing(3);
	m_grid.SetBackColor(0x00ffffff);
	m_grid.SetBackColorBkg(0x00FFFFFF);
	return 0;
}

void CShowDataView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	CRect rect;
	GetClientRect(&rect);
	m_grid.MoveWindow(&rect);
	
}

void CShowDataView::OnInitialUpdate() 
{
	CMSFlexGrid& grid=m_grid;
	CShowDataDoc* pDoc=(CShowDataDoc*)GetDocument();
	ifstream in;
	in.open(pDoc->GetPathName());
	if(!in)
	{
		AfxMessageBox("Can't open the file!");
		return;
	}
	if(!pDoc->ReadFileHeader(in))		//read file header
	{
		in.close();
		return ;
	}

	
	//---------------display the data of the file=-----------------------

	if(stricmp(pDoc->GetStyle(),"train")==0 || stricmp(pDoc->GetStyle(),"test")==0 )
		ShowTrainFile(in,grid);
	else if(stricmp(pDoc->GetStyle(),"input")==0)
		ShowInputFile(in,grid);
	else if(stricmp(pDoc->GetStyle(),"rule")==0)
		ShowRuleFile(in,grid);
	else if(stricmp(pDoc->GetStyle(),"result")==0)
		ShowResultFile(in,grid);

	in.close();

	
}


BOOL CShowDataView::ShowTrainFile(ifstream &in,CMSFlexGrid& grid)
{
	char buf[256];
	CString strTemp;
	CShowDataDoc* pDoc=GetDocument();
	grid.SetCols(pDoc->GetAttrNum()+2);
	grid.SetRows(pDoc->GetRecordNum()+1);
	for( int i=0;i<grid.GetCols();i++)
	{
		grid.SetColAlignment(i,1);
		grid.SetColWidth(i,1000);
	}
	grid.SetRow(0);			//row 0 of the grid
	for(i=0;i<pDoc->GetAttrNum()+1;i++)
	{
		grid.SetCol(i+1);
		grid.SetText(pDoc->GetAttrName()[i]);
	}
///*
	if(m_pShowProgressDlg->GetSafeHwnd()==0)
	{
		m_pShowProgressDlg->Create();
		m_pShowProgressDlg->ShowWindow(SW_NORMAL);
		m_pShowProgressDlg->CenterWindow();
		m_pShowProgressDlg->UpdateWindow();
	}
	int totallength=pDoc->GetRecordNum();
	
//*/
	for(i=0;i<pDoc->GetRecordNum();i++)
	{
		grid.SetRow(i+1);
		grid.SetCol(0);
		strTemp.Format("%d",i+1);
		grid.SetText(strTemp);
		for(int j=0;j<pDoc->GetAttrNum()+1;j++)		//condition attributes
		{
			grid.SetCol(j+1);
			in>>buf;
			grid.SetText(buf);
			if(pDoc->IsComplete() && (stricmp(buf,"?")==0 || stricmp(buf,"-")==0)) 
				pDoc->SetComplete(false);
		}
		m_pShowProgressDlg->SetPosition(i*100/totallength);
//		m_pShowProgressDlg->PostMessage(WM_KYLIN_PROGRESS,i*100/totallength,0); //
	}
	m_pShowProgressDlg->DestroyWindow();
	return TRUE;
}



BOOL CShowDataView::ShowInputFile(ifstream &in,CMSFlexGrid& grid)
{
	char buf[256];
	CString strTemp;
	CShowDataDoc* pDoc=GetDocument();

	grid.SetCols(pDoc->GetAttrNum()+1);
	grid.SetRows(pDoc->GetRecordNum()+1);
	for( int i=0;i<grid.GetCols();i++)
	{
		grid.SetColAlignment(i,1);
		grid.SetColWidth(i,1000);
	}
	grid.SetRow(0);			//row 0 of the grid,头部
	for( i=0;i<pDoc->GetAttrNum();i++)
	{
		grid.SetCol(i+1);
		grid.SetText(pDoc->GetAttrName()[i]);
	}
	// show the progress dialog
	if(m_pShowProgressDlg->GetSafeHwnd()==0)
	{
		m_pShowProgressDlg->Create();
		m_pShowProgressDlg->ShowWindow(SW_NORMAL);
		m_pShowProgressDlg->CenterWindow();
		m_pShowProgressDlg->UpdateWindow();
	}
	int totallength=pDoc->GetRecordNum();

	for(i=0;i<pDoc->GetRecordNum();i++)
	{
		grid.SetRow(i+1);
		grid.SetCol(0);
		strTemp.Format("%d",i+1);
		grid.SetText(strTemp);
		for(int j=0;j<pDoc->GetAttrNum();j++)		//condition attributes
		{
			grid.SetCol(j+1);
			in>>buf;
			grid.SetText(buf);
		}
		// update progress bar
		m_pShowProgressDlg->SetPosition(i*100/totallength);

	}
	// destroy progress bar 
	m_pShowProgressDlg->DestroyWindow();

	return TRUE;
}

BOOL CShowDataView::ShowResultFile(ifstream &in,CMSFlexGrid& grid)
{

	char buf[256];
	CString strTemp;
	CShowDataDoc* pDoc=GetDocument();

	if(pDoc->GetStage()==1)	//识别产生的文件
	{
		grid.SetCols(pDoc->GetAttrNum()+3);
		grid.SetRows(pDoc->GetRecordNum()+1);
		for( int i=0;i<grid.GetCols();i++)
		{
			grid.SetColAlignment(i,1);
			grid.SetColWidth(i,1000);
		}
		grid.SetRow(0);			//row 0 of the grid
		for( i=0;i<pDoc->GetAttrNum()+1;i++)
		{
			grid.SetCol(i+1);
			grid.SetText(pDoc->GetAttrName()[i]);
		}
		grid.SetCol(pDoc->GetAttrNum()+1);
		grid.SetText("识别值");
		grid.SetCol(pDoc->GetAttrNum()+2);
		grid.SetText("所用规则");
		// show the progress dialog
		if(m_pShowProgressDlg->GetSafeHwnd()==0)
		{
			m_pShowProgressDlg->Create();
			m_pShowProgressDlg->ShowWindow(SW_NORMAL);
			m_pShowProgressDlg->CenterWindow();
			m_pShowProgressDlg->UpdateWindow();
		}
		int totallength=pDoc->GetRecordNum();

		for(i=0;i<pDoc->GetRecordNum();i++)
		{
			grid.SetRow(i+1);
			grid.SetCol(0);
			strTemp.Format("%d",i+1);
			grid.SetText(strTemp);
			for(int j=0;j<pDoc->GetAttrNum()+2;j++)		//condition attributes
			{
				grid.SetCol(j+1);
				in>>buf;
				grid.SetText(buf);
			}
			// update progress bar
			m_pShowProgressDlg->SetPosition(i*100/totallength);

		}
		// destroy progress bar
		m_pShowProgressDlg->DestroyWindow();
		return true;	
	}
	
	else		//测试产生的文件
	{
		grid.SetCols(pDoc->GetAttrNum()+4);
		grid.SetRows(pDoc->GetRecordNum()+7);
		for( int i=0;i<grid.GetCols();i++)
		{
			grid.SetColAlignment(i,1);
			grid.SetColWidth(i,1000);
		}
		grid.SetRow(0);
		for(i=0;i<pDoc->GetAttrNum()+1;i++)
		{
			grid.SetCol(i+1);
			grid.SetText(pDoc->GetAttrName()[i]);
		}
		grid.SetCol(pDoc->GetAttrNum()+2);
		grid.SetText("识别值");
		grid.SetCol(pDoc->GetAttrNum()+3);
		grid.SetText("所用规则");
		
		if(m_pShowProgressDlg->GetSafeHwnd()==0)
		{
			m_pShowProgressDlg->Create();
			m_pShowProgressDlg->ShowWindow(SW_NORMAL);
			m_pShowProgressDlg->CenterWindow();
			m_pShowProgressDlg->UpdateWindow();
		}
		int totallength=pDoc->GetRecordNum();

		for(i=0;i<pDoc->GetRecordNum();i++)
		{
			grid.SetRow(i+1);
			grid.SetCol(0);
			strTemp.Format("%d",i+1);
			grid.SetText(strTemp);
			for(int j=0;j<pDoc->GetAttrNum()+3;j++)		//condition attributes
			{
				grid.SetCol(j+1);
				in>>buf;
				grid.SetText(buf);
			}
			// update progress bar
			m_pShowProgressDlg->SetPosition(i*100/totallength);

		}
		
		
		grid.SetRow(pDoc->GetRecordNum()+1);
		grid.SetCol(0);
		grid.SetText("正确识别数");
		grid.SetCol(1);
		in.getline(buf,256,':');
		in>>buf;
		grid.SetText(buf);
		grid.SetRow(pDoc->GetRecordNum()+2);
		grid.SetCol(0);
		grid.SetText("错误识别数");
		grid.SetCol(1);
		in.getline(buf,256,':');

		in>>buf;
		grid.SetText(buf);
		grid.SetRow(pDoc->GetRecordNum()+3);
		grid.SetCol(0);
		grid.SetText("未识别数");
		grid.SetCol(1);
				in.getline(buf,256,':');
in>>buf;
		grid.SetText(buf);
		grid.SetRow(pDoc->GetRecordNum()+4);
		grid.SetCol(0);
		grid.SetText("冲突样本数");
		grid.SetCol(1);
			in.getline(buf,256,':');
	in>>buf;
		grid.SetText(buf);
		grid.SetRow(pDoc->GetRecordNum()+5);
		grid.SetCol(0);
		grid.SetText("决策正确数");
		grid.SetCol(1);
		in.getline(buf,256,':');
		in>>buf;
		grid.SetText(buf);
		grid.SetRow(pDoc->GetRecordNum()+6);
		grid.SetCol(0);
		grid.SetText("决策错误数");
		grid.SetCol(1);
		in.getline(buf,256,':');
		in>>buf;
		grid.SetText(buf);
		// destroy progress bar
		m_pShowProgressDlg->DestroyWindow();

		return TRUE;
	}
}

BOOL CShowDataView::ShowRuleFile(ifstream &in,CMSFlexGrid& grid)
{
	char buf[256];
	CString strTemp;
	CShowDataDoc* pDoc=GetDocument();
	grid.SetCols(pDoc->GetAttrNum()+5);
	grid.SetRows(pDoc->GetRecordNum()+1+pDoc->GetBlockNum());
	for( int i=0;i<grid.GetCols();i++)
	{
		grid.SetColAlignment(i,1);
		grid.SetColWidth(i,1000);
	}
	grid.SetRow(0);			//row 0 of the grid
	for(i=0;i<pDoc->GetAttrNum()+1;i++)
	{
		grid.SetCol(i+1);
		grid.SetText(pDoc->GetAttrName()[i]);
	}
	grid.SetCol(pDoc->GetAttrNum()+2);
	grid.SetText("可信度");
	grid.SetCol(pDoc->GetAttrNum()+3);
	grid.SetText("覆盖度");
	grid.SetCol(pDoc->GetAttrNum()+4);
	grid.SetText("分类数");

	if(m_pShowProgressDlg->GetSafeHwnd()==0)
	{
		m_pShowProgressDlg->Create();
		m_pShowProgressDlg->ShowWindow(SW_NORMAL);
		m_pShowProgressDlg->CenterWindow();
		m_pShowProgressDlg->UpdateWindow();
	}
	int totallength=pDoc->GetRecordNum()+pDoc->GetBlockNum();

	for(i=0;i<pDoc->GetRecordNum();i++)
	{
		grid.SetRow(i+1);
		grid.SetCol(0);
		strTemp.Format("%d",i+1);
		grid.SetText(strTemp);
		for(int j=0;j<pDoc->GetAttrNum()+4;j++)		//condition attributes
		{
			grid.SetCol(j+1);
			in>>buf;
			grid.SetText(buf);
		}
		// update progress bar
		m_pShowProgressDlg->SetPosition(i*100/totallength);

	}
	
	in.getline(buf,256); //filter [block]
	in.getline(buf,256); //filter [block]

	for(i=0;i<pDoc->GetBlockNum();i++)
	{
		grid.SetRow(i+pDoc->GetRecordNum()+1);
		grid.SetCol(0);
		strTemp.Format("%d",i+1);
		grid.SetText(strTemp);
		
		for(int j=0;j<pDoc->GetAttrNum()+1;j++)
		{
			grid.SetCol(j+1);
			in>>buf;
			grid.SetText(buf);
		}
		m_pShowProgressDlg->SetPosition( (i+pDoc->GetRecordNum())*100/totallength);
	}

	m_pShowProgressDlg->DestroyWindow();
	return TRUE;
}

⌨️ 快捷键说明

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