00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifdef HAVE_CONFIG_H
00030 # include <config.h>
00031 #endif
00032
00033 #ifdef _MSC_VER
00034 #pragma warning(disable: 4786)
00035 #pragma warning(disable: 4800)
00036 #endif
00037
00038 #include <wx/wx.h>
00039 #include <wx/minifram.h>
00040 #include <wx/string.h>
00041 #include <wx/print.h>
00042 #include <wx/printdlg.h>
00043 #include <wx/filename.h>
00044 #include <wx/tokenzr.h>
00045 #include <wx/choicdlg.h>
00046
00047 #if defined _WINDOWS
00048 #include <windows.h>
00049 #endif
00050
00051 #ifdef HAVE_MATH_H
00052 #include <math.h>
00053 #endif
00054
00055 #include "libroadnav/Map.h"
00056 #include "libroadnav/MapLookup.h"
00057 #include "libroadnav/MapSupport.h"
00058 #include "libroadnav/MapMath.h"
00059 #include "libroadnav/MapRepresentations.h"
00060 #include "libroadnav/Debug.h"
00061 #include "Frame.h"
00062 #include "MapEventExtender.h"
00063 #include "GPSMonitorThread.h"
00064 #include "LocationDialog.h"
00065 #include "CountyDialog.h"
00066 #include "libroadnav/MapCounty.h"
00067 #include "libroadnav/MapState.h"
00068 #include "Printout.h"
00069 #include "SaveAsSettingsDialog.h"
00070 #include "libroadnav/MapDataImporter_GNISDECI.h"
00071 #include "libroadnav/MapDataImporter_TigerLine.h"
00072 #include "TTSFactory.h"
00073 #include "Support.h"
00074 #include "KeyboardDialog.h"
00075 #include "libroadnav/StringTable.h"
00076
00077 #include "OptionsLaunch.h"
00078
00079 #ifdef USE_OPENSTREETMAP
00080 #include "libroadnav/MapDataImporter_OSM.h"
00081 #endif
00082
00083 #include "libroadnav/MapDataImporter_GPX.h"
00084
00085 #include "libroadnav/MapZip.h"
00086 #include "libroadnav/URLs.h"
00087 #include "libroadnav/DownloadFiles.h"
00088 #include "LCDprocInterface.h"
00089
00090 #include "appicon16.xpm"
00091 #include "appicon32.xpm"
00092 #include "appicon64.xpm"
00093
00094 #include <vector>
00095
00096 using namespace std;
00097
00098
00099
00100
00101
00102
00103 enum
00104 {
00105 idMapControl = 0,
00106 idWhatsNearBy,
00107
00108 #ifdef USE_SCRIPTING
00109 idFileRunScript,
00110 #endif
00111 idFileSaveAs,
00112 idFilePrint,
00113 idFilePrintPreview,
00114
00115 idViewCompass,
00116 idViewAerialPhotos,
00117 idView3DMode,
00118 idViewScale,
00119 idViewGPSHistory,
00120 idViewZoomIn,
00121 idViewZoomOut,
00122 idViewZoomMax,
00123 idViewZoomMin,
00124 idViewGPSMarker,
00125 idViewGPSWindow,
00126 idViewWhatsNearByWindow,
00127 idViewFullScreen,
00128
00129 idMapSetAddress,
00130 idMapWaypoints,
00131 idMapSetAngle,
00132 idMapGetDirections,
00133 idMapGetDirectionsAccel,
00134 idMapMoveCenterLeft,
00135 idMapMoveCenterRight,
00136 idMapMoveCenterUp,
00137 idMapMoveCenterDown,
00138
00139 idToolsMeasure,
00140 idToolsZoom,
00141
00142 idToolsDownloadMaps,
00143 #ifdef USE_OPENSTREETMAP
00144 idToolsDownloadOSMMaps,
00145 idToolsImportOSMMaps,
00146 #endif
00147
00148 idToolsImportGPXData,
00149
00150 idSolarTimerTest,
00151 idRefreshMapControl,
00152 idEscape,
00153
00154 idViewZoom0,
00155 idViewZoom1,
00156 idViewZoom2,
00157 idViewZoom3,
00158 idViewZoom4,
00159 idViewZoom5,
00160 idViewZoom6,
00161 idViewZoom7,
00162 idViewZoom8,
00163 idViewZoom9,
00164 idViewZoom10,
00165 idViewZoom11,
00166 idViewZoom12,
00167 idViewZoom13,
00168 idViewZoom14,
00169 };
00170
00171 #define TIMER_INIT 4
00172
00173 #ifdef USE_SCRIPTING
00174 #define TIMER_SCRIPTING 5
00175 #endif
00176
00177 #define TIMER_CONFIGFLUSH 6
00178
00179
00180
00181
00182
00183
00184 BEGIN_EVENT_TABLE(MapFrame, wxFrame)
00185 #ifdef USE_SCRIPTING
00186 EVT_MENU (idFileRunScript, MapFrame::OnFileRunScript)
00187 #endif
00188 EVT_MENU (idFileSaveAs, MapFrame::OnFileSaveAs)
00189 EVT_BUTTON(idFileSaveAs, MapFrame::OnFileSaveAs)
00190 EVT_MENU (idFilePrint, MapFrame::OnFilePrint)
00191 EVT_BUTTON(idFilePrint, MapFrame::OnFilePrint)
00192 EVT_MENU (idFilePrintPreview, MapFrame::OnFilePrintPreview)
00193 EVT_MENU (wxID_EXIT, MapFrame::OnFileExit)
00194 EVT_BUTTON(wxID_EXIT, MapFrame::OnFileExit)
00195
00196 EVT_MENU (idViewCompass, MapFrame::OnViewCompass)
00197 EVT_MENU (idViewAerialPhotos, MapFrame::OnViewAerialPhotos)
00198 EVT_MENU (idView3DMode, MapFrame::OnView3DMode)
00199 EVT_MENU (idViewScale, MapFrame::OnViewScale)
00200 EVT_MENU (idViewGPSHistory, MapFrame::OnViewGPSHistory)
00201 EVT_MENU (idViewZoomIn, MapFrame::OnViewZoomIn)
00202 EVT_BUTTON(idViewZoomIn, MapFrame::OnViewZoomIn)
00203 EVT_MENU (idViewZoomOut, MapFrame::OnViewZoomOut)
00204 EVT_BUTTON(idViewZoomOut, MapFrame::OnViewZoomOut)
00205 EVT_MENU (idViewZoomMax, MapFrame::OnViewZoomMax)
00206 EVT_MENU (idViewZoomMin, MapFrame::OnViewZoomMin)
00207 EVT_MENU (idViewGPSMarker, MapFrame::OnViewGPSMarker)
00208 EVT_BUTTON(idViewGPSMarker, MapFrame::OnViewGPSMarkerToggle)
00209 EVT_MENU (idViewGPSWindow, MapFrame::OnViewGPSWindow)
00210 EVT_MENU (idViewWhatsNearByWindow, MapFrame::OnViewWhatsNearByWindow)
00211 EVT_MENU (idViewFullScreen, MapFrame::OnViewFullScreen)
00212
00213 EVT_MENU (idMapSetAddress, MapFrame::OnMapSetAddress)
00214 EVT_BUTTON(idMapSetAddress, MapFrame::OnMapSetAddress)
00215 EVT_MENU (idMapWaypoints, MapFrame::OnMapWaypoints)
00216 EVT_MENU (idMapSetAngle, MapFrame::OnMapSetAngle)
00217 EVT_MENU (idMapGetDirections, MapFrame::OnMapGetDirections)
00218 EVT_BUTTON(idMapGetDirections, MapFrame::OnMapGetDirectionsAccel)
00219 EVT_MENU (idMapGetDirectionsAccel, MapFrame::OnMapGetDirectionsAccel)
00220 EVT_MENU (idMapMoveCenterLeft, MapFrame::OnMapMoveCenterLeft)
00221 EVT_BUTTON(idMapMoveCenterLeft, MapFrame::OnMapMoveCenterLeft)
00222 EVT_MENU (idMapMoveCenterRight, MapFrame::OnMapMoveCenterRight)
00223 EVT_BUTTON(idMapMoveCenterRight, MapFrame::OnMapMoveCenterRight)
00224 EVT_MENU (idMapMoveCenterUp, MapFrame::OnMapMoveCenterUp)
00225 EVT_BUTTON(idMapMoveCenterUp, MapFrame::OnMapMoveCenterUp)
00226 EVT_MENU (idMapMoveCenterDown, MapFrame::OnMapMoveCenterDown)
00227 EVT_BUTTON(idMapMoveCenterDown, MapFrame::OnMapMoveCenterDown)
00228
00229 EVT_MENU (idToolsMeasure, MapFrame::OnToolsMeasure)
00230 EVT_UPDATE_UI(idToolsMeasure, MapFrame::OnUpdateToolsMeasure)
00231 EVT_MENU (idToolsZoom, MapFrame::OnToolsZoom)
00232 EVT_UPDATE_UI(idToolsZoom, MapFrame::OnUpdateToolsZoom)
00233
00234 EVT_BUTTON(idToolsDownloadMaps, MapFrame::OnToolsDownloadTIGERLineMaps)
00235 EVT_MENU (idToolsDownloadMaps, MapFrame::OnToolsDownloadTIGERLineMaps)
00236
00237 #ifdef USE_OPENSTREETMAP
00238 EVT_MENU (idToolsDownloadOSMMaps, MapFrame::OnToolsDownloadOSMMaps)
00239 EVT_MENU (idToolsImportOSMMaps, MapFrame::OnToolsImportOSMMaps)
00240 #endif
00241
00242 EVT_MENU (idToolsImportGPXData, MapFrame::OnToolsImportGPXData)
00243
00244 EVT_BUTTON(wxID_PREFERENCES, MapFrame::OnToolsPreferences)
00245 EVT_MENU (wxID_PREFERENCES, MapFrame::OnToolsPreferences)
00246
00247 EVT_MENU (wxID_ABOUT, MapFrame::OnHelpAbout)
00248
00249 EVT_MENU (idSolarTimerTest, MapFrame::OnSolarTimerTest)
00250 EVT_MENU (idRefreshMapControl, MapFrame::RedrawMap)
00251
00252 EVT_MENU (idEscape, MapFrame::OnEscapeKey)
00253
00254 EVT_BUTTON(idWhatsNearBy, MapFrame::OnWhatsNearbyDoubleClick)
00255
00256 EVT_BUTTON(idMapControl, MapFrame::OnMapRecentered)
00257 EVT_COMMAND_RIGHT_CLICK(idMapControl, MapFrame::OnDownloadCounty)
00258
00259 EVT_SOLAR(MapFrame::OnSolarEvent)
00260 EVT_IDLE(MapFrame::OnIdle)
00261
00262 EVT_SIZE(wxSkinnableFrame::OnSize)
00263 EVT_TIMER(TIMER_REFRESH, wxSkinnableFrame::OnTimerRefresh)
00264
00265 EVT_TIMER(TIMER_INIT, MapFrame::OnTimerInit)
00266
00267 EVT_TIMER(TIMER_CONFIGFLUSH, MapFrame::OnTimerConfigFlush)
00268
00269 #ifdef USE_SCRIPTING
00270 EVT_TIMER(TIMER_SCRIPTING, MapFrame::OnTimerScripting)
00271 #endif
00272
00273 EVT_GPS(MapFrame::OnGPSUpdate)
00274
00275 EVT_CLOSE(MapFrame::OnClose)
00276
00277 EVT_MENU (idViewZoom0, MapFrame::OnViewZoomLevel)
00278 EVT_BUTTON(idViewZoom0, MapFrame::OnViewZoomLevel)
00279 EVT_MENU (idViewZoom1, MapFrame::OnViewZoomLevel)
00280 EVT_BUTTON(idViewZoom1, MapFrame::OnViewZoomLevel)
00281 EVT_MENU (idViewZoom2, MapFrame::OnViewZoomLevel)
00282 EVT_BUTTON(idViewZoom2, MapFrame::OnViewZoomLevel)
00283 EVT_MENU (idViewZoom3, MapFrame::OnViewZoomLevel)
00284 EVT_BUTTON(idViewZoom3, MapFrame::OnViewZoomLevel)
00285 EVT_MENU (idViewZoom4, MapFrame::OnViewZoomLevel)
00286 EVT_BUTTON(idViewZoom4, MapFrame::OnViewZoomLevel)
00287 EVT_MENU (idViewZoom5, MapFrame::OnViewZoomLevel)
00288 EVT_BUTTON(idViewZoom5, MapFrame::OnViewZoomLevel)
00289 EVT_MENU (idViewZoom6, MapFrame::OnViewZoomLevel)
00290 EVT_BUTTON(idViewZoom6, MapFrame::OnViewZoomLevel)
00291 EVT_MENU (idViewZoom7, MapFrame::OnViewZoomLevel)
00292 EVT_BUTTON(idViewZoom7, MapFrame::OnViewZoomLevel)
00293 EVT_MENU (idViewZoom8, MapFrame::OnViewZoomLevel)
00294 EVT_BUTTON(idViewZoom8, MapFrame::OnViewZoomLevel)
00295 EVT_MENU (idViewZoom9, MapFrame::OnViewZoomLevel)
00296 EVT_BUTTON(idViewZoom9, MapFrame::OnViewZoomLevel)
00297 EVT_MENU (idViewZoom10, MapFrame::OnViewZoomLevel)
00298 EVT_BUTTON(idViewZoom10, MapFrame::OnViewZoomLevel)
00299 EVT_MENU (idViewZoom11, MapFrame::OnViewZoomLevel)
00300 EVT_BUTTON(idViewZoom11, MapFrame::OnViewZoomLevel)
00301 EVT_MENU (idViewZoom12, MapFrame::OnViewZoomLevel)
00302 EVT_BUTTON(idViewZoom12, MapFrame::OnViewZoomLevel)
00303 EVT_MENU (idViewZoom13, MapFrame::OnViewZoomLevel)
00304 EVT_BUTTON(idViewZoom13, MapFrame::OnViewZoomLevel)
00305 EVT_MENU (idViewZoom14, MapFrame::OnViewZoomLevel)
00306 EVT_BUTTON(idViewZoom14, MapFrame::OnViewZoomLevel)
00307 END_EVENT_TABLE()
00308
00309
00310
00311
00312
00313
00314 MapFrame::MapFrame(wxString title) : wxSkinnableFrame((wxFrame *) NULL, -1, title), m_tLastRoadTypeZoomingCheck((time_t) 0)
00315 {
00316 wxConfigBase * pConfig = wxConfigBase::Get();
00317
00318
00319
00320
00321
00322 wxIconBundle icbApp;
00323
00324 wxIcon icoApp16;
00325 wxBitmap bmpAppIcon16(appicon16_xpm);
00326 icoApp16.CopyFromBitmap(bmpAppIcon16);
00327 icbApp.AddIcon(icoApp16);
00328
00329 wxIcon icoApp32;
00330 wxBitmap bmpAppIcon32(appicon32_xpm);
00331 icoApp32.CopyFromBitmap(bmpAppIcon32);
00332 icbApp.AddIcon(icoApp32);
00333
00334 wxIcon icoApp64;
00335 wxBitmap bmpAppIcon64(appicon64_xpm);
00336 icoApp64.CopyFromBitmap(bmpAppIcon64);
00337 icbApp.AddIcon(icoApp64);
00338
00339 SetIcons(icbApp);
00340
00341
00342
00343
00344
00345 m_ptGPS.Set(0, 0);
00346 m_fGPSHeading = 0;
00347 m_fGPSSpeed = 0;
00348 m_bOnGPSInProgress = false;
00349 m_bNewGPSData = false;
00350 m_bGPSJustRun = false;
00351 m_iRoadTypeZoomingCountdown = -1;
00352 m_eRoadTypeZoomingCurrentType = RecordTypeDefault;
00353 m_eRoadTypeZoomingNextType = RecordTypeDefault;
00354
00355 m_bScreenTracksGPS = pConfig->Read(wxT("TrackGPSMarker"), true);
00356
00357 m_iSpeedControlledDetailLevelOffset = 0;
00358
00359 m_ToolMode = toolNone;
00360
00361 m_pcTTS = ConstructTTS(TTSTypeNone);
00362
00363 m_pdData = NULL;
00364
00365 InitializeThemes();
00366
00367
00368
00369
00370
00371 m_pfrmWhatsNearBy = new WhatsNearByFrame(this, idWhatsNearBy, new MapData_Tiles());
00372
00373
00374
00375
00376 m_ctlMap = new MapControl(&m_cRecords, &m_MapAppearanceSettings, this, idMapControl, wxDefaultPosition, wxDefaultSize);
00377 m_ctlMap->Hide();
00378
00379
00380
00381
00382 m_ctlMap->PushEventHandler(new MapEventExtender(this, m_ctlMap));
00383
00384
00385
00386
00387
00388 AddNamedControl(m_ctlMap, wxT("map"));
00389
00390 m_pctlCompass = NULL;
00391
00392
00393
00394
00395
00396 wxMenu * menuFile = new wxMenu;
00397 #ifdef USE_SCRIPTING
00398 menuFile->Append(idFileRunScript, wxT("Run S&cript..."));
00399 #endif
00400 menuFile->Append(idFileSaveAs, wxT("Save &as...\tCtrl-s"));
00401 menuFile->Append(idFilePrint, wxT("&Print...\tCtrl-p"));
00402 menuFile->Append(idFilePrintPreview, wxT("P&rint Preview..."));
00403 menuFile->AppendSeparator();
00404 menuFile->Append(wxID_EXIT, wxT("E&xit"));
00405
00406
00407
00408
00409 m_menuView = new wxMenu;
00410
00411 m_menuView->AppendCheckItem(idViewCompass, wxT("&Compass"));
00412 m_menuView->Check(idViewCompass, TRUE);
00413
00414 m_menuView->AppendCheckItem(idViewAerialPhotos, wxT("Aerial &Photos"));
00415 m_menuView->Check(idViewAerialPhotos, pConfig->Read(wxT("AerialPhotosVisible"), (long int) 0));
00416
00417 m_menuView->AppendCheckItem(idView3DMode, wxT("&3D Mode"));
00418 m_menuView->Check(idView3DMode, pConfig->Read(wxT("3DMode"), (long int) 0));
00419
00420 m_menuView->AppendCheckItem(idViewScale, wxT("&Scale"));
00421 m_menuView->Check(idViewScale, TRUE);
00422
00423 m_menuView->AppendCheckItem(idViewGPSHistory, wxT("GPS &History"));
00424 m_menuView->Check(idViewGPSHistory, pConfig->Read(wxT("GPSHistory"), (long int) 1));
00425
00426 m_menuView->AppendCheckItem(idViewGPSMarker, wxT("Map Tracks &GPS"));
00427 m_menuView->Check(idViewGPSMarker, m_bScreenTracksGPS);
00428
00429 m_menuView->AppendCheckItem(idViewGPSWindow, wxT("G&PS Window"));
00430 m_menuView->Check(idViewGPSWindow, pConfig->Read(wxT("GPSWindowVisible"), (long int) 0));
00431
00432 m_menuView->AppendCheckItem(idViewWhatsNearByWindow, wxT("What's Nearby Window"));
00433 m_menuView->Check(idViewWhatsNearByWindow, pConfig->Read(wxT("WhatsNearByWindowVisible"), (long int) 0));
00434
00435 m_menuView->AppendSeparator();
00436
00437 m_menuView->Append(idViewZoomIn, wxT("Zoom &In\t+"));
00438 m_menuView->Append(idViewZoomOut, wxT("Zoom &Out\t-"));
00439
00440 m_menuView->Append(idViewZoomMax, wxT("Zoom Max"));
00441 m_menuView->Append(idViewZoomMin, wxT("Zoom Min"));
00442
00443 #if defined(__DARWIN__)
00444 m_menuView->AppendCheckItem(idViewFullScreen, wxT("&Full Screen\tCtrl-Shift-F"));
00445 #else
00446 m_menuView->AppendCheckItem(idViewFullScreen, wxT("&Full Screen\tF11"));
00447 #endif
00448 m_menuView->Check(idViewFullScreen, FALSE);
00449
00450
00451
00452
00453 m_menuMap = new wxMenu;
00454 m_menuMap->Append(idMapSetAddress, wxT("Set &Address...\tCtrl-A"));
00455 m_menuMap->Append(idMapWaypoints, wxT("&Waypoints..."));
00456 m_menuMap->Append(idMapSetAngle, wxT("Set Map Orientation..."));
00457 m_menuMap->AppendCheckItem(idMapGetDirections, wxT("Get &Directions...\tCtrl-D"));
00458 m_menuMap->Check(idMapGetDirections, (long int) 0);
00459
00460
00461
00462
00463 wxMenu * menuTools = new wxMenu;
00464
00465 menuTools->AppendCheckItem(idToolsMeasure, wxT("Measure"));
00466 menuTools->AppendCheckItem(idToolsZoom, wxT("Zoom"));
00467
00468 menuTools->AppendSeparator();
00469
00470 menuTools->Append(idToolsDownloadMaps, wxT("Download TIGER/Line &Maps (US)..."));
00471 #ifdef USE_OPENSTREETMAP
00472 menuTools->Append(idToolsDownloadOSMMaps, wxT("Download &OpenStreetMap Maps (non-US)..."));
00473 menuTools->Append(idToolsImportOSMMaps, wxT("Import O&penStreetMap XML Maps (non-US)..."));
00474 #endif
00475 menuTools->Append(idToolsImportGPXData, wxT("Import &GPX Data..."));
00476 menuTools->Append(wxID_PREFERENCES, wxT("&Preferences..."));
00477
00478
00479
00480
00481 wxMenu * menuHelp = new wxMenu;
00482 menuHelp->Append(wxID_ABOUT, wxT("&About..."));
00483
00484
00485
00486
00487 wxMenuBar * mbMenu = new wxMenuBar(wxMB_DOCKABLE);
00488 mbMenu->Append(menuFile, wxT("&File"));
00489 mbMenu->Append(m_menuView, wxT("&View"));
00490 mbMenu->Append(m_menuMap, wxT("&Map"));
00491 mbMenu->Append(menuTools, wxT("&Tools"));
00492 mbMenu->Append(menuHelp, wxT("&Help"));
00493
00494 SetMenuBar(mbMenu);
00495
00496
00497
00498
00499
00500 wxAcceleratorEntry entries[15];
00501 entries[0].Set(wxACCEL_NORMAL, (int) wxT('+'), idViewZoomIn);
00502 entries[1].Set(wxACCEL_NORMAL, (int) wxT('='), idViewZoomIn);
00503 entries[2].Set(wxACCEL_SHIFT, (int) wxT('='), idViewZoomIn);
00504 entries[3].Set(wxACCEL_NORMAL, (int) wxT('-'), idViewZoomOut);
00505 entries[4].Set(wxACCEL_NORMAL, WXK_UP, idMapMoveCenterUp);
00506 entries[5].Set(wxACCEL_NORMAL, WXK_DOWN, idMapMoveCenterDown);
00507 entries[6].Set(wxACCEL_NORMAL, WXK_LEFT, idMapMoveCenterLeft);
00508 entries[7].Set(wxACCEL_NORMAL, WXK_RIGHT, idMapMoveCenterRight);
00509 #if defined(__DARWIN__)
00510 entries[8].Set(wxACCEL_CTRL | wxACCEL_SHIFT, (int) wxT('F'), idViewFullScreen);
00511 #else
00512 entries[8].Set(wxACCEL_NORMAL, WXK_F11, idViewFullScreen);
00513 #endif
00514 entries[9].Set(wxACCEL_CTRL, (int) wxT('A'), idMapSetAddress);
00515 entries[10].Set(wxACCEL_CTRL, (int) wxT('D'), idMapGetDirectionsAccel);
00516 entries[11].Set(wxACCEL_CTRL, (int) wxT('S'), idFileSaveAs);
00517 entries[12].Set(wxACCEL_CTRL, (int) wxT('P'), idFilePrint);
00518 entries[13].Set(wxACCEL_CTRL, (int) wxT('T'), idSolarTimerTest);
00519 entries[14].Set(wxACCEL_NORMAL, WXK_ESCAPE, idEscape);
00520
00521 wxAcceleratorTable accel(sizeof(entries)/sizeof(wxAcceleratorEntry), entries);
00522 SetAcceleratorTable(accel);
00523
00524
00525
00526
00527 CreateStatusBar(3);
00528
00529
00530
00531
00532 m_pfrmGPS = new GPSFrame(this);
00533
00534
00535
00536
00537
00538 m_pfrmDirections = new DirectionsFrame(this);
00539
00540
00541
00542
00543
00544 int iMarkerCount;
00545 int iMarker;
00546
00547 m_ctlMap->ClearMarkers();
00548 pConfig->Read(wxT("MarkerCount"), &iMarkerCount, 0);
00549 for (iMarker = 0; iMarker < iMarkerCount; iMarker++)
00550 {
00551 wxString strMarker;
00552 MapMarker cMarker;
00553
00554 pConfig->Read(wxString::Format(wxT("Marker%d"), iMarker), &strMarker, wxT(""));
00555
00556 cMarker.FromString(strMarker);
00557
00558 m_ctlMap->SetMarker(cMarker);
00559 }
00560
00561 m_ctlMap->ClearMarker(wxT("GPS Position"));
00562 m_ctlMap->ClearMarker(wxT("Starting Address"));
00563 m_ctlMap->ClearMarker(wxT("Ending Address"));
00564
00565 double fCenterLong;
00566 double fCenterLat;
00567 pConfig->Read(wxT("CenterLong"), &fCenterLong, -82);
00568 pConfig->Read(wxT("CenterLat"), &fCenterLat, 40);
00569 m_ctlMap->SetCenterCoordinates(Point(fCenterLong, fCenterLat));
00570
00571 double fMapAngle;
00572 pConfig->Read(wxT("MapAngle"), &fMapAngle, 0);
00573 m_ctlMap->SetAngle(fMapAngle);
00574
00575 int iDetailLevel;
00576 pConfig->Read(wxT("DetailLevel"), &iDetailLevel, 1);
00577 m_ctlMap->SetDetailLevel(iDetailLevel);
00578
00579 for (iDetailLevel = 0; iDetailLevel <= LAST_RECORD_TYPE; iDetailLevel++)
00580 m_ariRoadTypeZoomingDetailLevels[iDetailLevel] = pConfig->Read(wxString::Format(wxT("RoadTypeZoomingDetailLevels%d"), iDetailLevel), -1);
00581
00582
00583
00584
00585
00586 RestoreWindowPosition(this, wxT("Window"));
00587
00588
00589
00590
00591
00592 RestoreWindowPosition(m_pfrmGPS, wxT("GPSWindow"));
00593
00594
00595
00596
00597
00598 RestoreWindowPosition(m_pfrmDirections, wxT("DirectionsWindow"));
00599
00600
00601
00602
00603
00604 RestoreWindowPosition(m_pfrmWhatsNearBy, wxT("WhatsNearByWindow"));
00605
00606
00607
00608
00609
00610 int iIsMaximized;
00611 pConfig->Read(wxT("IsMaximized"), &iIsMaximized, 1);
00612 if (iIsMaximized)
00613 Maximize();
00614
00615
00616
00617
00618
00619 if (m_menuView->IsChecked(idViewGPSWindow))
00620 m_pfrmGPS->Show();
00621 else
00622 m_pfrmGPS->Hide();
00623
00624 if (m_menuView->IsChecked(idViewWhatsNearByWindow))
00625 m_pfrmWhatsNearBy->Show();
00626 else
00627 m_pfrmWhatsNearBy->Hide();
00628
00629 m_ctlMap->ShowCompass(m_menuView->IsChecked(idViewCompass));
00630 m_ctlMap->ShowScale(m_menuView->IsChecked(idViewScale));
00631 m_ctlMap->ShowAerialPhotos(m_menuView->IsChecked(idViewAerialPhotos), pConfig->Read(wxT("AutoDownloadMaps"), (int) 1));
00632 m_ctlMap->Enable3DMode(m_menuView->IsChecked(idView3DMode));
00633
00634
00635
00636
00637 #ifdef USE_SCRIPTING
00638 m_pScripting = new Scripting(this, m_ctlMap);
00639
00640 if (pConfig->Read(wxT("ScriptingStartupScriptEnabled"), (long) 0))
00641 {
00642
00643 m_pScripting->RunFromFile(pConfig->Read(wxT("ScriptingStartupScriptFilename"), wxT("")));
00644
00645
00646 if (pConfig->Read(wxT("ScriptingStartupScriptErase"), (long) 0))
00647 wxRemoveFile(pConfig->Read(wxT("ScriptingStartupScriptFilename"), wxT("")));
00648 }
00649
00650 m_ptmrScripting = new wxTimer(this, TIMER_SCRIPTING);
00651 m_ptmrScripting->Start(500, false);
00652 #endif
00653
00654
00655
00656
00657 m_ThemeManager.Load(wxConfigBase::Get());
00658
00659
00660
00661
00662
00663 m_GPSMonitorThread = new GPSMonitorThread(this);
00664 m_GPSMonitorThread->Create();
00665
00666 m_DownloadThread = new DownloadThread(this, idRefreshMapControl);
00667 m_DownloadThread->Create();
00668 m_DownloadThread->Run();
00669
00670 m_ptmrInit = new wxTimer(this, TIMER_INIT);
00671 m_ptmrInit->Start(1, true);
00672
00673 m_ptmrConfigFlush = new wxTimer(this, TIMER_CONFIGFLUSH);
00674 m_ptmrConfigFlush->Start(60 * 1000, false);
00675
00676 m_bShowPopupGPSErrors = false;
00677 }
00678
00679
00680
00681
00682
00683
00684 void MapFrame::OnTimerConfigFlush(wxTimerEvent& event)
00685 {
00686 if (wxConfigBase::Get()->Read(wxT("MarkerCount"), (long) 0) != m_ctlMap->GetMarkerCount())
00687 SaveMarkers();
00688
00689 wxConfigBase::Get()->Flush();
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 void MapFrame::OnTimerInit(wxTimerEvent& event)
00703 {
00704 wxCommandEvent ev;
00705
00706 if (MapInit())
00707 {
00708 Close(TRUE);
00709 return;
00710 }
00711
00712 ApplyPreferences();
00713
00714 LCDprocInit();
00715
00716 OnMapRecentered(ev);
00717
00718 m_GPSMonitorThread->Run();
00719 }
00720
00721 #ifdef USE_SCRIPTING
00722
00723
00724
00725
00726
00727 void MapFrame::OnTimerScripting(wxTimerEvent& event)
00728 {
00729 m_pScripting->Pump();
00730 }
00731 #endif
00732
00733
00734
00735
00736
00737
00738 MapFrame::~MapFrame()
00739 {
00740 m_ThemeManager.Save(wxConfigBase::Get());
00741 delete m_ptmrInit;
00742 delete m_ptmrConfigFlush;
00743 if (m_pdData != NULL)
00744 delete m_pdData;
00745 }
00746
00747
00748
00749
00750
00751
00752 EToolMode MapFrame::GetToolMode() const
00753 {
00754 return m_ToolMode;
00755 }
00756
00757
00758
00759
00760
00761
00762 void MapFrame::SetToolMode(EToolMode mode)
00763 {
00764 m_ToolMode = mode;
00765 }
00766
00767
00768
00769
00770
00771
00772 IMapData& MapFrame::GetMapData()
00773 {
00774 return m_cRecords;
00775 }
00776
00777
00778
00779
00780
00781
00782 MapAppearanceSettings& MapFrame::GetMapAppearanceSettings()
00783 {
00784 return m_MapAppearanceSettings;
00785 }
00786
00787
00788
00789
00790
00791
00792 void MapFrame::OnIdle(wxIdleEvent & event)
00793 {
00794 if (!IsShown())
00795 return;
00796
00797 wxString strOldText;
00798 wxString strNewText;
00799
00800 strOldText = GetStatusBar()->GetStatusText(2);
00801
00802 strNewText = wxString::Format(wxT("Detail Level: %d"), m_ctlMap->GetDetailLevel());
00803
00804 if (strOldText != strNewText)
00805 SetStatusText(strNewText, 2);
00806
00807
00808 {
00809 bool bNewGPSData = false;
00810 wxGPSEvent evGPS;
00811
00812 if (m_bGPSJustRun)
00813 {
00814 m_mtxGPS.Lock();
00815 m_bNewGPSData = false;
00816 m_bGPSJustRun = false;
00817 m_mtxGPS.Unlock();
00818 }
00819
00820 m_mtxGPS.Lock();
00821 bNewGPSData = m_bNewGPSData;
00822 evGPS = m_evGPS;
00823 m_mtxGPS.Unlock();
00824
00825 if (bNewGPSData)
00826 {
00827 OnGPSUpdateIdle(evGPS);
00828
00829 m_mtxGPS.Lock();
00830 m_bNewGPSData = false;
00831 m_bGPSJustRun = true;
00832 m_mtxGPS.Unlock();
00833
00834 event.RequestMore();
00835 }
00836 }
00837 }
00838
00839
00840
00841
00842
00843
00844 void MapFrame::OnSolarEvent(SolarEvent& event)
00845 {
00846 UpdateTheme();
00847 m_ctlMap->MapUpdated(UPDATED_THEME);
00848 }
00849
00850
00851
00852
00853
00854
00855 void MapFrame::UpdateTheme()
00856 {
00857 bool bViewPhotos;
00858 wxConfigBase * pConfig = wxConfigBase::Get();
00859
00860 pConfig->Read(wxT("AerialPhotosVisible"), &bViewPhotos, false);
00861
00862 if ( bViewPhotos )
00863 {
00864 m_MapAppearanceSettings = m_ThemeManager.GetPhotoTheme();
00865 }
00866 else
00867 {
00868 switch( m_ThemeManager.GetThemeUsage() )
00869 {
00870 case ThemeManager::AutoSwap:
00871 m_SolarTimer.Start();
00872 if ( m_SolarTimer.IsDaytime() || !m_SolarTimer.Valid())
00873 m_MapAppearanceSettings = m_ThemeManager.GetDayTheme();
00874 else
00875 m_MapAppearanceSettings = m_ThemeManager.GetNightTheme();
00876 break;
00877
00878 case ThemeManager::Night:
00879 m_SolarTimer.Stop();
00880 m_MapAppearanceSettings = m_ThemeManager.GetNightTheme();
00881 break;
00882
00883 case ThemeManager::Day:
00884 m_SolarTimer.Stop();
00885 m_MapAppearanceSettings = m_ThemeManager.GetDayTheme();
00886 break;
00887 }
00888 }
00889
00890
00891
00892
00893 wxString strSkinPath;
00894
00895 if (m_SolarTimer.IsDaytime())
00896 pConfig->Read(wxT("SkinPath-Day"), &strSkinPath, wxT("Default-Day"));
00897 else
00898 pConfig->Read(wxT("SkinPath-Night"), &strSkinPath, wxT("Default-Night"));
00899
00900 bool bSkinLoaded = false;
00901
00902 if (strSkinPath != wxT(""))
00903 bSkinLoaded = !LoadSkin(strSkinPath, true);
00904
00905 if (!bSkinLoaded)
00906 {
00907 LoadSkin(
00908 wxT("<?xml version=\"1.0\">\
00909 <roadnavskin>\
00910 <layout>\
00911 <control name=\"map\">\
00912 <region>\
00913 <topleft>\
00914 <x/>\
00915 <y/>\
00916 </topleft>\
00917 <bottomright>\
00918 <x multiplier=\"1\"/>\
00919 <y multiplier=\"1\"/>\
00920 </bottomright>\
00921 </region>\
00922 </control>\
00923 </layout>\
00924 </roadnavskin>"),
00925 false);
00926 }
00927
00928 m_pfrmGPS->SetFont(GetFont());
00929 m_pfrmGPS->SetBackgroundStyle(wxBG_STYLE_COLOUR);
00930 m_pfrmGPS->SetBackgroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorBackground));
00931 m_pfrmGPS->SetForegroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorForeground));
00932 m_pfrmGPS->SafeRefresh();
00933
00934 m_pfrmWhatsNearBy->SetFont(GetFont());
00935 m_pfrmWhatsNearBy->SetBackgroundStyle(wxBG_STYLE_COLOUR);
00936 m_pfrmWhatsNearBy->SetBackgroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorBackground));
00937 m_pfrmWhatsNearBy->SetForegroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorForeground));
00938
00939 m_pfrmDirections->SetFont(GetFont());
00940 m_pfrmDirections->SetBackgroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorBackground));
00941 m_pfrmDirections->SetForegroundColour(m_MapAppearanceSettings.GetMiscColor(MiscColorForeground));
00942
00943 UpdateSkinState();
00944 }
00945
00946 #if defined _WINDOWS
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 long MapFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
00957 {
00958 long result = wxFrame::MSWWindowProc(nMsg,wParam,lParam);
00959 if ( nMsg == WM_TIMECHANGE )
00960 {
00961
00962 wxTimeChangeEvent event;
00963 m_SolarTimer.AddPendingEvent(event);
00964 }
00965 return result;
00966 }
00967
00968 #endif
00969
00970
00971
00972
00973
00974
00975
00976 void MapFrame::OnGPSUpdate(const wxGPSEvent & evGPS)
00977 {
00978 wxMutexLocker mlLocker(m_mtxGPS);
00979
00980 m_evGPS = evGPS;
00981 m_bNewGPSData = true;
00982 }
00983
00984
00985
00986
00987
00988
00989 void MapFrame::OnGPSUpdateIdleSpeedControlledZooming(const wxGPSEvent & evGPS)
00990 {
00991 double fSpeed = evGPS.m_fSpeed;
00992
00993
00994
00995
00996 int iDesiredSpeedControlledDetailLevelOffset;
00997 bool bSignificantOffset;
00998 double fHighestExceededCutoff;
00999 vector<double>::iterator iCutoff;
01000 double fHysteresis;
01001
01002 fHysteresis = 5;
01003 iDesiredSpeedControlledDetailLevelOffset = 0;
01004 bSignificantOffset = false;
01005 fHighestExceededCutoff = -1000;
01006
01007
01008 for (iCutoff = m_vSpeedControlledDetailLevelCutoffs.begin(); iCutoff != m_vSpeedControlledDetailLevelCutoffs.end(); iCutoff++)
01009 {
01010 if (fSpeed > *iCutoff)
01011 {
01012 iDesiredSpeedControlledDetailLevelOffset--;
01013
01014 if (*iCutoff > fHighestExceededCutoff)
01015 fHighestExceededCutoff = *iCutoff;
01016 }
01017 }
01018
01019 if (fSpeed - fHighestExceededCutoff > fHysteresis)
01020 bSignificantOffset = true;
01021
01022
01023 if ((m_iSpeedControlledDetailLevelOffset - iDesiredSpeedControlledDetailLevelOffset > 1) ||
01024 (m_iSpeedControlledDetailLevelOffset - iDesiredSpeedControlledDetailLevelOffset == 1 && bSignificantOffset))
01025 {
01026 m_iSpeedControlledDetailLevelOffset--;
01027 m_ctlMap->LessDetail();
01028 }
01029
01030
01031 if ((iDesiredSpeedControlledDetailLevelOffset - m_iSpeedControlledDetailLevelOffset >= 1))
01032 {
01033 m_iSpeedControlledDetailLevelOffset++;
01034 m_ctlMap->MoreDetail();
01035 }
01036
01037
01038
01039
01040 }
01041
01042
01043
01044
01045
01046
01047 void MapFrame::OnGPSUpdateIdleRoadTypeZooming(const wxGPSEvent & evGPS)
01048 {
01049 if (m_adrGPS.m_eRecordType == m_eRoadTypeZoomingCurrentType ||
01050 m_adrGPS.m_eRecordType < FIRST_RECORD_TYPE_ROAD ||
01051 m_adrGPS.m_eRecordType > LAST_RECORD_TYPE_ROAD)
01052 {
01053
01054
01055 m_iRoadTypeZoomingCountdown = -1;
01056 m_eRoadTypeZoomingNextType = m_adrGPS.m_eRecordType;
01057 }
01058 else if (m_adrGPS.m_eRecordType != m_eRoadTypeZoomingNextType)
01059 {
01060
01061 m_iRoadTypeZoomingCountdown = 2;
01062 m_eRoadTypeZoomingNextType = m_adrGPS.m_eRecordType;
01063 }
01064 else if (m_iRoadTypeZoomingCountdown > 0)
01065 {
01066
01067
01068 m_iRoadTypeZoomingCountdown--;
01069 }
01070 else
01071 {
01072
01073 wxASSERT(m_iRoadTypeZoomingCountdown == 0);
01074
01075
01076 m_ariRoadTypeZoomingDetailLevels[m_eRoadTypeZoomingCurrentType] = m_ctlMap->GetDetailLevel() - m_iSpeedControlledDetailLevelOffset;
01077
01078
01079 m_eRoadTypeZoomingCurrentType = m_adrGPS.m_eRecordType;
01080
01081
01082 if (m_ariRoadTypeZoomingDetailLevels[m_eRoadTypeZoomingCurrentType] >= 0)
01083 m_ctlMap->SetDetailLevel(m_ariRoadTypeZoomingDetailLevels[m_eRoadTypeZoomingCurrentType] + m_iSpeedControlledDetailLevelOffset);
01084
01085 m_iRoadTypeZoomingCountdown = -1;
01086 }
01087 }
01088
01089
01090
01091
01092
01093
01094
01095 void MapFrame::OnGPSUpdateIdleKeepGPSOnScreen(const wxGPSEvent & evGPS)
01096 {
01097 double fScreenEdge = 0.1;
01098 double fSafety = 0.05;
01099 double fScreenRelativeHeading;
01100
01101 wxPoint ptScreenGPS;
01102 wxSize szMapCtl;
01103
01104 const Point & pt = evGPS.m_pt;
01105 double fHeading = evGPS.m_fHeading;
01106
01107 wxRealPoint ptRelativeScreenGPS;
01108
01109 ptScreenGPS = m_ctlMap->MapLongLatToScreen(pt);
01110 szMapCtl = m_ctlMap->GetSize();
01111
01112 fScreenRelativeHeading = fHeading - m_ctlMap->GetAngle();
01113
01114 ptRelativeScreenGPS.x = (((double) ptScreenGPS.x) / szMapCtl.x);
01115 ptRelativeScreenGPS.y = (((double) ptScreenGPS.y) / szMapCtl.y);
01116
01117 if (!m_ctlMap->IsOnScreen(pt))
01118 {
01119
01120 m_ctlMap->SetCenterCoordinates(pt);
01121 }
01122 else if (ptRelativeScreenGPS.x < fScreenEdge)
01123 {
01124
01125 m_ctlMap->MoveCenterLeft(1.0 - ptRelativeScreenGPS.x - fScreenEdge - fSafety);
01126
01127
01128 m_ctlMap->MoveCenterUp(0.5 - ptRelativeScreenGPS.y - (0.5 - fScreenEdge - fSafety) * sin_deg(fScreenRelativeHeading - 90));
01129 }
01130 else if (ptRelativeScreenGPS.y < fScreenEdge)
01131 {
01132
01133 m_ctlMap->MoveCenterUp(1.0 - ptRelativeScreenGPS.y - fScreenEdge - fSafety);
01134
01135
01136 m_ctlMap->MoveCenterLeft(0.5 - ptRelativeScreenGPS.x - (0.5 - fScreenEdge - fSafety) * cos_deg(fScreenRelativeHeading - 90));
01137 }
01138 else if (ptRelativeScreenGPS.x > (1.0 - fScreenEdge))
01139 {
01140
01141 m_ctlMap->MoveCenterRight(ptRelativeScreenGPS.x - fScreenEdge - fSafety);
01142
01143
01144 m_ctlMap->MoveCenterUp(0.5 - ptRelativeScreenGPS.y - (0.5 - fScreenEdge - fSafety) * sin_deg(fScreenRelativeHeading - 90));
01145 }
01146 else if (ptRelativeScreenGPS.y > (1.0 - fScreenEdge))
01147 {
01148
01149 m_ctlMap->MoveCenterDown(ptRelativeScreenGPS.y - fScreenEdge - fSafety);
01150
01151
01152 m_ctlMap->MoveCenterLeft(0.5 - ptRelativeScreenGPS.x - (0.5 - fScreenEdge - fSafety) * cos_deg(fScreenRelativeHeading - 90));
01153 }
01154 }
01155
01156
01157
01158
01159
01160
01161 void MapFrame::OnGPSUpdateIdlePointGPSHeadingUp(const wxGPSEvent & evGPS)
01162 {
01163 double fDesiredAngle;
01164 double fHeading = evGPS.m_fHeading;
01165 double fAngleDifference;
01166
01167 fDesiredAngle = floor((fHeading + 22.5) / 45) * 45;
01168
01169 fAngleDifference = fabs(m_ctlMap->GetAngle() - fHeading);
01170
01171 if (fAngleDifference > 180)
01172 fAngleDifference = 360 - fAngleDifference;
01173
01174 if (fAngleDifference > 45)
01175 m_ctlMap->SetAngle(fDesiredAngle);
01176 }
01177
01178
01179
01180
01181
01182
01183 void MapFrame::OnGPSUpdateIdleUpdateGPSTrack(const wxGPSEvent & evGPS)
01184 {
01185 MapTrack * pTrack;
01186 const Point & pt = evGPS.m_pt;
01187
01188 pTrack = m_ctlMap->GetTrack(wxT("GPSHistory"));
01189
01190 if (!pTrack)
01191 {
01192 vector<Point> vptCoords;
01193
01194 vptCoords.push_back(pt);
01195
01196 MapTrack cTrack(wxT("GPSHistory"), vptCoords, wxColour(0, 255, 255), false);
01197
01198 m_ctlMap->SetTrack(cTrack);
01199
01200 pTrack = m_ctlMap->GetTrack(wxT("GPSHistory"));
01201 }
01202
01203 pTrack->m_vptCoordinates.push_back(pt);
01204
01205 m_ctlMap->SetTrack(*pTrack);
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215 void MapFrame::OnGPSUpdateIdle(const wxGPSEvent & evGPS)
01216 {
01217 LibRoadnavDebug0(wxT("GPS"), wxT("MapFrame::OnGPSUpdate"));
01218
01219 if (m_bOnGPSInProgress)
01220 {
01221 LibRoadnavDebug0(wxT("GPS"), wxT("MapFrame::OnGPSUpdate already running - exiting"));
01222 return;
01223 }
01224
01225 m_bOnGPSInProgress = true;
01226
01227 LibRoadnavDebug5(wxT("GPS"), wxT("bEnabled = %d, bActive = %d, bLocked = %d, fSpeed = %.1f, fHeading = %.1f"),
01228 evGPS.m_bEnabled,
01229 evGPS.m_bActive,
01230 evGPS.m_bLocked,
01231 evGPS.m_fSpeed,
01232 evGPS.m_fHeading);
01233
01234 if ((m_bShowPopupGPSErrors || evGPS.m_bFatalError) && !evGPS.m_strErrorMessage.IsEmpty())
01235 {
01236
01237 wxMessageBox(evGPS.m_strErrorMessage, wxT("Error"), wxOK | wxICON_ERROR, this);
01238 }
01239
01240 wxConfigBase * pConfig = wxConfigBase::Get();
01241
01242 if (evGPS.m_bLocked)
01243 {
01244 double fHeadingChange = fabs(m_fGPSHeading - evGPS.m_fHeading);
01245 bool bPositionChange;
01246 bool bAngleChange;
01247
01248
01249 bPositionChange = fabs(m_ptGPS.GetLong() - evGPS.m_pt.GetLong()) > 2e-6 || fabs(m_ptGPS.GetLat() - evGPS.m_pt.GetLat()) > 2e-6;
01250
01251 if (fHeadingChange > 180)
01252 fHeadingChange = 360 - fHeadingChange;
01253
01254 bAngleChange = fHeadingChange > 5;
01255
01256 if (bPositionChange || bAngleChange)
01257 {
01258 bool bDoRoadTypeZoomingNow = false;
01259 bool bKeepGPSCentered = pConfig->Read(wxT("KeepGPSCentered"), (long) true);
01260
01261 if (bPositionChange)
01262 {
01263 Address adrGPS;
01264
01265 if (pConfig->Read(wxT("RoadTypeZooming"), (long) false))
01266 {
01267 if (wxDateTime::Now() - m_tLastRoadTypeZoomingCheck > wxTimeSpan(0, 0, 2, 0))
01268 {
01269 bDoRoadTypeZoomingNow = true;
01270 m_tLastRoadTypeZoomingCheck = wxDateTime::Now();
01271
01272 m_cRecords.LoadRegion(evGPS.m_pt, evGPS.m_pt, OnlyRoadsVisibility(), false);
01273 }
01274 }
01275
01276 adrGPS = FindCoordinates(evGPS.m_pt, OnlyRoadsVisibility(), false, false, &m_cRecords);
01277
01278 if (adrGPS.m_bValid)
01279 m_adrGPS = adrGPS;
01280 else
01281 m_adrGPS.m_ptCoordinates = evGPS.m_pt;
01282 }
01283
01284 m_ctlMap->SetMarker( MapMarker( wxT("GPS Position"),
01285 &m_adrGPS,
01286 evGPS.m_fHeading,
01287 pConfig->Read(wxT("GPS Callout Box"), (long) false),
01288 pConfig->Read(wxT("GPS Small Label"), true),
01289 pConfig->Read(wxT("GPS Arrow"), true),
01290 pConfig->Read(wxT("GPS Icon"), wxT("")),
01291 false
01292 ),
01293 false);
01294
01295 OnGPSUpdateIdleSpeedControlledZooming(evGPS);
01296
01297 if (bDoRoadTypeZoomingNow)
01298 OnGPSUpdateIdleRoadTypeZooming(evGPS);
01299
01300 if (m_bScreenTracksGPS && !bKeepGPSCentered)
01301 OnGPSUpdateIdleKeepGPSOnScreen(evGPS);
01302
01303 if (m_menuView->IsChecked(idView3DMode))
01304 {
01305 m_ctlMap->SetCenterCoordinates(evGPS.m_pt);
01306 m_ctlMap->SetAngle(evGPS.m_fHeading);
01307 }
01308 else
01309 {
01310 if (!m_bNorthAlwaysUp)
01311 OnGPSUpdateIdlePointGPSHeadingUp(evGPS);
01312
01313 if (m_bScreenTracksGPS && bKeepGPSCentered)
01314 m_ctlMap->SetCenterCoordinates(evGPS.m_pt);
01315 }
01316
01317 if (m_menuView->IsChecked(idViewGPSHistory))
01318 OnGPSUpdateIdleUpdateGPSTrack(evGPS);
01319
01320 m_SolarTimer.SetPosition(evGPS.m_pt.GetLong(),evGPS.m_pt.GetLat());
01321
01322 m_ptGPS = evGPS.m_pt;
01323 m_fGPSSpeed = evGPS.m_fSpeed;
01324 m_fGPSHeading = evGPS.m_fHeading;
01325 }
01326 }
01327
01328 if (m_pctlCompass)
01329 m_pctlCompass->SetDirection(evGPS.m_fHeading);
01330
01331 wxString strStreet =
01332 wxString::Format(wxT("%d "), m_adrGPS.m_iStreetNumber) +
01333 m_adrGPS.m_strStreetName +
01334 wxT(" ") +
01335 m_adrGPS.m_strStreetType;
01336
01337 SetVariable(wxT("GPS Street"), strStreet);
01338 SetVariable(wxT("GPS City"), m_adrGPS.m_strCityName);
01339 SetVariable(wxT("GPS State"), m_adrGPS.m_strStateName);
01340
01341
01342 if (m_adrGPS.m_iZipCode)
01343 {
01344 int iZipHome;
01345 pConfig->Read(wxT("HomeZipCode"), &iZipHome, 0);
01346
01347 if (!iZipHome)
01348 {
01349 pConfig->Write(wxT("HomeZipCode"), m_adrGPS.m_iZipCode);
01350 wxConfigBase::Get()->Flush();
01351 }
01352 }
01353
01354 if (!evGPS.m_strErrorMessage.IsEmpty())
01355 SetVariable(wxT("GPS Full Address"), evGPS.m_strErrorMessage);
01356 else if (!evGPS.m_bEnabled)
01357 SetVariable(wxT("GPS Full Address"), wxT("GPS disabled"));
01358 else if (!evGPS.m_bActive)
01359 SetVariable(wxT("GPS Full Address"), wxT("No GPS unit detected"));
01360 else if (!evGPS.m_bLocked)
01361 SetVariable(wxT("GPS Full Address"), wxT("No GPS lock"));
01362 else
01363 SetVariable(wxT("GPS Full Address"), m_adrGPS.FormatAddress(false));
01364
01365 SetVariable(wxT("GPS Speed"), FormatSpeed(evGPS.m_fSpeed));
01366
01367 if (evGPS.m_fHeading >= 0)
01368 SetVariable(wxT("GPS Heading"), wxString::Format(wxT("%.0f ("), evGPS.m_fHeading) + FormatHeading(evGPS.m_fHeading) + wxT(")"));
01369 else
01370 SetVariable(wxT("GPS Heading"), wxT("?"));
01371
01372 LibRoadnavDebug0(wxT("GPS"), wxT("Calling m_pfrmGPS->OnGPSUpdate"));
01373 m_pfrmGPS->OnGPSUpdate(evGPS);
01374
01375 LibRoadnavDebug0(wxT("GPS"), wxT("Calling m_pfrmDirections->OnGPSUpdate"));
01376 m_pfrmDirections->OnGPSUpdate(evGPS, m_adrGPS);
01377
01378 m_bOnGPSInProgress = false;
01379
01380 LibRoadnavDebug0(wxT("GPS"), wxT("MapFrame::OnGPSUpdate done"));
01381 }
01382
01383
01384
01385
01386
01387
01388 void MapFrame::SaveMarkers()
01389 {
01390 int iMarker;
01391 wxConfigBase * pConfig = wxConfigBase::Get();
01392
01393 for (iMarker = 0; iMarker < m_ctlMap->GetMarkerCount(); iMarker++)
01394 {
01395 wxString strMarker = m_ctlMap->GetMarker(iMarker).ToString();
01396
01397 pConfig->Write(wxString::Format(wxT("Marker%d"), iMarker), strMarker);
01398 }
01399 pConfig->Write(wxT("MarkerCount"), m_ctlMap->GetMarkerCount());
01400 pConfig->Flush();
01401 }
01402
01403
01404
01405
01406
01407
01408
01409 void MapFrame::OnClose(wxCloseEvent& event)
01410 {
01411 wxRect rectWindow;
01412 int iDetailLevel;
01413 wxConfigBase * pConfig = wxConfigBase::Get();
01414
01415 if (!pConfig->Read(wxT("CacheDownloads"), (long) 1))
01416 ClearDownloadCache();
01417
01418 #ifdef USE_SCRIPTING
01419 delete m_ptmrScripting;
01420 #endif
01421
01422 m_pfrmGPS->Hide();
01423 m_pfrmDirections->Hide();
01424 m_pfrmWhatsNearBy->Hide();
01425
01426 m_pfrmGPS->Destroy();
01427 m_pfrmDirections->Destroy();
01428 m_pfrmWhatsNearBy->Destroy();
01429
01430 Hide();
01431
01432 m_GPSMonitorThread->Delete();
01433 delete m_GPSMonitorThread;
01434
01435 m_DownloadThread->ReleaseAndExit();
01436 delete m_DownloadThread;
01437
01438 #ifdef USE_SCRIPTING
01439 delete m_pScripting;
01440 #endif
01441
01442 LCDprocCleanup();
01443
01444 SaveMarkers();
01445
01446 Point ptCenter = m_ctlMap->GetCenterCoordinates();
01447 pConfig->Write(wxT("CenterLong"), ptCenter.GetLong());
01448 pConfig->Write(wxT("CenterLat"), ptCenter.GetLat());
01449
01450 pConfig->Write(wxT("MapAngle"), m_ctlMap->GetAngle());
01451
01452 pConfig->Write(wxT("DetailLevel"), m_ctlMap->GetDetailLevel() - m_iSpeedControlledDetailLevelOffset);
01453
01454 m_ariRoadTypeZoomingDetailLevels[m_eRoadTypeZoomingCurrentType] = m_ctlMap->GetDetailLevel() - m_iSpeedControlledDetailLevelOffset;
01455 for (iDetailLevel = 0; iDetailLevel <= LAST_RECORD_TYPE; iDetailLevel++)
01456 pConfig->Write(wxString::Format(wxT("RoadTypeZoomingDetailLevels%d"), iDetailLevel), m_ariRoadTypeZoomingDetailLevels[iDetailLevel]);
01457
01458 pConfig->Write(wxT("TrackGPSMarker"), m_bScreenTracksGPS);
01459
01460 pConfig->Write(wxT("IsMaximized"), IsMaximized());
01461
01462 SaveWindowPosition(this, wxT("Window"));
01463 SaveWindowPosition(m_pfrmGPS, wxT("GPSWindow"));
01464 SaveWindowPosition(m_pfrmDirections, wxT("DirectionsWindow"));
01465 SaveWindowPosition(m_pfrmWhatsNearBy, wxT("WhatsNearByWindow"));
01466
01467 delete m_pcTTS;
01468
01469 m_ctlMap->PopEventHandler(true);
01470
01471 g_pcStringTable->Save();
01472
01473 MapCleanup();
01474
01475 if (pConfig->Read(wxT("EnableExitCommand"), (long) 0))
01476 wxExecute(pConfig->Read(wxT("ExitCommand"), GetDefaultShutdownCommand()));
01477
01478 Destroy();
01479 }
01480
01481
01482
01483
01484
01485
01486 #ifdef USE_SCRIPTING
01487 void MapFrame::OnFileRunScript(wxCommandEvent & event)
01488 {
01489 wxFileDialog dlg(this,
01490 wxT("Run Script..."),
01491 wxT(""),
01492 wxT(""),
01493 wxT("*.rnv"),
01494 #if wxCHECK_VERSION(2, 8, 0)
01495 wxFD_OPEN | wxFD_FILE_MUST_EXIST
01496 #else
01497 wxOPEN | wxFILE_MUST_EXIST
01498 #endif
01499 );
01500
01501 if (dlg.ShowModal() == wxID_OK)
01502 {
01503 if (m_pScripting->RunFromFile(dlg.GetPath()))
01504 {
01505 wxMessageBox(wxT("Error running script"), wxT("Error"), wxOK | wxICON_ERROR, this);
01506 }
01507 else
01508 {
01509 wxMessageBox(wxT("Script run successfully"), wxT("Information"), wxOK | wxICON_INFORMATION, this);
01510 }
01511 }
01512 }
01513 #endif
01514
01515
01516
01517
01518
01519
01520 void MapFrame::OnFileSaveAs(wxCommandEvent & event)
01521 {
01522 wxFileDialog dlg(this,
01523 wxT("Save As..."),
01524 wxT(""),
01525 wxT(""),
01526 wxT("*.png"),
01527 #if wxCHECK_VERSION(2, 8, 0)
01528 wxFD_SAVE | wxFD_OVERWRITE_PROMPT
01529 #else
01530 wxSAVE | wxOVERWRITE_PROMPT
01531 #endif
01532 );
01533 SaveAsSettingsDialog dlgSettings(this);
01534
01535 if (dlgSettings.ShowModal() == wxID_OK)
01536 {
01537 if (dlg.ShowModal() == wxID_OK)
01538 {
01539 wxMemoryDC dc;
01540 wxBitmap bmpOut(dlgSettings.m_iWidth, dlgSettings.m_iHeight);
01541
01542 dc.SelectObject(bmpOut);
01543 m_ctlMap->DrawAll(&dc, wxSize(dlgSettings.m_iWidth, dlgSettings.m_iHeight));
01544
01545 bmpOut.SaveFile(dlg.GetPath(), wxBITMAP_TYPE_PNG);
01546 }
01547 }
01548 }
01549
01550
01551
01552
01553
01554
01555 void MapFrame::OnFilePrint(wxCommandEvent & event)
01556 {
01557 wxString strTitle;
01558 Address sAddr;
01559
01560 sAddr = FindCoordinates(m_ctlMap->GetCenterCoordinates(), OnlyRoadsVisibility());
01561
01562 if (sAddr.m_bValid)
01563 {
01564 strTitle = sAddr.FormatAddress(false, false, true);
01565 }
01566 else
01567 {
01568 strTitle = m_ctlMap->GetCenterCoordinates().FormatPoint();
01569 }
01570
01571
01572 if (m_pdData == NULL)
01573 m_pdData = new wxPrintData();
01574
01575 wxPrintDialogData printDialogData(*m_pdData);
01576 wxPrinter printer(&printDialogData);
01577
01578 Printout printout(strTitle, m_ctlMap);
01579 if (!printer.Print(this, &printout, TRUE))
01580 {
01581 if (wxPrinter::GetLastError() == wxPRINTER_ERROR)
01582 wxMessageBox(wxT("There was a problem printing.\nPerhaps your current printer is not set correctly?"), wxT("Printing"), wxOK, this);
01583 else
01584 {
01585
01586 }
01587 }
01588 else
01589 {
01590 *m_pdData = printer.GetPrintDialogData().GetPrintData();
01591 }
01592 }
01593
01594
01595
01596
01597
01598
01599 void MapFrame::OnFilePrintPreview(wxCommandEvent & event)
01600 {
01601 wxString strTitle;
01602 Address sAddr;
01603
01604 sAddr = FindCoordinates(m_ctlMap->GetCenterCoordinates(), OnlyRoadsVisibility());
01605
01606 if (sAddr.m_bValid)
01607 {
01608 strTitle = sAddr.FormatAddress(false, false, true);
01609 }
01610 else
01611 {
01612 strTitle = m_ctlMap->GetCenterCoordinates().FormatPoint();
01613 }
01614
01615
01616 if (m_pdData == NULL)
01617 m_pdData = new wxPrintData();
01618
01619 wxPrintDialogData printDialogData(*m_pdData);
01620 wxPrintPreview * preview = new wxPrintPreview( new Printout(strTitle, m_ctlMap),
01621 new Printout(strTitle, m_ctlMap),
01622 &printDialogData);
01623 if (!preview->Ok())
01624 {
01625 delete preview;
01626 wxMessageBox(wxT("There was a problem previewing.\nPerhaps your current printer is not set correctly?"), _T("Previewing"), wxOK, this);
01627 return;
01628 }
01629
01630 wxPreviewFrame *pfrmPreview = new wxPreviewFrame(preview, this, wxT("Print Preview"), wxPoint(100, 100), wxSize(600, 650));
01631 pfrmPreview->Centre(wxBOTH);
01632 pfrmPreview->Initialize();
01633 pfrmPreview->Show(TRUE);
01634 }
01635
01636
01637
01638
01639
01640
01641 void MapFrame::OnFileExit(wxCommandEvent & event)
01642 {
01643 Close(TRUE);
01644 }
01645
01646
01647
01648
01649
01650
01651 void MapFrame::OnViewCompass(wxCommandEvent & event)
01652 {
01653 m_ctlMap->ShowCompass(m_menuView->IsChecked(idViewCompass));
01654 }
01655
01656
01657
01658
01659
01660
01661 void MapFrame::OnViewAerialPhotos(wxCommandEvent & event)
01662 {
01663 wxConfigBase * pConfig = wxConfigBase::Get();
01664
01665 pConfig->Write(wxT("AerialPhotosVisible"), m_menuView->IsChecked(idViewAerialPhotos));
01666 pConfig->Flush();
01667
01668 UpdateTheme();
01669 m_ctlMap->ShowAerialPhotos(m_menuView->IsChecked(idViewAerialPhotos), pConfig->Read(wxT("AutoDownloadMaps"), (int) 1));
01670
01671 if (m_menuView->IsChecked(idViewAerialPhotos) && m_menuView->IsChecked(idView3DMode))
01672 {
01673 wxCommandEvent ev;
01674
01675 m_menuView->Check(idView3DMode, false);
01676 OnView3DMode(ev);
01677 }
01678 }
01679
01680
01681
01682
01683
01684
01685 void MapFrame::OnView3DMode(wxCommandEvent & event)
01686 {
01687 wxConfigBase * pConfig = wxConfigBase::Get();
01688
01689 pConfig->Write(wxT("3DMode"), m_menuView->IsChecked(idView3DMode));
01690 pConfig->Flush();
01691
01692 m_ctlMap->Enable3DMode(m_menuView->IsChecked(idView3DMode));
01693
01694 if (m_menuView->IsChecked(idViewAerialPhotos) && m_menuView->IsChecked(idView3DMode))
01695 {
01696 wxCommandEvent ev;
01697
01698 m_menuView->Check(idViewAerialPhotos, false);
01699 OnViewAerialPhotos(ev);
01700 }
01701 }
01702
01703
01704
01705
01706
01707
01708 void MapFrame::OnViewScale(wxCommandEvent & event)
01709 {
01710 m_ctlMap->ShowScale(m_menuView->IsChecked(idViewScale));
01711 }
01712
01713
01714
01715
01716
01717
01718 void MapFrame::OnViewGPSHistory(wxCommandEvent & event)
01719 {
01720 wxConfigBase * pConfig = wxConfigBase::Get();
01721
01722 if (!m_menuView->IsChecked(idViewGPSHistory))
01723 m_ctlMap->ClearTrack(wxT("GPSHistory"));
01724
01725 pConfig->Write(wxT("GPSHistory"), m_menuView->IsChecked(idViewGPSHistory));
01726 pConfig->Flush();
01727 }
01728
01729
01730
01731
01732
01733
01734 void MapFrame::OnViewZoomLevel(wxCommandEvent& event)
01735 {
01736 m_ctlMap->SetDetailLevel(event.GetId() - idViewZoom0);
01737 }
01738
01739
01740
01741
01742
01743
01744 void MapFrame::OnViewZoomIn(wxCommandEvent& event)
01745 {
01746 m_ctlMap->MoreDetail();
01747 }
01748
01749
01750
01751
01752
01753
01754 void MapFrame::OnViewZoomOut(wxCommandEvent& event)
01755 {
01756 m_ctlMap->LessDetail();
01757 }
01758
01759
01760
01761
01762
01763
01764 void MapFrame::OnViewZoomMax(wxCommandEvent& event)
01765 {
01766 m_ctlMap->SetDetailLevel(m_MapAppearanceSettings.GetDetailLevelCount());
01767 }
01768
01769
01770
01771
01772
01773
01774 void MapFrame::OnViewZoomMin(wxCommandEvent& event)
01775 {
01776 m_ctlMap->SetDetailLevel(0);
01777 }
01778
01779
01780
01781
01782
01783
01784 void MapFrame::OnViewGPSMarker(wxCommandEvent& event)
01785 {
01786 m_bScreenTracksGPS = m_menuView->IsChecked(idViewGPSMarker);
01787 SetActive(wxT("MapTracksGPS"), m_bScreenTracksGPS);
01788 }
01789
01790
01791
01792
01793
01794
01795 void MapFrame::OnViewGPSMarkerToggle(wxCommandEvent& event)
01796 {
01797 m_bScreenTracksGPS = !m_bScreenTracksGPS;
01798 m_menuView->Check(idViewGPSMarker, m_bScreenTracksGPS);
01799 SetActive(wxT("MapTracksGPS"), m_bScreenTracksGPS);
01800 }
01801
01802
01803
01804
01805
01806
01807 void MapFrame::OnViewGPSWindow(wxCommandEvent& event)
01808 {
01809 wxConfigBase * pConfig = wxConfigBase::Get();
01810
01811 if (m_menuView->IsChecked(idViewGPSWindow))
01812 m_pfrmGPS->Show();
01813 else
01814 m_pfrmGPS->Hide();
01815
01816 pConfig->Write(wxT("GPSWindowVisible"), m_menuView->IsChecked(idViewGPSWindow));
01817 pConfig->Flush();
01818 }
01819
01820
01821
01822
01823
01824
01825
01826 void MapFrame::OnViewWhatsNearByWindow(wxCommandEvent& event)
01827 {
01828 if (m_menuView->IsChecked(idViewWhatsNearByWindow))
01829 {
01830 m_pfrmWhatsNearBy->SetCenter(m_ctlMap->GetCenterCoordinates());
01831 m_pfrmWhatsNearBy->Show();
01832 }
01833 else
01834 {
01835 m_pfrmWhatsNearBy->Hide();
01836 }
01837
01838 wxConfigBase::Get()->Write(wxT("WhatsNearByWindowVisible"), m_menuView->IsChecked(idViewWhatsNearByWindow));
01839 wxConfigBase::Get()->Flush();
01840 }
01841
01842
01843
01844
01845
01846
01847 void MapFrame::SetFullScreenMode(bool bFullScreen)
01848 {
01849 ShowFullScreen(bFullScreen);
01850 m_menuView->Check(idViewFullScreen, IsFullScreen());
01851 }
01852
01853
01854
01855
01856
01857
01858 void MapFrame::OnViewFullScreen(wxCommandEvent& event)
01859 {
01860 SetFullScreenMode(!IsFullScreen());
01861 }
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871 void MapFrame::OnMapSetAddress(wxCommandEvent & event)
01872 {
01873 wxString strErrorMsg;
01874 wxString strMarkerName;
01875 MapMarker cMarker;
01876
01877 if (QueryAddress( wxT("Set Address"),
01878 this,
01879 m_ctlMap,
01880 wxT(""),
01881 m_adrGPS.m_strCityName,
01882 m_adrGPS.m_strStateName,
01883 false,
01884 cMarker,
01885 &strErrorMsg) != wxID_OK)
01886 return;
01887
01888 m_ctlMap->SetMarker(cMarker);
01889
01890 }
01891
01892
01893
01894
01895
01896
01897
01898
01899 void MapFrame::OnMapSetAngle(wxCommandEvent & event)
01900 {
01901 if (m_menuView->IsChecked(idViewAerialPhotos))
01902 {
01903 ::wxMessageBox(wxT("Sorry, maps cannot be rotated when aerial photos are enabled."),
01904 wxT("Error"),
01905 wxOK | wxICON_ERROR,
01906 this);
01907 return;
01908 }
01909
01910 wxTextEntryDialog dlg(this, wxT("Enter desired orientation in degrees"), wxT("Set Map Orientation"), wxString::Format(wxT("%.1f"), m_ctlMap->GetAngle()));
01911
01912 dlg.SetValue(wxString::Format(wxT("%.1f"), m_ctlMap->GetAngle()));
01913
01914 if (dlg.ShowModal() == wxID_OK)
01915 {
01916 double fAngle;
01917
01918 fAngle = 0;
01919 dlg.GetValue().ToDouble(&fAngle);
01920
01921 m_ctlMap->SetAngle(fAngle);
01922 }
01923 }
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933 void MapFrame::OnMapWaypoints(wxCommandEvent & event)
01934 {
01935 wxFont fntThis = GetFont();
01936 LocationDialog dlgAddress(this, m_ctlMap, ADFLAG_MARKERMANAGEMENTBUTTONS, &fntThis);
01937
01938 dlgAddress.m_strTitle = wxT("Waypoints");
01939
01940 dlgAddress.ShowModal();
01941
01942 SaveMarkers();
01943 }
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953 void MapFrame::OnMapGetDirections(wxCommandEvent & event)
01954 {
01955 if (m_menuMap->IsChecked(idMapGetDirections))
01956 {
01957 if (!m_pfrmDirections->Setup())
01958 m_pfrmDirections->Show();
01959 else
01960 m_menuMap->Check(idMapGetDirections, false);
01961 }
01962 else
01963 {
01964 m_pfrmDirections->Close();
01965 }
01966 }
01967
01968
01969
01970
01971
01972
01973
01974 void MapFrame::OnMapGetDirectionsAccel(wxCommandEvent & event)
01975 {
01976 if (m_menuMap->IsChecked(idMapGetDirections))
01977 {
01978
01979 m_menuMap->Check(idMapGetDirections, 0);
01980 OnMapGetDirections(event);
01981 }
01982
01983
01984 m_menuMap->Check(idMapGetDirections, 1);
01985 OnMapGetDirections(event);
01986 }
01987
01988
01989
01990
01991
01992
01993 void MapFrame::OnMapMoveCenterLeft(wxCommandEvent & event)
01994 {
01995 m_ctlMap->MoveCenterLeft();
01996 }
01997
01998
01999
02000
02001
02002
02003 void MapFrame::OnMapMoveCenterRight(wxCommandEvent & event)
02004 {
02005 m_ctlMap->MoveCenterRight();
02006 }
02007
02008
02009
02010
02011
02012
02013 void MapFrame::OnMapMoveCenterUp(wxCommandEvent & event)
02014 {
02015 m_ctlMap->MoveCenterUp();
02016 }
02017
02018
02019
02020
02021
02022
02023 void MapFrame::OnMapMoveCenterDown(wxCommandEvent & event)
02024 {
02025 m_ctlMap->MoveCenterDown();
02026 }
02027
02028
02029
02030
02031
02032
02033 void MapFrame::OnToolsMeasure(wxCommandEvent& event)
02034 {
02035 if ( m_ToolMode == toolMeasure )
02036 {
02037 m_ToolMode = toolNone;
02038 return;
02039 }
02040
02041 m_ToolMode = toolMeasure;
02042 }
02043
02044
02045
02046
02047
02048
02049 void MapFrame::OnUpdateToolsMeasure(wxUpdateUIEvent& event)
02050 {
02051 event.Check( m_ToolMode == toolMeasure );
02052 }
02053
02054
02055
02056
02057
02058
02059 void MapFrame::OnToolsZoom(wxCommandEvent& event)
02060 {
02061 if ( m_ToolMode == toolZoom )
02062 {
02063 m_ToolMode = toolNone;
02064 return;
02065 }
02066
02067 m_ToolMode = toolZoom;
02068 }
02069
02070
02071
02072
02073
02074
02075 void MapFrame::OnUpdateToolsZoom(wxUpdateUIEvent& event)
02076 {
02077 event.Check( m_ToolMode == toolZoom );
02078 }
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089 void MapFrame::OnToolsDownloadTIGERLineMaps(wxCommandEvent & event)
02090 {
02091 wxFont fntThis = GetFont();
02092 vector<wxString> vCounties;
02093 vector<wxString>::iterator i;
02094 vector<wxString> vDownloaded;
02095 MapDataImporter_GNISDECI diGNIS;
02096 MapDataImporter_TigerLine diTigerLine;
02097
02098 vCounties = GetCountyNames();
02099
02100 for (i = vCounties.begin(); i != vCounties.end(); i++)
02101 {
02102 int iCountyCode;
02103
02104 iCountyCode = CountyCodeByName(*i);
02105
02106 if (diTigerLine.IsCountyLoaded(iCountyCode))
02107 vDownloaded.push_back(*i);
02108 }
02109
02110 CountyDialog dlgCounty(this, &fntThis, vDownloaded);
02111
02112 if (dlgCounty.ShowModal() == wxID_OK)
02113 {
02114 vector<wxInt32> viStateCountyCodes;
02115 unsigned int i;
02116 map<wxString, bool> mapDownloading;
02117 int iCount;
02118 int iProgressPosition;
02119
02120 iCount = 0;
02121 for (i = 0; i < dlgCounty.m_strSelCounties.size(); i++)
02122 {
02123 int iCountyCode;
02124 wxString strStateAbbrev;
02125
02126 iCountyCode = CountyCodeByName(dlgCounty.m_strSelCounties[i]);
02127 strStateAbbrev = StateAbbreviationByCode(iCountyCode / 1000);
02128
02129 if (!diTigerLine.IsCountyLoaded(iCountyCode))
02130 iCount++;
02131
02132 if (!diGNIS.IsGNISStateLoaded(strStateAbbrev) && !mapDownloading[strStateAbbrev])
02133 {
02134 mapDownloading[strStateAbbrev] = true;
02135 iCount++;
02136 }
02137 }
02138
02139 if (!iCount)
02140 {
02141 ::wxMessageBox(wxT("Selected maps have already been downloaded."),
02142 wxT("Error"),
02143 wxOK | wxICON_ERROR,
02144 this);
02145 return;
02146 }
02147
02148 ProgressDialog dlgProgress(NULL, wxT("Downloading..."), iCount * 100);
02149 dlgProgress.Show();
02150 iProgressPosition = 0;
02151 for (i = 0; i < dlgCounty.m_strSelCounties.size(); i++)
02152 {
02153 int iCountyCode;
02154 wxString strStateAbbrev;
02155 MapDataImporter_GNISDECI diGNIS;
02156 MapDataImporter_TigerLine diTigerLine;
02157
02158 iCountyCode = CountyCodeByName(dlgCounty.m_strSelCounties[i]);
02159 strStateAbbrev = StateAbbreviationByCode(iCountyCode / 1000);
02160
02161 if (!diTigerLine.IsCountyLoaded(iCountyCode))
02162 {
02163 viStateCountyCodes.push_back(iCountyCode);
02164 }
02165
02166 if (!diGNIS.IsGNISStateLoaded(strStateAbbrev))
02167 {
02168 diGNIS.DownloadGNISState(&m_cRecords, strStateAbbrev, &dlgProgress, iProgressPosition, 99);
02169 iProgressPosition += 100;
02170 }
02171 }
02172
02173 MapDataImporter_TigerLine diTigerLine;
02174 diTigerLine.DownloadCounties(&m_cRecords, viStateCountyCodes, &dlgProgress, iProgressPosition, viStateCountyCodes.size() * 100);
02175 iProgressPosition += viStateCountyCodes.size() * 100;
02176
02177 m_ctlMap->MapUpdated(UPDATED_DATA);
02178 }
02179 }
02180
02181 #ifdef USE_OPENSTREETMAP
02182
02183
02184
02185
02186
02187 void MapFrame::OnToolsDownloadOSMMaps(wxCommandEvent & event)
02188 {
02189 wxString strRtn = wxT("");
02190 wxStringTokenizer tkz;
02191 Point ptTL;
02192 Point ptBR;
02193 MapDataImporter_OSM osm;
02194 wxConfigBase * pConfig = wxConfigBase::Get();
02195
02196 if (pConfig->Read(wxT("OSMUsername")) == wxT(""))
02197 {
02198 ::wxMessageBox(wxT("You must enter your OpenStreetMap username and password in Preferences before you can download any maps."),
02199 wxT("Error"),
02200 wxOK | wxICON_ERROR,
02201 this);
02202 return;
02203 }
02204
02205 while (strRtn == wxT(""))
02206 {
02207 strRtn = wxGetTextFromUser(wxT("Please enter the coordinate range you wish to download."),
02208 wxT("Specify Coordinates"),
02209 wxT("0 N, 0 W : 0 N, 0 W"),
02210 this);
02211
02212 if (strRtn == wxT(""))
02213 return;
02214
02215 if (strRtn.Find(wxT(":")) < 0)
02216 strRtn = wxT("");
02217
02218 tkz.SetString(strRtn, wxT(":"), wxTOKEN_STRTOK);
02219
02220 ptTL.SetInvalid();
02221 ptTL.ParsePoint(tkz.GetNextToken());
02222 ptBR.SetInvalid();
02223 ptBR.ParsePoint(tkz.GetNextToken());
02224
02225 if (!ptTL.IsValid() || !ptBR.IsValid())
02226 strRtn = wxT("");
02227
02228 if (strRtn == wxT(""))
02229 {
02230 ::wxMessageBox( wxT("Unable to parse the coordinates you entered. Please enter two coordinates separated by a colon."),
02231 wxT("Error"),
02232 wxOK | wxICON_ERROR,
02233 this);
02234 }
02235 }
02236
02237 ProgressDialog dlgProgress(NULL, wxT("Downloading..."), 1000);
02238 dlgProgress.Show();
02239
02240 if (!osm.DownloadRegion(&m_cRecords, ptTL, ptBR, pConfig->Read(wxT("OSMUsername")), pConfig->Read(wxT("OSMPassword")), &dlgProgress, 0, 1000))
02241 m_ctlMap->SetCenterCoordinates((ptTL + ptBR) / 2);
02242 }
02243
02244
02245
02246
02247
02248
02249 void MapFrame::OnToolsImportOSMMaps(wxCommandEvent & event)
02250 {
02251 wxString strFilename;
02252
02253 strFilename = wxFileSelector(wxT("Select OpenStreetMaps XML File"),
02254 wxT(""),
02255 wxT(""),
02256 wxT("osm"),
02257 wxT("*.osm"),
02258 #if wxCHECK_VERSION(2, 8, 0)
02259 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
02260 #else
02261 wxOPEN | wxFILE_MUST_EXIST);
02262 #endif
02263
02264 if (strFilename != wxT(""))
02265 {
02266 Point ptCenter;
02267 MapDataImporter_OSM osm;
02268 ProgressDialog dlgProgress(NULL, wxT("Importing..."), 100);
02269 dlgProgress.Show();
02270
02271 osm.LoadDirect(strFilename, &m_cRecords, &dlgProgress, 0, 100, &ptCenter);
02272
02273 if (ptCenter.IsValid())
02274 m_ctlMap->SetCenterCoordinates(ptCenter);
02275 }
02276 }
02277 #endif
02278
02279
02280
02281
02282
02283
02284 void MapFrame::OnToolsImportGPXData(wxCommandEvent & event)
02285 {
02286 wxString strFilename;
02287
02288
02289 strFilename = wxFileSelector(wxT("Select GPX File"),
02290 wxT(""),
02291 wxT(""),
02292 wxT("gpx"),
02293 wxT("*.gpx"),
02294 #if wxCHECK_VERSION(2, 8, 0)
02295 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
02296 #else
02297 wxOPEN | wxFILE_MUST_EXIST);
02298 #endif
02299
02300 if (strFilename == wxT(""))
02301 return;
02302
02303
02304 wxArrayString arTypes;
02305 int iType;
02306 int iMarker;
02307
02308 for (iType = FIRST_RECORD_TYPE; iType < LAST_RECORD_TYPE; iType++)
02309 arTypes.Add(m_cRecords.GetRecordTypeDisplayName(iType));
02310
02311 wxSingleChoiceDialog dlgType( this,
02312 wxT("Please select the type of data"),
02313 wxT("Type of Data"),
02314 arTypes);
02315 if (dlgType.ShowModal() != wxID_OK)
02316 return;
02317
02318
02319 Point ptCenter;
02320 MapDataImporter_GPX gpx;
02321 ProgressDialog dlgProgress(NULL, wxT("Importing..."), 100);
02322 dlgProgress.Show();
02323
02324 gpx.Load(strFilename, &m_cRecords, &dlgProgress, 0, 100, &ptCenter, (ERecordType) (dlgType.GetSelection() + FIRST_RECORD_TYPE));
02325
02326 if (ptCenter.IsValid())
02327 m_ctlMap->SetCenterCoordinates(ptCenter);
02328
02329 for (iMarker = 0; iMarker < gpx.MarkerCount(); iMarker++)
02330 m_ctlMap->SetMarker(*gpx.GetMarker(iMarker));
02331 }
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341 void MapFrame::OnToolsPreferences(wxCommandEvent & event)
02342 {
02343
02344
02345
02346
02347 if ( ShowOptionsDialog(this, &m_cRecords, &m_ThemeManager) == wxID_SAVE)
02348 {
02349 m_GPSMonitorThread->Delete();
02350 m_GPSMonitorThread = new GPSMonitorThread(this);
02351 m_GPSMonitorThread->Create();
02352 m_GPSMonitorThread->Run();
02353
02354 ApplyPreferences();
02355 }
02356 }
02357
02358
02359
02360
02361
02362
02363
02364
02365 void MapFrame::OnHelpAbout(wxCommandEvent & event)
02366 {
02367 wxDialog dlg(this, -1, wxString(wxT("About Roadnav")));
02368 wxBoxSizer * sizerWnd = new wxBoxSizer(wxHORIZONTAL);
02369 wxBoxSizer * sizerOutside = new wxBoxSizer(wxHORIZONTAL);
02370 wxBoxSizer * sizerInside = new wxBoxSizer(wxVERTICAL);
02371 wxString strLicense;
02372
02373 strLicense += wxT("This program is free software; you can redistribute it and/or\n");
02374 strLicense += wxT("modify it under the terms of version 2 of the GNU General Public License\n");
02375 strLicense += wxT("as published by the Free Software Foundation.\n");
02376 strLicense += wxT("\n");
02377 strLicense += wxT("This program is distributed in the hope that it will be useful,\n");
02378 strLicense += wxT("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
02379 strLicense += wxT("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
02380 strLicense += wxT("GNU General Public License for more details.\n");
02381 strLicense += wxT("\n");
02382 strLicense += wxT("You should have received a copy of the GNU General Public License\n");
02383 strLicense += wxT("along with this program (COPYING in the application folder);\n");
02384 strLicense += wxT("if not, write to the Free Software Foundation, Inc.,\n");
02385 strLicense += wxT("51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n");
02386
02387
02388
02389
02390 sizerInside->Add(
02391 new wxStaticText(&dlg, -1, wxT("Roadnav ") wxT(VERSION), wxDefaultPosition),
02392 0,
02393 wxALIGN_LEFT | wxALL,
02394 3);
02395
02396 sizerInside->Add(
02397 new wxStaticText(&dlg, -1, wxT("Copyright (c) 2004 - 2008 Richard L. Lynch <rllynch@users.sourceforge.net>"), wxDefaultPosition),
02398 0,
02399 wxALIGN_LEFT | wxALL,
02400 3);
02401
02402 sizerInside->Add(
02403 new wxStaticText(&dlg, -1, wxT("http://roadnav.sourceforge.net/"), wxDefaultPosition),
02404 0,
02405 wxALIGN_LEFT | wxALL,
02406 3);
02407
02408 sizerInside->Add(
02409 new wxStaticText(&dlg, -1, strLicense, wxDefaultPosition),
02410 0,
02411 wxALIGN_LEFT | wxALL,
02412 3);
02413
02414 sizerInside->Add(new wxButton(&dlg, wxID_OK, _T("&OK")), 0, wxALL | wxALIGN_RIGHT, 5);
02415
02416
02417
02418
02419 wxBitmap bmpAppIcon(appicon64_xpm);
02420 sizerOutside->Add(
02421 new wxStaticBitmap(&dlg, -1, bmpAppIcon),
02422 0,
02423 wxALIGN_CENTER | wxALL,
02424 5);
02425
02426 sizerOutside->Add(
02427 sizerInside,
02428 0,
02429 wxALL,
02430 5);
02431
02432
02433
02434
02435
02436 sizerWnd->Add(
02437 sizerOutside,
02438 0,
02439 wxALL,
02440 8);
02441
02442 dlg.SetSizer(sizerWnd);
02443 sizerWnd->Fit(&dlg);
02444 dlg.Center();
02445 dlg.Layout();
02446 dlg.ShowModal();
02447 }
02448
02449
02450
02451
02452
02453
02454 void MapFrame::OnSolarTimerTest(wxCommandEvent& event)
02455 {
02456 wxDateTime sunrise = m_SolarTimer.GetSunrise();
02457 wxDateTime sunset = m_SolarTimer.GetSunset();
02458
02459 double lat,lon;
02460 m_SolarTimer.GetPosition(lon,lat);
02461
02462 wxString msg = wxString::Format(wxT("Lat %.1f, Long %.1f\nSunrise %s\nSunset %s"),
02463 lat,lon,
02464 wx_c_str(sunrise.FormatTime()),
02465 wx_c_str(sunset.FormatTime()));
02466
02467 wxMessageBox(msg);
02468 }
02469
02470
02471
02472
02473
02474
02475
02476 void MapFrame::OnGPSWindowHiding()
02477 {
02478 m_menuView->Check(idViewGPSWindow, false);
02479 wxConfigBase::Get()->Write(wxT("GPSWindowVisible"), 0);
02480 wxConfigBase::Get()->Flush();
02481 }
02482
02483
02484
02485
02486
02487
02488
02489 void MapFrame::OnDirectionsWindowHiding()
02490 {
02491 m_menuMap->Check(idMapGetDirections, false);
02492 }
02493
02494
02495
02496
02497
02498
02499
02500 void MapFrame::OnWhatsNearByWindowHiding()
02501 {
02502 m_menuView->Check(idViewWhatsNearByWindow, false);
02503 wxConfigBase::Get()->Write(wxT("WhatsNearByWindowVisible"), 0);
02504 wxConfigBase::Get()->Flush();
02505 }
02506
02507
02508
02509
02510
02511
02512
02513 void MapFrame::OnMapRecentered(wxCommandEvent & event)
02514 {
02515 Address sAddr;
02516 wxString strAddress;
02517 static int iLastDetailLevel = -1;
02518 int iCurrentDetailLevel;
02519
02520 if (m_menuView->IsChecked(idViewWhatsNearByWindow))
02521 m_pfrmWhatsNearBy->SetCenter(m_ctlMap->GetCenterCoordinates());
02522
02523 sAddr = FindCoordinates(m_ctlMap->GetCenterCoordinates(), OnlyRoadsVisibility(), false, false, &m_cRecords);
02524
02525 if (sAddr.m_bValid)
02526 {
02527 strAddress = sAddr.FormatAddress();
02528
02529 strAddress.Replace(wxT("\r"), wxT(""));
02530 strAddress.Replace(wxT("\n"), wxT(" "));
02531
02532 SetTitle(wxT("Roadnav - ") + strAddress);
02533 }
02534 else
02535 {
02536 SetTitle(wxT("Roadnav - ") + m_ctlMap->GetCenterCoordinates().FormatPoint());
02537 }
02538
02539 iCurrentDetailLevel = m_ctlMap->GetDetailLevel();
02540
02541 if (iCurrentDetailLevel != iLastDetailLevel)
02542 {
02543 UpdateSkinState();
02544 iLastDetailLevel = iCurrentDetailLevel;
02545 }
02546 }
02547
02548
02549
02550
02551
02552
02553
02554 void MapFrame::OnWhatsNearbyDoubleClick(wxCommandEvent & event)
02555 {
02556 Point ptSel;
02557
02558 ptSel = m_pfrmWhatsNearBy->GetSelectedCoordinates();
02559
02560 if (ptSel.IsValid())
02561 m_ctlMap->SetCenterCoordinates(ptSel);
02562 }
02563
02564
02565
02566
02567
02568
02569 void MapFrame::RedrawMap(wxCommandEvent & event)
02570 {
02571 m_ctlMap->MapUpdated(UPDATED_DATA);
02572 }
02573
02574
02575
02576
02577
02578
02579 MapControl * MapFrame::GetMapControl()
02580 {
02581 return m_ctlMap;
02582 }
02583
02584 void MapFrame::InitializeThemes()
02585 {
02586
02587
02588
02589 MapAppearanceSettings cThemeDefaultDay;
02590 cThemeDefaultDay.SetMiscColor(MiscColorBackground, ParseColor(wxT("#FFFFFF")) );
02591 cThemeDefaultDay.SetMiscColor(MiscColorForeground, ParseColor(wxT("#000000")) );
02592 cThemeDefaultDay.SetMiscColor(MiscColorMarkerBackground, ParseColor(wxT("#FFFF00")) );
02593 cThemeDefaultDay.SetMiscColor(MiscColorMarkerForeground, ParseColor(wxT("#000000")) );
02594 cThemeDefaultDay.SetColor( RecordTypeDefault, ParseColor(wxT("#C0C0C0")) );
02595 cThemeDefaultDay.SetColor( RecordTypeOneWaySmallRoad, ParseColor(wxT("#808080")) );
02596 cThemeDefaultDay.SetColor( RecordTypeTwoWaySmallRoad, ParseColor(wxT("#808080")) );
02597 cThemeDefaultDay.SetColor( RecordTypeOneWayLargeRoad, ParseColor(wxT("#827000")) );
02598 cThemeDefaultDay.SetColor( RecordTypeTwoWayLargeRoad, ParseColor(wxT("#827000")) );
02599 cThemeDefaultDay.SetColor( RecordTypeOneWayHighway, ParseColor(wxT("#B68628")) );
02600 cThemeDefaultDay.SetColor( RecordTypeTwoWayHighway, ParseColor(wxT("#B68628")) );
02601 cThemeDefaultDay.SetColor( RecordTypeRailroad, ParseColor(wxT("#808080")) );
02602 cThemeDefaultDay.SetColor( RecordTypeWater, ParseColor(wxT("#0000ff")) );
02603 cThemeDefaultDay.SetColor( RecordTypeInvisibleLandBoundary, ParseColor(wxT("#A0A0A0")) );
02604 cThemeDefaultDay.SetColor( RecordTypeInvisibleWaterBoundary, ParseColor(wxT("#C0C0FF")) );
02605 cThemeDefaultDay.SetColor( RecordTypeInvisibleMiscBoundary, ParseColor(wxT("#C0C0FF")) );
02606 cThemeDefaultDay.SetColor( RecordTypeLandmark, ParseColor(wxT("#2FAF41")) );
02607 cThemeDefaultDay.SetColor( RecordTypePhysicalFeature, ParseColor(wxT("#000000")) );
02608 cThemeDefaultDay.SetColor( RecordTypeTownOrCity, ParseColor(wxT("#808080")) );
02609 cThemeDefaultDay.SetColor( RecordTypeStateBoundary, ParseColor(wxT("#008000")) );
02610 cThemeDefaultDay.SetColor( RecordTypeCountyBoundary, ParseColor(wxT("#f0f0f0")) );
02611 cThemeDefaultDay.FixTextColorInsideLines();
02612
02613 MapAppearanceSettings cThemeDefaultNight;
02614 cThemeDefaultNight.SetMiscColor(MiscColorBackground, ParseColor(wxT("#000000")) );
02615 cThemeDefaultNight.SetMiscColor(MiscColorForeground, ParseColor(wxT("#ffffff")) );
02616 cThemeDefaultNight.SetMiscColor(MiscColorMarkerBackground, ParseColor(wxT("#000040")) );
02617 cThemeDefaultNight.SetMiscColor(MiscColorMarkerForeground, ParseColor(wxT("#FFFFFF")) );
02618 cThemeDefaultNight.SetColor( RecordTypeDefault, ParseColor(wxT("#C0C0C0")) );
02619 cThemeDefaultNight.SetColor( RecordTypeOneWaySmallRoad, ParseColor(wxT("#d0d0d0")) );
02620 cThemeDefaultNight.SetColor( RecordTypeTwoWaySmallRoad, ParseColor(wxT("#d0d0d0")) );
02621 cThemeDefaultNight.SetColor( RecordTypeOneWayLargeRoad, ParseColor(wxT("#cccc00")) );
02622 cThemeDefaultNight.SetColor( RecordTypeTwoWayLargeRoad, ParseColor(wxT("#cccc00")) );
02623 cThemeDefaultNight.SetColor( RecordTypeOneWayHighway, ParseColor(wxT("#B68628")) );
02624 cThemeDefaultNight.SetColor( RecordTypeTwoWayHighway, ParseColor(wxT("#B68628")) );
02625 cThemeDefaultNight.SetColor( RecordTypeRailroad, ParseColor(wxT("#808080")) );
02626 cThemeDefaultNight.SetColor( RecordTypeWater, ParseColor(wxT("#6060ff")) );
02627 cThemeDefaultNight.SetColor( RecordTypeInvisibleLandBoundary, ParseColor(wxT("#A0A0A0")) );
02628 cThemeDefaultNight.SetColor( RecordTypeInvisibleWaterBoundary, ParseColor(wxT("#C0C0FF")) );
02629 cThemeDefaultNight.SetColor( RecordTypeInvisibleMiscBoundary, ParseColor(wxT("#C0C0FF")) );
02630 cThemeDefaultNight.SetColor( RecordTypeLandmark, ParseColor(wxT("#2FAF41")) );
02631 cThemeDefaultNight.SetColor( RecordTypePhysicalFeature, ParseColor(wxT("#000000")) );
02632 cThemeDefaultNight.SetColor( RecordTypeTownOrCity, ParseColor(wxT("#E5E5E5")) );
02633 cThemeDefaultNight.SetColor( RecordTypeStateBoundary, ParseColor(wxT("#00FF00")) );
02634 cThemeDefaultNight.SetColor( RecordTypeCountyBoundary, ParseColor(wxT("#404040")) );
02635 cThemeDefaultNight.FixTextColorInsideLines();
02636
02637 MapAppearanceSettings cThemeDefaultPhoto;
02638 cThemeDefaultPhoto.SetMiscColor(MiscColorBackground, ParseColor(wxT("#808080")) );
02639 cThemeDefaultPhoto.SetMiscColor(MiscColorForeground, ParseColor(wxT("#ffffff")) );
02640 cThemeDefaultPhoto.SetMiscColor(MiscColorMarkerBackground, ParseColor(wxT("#000040")) );
02641 cThemeDefaultPhoto.SetMiscColor(MiscColorMarkerForeground, ParseColor(wxT("#FFFFFF")) );
02642 cThemeDefaultPhoto.SetColor( RecordTypeDefault, ParseColor(wxT("#C0C0C0")) );
02643 cThemeDefaultPhoto.SetColor( RecordTypeOneWaySmallRoad, ParseColor(wxT("#40ffff")) );
02644 cThemeDefaultPhoto.SetColor( RecordTypeTwoWaySmallRoad, ParseColor(wxT("#40ffff")) );
02645 cThemeDefaultPhoto.SetColor( RecordTypeOneWayLargeRoad, ParseColor(wxT("#ffff00")) );
02646 cThemeDefaultPhoto.SetColor( RecordTypeTwoWayLargeRoad, ParseColor(wxT("#ffff00")) );
02647 cThemeDefaultPhoto.SetColor( RecordTypeOneWayHighway, ParseColor(wxT("#00ff00")) );
02648 cThemeDefaultPhoto.SetColor( RecordTypeTwoWayHighway, ParseColor(wxT("#00ff00")) );
02649 cThemeDefaultPhoto.SetColor( RecordTypeRailroad, ParseColor(wxT("#80ff80")) );
02650 cThemeDefaultPhoto.SetColor( RecordTypeWater, ParseColor(wxT("#0000ff")) );
02651 cThemeDefaultPhoto.SetColor( RecordTypeInvisibleLandBoundary, ParseColor(wxT("#A0A0A0")) );
02652 cThemeDefaultPhoto.SetColor( RecordTypeInvisibleWaterBoundary, ParseColor(wxT("#C0C0FF")) );
02653 cThemeDefaultPhoto.SetColor( RecordTypeInvisibleMiscBoundary, ParseColor(wxT("#C0C0FF")) );
02654 cThemeDefaultPhoto.SetColor( RecordTypeLandmark, ParseColor(wxT("#2FAF41")) );
02655 cThemeDefaultPhoto.SetColor( RecordTypePhysicalFeature, ParseColor(wxT("#000000")) );
02656 cThemeDefaultPhoto.SetColor( RecordTypeTownOrCity, ParseColor(wxT("#E5E5E5")) );
02657 cThemeDefaultPhoto.SetColor( RecordTypeStateBoundary, ParseColor(wxT("#00FF00")) );
02658 cThemeDefaultPhoto.SetColor( RecordTypeCountyBoundary, ParseColor(wxT("#00ffff")) );
02659 cThemeDefaultPhoto.FixTextColorInsideLines();
02660
02661 m_ThemeManager.AddTheme(wxT("Default-Day"), cThemeDefaultDay);
02662 m_ThemeManager.AddTheme(wxT("Default-Night"), cThemeDefaultNight);
02663 m_ThemeManager.AddTheme(wxT("Default-Photo"), cThemeDefaultPhoto);
02664
02665 m_ThemeManager.SetNightTheme(wxT("Default-Night"));
02666 m_ThemeManager.SetDayTheme(wxT("Default-Day"));
02667 m_ThemeManager.SetPhotoTheme(wxT("Default-Photo"));
02668
02669
02670
02671
02672
02673 m_MapAppearanceSettings = cThemeDefaultDay;
02674
02675 }
02676
02677
02678
02679
02680
02681
02682
02683 void MapFrame::ApplyPreferences()
02684 {
02685 wxConfigBase * pConfig = wxConfigBase::Get();
02686
02687
02688
02689
02690 ConfigureProxy();
02691
02692
02693
02694
02695
02696 int zipHome;
02697 pConfig->Read(wxT("HomeZipCode"), &zipHome, 0);
02698
02699 Point ptHome;
02700 GetZipCodeCoordinates(zipHome, &ptHome, &ptHome);
02701 m_SolarTimer.SetOwner(this,ptHome.GetLong(),ptHome.GetLat(),SolarTimer::Official);
02702
02703 UpdateTheme();
02704
02705
02706
02707
02708
02709 wxString strPositionFormat;
02710 pConfig->Read(wxT("PositionFormat"), &strPositionFormat, POSITION_FORMAT_3);
02711 Point::SetPointFormat(strPositionFormat);
02712
02713
02714
02715
02716
02717 wxString strCurrentValue;
02718 long units;
02719 pConfig->Read(wxT("Units"),&units,0);
02720 SetDisplayUnits((EUnits)units);
02721
02722
02723
02724
02725 pConfig->Read(wxT("NorthAlwaysUp"), &m_bNorthAlwaysUp, 0);
02726 if (m_bNorthAlwaysUp)
02727 m_ctlMap->SetAngle(0);
02728
02729
02730
02731
02732
02733 double fDrawingScaleFactor;
02734 pConfig->Read(wxT("DrawingScaleFactor"), &fDrawingScaleFactor, 1);
02735 m_ctlMap->SetDrawingScaleFactor(fDrawingScaleFactor);
02736
02737
02738
02739
02740 double fPreferSmallRoads, fPreferLargeRoads, fPreferHighways;
02741 pConfig->Read(wxT("PreferSmallRoads"), &fPreferSmallRoads, 1);
02742 pConfig->Read(wxT("PreferLargeRoads"), &fPreferLargeRoads, 1.44);
02743 pConfig->Read(wxT("PreferHighways"), &fPreferHighways, 1.54);
02744 MapDataEntry_Std::SetRoutingPreferences(fPreferSmallRoads, fPreferLargeRoads, fPreferHighways);
02745
02746
02747
02748
02749 wxString strSpeedControlledCutoffs;
02750 wxStringTokenizer tkzSpeedControlledCutoffs;
02751 bool bDone;
02752
02753 pConfig->Read(wxT("SpeedControlledDetailLevelCutoffs"), &strSpeedControlledCutoffs, wxT("25, 50"));
02754
02755 m_vSpeedControlledDetailLevelCutoffs.clear();
02756 tkzSpeedControlledCutoffs.SetString(strSpeedControlledCutoffs, wxT(",; "), wxTOKEN_STRTOK);
02757
02758 bDone = false;
02759 while (!bDone)
02760 {
02761 wxString strToken;
02762 double fCutoff;
02763
02764 strToken = tkzSpeedControlledCutoffs.GetNextToken();
02765
02766 fCutoff = 0;
02767 strToken.ToDouble(&fCutoff);
02768
02769 if (fCutoff > 1e-6)
02770 m_vSpeedControlledDetailLevelCutoffs.push_back(fCutoff);
02771 else
02772 bDone = true;
02773 }
02774
02775 #ifdef USE_SCRIPTING
02776
02777 // Scripting settings
02778
02779 m_pScripting->DeleteAllTCPServers();
02780 if (pConfig->Read(wxT("ScriptingTCPServerEnabled"), (long) 0))
02781 m_pScripting->AddTCPServer(pConfig->Read(wxT("ScriptingTCPServerPortNumber"), DEFAULT_SCRIPTING_TCP_PORT_NUMBER),
02782 pConfig->Read(wxT("ScriptingTCPServerAcceptOnlyLocal"), (long) 1));
02783 #endif
02784
02785
02786
02787
02788 delete m_pcTTS;
02789
02790 if (pConfig->Read(wxT("TTSType"), (long) TTSTypeUseAny) == TTSTypeUseAny)
02791 {
02792 ETTSType eFoundTTSType = TTSTypeUseAny;
02793 int iSearchTTSType;
02794
02795
02796
02797 for (iSearchTTSType = FIRST_TTSTYPE; iSearchTTSType <= LAST_TTSTYPE && eFoundTTSType == TTSTypeNone; iSearchTTSType++)
02798 {
02799 ETTSType eSearchTTSType = (ETTSType) iSearchTTSType;
02800 ITTS * pcTTS;
02801
02802 pcTTS = ConstructTTS(eSearchTTSType);
02803
02804 if (pcTTS->Name() != wxT("None") && pcTTS->GetStatus() == ITTS::TTSStatusOK)
02805 eFoundTTSType = eSearchTTSType;
02806
02807 delete pcTTS;
02808 }
02809
02810 pConfig->Write(wxT("TTSType"), (long) eFoundTTSType);
02811 }
02812
02813 m_pcTTS = ConstructTTS((ETTSType) pConfig->Read(wxT("TTSType"), (long) TTSTypeUseAny));
02814
02815 #ifdef LIBROADNAV_DEBUG
02816
02817 // Debugging
02818
02819 if (pConfig->Read(wxT("GenerateDebugLog"), (long) 0))
02820 LibRoadnavDebugEnable();
02821 #endif
02822
02823
02824 m_bShowPopupGPSErrors = pConfig->Read(wxT("ShowPopupGPSErrors"), (long)0);
02825
02826
02827
02828
02829 m_ctlMap->ShowAerialPhotos(m_menuView->IsChecked(idViewAerialPhotos), pConfig->Read(wxT("AutoDownloadMaps"), (int) 1));
02830
02831
02832
02833
02834 m_ctlMap->MapUpdated(UPDATED_THEME);
02835 }
02836
02837
02838
02839
02840
02841
02842 int MapFrame::MapNameToID(wxString strName)
02843 {
02844 if (strName == wxT("zoomin"))
02845 return idViewZoomIn;
02846
02847 if (strName == wxT("zoomout"))
02848 return idViewZoomOut;
02849
02850 if (strName == wxT("save"))
02851 return idFileSaveAs;
02852
02853 if (strName == wxT("print"))
02854 return idFilePrint;
02855
02856 if (strName == wxT("exit"))
02857 return wxID_EXIT;
02858
02859 if (strName == wxT("setaddress"))
02860 return idMapSetAddress;
02861
02862 if (strName == wxT("getdirections"))
02863 return idMapGetDirections;
02864
02865 if (strName == wxT("mapmoveleft"))
02866 return idMapMoveCenterLeft;
02867
02868 if (strName == wxT("mapmoveright"))
02869 return idMapMoveCenterRight;
02870
02871 if (strName == wxT("mapmoveup"))
02872 return idMapMoveCenterUp;
02873
02874 if (strName == wxT("mapmovedown"))
02875 return idMapMoveCenterDown;
02876
02877 if (strName == wxT("downloadmaps"))
02878 return idToolsDownloadMaps;
02879
02880 if (strName == wxT("preferences"))
02881 return wxID_PREFERENCES;
02882
02883 if (strName == wxT("zoom0"))
02884 return idViewZoom0;
02885
02886 if (strName == wxT("zoom1"))
02887 return idViewZoom1;
02888
02889 if (strName == wxT("zoom2"))
02890 return idViewZoom2;
02891
02892 if (strName == wxT("zoom3"))
02893 return idViewZoom3;
02894
02895 if (strName == wxT("zoom4"))
02896 return idViewZoom4;
02897
02898 if (strName == wxT("zoom5"))
02899 return idViewZoom5;
02900
02901 if (strName == wxT("zoom6"))
02902 return idViewZoom6;
02903
02904 if (strName == wxT("zoom7"))
02905 return idViewZoom7;
02906
02907 if (strName == wxT("zoom8"))
02908 return idViewZoom8;
02909
02910 if (strName == wxT("zoom9"))
02911 return idViewZoom9;
02912
02913 if (strName == wxT("zoom10"))
02914 return idViewZoom10;
02915
02916 if (strName == wxT("zoom11"))
02917 return idViewZoom11;
02918
02919 if (strName == wxT("zoom12"))
02920 return idViewZoom12;
02921
02922 if (strName == wxT("zoom13"))
02923 return idViewZoom13;
02924
02925 if (strName == wxT("zoom14"))
02926 return idViewZoom14;
02927
02928 if (strName == wxT("MapTracksGPS"))
02929 return idViewGPSMarker;
02930
02931 return -1;
02932 }
02933
02934
02935
02936
02937
02938
02939
02940 void MapFrame::OnEscapeKey(wxCommandEvent & event)
02941 {
02942 if (!IsFullScreen())
02943 return;
02944
02945 OnViewFullScreen(event);
02946 }
02947
02948
02949
02950
02951
02952
02953
02954 void MapFrame::CreateNamedControl(wxString strName)
02955 {
02956 if (strName == wxT("compass") && !m_pctlCompass)
02957 {
02958 m_pctlCompass = new CompassControl(this);
02959 AddNamedControl(m_pctlCompass, wxT("compass"));
02960 }
02961 }
02962
02963
02964
02965
02966
02967
02968 void MapFrame::DeleteNamedControl(wxString strName, wxControl * pControl)
02969 {
02970 if (strName == wxT("compass"))
02971 {
02972 delete m_pctlCompass;
02973 m_pctlCompass = NULL;
02974 }
02975
02976 if (strName == wxT("map"))
02977 {
02978 AddNamedControl(m_ctlMap, wxT("map"));
02979 }
02980 }
02981
02982
02983
02984
02985
02986
02987
02988 void MapFrame::OnDownloadCounty(wxCommandEvent & ev)
02989 {
02990 wxString strStateAbbrev;
02991 int iCount;
02992 int iProgressPosition;
02993 MapDataImporter_GNISDECI diGNIS;
02994 MapDataImporter_TigerLine diTigerLine;
02995 int iCountyCode;
02996
02997 if (!wxConfigBase::Get()->Read(wxT("AutoDownloadMaps"), (int) 1))
02998 return;
02999
03000 iCountyCode = ev.GetInt();
03001
03002 iCount = 0;
03003 iProgressPosition = 0;
03004
03005 strStateAbbrev = StateAbbreviationByCode(iCountyCode / 1000);
03006
03007 if (!diTigerLine.IsCountyLoaded(iCountyCode))
03008 iCount += 100;
03009
03010 if (!diGNIS.IsGNISStateLoaded(strStateAbbrev))
03011 iCount += 100;
03012
03013 if (!iCount)
03014 return;
03015
03016 ProgressDialog dlgProgress(NULL, wxT("Downloading..."), iCount);
03017 dlgProgress.Show();
03018
03019 if (!diTigerLine.IsCountyLoaded(iCountyCode))
03020 {
03021 diTigerLine.DownloadCounty(&m_cRecords, iCountyCode, &dlgProgress, iProgressPosition, 100);
03022 iProgressPosition += 100;
03023 }
03024 if (!diGNIS.IsGNISStateLoaded(strStateAbbrev))
03025 {
03026 diGNIS.DownloadGNISState(&m_cRecords, strStateAbbrev, &dlgProgress, iProgressPosition, 100);
03027 iProgressPosition += 100;
03028 }
03029 m_ctlMap->MapUpdated(UPDATED_DATA);
03030 }
03031
03032
03033
03034
03035
03036
03037 void MapFrame::SetVariable(wxString strName, wxString strValue)
03038 {
03039 SetNamedText(strName, strValue);
03040 LCDprocSetText(strName, strValue);
03041 }
03042
03043
03044
03045
03046
03047
03048 void MapFrame::UpdateSkinState()
03049 {
03050 int iDL;
03051 int nDetailLevels;
03052 int iCurrentDetailLevel;
03053
03054 iCurrentDetailLevel = m_ctlMap->GetDetailLevel();
03055 nDetailLevels = m_ctlMap->GetDetailLevelCount();
03056
03057 for (iDL = 0; iDL < nDetailLevels; iDL++)
03058 SetActive(wxString::Format(wxT("zoom%d"), iDL), iDL == iCurrentDetailLevel);
03059
03060 SetActive(wxT("MapTracksGPS"), m_bScreenTracksGPS);
03061 }
03062
03063 ITTS * MapFrame::GetTTS()
03064 {
03065 return m_pcTTS;
03066 }