directionsframe.cpp
来自「roadnav 内含一个基于wxWindows库的车载导航系统。编译后」· C++ 代码 · 共 703 行 · 第 1/2 页
CPP
703 行
fTmp = ptTopLeft.m_fLat; ptTopLeft.m_fLat = ptBottomRight.m_fLat; ptBottomRight.m_fLat = fTmp; } // load the region that the route may cover m_pcRecords->LoadRegion(ptTopLeft, ptBottomRight, bVisibility); // enumerate counties present iCount = m_pcRecords->Count(); for (iRec = 0; iRec < iCount; iRec++) { IMapControlDataEntry * pcRec; Point * pptRec; int iCoordinate; pcRec = m_pcRecords->GetRecord(iRec); for (iCoordinate = 0; iCoordinate < pcRec->nCoordinates; iCoordinate++) { pptRec = &pcRec->psCoordinates[iCoordinate]; if (pptRec->m_fLong >= ptTopLeft.m_fLong && pptRec->m_fLong <= ptBottomRight.m_fLong && pptRec->m_fLat >= ptTopLeft.m_fLat && pptRec->m_fLat <= ptBottomRight.m_fLat) { mapCounties[pcRec->CountyCode()] = true; } } } map<int,bool> bDownloadingCounty; map<wxString,bool> bDownloadingState; int iTotal; // 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) { wxASSERT(strState != wxT("")); if (!diTigerLine.IsCountyLoaded(iCountyCode)) bDownloadingCounty[iCountyCode] = true; if (!diGNIS.IsGNISStateLoaded(strState)) bDownloadingState[strState] = true; } } 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) { map<int,bool>::iterator iCounty; map<wxString,bool>::iterator iState; ProgressDialog dlgProgress(NULL, wxT("Downloading..."), iTotal * 100); dlgProgress.Show(); iCount = 0; // download missing counties for (iCounty = bDownloadingCounty.begin(); iCounty != bDownloadingCounty.end(); iCounty++) { MapControlDataImporter_TigerLine diTigerLine; diTigerLine.DownloadCounty(m_pcRecords, (*iCounty).first, &dlgProgress, iCount * 100, 100); iCount++; } // download missing states for (iState = bDownloadingState.begin(); iState != bDownloadingState.end(); iState++) { MapControlDataImporter_GNISDECI diGNIS; diGNIS.DownloadGNISState(m_pcRecords, (*iState).first, &dlgProgress, iCount * 100, 100); iCount++; } } 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); 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, wxColor(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 fBestDistance = INFINITY; int iBestLeg = -1; vector<tRecordID> vrPathLeft; wxString strNext; 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; psRec = m_pcRecords->GetRecordByID(m_vrPath[i]); wxASSERT(psRec); fDistance = psRec->Distance(m_ptGPS); if (fDistance < fBestDistance) { fBestDistance = fDistance; iBestLeg = i; } fDistance = psRec->Distance(adrGPS.m_ptCoordinates); if (fDistance < fBestDistance) { fBestDistance = fDistance; iBestLeg = i; } } ////////////////////////////////////////////////////////////////////////// // if more than 0.1 miles from path, recompute path ////////////////////////////////////////////////////////////////////////// if (fBestDistance > 0.1) { LibRoadnavDebug0(wxT("Routing"), wxT("Too far from route - recomputing")); int iLiveDirectionsTTS = 1; g_pConfig->Read(wxT("LiveDirectionsTTS"), &iLiveDirectionsTTS, 1); if (iLiveDirectionsTTS) TTSSpeak("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(*wxBLACK, wxNullColour, 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")); TTSSpeak(strNext.mb_str(*wxConvCurrent)); 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("Ending Address")); m_pfrmMap->GetMapControl()->ClearTrack(wxT("Directions")); Hide(); m_pfrmMap->OnDirectionsWindowHiding(); m_pcRecords->Clear();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?