📄 support.cpp
字号:
/* * Roadnav * Support.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////// General support functions/////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H# include <config.h>#endif#ifdef HAVE_MATH_H#include <math.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include <wx/wx.h>#include <wx/stdpaths.h>#include <map>#include "libroadnav/Constants.h"#include "libroadnav/MapState.h"#include "libroadnav/MapZip.h"#include "libroadnav/MapControlDataImporter_GNISDECI.h"#include "libroadnav/MapControlDataImporter_TigerLine.h"#include "libroadnav/MapControlData_Tiles.h"#include "libroadnav/MapLookup.h"#include "libroadnav/MapSupport.h"#include "App.h"#include "Support.h"#include "KeyboardDialog.h"#include "LocationDialog.h"#include "WaypointDialog.h"using namespace std;//////////////////////////////////////////////////////////////////////////////////// \brief Returns the location of the Roadnav common directory, where states.tdf,/// zips.tdf, and abbreviations.txt are stored./////////////////////////////////////////////////////////////////////////////////wxString RoadnavCommonDirectory(){ wxStandardPathsBase & p = wxStandardPaths::Get(); return p.GetDataDir();}//////////////////////////////////////////////////////////////////////////////////// \brief Returns the command used to shutdown this computer/////////////////////////////////////////////////////////////////////////////////wxString GetDefaultShutdownCommand(){#ifdef __WINDOWS__ OSVERSIONINFO sVersionInfo; sVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&sVersionInfo); if (sVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) return wxT("RUNDLL32.EXE user,exitwindows"); // Win95 line else return wxT("shutdown -s -t 5"); // WinNT line#else return wxT("sudo poweroff");#endif}int DownloadCityState(const wxString & strCity, const wxString & strState, IMapControlData * pData){ wxString strStateMod; int iTotalDownload; int iAutoDownloadMaps = 1; vector<wxUint32> vZips; strStateMod = StateAbbreviationByName(strState); if (strStateMod == wxT("")) strStateMod = strState; strStateMod = strStateMod.Upper(); ////////////////////////////////////////////////////////////////////////// // download if necessary and enabled ////////////////////////////////////////////////////////////////////////// g_pConfig->Read(wxT("AutoDownloadMaps"), &iAutoDownloadMaps, 1); { unsigned int i; map<int,bool> bDownloadingCounty; map<wxString,bool> bDownloadingState; vZips = ZipCodesByCityState(strCity, strStateMod); iTotalDownload = 0; for (i = 0; i < vZips.size(); i++) { int iCountyCode = CountyCodeByZip(vZips[i]); MapControlDataImporter_GNISDECI diGNIS; MapControlDataImporter_TigerLine diTigerLine; if (!diTigerLine.IsCountyLoaded(iCountyCode)) { if (bDownloadingCounty.find(iCountyCode) == bDownloadingCounty.end()) { bDownloadingCounty[iCountyCode] = true; iTotalDownload++; } } if (!diGNIS.IsGNISStateLoaded(strState)) { if (bDownloadingState.find(strState) == bDownloadingState.end()) { bDownloadingState[strState] = true; iTotalDownload++; } } } } if (iAutoDownloadMaps) { if (iTotalDownload) { int iCount; unsigned int i; ProgressDialog dlgProgress(NULL, wxT("Downloading..."), iTotalDownload * 100); dlgProgress.Show(); iCount = 0; for (i = 0; i < vZips.size(); i++) { int iCountyCode = CountyCodeByZip(vZips[i]); MapControlDataImporter_GNISDECI diGNIS; MapControlDataImporter_TigerLine diTigerLine; if (!diTigerLine.IsCountyLoaded(iCountyCode)) { diTigerLine.DownloadCounty(pData, iCountyCode, &dlgProgress, iCount * 100, 100); iCount++; } if (!diGNIS.IsGNISStateLoaded(strState)) { diGNIS.DownloadGNISState(pData, strState, &dlgProgress, iCount * 100, 100); iCount++; } } // downloading complete iTotalDownload = 0; } } return iTotalDownload;}int QueryAddress( const wxString & strTitle, wxWindow * pParent, MapControl * pctlMap, const wxString & strDefaultStreet, const wxString & strDefaultCity, const wxString & strDefaultState, bool bRoadsOnly, MapMarker * pcMarker, wxString * pstrErrorMsg, int iSimple){ if (iSimple == 2) iSimple = !g_pConfig->Read(wxT("AlwaysUseAdvancedWaypointsDialog"), (long) 0); if (iSimple) { wxFont fntThis = pParent->GetFont(); wxTextCtrl ctlText(pParent, -1); WaypointDialog dlgExisting(pParent, pctlMap, &fntThis, wxT("Select Waypoint"), strTitle); switch (dlgExisting.ShowModal()) { case wxID_CANCEL: return wxID_CANCEL; case wxID_OK: break; default: // advanced entry return QueryAddress(strTitle, pParent, pctlMap, strDefaultStreet, strDefaultCity, strDefaultState, bRoadsOnly, pcMarker, pstrErrorMsg, false); } *pcMarker = dlgExisting.GetMarker(); if (pcMarker->m_cAddress.m_bValid) return wxID_OK; wxString strState = strDefaultState; wxString strCity = strDefaultCity; wxString strStreet = strDefaultStreet; ctlText.Show(false); { AutoComplete_State m_cAutoCompleteState; ctlText.SetValue(strState); KeyboardDialog dlg( pParent, strTitle + wxT(" - Enter state"), &ctlText, pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground), pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground), &m_cAutoCompleteState); if (dlg.ShowModal() != wxID_OK) return wxID_CANCEL; strState = ctlText.GetValue(); } { AutoComplete_City m_cAutoCompleteCity; m_cAutoCompleteCity.SetState(strState); ctlText.SetValue(strCity); KeyboardDialog dlg( pParent, strTitle + wxT(" - Enter city"), &ctlText, pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground), pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground), &m_cAutoCompleteCity); if (dlg.ShowModal() != wxID_OK) return wxID_CANCEL; strCity = ctlText.GetValue(); } MapControlData_Tiles cRec; DownloadCityState(strCity, strState, &cRec); { AutoComplete_Street m_cAutoCompleteStreet; m_cAutoCompleteStreet.SetState(strState); m_cAutoCompleteStreet.SetCity(strCity); ctlText.SetValue(strStreet); KeyboardDialog dlg( pParent, strTitle + wxT(" - Enter street"), &ctlText, pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground), pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground), &m_cAutoCompleteStreet); if (dlg.ShowModal() != wxID_OK) return wxID_CANCEL; strStreet = ctlText.GetValue(); } bool bTryAgain = true; int iAttemptsLeft = 4; Address cAddr; while (bTryAgain && iAttemptsLeft--) { wxString strSuggestedStreet; wxString strSuggestedCity; wxString strSuggestedState; cAddr = FindAddress( strStreet, strCity, strState, bRoadsOnly ? OnlyRoadsVisibility() : AllVisibility(), NULL, pstrErrorMsg, &strSuggestedStreet, &strSuggestedCity, &strSuggestedState); if (!cAddr.m_bValid) { if (strSuggestedState != wxT("")) { strState = strSuggestedState; bTryAgain = true; } else if (strSuggestedCity != wxT("")) { strCity = strSuggestedCity; bTryAgain = true; } else if (strSuggestedStreet != wxT("")) { strStreet = strSuggestedStreet; bTryAgain = true; } } } // while (bTryAgain && iAttemptsLeft--) pcMarker->Init(wxT("Selected Address"), &cAddr); } else { // advanced address dialog wxFont fntThis = pParent->GetFont(); LocationDialog dlgAddress(pParent, pctlMap, ADFLAG_CANCELBUTTON, &fntThis); dlgAddress.m_bRoadsOnly = bRoadsOnly; if (dlgAddress.ShowModal() == wxID_OK) { Address cAddr; if (dlgAddress.m_strName == wxT("")) dlgAddress.m_strName = wxT("Selected Address"); cAddr = dlgAddress.GetAddress(pstrErrorMsg); pcMarker->Init( dlgAddress.m_strName, &cAddr, -1, dlgAddress.m_bShowCalloutBox, dlgAddress.m_bShowSmallLabel, true, dlgAddress.m_strIconFilename, dlgAddress.m_bScaleIcon, dlgAddress.m_bVisible); } else { return wxID_CANCEL; } } return wxID_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -