📄 clipsdlg.cpp
字号:
// ClipsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "clips test.h"
#include "clipsmfc.h"
#include "ClipsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ClipsDlg dialog
ClipsDlg::ClipsDlg(CWnd* pParent /*=NULL*/)
: CDialog(ClipsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(ClipsDlg)
m_eFile = _T("");
//}}AFX_DATA_INIT
}
ClipsDlg::~ClipsDlg()
{
delete m_pClips;
}
void ClipsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ClipsDlg)
DDX_Control(pDX, IDC_RUN2, m_bCLP);
DDX_Control(pDX, IDC_WWARNING, m_lbWarning);
DDX_Control(pDX, IDC_WDISPLAY, m_lbDisplay);
DDX_Control(pDX, IDC_WERROR, m_lbError);
DDX_Control(pDX, IDC_WAGENDA, m_lbAgenda);
DDX_Control(pDX, IDC_RUN, m_bRun);
DDX_Control(pDX, IDC_CLEAR, m_bClear);
DDX_Text(pDX, IDC_CLP_FILE, m_eFile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ClipsDlg, CDialog)
//{{AFX_MSG_MAP(ClipsDlg)
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_EN_CHANGE(IDC_CLP_FILE, OnChangeClpFile)
ON_WM_TIMER()
ON_WM_CREATE()
ON_BN_CLICKED(IDC_RUN, OnRunBatch)
ON_BN_CLICKED(IDC_RUN2, OnRunCLP)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ClipsDlg message handlers
void ClipsDlg::OnBrowse()
{
CString filter;
CFileDialog* pdlg;
filter = "CLIPS Construct Files (*.clp) |*.clp| CLIPS Batch Files (*.bat)|*.bat| CLIPS Test Batch Files (*.tst)|*.tst||";
pdlg = new CFileDialog( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, AfxGetApp()->m_pMainWnd );
pdlg->DoModal();
m_eFile = pdlg->GetPathName();
UpdateData(FALSE);
delete pdlg;
if(m_eFile.IsEmpty()) {
m_bRun.EnableWindow(FALSE);
m_bCLP.EnableWindow(FALSE);
}
else {
if((m_eFile.Right(3) == "CLP") ||
(m_eFile.Right(3) == "clp") ||
(m_eFile.Right(3) == "Clp")) {
m_bCLP.EnableWindow(TRUE);
m_bRun.EnableWindow(FALSE);
}
else {
m_bRun.EnableWindow(TRUE);
m_bCLP.EnableWindow(FALSE);
}
}
}
void ClipsDlg::OnClear()
{
m_lbDisplay.ResetContent();
m_lbAgenda.ResetContent();
m_lbError.ResetContent();
m_lbWarning.ResetContent();
m_bClear.EnableWindow(FALSE);
m_pClips->CLIPSClear();
m_pClips->CLIPSFreeMem();
}
void ClipsDlg::OnChangeClpFile()
{
UpdateData();
if(m_eFile.IsEmpty()) {
m_bRun.EnableWindow(FALSE);
m_bCLP.EnableWindow(FALSE);
}
else {
if((m_eFile.Right(3) == "CLP") ||
(m_eFile.Right(3) == "clp") ||
(m_eFile.Right(3) == "Clp")) {
m_bCLP.EnableWindow(TRUE);
m_bRun.EnableWindow(FALSE);
}
else {
m_bRun.EnableWindow(TRUE);
m_bCLP.EnableWindow(FALSE);
}
}
}
extern "C" {
int WINAPI CLIPSVERSION(BOOL);
//int WINAPI TestSharedPool();
}
void ClipsDlg::OnRunBatch()
{
int ret, i;
CString Temp;
CString Val;
m_bRun.EnableWindow(FALSE);
m_bCLP.EnableWindow(FALSE);
//clear CLIPS
m_pClips->CLIPSClear();
//reset CLIPS
m_pClips->CLIPSReset();
//execute the batch
ret = m_pClips->CLIPSBatchStar(m_eFile);
if(ret == 0) {
MessageBox("Batch Failed to Load/Execute", "CLIPS", MB_OK | MB_ICONSTOP);
m_bRun.EnableWindow();
m_bCLP.EnableWindow();
return;
}
//display the results
for(i = 0; i < m_Display.GetSize(); i++)
m_lbDisplay.AddString((LPCSTR)(m_Display.GetAt(i)));
for(i = 0; i < m_Agenda.GetSize(); i++)
m_lbAgenda.AddString((LPCSTR)(m_Agenda.GetAt(i)));
for(i = 0; i < m_Error.GetSize(); i++)
m_lbError.AddString((LPCSTR)(m_Error.GetAt(i)));
for(i = 0; i < m_Warning.GetSize(); i++)
m_lbWarning.AddString((LPCSTR)(m_Warning.GetAt(i)));
m_bRun.EnableWindow();
m_bCLP.EnableWindow();
m_bClear.EnableWindow();
}
void ClipsDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
int ClipsDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
BOOL ClipsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString sDisplay;
CString sAgenda;
CString sError;
CString sWarning;
m_pClips = new CCLIPSWrap();
if(m_pClips) {
sDisplay = "wdisplay";
sAgenda = "wagenda";
sError = "werror";
sWarning = "wwarning";
m_pClips->CLIPSInit();
m_pClips->SetRouteBuffer(&m_Display,sDisplay);
m_pClips->SetRouteBuffer(&m_Agenda,sAgenda);
m_pClips->SetRouteBuffer(&m_Error,sError);
m_pClips->SetRouteBuffer(&m_Warning,sWarning);
}
m_bRun.EnableWindow(FALSE);
m_bCLP.EnableWindow(FALSE);
m_bClear.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void ClipsDlg::OnRunCLP()
{
int ret, i; //, retint;
CString Temp;
CString Val;
m_bRun.EnableWindow(FALSE);
m_bCLP.EnableWindow(FALSE);
//clear CLIPS
m_pClips->CLIPSClear();
//load the specified file
ret = m_pClips->CLIPSLoad(m_eFile);
if( ret != 2) {
MessageBox("Failed to load/parse CLP File",m_eFile,MB_OK | MB_ICONSTOP);
m_bRun.EnableWindow();
m_bCLP.EnableWindow();
return;
}
//issue a reset
m_pClips->CLIPSReset();
ret = m_pClips->CLIPSRun();
if(ret == 0) {
MessageBox("CLP Failed to Execute", "CLIPS", MB_OK | MB_ICONSTOP);
return;
}
//display the results from the route buffers
for(i = 0; i < m_Display.GetSize(); i++)
m_lbDisplay.AddString((LPCSTR)(m_Display.GetAt(i)));
for(i = 0; i < m_Agenda.GetSize(); i++)
m_lbAgenda.AddString((LPCSTR)(m_Agenda.GetAt(i)));
for(i = 0; i < m_Error.GetSize(); i++)
m_lbError.AddString((LPCSTR)(m_Error.GetAt(i)));
for(i = 0; i < m_Warning.GetSize(); i++)
m_lbWarning.AddString((LPCSTR)(m_Warning.GetAt(i)));
m_bRun.EnableWindow();
m_bCLP.EnableWindow();
m_bClear.EnableWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -