www.pudn.com > GPSComEVC3.0.rar > WptDlg.cpp


// WptDlg.cpp : implementation file 
// 
#include "stdafx.h" 
#include "resource.h" 
#include "WptDlg.h" 
#include  
#include  
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CWptDlg dialog 
double Dms2Rad(double dms); 
double Rad2Dms(double rad);	 
CWptDlg::CWptDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CWptDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CWptDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	 
	POSITION po=AfxGetApp()->GetFirstDocTemplatePosition(); 
	CDocTemplate *pDocTem=AfxGetApp()->GetNextDocTemplate(po); 
	po=pDocTem->GetFirstDocPosition(); 
	pDoc=(CGpsNavDoc *)pDocTem->GetNextDoc(po);		 
} 
 
 
void CWptDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CWptDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CWptDlg, CDialog) 
	//{{AFX_MSG_MAP(CWptDlg) 
	ON_BN_CLICKED(IDC_ADD, OnAdd) 
	ON_BN_CLICKED(IDC_INSERT, OnInsert) 
	ON_BN_CLICKED(IDC_UPDATE, OnUpdate) 
	ON_BN_CLICKED(IDC_REMOVE, OnRemove) 
	ON_BN_CLICKED(IDC_REMOVEALL, OnRemoveall) 
	ON_BN_CLICKED(IDC_QUIT, OnQuit) 
	ON_WM_PAINT() 
	ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList) 
	ON_CBN_SELCHANGE(IDC_BISIS, OnSelchangeBisis) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CWptDlg message handlers 
 
BOOL CWptDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
 
	CComboBox *pBisis=(CComboBox *)GetDlgItem(IDC_BISIS); 
	pBisis->AddString(TEXT("BLH")); 
	pBisis->AddString(TEXT("XYH")); 
	pBisis->SetCurSel(0); 
	nBisis=0; 
 
	return TRUE; 
} 
 
void CWptDlg::OnAdd()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
	CWayPoint wp; 
	CString str=""; 
	double a,b,c; 
	unsigned short ls[20]=_T(""); 
	char ch[20]=""; 
	(GetDlgItem(IDC_EDITNAME))->GetWindowText(ls,20); 
	if(pDoc->m_Way.FindPoint(ls)!=-1) 
	{ 
		::AfxMessageBox(_T("Point Name Exit!"),MB_OK); 
		return; 
	} 
	wp.SetPointName(ls); 
 
	int i=0; 
	memset(ch,0,20); 
	(GetDlgItem(IDC_EDITCX))->GetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;im_Way.GetFPoint())!=-1) 
	{ 
		(pDoc->m_Way.GetWpts())[f].GetPointName(lsf);// 
	} 
	if((t=pDoc->m_Way.GetTPoint())!=-1) 
	{ 
		(pDoc->m_Way.GetWpts())[t].GetPointName(lst);// 
	} 
	pDoc->m_Way.AddWpt(wp); 
	if(f!=-1) 
	{ 
		pDoc->m_Way.SetFPoint(pDoc->m_Way.FindPoint(lsf)); 
	} 
	if(t!=-1) 
	{ 
		pDoc->m_Way.SetTPoint(pDoc->m_Way.FindPoint(lst)); 
	} 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCX))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCY))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCH))->SetWindowText(_T("")); 
	SendMessage(WM_PAINT); 
} 
 
void CWptDlg::OnInsert()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
	CListBox *pWptList=(CListBox *)GetDlgItem(IDC_LIST); 
	if(pWptList->GetCurSel()==LB_ERR) 
	{ 
		return; 
	} 
	unsigned short ls[20]; 
	CWayPoint wp; 
	(GetDlgItem(IDC_EDITNAME))->GetWindowText(ls,20); 
	if(pDoc->m_Way.FindPoint(ls)!=-1) 
	{ 
		::AfxMessageBox(_T("Point Name Exit!"),MB_OK); 
		return; 
	} 
	wp.SetPointName(ls); 
	 
	CString str; 
	double a,b,c; 
	int i=0; 
	char ch[20]=""; 
	memset(ch,0,20); 
	(GetDlgItem(IDC_EDITCX))->GetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;im_Way.GetFPoint())!=-1) 
	{ 
		(pDoc->m_Way.GetWpts())[f].GetPointName(lsf);// 
	} 
	if((t=pDoc->m_Way.GetTPoint())!=-1) 
	{ 
		(pDoc->m_Way.GetWpts())[t].GetPointName(lst);// 
	} 
	pDoc->m_Way.AddWpt(wp,pWptList->GetCurSel()); 
	if(f!=-1) 
	{ 
		pDoc->m_Way.SetFPoint(pDoc->m_Way.FindPoint(lsf)); 
	} 
	if(t!=-1) 
	{ 
		pDoc->m_Way.SetTPoint(pDoc->m_Way.FindPoint(lst)); 
	} 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCX))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCY))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCH))->SetWindowText(_T("")); 
	SendMessage(WM_PAINT); 
} 
 
void CWptDlg::OnUpdate()  
{ 
	UpdateData();	 
	CListBox *pWptList=(CListBox *)GetDlgItem(IDC_LIST); 
	if(pWptList->GetCurSel()==LB_ERR) 
	{ 
		return; 
	} 
	unsigned short ls[20]; 
	(GetDlgItem(IDC_EDITNAME))->GetWindowText(ls,20); 
	if(pDoc->m_Way.FindPoint(ls)!=-1&&pDoc->m_Way.FindPoint(ls)!=pWptList->GetCurSel()) 
	{ 
		::AfxMessageBox(_T("Point Name Exit!"),MB_OK); 
		return; 
	} 
	 
	CArray &wps=pDoc->m_Way.GetWpts(); 
	wps[pWptList->GetCurSel()].SetPointName(ls); 
 
	CString str; 
	double a,b,c; 
	int i=0; 
	char ch[20]=""; 
	memset(ch,0,20); 
	(GetDlgItem(IDC_EDITCX))->GetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;iGetWindowText(str); 
	for(i=0;iGetCurSel()].SetDblh(dd); 
	} 
	else 
	{ 
		CXYH cc={a,b,c}; 
		wps[pWptList->GetCurSel()].SetCxyh(cc); 
	} 
	SendMessage(WM_PAINT); 
} 
 
void CWptDlg::OnRemove()  
{ 
	// TODO: Add your control notification handler code here 
	CListBox *pWptList=(CListBox *)GetDlgItem(IDC_LIST); 
	if(pWptList->GetCurSel()==LB_ERR) 
	{ 
		return; 
	} 
	TCHAR lp1[40]=_T(""); 
	TCHAR lp2[40]=_T(""); 
	CArray &wps=pDoc->m_Way.GetWpts(); 
	wps[pWptList->GetCurSel()].GetPointName(lp1); 
	wsprintf(lp2,_T("Clear %s WayPoint?"),lp1); 
	if(::AfxMessageBox(lp2,MB_OKCANCEL)!=IDOK) 
		return; 
	pDoc->m_Way.DelWpt(pWptList->GetCurSel()); 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCX))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCY))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCH))->SetWindowText(_T("")); 
	SendMessage(WM_PAINT); 
} 
 
void CWptDlg::OnRemoveall()  
{ 
	if(pDoc->m_Way.GetWptNum()<=0) 
	{ 
		return; 
	} 
	if(::AfxMessageBox(_T("Clear All WayPoints?"),MB_OKCANCEL)!=IDOK) 
		return; 
	pDoc->m_Way.DelAll(); 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCX))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCY))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCH))->SetWindowText(_T("")); 
	SendMessage(WM_PAINT); 
} 
 
void CWptDlg::OnQuit()  
{ 
	// TODO: Add your control notification handler code here 
	OnOK(); 
} 
 
void CWptDlg::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
	 
	CListBox *pWptList=(CListBox *)GetDlgItem(IDC_LIST); 
	CArray &wps=pDoc->m_Way.GetWpts(); 
	int num=pDoc->m_Way.GetWptNum(); 
	CString str=""; 
	unsigned short lpStr[20]; 
	pWptList->ResetContent(); 
	if(num>0) 
	{ 
		for(int i=0;iAddString(str); 
		} 
	} 
	else 
	{ 
		return; 
	} 
 
	if(pWptList->GetCurSel()==LB_ERR) 
	{ 
		return; 
	} 
	unsigned short lp[20]; 
	char ch[20]; 
	wps[pWptList->GetCurSel()].GetPointName(lp); 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(lp); 
 
	if(nBisis==0) 
	{ 
		DBLH dd; 
		wps[pWptList->GetCurSel()].GetD(dd); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",Rad2Dms(dd.DB)); 
		str=ch; 
		(GetDlgItem(IDC_EDITCX))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",Rad2Dms(dd.DL)); 
		str=ch; 
		(GetDlgItem(IDC_EDITCY))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",dd.DH); 
		str=ch; 
		(GetDlgItem(IDC_EDITCH))->SetWindowText(str); 
	} 
	else 
	{ 
		CXYH cc; 
		wps[pWptList->GetCurSel()].GetC(cc); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CX); 
		str=ch; 
		(GetDlgItem(IDC_EDITCX))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CY); 
		str=ch; 
		(GetDlgItem(IDC_EDITCY))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CH); 
		str=ch; 
		(GetDlgItem(IDC_EDITCH))->SetWindowText(str); 
	} 
} 
 
void CWptDlg::OnSelchangeList()  
{ 
	CListBox *pWptList=(CListBox *)GetDlgItem(IDC_LIST); 
	CArray &wps=pDoc->m_Way.GetWpts(); 
	CString str=""; 
 
	if(pWptList->GetCurSel()==LB_ERR) 
	{ 
		return; 
	} 
	unsigned short lp[20]; 
	char ch[20]; 
	wps[pWptList->GetCurSel()].GetPointName(lp); 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(lp); 
 
	if(nBisis==0) 
	{ 
		DBLH dd; 
		wps[pWptList->GetCurSel()].GetD(dd); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",Rad2Dms(dd.DB)); 
		str=ch; 
		(GetDlgItem(IDC_EDITCX))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",Rad2Dms(dd.DL)); 
		str=ch; 
		(GetDlgItem(IDC_EDITCY))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",dd.DH); 
		str=ch; 
		(GetDlgItem(IDC_EDITCH))->SetWindowText(str); 
	} 
	else 
	{ 
		CXYH cc; 
		wps[pWptList->GetCurSel()].GetC(cc); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CX); 
		str=ch; 
		(GetDlgItem(IDC_EDITCX))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CY); 
		str=ch; 
		(GetDlgItem(IDC_EDITCY))->SetWindowText(str); 
		memset(ch,0,20); 
		sprintf(ch,"%.6lf",cc.CH); 
		str=ch; 
		(GetDlgItem(IDC_EDITCH))->SetWindowText(str); 
	} 
} 
 
void CWptDlg::OnSelchangeBisis()  
{ 
	CComboBox *pBisis=(CComboBox *)GetDlgItem(IDC_BISIS); 
	if(nBisis==pBisis->GetCurSel()) 
	{ 
		return; 
	} 
	nBisis=pBisis->GetCurSel(); 
	CString str; 
	switch(nBisis) 
	{ 
	case 0: 
		str=_T("B:"); 
		(GetDlgItem(IDC_STATICCX))->SetWindowText(str); 
		str=_T("L:"); 
		(GetDlgItem(IDC_STATICCY))->SetWindowText(str); 
		str=_T("H:"); 
		(GetDlgItem(IDC_STATICCH))->SetWindowText(str); 
		(GetDlgItem(IDC_EDITNAME))->EnableWindow(TRUE); 
		((CEdit*)(GetDlgItem(IDC_EDITCX)))->SetReadOnly(FALSE); 
		((CEdit*)(GetDlgItem(IDC_EDITCY)))->SetReadOnly(FALSE); 
		((CEdit*)(GetDlgItem(IDC_EDITCH)))->SetReadOnly(FALSE); 
		(GetDlgItem(IDC_ADD))->EnableWindow(TRUE); 
		(GetDlgItem(IDC_INSERT))->EnableWindow(TRUE); 
		(GetDlgItem(IDC_UPDATE))->EnableWindow(TRUE); 
		break; 
	case 1: 
		str=_T("X:"); 
		(GetDlgItem(IDC_STATICCX))->SetWindowText(str); 
		str=_T("Y:"); 
		(GetDlgItem(IDC_STATICCY))->SetWindowText(str); 
		str=_T("H:"); 
		(GetDlgItem(IDC_EDITNAME))->EnableWindow(FALSE); 
		((CEdit*)(GetDlgItem(IDC_EDITCX)))->SetReadOnly(); 
		((CEdit*)(GetDlgItem(IDC_EDITCY)))->SetReadOnly(); 
		((CEdit*)(GetDlgItem(IDC_EDITCH)))->SetReadOnly(); 
		(GetDlgItem(IDC_ADD))->EnableWindow(FALSE); 
		(GetDlgItem(IDC_INSERT))->EnableWindow(FALSE); 
		(GetDlgItem(IDC_UPDATE))->EnableWindow(FALSE); 
		break; 
	} 
	(GetDlgItem(IDC_EDITNAME))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCX))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCY))->SetWindowText(_T("")); 
	(GetDlgItem(IDC_EDITCH))->SetWindowText(_T("")); 
}