// InferenceDlg.cpp : implementation file // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "DGDLG.h" #include "InferenceDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif class CTable; ///////////////////////////////////////////////////////////////////////////// // CInferenceDlg dialog CInferenceDlg::CInferenceDlg(CWnd* pParent /*=NULL*/) : CDialog(CInferenceDlg::IDD, pParent) { //{{AFX_DATA_INIT(CInferenceDlg) //}}AFX_DATA_INIT } void CInferenceDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CInferenceDlg) DDX_Control(pDX, IDC_Functions, m_FunctionListBox); DDX_Control(pDX, IDC_Tables, m_TableListBox); DDX_Control(pDX, IDC_STATICROLES, m_StaticRoleListBox); DDX_Control(pDX, IDC_CLUSTERS, m_ClusterListBox); DDX_Control(pDX, IDC_INFERENCELIST, m_InfCombo); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CInferenceDlg, CDialog) //{{AFX_MSG_MAP(CInferenceDlg) ON_BN_CLICKED(IDADDINFERENCE, OnAddinference) ON_BN_CLICKED(IDDELINFERENCE, OnDelinference) ON_BN_CLICKED(IDC_ADDRELATION, OnAddRelation) ON_CBN_SELCHANGE(IDC_INFERENCELIST, OnSelchangeInferencelist) ON_BN_CLICKED(IDC_DELRELATION, OnDelRelation) ON_CBN_SETFOCUS(IDC_INFERENCELIST, OnSetfocusInferencelist) ON_LBN_DBLCLK(IDC_CLUSTERS, OnDblclkClusters) ON_BN_CLICKED(IDC_Down, OnDown) ON_BN_CLICKED(IDC_Up, OnUp) ON_BN_CLICKED(IDC_ADDTable, OnADDTable) ON_BN_CLICKED(IDC_DGBTN, OnDgbtn) ON_BN_CLICKED(IDC_BUTTON2, OnAddFunctions) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CInferenceDlg message handlers void CInferenceDlg::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } void CInferenceDlg::FillClusterList() { m_ClusterListBox.ResetContent(); POSITION pos1 =m_Doc->m_ClusterList.GetStartPosition(); while (pos1) { CCluster * Cluster; CString str ; m_Doc->m_ClusterList.GetNextAssoc(pos1,str,Cluster); m_ClusterListBox.AddString(str); } } void CInferenceDlg::FillTableList() { CTable *TableObj; m_TableListBox.ResetContent(); POSITION posTable = m_Doc->m_TableList.GetStartPosition(); while (posTable !=NULL) { CString str; m_Doc->m_TableList.GetNextAssoc(posTable,str,TableObj); m_TableListBox.AddString(str); } } void CInferenceDlg::FillFunctionList() { CObArray *FunCluster; m_FunctionListBox.ResetContent (); POSITION pos =m_Doc->m_FunctionList.GetStartPosition(); while (pos) { CString str ; m_Doc->m_FunctionList.GetNextAssoc(pos,str,FunCluster); m_FunctionListBox.AddString(str); } } BOOL CInferenceDlg::OnInitDialog() { CDialog::OnInitDialog(); CenterWindow(GetDesktopWindow()); FillClusterList(); FillTableList(); FillFunctionList(); POSITION pos1 =m_Doc->m_InferenceList.GetStartPosition(); while (pos1) { CInference * Inference; CString str ; m_Doc->m_InferenceList.GetNextAssoc(pos1,str,Inference); m_InfCombo.AddString(str); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CInferenceDlg::OnAddinference() { int Sel = m_InfCombo.GetCurSel(); if (Sel >= 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); if (str.IsEmpty()) return; CInference * inf; if (m_Doc->m_InferenceList.Lookup(str,inf)) return; FillClusterList(); FillTableList(); inf = new CInference; inf->InferenceID = str; m_Doc->m_InferenceList.SetAt(str,inf); m_InfCombo.AddString(str); m_StaticRoleListBox.ResetContent(); AfxMessageBox("Inference "+str+" added successfully"); } void CInferenceDlg::OnDelinference() { int Sel = m_InfCombo.GetCurSel(); if (Sel < 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; m_Doc->m_InferenceList.RemoveKey(str); delete inf; m_InfCombo.DeleteString(Sel); m_StaticRoleListBox.ResetContent(); } void CInferenceDlg::OnAddRelation() { int Sel = m_InfCombo.GetCurSel(); if (Sel < 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; Sel = m_ClusterListBox.GetCurSel(); if (Sel < 0 ) return; m_ClusterListBox.GetText(Sel,str); m_ClusterListBox.DeleteString(Sel); // if (inf->StaticRoleList.Find(str)) return; inf->StaticRoleList.AddTail(str+"(Cluster)"); m_StaticRoleListBox.AddString(str+"(Cluster)"); } void CInferenceDlg::OnADDTable() { int Sel = m_InfCombo.GetCurSel(); if (Sel < 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; Sel = m_TableListBox.GetCurSel(); if (Sel < 0 ) return; m_TableListBox.GetText(Sel,str); m_TableListBox.DeleteString(Sel); // if (inf->StaticRoleList.Find(str)) return; inf->StaticRoleList.AddTail(str+"(Table)"); m_StaticRoleListBox.AddString(str+"(Table)"); } void CInferenceDlg::OnSelchangeInferencelist() { int Sel = m_InfCombo.GetCurSel(); if (Sel < 0 ) return; FillClusterList(); FillTableList(); m_StaticRoleListBox.ResetContent(); CString str; m_InfCombo.GetLBText(Sel,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; POSITION pos = inf->StaticRoleList.GetHeadPosition(); int Flage=0; while ( pos ) { str = inf->StaticRoleList.GetAt(pos); CString strSourceName,strType; m_Doc->DecomposeString(str,strSourceName,strType,"("); if(strType.IsEmpty()){ m_StaticRoleListBox.AddString(str+"(Cluster)"); m_ClusterListBox.DeleteString(m_ClusterListBox.SelectString(-1,strSourceName)); inf->StaticRoleList.SetAt(pos,str+"(Cluster)"); Flage=1; } else{ m_StaticRoleListBox.AddString(str); if(strType=="Cluster"){ m_ClusterListBox.DeleteString(m_ClusterListBox.SelectString(-1,strSourceName)); } else{ m_TableListBox.DeleteString(m_TableListBox.SelectString(-1,strSourceName)); } } inf->StaticRoleList.GetNext(pos); } if(Flage) m_Doc->OnSaveDocument(m_Doc->AppName); } void CInferenceDlg::OnDelRelation() { int Sel = m_InfCombo.GetCurSel(); // if ( Sel < 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; Sel = m_StaticRoleListBox.GetCurSel(); if ( Sel < 0 ) return; CString str1; m_StaticRoleListBox.GetText(Sel,str1); CString strSourceName,strType; m_Doc->DecomposeString(str1,strSourceName,strType,"("); POSITION pos = inf->StaticRoleList.GetHeadPosition(); while ( pos ) { str = inf->StaticRoleList.GetAt(pos); if (str == str1) { inf->StaticRoleList.RemoveAt(pos); m_StaticRoleListBox.DeleteString(Sel); if(strType=="Cluster") m_ClusterListBox.AddString(strSourceName); else if(strType=="Table") m_TableListBox.AddString(strSourceName); else if(strType=="Function") m_FunctionListBox.AddString(strSourceName); break; } inf->StaticRoleList.GetNext(pos); } } void CInferenceDlg::OnSetfocusInferencelist() { OnSelchangeInferencelist(); } void CInferenceDlg::OnDblclkClusters() { int Sel = m_ClusterListBox.GetCurSel(); if (Sel < 0 ) return; CString str; m_ClusterListBox.GetText(Sel,str); SetDlgItemText(IDC_INFERENCELIST,str); } void CInferenceDlg::OnUp() { int SelInf = m_InfCombo.GetCurSel(); if (SelInf < 0 ) return; CString Infstr; m_InfCombo.GetLBText(SelInf,Infstr); int SelStaticRol = m_StaticRoleListBox.GetCurSel(); if (SelStaticRol <= 0 ) return; int PrevStaticRol = SelStaticRol-1; CString CurSelText,PrevSelText; m_StaticRoleListBox.GetText(SelStaticRol,CurSelText); m_StaticRoleListBox.GetText(PrevStaticRol,PrevSelText); /////////////////////// CInference * infCurObj; if (!m_Doc->m_InferenceList.Lookup(Infstr,infCurObj)) return; POSITION CurrPos = infCurObj->StaticRoleList.Find((LPCTSTR)CurSelText); POSITION PrevPos =infCurObj->StaticRoleList.Find((LPCTSTR)PrevSelText); infCurObj->StaticRoleList.SetAt(CurrPos,PrevSelText); infCurObj->StaticRoleList.SetAt(PrevPos,CurSelText); m_StaticRoleListBox.ResetContent(); CString str; POSITION pos = infCurObj->StaticRoleList.GetHeadPosition(); while ( pos ) { str = infCurObj->StaticRoleList.GetAt(pos); m_StaticRoleListBox.AddString(str); infCurObj->StaticRoleList.GetNext(pos); } m_StaticRoleListBox.SelectString(-1,CurSelText); } void CInferenceDlg::OnDown() { int SelInf = m_InfCombo.GetCurSel(); if (SelInf < 0 ) return; CString Infstr; m_InfCombo.GetLBText(SelInf,Infstr); int SelStaticRol = m_StaticRoleListBox.GetCurSel(); if (SelStaticRol < 0 || SelStaticRol >= m_StaticRoleListBox.GetCount()-1 ) return; int NextStaticRol = SelStaticRol+1; CString CurSelText,NextSelText; m_StaticRoleListBox.GetText(SelStaticRol,CurSelText); m_StaticRoleListBox.GetText(NextStaticRol,NextSelText); /////////////////////// CInference * infCurObj; if (!m_Doc->m_InferenceList.Lookup(Infstr,infCurObj)) return; POSITION CurrPos = infCurObj->StaticRoleList.Find((LPCTSTR)CurSelText); POSITION NextPos = infCurObj->StaticRoleList.Find((LPCTSTR)NextSelText); infCurObj->StaticRoleList.SetAt(CurrPos,NextSelText); infCurObj->StaticRoleList.SetAt(NextPos,CurSelText); m_StaticRoleListBox.ResetContent(); CString str; POSITION pos = infCurObj->StaticRoleList.GetHeadPosition(); while ( pos ) { str = infCurObj->StaticRoleList.GetAt(pos); m_StaticRoleListBox.AddString(str); infCurObj->StaticRoleList.GetNext(pos); } m_StaticRoleListBox.SelectString(-1,CurSelText); } void CInferenceDlg::OnDgbtn() { CDGDlg Dlg; Dlg.SeeDoc(m_Doc); Dlg.DoModal(); } void CInferenceDlg::OnAddFunctions() { // TODO: Add your control notification handler code here int Sel = m_InfCombo.GetCurSel(); if (Sel < 0 ) return; CString str; GetDlgItemText(IDC_INFERENCELIST,str); CInference * inf; if (!m_Doc->m_InferenceList.Lookup(str,inf)) return; Sel = m_FunctionListBox.GetCurSel(); if (Sel < 0 ) return; m_FunctionListBox.GetText(Sel,str); m_FunctionListBox.DeleteString(Sel); // if (inf->StaticRoleList.Find(str)) return; inf->StaticRoleList.AddTail(str+"(Function)"); m_StaticRoleListBox.AddString(str+"(Function)"); }