// FunDlg.cpp : implementation file // #include "stdafx.h" #include "kbeditors.h" #include "FunDlg.h" #include "FunParser.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFunDlg property page IMPLEMENT_DYNCREATE(CFunDlg, CPropertyPage) CFunDlg::CFunDlg() : CPropertyPage(CFunDlg::IDD) { //{{AFX_DATA_INIT(CFunDlg) m_StrBody = _T(""); m_StrOutput = _T(""); //}}AFX_DATA_INIT } CFunDlg::~CFunDlg() { } void CFunDlg::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFunDlg) DDX_Control(pDX, IDC_FunIDCOMBO, m_FunList); DDX_Control(pDX, IDC_FunClusterCOMBO, m_FunCluster); DDX_Control(pDX, IDC_CPTTREE, m_CptTree); DDX_Text(pDX, IDC_Body1, m_StrBody); DDX_Text(pDX, IDC_Output1, m_StrOutput); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFunDlg, CPropertyPage) //{{AFX_MSG_MAP(CFunDlg) ON_NOTIFY(NM_DBLCLK, IDC_CPTTREE, OnDblclkCpttree) ON_BN_CLICKED(IDC_SaveFunction, OnSaveFunction) ON_BN_CLICKED(IDC_NewFun, OnNewFun) ON_BN_CLICKED(IDC_DeleteFun, OnDeleteFun) ON_BN_CLICKED(IDC_DeleteCluster, OnDeleteCluster) ON_BN_CLICKED(IDC_AddBody, OnAddBody) ON_BN_CLICKED(IDC_CompileBody, OnCompileBody) ON_CBN_SELCHANGE(IDC_FunClusterCOMBO, OnSelchangeFunClusterCOMBO) ON_CBN_SELCHANGE(IDC_FunIDCOMBO, OnSelchangeFunIDCOMBO) ON_CBN_EDITCHANGE(IDC_FunIDCOMBO, OnEditchangeFunIDCOMBO) ON_CBN_EDITCHANGE(IDC_FunClusterCOMBO, OnEditchangeFunClusterCOMBO) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFunDlg message handlers BOOL CFunDlg::Search(CComboBox *pmyComboBox, CString str) { int nIndex = 0; if(nIndex=pmyComboBox->FindStringExact(nIndex, str)!= LB_ERR) return true; return false; } BOOL CFunDlg::CheckPropValType(CConcept *inputconcept) { BOOL flage; flage=false; CProperty *CurProp; if(inputconcept->m_PropList.GetCount ()>0) { POSITION pos1 =inputconcept->m_PropList.GetStartPosition(); while (pos1 !=NULL) { CString str1; inputconcept->m_PropList.GetNextAssoc(pos1,str1,CurProp); for(int i=0;iType==(TypeList.GetAt(i))) { OutputPropList.Add(str1); flage=true; } } } } return flage; } void CFunDlg::SeeDoc(CKBEditorsDoc *Doc) { m_Doc = Doc; } void CFunDlg::FillCluster() { m_FunList.ResetContent (); m_FunCluster.ResetContent (); POSITION pos =m_Doc->m_FunctionList.GetStartPosition(); while (pos) { CString str ; m_Doc->m_FunctionList.GetNextAssoc(pos,str,FunCluster); m_FunCluster.AddString(str); } } void CFunDlg::DrawTree() { m_CptTree.DeleteAllItems(); CString str ; //CObArray *TypeList=new CObArray ; //CStringArray TypeList; TypeList.Add ("integer"); TypeList.Add ("date"); TypeList.Add ("real"); POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,m_Doc->Cpt); OutputPropList.RemoveAll(); if (m_Doc->Cpt->m_PropList.GetCount() > 0) { if(CheckPropValType(m_Doc->Cpt)==true) { if(OutputPropList.GetSize ()>0) { HTREEITEM TreeItem = m_CptTree.InsertItem(str,TVI_ROOT,TVI_SORT); for(int i=0;im_CptList)==false) { AfxMessageBox(error); return; } Function1->SetOutput(str); /***********************************/ GetDlgItemText(IDC_Body1,str); if(str.IsEmpty()){ AfxMessageBox("Please Enter Function Body"); return; } /****** Compile the Body *********/ if(obj.ParseBody(str,error,&m_Doc->m_CptList)==false) { AfxMessageBox(error); return; } str+=";"; Function1->SetBody(str); /***********************************/ GetDlgItemText(IDC_FunIDCOMBO,str); if(str.IsEmpty()){ AfxMessageBox("Please Enter Function ID"); return; } Function1->FunID= str; GetDlgItemText(IDC_FunClusterCOMBO,str); if(str.IsEmpty()){ AfxMessageBox("Please Enter Function Cluster"); return; } if (!m_Doc->m_FunctionList.Lookup(str,FunCluster)) { FunCluster= new CObArray ;// CFunCluster; } if(Search(&m_FunList,Function1->FunID)==false) { FunCluster->Add(Function1); m_Doc->m_FunctionList.SetAt(str,FunCluster); m_FunList.AddString(Function1->FunID); SetDlgItemText(IDC_Output1,""); SetDlgItemText(IDC_Body1,""); m_Doc->OnSaveDocument(m_Doc->AppName); FillCluster (); } else { if(AfxMessageBox("Do you want to update existing Function ?",MB_YESNO) == IDYES){ CFunction *Function2; for(int i=0;iGetSize();i++) { Function2=(CFunction*)FunCluster->GetAt(i); if(Function2->FunID==Function1->FunID){ FunCluster->RemoveAt(i); break; } } FunCluster->Add(Function1); m_Doc->m_FunctionList.SetAt(str,FunCluster); m_FunList.AddString(Function1->FunID); SetDlgItemText(IDC_Output1,""); SetDlgItemText(IDC_Body1,""); m_Doc->OnSaveDocument(m_Doc->AppName); FillCluster (); AfxMessageBox ("Operation Complete"); } else AfxMessageBox ("Operation Canceled"); } } void CFunDlg::OnNewFun() { // TODO: Add your control notification handler code here CString str=""; SetDlgItemText(IDC_FunIDCOMBO,str); SetDlgItemText(IDC_Output1,str); SetDlgItemText(IDC_Body1,str); SetDlgItemText(IDC_FunClusterCOMBO,str); } void CFunDlg::OnDeleteFun() { // TODO: Add your control notification handler code here int Sel = m_FunCluster.GetCurSel(); if (Sel < 0 ) return; CString str; m_FunCluster.GetLBText(Sel,str); m_Doc->m_FunctionList.Lookup(str,FunCluster); CString str1; GetDlgItemText(IDC_FunIDCOMBO,str1); CFunction *Function1; for(int i=0;iGetSize();i++) { Function1=(CFunction*)FunCluster->GetAt(i); if(Function1->FunID==str1) { FunCluster->RemoveAt(i); break; } } //m_Doc->FunCluster->FunctionList.Lookup(str1,Function); //m_Doc->FunCluster->FunctionList.RemoveKey(str1); //delete delete Function1; SetDlgItemText(IDC_Output1,""); SetDlgItemText(IDC_Body1,""); OnSelchangeFunClusterCOMBO(); } void CFunDlg::OnDeleteCluster() { // TODO: Add your control notification handler code here int Sel = m_FunCluster.GetCurSel(); if (Sel < 0 ) return; CString str1; m_FunCluster.GetLBText(Sel,str1); m_Doc->m_FunctionList.Lookup(str1,FunCluster); //POSITION pos = m_Doc->FunCluster->FunctionList.GetStartPosition(); //while (pos !=NULL) for(int j=FunCluster->GetSize()-1;j>0;j--) { // CFunction * Function1; // CString str; //m_Doc->FunCluster->FunctionList.GetNextAssoc(pos,str,Function1); FunCluster->RemoveAt(j); // Function1=(CFunction*)m_Doc->FunCluster->GetAt(i); // delete Function1; } //m_Doc->FunCluster->FunctionList.RemoveAll(); m_Doc->m_FunctionList.RemoveKey(str1); m_FunCluster.DeleteString(Sel); m_FunCluster.SetWindowText(""); m_FunList.ResetContent(); } void CFunDlg::OnAddBody() { // TODO: Add your control notification handler code here HTREEITEM TreeItem = m_CptTree.GetSelectedItem(); CString str1 = m_CptTree.GetItemText(TreeItem); HTREEITEM TreeItem1 = m_CptTree.GetParentItem(TreeItem); if (TreeItem1==NULL)return; CString str2 = m_CptTree.GetItemText(TreeItem1); CString str; CString m_str; GetDlgItemText(IDC_Body1,m_str); HTREEITEM TreeItem2 = m_CptTree.GetParentItem(TreeItem1); if (TreeItem2==NULL) { str = "@" + str2 +"."+str1; str = m_str + str; SetDlgItemText(IDC_Body1,str); return; } CString str3 = m_CptTree.GetItemText(TreeItem2); //str1 = str1.Mid(1,str1.GetLength()-1); //str1 = str1.SpanExcluding("'"); str1 = "\"" + str1 + "\""; str = "@" + str3 +"."+str2 +"=="+str1; str = m_str + str; SetDlgItemText(IDC_Body1,str); } void CFunDlg::OnCompileBody() { CString error,str; FunParser obj; GetDlgItemText(IDC_Output1,str); /****** Compile the Output *********/ if(obj.ParseHeader(str,error,&m_Doc->m_CptList)==false){ AfxMessageBox(error); return; } /***********************************/ GetDlgItemText(IDC_Body1,str); /****** Compile the Body *********/ if(obj.ParseBody(str,error,&m_Doc->m_CptList)==false){ AfxMessageBox(error); return; } /***********************************/ } void CFunDlg::OnSelchangeFunClusterCOMBO() { // TODO: Add your control notification handler code here m_FunList.ResetContent(); int Sel = m_FunCluster.GetCurSel(); if (Sel < 0 ) return; CString str; m_FunCluster.GetLBText(Sel,str); m_Doc->m_FunctionList.Lookup(str,FunCluster); for(int j=0;jGetSize();j++) { m_FunList.AddString(((CFunction*)FunCluster->GetAt(j))->FunID); } } void CFunDlg::OnSelchangeFunIDCOMBO() { CString str; GetDlgItemText(IDC_FunClusterCOMBO,str); if (!m_Doc->m_FunctionList.Lookup(str,FunCluster)) return; int Sel = m_FunList.GetCurSel(); if (Sel < 0 ) return; m_FunList.GetLBText(Sel,str); Function=NULL; for(int j=0;jGetSize();j++) { ; if(((CFunction*)FunCluster->GetAt(j))->FunID==str) { Function=(CFunction*)FunCluster->GetAt(j); break; } } //if (!m_Doc->FunCluster->FunctionList.Lookup(str,m_Doc->Function)) if(Function==NULL) return; SetDlgItemText(IDC_Output1,Function->GetOutput()); SetDlgItemText(IDC_Body1,Function->GetBody()); } void CFunDlg::OnEditchangeFunIDCOMBO() { } void CFunDlg::OnEditchangeFunClusterCOMBO() { //SetDlgItemText(IDC_Output1,""); //SetDlgItemText(IDC_Body1,""); //m_FunList.ResetContent(); } BOOL CFunDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }