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

📄 displayview.cpp

📁 程序实现了PDA对手持型GPS的导航设计。用一个串口类控制串口通讯
💻 CPP
字号:
// DisplayView.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "MainFrm.h"
#include "DisplayView.h"
#include "NameDlg.h"
#include "GpsNavDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


double Rad2Dms(double rad);
double GetBearing(const CWayPoint &wpt1,const CWayPoint &wpt2);
RESULT GetResult(const CString str);
double GetDist(const CWayPoint &wpt1,double x,double y);
double GetDist(const CWayPoint &wpt1,const CWayPoint &wpt2);
FPOINT GetPoint(const CWayPoint &p1,const CWayPoint &p2,const CWayPoint &p3);
/////////////////////////////////////////////////////////////////////////////
// CDisplayView

IMPLEMENT_DYNCREATE(CDisplayView, CFormView)

CDisplayView::CDisplayView()
	: CFormView(CDisplayView::IDD)
{
	//{{AFX_DATA_INIT(CDisplayView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CDisplayView::~CDisplayView()
{
}

void CDisplayView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDisplayView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDisplayView, CFormView)
	//{{AFX_MSG_MAP(CDisplayView)
	ON_BN_CLICKED(IDC_ADDHERE, OnAddhere)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisplayView diagnostics

#ifdef _DEBUG
void CDisplayView::AssertValid() const
{
	CFormView::AssertValid();
}

void CDisplayView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDisplayView message handlers
/////////////////////////////////////////////////////////////////////////////
// CDisplayView

void CDisplayView::OnAddhere() 
{
	// TODO: Add your control notification handler code here
	if(((CGpsNavDoc *)GetDocument())->m_Serial==NULL)
	{
		GetDlgItem(IDC_INFO)->SetWindowText(_T("Please Start Navigation!"));
		return;
	}
	NameDlg dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	CGpsNavDoc *pDoc=(CGpsNavDoc *)GetDocument();
	CString str="";
	if(dlg.name=="")
	{
		str=_T("No Name");
	}
	else
	{
		str=dlg.name;
	}

	int nIndex=pDoc->m_Way.GetForward();
	if(nIndex==-1)
	{
		return;
	}
	CWayPoint wpt=pDoc->m_Way.GetCurPoint();
	wpt.SetPointName(str);
	pDoc->m_Way.AddWpt(wpt,nIndex);
	pDoc->m_Way.SetAfterward(nIndex);
	if(pDoc->m_Way.GetTPoint()>pDoc->m_Way.GetFPoint())
	{
		pDoc->m_Way.SetForward(nIndex+1);
		pDoc->m_Way.SetTPoint(pDoc->m_Way.GetTPoint()+1);
	}
	else
	{
		pDoc->m_Way.SetForward(nIndex-1);
		pDoc->m_Way.SetTPoint(pDoc->m_Way.GetTPoint()-1);
	}

	CArray<CWayPoint,CWayPoint> &wps=pDoc->m_Way.GetWpts();
}

void CDisplayView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	CGpsNavDoc *pDoc=(CGpsNavDoc *)GetDocument();
	CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
	
	CString str="";
	CArray<CWayPoint,CWayPoint> &wps=pDoc->m_Way.GetWpts();

	if(pDoc->m_Serial==NULL)
	{
		pDoc->m_Info="";
	}
	else
	{		
		pDoc->m_Info="";
		if( GetDist(pDoc->m_Way.GetCurPoint(),wps[pDoc->m_Way.GetForward()])==0)
		{
			if(pDoc->m_Way.GetForward()==pDoc->m_Way.GetTPoint())
			{
				delete pDoc->m_Serial;
				pDoc->m_Info="Arrived Destination!";
				pMain->m_wndStatusBar.SetPaneText(0,LPCTSTR(pDoc->m_Info),TRUE);
			}
			int nTemp=pDoc->m_Way.GetForward();
			pDoc->m_Way.SetAfterward(nTemp);
			pDoc->m_Way.SetForward(2*pDoc->m_Way.GetAfterward()-nTemp);
			unsigned short lp[20];
			wps[pDoc->m_Way.GetForward()].GetPointName(lp);
			pDoc->m_Info="Arrived ";
			pDoc->m_Info+=lp;
			pDoc->m_Info+=" Point!\r\n";
				str.Format(_T("Curent Point:\r\n\tB:%.6lf\r\n\tL:%.6lf\r\n\tH:%.6lf"),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DB),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DL),pDoc->m_Way.GetCurPoint().d.DH);
				pDoc->m_Info+=str;
		}
		else
		{	
			double dis=GetDist(pDoc->m_Way.GetCurPoint(),wps[pDoc->m_Way.GetForward()]);
			double totdis=dis;
			int i=pDoc->m_Way.GetForward();
			if(pDoc->m_Way.GetFPoint()<pDoc->m_Way.GetTPoint())
			{
				for(;i<pDoc->m_Way.GetTPoint();i++)
				{
					totdis+=GetDist(wps[i],wps[i+1]);
				}
			}
			else
			{
				for(;i>pDoc->m_Way.GetTPoint();i--)
				{
					totdis+=GetDist(wps[i],wps[i-1]);
				}
			}
		
			double Heading=GetBearing(wps[pDoc->m_Way.GetAfterward()],pDoc->m_Way.GetCurPoint());
			double Bearing=GetBearing(wps[pDoc->m_Way.GetAfterward()],wps[pDoc->m_Way.GetForward()]);
	
			if( GetDist(pDoc->m_Way.GetCurPoint(),wps[pDoc->m_Way.GetAfterward()])==0)
			{
				Heading=Bearing;
			}
			double dmsB=Rad2Dms(Bearing);
			double dmsH=Rad2Dms(Heading);
			double turn=Rad2Dms(Heading-Bearing);			
			unsigned short lp[20];			
			unsigned short lp1[20];
			double dx=0,dy=0,dh=0,ds=0;
			double elevation=0;
			switch(pDoc->nDisFormat)
			{
			case 0:
				pDoc->m_Info=_T("1.Dist/Bearing\r\n");
				wps[pDoc->m_Way.GetForward()].GetPointName(lp);
				str.Format(_T(">%d %s\r\n"),pDoc->m_Way.GetForward()+1,lp);
				pDoc->m_Info+=str;
				str.Format(_T("Dist:%.4lfkm\r\n"),dis/1000);
				pDoc->m_Info+=str;
				if(turn<=180)
				{
					str.Format(_T("Turn:left%.0lf\r\n"),turn);
					pDoc->m_Info+=str;
				}
				else
				{
					str.Format(_T("Turn:right%.0lf\r\n"),360.-turn);
					pDoc->m_Info+=str;
				}
				str.Format(_T("Bearing:%.0lf\r\n"),dmsB);
				pDoc->m_Info+=str;
				str.Format(_T("Heading:%.0lf\r\n"),dmsH);
				pDoc->m_Info+=str;
				str.Format(_T("Curent Point:\r\n\tB:%.6lf\r\n\tL:%.6lf\r\n\tH:%.6lf"),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DB),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DL),pDoc->m_Way.GetCurPoint().d.DH);
				pDoc->m_Info+=str;
				break;
			case 1:
				pDoc->m_Info=_T("2.Track/XTE\r\n");				
				wps[pDoc->m_Way.GetFPoint()].GetPointName(lp);			
				wps[pDoc->m_Way.GetTPoint()].GetPointName(lp1);
				str.Format(_T("From %s To %s\r\n"),lp,lp1);
				pDoc->m_Info+=str;
				str.Format(_T("Heading:%.0lf\r\n"),dmsH);
				pDoc->m_Info+=str;
				str.Format(_T("Dist:%.4lfkm\r\n"),dis/1000);
				pDoc->m_Info+=str;
				if(turn<=180)
				{
					FPOINT p=GetPoint(wps[pDoc->m_Way.GetAfterward()],wps[pDoc->m_Way.GetForward()],pDoc->m_Way.GetCurPoint());
					str.Format(_T("XTE:+%.4lfKm\r\n"),GetDist(pDoc->m_Way.GetCurPoint(),p.X,p.Y)/1000.);
					pDoc->m_Info+=str;
				}
				else
				{
					FPOINT p=GetPoint(wps[pDoc->m_Way.GetAfterward()],wps[pDoc->m_Way.GetForward()],pDoc->m_Way.GetCurPoint());
					str.Format(_T("XTE:-%.4lfKm\r\n"),GetDist(pDoc->m_Way.GetCurPoint(),p.X,p.Y)/1000.);
					pDoc->m_Info+=str;
				}
				str.Format(_T("Curent Point:\r\n\tB:%.6lf\r\n\tL:%.6lf\r\n\tH:%.6lf"),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DB),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DL),pDoc->m_Way.GetCurPoint().d.DH);
				pDoc->m_Info+=str;
				break;
			case 2:
				pDoc->m_Info=_T("3.East/North\r\n");
				wps[pDoc->m_Way.GetForward()].GetPointName(lp);
				str.Format(_T(">%d %s\r\n"),pDoc->m_Way.GetForward()+1,lp);
				pDoc->m_Info+=str;
				dx=wps[pDoc->m_Way.GetForward()].c.CX-pDoc->m_Way.GetCurPoint().c.CX;
				dy=wps[pDoc->m_Way.GetForward()].c.CY-pDoc->m_Way.GetCurPoint().c.CY;
				dh=wps[pDoc->m_Way.GetForward()].c.CH-pDoc->m_Way.GetCurPoint().c.CH;
				ds=sqrt(dx*dx+dy*dy);
				elevation=atan(dh/ds)/PI*180.0;
				str.Format(_T("Elevation:%.0lf\r\n"),elevation);
				pDoc->m_Info+=str;
				str.Format(_T("Heading:%.0lf\r\n"),dmsH);
				pDoc->m_Info+=str;
				str.Format(_T("Go E:%.4lfKm\r\n"),dy/1000);
				pDoc->m_Info+=str;
				str.Format(_T("Go N:%.4lfKm\r\n"),dx/1000);
				pDoc->m_Info+=str;
				str.Format(_T("Go U:%.4lfKm\r\n"),dh/1000);
				pDoc->m_Info+=str;
				str.Format(_T("Curent Point:\r\n\tB:%.6lf\r\n\tL:%.6lf\r\n\tH:%.6lf"),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DB),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DL),pDoc->m_Way.GetCurPoint().d.DH);
				pDoc->m_Info+=str;
				break;
			case 3:
				pDoc->m_Info=_T("4.Velocity/Time\r\n");				
				wps[pDoc->m_Way.GetFPoint()].GetPointName(lp);			
				wps[pDoc->m_Way.GetTPoint()].GetPointName(lp1);
				str.Format(_T("From %s To %s\r\n"),lp,lp1);
				pDoc->m_Info+=str;
				str.Format(_T("Vel:N/A\r\n"));
				pDoc->m_Info+=str;
				str.Format(_T("TTG:N/A\r\n"));
				pDoc->m_Info+=str;
				str.Format(_T("ETA:N/A\r\n"));
				pDoc->m_Info+=str;
				if(turn<=180)
				{
					str.Format(_T("Turn:left%.0lf\r\n"),turn);
					pDoc->m_Info+=str;
				}
				else
				{
					str.Format(_T("Turn:right%.0lf\r\n"),360.-turn);
					pDoc->m_Info+=str;
				}
				str.Format(_T("Heading:%.0lf\r\n"),dmsH);
				pDoc->m_Info+=str;
				str.Format(_T("TotDist:%.4lfkm\r\n"),totdis/1000);
				pDoc->m_Info+=str;
				str.Format(_T("Curent Point:\r\n\tB:%.6lf\r\n\tL:%.6lf\r\n\tH:%.6lf"),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DB),Rad2Dms(pDoc->m_Way.GetCurPoint().d.DL),pDoc->m_Way.GetCurPoint().d.DH);
				pDoc->m_Info+=str;
				break;
			}
		}
	}
	GetDlgItem(IDC_INFO)->SetWindowText(pDoc->m_Info);
}

⌨️ 快捷键说明

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