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

📄 bbbdlg.cpp

📁 这是个源码合集
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// BBBDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BBB.h"
#include "BBBDlg.h"

#include <stdio.h>
#include <stdlib.h>
#include "my_define.h"
#include "my_global.h"
#include "my_read_in.h"
#include "my_function.h"
#include "my_Syn_G.h"
#include "my_Syn_F.h"
#include "my_Syn_R.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBBBDlg dialog

CBBBDlg::CBBBDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBBBDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBBBDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
   
	//初始化时保存着工程所在的当前目录备用
    GetCurrentDirectory(dirlen,sDir);
}

void CBBBDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBBBDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_EDIT_R_H, m_R_H_Edit);
	DDX_Control(pDX, IDC_EDIT_R_B, m_R_B_Edit);
    DDX_Control(pDX, IDC_EDIT_F, m_F_Edit);
	DDX_Control(pDX, IDC_EDIT_RF_P, m_RF_P_Edit);
    DDX_Control(pDX, IDC_EDIT_F_P, m_F_P_Edit);
    DDX_Control(pDX, IDC_EDIT_S_P, m_S_P_Edit);
    DDX_Control(pDX, IDC_EDIT_R_P, m_R_P_Edit);
    DDX_Control(pDX, IDC_EDIT_G_P, m_G_P_Edit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBBBDlg, CDialog)
	//{{AFX_MSG_MAP(CBBBDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_R_ADD, OnButtonRAdd)
	ON_BN_CLICKED(IDC_BUTTON_F_ADD, OnButtonFAdd)
	ON_BN_CLICKED(IDC_BUTTON_RUN, OnButtonRun)
	ON_BN_CLICKED(IDC_BUTTON_RF_P_CLS, OnButtonRfPCls)
	ON_BN_CLICKED(IDC_BUTTON_IN_RF, OnButtonInRf)
	ON_BN_CLICKED(IDC_BUTTON_OUT_RF, OnButtonOutRf)
	ON_BN_CLICKED(IDC_BUTTON_IN_G, OnButtonInG)
	ON_BN_CLICKED(IDC_BUTTON_OUT_G, OnButtonOutG)
	ON_BN_CLICKED(IDC_BUTTON_G_P_CLS, OnButtonGPCls)
	ON_BN_CLICKED(IDC_BUTTON_TEST_GOAL_SYN, OnButtonTestGoalSyn)
	ON_BN_CLICKED(IDC_BUTTON_IN_F, OnButtonInF)
	ON_BN_CLICKED(IDC_BUTTON_OUT_F, OnButtonOutF)
	ON_BN_CLICKED(IDC_BUTTON_F_P_CLS, OnButtonFPCls)
	ON_BN_CLICKED(IDC_BUTTON_TEST_FACTOR_SYN, OnButtonTestFactorSyn)
	ON_BN_CLICKED(IDC_BUTTON_TEST_RULE_SYN, OnButtonTestRuleSyn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBBBDlg message handlers

BOOL CBBBDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CBBBDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CBBBDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CBBBDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CBBBDlg::OnButtonRAdd() 
{
	// TODO: Add your control notification handler code here
	//添加一条规则
//
////////////////////////	
	char cstr_Test_R_H[MAX];
	m_R_H_Edit.GetWindowText(cstr_Test_R_H,MAX);
	if(strlen(cstr_Test_R_H)==0 )
	{
		AfxMessageBox("请先填入规则头!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
//////////////////////////
	char cstr_Test_R_B[MAX];
    m_R_B_Edit.GetWindowText(cstr_Test_R_B,MAX);
	if(strlen(cstr_Test_R_B)==0 )
	{
		AfxMessageBox("请先填入规则体!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
////////////////////////
//
    char cstr_R_H[MAX];
	char cstr_R_B[MAX];		
	char cstr_R[MAX];
	char cstr_R_P_buff[MAX*LINES];
	m_R_H_Edit.GetWindowText(cstr_R_H,MAX);
    m_R_B_Edit.GetWindowText(cstr_R_B,MAX);

	strcpy(cstr_R,cstr_R_H);
    strcat(cstr_R,":-");
    strcat(cstr_R,cstr_R_B);

    m_RF_P_Edit.GetWindowText(cstr_R_P_buff,MAX*LINES);
    
	if ( strlen(cstr_R_P_buff)!=0 )
     strcat(cstr_R_P_buff,"\r\n");
     strcat(cstr_R_P_buff,cstr_R);

    m_RF_P_Edit.SetSel(0,-1);
	m_RF_P_Edit.ReplaceSel(cstr_R_P_buff);

	m_R_H_Edit.SetSel(0,-1);
	m_R_H_Edit.ReplaceSel("");
    m_R_B_Edit.SetSel(0,-1);
	m_R_B_Edit.ReplaceSel("");
}

void CBBBDlg::OnButtonFAdd() 
{
	// TODO: Add your control notification handler code here
	//添加一条事实

//
////////////////////////	
	char cstr_Test_F[MAX];
	m_F_Edit.GetWindowText(cstr_Test_F,MAX);
	if(strlen(cstr_Test_F)==0 )
	{
		AfxMessageBox("请先填入事实!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
//////////////////////////

    char cstr_F[MAX];
    char cstr_F_P_buff[MAX*LINES];
    m_F_Edit.GetWindowText(cstr_F,MAX);

    m_F_P_Edit.GetWindowText(cstr_F_P_buff,MAX*LINES);
	if ( strlen(cstr_F_P_buff)!=0 )
     strcat(cstr_F_P_buff,"\r\n");
     strcat(cstr_F_P_buff,cstr_F);

    m_F_P_Edit.SetSel(0,-1);
	m_F_P_Edit.ReplaceSel(cstr_F_P_buff);

    m_F_Edit.SetSel(0,-1);
	m_F_Edit.ReplaceSel("");
	
}

void CBBBDlg::OnButtonRun() 
{
	// TODO: Add your control notification handler code here
	//运行

	//
//////////////////////////////////////
	// 刷新结果栏	
       m_R_P_Edit.SetSel(0,-1);
	   m_R_P_Edit.ReplaceSel("");
	//
//////////////////////////////////////
	// 刷新状态栏
       m_S_P_Edit.SetSel(0,-1);
	   m_S_P_Edit.ReplaceSel("");
	//
////////////////////////
	// 确认规则栏不为空
	char cstr_Test_RF_P[MAX*LINES];
	m_RF_P_Edit.GetWindowText(cstr_Test_RF_P,MAX*LINES);
	if(strlen(cstr_Test_RF_P)==0 )
	{
		AfxMessageBox("请先添加规则!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
	//
////////////////////////
	// 确认事实栏不为空
	char cstr_Test_F_P[MAX*LINES];
	m_F_P_Edit.GetWindowText(cstr_Test_F_P,MAX*LINES);
	if(strlen(cstr_Test_F_P)==0 )
	{
		AfxMessageBox("请先添加事实!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
	//
////////////////////////
	// 确认目标栏不为空
	char cstr_Test_G_P[MAX*LINES];
    m_G_P_Edit.GetWindowText(cstr_Test_G_P,MAX*LINES);
	if(strlen(cstr_Test_G_P)==0 )
	{
		AfxMessageBox("请先添加目标!");
		SetCursor(LoadCursor(NULL,IDC_ARROW));	
		return;
	}
////////////////////////////////////////////
//
// 每次运行前都要把当前目录设回工程目录
//
    SetCurrentDirectory(sDir);
//
/////////////////////////////////////

///////////////////////////////////////////
//  加入标记
//
	//
    //////////////////////////////////////////
	//  首先构建合适的内部谓词
	//
	char Flag_P[MAX];
    strcpy(Flag_P,"inner_flag");
    int flag_num=0;
	while(flag_num<K)
	{
	  for(flag_num=0;flag_num<K;flag_num++)
	  {
	    if(strcmp(Flag_P,c[flag_num])==0)
	    //如果与用户提出的标识符冲突
		{
	      add_one(Flag_P,'z');//则所使用的内部标识符后加z来区分
		  break;
		}
	  }
	}//当for循环没有被中断时,退出while循环,此时已通过检测
	 //最后由Flag_P返回一个合适的内部谓词

////////////////////////////////////////////////////////


  TERM t;
  TF tf;
  ENGid CurEng;//定义指向逻辑服务器的指针
  lsInit(&CurEng,"XGENE");//初始化逻辑服务器并用CurEng代表它
  lsLoad(CurEng,"XGENE");//把Prolog文件调入到CurEng服务器中


 char cstr_Buff[MAX];   
 char *m_myBuffer; 
 m_myBuffer = new char[strlen(cstr_Buff)+1]; 
 char *m_myBuffer_f; 
 m_myBuffer_f = new char[strlen(cstr_Buff)+1]; 
 char *m_wrongBuffer;
 m_wrongBuffer= new char[strlen(cstr_Buff)+1]; 

 int j; 
 int i;
 int nLineCount; 
 char i_temp[4];
 char cstr_Buff_R_S[MAX*LINES];

//////////////////////////////////////    
//  分行读出  规则 并载入逻辑服务器
//  

  ///////////////////////////////////////////////// 
  // 规则标记部分预处理    循环外
  add_one(Flag_P,'(');
  add_one(Flag_P,'f');

  nLineCount = m_RF_P_Edit.GetLineCount();

  for (i=0;i < nLineCount;i++)
  {
    j=0;
    m_RF_P_Edit.GetLine(i,cstr_Buff,MAX);	  
    for(j=0;j<m_RF_P_Edit.LineLength(m_RF_P_Edit.LineIndex(i));j++)
	{
        m_myBuffer[j]=cstr_Buff[j];
	}
    m_myBuffer[j]='\0';
   // AfxMessageBox(m_myBuffer);
   // AfxMessageBox(Flag_P);
    ///////////////////////////////////////////////// 
    //规则标记部分预处理    循环内
	//
	if(j>0)//依此排除空行造成的错误
	{
      //
	  ////////////////////////////////////////////
	  //
      if ( lsAssertzStr(CurEng, m_myBuffer) )
	  {
	    //
	    //--显示段开始 //显示 "规则部分脚本语言连接错误!错误在"
	    m_S_P_Edit.GetWindowText(cstr_Buff_R_S,MAX*LINES);
	    if ( strlen(cstr_Buff_R_S)!=0 )
		{
           strcat(cstr_Buff_R_S,"\r\n");
		}
        strcpy(m_wrongBuffer,"规则部分脚本语言连接错误!错误在");
        strcat(cstr_Buff_R_S,m_wrongBuffer);
        m_S_P_Edit.SetSel(0,-1);
	    m_S_P_Edit.ReplaceSel(cstr_Buff_R_S); 
        //--显示段结束
	    //
	    //--显示段开始  //显示 m_myBuffer
	    m_S_P_Edit.GetWindowText(cstr_Buff_R_S,MAX*LINES);
	    if ( strlen(cstr_Buff_R_S)!=0 )
		{
           strcat(cstr_Buff_R_S,"\r\n");
		}
        strcpy(m_wrongBuffer,m_myBuffer);
        strcat(cstr_Buff_R_S,m_wrongBuffer);
        m_S_P_Edit.SetSel(0,-1);
	    m_S_P_Edit.ReplaceSel(cstr_Buff_R_S); 
        //--显示段结束
	    //
	    //--显示段开始 //显示 "行附近。"
	    m_S_P_Edit.GetWindowText(cstr_Buff_R_S,MAX*LINES);
	    if ( strlen(cstr_Buff_R_S)!=0 )
		{
          strcat(cstr_Buff_R_S,"\r\n");
		}
        strcpy(m_wrongBuffer,"行附近。");
        strcat(cstr_Buff_R_S,m_wrongBuffer);
        m_S_P_Edit.SetSel(0,-1);
	    m_S_P_Edit.ReplaceSel(cstr_Buff_R_S); 
        //--显示段结束
	    //
        lsClose(CurEng);  //关闭逻辑服务器 
	    return;
	  } 
	  else
	  {
         ///////////////////////////////////
		 //  如果当前规则插入成功,则开始做标记,做标记的实质是插入事实
         //
	  	 strcpy(m_myBuffer_f,m_myBuffer);
	     cut_head(m_myBuffer_f);
	     itoa(i,i_temp,10);
	     char temp_flag[MAX];
	     strcpy(temp_flag,Flag_P);
	     strcat(temp_flag,i_temp);
	     add_one(temp_flag,')');
         strcat(temp_flag,m_myBuffer_f);
         //AfxMessageBox(temp_flag);
         if ( lsAssertzStr(CurEng, temp_flag) )
		 {  
			AfxMessageBox("发生内部错误!错误代码:");
            AfxMessageBox(temp_flag);
            lsClose(CurEng);  //关闭逻辑服务器 
	        return;
		 }
	  }

	}
  }

//////////////////////////////////////    
//  分行读出  事实 并载入逻辑服务器
//  
  nLineCount = m_F_P_Edit.GetLineCount();

  for (i=0;i < nLineCount;i++)
  {
	j=0;
    m_F_P_Edit.GetLine(i,cstr_Buff,MAX);	  
    for(j=0;j<m_F_P_Edit.LineLength(m_F_P_Edit.LineIndex(i));j++)
	{
        m_myBuffer[j]=cstr_Buff[j];
	}
    m_myBuffer[j]='\0';
    //AfxMessageBox(m_myBuffer);
	if (j>0)
	{
       if ( lsAssertzStr(CurEng, m_myBuffer) )
	   {
       //
       //--显示段开始 //显示 "事实部分脚本语言连接错误!错误在"
	   m_S_P_Edit.GetWindowText(cstr_Buff_R_S,MAX*LINES);
	   if ( strlen(cstr_Buff_R_S)!=0 )
	   {
         strcat(cstr_Buff_R_S,"\r\n");
	   }
       strcpy(m_wrongBuffer,"事实部分脚本语言连接错误!错误在");
       strcat(cstr_Buff_R_S,m_wrongBuffer);
       m_S_P_Edit.SetSel(0,-1);
 	   m_S_P_Edit.ReplaceSel(cstr_Buff_R_S); 
       //--显示段结束
	   //
	   //--显示段开始  //显示 m_myBuffer
	   m_S_P_Edit.GetWindowText(cstr_Buff_R_S,MAX*LINES);
	   if ( strlen(cstr_Buff_R_S)!=0 )

⌨️ 快捷键说明

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