📄 frame.cpp
字号:
/* * Roadnav * Frame.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 frame class for the application, and the associated/// event handlers./////////////////////////////////////////////////////////////////////////////////#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/minifram.h>#include <wx/string.h>#include <wx/print.h>#include <wx/printdlg.h>#include <wx/filename.h>#include <wx/tokenzr.h>#if defined _WINDOWS#include <windows.h> // for WM_TIMECHANGE#endif#ifdef HAVE_MATH_H#include <math.h>#endif#include "libroadnav/Map.h"#include "libroadnav/MapLookup.h"#include "libroadnav/MapSupport.h"#include "libroadnav/MapRepresentations.h"#include "libroadnav/Debug.h"#include "App.h"#include "Frame.h"#include "MapEventExtender.h"#include "GPSMonitorThread.h"#include "LocationDialog.h"#include "CountyDialog.h"#include "libroadnav/MapCounty.h"#include "libroadnav/MapState.h"#include "Printout.h"#include "PreferencesDialog.h"#include "SaveAsSettingsDialog.h"#include "TTS.h"#include "libroadnav/MapControlDataImporter_GNISDECI.h"#include "libroadnav/MapControlDataImporter_TigerLine.h"#ifdef USE_OPENSTREETMAP#include "libroadnav/MapControlDataImporter_OSM.h"#endif#include "libroadnav/MapZip.h"#include "libroadnav/URLs.h"#include "libroadnav/DownloadFiles.h"#include "LCDprocInterface.h"#include "appicon16.xpm"#include "appicon32.xpm"#include "appicon64.xpm"#include <vector>using namespace std;///////////////////////////////////////////////////////////////////////////////// /// Menu item IDs/////////////////////////////////////////////////////////////////////////////////enum{ idMapControl = 0, idWhatsNearBy,#ifdef USE_SCRIPTING idFileRunScript,#endif idFileSaveAs, idFilePrint, idFilePrintPreview, idViewCompass, idViewAerialPhotos, idView3DMode, idViewScale, idViewGPSHistory, idViewZoomIn, idViewZoomOut, idViewZoomMax, idViewZoomMin, idViewGPSMarker, idViewGPSWindow, idViewWhatsNearByWindow, idViewFullScreen, idMapSetAddress, idMapWaypoints, idMapSetAngle, idMapGetDirections, idMapGetDirectionsAccel, idMapMoveCenterLeft, idMapMoveCenterRight, idMapMoveCenterUp, idMapMoveCenterDown, idToolsMeasure, idToolsZoom, idToolsDownloadMaps,#ifdef USE_OPENSTREETMAP idToolsDownloadOSMMaps, idToolsImportOSMMaps,#endif idSolarTimerTest, idRefreshMapControl, idEscape};#define TIMER_INIT 4#ifdef USE_SCRIPTING#define TIMER_SCRIPTING 5#endif//////////////////////////////////////////////////////////////////////////////////// MapFrame event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(MapFrame, wxFrame)#ifdef USE_SCRIPTING EVT_MENU (idFileRunScript, MapFrame::OnFileRunScript)#endif EVT_MENU (idFileSaveAs, MapFrame::OnFileSaveAs) EVT_BUTTON(idFileSaveAs, MapFrame::OnFileSaveAs) EVT_MENU (idFilePrint, MapFrame::OnFilePrint) EVT_BUTTON(idFilePrint, MapFrame::OnFilePrint) EVT_MENU (idFilePrintPreview, MapFrame::OnFilePrintPreview) EVT_MENU (wxID_EXIT, MapFrame::OnFileExit) EVT_BUTTON(wxID_EXIT, MapFrame::OnFileExit) EVT_MENU (idViewCompass, MapFrame::OnViewCompass) EVT_MENU (idViewAerialPhotos, MapFrame::OnViewAerialPhotos) EVT_MENU (idView3DMode, MapFrame::OnView3DMode) EVT_MENU (idViewScale, MapFrame::OnViewScale) EVT_MENU (idViewGPSHistory, MapFrame::OnViewGPSHistory) EVT_MENU (idViewZoomIn, MapFrame::OnViewZoomIn) EVT_BUTTON(idViewZoomIn, MapFrame::OnViewZoomIn) EVT_MENU (idViewZoomOut, MapFrame::OnViewZoomOut) EVT_BUTTON(idViewZoomOut, MapFrame::OnViewZoomOut) EVT_MENU (idViewZoomMax, MapFrame::OnViewZoomMax) EVT_MENU (idViewZoomMin, MapFrame::OnViewZoomMin) EVT_MENU (idViewGPSMarker, MapFrame::OnViewGPSMarker) EVT_MENU (idViewGPSWindow, MapFrame::OnViewGPSWindow) EVT_MENU (idViewWhatsNearByWindow, MapFrame::OnViewWhatsNearByWindow) EVT_MENU (idViewFullScreen, MapFrame::OnViewFullScreen) EVT_MENU (idMapSetAddress, MapFrame::OnMapSetAddress) EVT_BUTTON(idMapSetAddress, MapFrame::OnMapSetAddress) EVT_MENU (idMapWaypoints, MapFrame::OnMapWaypoints) EVT_MENU (idMapSetAngle, MapFrame::OnMapSetAngle) EVT_MENU (idMapGetDirections, MapFrame::OnMapGetDirections) EVT_BUTTON(idMapGetDirections, MapFrame::OnMapGetDirectionsAccel) EVT_MENU (idMapGetDirectionsAccel, MapFrame::OnMapGetDirectionsAccel) EVT_MENU (idMapMoveCenterLeft, MapFrame::OnMapMoveCenterLeft) EVT_BUTTON(idMapMoveCenterLeft, MapFrame::OnMapMoveCenterLeft) EVT_MENU (idMapMoveCenterRight, MapFrame::OnMapMoveCenterRight) EVT_BUTTON(idMapMoveCenterRight, MapFrame::OnMapMoveCenterRight) EVT_MENU (idMapMoveCenterUp, MapFrame::OnMapMoveCenterUp) EVT_BUTTON(idMapMoveCenterUp, MapFrame::OnMapMoveCenterUp) EVT_MENU (idMapMoveCenterDown, MapFrame::OnMapMoveCenterDown) EVT_BUTTON(idMapMoveCenterDown, MapFrame::OnMapMoveCenterDown) EVT_MENU (idToolsMeasure, MapFrame::OnToolsMeasure) EVT_UPDATE_UI(idToolsMeasure, MapFrame::OnUpdateToolsMeasure) EVT_MENU (idToolsZoom, MapFrame::OnToolsZoom) EVT_UPDATE_UI(idToolsZoom, MapFrame::OnUpdateToolsZoom) EVT_BUTTON(idToolsDownloadMaps, MapFrame::OnToolsDownloadTIGERLineMaps) EVT_MENU (idToolsDownloadMaps, MapFrame::OnToolsDownloadTIGERLineMaps)#ifdef USE_OPENSTREETMAP EVT_MENU (idToolsDownloadOSMMaps, MapFrame::OnToolsDownloadOSMMaps) EVT_MENU (idToolsImportOSMMaps, MapFrame::OnToolsImportOSMMaps)#endif EVT_BUTTON(wxID_PREFERENCES, MapFrame::OnToolsPreferences) EVT_MENU (wxID_PREFERENCES, MapFrame::OnToolsPreferences) EVT_MENU (wxID_ABOUT, MapFrame::OnHelpAbout) EVT_MENU (idSolarTimerTest, MapFrame::OnSolarTimerTest) EVT_MENU (idRefreshMapControl, MapFrame::RedrawMap) EVT_MENU (idEscape, MapFrame::OnEscapeKey) EVT_BUTTON(idWhatsNearBy, MapFrame::OnWhatsNearbyDoubleClick) EVT_BUTTON(idMapControl, MapFrame::OnMapRecentered) EVT_COMMAND_RIGHT_CLICK(idMapControl, MapFrame::OnDownloadCounty) EVT_SOLAR(MapFrame::OnSolarEvent) EVT_IDLE(MapFrame::OnIdle) EVT_SIZE(wxSkinnableFrame::OnSize) EVT_TIMER(TIMER_REFRESH, wxSkinnableFrame::OnTimerRefresh) EVT_TIMER(TIMER_INIT, MapFrame::OnTimerInit)#ifdef USE_SCRIPTING EVT_TIMER(TIMER_SCRIPTING, MapFrame::OnTimerScripting)#endif EVT_GPS(MapFrame::OnGPSUpdate) EVT_CLOSE(MapFrame::OnClose)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief MapFrame constructor - create controls and initialize them/////////////////////////////////////////////////////////////////////////////////MapFrame::MapFrame(wxString title) : wxSkinnableFrame((wxFrame *) NULL, -1, title){ ////////////////////////////////////////////////////////////////////////////// // Icon ////////////////////////////////////////////////////////////////////////////// wxIconBundle icbApp; wxIcon icoApp16; wxBitmap bmpAppIcon16(appicon16_xpm); icoApp16.CopyFromBitmap(bmpAppIcon16); icbApp.AddIcon(icoApp16); wxIcon icoApp32; wxBitmap bmpAppIcon32(appicon32_xpm); icoApp32.CopyFromBitmap(bmpAppIcon32); icbApp.AddIcon(icoApp32); wxIcon icoApp64; wxBitmap bmpAppIcon64(appicon64_xpm); icoApp64.CopyFromBitmap(bmpAppIcon64); icbApp.AddIcon(icoApp64); SetIcons(icbApp); ////////////////////////////////////////////////////////////////////////////// // Initialize variables ////////////////////////////////////////////////////////////////////////////// m_ptGPS.Set(0, 0); m_fGPSHeading = 0; m_fGPSSpeed = 0; m_bOnGPSInProgress = false; m_bNewGPSData = false; m_bGPSJustRun = false; m_bScreenTracksGPS = g_pConfig->Read(wxT("TrackGPSMarker"), true); m_iSpeedControlledDetailLevelOffset = 0; m_ToolMode = toolNone; InitializeThemes(); ////////////////////////////////////////////////////////////////////////// // Create the "What's Nearby" miniframe ////////////////////////////////////////////////////////////////////////// m_pfrmWhatsNearBy = new WhatsNearByFrame(this, idWhatsNearBy, new MapControlData_Tiles()); ////////////////////////////////////////////////////////////////////////////// // Create controls ////////////////////////////////////////////////////////////////////////////// m_ctlMap = new MapControl(&m_cRecords, &m_MapAppearanceSettings, this, idMapControl, wxDefaultPosition, wxDefaultSize); ////////////////////////////////////////////////////////////////////////////// // Extend map control event handling ////////////////////////////////////////////////////////////////////////////// m_ctlMap->PushEventHandler(new MapEventExtender(this, m_ctlMap)); ////////////////////////////////////////////////////////////////////////////// // Add map control to skin ////////////////////////////////////////////////////////////////////////////// AddNamedControl(m_ctlMap, wxT("map")); m_pctlCompass = NULL; ////////////////////////////////////////////////////////////////////////////// // File Menu ////////////////////////////////////////////////////////////////////////////// wxMenu * menuFile = new wxMenu;#ifdef USE_SCRIPTING menuFile->Append(idFileRunScript, wxT("Run S&cript..."));#endif menuFile->Append(idFileSaveAs, wxT("Save &as...\tCtrl-s")); menuFile->Append(idFilePrint, wxT("&Print...\tCtrl-p")); menuFile->Append(idFilePrintPreview, wxT("P&rint Preview...")); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT, wxT("E&xit")); ////////////////////////////////////////////////////////////////////////////// // View Menu ////////////////////////////////////////////////////////////////////////////// m_menuView = new wxMenu; m_menuView->AppendCheckItem(idViewCompass, wxT("&Compass")); m_menuView->Check(idViewCompass, TRUE); m_menuView->AppendCheckItem(idViewAerialPhotos, wxT("Aerial &Photos")); m_menuView->Check(idViewAerialPhotos, g_pConfig->Read(wxT("AerialPhotosVisible"), (long int) 0)); m_menuView->AppendCheckItem(idView3DMode, wxT("&3D Mode")); m_menuView->Check(idView3DMode, g_pConfig->Read(wxT("3DMode"), (long int) 0)); m_menuView->AppendCheckItem(idViewScale, wxT("&Scale")); m_menuView->Check(idViewScale, TRUE); m_menuView->AppendCheckItem(idViewGPSHistory, wxT("GPS &History")); m_menuView->Check(idViewGPSHistory, g_pConfig->Read(wxT("GPSHistory"), (long int) 1)); m_menuView->AppendCheckItem(idViewGPSMarker, wxT("Map Tracks &GPS")); m_menuView->Check(idViewGPSMarker, m_bScreenTracksGPS); m_menuView->AppendCheckItem(idViewGPSWindow, wxT("G&PS Window")); m_menuView->Check(idViewGPSWindow, g_pConfig->Read(wxT("GPSWindowVisible"), (long int) 0)); m_menuView->AppendCheckItem(idViewWhatsNearByWindow, wxT("What's Nearby Window")); m_menuView->Check(idViewWhatsNearByWindow, g_pConfig->Read(wxT("WhatsNearByWindowVisible"), (long int) 0)); m_menuView->AppendSeparator(); m_menuView->Append(idViewZoomIn, wxT("Zoom &In\t+")); m_menuView->Append(idViewZoomOut, wxT("Zoom &Out\t-")); m_menuView->Append(idViewZoomMax, wxT("Zoom Max")); m_menuView->Append(idViewZoomMin, wxT("Zoom Min"));#if defined(__DARWIN__) m_menuView->AppendCheckItem(idViewFullScreen, wxT("&Full Screen\tCtrl-Shift-F"));#else m_menuView->AppendCheckItem(idViewFullScreen, wxT("&Full Screen\tF11"));#endif m_menuView->Check(idViewFullScreen, FALSE); ////////////////////////////////////////////////////////////////////////////// // Map Menu ////////////////////////////////////////////////////////////////////////////// m_menuMap = new wxMenu; m_menuMap->Append(idMapSetAddress, wxT("Set &Address...\tCtrl-A")); m_menuMap->Append(idMapWaypoints, wxT("&Waypoints...")); m_menuMap->Append(idMapSetAngle, wxT("Set Map Orientation...")); m_menuMap->AppendCheckItem(idMapGetDirections, wxT("Get &Directions...\tCtrl-D")); m_menuMap->Check(idMapGetDirections, (long int) 0); ////////////////////////////////////////////////////////////////////////////// // Tools Menu ////////////////////////////////////////////////////////////////////////////// wxMenu * menuTools = new wxMenu; menuTools->AppendCheckItem(idToolsMeasure, wxT("Measure")); menuTools->AppendCheckItem(idToolsZoom, wxT("Zoom")); menuTools->AppendSeparator(); menuTools->Append(idToolsDownloadMaps, wxT("Download TIGER/Line &Maps..."));#ifdef USE_OPENSTREETMAP menuTools->Append(idToolsDownloadOSMMaps, wxT("Download &OpenStreetMap Maps...")); menuTools->Append(idToolsImportOSMMaps, wxT("Import O&penStreetMap XML Maps..."));#endif menuTools->Append(wxID_PREFERENCES, wxT("&Preferences...")); ////////////////////////////////////////////////////////////////////////////// // Help Menu ////////////////////////////////////////////////////////////////////////////// wxMenu * menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT, wxT("&About...")); ////////////////////////////////////////////////////////////////////////////// // Menu Bar ////////////////////////////////////////////////////////////////////////////// wxMenuBar * mbMenu = new wxMenuBar(wxMB_DOCKABLE); mbMenu->Append(menuFile, wxT("&File")); mbMenu->Append(m_menuView, wxT("&View")); mbMenu->Append(m_menuMap, wxT("&Map")); mbMenu->Append(menuTools, wxT("&Tools")); mbMenu->Append(menuHelp, wxT("&Help")); SetMenuBar(mbMenu); ////////////////////////////////////////////////////////////////////////// // Accelerators ////////////////////////////////////////////////////////////////////////// wxAcceleratorEntry entries[15]; entries[0].Set(wxACCEL_NORMAL, (int) wxT('+'), idViewZoomIn); entries[1].Set(wxACCEL_NORMAL, (int) wxT('='), idViewZoomIn); entries[2].Set(wxACCEL_SHIFT, (int) wxT('='), idViewZoomIn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -