📄 directionsframe.cpp
字号:
// compile list of what's needed iTotal = 0; for (iCounties = mapCounties.begin(); iCounties != mapCounties.end(); iCounties++) { MapControlDataImporter_GNISDECI diGNIS; MapControlDataImporter_TigerLine diTigerLine; wxString strState; int iCountyCode; iCountyCode = (*iCounties).first; strState = StateAbbreviationByCode(iCountyCode / 1000); // check county code if (iCountyCode > 0) { wxASSERT(strState != wxT("")); if (!diTigerLine.IsCountyLoaded(iCountyCode) && bDownloadingCounty.find(iCountyCode) == bDownloadingCounty.end()) { bDownloadingCounty[iCountyCode] = true; vDownloadCounties.push_back(iCountyCode); } if (!diGNIS.IsGNISStateLoaded(strState) && bDownloadingState.find(strState) == bDownloadingState.end()) { bDownloadingState[strState] = true; vDownloadStates.push_back(strState); } } } iTotal = bDownloadingCounty.size() + bDownloadingState.size(); LibRoadnavDebug2(wxT("Routing"), wxT("Want to download %d counties and %d states"), bDownloadingCounty.size(), bDownloadingState.size()); // does anything need to be downloaded? if (iTotal) { MapControlDataImporter_TigerLine diTigerLine; MapControlDataImporter_GNISDECI diGNIS; ProgressDialog dlgProgress(NULL, wxT("Downloading..."), iTotal * 100); dlgProgress.Show(); diTigerLine.DownloadCounties(m_pcRecords, vDownloadCounties, &dlgProgress, 0, vDownloadCounties.size() * 100); diGNIS.DownloadGNISStates(m_pcRecords, vDownloadStates, &dlgProgress, vDownloadCounties.size() * 100, vDownloadStates.size() * 100); } LibRoadnavDebug0(wxT("Routing"), wxT("Downloading complete")); } LibRoadnavDebug4(wxT("Routing"), wxT("Calculating route from %.7f, %.7f to %.7f to %.7f"), m_sStart.m_ptCoordinates.m_fLong, m_sStart.m_ptCoordinates.m_fLat, m_sEnd.m_ptCoordinates.m_fLong, m_sEnd.m_ptCoordinates.m_fLat ); m_vrPath = m_pcRecords->ShortestPath(m_sStart.m_ptCoordinates, m_sEnd.m_ptCoordinates, m_sStart.m_idRecord, m_sEnd.m_idRecord); if (!m_vrPath.size()) return true; LibRoadnavDebug0(wxT("Routing"), wxT("Shortest route found")); LibRoadnavDebug0(wxT("Routing"), wxT("Translating records to coordinates")); /// Current path in long/lat vector<Point> vptPath; vptPath = m_pcRecords->TranslateRecordsToCoordinates(m_vrPath); LibRoadnavDebug0(wxT("Routing"), wxT("Translation done")); MapTrack cTrack(wxT("Directions"), vptPath, wxColour(255, 0, 0), true); // plot LibRoadnavDebug0(wxT("Routing"), wxT("Plotting track")); m_pfrmMap->GetMapControl()->SetTrack(cTrack); LibRoadnavDebug0(wxT("Routing"), wxT("Done plotting")); return false;}//////////////////////////////////////////////////////////////////////////////////// \brief Updated GPS coordinates received////// Record the coordinates, figure out if we're on path, give any verbal cues/// necessary, and recompute the path if the user is off course/////////////////////////////////////////////////////////////////////////////////void DirectionsFrame::OnGPSUpdate(bool bEnabled, bool bActive, bool bLocked, Point pt, double fSpeed, double fHeading, wxString strLockType, int nSat, Address adrGPS){ unsigned int i; double fBestDistanceAbs = INFINITY; double fBestDistanceMiles = INFINITY; int iBestLeg = -1; vector<tRecordID> vrPathLeft; wxString strNext; static MapControlData_Tiles cRecLocal; Address adrGPSLocal; cRecLocal.LoadRegion(pt, pt, OnlyRoadsVisibility()); adrGPSLocal = FindCoordinates(pt, OnlyRoadsVisibility(), false, true, &cRecLocal); LibRoadnavDebug0(wxT("Routing"), wxT("OnGPSUpdate")); ////////////////////////////////////////////////////////////////////////// // remember the GPS state ////////////////////////////////////////////////////////////////////////// m_bGPSLock = bLocked; m_ptGPS = pt; m_fGPSHeading = fHeading; m_fGPSSpeed = fSpeed; ////////////////////////////////////////////////////////////////////////// // don't do anything if the window isn't visible ////////////////////////////////////////////////////////////////////////// if (!IsShown()) { LibRoadnavDebug0(wxT("Routing"), wxT("Not visible - OnGPSUpdate exiting")); return; } ////////////////////////////////////////////////////////////////////////// // If live mode is off, then don't bother with the calculations either ////////////////////////////////////////////////////////////////////////// if (!m_bLiveMode) { LibRoadnavDebug0(wxT("Routing"), wxT("Live mode off - OnGPSUpdate exiting")); return; } ////////////////////////////////////////////////////////////////////////// // lost GPS lock? stop now then ////////////////////////////////////////////////////////////////////////// if (!bLocked) { LibRoadnavDebug0(wxT("Routing"), wxT("No lock - OnGPSUpdate exiting")); return; } ////////////////////////////////////////////////////////////////////////// // Lockout? ////////////////////////////////////////////////////////////////////////// if (m_bLockOutGPSUpdate) { LibRoadnavDebug0(wxT("Routing"), wxT("Lockout - OnGPSUpdate exiting")); return; } m_bLockOutGPSUpdate = true; ////////////////////////////////////////////////////////////////////////// // find the leg of the trip that we're closest too ////////////////////////////////////////////////////////////////////////// LibRoadnavDebug0(wxT("Routing"), wxT("Finding closest leg of route")); for (i = 0; i < m_vrPath.size(); i++) { double fDistance; IMapControlDataEntry * psRec; int iCoordinate; psRec = m_pcRecords->GetRecordByID(m_vrPath[i]); wxASSERT(psRec); for (iCoordinate = 0; iCoordinate < psRec->nCoordinates; iCoordinate++) { fDistance = (psRec->psCoordinates[iCoordinate] - adrGPSLocal.m_ptCoordinates).abs(); if (fDistance < fBestDistanceAbs) { fBestDistanceAbs = fDistance; fBestDistanceMiles = Distance(psRec->psCoordinates[iCoordinate], adrGPSLocal.m_ptCoordinates); iBestLeg = i; } } } ////////////////////////////////////////////////////////////////////////// // if more than 0.1 miles from path, recompute path ////////////////////////////////////////////////////////////////////////// if (fBestDistanceMiles > 0.1) { LibRoadnavDebug0(wxT("Routing"), wxT("Too far from route - recomputing")); int iLiveDirectionsTTS = 1; g_pConfig->Read(wxT("LiveDirectionsTTS"), &iLiveDirectionsTTS, 1); if (iLiveDirectionsTTS) m_pfrmMap->GetTTS()->Speak(wxT("Recalculating path")); ComputePath(); iBestLeg = 0; } ////////////////////////////////////////////////////////////////////////// // ignore the part of the path that has been covered and just show // what's left ////////////////////////////////////////////////////////////////////////// LibRoadnavDebug0(wxT("Routing"), wxT("Figuring out what's left")); for (i = iBestLeg; i < m_vrPath.size(); i++) vrPathLeft.push_back(m_vrPath[i]); if (vrPathLeft.size() >= 2) { ////////////////////////////////////////////////////////////////////////// // if there are at least two legs left, then figure out some directions ////////////////////////////////////////////////////////////////////////// double fDeltaAngle = 0; wxString strDirectionChange = wxT(""); vector<IMapControlDataEntry *> vAssociatedRecords; LibRoadnavDebug0(wxT("Routing"), wxT("Looking up intersection information")); vAssociatedRecords = m_pcRecords->IntersectionInformation(vrPathLeft[0], vrPathLeft[1], &fDeltaAngle, &strDirectionChange); if (strDirectionChange == wxT("continue")) strDirectionChange = wxT("go straight"); if (strDirectionChange.Length() > 0) strDirectionChange.GetWritableChar(0) = toupper(strDirectionChange.GetChar(0)); strNext = strDirectionChange + wxT(" onto ") + m_pcRecords->GetRecordByID(vrPathLeft[1])->NameAndType(0, true); } else { ////////////////////////////////////////////////////////////////////////// // we must be at the destination if there's one leg left ////////////////////////////////////////////////////////////////////////// strNext = wxT("At destination"); } ////////////////////////////////////////////////////////////////////////// // write out directions ////////////////////////////////////////////////////////////////////////// wxString strDirections; LibRoadnavDebug0(wxT("Routing"), wxT("Writing out directions")); strDirections = m_pcRecords->TranslateRecordsToDirections(vrPathLeft); m_pctlText->SetValue(strNext + wxT("\r\n") + strDirections + wxT("\r\n") + m_sEnd.FormatAddress() ); ////////////////////////////////////////////////////////////////////////// // update font ////////////////////////////////////////////////////////////////////////// LibRoadnavDebug0(wxT("Routing"), wxT("Fixing UI")); wxTextAttr taEdit(m_clrText, m_clrBackground, m_fntText); m_pctlText->SetDefaultStyle(taEdit); m_pctlText->SetStyle(0, m_pctlText->GetLastPosition(), taEdit); ////////////////////////////////////////////////////////////////////////// // verbalize if the current action is different than the previous action ////////////////////////////////////////////////////////////////////////// if (strNext != m_strLastNext) { int iLiveDirectionsTTS = 1; g_pConfig->Read(wxT("LiveDirectionsTTS"), &iLiveDirectionsTTS, 1); if (iLiveDirectionsTTS) { LibRoadnavDebug0(wxT("Routing"), wxT("Speaking directions")); m_pfrmMap->GetTTS()->Speak(strNext); LibRoadnavDebug0(wxT("Routing"), wxT("Done speaking")); } m_pfrmMap->SetVariable(wxT("Directions - Next Step"), strNext); m_strLastNext = strNext; } wxString strBalance; LibRoadnavDebug0(wxT("Routing"), wxT("Updating skin variables")); strBalance = strDirections; m_pfrmMap->SetVariable(wxT("Directions - Line 1"), strBalance.BeforeFirst(wxT('\n'))); strBalance = strBalance.AfterFirst(wxT('\n')); m_pfrmMap->SetVariable(wxT("Directions - Line 2"), strBalance.BeforeFirst(wxT('\n'))); strBalance = strBalance.AfterFirst(wxT('\n')); m_pfrmMap->SetVariable(wxT("Directions - Line 3"), strBalance.BeforeFirst(wxT('\n'))); strBalance = strBalance.AfterFirst(wxT('\n')); m_pfrmMap->SetVariable(wxT("Directions - Line 4"), strBalance.BeforeFirst(wxT('\n'))); m_bLockOutGPSUpdate = false; LibRoadnavDebug0(wxT("Routing"), wxT("OnGPSUpdate done"));}//////////////////////////////////////////////////////////////////////////////////// \brief User wants to close this window - notify parent and hide./////////////////////////////////////////////////////////////////////////////////void DirectionsFrame::OnClose(wxCloseEvent& event){ m_pfrmMap->GetMapControl()->ClearMarker(wxT("Starting Address")); m_pfrmMap->GetMapControl()->ClearMarker(wxT("Destination Address")); m_pfrmMap->GetMapControl()->ClearTrack(wxT("Directions")); Hide(); m_pfrmMap->OnDirectionsWindowHiding(); m_pcRecords->Clear();}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetBackgroundColour calls down to m_pctlText/////////////////////////////////////////////////////////////////////////////////bool DirectionsFrame::SetBackgroundColour(const wxColour& colour){ if (colour != m_clrBackground) { m_clrBackground = colour; wxTextAttr taEdit(m_clrText, m_clrBackground, m_fntText); m_pctlText->SetDefaultStyle(taEdit); m_pctlText->SetStyle(0, m_pctlText->GetLastPosition(), taEdit); m_pctlText->SetBackgroundColour(m_clrBackground); } return wxFrame::SetBackgroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetForegroundColour calls down to m_pctlText/////////////////////////////////////////////////////////////////////////////////bool DirectionsFrame::SetForegroundColour(const wxColour& colour){ if (colour != m_clrText) { m_clrText = colour; wxTextAttr taEdit(m_clrText, m_clrBackground, m_fntText); m_pctlText->SetDefaultStyle(taEdit); m_pctlText->SetStyle(0, m_pctlText->GetLastPosition(), taEdit); } return wxFrame::SetForegroundColour(colour);}//////////////////////////////////////////////////////////////////////////////////// \brief Propagates SetFont calls down to m_pctlText/////////////////////////////////////////////////////////////////////////////////bool DirectionsFrame::SetFont(const wxFont& font){ m_fntText = font; wxTextAttr taEdit(m_clrText, m_clrBackground, m_fntText); m_pctlText->SetDefaultStyle(taEdit); m_pctlText->SetStyle(0, m_pctlText->GetLastPosition(), taEdit); return wxFrame::SetFont(font);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -