⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rulewizardview.cpp

📁 实现规则推理 模糊识别 神经网络的专家系统
💻 CPP
字号:
// RuleWizardView.cpp : implementation file
//

#include "stdafx.h"
#include "AcquireKlg.h"
#include "AcquireKlgDoc.h"
#include "MainFrm.h"
#include "Global.h"

//四个视图类头文件
#include "RuleDefineView.h"
#include "NodeTreeView.h"
#include "RuleWizardView.h"
#include "TipView.h"

//#include "Global.h"

extern int nCurStyle;//1:规则推理 2:模糊推理 3:信息融合 4:神经网络
extern CADODatabase GlDataBase;

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

/////////////////////////////////////////////////////////////////////////////
// CRuleWizardView
extern int nCurStyle;

IMPLEMENT_DYNCREATE(CRuleWizardView, CFormView)

CRuleWizardView::CRuleWizardView()
	: CFormView(CRuleWizardView::IDD)
{
	//{{AFX_DATA_INIT(CRuleWizardView)
	//}}AFX_DATA_INIT
}

CRuleWizardView::~CRuleWizardView()
{
}

void CRuleWizardView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRuleWizardView)
	DDX_Control(pDX, IDC_STATIC_2, m_static_2);
	DDX_Control(pDX, IDC_STATIC_1, m_static_1);
	DDX_Control(pDX, IDC_COMBO_mhhs, m_combo_mhhs);
	DDX_Control(pDX, IDC_COMBO_RELATIONOP, m_cRelationOp);
	DDX_Control(pDX, IDC_COMBO_LOGICOP, m_cLogicOp);
	DDX_Control(pDX, IDC_COMBO_DATATYPEE, m_cDtElement);
	DDX_Control(pDX, IDC_PICTURE, m_Picture);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRuleWizardView, CFormView)
	//{{AFX_MSG_MAP(CRuleWizardView)
	ON_BN_CLICKED(IDC_BUTTON_ALTER1, OnButtonAlter1)
	ON_BN_CLICKED(IDC_BUTTON_ALTER2, OnButtonAlter2)
	ON_BN_CLICKED(IDC_BUTTON_ALTER3, OnButtonAlter3)
	ON_CBN_SELENDOK(IDC_COMBO_DATATYPEE, OnSelendokComboDatatypee)
	ON_CBN_SELENDOK(IDC_COMBO_RELATIONOP, OnSelendokComboRelationop)
	ON_CBN_SELENDOK(IDC_COMBO_LOGICOP, OnSelendokComboLogicop)
	ON_CBN_SELENDOK(IDC_COMBO_mhhs, OnSelendokCOMBOmhhs)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRuleWizardView diagnostics

#ifdef _DEBUG
void CRuleWizardView::AssertValid() const
{
	CFormView::AssertValid();
}

void CRuleWizardView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG


void CRuleWizardView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	//m_pRwView = (CRuleWizardView*)GetView(RUNTIME_CLASS(CRuleWizardView)); 
	m_pRdView = (CRuleDefineView*)GetView(RUNTIME_CLASS(CRuleDefineView)); 
	m_pNtView = (CNodeTreeView*)GetView(RUNTIME_CLASS(CNodeTreeView));
	m_pTipView = (CTipView*)GetView(RUNTIME_CLASS(CTipView));
	m_pMainWnd = (CMainFrame*)AfxGetMainWnd();

	
    
	//CAcquireKlgDoc* pDoc = (CAcquireKlgDoc*)GetDocument();
	CADORecordset recordset(&GlDataBase);
	int i,j=4;
	CString str;
	//str.Format("select MAX(层号) from 结点表 where 结点号=%d",j );
	recordset.SetQuery("select * from 条件元件表");
	recordset.Open();
	CString strelement;
	while(recordset.IsEof()!=TRUE){
		recordset.GetFieldValue("条件元内容",strelement);
		m_cDtElement.AddString(strelement);
		recordset.MoveNext();
	}

	m_cLogicOp.SetCurSel(0);
	m_cRelationOp.SetCurSel(0);
	m_cDtElement.SetCurSel(0);
	m_combo_mhhs.SetCurSel(0);
	
  // HBITMAP bm =  (HBITMAP)::LoadImage(NULL, "bmtreefi.bmp",IMAGE_BITMAP,100,160,LR_LOADFROMFILE);

//	BITMAP bm;
//	bitmap.GetBitmap(&bm);
	
	//m_Picture.SetBitmap(bm);
}




/////////////////////////////////////////////////////////////////////////////
// CRuleWizardView message handlers
////////////////////////////自定义函数//////////////////////////////////////////////////

//根据指定的style来设定界面
bool CRuleWizardView::SetCurStyle(int style)
{
	bool bShow = false;
	if(style == nCurStyle)
		return true;
	switch(style){
	case 1:
	  SetDlgItemText(IDC_BUTTON_ALTER1,"模糊推理");
	  SetDlgItemText(IDC_BUTTON_ALTER2,"信息融合");
	  SetDlgItemText(IDC_BUTTON_ALTER3,"神经网络");
	  bShow = true;
	  break;
	case 2:
	  SetDlgItemText(IDC_BUTTON_ALTER1,"规则推理");
	  SetDlgItemText(IDC_BUTTON_ALTER2,"信息融合");
	  SetDlgItemText(IDC_BUTTON_ALTER3,"神经网络");
	  bShow = false;
	  break;
	case 3:
	  SetDlgItemText(IDC_BUTTON_ALTER1,"规则推理");
	  SetDlgItemText(IDC_BUTTON_ALTER2,"模糊推理");
	  SetDlgItemText(IDC_BUTTON_ALTER3,"神经网络");
	  bShow = false;
	  break;
	case 4:
	  SetDlgItemText(IDC_BUTTON_ALTER1,"规则推理");
	  SetDlgItemText(IDC_BUTTON_ALTER2,"模糊推理");
	  SetDlgItemText(IDC_BUTTON_ALTER3,"信息融合");
	   bShow = false;
	  break;
	default:return false;
	}
    nCurStyle = style;
	ShowRegWizard(bShow);
	return true;

}



//根据所按按扭与当前状态来推知下一个状态
int CRuleWizardView::GetNextStyle(int buttonnum)
{
	int nextstyle;
	switch(buttonnum)
	{
	case 1:
		switch(nCurStyle){
		case 1:nextstyle = 2;break;
		case 2:
		case 3:
		case 4:nextstyle = 1;break;
		default:nextstyle = ERR_STYLEOUT;
		}
		break;

	
	case 2:
		switch(nCurStyle){
		case 1:
		case 2:nextstyle = 3;break;
		case 3:
		case 4:nextstyle = 2;break;
		default:nextstyle = ERR_STYLEOUT;
		}
		break;


    case 3:
		switch(nCurStyle){
		case 1:
		case 2:
		case 3:nextstyle = 4;break;
		case 4:nextstyle = 3;break;
		default:nextstyle = ERR_STYLEOUT;
		}
		break;

	
	default:nextstyle = ERR_BUTTONOUT;break;
	}
	return nextstyle;
		
}

//获得指定的视图类指针
CView* CRuleWizardView::GetView(CRuntimeClass* pClass) 
{ 
	CAcquireKlgDoc* pDoc=(CAcquireKlgDoc*)GetDocument();
	ASSERT(pDoc);
	CView* pView = NULL; 
	POSITION pos=pDoc->GetFirstViewPosition(); 
	while(pos!=NULL){ 
		pView=pDoc->GetNextView(pos); 
		if(pView->IsKindOf(pClass)) 
			break;
	} 
	if(!pView->IsKindOf(pClass)){ 
		AfxMessageBox("Can't Locate the View."); 
		return NULL;
	} 
	return pView;
} 



bool CRuleWizardView::SetCorMenu(int index){

	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_REGRULE,MF_UNCHECKED);
	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_BLURRULE,MF_UNCHECKED);
	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_MERGE,MF_UNCHECKED);
	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_NETWORK,MF_UNCHECKED);

	if(index==1)
		m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_REGRULE,MF_CHECKED);
	else if (index==2)
    	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_BLURRULE,MF_CHECKED);
	else if (index==3)
    	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_MERGE,MF_CHECKED);
	else if (index==4)
    	m_pMainWnd->GetMenu()->CheckMenuItem(IDM_FA_NETWORK,MF_CHECKED);
	else
		return false;
	return true;
	
		


	
};


CString CRuleWizardView::GetRegRule(){
	return m_strRegRule;
}

void CRuleWizardView::ClearRegRule(){
	m_strRegRule.Empty();
}

