// Debug.cpp : implementation file // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "DebugPage.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDebugPage property page IMPLEMENT_DYNCREATE(CDebugPage, CPropertyPage) CDebugPage::CDebugPage() : CPropertyPage(CDebugPage::IDD) { //{{AFX_DATA_INIT(CDebugPage) //}}AFX_DATA_INIT } CDebugPage::~CDebugPage() { } void CDebugPage::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDebugPage) DDX_Control(pDX, IDC_MVALLIST, m_MValList); DDX_Control(pDX, IDC_DATETIMEPICKER, m_date); DDX_Control(pDX, IDC_VALLIST, m_ValList); DDX_Control(pDX, IDC_RULESCOMBO, m_RuleList); DDX_Control(pDX, IDC_PROPLIST, m_PropList); DDX_Control(pDX, IDC_CPTLIST, m_CptList); DDX_Control(pDX, IDC_CLUSTERCOMBO, m_ClusterList); DDX_Control(pDX, IDC_MSFGWM, m_flex); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDebugPage, CPropertyPage) //{{AFX_MSG_MAP(CDebugPage) ON_LBN_SELCHANGE(IDC_CPTLIST, OnSelchangeCptlist) ON_CBN_SELCHANGE(IDC_CLUSTERCOMBO, OnSelchangeClustercombo) ON_LBN_SELCHANGE(IDC_PROPLIST, OnSelchangeProplist) ON_BN_CLICKED(IDC_SET, OnSet) ON_BN_CLICKED(IDC_RUNRULE, OnRunRule) ON_BN_CLICKED(IDC_INITWM, OnInitwm) ON_BN_CLICKED(IDC_RUNCLUSTER, OnRuncluster) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDebug message handlers void CDebugPage::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } BOOL CDebugPage::OnSetActive() { m_ClusterList.ResetContent(); POSITION pos1 =m_Doc->m_ClusterList.GetStartPosition(); while (pos1) { CString str ; m_Doc->m_ClusterList.GetNextAssoc(pos1,str,m_Doc->Cluster); m_ClusterList.AddString(str); } m_ClusterList.SetCurSel(0); OnSelchangeClustercombo(); m_RuleList.SetCurSel(0); m_CptList.ResetContent(); CString str ; POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,m_Doc->Cpt); if (m_Doc->Cpt->m_PropList.GetCount() > 0) { m_CptList.AddString(m_Doc->Cpt->NameL); } } return CPropertyPage::OnSetActive(); } void CDebugPage::OnSelchangeCptlist() { m_PropList.ResetContent(); int Sel = m_CptList.GetCurSel(); if (Sel < 0 ) return; CString str; m_CptList.GetText(Sel,str); m_Doc->m_CptList.Lookup(str,m_Doc->Cpt); POSITION pos = m_Doc->Cpt->m_PropList.GetStartPosition(); while (pos !=NULL) { m_Doc->Cpt->m_PropList.GetNextAssoc(pos,str,m_Doc->Prop); m_PropList.AddString(m_Doc->Prop->NameL); } } void CDebugPage::OnSelchangeClustercombo() { m_RuleList.ResetContent(); int Sel = m_ClusterList.GetCurSel(); if (Sel < 0 ) return; CString str; m_ClusterList.GetLBText(Sel,str); m_Doc->m_ClusterList.Lookup(str,m_Doc->Cluster); POSITION pos = m_Doc->Cluster->RuleList.GetStartPosition(); while (pos !=NULL) { m_Doc->Cluster->RuleList.GetNextAssoc(pos,str,m_Doc->Rule); m_RuleList.AddString(m_Doc->Rule->RuleID); } } void CDebugPage::OnSelchangeProplist() { m_ValList.ResetContent(); m_MValList.ResetContent(); int Sel = m_CptList.GetCurSel(); if (Sel < 0 ) return; CString strCpt; m_CptList.GetText(Sel,strCpt); m_Doc->m_CptList.Lookup(strCpt,m_Doc->Cpt); Sel = m_PropList.GetCurSel(); if (Sel < 0 ) return; CString strProp; m_PropList.GetText(Sel,strProp); m_Doc->Cpt->m_PropList.Lookup(strProp,m_Doc->Prop); if (m_Doc->Prop->Type == "Multi-Value") { m_ValList.ShowWindow(SW_HIDE); m_MValList.ShowWindow(SW_SHOW); } else { m_MValList.ShowWindow(SW_HIDE); m_ValList.ShowWindow(SW_SHOW); } POSITION pos = m_Doc->Prop->m_LegalValueList.GetStartPosition(); while (pos !=NULL) { CString Legal,str; m_Doc->Prop->m_LegalValueList.GetNextAssoc(pos,str,Legal); if (m_Doc->Prop->Type != "Multi-Value") m_ValList.AddString(str); else m_MValList.AddString(str); } CString strCptProp = strCpt +"-"+strProp; CValue *Value = new CValue; CValueList * Arr= new CValueList; if (!m_WM.Lookup(strCptProp,Arr)) return; Value = (CValue * )Arr->m_CValueList.GetAt(0); SetDlgItemText(IDC_VALLIST,Value->V); } void CDebugPage::OnSet() { CString strCpt; CString strProp; CString strVal; CString strCptProp; int SelCpt = m_CptList.GetCurSel(); if (SelCpt < 0 ) return; int SelProp = m_PropList.GetCurSel(); if (SelProp < 0 ) return; m_CptList.GetText(SelCpt,strCpt); m_PropList.GetText(SelProp,strProp); strCptProp = strCpt +"-"+strProp; CValue *Value = new CValue; m_Doc->m_CptList.Lookup(strCpt,m_Doc->Cpt); m_Doc->Cpt->m_PropList.Lookup(strProp,m_Doc->Prop); if (m_Doc->Prop->Type == "Multi-Value") { CListBox * pMulti= new CListBox; pMulti = (CListBox * ) GetDlgItem(IDC_MVALLIST); int * pInt=new int[pMulti->GetSelCount()]; for(int i=0;iGetSelCount();i++)pInt[i]=-1; pMulti->GetSelItems(pMulti->GetSelCount(),pInt); CValueList * Arr= new CValueList; int selMulti = 0; for(i=0;iGetSelCount();i++) { if(pInt[i]!=-1){ Value = new CValue; pMulti->GetText(pInt[i],Value->V); Arr->m_CValueList.SetAtGrow(selMulti++,Value); } } m_Doc->m_WM->SetAt(strCptProp,Arr); //delete pMulti; } else { GetDlgItemText(IDC_VALLIST,strVal); Value->V = strVal; CValueList * Arr= new CValueList; Arr->m_CValueList.SetAtGrow(0,Value); m_Doc->m_WM->SetAt(strCptProp,Arr); } UpdateWorkingMemory(); } void CDebugPage::OnRunRule() { int Sel = m_ClusterList.GetCurSel(); if (Sel < 0 ) return; CString str; m_ClusterList.GetLBText(Sel,str); m_Doc->m_ClusterList.Lookup(str,m_Doc->Cluster); Sel = m_RuleList.GetCurSel(); if (Sel < 0 ) return; CString strRule; m_RuleList.GetLBText(Sel,strRule); CRule * r; m_Doc->Cluster->RuleList.Lookup(strRule,r); r->Run(m_Doc->m_WM,&(m_Doc->m_CptList)); //Exhustive UpdateWorkingMemory(); } void CDebugPage::ClearGrid() { CString ss; for(int i = m_flex.GetRows();i >2;i--){ m_flex.RemoveItem(i); m_flex.Refresh(); } ss.Empty(); m_flex.SetTextMatrix(1,0,(LPCTSTR) ss); m_flex.SetTextMatrix(1,1,(LPCTSTR) ss); m_flex.SetTextMatrix(1,2,(LPCTSTR) ss); } void CDebugPage::OnInitwm() { ClearGrid(); m_Doc->InitWM(); /* POSITION pos = m_Doc->m_WM->GetStartPosition(); while( pos != NULL ) { CValueList * Arr= new CValueList; CString string; m_WM.GetNextAssoc( pos, string, Arr ); int i = 0; while (i < Arr->m_CValueList.GetSize() ) delete Arr->m_CValueList.GetAt( i++ ); Arr->m_CValueList.RemoveAll(); delete Arr; } m_WM.RemoveAll(); */ } void CDebugPage::DecomposeCptProp(CString str, CString &ssCpt, CString &ssProp) { ssCpt = str.SpanExcluding("-"); ssCpt.TrimLeft();ssCpt.TrimRight(); str.MakeReverse(); ssProp = str.SpanExcluding("-"); ssProp.MakeReverse(); ssProp.TrimLeft();ssProp.TrimRight(); } void CDebugPage::UpdateWorkingMemory() { ClearGrid(); FillGrid(); } void CDebugPage::FillGrid() { CString strCpt; CString strProp; CValueList * Arr= new CValueList; CValue *Value = new CValue; CString str ; POSITION pos = m_Doc->m_WM->GetStartPosition(); while(pos) { m_Doc->m_WM->GetNextAssoc(pos,str,Arr); for(int i=0; im_CValueList.GetSize();i++) { Value=(CValue*)Arr->m_CValueList.GetAt(i); DecomposeCptProp(str, strCpt,strProp); m_flex.SetTextMatrix(m_flex.GetRows()-1,0,(LPCTSTR) strCpt); m_flex.SetTextMatrix(m_flex.GetRows()-1,1,(LPCTSTR) strProp); m_flex.SetTextMatrix(m_flex.GetRows()-1,2,(LPCTSTR) Value->V); m_flex.SetRows(m_flex.GetRows()+1); str.Empty(); strCpt.Empty(); strProp.Empty(); } } } void CDebugPage::OnRuncluster() { int Sel = m_ClusterList.GetCurSel(); if (Sel < 0 ) return; CString str; m_ClusterList.GetLBText(Sel,str); if (!m_Doc->m_ClusterList.Lookup(str,m_Doc->Cluster))return; m_Doc->Cluster->Run(m_Doc->m_WM,&(m_Doc->m_CptList)); // m_Doc->Cluster->RunByPriority(m_Doc,m_WM); UpdateWorkingMemory(); }