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

📄 gpsframe.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/* *  Roadnav *  GPSFrame.cpp * *  Copyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net> * *  This program is free software; you can redistribute it and/or *  modify it under the terms of version 2 of the GNU General Public License *  as published by the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */ ///////////////////////////////////////////////////////////////////////////////// \file////// Contains the GPSFrame class - a frame that has a single child - a/// GPSControl./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#pragma warning(disable: 4800)#endif#include <wx/wx.h>#ifdef HAVE_MATH_H#include <math.h>#endif#include "GPSFrame.h"#include "Frame.h"#include "libroadnav/MapRepresentations.h"//////////////////////////////////////////////////////////////////////////////////// GPSFrame event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(GPSFrame, wxFrame)	EVT_CLOSE(GPSFrame::OnClose)	EVT_PAINT(GPSFrame::OnPaint)	EVT_ERASE_BACKGROUND(GPSFrame::OnEraseBackground)	EVT_COMMAND(0, wxEVT_SAFE_REFRESH, GPSFrame::OnSafeRefresh)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief GPSFrame construct - create children, set up timer////////////////////////////////////////////////////////////////////////////////GPSFrame::GPSFrame (		class MapFrame * pfrmMap	)	: 	wxFrame	(		(wxFrame *) pfrmMap,		-1,		wxT("GPS Information"),		wxDefaultPosition,		wxDefaultSize,		wxDEFAULT_FRAME_STYLE	){	wxFlexGridSizer * psizerWnd;	wxFlexGridSizer * psizerLeft;	int iMargin = 3;		m_pfrmMap = pfrmMap;		psizerWnd = new wxFlexGridSizer(2);		//////////////////////////////////////////////////////////////////////////	// sizer for left side of window, containing all of the text	//////////////////////////////////////////////////////////////////////////	psizerLeft = new wxFlexGridSizer(2);		//////////////////////////////////////////////////////////////////////////	// add to window sizer	//////////////////////////////////////////////////////////////////////////	psizerWnd->Add(	psizerLeft,					1,					wxGROW,					0);		//////////////////////////////////////////////////////////////////////////	// Status label	//////////////////////////////////////////////////////////////////////////	m_pctlStatusLabel = new wxStaticText(this, -1, wxT("Status"));		psizerLeft->Add(		m_pctlStatusLabel,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Status text	//////////////////////////////////////////////////////////////////////////		m_pctlStatus = new wxStaticText(this, -1, wxT(""));		psizerLeft->Add(		m_pctlStatus,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Position label	//////////////////////////////////////////////////////////////////////////	m_pctlPositionLabel = new wxStaticText(this, -1, wxT("Position"));		psizerLeft->Add(		m_pctlPositionLabel,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Position text	//////////////////////////////////////////////////////////////////////////	Point ptDummy(0, 0);	m_pctlPosition = new wxStaticText(this, -1, ptDummy.FormatPoint());		psizerLeft->Add(		m_pctlPosition,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Speed label	//////////////////////////////////////////////////////////////////////////	m_pctlSpeedLabel = new wxStaticText(this, -1, wxT("Speed"));		psizerLeft->Add(		m_pctlSpeedLabel,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Speed text	//////////////////////////////////////////////////////////////////////////		m_pctlSpeed = new wxStaticText(this, -1, wxT(""));		psizerLeft->Add(		m_pctlSpeed,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Heading label	//////////////////////////////////////////////////////////////////////////	m_pctlHeadingLabel = new wxStaticText(this, -1, wxT("Heading"));		psizerLeft->Add(		m_pctlHeadingLabel,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Heading text	//////////////////////////////////////////////////////////////////////////		m_pctlHeading = new wxStaticText(this, -1, wxT(""));		psizerLeft->Add(		m_pctlHeading,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Satellites label	//////////////////////////////////////////////////////////////////////////	m_pctlSatellitesLabel = new wxStaticText(this, -1, wxT("Satellites"));		psizerLeft->Add(		m_pctlSatellitesLabel,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Satellites text	//////////////////////////////////////////////////////////////////////////		m_pctlSatellites = new wxStaticText(this, -1, wxT(""));		psizerLeft->Add(		m_pctlSatellites,		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL,		iMargin	);		//////////////////////////////////////////////////////////////////////////	// Satellites map	//////////////////////////////////////////////////////////////////////////		m_pctlSatelliteMap = new SatelliteControl(this);	psizerWnd->Add(		m_pctlSatelliteMap,		1,		wxALL | wxSHAPED,		iMargin	);	//////////////////////////////////////////////////////////////////////////	// Set up the sizer	//////////////////////////////////////////////////////////////////////////	psizerWnd->AddGrowableCol(1);	psizerWnd->AddGrowableRow(0);	psizerWnd->Fit(this);	SetSizer(psizerWnd);	Layout();	psizerWnd->SetSizeHints(this);}//////////////////////////////////////////////////////////////////////////////////// \brief GPSFrame destructor - doesn't do anything/////////////////////////////////////////////////////////////////////////////////GPSFrame::~GPSFrame(){}//////////////////////////////////////////////////////////////////////////////////// \brief SetBackgroundColour handler - pass background color down to/// children./////////////////////////////////////////////////////////////////////////////////bool GPSFrame::SetBackgroundColour(const wxColour& colour){	m_pctlSatelliteMap->SetBackgroundStyle(wxBG_STYLE_COLOUR);		m_pctlStatus->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlPosition->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlSpeed->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlHeading->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlSatellites->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlStatusLabel->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlPositionLabel->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlSpeedLabel->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlHeadingLabel->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlSatellitesLabel->SetBackgroundStyle(wxBG_STYLE_COLOUR);	m_pctlSatelliteMap->SetBackgroundColour(colour);		m_pctlStatus->SetBackgroundColour(colour);	m_pctlPosition->SetBackgroundColour(colour);	m_pctlSpeed->SetBackgroundColour(colour);	m_pctlHeading->SetBackgroundColour(colour);	m_pctlSatellites->SetBackgroundColour(colour);	m_pctlStatusLabel->SetBackgroundColour(colour);	m_pctlPositionLabel->SetBackgroundColour(colour);	m_pctlSpeedLabel->SetBackgroundColour(colour);	m_pctlHeadingLabel->SetBackgroundColour(colour);	m_pctlSatellitesLabel->SetBackgroundColour(colour);	return wxFrame::SetBackgroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief SetForegroundColour handler - pass foreground color down to/// children./////////////////////////////////////////////////////////////////////////////////bool GPSFrame::SetForegroundColour(const wxColour& colour){	m_pctlSatelliteMap->SetForegroundColour(colour);	m_pctlStatus->SetForegroundColour(colour);	m_pctlPosition->SetForegroundColour(colour);	m_pctlSpeed->SetForegroundColour(colour);	m_pctlHeading->SetForegroundColour(colour);	m_pctlSatellites->SetForegroundColour(colour);	m_pctlStatusLabel->SetForegroundColour(colour);	m_pctlPositionLabel->SetForegroundColour(colour);	m_pctlSpeedLabel->SetForegroundColour(colour);	m_pctlHeadingLabel->SetForegroundColour(colour);	m_pctlSatellitesLabel->SetForegroundColour(colour);	return wxFrame::SetForegroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief SetFont handler - pass font down to children./////////////////////////////////////////////////////////////////////////////////bool GPSFrame::SetFont(const wxFont& font){	m_pctlSatelliteMap->SetFont(font);	m_pctlStatus->SetFont(font);	m_pctlPosition->SetFont(font);	m_pctlSpeed->SetFont(font);	m_pctlHeading->SetFont(font);	m_pctlSatellites->SetFont(font);	m_pctlStatusLabel->SetFont(font);	m_pctlPositionLabel->SetFont(font);	m_pctlSpeedLabel->SetFont(font);	m_pctlHeadingLabel->SetFont(font);	m_pctlSatellitesLabel->SetFont(font);	Layout();	return wxFrame::SetFont(font);}//////////////////////////////////////////////////////////////////////////////////// \brief Updated GPS coordinates received - pass on to child/////////////////////////////////////////////////////////////////////////////////void GPSFrame::OnGPSUpdate(wxGPSEvent evGPS){	wxString strTmp;		//////////////////////////////////////////////////////////////////////////	// Status	//////////////////////////////////////////////////////////////////////////	if (!evGPS.m_bEnabled)		strTmp = wxT("GPS disabled");	else if (!evGPS.m_bActive)		strTmp = wxT("No GPS unit detected");	else if (!evGPS.m_bLocked)		strTmp = wxT("No GPS lock");	else		strTmp = evGPS.m_strLockType;			if (m_pctlStatus->GetLabel() != strTmp)		m_pctlStatus->SetLabel(strTmp);				//////////////////////////////////////////////////////////////////////////	// Position	//////////////////////////////////////////////////////////////////////////		strTmp = evGPS.m_pt.FormatPoint();		if (m_pctlPosition->GetLabel() != strTmp)		m_pctlPosition->SetLabel(strTmp);			//////////////////////////////////////////////////////////////////////////	// Speed	//////////////////////////////////////////////////////////////////////////		strTmp = FormatSpeed(evGPS.m_fSpeed);		if (m_pctlSpeed->GetLabel() != strTmp)		m_pctlSpeed->SetLabel(strTmp);			//////////////////////////////////////////////////////////////////////////	// Heading	//////////////////////////////////////////////////////////////////////////		strTmp = wxString::Format(	wxT("%.0f (%s)"), 								evGPS.m_fHeading, 								FormatHeading(evGPS.m_fHeading).c_str());		if (m_pctlHeading->GetLabel() != strTmp)		m_pctlHeading->SetLabel(strTmp);			//////////////////////////////////////////////////////////////////////////	// Satellites	//////////////////////////////////////////////////////////////////////////		strTmp = wxString::Format(wxT("%d"), evGPS.m_nSatUsedForLock);		if (m_pctlSatellites->GetLabel() != strTmp)		m_pctlSatellites->SetLabel(strTmp);			m_pctlSatelliteMap->OnGPSUpdate(evGPS);}//////////////////////////////////////////////////////////////////////////////////// \brief User wants to close this window - notify parent and hide./////////////////////////////////////////////////////////////////////////////////void GPSFrame::OnClose(wxCloseEvent& event){	Hide();	m_pfrmMap->OnGPSWindowHiding();}//////////////////////////////////////////////////////////////////////////////////// \brief Trigger a refresh of the entire control in a thread safe manner////// (calling Refresh() in a thread other than the main thread causes the/// UI to hang under GTK)/////////////////////////////////////////////////////////////////////////////////void GPSFrame::SafeRefresh(){	wxCommandEvent ev(wxEVT_SAFE_REFRESH, 0);	AddPendingEvent(ev);}//////////////////////////////////////////////////////////////////////////////////// \brief Triggered in the main thread by a SafeRefresh() call from any/// thread./////////////////////////////////////////////////////////////////////////////////void GPSFrame::OnSafeRefresh(wxCommandEvent & event){#if wxCHECK_VERSION(2, 5, 0)	wxMilliSleep(1);#else	wxUsleep(1);#endif	Refresh();}//////////////////////////////////////////////////////////////////////////////////// \brief Called to paint the window. This just paints the background color./////////////////////////////////////////////////////////////////////////////////void GPSFrame::OnPaint(wxPaintEvent& event){	wxPaintDC dc(this);	wxSize szWnd;	wxBrush brBk(GetBackgroundColour());	wxPen penBk(GetBackgroundColour());		szWnd = GetSize();		dc.SetBrush(brBk);	dc.SetPen(penBk);	dc.DrawRectangle(0, 0, szWnd.GetWidth(), szWnd.GetHeight());}//////////////////////////////////////////////////////////////////////////////////// \brief Called to erase the background of the control. Our function doesn't /// do anything - OnPaint will draw everything/////////////////////////////////////////////////////////////////////////////////void GPSFrame::OnEraseBackground(wxEraseEvent& event){	// don't do anything .. OnPaint will draw everything}

⌨️ 快捷键说明

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