//控制向导区控件是否显示
void CRuleWizardView::ShowRegWizard(bool bShow){
	DWORD dwShow = bShow?SW_SHOW:SW_HIDE;
	/*m_btInsert.ShowWindow(dwShow);
	m_btAnd.ShowWindow(dwShow);
	m_btOr.ShowWindow(dwShow);
	m_btNot.ShowWindow(dwShow);
	m_btlBracket.ShowWindow(dwShow);
	m_btrBlacket.ShowWindow(dwShow);
	m_cListElements.ShowWindow(dwShow);
	*/

	
	
	if(nCurStyle == 2)
	{
		m_Picture.ShowWindow(true);
		m_combo_mhhs.ShowWindow(true);
		m_static_1.ShowWindow(true);
		m_static_2.ShowWindow(false);
		m_cRelationOp.ShowWindow(false);
	}
	else
	{
		m_Picture.ShowWindow(false);
	    m_combo_mhhs.ShowWindow(false);
		m_static_1.ShowWindow(false);
		m_static_2.ShowWindow(true);
		m_cRelationOp.ShowWindow(true);
	}
	

}

//显示相应隶属函数的图象
void CRuleWizardView::ShowImage(CString strname){

	HBITMAP bm =  (HBITMAP)::LoadImage(NULL, strname,IMAGE_BITMAP,160,174,LR_LOADFROMFILE);
    m_Picture.SetBitmap(bm);

}


//用来获取相应COMBOBOX的选中条目并显示
void CRuleWizardView::GetComboSelItem(const CComboBox &cCombox){
//	if(nCurStyle!=1) return;
	
	int index = cCombox.GetCurSel();
	CString strtmp,stmp;
	if(index == CB_ERR ){
		AfxMessageBox("请选择!");
		return;
	}
	cCombox.GetLBText(index,strtmp);

	strtmp.TrimRight();
	
	if(strtmp==""){
			AfxMessageBox("选项不能为空!");
			return;
		}
	int n=strtmp.Find("f",1);
	if (n > 0 )
	 strtmp=strtmp.Mid(n,2);
	
	switch (nCurStyle) {
	   case	1:
	
	m_strRegRule = m_pRdView->GetRegRule();
	
	m_strRegRule+=strtmp;

	m_pRdView->SetRegRule(m_strRegRule);

       break;
	   case 2:
		   m_strRegRule = m_pRdView->GetBlurRule();
		   m_strRegRule.TrimRight();
		   stmp=m_strRegRule.Right(1);
		   if ((m_strRegRule.GetLength()>0)&&(stmp!='&')&&(stmp!='|')&&(strtmp.GetLength()>1))
		   {m_strRegRule=m_strRegRule.Left(m_strRegRule.GetLength()-1);
		   m_strRegRule+=strtmp;
			m_strRegRule+="("+stmp+")";
		   }else
		   {
		   
		   if (m_strRegRule.GetLength()==(m_strRegRule.ReverseFind('f')+2))
			   strtmp="("+strtmp+")";
	       m_strRegRule+=strtmp;
			}
			m_pRdView->SetBlurRule(m_strRegRule);
		   break;
       default:
		return;
		break;
	}
		
}





////////////////////控件的消息函数///////////////////////////////////////
void CRuleWizardView::OnButtonAlter1() 
{
	int index = GetNextStyle(1);
	SetCurStyle(index); //CRuleWizardView中相应界面改变
	m_pRdView->m_cTabSheets.SetCurSel(index-1);//CRuleDefineView中相应界面改变
	
	SetCorMenu(index);

	
	

	
	
}

void CRuleWizardView::OnButtonAlter2() 
{
	int index = GetNextStyle(2);
	SetCurStyle(index);
	m_pRdView->m_cTabSheets.SetCurSel(index-1);
	SetCorMenu(index);

	
}

void CRuleWizardView::OnButtonAlter3() 
{
	int index = GetNextStyle(3);
	SetCurStyle(index);
	m_pRdView->m_cTabSheets.SetCurSel(index-1);
	SetCorMenu(index);
	
}



////////////////CRuleWizardView中的按钮事件////////////////////////////////////////////

void CRuleWizardView::OnSelendokComboDatatypee() 
{

	GetComboSelItem(m_cDtElement);

	
}



void CRuleWizardView::OnSelendokComboRelationop() 
{
	GetComboSelItem(m_cRelationOp);
	m_pRdView->SetRegEditSel();
	
}

void CRuleWizardView::OnSelendokComboLogicop() 
{
	GetComboSelItem(m_cLogicOp);
	
}



void CRuleWizardView::OnSelendokCOMBOmhhs() 
{
	// TODO: Add your control notification handler code here
GetComboSelItem(m_combo_mhhs);
//m_blurview->SetFuncTypeCurSel(0);
m_pRdView->SetBlurFun(m_combo_mhhs.GetCurSel()+1);	
}

⌨️ 快捷键说明

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