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

📄 gpsview.cpp

📁 由GPS原始数据求方位角的程序源码
💻 CPP
字号:
// GpsView.cpp : implementation of the CGpsView class
//

#include "stdafx.h"
#include "Gps.h"

#include "GpsDoc.h"
#include "GpsView.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI (3.1415926)
/////////////////////////////////////////////////////////////////////////////
// CGpsView

IMPLEMENT_DYNCREATE(CGpsView, CScrollView)

BEGIN_MESSAGE_MAP(CGpsView, CScrollView)
	//{{AFX_MSG_MAP(CGpsView)
	ON_COMMAND(ID_FWJ, OnFwj)
	ON_WM_SIZE()
	ON_WM_CANCELMODE()
	ON_WM_VSCROLL()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsView construction/destruction

CGpsView::CGpsView()
{
	// TODO: add construction code here

}

CGpsView::~CGpsView()
{
}

BOOL CGpsView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGpsView drawing
//在窗口中显示新算出的数据
void CGpsView::OnDraw(CDC* pDC)
{

	CGpsDoc* pDoc = GetDocument();

	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	if(!pDoc->HadFwj)
	 return;
	CString strE,strN,strFwj;
	int x=0,y=0;
	TEXTMETRIC tm;
	pDC->GetOutputTextMetrics(&tm);
	for(int i=0;i<pDoc->NodeNumber-1;i++)
	{
		strE.Format("%f   ",pDoc->ESource[i]);
		strN.Format("%f   ",pDoc->NSource[i]);
		strFwj.Format("%f   ",pDoc->Fwj[i]);
		x=10+tm.tmAveCharWidth*2;
		y=20+y;//tm.tmExternalLeading;
		pDC->TextOut(x,y,pDoc->IDSource[i]);
		x=x+tm.tmAveCharWidth*20;	
		pDC->TextOut(x,y,strE);
		x=x+tm.tmAveCharWidth*20;
		pDC->TextOut(x,y,strN);
		x=x+tm.tmAveCharWidth*20;
		pDC->TextOut(x,y,pDoc->HSource[i]);
		x=x+tm.tmAveCharWidth*20;
		pDC->TextOut(x,y,strFwj);	
	}
}

void CGpsView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();	
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);//,sizePage,sizeLine);
}

/////////////////////////////////////////////////////////////////////////////
// CGpsView printing

BOOL CGpsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGpsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGpsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGpsView diagnostics

#ifdef _DEBUG
void CGpsView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CGpsView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CGpsDoc* CGpsView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGpsDoc)));
	return (CGpsDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGpsView message handlers
//////////////////////////////////////////////////////////////////////////////
//本模块计算方位角
////////////////////////////////////////
void CGpsView::OnFwj() 
{
	// TODO: Add your command handler code here
	CGpsDoc* pDoc = GetDocument();
	long total=pDoc->NodeNumber;
	

	if(total==0)//判断是否已经读出数据
	{
		AfxMessageBox("没有装载数据");
			return;
	}
	
	
	pDoc->Fwj=new double[total-1];
	double dx=1,dy=1,f=0;//dx为前后两点的横坐标差,dy为纵坐标差	
	for(long i=0;i<total-1;i++)
	{
		dx=pDoc->ESource[i+1]-pDoc->ESource[i];
		dy=pDoc->NSource[i+1]-pDoc->NSource[i];

		if(dx==0 && dy>0)//点位于Y上半轴
		{
			pDoc->Fwj[i]=0;
		}
		else if(dx>0 && dy>0)//点位于第一象限
		{
			f=atan2(dx,dy);
			f=f*180/PI;
			pDoc->Fwj[i]=f;
		}
		else if(dx>0 && dy==0)//位于X右轴
		{
			pDoc->Fwj[i]=90;
		}
		else if(dx>0 && dy<0)//位于第四象限
		{
			f=atan2(-dy,dx);
			f=f*180/PI+90;
			pDoc->Fwj[i]=f;
		}
		else if(dx==0 && dy<0)//位于Y下轴
		{
			pDoc->Fwj[i]=180;
		}
		else if(dx<0 && dy<0)//位于第三象限
		{
			f=atan2(-dx,-dy);
			f=f*180/PI+180;
			pDoc->Fwj[i]=f;
		}
		else if(dx<0 && dy==0)//位于X左半轴
		{
			pDoc->Fwj[i]=270;
		}
		else if(dx<0 && dy>0)//位于第二象限
		{
			f=atan2(dy,-dx);
			f=f*180/PI+270;
			pDoc->Fwj[i]=f;
		}
		else if(dx==0 && dy==0)
			pDoc->Fwj[i]=360;
	}
	pDoc->HadFwj=true;
	AfxMessageBox("数据处理完毕,请保存!");//提示保存

	pDoc = GetDocument();
	CDC* dc;
	dc=GetDC();
	
	CSize sizeTotal,sizeLine,sizePage;
	TEXTMETRIC tm;
	sizeTotal.cx=100;
	dc->GetOutputTextMetrics(&tm);
	//sizeTotal.cx=1000;
	sizeTotal.cy=tm.tmHeight*total*1.25;
	//SetScrollRange(SB_VERT,-9999999,9999999,TRUE);
	SetScrollSizes(MM_TEXT, sizeTotal);
	RedrawWindow();//重画窗口

	// TODO: add draw code for native data here

}



void CGpsView::OnSize(UINT nType, int cx, int cy) 
{
	CScrollView::OnSize(nType, cx, cy);
	this->cx=cx;
	this->cy=cy;
	// TODO: Add your message handler code here
	
}

void CGpsView::OnCancelMode() 
{
	CScrollView::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

BOOL CGpsView::IsSelected(const CObject* pDocItem) const
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CScrollView::IsSelected(pDocItem);
}


void CGpsView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
//if(nSBCode==SB_THUMBTRACK)
{
	CDC* dc;
	dc=GetDC();
	CString sPos;
	sPos.Format("%d",nPos);
	dc->TextOut(100,100,sPos);
}
	CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
	
	
}

⌨️ 快捷键说明

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