Review fixes

This commit is contained in:
VladiMihaylenko 2017-06-05 14:42:37 +03:00
parent 8c2a0f67ae
commit e71f055fef
4 changed files with 98 additions and 69 deletions

View file

@ -237,16 +237,7 @@ void Framework::OnLocationUpdate(GpsInfo const & info)
GpsInfo rInfo(info);
#endif
location::RouteMatchingInfo routeMatchingInfo;
m_routingManager.CheckLocationForRouting(rInfo);
m_routingManager.MatchLocationToRoute(rInfo, routeMatchingInfo);
auto & routingSession = m_routingManager.RoutingSession();
CallDrapeFunction(bind(&df::DrapeEngine::SetGpsInfo, _1, rInfo, routingSession.IsNavigable(),
routeMatchingInfo));
if (m_routingManager.IsTrackingReporterEnabled())
m_trackingReporter.AddLocation(info, routingSession.MatchTraffic(routeMatchingInfo));
m_routingManager.OnLocationUpdate(rInfo);
}
void Framework::OnCompassUpdate(CompassInfo const & info)
@ -285,10 +276,7 @@ void Framework::OnUserPositionChanged(m2::PointD const & position)
{
MyPositionMarkPoint * myPosition = UserMarkContainer::UserMarkForMyPostion();
myPosition->SetUserPosition(position);
if (m_routingManager.IsRoutingActive())
m_routingManager.RoutingSession().SetUserCurrentPosition(position);
m_routingManager.SetUserCurrentPosition(position);
m_trafficManager.UpdateMyPosition(TrafficManager::MyPosition(position));
}
@ -392,19 +380,15 @@ Framework::Framework(FrameworkParams const & params)
, m_storage(platform::migrate::NeedMigrate() ? COUNTRIES_OBSOLETE_FILE : COUNTRIES_FILE)
, m_bmManager(*this)
, m_isRenderingEnabled(true)
, m_trackingReporter(platform::CreateSocket(), TRACKING_REALTIME_HOST, TRACKING_REALTIME_PORT,
tracking::Reporter::kPushDelayMs)
, m_routingManager(RoutingManager::Callbacks([this]() -> Index & { return m_model.GetIndex(); },
bind(&Framework::GetCountryInfoGetter, this),
[this](m2::PointD const & pt) {
#ifdef DEBUG
{
UserMarkControllerGuard guard(
m_bmManager, UserMarkType::DEBUG_MARK);
guard.m_controller.SetIsVisible(true);
guard.m_controller.SetIsDrawable(true);
guard.m_controller.CreateUserMark(pt);
}
UserMarkControllerGuard guard(
m_bmManager, UserMarkType::DEBUG_MARK);
guard.m_controller.SetIsVisible(true);
guard.m_controller.SetIsDrawable(true);
guard.m_controller.CreateUserMark(pt);
#endif
}),
static_cast<RoutingManager::Delegate &>(*this))
@ -610,7 +594,7 @@ void Framework::ShowNode(storage::TCountryId const & countryId)
void Framework::OnCountryFileDownloaded(storage::TCountryId const & countryId, storage::Storage::TLocalFilePtr const localFile)
{
// Soft reset to signal that mwm file may be out of date in routing caches.
m_routingManager.RoutingSession().Reset();
m_routingManager.ResetRoutingSession();
m2::RectD rect = MercatorBounds::FullRect();
@ -631,7 +615,7 @@ void Framework::OnCountryFileDownloaded(storage::TCountryId const & countryId, s
bool Framework::OnCountryFileDelete(storage::TCountryId const & countryId, storage::Storage::TLocalFilePtr const localFile)
{
// Soft reset to signal that mwm file may be out of date in routing caches.
m_routingManager.RoutingSession().Reset();
m_routingManager.ResetRoutingSession();
if (countryId == m_lastReportedCountry)
m_lastReportedCountry = kInvalidCountryId;
@ -1385,7 +1369,7 @@ void Framework::EnterBackground()
SaveViewport();
m_trafficManager.OnEnterBackground();
m_trackingReporter.SetAllowSendingPoints(false);
m_routingManager.SetAllowSendingPoints(false);
ms::LatLon const ll = MercatorBounds::ToLatLon(GetViewportCenter());
alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())},
@ -1407,7 +1391,7 @@ void Framework::EnterForeground()
CallDrapeFunction(bind(&df::DrapeEngine::SetTimeInBackground, _1, time));
m_trafficManager.OnEnterForeground();
m_trackingReporter.SetAllowSendingPoints(true);
m_routingManager.SetAllowSendingPoints(true);
}
bool Framework::GetCurrentPosition(double & lat, double & lon) const
@ -1855,8 +1839,6 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
double const fontsScaleFactor = LoadLargeFontsSize() ? kLargeFontsScaleFactor : 1.0;
auto const & routingSession = m_routingManager.RoutingSession();
df::DrapeEngine::Params p(
params.m_apiVersion, contextFactory, make_ref(&m_stringsBundle),
dp::Viewport(0, 0, params.m_surfaceWidth, params.m_surfaceHeight),
@ -1865,8 +1847,8 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
make_pair(params.m_initialMyPositionState, params.m_hasMyPositionState),
move(myPositionModeChangedFn), allow3dBuildings, trafficEnabled,
params.m_isChoosePositionMode, params.m_isChoosePositionMode, GetSelectedFeatureTriangles(),
routingSession.IsActive() && routingSession.IsFollowing(), isAutozoomEnabled,
simplifiedTrafficColors, move(overlaysShowStatsFn));
m_routingManager.IsRoutingActive() && m_routingManager.IsRoutingFollowing(),
isAutozoomEnabled, simplifiedTrafficColors, move(overlaysShowStatsFn));
m_drapeEngine = make_unique_dp<df::DrapeEngine>(move(p));
m_drapeEngine->SetModelViewListener([this](ScreenBase const & screen)
@ -1892,14 +1874,6 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
SetVisibleViewport(m2::RectD(0, 0, params.m_surfaceWidth, params.m_surfaceHeight));
// In case of the engine reinitialization recover route.
if (routingSession.IsActive())
{
m_routingManager.InsertRoute(*routingSession.GetRoute());
if (allow3d && routingSession.IsFollowing())
m_drapeEngine->EnablePerspective();
}
if (m_connectToGpsTrack)
GpsTracker::Instance().Connect(bind(&Framework::OnUpdateGpsTrackPointsCallback, this, _1, _2));
@ -1909,7 +1883,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
});
m_drapeApi.SetEngine(make_ref(m_drapeEngine));
m_routingManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_routingManager.SetDrapeEngine(make_ref(m_drapeEngine), allow3d);
m_trafficManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_localAdsManager.SetDrapeEngine(make_ref(m_drapeEngine));
@ -2055,7 +2029,7 @@ void Framework::SetupMeasurementSystem()
auto units = measurement_utils::Units::Metric;
UNUSED_VALUE(settings::Get(settings::kMeasurementUnits, units));
m_routingManager.RoutingSession().SetTurnNotificationsUnits(units);
m_routingManager.SetTurnNotificationsUnits(units);
}
void Framework::SetWidgetLayout(gui::TWidgetsLayoutInfo && layout)
@ -3273,7 +3247,7 @@ void Framework::OnRouteFollow(routing::RouterType type)
}
// RoutingManager::Delegate
void Framework::RegisterCountryFiles(std::shared_ptr<routing::NumMwmIds> ptr) const
void Framework::RegisterCountryFilesOnRoute(std::shared_ptr<routing::NumMwmIds> ptr) const
{
m_storage.ForEachCountryFile(
[&ptr](platform::CountryFile const & file) { ptr->RegisterFile(file); });

View file

@ -183,7 +183,6 @@ protected:
df::DrapeApi m_drapeApi;
bool m_isRenderingEnabled;
tracking::Reporter m_trackingReporter;
// Note. |m_routingManager| should be declared before |m_trafficManager|
RoutingManager m_routingManager;
@ -780,7 +779,7 @@ public:
protected:
/// RoutingManager::Delegate
void OnRouteFollow(routing::RouterType type) override;
void RegisterCountryFiles(std::shared_ptr<routing::NumMwmIds> ptr) const override;
void RegisterCountryFilesOnRoute(std::shared_ptr<routing::NumMwmIds> ptr) const override;
public:
/// @name Editor interface.

View file

@ -3,6 +3,8 @@
#include "map/chart_generator.hpp"
#include "map/mwm_tree.hpp"
#include "private.h"
#include "tracking/reporter.hpp"
#include "routing/car_router.hpp"
@ -25,9 +27,12 @@
#include "platform/country_file.hpp"
#include "platform/mwm_traits.hpp"
#include "platform/platform.hpp"
#include "platform/socket.hpp"
#include "3party/Alohalytics/src/alohalytics.h"
#include <map>
namespace
{
char const kRouterTypeKey[] = "router";
@ -41,17 +46,20 @@ char const * const kRoutingCalculatingRoute = "Routing_CalculatingRoute";
using namespace routing;
RoutingManager::RoutingManager(Callbacks && callbacks, Delegate & delegate)
: m_callbacks(std::move(callbacks)), m_delegate(delegate)
: m_callbacks(std::move(callbacks))
, m_delegate(delegate)
, m_trackingReporter(platform::CreateSocket(), TRACKING_REALTIME_HOST, TRACKING_REALTIME_PORT,
tracking::Reporter::kPushDelayMs)
{
auto const routingStatisticsFn = [](map<string, string> const & statistics) {
auto const routingStatisticsFn = [](std::map<std::string, std::string> const & statistics) {
alohalytics::LogEvent("Routing_CalculatingRoute", statistics);
GetPlatform().GetMarketingService().SendMarketingEvent(marketing::kRoutingCalculatingRoute, {});
};
m_routingSession.Init(routingStatisticsFn, m_callbacks.m_visualizer);
m_routingSession.SetReadyCallbacks(
[&](Route const & route, IRouter::ResultCode code) { OnBuildRouteReady(route, code); },
[&](Route const & route, IRouter::ResultCode code) { OnRebuildRouteReady(route, code); });
[this](Route const & route, IRouter::ResultCode code) { OnBuildRouteReady(route, code); },
[this](Route const & route, IRouter::ResultCode code) { OnRebuildRouteReady(route, code); });
}
void RoutingManager::OnBuildRouteReady(Route const & route, IRouter::ResultCode code)
@ -103,7 +111,7 @@ RouterType RoutingManager::GetBestRouter(m2::PointD const & startPoint,
RouterType RoutingManager::GetLastUsedRouter() const
{
string routerTypeStr;
std::string routerTypeStr;
if (!settings::Get(kRouterTypeKey, routerTypeStr))
return RouterType::Vehicle;
@ -121,10 +129,10 @@ void RoutingManager::SetRouterImpl(routing::RouterType type)
{
auto const indexGetterFn = m_callbacks.m_featureIndexGetter;
ASSERT(indexGetterFn, ());
unique_ptr<IRouter> router;
unique_ptr<OnlineAbsentCountriesFetcher> fetcher;
std::unique_ptr<IRouter> router;
std::unique_ptr<OnlineAbsentCountriesFetcher> fetcher;
auto const countryFileGetter = [this](m2::PointD const & p) -> string {
auto const countryFileGetter = [this](m2::PointD const & p) -> std::string {
// TODO (@gorshenin): fix CountryInfoGetter to return CountryFile
// instances instead of plain strings.
return m_callbacks.m_countryInfoGetter().GetRegionCountryId(p);
@ -144,7 +152,7 @@ void RoutingManager::SetRouterImpl(routing::RouterType type)
{
auto & index = m_callbacks.m_featureIndexGetter();
auto localFileChecker = [this](string const & countryFile) -> bool {
auto localFileChecker = [this](std::string const & countryFile) -> bool {
MwmSet::MwmId const mwmId = m_callbacks.m_featureIndexGetter().GetMwmIdByCountryFile(
platform::CountryFile(countryFile));
if (!mwmId.IsAlive())
@ -155,9 +163,9 @@ void RoutingManager::SetRouterImpl(routing::RouterType type)
auto numMwmIds = make_shared<routing::NumMwmIds>();
m_delegate.RegisterCountryFiles(numMwmIds);
m_delegate.RegisterCountryFilesOnRoute(numMwmIds);
auto const getMwmRectByName = [this](string const & countryId) -> m2::RectD {
auto const getMwmRectByName = [this](std::string const & countryId) -> m2::RectD {
return m_callbacks.m_countryInfoGetter().GetLimitRectForLeaf(countryId);
};
@ -191,7 +199,7 @@ void RoutingManager::InsertRoute(routing::Route const & route)
return;
}
vector<double> turns;
std::vector<double> turns;
if (m_currentRouterType == RouterType::Vehicle || m_currentRouterType == RouterType::Bicycle ||
m_currentRouterType == RouterType::Taxi)
{
@ -252,7 +260,7 @@ void RoutingManager::SetRouteFinishPoint(m2::PointD const & pt, bool isValid)
m_drapeEngine->SetRoutePoint(pt, false /* isStart */, isValid);
}
void RoutingManager::GenerateTurnNotifications(vector<string> & turnNotifications)
void RoutingManager::GenerateTurnNotifications(std::vector<std::string> & turnNotifications)
{
if (m_currentRouterType == routing::RouterType::Taxi)
return;
@ -282,7 +290,7 @@ void RoutingManager::BuildRoute(m2::PointD const & start, m2::PointD const & fin
// Send tag to Push Woosh.
{
string tag;
std::string tag;
switch (m_currentRouterType)
{
case RouterType::Vehicle:
@ -310,6 +318,12 @@ void RoutingManager::BuildRoute(m2::PointD const & start, m2::PointD const & fin
m_routingSession.BuildRoute(start, finish, timeoutSec);
}
void RoutingManager::SetUserCurrentPosition(m2::PointD const & position)
{
if (IsRoutingActive())
m_routingSession.SetUserCurrentPosition(position);
}
bool RoutingManager::DisableFollowMode()
{
bool const disabled = m_routingSession.DisableFollowMode();
@ -355,15 +369,41 @@ void RoutingManager::MatchLocationToRoute(location::GpsInfo & location,
m_routingSession.MatchLocationToRoute(location, routeMatchingInfo);
}
void RoutingManager::OnLocationUpdate(location::GpsInfo & info)
{
location::RouteMatchingInfo routeMatchingInfo;
CheckLocationForRouting(info);
MatchLocationToRoute(info, routeMatchingInfo);
m_drapeEngine->SetGpsInfo(info, m_routingSession.IsNavigable(), routeMatchingInfo);
if (IsTrackingReporterEnabled())
m_trackingReporter.AddLocation(info, m_routingSession.MatchTraffic(routeMatchingInfo));
}
void RoutingManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAllowed)
{
m_drapeEngine = engine;
// In case of the engine reinitialization recover route.
if (IsRoutingActive())
{
InsertRoute(*m_routingSession.GetRoute());
if (is3dAllowed && m_routingSession.IsFollowing())
m_drapeEngine->EnablePerspective();
}
}
bool RoutingManager::HasRouteAltitude() const { return m_routingSession.HasRouteAltitude(); }
bool RoutingManager::GenerateRouteAltitudeChart(uint32_t width, uint32_t height,
vector<uint8_t> & imageRGBAData,
std::vector<uint8_t> & imageRGBAData,
int32_t & minRouteAltitude,
int32_t & maxRouteAltitude,
measurement_utils::Units & altitudeUnits) const
{
feature::TAltitudes altitudes;
vector<double> segDistance;
std::vector<double> segDistance;
if (!m_routingSession.GetRouteAltitudesAndDistancesM(segDistance, altitudes))
return false;

View file

@ -5,10 +5,15 @@
#include "storage/index.hpp"
#include "tracking/reporter.hpp"
#include "base/thread_checker.hpp"
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>
namespace df
{
@ -35,7 +40,7 @@ public:
{
public:
virtual void OnRouteFollow(routing::RouterType type) = 0;
virtual void RegisterCountryFiles(std::shared_ptr<routing::NumMwmIds> ptr) const = 0;
virtual void RegisterCountryFilesOnRoute(std::shared_ptr<routing::NumMwmIds> ptr) const = 0;
virtual ~Delegate() = default;
};
@ -76,9 +81,12 @@ public:
bool IsRouteNotReady() const { return m_routingSession.IsNotReady(); }
bool IsRouteFinished() const { return m_routingSession.IsFinished(); }
bool IsOnRoute() const { return m_routingSession.IsOnRoute(); }
bool IsRoutingFollowing() const { return m_routingSession.IsFollowing(); }
void BuildRoute(m2::PointD const & finish, uint32_t timeoutSec);
void BuildRoute(m2::PointD const & start, m2::PointD const & finish, bool isP2P,
uint32_t timeoutSec);
void SetUserCurrentPosition(m2::PointD const & position);
void ResetRoutingSession() { m_routingSession.Reset(); }
// FollowRoute has a bug where the router follows the route even if the method hads't been called.
// This method was added because we do not want to break the behaviour that is familiar to our
// users.
@ -124,7 +132,7 @@ public:
/// \brief Sets a locale for TTS.
/// \param locale is a string with locale code. For example "en", "ru", "zh-Hant" and so on.
/// \note See sound/tts/languages.txt for the full list of available locales.
void SetTurnNotificationsLocale(string const & locale)
void SetTurnNotificationsLocale(std::string const & locale)
{
m_routingSession.SetTurnNotificationsLocale(locale);
}
@ -132,7 +140,7 @@ public:
/// In case of error returns an empty string.
/// \note The method returns correct locale after SetTurnNotificationsLocale has been called.
/// If not, it returns an empty string.
string GetTurnNotificationsLocale() const
std::string GetTurnNotificationsLocale() const
{
return m_routingSession.GetTurnNotificationsLocale();
}
@ -144,7 +152,7 @@ public:
/// For example if C++ part wants the client to pronounce "Make a right turn." this method returns
/// an array with one string "Make a right turn.". The next call of the method returns nothing.
/// GenerateTurnNotifications shall be called by the client when a new position is available.
void GenerateTurnNotifications(vector<string> & turnNotifications);
void GenerateTurnNotifications(std::vector<std::string> & turnNotifications);
void SetRouteStartPoint(m2::PointD const & pt, bool isValid);
void SetRouteFinishPoint(m2::PointD const & pt, bool isValid);
@ -152,16 +160,19 @@ public:
void SetRouterImpl(routing::RouterType type);
void RemoveRoute(bool deactivateFollowing);
void InsertRoute(routing::Route const & route);
void CheckLocationForRouting(location::GpsInfo const & info);
void CallRouteBuilded(routing::IRouter::ResultCode code,
storage::TCountriesVec const & absentCountries);
void MatchLocationToRoute(location::GpsInfo & info,
location::RouteMatchingInfo & routeMatchingInfo) const;
void OnBuildRouteReady(routing::Route const & route, routing::IRouter::ResultCode code);
void OnRebuildRouteReady(routing::Route const & route, routing::IRouter::ResultCode code);
void OnLocationUpdate(location::GpsInfo & info);
void SetAllowSendingPoints(bool isAllowed)
{
m_trackingReporter.SetAllowSendingPoints(isAllowed);
}
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine) { m_drapeEngine = engine; };
void SetTurnNotificationsUnits(measurement_utils::Units const units) { m_routingSession.SetTurnNotificationsUnits(units); }
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAllowed);
/// \returns true if altitude information along |m_route| is available and
/// false otherwise.
bool HasRouteAltitude() const;
@ -178,11 +189,15 @@ public:
/// |imageRGBAData| is not zero.
/// \note If HasRouteAltitude() method returns true, GenerateRouteAltitudeChart(...)
/// could return false if route was deleted or rebuilt between the calls.
bool GenerateRouteAltitudeChart(uint32_t width, uint32_t height, vector<uint8_t> & imageRGBAData,
bool GenerateRouteAltitudeChart(uint32_t width, uint32_t height, std::vector<uint8_t> & imageRGBAData,
int32_t & minRouteAltitude, int32_t & maxRouteAltitude,
measurement_utils::Units & altitudeUnits) const;
private:
void InsertRoute(routing::Route const & route);
bool IsTrackingReporterEnabled() const;
void MatchLocationToRoute(location::GpsInfo & info,
location::RouteMatchingInfo & routeMatchingInfo) const;
private:
RouteBuildingCallback m_routingCallback = nullptr;
@ -192,4 +207,5 @@ private:
routing::RoutingSession m_routingSession;
DECLARE_THREAD_CHECKER(m_threadChecker);
Delegate & m_delegate;
tracking::Reporter m_trackingReporter;
};