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

📄 simulategpsview.cpp

📁 GPS电子狗数据采集、测试软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SimulateGPSView.cpp : implementation of the CSimulateGPSView class
//

#include "stdafx.h"
#include "SimulateGPS.h"

#include "SimulateGPSDoc.h"
#include "SimulateGPSView.h"

#include "MainFrm.h"
#include "DlgSetup.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CSimulateGPSApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView

IMPLEMENT_DYNCREATE(CSimulateGPSView, CView)

BEGIN_MESSAGE_MAP(CSimulateGPSView, CView)
	//{{AFX_MSG_MAP(CSimulateGPSView)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_MAP_PAN, OnMapPan)
	ON_COMMAND(ID_MAP_REFRESH, OnMapRefresh)
	ON_COMMAND(ID_MAP_VIEWENTIRE, OnMapViewentire)
	ON_COMMAND(ID_MAP_ZOOMIN, OnMapZoomin)
	ON_COMMAND(ID_MAP_ZOOMOUT, OnMapZoomout)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
	ON_COMMAND(ID_MAP_PICK, OnMapPick)
	ON_COMMAND(ID_TOOL_PLAYSELECT, OnToolPlayselect)
	ON_WM_TIMER()
	ON_COMMAND(ID_TOOL_SETUP, OnToolSetup)
	ON_COMMAND(ID_TOOL_WORKLAYER, OnToolWorklayer)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_MESSAGE(WM_COMM_RXSTR, OnRcvCommStr)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView construction/destruction

CSimulateGPSView::CSimulateGPSView()
{
	// TODO: add construction code here
	m_bFileOpened = false;
	m_PlayStatus = 0;
	m_pCurPnts = NULL;
	m_Total = 0;
	m_Count = 0;

}

CSimulateGPSView::~CSimulateGPSView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView drawing

void CSimulateGPSView::OnDraw(CDC* pDC)
{
	CSimulateGPSDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CRect rcClient;
	GetClientRect( &rcClient );
	if( m_bFileOpened )
	{
		m_MapWnd.OnDraw( pDC, rcClient, rcClient );
	}else
	{
		pDC->FillSolidRect( &rcClient, RGB(255,255,255) );
	}
}

/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView diagnostics

#ifdef _DEBUG
void CSimulateGPSView::AssertValid() const
{
	CView::AssertValid();
}

void CSimulateGPSView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CSimulateGPSView message handlers

void CSimulateGPSView::OnFileOpen() 
{
	CFileDialog dlgFile( true, _T(""), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		_T("WorkSpace Files (*.pmw)|*.pmw") );

	//弹出对话框选择工作空间文件
	if( dlgFile.DoModal() == IDOK )
	{
		//如果已经打开工作空间文件,则先关闭
		if( theApp.m_WorkSpace.IsOpen() )
		{ 
			theApp.m_WorkSpace.Close();
			m_MapWnd.Close();
			m_bFileOpened = false;
		}
		//获得图形文件的完整路径及文件名
		CString strFileName = dlgFile.GetPathName();

		//打开工作空间
		if( theApp.m_WorkSpace.Open( strFileName ) )
		{ 
			//与地图窗口关联
			m_MapWnd.OnInitialUpdate( &theApp.m_WorkSpace, this );

			//获取地图列表
			CSeMaps *pMaps = theApp.m_WorkSpace.GetMaps();
			if( pMaps )
			{
				if( pMaps->GetMapCount() > 0 ) 
				{//如果有定义好的地图就打开第一个地图
					CSeMapDef MapDef;

					//打开地图方法一: 通过名字取地图
					CString strMapName = pMaps->GetMapNameAt(0);
					if( pMaps->GetMap( strMapName, MapDef ) )
					{
						if( m_MapWnd.OpenMap( MapDef ) )
						{
							m_MapWnd.Refresh();
						}
					}
				}else{//没有地图,打开第一个数据源的第一个数据集作为当前地图
					CSeDataSource *pDataSource = theApp.m_WorkSpace.GetDataSourceAt( 0 );
					if( pDataSource && pDataSource->GetDatasetCount() > 0 )
					{
						//取第一个数据集添加到地图窗口中
						CSeDataset *pDataset = pDataSource->GetDatasetAt( 0 );
						if( pDataset )
						{
							m_MapWnd.AddLayer( pDataset );
							m_MapWnd.Refresh(); 
						}
					} 
				}
			}
			m_bFileOpened = true; 
			CSeStylePoint * trackStyle = new CSeStylePoint();
			trackStyle->m_nPenColor = RGB( 255, 0, 0 );
			m_MapWnd.m_TrackingLayer.SetStyle( trackStyle );
		}
	}
}

void CSimulateGPSView::OnMapPan() 
{
	m_MapWnd.SetAction( CSeDrawParameters::uaPan ); 
}

void CSimulateGPSView::OnMapRefresh() 
{
	m_MapWnd.Refresh();
}

void CSimulateGPSView::OnMapViewentire() 
{
	m_MapWnd.ViewEntire();
}

void CSimulateGPSView::OnMapZoomin() 
{
	m_MapWnd.SetAction( CSeDrawParameters::uaZoomIn );
}

void CSimulateGPSView::OnMapZoomout() 
{
	m_MapWnd.SetAction( CSeDrawParameters::uaZoomOut );
}

void CSimulateGPSView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_MapWnd.OnLButtonDown(nFlags, point);
	
	CView::OnLButtonDown(nFlags, point);
}

void CSimulateGPSView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	m_MapWnd.OnLButtonUp(nFlags, point);
	
	CView::OnLButtonUp(nFlags, point);
}

void CSimulateGPSView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if( m_PlayStatus==0 )
	{
		CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();

		CPoint MapPoint = point;

		m_MapWnd.GetDrawParam()->ClientToMap( &MapPoint, 1 );

		CString CoordText;

		CoordText.Format( "(%.6f,%.6f)", MapPoint.x/3600000.0, MapPoint.y/3600000.0 );
		pMain->m_wndStatusBar.SetPaneText( 0, CoordText );
	}

	CView::OnMouseMove(nFlags, point);
}

void CSimulateGPSView::OnFileClose() 
{
	theApp.m_WorkSpace.Close();
	m_MapWnd.Close();
	m_bFileOpened = false;
	m_MapWnd.Refresh();	
}

void CSimulateGPSView::OnMapPick() 
{
	m_MapWnd.SetAction( CSeDrawParameters::uaPointModeSelect );
}

void CSimulateGPSView::OnToolPlayselect() 
{
	if( !m_bFileOpened )
	{
		MessageBox("请先打开相应的电子地图!");
		return;
	}

	if( !HaveAllLayer() ){
		MessageBox("请先创建所需的工作图层!");
		return;
	}

	CSeRandomSelection *pSelection = m_MapWnd.GetSelection();
	if ( pSelection )
	{
		m_pRSSel = pSelection->ToRecordset( false );
		if( m_pRSSel && m_pRSSel->GetCount()>0 )
		{
			CSeDatasetInfo::Type dsType = m_pRSSel->GetDataset()->GetType();

			if( dsType==CSeDatasetInfo::Line || dsType==CSeDatasetInfo::Network )
			{
				if( !theApp.m_bPlayReady )
				{
					if( theApp.m_PlaySerial.Open( this, theApp.m_GPSPort, theApp.m_GPSBaud ) )
					{
						if( theApp.m_PlaySerial.Start() )
						{
							theApp.m_bPlayReady = true;
						}
					}
				}
				if( theApp.m_InPort!=theApp.m_GPSPort )
				{
					if( !theApp.m_bReciveReady )
					{
						if( theApp.m_ReceiveSerial.Open( this, theApp.m_InPort, theApp.m_InBaud ) )
						{
							if( theApp.m_ReceiveSerial.Start() )
							{
								theApp.m_bReciveReady = true;
							}
						}
					}
				}else theApp.m_bReciveReady = theApp.m_bPlayReady;
				if( theApp.m_bPlayReady && theApp.m_bReciveReady )
				{
					m_pRSSel->MoveFirst();
					if( GetSelGeo() )
					{
						SetTimer( 1, 250, 0 );
						m_TimerCount = 0;
						pSelection->ReleaseAll();
					}else{
						MessageBox("请先选择要播放的路线");
						m_pRSSel->GetDataset()->ReleaseRecordset( m_pRSSel );
					}
				}else
				{
					MessageBox("串口打开失败!");
				}

			}else MessageBox("此操作必须在线图层上");
        }else MessageBox("请先选择要播放的路线");
    }else MessageBox("请先选择要播放的路线");
}



void CSimulateGPSView::OnTimer(UINT nIDEvent) 
{
	m_TimerCount++;
	if( m_TimerCount>=4 )
	{
		m_TimerCount = 0;
		PlayGPSData();
	}
	
	CView::OnTimer(nIDEvent);
}

bool CSimulateGPSView::GetSelGeo()
{
	CSeGeoLine *pLine;
	double dist;

	if( !m_pRSSel->IsEOF() )
	{
		if( m_pRSSel->GetGeometry( (CSeGeometry *&)pLine ) )
		{
			if( pLine )
			{
				dist = theApp.m_Speed * 9.1;

				MyResampleLine( pLine, dist, m_pCurPnts, m_Total, m_Count, 1 );
				m_PlayIdx = 0;
				m_PlayStatus = 1;
				delete pLine;
				return true;
			}
		}
	}
	return false;
}

void CSimulateGPSView::PlayGPSData()
{
	char *GPGGA = "$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000*1F\n";
	theApp.m_PlaySerial.SendData( GPGGA, strlen(GPGGA) );

	BYTE hh,mm,ss,YY,MM,DD;
	int x,y;
	double xx,yy,Speed,Angle;
	COleDateTime dt = COleDateTime::GetCurrentTime();

	hh = dt.GetHour();
	mm = dt.GetMinute();
	ss = dt.GetSecond();
	YY = dt.GetYear() % 100;
	MM = dt.GetMonth();

⌨️ 快捷键说明

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