📄 locationpageaddress.cpp
字号:
/* * Roadnav * LocationPageAddress.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////// \brief This location page allows a street address to be entered./////////////////////////////////////////////////////////////////////////////////#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 <wx/valgen.h>#include <vector>#include "App.h"#include "LocationPageAddress.h"#include "libroadnav/MapLookup.h"#include "libroadnav/MapState.h"#include "libroadnav/Map.h"#include "libroadnav/MapAbbreviations.h"#include "libroadnav/MapZip.h"#include "libroadnav/MapRepresentations.h"#include "libroadnav/MapControlDataImporter_GNISDECI.h"#include "libroadnav/MapControlDataImporter_TigerLine.h"using namespace std;//////////////////////////////////////////////////////////////////////////////////// Event table for LocationPageAddress/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(LocationPageAddress, wxPanel)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief Constructor - create the controls/////////////////////////////////////////////////////////////////////////////////LocationPageAddress::LocationPageAddress(wxWindow *parent, MapControl * pctlMap) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER){ wxBoxSizer * sizerWnd = new wxBoxSizer(wxVERTICAL); m_pctlMap = pctlMap; ////////////////////////////////////////////////////////////////////////////// // street entry ////////////////////////////////////////////////////////////////////////////// sizerWnd->Add( new wxStaticText(this, -1, wxT("Street"), wxDefaultPosition), 1, wxALIGN_LEFT | wxALIGN_BOTTOM | wxLEFT | wxRIGHT | wxTOP, 5); m_ctlStreet = new wxTextCtrl(this, -1, m_strStreet, wxDefaultPosition, wxSize(200, -1), 0, wxGenericValidator(&m_strStreet)); sizerWnd->Add(m_ctlStreet, 1, wxGROW | wxALL, 5); ////////////////////////////////////////////////////////////////////////////// // city entry ////////////////////////////////////////////////////////////////////////////// sizerWnd->Add( new wxStaticText(this, -1, wxT("City"), wxDefaultPosition), 1, wxALIGN_LEFT | wxALIGN_BOTTOM | wxLEFT | wxRIGHT | wxTOP, 5); m_ctlCity = new wxTextCtrl(this, -1, m_strCity, wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&m_strCity)); sizerWnd->Add(m_ctlCity, 1, wxGROW | wxALL, 5); ////////////////////////////////////////////////////////////////////////////// // state entry ////////////////////////////////////////////////////////////////////////////// sizerWnd->Add( new wxStaticText(this, -1, wxT("State"), wxDefaultPosition), 1, wxALIGN_LEFT | wxALIGN_BOTTOM | wxLEFT | wxRIGHT | wxTOP, 5); m_ctlState = new wxTextCtrl(this, -1, m_strState, wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&m_strState)); sizerWnd->Add(m_ctlState, 1, wxGROW | wxALL, 5); ////////////////////////////////////////////////////////////////////////// // Set up the sizer ////////////////////////////////////////////////////////////////////////// m_ctlStreet->SetFocus(); sizerWnd->Fit(this); SetSizer(sizerWnd); Layout(); sizerWnd->SetSizeHints(this); }///////////////////////////////////////////////////////////////////////////////// /// \brief Parse the entered addresses.////// This function parses the address that was entered into it and returns/// an Address pointer. Multiple calls to GetAddress will return the same/// pointer since FindAddress is used./////////////////////////////////////////////////////////////////////////////////Address LocationPageAddress::GetAddress(wxString * pstrErrorMsg, bool bRoadsOnly){ int iAutoDownloadMaps = 1; vector<bool> bVisibility; wxString strState; int iTotalDownload; vector<wxUint32> vZips; if (bRoadsOnly) { int iRT; for (iRT = FIRST_RECORD_TYPE; iRT <= LAST_RECORD_TYPE; iRT++) { bVisibility.push_back(iRT >= FIRST_RECORD_TYPE_ROAD && iRT <= LAST_RECORD_TYPE_ROAD); } } ////////////////////////////////////////////////////////////////////////// // state .. convert to abbreviation if necessary ////////////////////////////////////////////////////////////////////////// strState = StateAbbreviationByName(m_strState); if (strState == wxT("")) strState = m_strState; strState = strState.MakeUpper(); ////////////////////////////////////////////////////////////////////////// // 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(m_strCity, m_strState); 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(m_pctlMap->GetMapControlData(), iCountyCode, &dlgProgress, iCount * 100, 100); iCount++; } if (!diGNIS.IsGNISStateLoaded(strState)) { diGNIS.DownloadGNISState(m_pctlMap->GetMapControlData(), strState, &dlgProgress, iCount * 100, 100); iCount++; } } // downloading complete iTotalDownload = 0; } } Address sAddr; sAddr = FindAddress(m_strStreet, m_strCity, m_strState, bVisibility, NULL, pstrErrorMsg); if (!sAddr.m_bValid && pstrErrorMsg) { if (iTotalDownload) *pstrErrorMsg = wxT("Maps unavailable for that address. Please download them first."); } return sAddr; }///////////////////////////////////////////////////////////////////////////////// /// \brief Set the text fields to a certain address./////////////////////////////////////////////////////////////////////////////////void LocationPageAddress::SetAddress(Address cAddress){ m_strStreet = wxT(""); if (cAddress.m_iStreetNumber) m_strStreet += wxString::Format(wxT("%d "), cAddress.m_iStreetNumber); m_strStreet += cAddress.m_strStreetName + wxT(" ") + cAddress.m_strStreetType; m_strCity = cAddress.m_strCityName; m_strState = cAddress.m_strStateName; m_strState = StateAbbreviationByName(m_strState); TransferDataToWindow();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -