diff --git a/routing/route.cpp b/routing/route.cpp index 4819a8d502..bcdb08f475 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -148,7 +148,9 @@ Route::TTurns::const_iterator Route::GetCurrentTurn() const }); } -void Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const +// @TODO After current GPS possition passes the finish of the route the method GetCurrentTurn +// continues returning the last turn of the route. It looks like an issue. +bool Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const { auto it = GetCurrentTurn(); if (it == m_turns.end()) @@ -156,13 +158,14 @@ void Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn ASSERT(it != m_turns.end(), ()); distanceToTurnMeters = 0; turn = turns::TurnItem(); - return; + return false; } size_t const segIdx = (*it).m_index; turn = (*it); distanceToTurnMeters = m_poly.GetDistanceM(m_poly.GetCurrentIter(), m_poly.GetIterToIndex(segIdx)); + return true; } bool Route::GetNextTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const @@ -185,6 +188,22 @@ bool Route::GetNextTurn(double & distanceToTurnMeters, turns::TurnItem & turn) c return true; } +bool Route::GetNextTurns(vector & turns) +{ + turns.clear(); + + turns::TurnItemDist currentTurn; + if (!GetCurrentTurn(currentTurn.m_distMeters, currentTurn.m_turnItem)) + return false; + turns.push_back(move(currentTurn)); + + turns::TurnItemDist nextTurn; + if (!GetNextTurn(nextTurn.m_distMeters, nextTurn.m_turnItem)) + return false; + turns.push_back(move(nextTurn)); + return true; +} + void Route::GetCurrentDirectionPoint(m2::PointD & pt) const { if (m_routingSettings.m_keepPedestrianInfo && m_simplifiedPoly.IsValid()) diff --git a/routing/route.hpp b/routing/route.hpp index e323f8b2cc..148929aa2a 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -72,12 +72,13 @@ public: double GetCurrentDistanceToEndMeters() const; double GetMercatorDistanceFromBegin() const; - void GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const; + bool GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const; /// @return true if GetNextTurn() returns a valid result in parameters, false otherwise. /// \param distanceToTurnMeters is a distance from current possition to the second turn. /// \param turn is information about the second turn. /// \note All parameters are filled while a GetNextTurn function call. bool GetNextTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const; + bool GetNextTurns(vector & turns); void GetCurrentDirectionPoint(m2::PointD & pt) const; diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index c1fb2827b8..867bfe0ca1 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -23,10 +23,6 @@ double constexpr kShowLanesDistInMeters = 500.; // The distance before the next turn in meters when notification // about the turn after the next one will be shown if available. double constexpr kShowTheTurnAfterTheNextM = 500.; -// If the distance between two sequential turns is more than kMaxTurnDistM -// the information about the second turn will be shown when the user is -// approaching to the first one. -double constexpr kMaxTurnDistM = 400.; // @todo(kshalnev) The distance may depend on the current speed. double constexpr kShowPedestrianTurnInMeters = 5.; @@ -222,7 +218,7 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const ASSERT_LESS_OR_EQUAL(0, distBetweenTurnsM, ()); if (m_routingSettings.m_showTurnAfterNext && - distanceToTurnMeters < kShowTheTurnAfterTheNextM && distBetweenTurnsM < kMaxTurnDistM) + distanceToTurnMeters < kShowTheTurnAfterTheNextM && distBetweenTurnsM < turns::kMaxTurnDistM) { info.m_nextTurn = nextTurn.m_turn; } diff --git a/routing/turns.cpp b/routing/turns.cpp index 41761b7281..24f606f51d 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -70,6 +70,15 @@ string DebugPrint(TurnItem const & turnItem) return out.str(); } +string DebugPrint(TurnItemDist const & turnItemDist) +{ + stringstream out; + out << "TurnItemDist [ m_turnItem = " << DebugPrint(turnItemDist.m_turnItem) + << ", m_distMeters = " << turnItemDist.m_distMeters + << " ]" << endl; + return out.str(); +} + string const GetTurnString(TurnDirection turn) { for (auto const & p : g_turnNames) diff --git a/routing/turns.hpp b/routing/turns.hpp index f842303fac..a91a2123b6 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -16,6 +16,11 @@ namespace turns /// @todo(vbykoianko) It's a good idea to gather all the turns information into one entity. /// For the time being several separate entities reflect the turn information. Like Route::TTurns +// If the distance between two sequential turns is more than kMaxTurnDistM +// the information about the second turn will be shown or pronounced when the user is +// approaching to the first one. +double constexpr kMaxTurnDistM = 400.; + /*! * \warning The order of values below shall not be changed. * TurnRight(TurnLeft) must have a minimal value and @@ -152,6 +157,14 @@ struct TurnItem string DebugPrint(TurnItem const & turnItem); +struct TurnItemDist +{ + TurnItem m_turnItem; + double m_distMeters; +}; + +string DebugPrint(TurnItemDist const & turnItemDist); + string const GetTurnString(TurnDirection turn); bool IsLeftTurn(TurnDirection t); diff --git a/routing/turns_sound.cpp b/routing/turns_sound.cpp index 378b466f9e..71296b3738 100644 --- a/routing/turns_sound.cpp +++ b/routing/turns_sound.cpp @@ -1,4 +1,4 @@ -#include "routing/turns_sound.hpp" + #include "routing/turns_sound.hpp" #include "platform/location.hpp" @@ -77,7 +77,7 @@ void TurnsSound::GenerateTurnSound(TurnItem const & turn, double distanceToTurnM uint32_t const distToPronounce = m_settings.RoundByPresetSoundedDistancesUnits(turnNotificationDistUnits); string const text = GenerateTurnText(distToPronounce, turn.m_exitNum, false, turn.m_turn, - m_settings.GetLengthUnits()); + m_settings.GetLengthUnits()); if (!text.empty()) turnNotifications.emplace_back(text); // @TODO(vbykoianko) Check if there's a turn immediately after the current turn.