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

📄 preferencespagegps.cpp

📁 roadnav 内含一个基于wxWindows库的车载导航系统。编译后
💻 CPP
字号:
/* *  Roadnav *  PreferencesPageGPS.cpp * *  Copyright (c) 2004 - 2006 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 GPS page of the preferences dialog box./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#pragma warning(disable: 4800)#endif#include <wx/wx.h>#include "App.h"#include "PreferencesPageGPS.h"#include "SerialIO.h"#include "GPSMonitorThread.h"enum {	idGPSType,	idIconBrowse};BEGIN_EVENT_TABLE(PreferencesPageGPS, wxPanel)	EVT_COMBOBOX(idGPSType, PreferencesPageGPS::OnGPSTypeChange)	EVT_BUTTON(idIconBrowse, PreferencesPageGPS::OnIconBrowse)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief PreferencesPageGPS constructor - create and initialize controls/////////////////////////////////////////////////////////////////////////////////PreferencesPageGPS::PreferencesPageGPS(wxWindow *parent)             : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){	wxBoxSizer * psizerWnd;	wxFlexGridSizer * psizerGrid;	wxString strSel;		psizerGrid = new wxFlexGridSizer(2, 5, 10);		//////////////////////////////////////////////////////////////////////////	// GPS type label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("GPS Type")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// GPS type selection	//////////////////////////////////////////////////////////////////////////	wxArrayString arOptions;		m_pctlGPSType = new wxComboBox(this, idGPSType, wxT(""), wxDefaultPosition, wxSize(200, -1), arOptions, wxCB_DROPDOWN | wxCB_READONLY);		m_pctlGPSType->Append(wxT("None"));	m_pctlGPSType->Append(wxT("Auto Detect"));#ifdef ROADNAV_SERIAL_SUPPORT	m_pctlGPSType->Append(wxT("Serial"));#endif#ifdef HAVE_LIBGPS	m_pctlGPSType->Append(wxT("gpsd"));#endif#ifdef HAVE_SIMULATED_GPS_SUPPORT	m_pctlGPSType->Append(wxT("Simulated"));#endif	// add to the sizer	psizerGrid->Add(m_pctlGPSType,				0,				wxGROW,				0	);	switch (GPSMonitorThread::GetGPSType())	{		case GPSTypeNone:			m_pctlGPSType->SetValue(wxT("None"));			break;					case GPSTypeAutoDetect:		case GPSTypeAutoDetectInProgress:			m_pctlGPSType->SetValue(wxT("Auto Detect"));			break;#ifdef ROADNAV_SERIAL_SUPPORT		case GPSTypeSerial:			m_pctlGPSType->SetValue(wxT("Serial"));			break;#endif#ifdef HAVE_LIBGPS		case GPSTypeGPSD:			m_pctlGPSType->SetValue(wxT("gpsd"));			break;#endif#ifdef HAVE_SIMULATED_GPS_SUPPORT		case GPSTypeSimulated:			m_pctlGPSType->SetValue(wxT("Simulated"));			break;#endif	}	#ifdef ROADNAV_SERIAL_SUPPORT	int iBaudRate;	int iSel;	int i;	bool bDone;	//////////////////////////////////////////////////////////////////////////	// Serial port label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("Serial port")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Serial port selection	//////////////////////////////////////////////////////////////////////////	m_pctlSerialPort = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxSize(200, -1));		// start by enumerating the serial ports and adding them to the combo box	i = 0;	bDone = false;	while (!bDone)	{		wxString strName;				strName = EnumSerialPort(i);				if (strName != wxT(""))		{			i++;			m_pctlSerialPort->Append(strName);		}		else		{			bDone = true;		}	}	// add to the sizer	psizerGrid->Add(m_pctlSerialPort,				0,				wxGROW,				0	);	g_pConfig->Read(wxT("GPSSerialPort"), &strSel, wxT(""));	iSel = m_pctlSerialPort->FindString(strSel);	if (iSel >= 0)		m_pctlSerialPort->SetSelection(iSel);	else		m_pctlSerialPort->SetValue(strSel);		//////////////////////////////////////////////////////////////////////////	// Baud rate label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("Baud rate")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Baud rate selection	//////////////////////////////////////////////////////////////////////////	m_pctlBaudRate = new wxComboBox(this, -1, wxT(""));	m_pctlBaudRate->Append(wxT("1200"));	m_pctlBaudRate->Append(wxT("2400"));	m_pctlBaudRate->Append(wxT("4800"));	m_pctlBaudRate->Append(wxT("9600"));	m_pctlBaudRate->Append(wxT("19200"));	m_pctlBaudRate->Append(wxT("38400"));	g_pConfig->Read(wxT("GPSBaudRate"), &iBaudRate, 4800);		strSel = wxString::Format(wxT("%d"), iBaudRate);	iSel = m_pctlBaudRate->FindString(strSel);	if (iSel >= 0)		m_pctlBaudRate->SetSelection(iSel);	else		m_pctlBaudRate->SetValue(strSel);	psizerGrid->Add(m_pctlBaudRate,				0,				wxGROW,				0	);#endif#ifdef HAVE_LIBGPS	//////////////////////////////////////////////////////////////////////////	// gpsd Host Label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("gpsd Host")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// gpsd Host Entry	//////////////////////////////////////////////////////////////////////////	m_pctlgpsdHost = new wxTextCtrl(this, -1, g_pConfig->Read(wxT("gpsdHost"), wxT("localhost")), wxDefaultPosition, wxSize(250, -1));	psizerGrid->Add(		m_pctlgpsdHost,		0,		wxALIGN_LEFT,		0	);		//////////////////////////////////////////////////////////////////////////	// gpsd Port Label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("gpsd Port")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// gpsd Port Entry	//////////////////////////////////////////////////////////////////////////	m_pctlgpsdPort = new wxTextCtrl(this, -1, g_pConfig->Read(wxT("gpsdPort"), wxT("2947")), wxDefaultPosition, wxSize(250, -1));	psizerGrid->Add(		m_pctlgpsdPort,		0,		wxALIGN_LEFT,		0	);			//////////////////////////////////////////////////////////////////////////	// gpsd check compatibility Label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("Check gpsd Server Compatibility")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// gpsd Port Entry	//////////////////////////////////////////////////////////////////////////	m_pctlgpsdCompatibilityCheck = new wxCheckBox(this, -1, wxT(""));	m_pctlgpsdCompatibilityCheck->SetValue(g_pConfig->Read(wxT("gpsdCompatibilityCheck"), (long) 1));	psizerGrid->Add(		m_pctlgpsdCompatibilityCheck,		0,		wxALIGN_LEFT,		0	);	#endif		//////////////////////////////////////////////////////////////////////////	// GPS Callout Box label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("GPS Callout Box")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// GPS Callout Box checkbox	//////////////////////////////////////////////////////////////////////////	m_pctlGPSCalloutBox = new wxCheckBox(this, -1, wxT(""));	m_pctlGPSCalloutBox->SetValue(g_pConfig->Read(wxT("GPS Callout Box"), (long) false));	psizerGrid->Add(		m_pctlGPSCalloutBox,		0,		wxALIGN_LEFT,		0	);	//////////////////////////////////////////////////////////////////////////	// GPS small label label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("GPS Small Label")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// GPS small label checkbox	//////////////////////////////////////////////////////////////////////////	m_pctlGPSSmallLabel = new wxCheckBox(this, -1, wxT(""));	m_pctlGPSSmallLabel->SetValue(g_pConfig->Read(wxT("GPS Small Label"), true));	psizerGrid->Add(		m_pctlGPSSmallLabel,		0,		wxALIGN_LEFT,		0	);	//////////////////////////////////////////////////////////////////////////	// GPS arrow label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("GPS Arrow")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// GPS arrow checkbox	//////////////////////////////////////////////////////////////////////////	m_pctlGPSArrow = new wxCheckBox(this, -1, wxT(""));	m_pctlGPSArrow->SetValue(g_pConfig->Read(wxT("GPS Arrow"), true));	psizerGrid->Add(		m_pctlGPSArrow,		0,		wxALIGN_LEFT,		0	);	//////////////////////////////////////////////////////////////////////////	// GPS icon label	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("GPS Icon")),		0,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		wxBoxSizer * sizerIcon = new wxBoxSizer(wxHORIZONTAL);	//////////////////////////////////////////////////////////////////////////	// GPS icon text control	//////////////////////////////////////////////////////////////////////////	m_pctlGPSIcon = new wxTextCtrl(this, -1, g_pConfig->Read(wxT("GPS Icon"), wxT("")), wxDefaultPosition, wxSize(250, -1));	sizerIcon->Add(m_pctlGPSIcon, 1, wxGROW | wxALL, 5);	wxButton * btnIconBrowse= new wxButton(this, idIconBrowse, wxT("&Browse..."));	sizerIcon->Add(btnIconBrowse, 0, wxALIGN_RIGHT | wxALL, 5);	psizerGrid->Add(		sizerIcon,		0,		wxALIGN_LEFT,		0	);	//////////////////////////////////////////////////////////////////////////	// psizerWnd just adds a border to psizerGrid	//////////////////////////////////////////////////////////////////////////		psizerWnd = new wxBoxSizer(wxVERTICAL);	psizerWnd->Add(		psizerGrid,		0,		wxALL | wxGROW,		10	);		//////////////////////////////////////////////////////////////////////////	// Set up the sizer	//////////////////////////////////////////////////////////////////////////	m_pctlGPSType->SetFocus();	psizerWnd->Fit(this);	SetSizer(psizerWnd);	Layout();	psizerWnd->SetSizeHints(this);	wxCommandEvent ev;	OnGPSTypeChange(ev);	}//////////////////////////////////////////////////////////////////////////////////// \brief Ok was pressed .. save the settings/////////////////////////////////////////////////////////////////////////////////void PreferencesPageGPS::OnOk(wxCommandEvent& event){	long lBaudRate;	if (m_pctlGPSType->GetValue() == wxT("None"))		GPSMonitorThread::SetGPSType(GPSTypeNone);	if (m_pctlGPSType->GetValue() == wxT("Auto Detect"))		GPSMonitorThread::SetGPSType(GPSTypeAutoDetect);#ifdef ROADNAV_SERIAL_SUPPORT	if (m_pctlGPSType->GetValue() == wxT("Serial"))		GPSMonitorThread::SetGPSType(GPSTypeSerial);#endif#ifdef HAVE_LIBGPS	if (m_pctlGPSType->GetValue() == wxT("gpsd"))		GPSMonitorThread::SetGPSType(GPSTypeGPSD);#endif#ifdef HAVE_SIMULATED_GPS_SUPPORT	if (m_pctlGPSType->GetValue() == wxT("Simulated"))		GPSMonitorThread::SetGPSType(GPSTypeSimulated);#endif	g_pConfig->Write(wxT("GPSSerialPort"), m_pctlSerialPort->GetValue());	m_pctlBaudRate->GetValue().ToLong(&lBaudRate);	g_pConfig->Write(wxT("GPSBaudRate"), lBaudRate);#ifdef HAVE_LIBGPS	g_pConfig->Write(wxT("gpsdHost"), m_pctlgpsdHost->GetValue());	g_pConfig->Write(wxT("gpsdPort"), m_pctlgpsdPort->GetValue());	g_pConfig->Write(wxT("gpsdCompatibilityCheck"), m_pctlgpsdCompatibilityCheck->GetValue());#endif	g_pConfig->Write(wxT("GPS Callout Box"), m_pctlGPSCalloutBox->GetValue());	g_pConfig->Write(wxT("GPS Small Label"), m_pctlGPSSmallLabel->GetValue());	g_pConfig->Write(wxT("GPS Arrow"), m_pctlGPSArrow->GetValue());	g_pConfig->Write(wxT("GPS Icon"), m_pctlGPSIcon->GetValue());}void PreferencesPageGPS::OnGPSTypeChange(wxCommandEvent & event){#ifdef ROADNAV_SERIAL_SUPPORT	m_pctlSerialPort->Enable(m_pctlGPSType->GetValue() == wxT("Serial"));	m_pctlBaudRate->Enable(m_pctlGPSType->GetValue() == wxT("Serial"));#endif#ifdef HAVE_LIBGPS	m_pctlgpsdHost->Enable(m_pctlGPSType->GetValue() == wxT("gpsd"));	m_pctlgpsdPort->Enable(m_pctlGPSType->GetValue() == wxT("gpsd"));	m_pctlgpsdCompatibilityCheck->Enable(m_pctlGPSType->GetValue() == wxT("gpsd"));#endif}//////////////////////////////////////////////////////////////////////////////////// \brief Browse button pressed. Lets a bitmap be used to indicate GPS/// position./////////////////////////////////////////////////////////////////////////////////void PreferencesPageGPS::OnIconBrowse(wxCommandEvent& event){	wxFileDialog dlg(this,					wxT("Select icon..."),					wxT(""),					wxT(""),					wxT("Images|*.bmp;*.png;*.jpg;*.jpeg;*.gif;*.pcx;*.pnm;*.tif;*.tiff;*.xpm;*.ico"),					wxOPEN					);	if (dlg.ShowModal() == wxID_OK)		m_pctlGPSIcon->SetValue(dlg.GetPath());}

⌨️ 快捷键说明

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