[core][iOS][android] Isolines manager.

Conflicts:
	drape_frontend/rule_drawer.cpp
This commit is contained in:
Daria Volvenkova 2020-01-31 03:10:42 +03:00
parent 07bb5e13fb
commit b311c4ff08
20 changed files with 358 additions and 26 deletions

View file

@ -1731,13 +1731,15 @@ Java_com_mapswithme_maps_Framework_nativeIsTransitSchemeEnabled(JNIEnv * env, jc
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeSetIsolinesLayerEnabled(JNIEnv * env, jclass, jboolean enabled)
{
frm()->EnableIsolines(static_cast<bool>(enabled));
auto const isolinesEnabled = static_cast<bool>(enabled);
frm()->GetIsolinesManager().SetEnabled(isolinesEnabled);
frm()->SaveIsolonesEnabled(isolinesEnabled);
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_Framework_nativeIsIsolinesLayerEnabled(JNIEnv * env, jclass)
{
return static_cast<jboolean>(frm()->IsolinesEnabled());
return static_cast<jboolean>(frm()->LoadIsolinesEnabled());
}
JNIEXPORT void JNICALL

View file

@ -35,6 +35,7 @@ BackendRenderer::BackendRenderer(Params && params)
, m_model(params.m_model)
, m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model,
params.m_allow3dBuildings, params.m_trafficEnabled,
params.m_isolinesEnabled,
std::move(params.m_isUGCFn)))
, m_transitBuilder(make_unique_dp<TransitSchemeBuilder>(
std::bind(&BackendRenderer::FlushTransitRenderData, this, _1)))
@ -520,6 +521,16 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
MessagePriority::Normal);
break;
}
case Message::Type::EnableIsolines:
{
ref_ptr<EnableIsolinesMessage> msg = message;
m_readManager->SetIsolinesEnabled(msg->IsEnabled());
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<EnableIsolinesMessage>(msg->IsEnabled()),
MessagePriority::Normal);
break;
}
case Message::Type::DrapeApiAddLines:
{
ref_ptr<DrapeApiAddLinesMessage> msg = message;

View file

@ -44,7 +44,7 @@ public:
ref_ptr<dp::GraphicsContextFactory> factory, ref_ptr<dp::TextureManager> texMng,
MapDataProvider const & model, TUpdateCurrentCountryFn const & updateCurrentCountryFn,
ref_ptr<RequestedTiles> requestedTiles, bool allow3dBuildings, bool trafficEnabled,
bool simplifiedTrafficColors, TIsUGCFn && isUGCFn,
bool isolinesEnabled, bool simplifiedTrafficColors, TIsUGCFn && isUGCFn,
OnGraphicsContextInitialized const & onGraphicsContextInitialized)
: BaseRenderer::Params(apiVersion, commutator, factory, texMng, onGraphicsContextInitialized)
, m_model(model)
@ -52,6 +52,7 @@ public:
, m_requestedTiles(requestedTiles)
, m_allow3dBuildings(allow3dBuildings)
, m_trafficEnabled(trafficEnabled)
, m_isolinesEnabled(isolinesEnabled)
, m_simplifiedTrafficColors(simplifiedTrafficColors)
, m_isUGCFn(std::move(isUGCFn))
{}
@ -61,6 +62,7 @@ public:
ref_ptr<RequestedTiles> m_requestedTiles;
bool m_allow3dBuildings;
bool m_trafficEnabled;
bool m_isolinesEnabled;
bool m_simplifiedTrafficColors;
TIsUGCFn m_isUGCFn;
};

View file

@ -102,6 +102,7 @@ DrapeEngine::DrapeEngine(Params && params)
make_ref(m_requestedTiles),
params.m_allow3dBuildings,
params.m_trafficEnabled,
params.m_isolinesEnabled,
params.m_simplifiedTrafficColors,
std::move(params.m_isUGCFn),
params.m_onGraphicsContextInitialized);
@ -805,6 +806,13 @@ void DrapeEngine::UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos
MessagePriority::Normal);
}
void DrapeEngine::EnableIsolines(bool enable)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<EnableIsolinesMessage>(enable),
MessagePriority::Normal);
}
void DrapeEngine::SetFontScaleFactor(double scaleFactor)
{
double const kMinScaleFactor = 0.5;

View file

@ -63,6 +63,7 @@ public:
location::TMyPositionModeChanged && myPositionModeChanged,
bool allow3dBuildings,
bool trafficEnabled,
bool isolinesEnabled,
bool blockTapEvents,
bool showChoosePositionMark,
std::vector<m2::TriangleD> && boundAreaTriangles,
@ -84,6 +85,7 @@ public:
, m_myPositionModeChanged(std::move(myPositionModeChanged))
, m_allow3dBuildings(allow3dBuildings)
, m_trafficEnabled(trafficEnabled)
, m_isolinesEnabled(isolinesEnabled)
, m_blockTapEvents(blockTapEvents)
, m_showChoosePositionMark(showChoosePositionMark)
, m_boundAreaTriangles(std::move(boundAreaTriangles))
@ -107,6 +109,7 @@ public:
location::TMyPositionModeChanged m_myPositionModeChanged;
bool m_allow3dBuildings;
bool m_trafficEnabled;
bool m_isolinesEnabled;
bool m_blockTapEvents;
bool m_showChoosePositionMark;
std::vector<m2::TriangleD> m_boundAreaTriangles;
@ -222,6 +225,8 @@ public:
void ClearTransitSchemeCache(MwmSet::MwmId const & mwmId);
void ClearAllTransitSchemeCache();
void EnableIsolines(bool enable);
void SetFontScaleFactor(double scaleFactor);
void RunScenario(ScenarioManager::ScenarioData && scenarioData,

View file

@ -14,6 +14,7 @@ EngineContext::EngineContext(TileKey tileKey,
CustomFeaturesContextWeakPtr customFeaturesContext,
bool is3dBuildingsEnabled,
bool isTrafficEnabled,
bool isolinesEnabled,
int displacementMode,
TIsUGCFn const & isUGCFn)
: m_tileKey(tileKey)
@ -23,6 +24,7 @@ EngineContext::EngineContext(TileKey tileKey,
, m_customFeaturesContext(customFeaturesContext)
, m_3dBuildingsEnabled(is3dBuildingsEnabled)
, m_trafficEnabled(isTrafficEnabled)
, m_isolinesEnabled(isolinesEnabled)
, m_displacementMode(displacementMode)
, m_isUGCFn(isUGCFn)
{}

View file

@ -32,12 +32,14 @@ public:
CustomFeaturesContextWeakPtr customFeaturesContext,
bool is3dBuildingsEnabled,
bool isTrafficEnabled,
bool isolinesEnabled,
int displacementMode,
TIsUGCFn const & isUGCFn);
TileKey const & GetTileKey() const { return m_tileKey; }
bool Is3dBuildingsEnabled() const { return m_3dBuildingsEnabled; }
bool IsTrafficEnabled() const { return m_trafficEnabled; }
bool IsolinesEnabled() const { return m_isolinesEnabled; }
bool IsUGC(FeatureID const & fid) { return m_isUGCFn ? m_isUGCFn(fid) : false; }
int GetDisplacementMode() const { return m_displacementMode; }
CustomFeaturesContextWeakPtr GetCustomFeaturesContext() const { return m_customFeaturesContext; }
@ -60,6 +62,7 @@ private:
CustomFeaturesContextWeakPtr m_customFeaturesContext;
bool m_3dBuildingsEnabled;
bool m_trafficEnabled;
bool m_isolinesEnabled;
int m_displacementMode;
TIsUGCFn m_isUGCFn;
};

View file

@ -921,6 +921,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::Type::SetDisplacementMode:
case Message::Type::UpdateMetalines:
case Message::Type::EnableUGCRendering:
case Message::Type::EnableIsolines:
{
m_forceUpdateScene = true;
break;

View file

@ -101,6 +101,7 @@ std::string DebugPrint(Message::Type msgType)
case Message::Type::ShowDebugInfo: return "ShowDebugInfo";
case Message::Type::NotifyRenderThread: return "NotifyRenderThread";
case Message::Type::NotifyGraphicsReady: return "NotifyGraphicsReady";
case Message::Type::EnableIsolines: return "EnableIsolines";
}
ASSERT(false, ("Unknown message type."));
return "Unknown type";

View file

@ -102,6 +102,7 @@ public:
ShowDebugInfo,
NotifyRenderThread,
NotifyGraphicsReady,
EnableIsolines,
};
virtual ~Message() = default;

View file

@ -1118,6 +1118,21 @@ private:
bool const m_isSimplified;
};
class EnableIsolinesMessage : public Message
{
public:
explicit EnableIsolinesMessage(bool isEnabled)
: m_isEnabled(isEnabled)
{}
Type GetType() const override { return Type::EnableIsolines; }
bool IsEnabled() { return m_isEnabled; }
private:
bool m_isEnabled = false;
};
class EnableTransitSchemeMessage : public Message
{
public:

View file

@ -44,12 +44,14 @@ bool ReadManager::LessByTileInfo::operator()(std::shared_ptr<TileInfo> const & l
}
ReadManager::ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider & model,
bool allow3dBuildings, bool trafficEnabled, EngineContext::TIsUGCFn && isUGCFn)
bool allow3dBuildings, bool trafficEnabled, bool isolinesEnabled,
EngineContext::TIsUGCFn && isUGCFn)
: m_commutator(commutator)
, m_model(model)
, m_have3dBuildings(false)
, m_allow3dBuildings(allow3dBuildings)
, m_trafficEnabled(trafficEnabled)
, m_isolinesEnabled(isolinesEnabled)
, m_displacementMode(dp::displacement::kDefaultMode)
, m_modeChanged(false)
, m_ugcRenderingEnabled(false)
@ -233,11 +235,13 @@ void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey,
ref_ptr<MetalineManager> metalineMng)
{
ASSERT(m_pool != nullptr, ());
auto context = make_unique_dp<EngineContext>(TileKey(tileKey, m_generationCounter, m_userMarksGenerationCounter),
auto context = make_unique_dp<EngineContext>(TileKey(tileKey, m_generationCounter,
m_userMarksGenerationCounter),
m_commutator, texMng, metalineMng,
m_customFeaturesContext,
m_have3dBuildings && m_allow3dBuildings,
m_trafficEnabled, m_displacementMode,
m_trafficEnabled, m_isolinesEnabled,
m_displacementMode,
m_ugcRenderingEnabled ? m_isUGCFn : nullptr);
std::shared_ptr<TileInfo> tileInfo = std::make_shared<TileInfo>(std::move(context));
m_tileInfos.insert(tileInfo);
@ -331,6 +335,15 @@ void ReadManager::SetTrafficEnabled(bool trafficEnabled)
}
}
void ReadManager::SetIsolinesEnabled(bool isolinesEnabled)
{
if (m_isolinesEnabled != isolinesEnabled)
{
m_modeChanged = true;
m_isolinesEnabled = isolinesEnabled;
}
}
void ReadManager::SetDisplacementMode(int displacementMode)
{
if (m_displacementMode != displacementMode)

View file

@ -33,7 +33,8 @@ class ReadManager
{
public:
ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider & model,
bool allow3dBuildings, bool trafficEnabled, EngineContext::TIsUGCFn && isUGCFn);
bool allow3dBuildings, bool trafficEnabled, bool isolinesEnabled,
EngineContext::TIsUGCFn && isUGCFn);
void Start();
void Stop();
@ -50,6 +51,7 @@ public:
void Allow3dBuildings(bool allow3dBuildings);
void SetTrafficEnabled(bool trafficEnabled);
void SetIsolinesEnabled(bool isolinesEnabled);
void SetDisplacementMode(int displacementMode);
@ -81,6 +83,7 @@ private:
bool m_have3dBuildings;
bool m_allow3dBuildings;
bool m_trafficEnabled;
bool m_isolinesEnabled;
int m_displacementMode;
bool m_modeChanged;
bool m_ugcRenderingEnabled;

View file

@ -97,7 +97,7 @@
}
+ (BOOL)isoLinesEnabled {
return GetFramework().IsolinesEnabled();
return GetFramework().LoadIsolinesEnabled();
}
+ (void)setTrafficEnabled:(BOOL)enable {
@ -128,7 +128,10 @@
[self setTransitEnabled:false];
}
GetFramework().EnableIsolines(enable);
auto &f = GetFramework();
f.GetIsolinesManager().SetEnabled(enable);
f.SaveIsolonesEnabled(enable);
for (id<MWMMapOverlayManagerObserver> observer in [MWMMapOverlayManager manager].observers) {
if ([observer respondsToSelector:@selector(onIsoLinesStateUpdated)]) {
[observer onIsoLinesStateUpdated];

View file

@ -69,6 +69,8 @@ set(
gps_track.hpp
gps_tracker.cpp
gps_tracker.hpp
isolines_manager.cpp
isolines_manager.hpp
local_ads_manager.cpp
local_ads_manager.hpp
local_ads_mark.cpp

View file

@ -313,6 +313,11 @@ TransitReadManager & Framework::GetTransitManager()
return m_transitManager;
}
IsolinesManager & Framework::GetIsolinesManager()
{
return m_isolinesManager;
}
void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosition)
{
GetBookmarkManager().MyPositionMark().SetUserPosition(position, hasPosition);
@ -339,6 +344,7 @@ void Framework::OnViewportChanged(ScreenBase const & screen)
m_trafficManager.UpdateViewport(m_currentModelView);
m_localAdsManager.UpdateViewport(m_currentModelView);
m_transitManager.UpdateViewport(m_currentModelView);
m_isolinesManager.UpdateViewport(m_currentModelView);
if (m_viewportChangedFn != nullptr)
m_viewportChangedFn(screen);
@ -356,6 +362,8 @@ Framework::Framework(FrameworkParams const & params)
return m_featuresFetcher.ReadFeatures(fn, features);
},
bind(&Framework::GetMwmsByRect, this, _1, false /* rough */))
, m_isolinesManager(m_featuresFetcher.GetDataSource(),
bind(&Framework::GetMwmsByRect, this, _1, false /* rough */))
, m_routingManager(
RoutingManager::Callbacks(
[this]() -> DataSource & { return m_featuresFetcher.GetDataSource(); },
@ -498,6 +506,8 @@ Framework::Framework(FrameworkParams const & params)
m_trafficManager.SetSimplifiedColorScheme(LoadTrafficSimplifiedColors());
m_trafficManager.SetEnabled(LoadTrafficEnabled());
m_isolinesManager.SetEnabled(LoadIsolinesEnabled());
m_adsEngine = make_unique<ads::Engine>();
InitTransliteration();
@ -625,6 +635,7 @@ void Framework::OnCountryFileDownloaded(storage::CountryId const & countryId,
}
m_trafficManager.Invalidate();
m_transitManager.Invalidate();
m_isolinesManager.Invalidate();
m_localAdsManager.OnDownloadCountry(countryId);
InvalidateRect(rect);
GetSearchAPI().ClearCaches();
@ -662,6 +673,7 @@ void Framework::OnMapDeregistered(platform::LocalCountryFile const & localFile)
{
m_localAdsManager.OnMwmDeregistered(localFile);
m_transitManager.OnMwmDeregistered(localFile);
m_isolinesManager.OnMwmDeregistered(localFile);
m_trafficManager.OnMwmDeregistered(localFile);
m_popularityLoader.OnMwmDeregistered(localFile);
@ -1872,6 +1884,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
bool const isAutozoomEnabled = LoadAutoZoom();
bool const trafficEnabled = m_trafficManager.IsEnabled();
auto const isolinesEnabled = m_isolinesManager.IsEnabled();
bool const simplifiedTrafficColors = m_trafficManager.HasSimplifiedColorScheme();
double const fontsScaleFactor = LoadLargeFontsSize() ? kLargeFontsScaleFactor : 1.0;
@ -1882,7 +1895,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
move(isCountryLoadedByNameFn), move(updateCurrentCountryFn)),
params.m_hints, params.m_visualScale, fontsScaleFactor, move(params.m_widgetsInitInfo),
make_pair(params.m_initialMyPositionState, params.m_hasMyPositionState),
move(myPositionModeChangedFn), allow3dBuildings, trafficEnabled,
move(myPositionModeChangedFn), allow3dBuildings, trafficEnabled, isolinesEnabled,
params.m_isChoosePositionMode, params.m_isChoosePositionMode, GetSelectedFeatureTriangles(),
m_routingManager.IsRoutingActive() && m_routingManager.IsRoutingFollowing(),
isAutozoomEnabled, simplifiedTrafficColors, move(overlaysShowStatsFn), move(isUGCFn),
@ -1928,12 +1941,13 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
m_routingManager.SetDrapeEngine(make_ref(m_drapeEngine), allow3d);
m_trafficManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_transitManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_isolinesManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_localAdsManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_searchMarks.SetDrapeEngine(make_ref(m_drapeEngine));
InvalidateUserMarks();
bool const transitSchemeEnabled = LoadTransitSchemeEnabled();
auto const transitSchemeEnabled = LoadTransitSchemeEnabled();
m_transitManager.EnableTransitSchemeMode(transitSchemeEnabled);
// Show debug info if it's enabled in the config.
@ -1961,6 +1975,7 @@ void Framework::OnRecoverSurface(int width, int height, bool recreateContextDepe
m_trafficManager.OnRecoverSurface();
m_transitManager.Invalidate();
m_isolinesManager.Invalidate();
m_localAdsManager.Invalidate();
}
@ -1994,6 +2009,7 @@ void Framework::DestroyDrapeEngine()
m_routingManager.SetDrapeEngine(nullptr, false);
m_trafficManager.SetDrapeEngine(nullptr);
m_transitManager.SetDrapeEngine(nullptr);
m_isolinesManager.SetDrapeEngine(nullptr);
m_localAdsManager.SetDrapeEngine(nullptr);
m_searchMarks.SetDrapeEngine(nullptr);
GetBookmarkManager().SetDrapeEngine(nullptr);
@ -2846,13 +2862,7 @@ void Framework::SaveTransitSchemeEnabled(bool enabled)
settings::Set(kTransitSchemeEnabledKey, enabled);
}
void Framework::EnableIsolines(bool enable)
{
// TODO(darina): Implement.
settings::Set(kIsolinesEnabledKey, enable);
}
bool Framework::IsolinesEnabled() const
bool Framework::LoadIsolinesEnabled()
{
bool enabled;
if (!settings::Get(kIsolinesEnabledKey, enabled))
@ -2860,6 +2870,11 @@ bool Framework::IsolinesEnabled() const
return enabled;
}
void Framework::SaveIsolonesEnabled(bool enabled)
{
settings::Set(kIsolinesEnabledKey, enabled);
}
void Framework::EnableChoosePositionMode(bool enable, bool enableBounds, bool applyPosition,
m2::PointD const & position)
{
@ -2984,6 +2999,16 @@ bool Framework::ParseDrapeDebugCommand(string const & query)
m_transitManager.EnableTransitSchemeMode(false /* enable */);
return true;
}
if (query == "?isolines")
{
m_isolinesManager.SetEnabled(true /* enable */);
return true;
}
if (query == "?no-isolines")
{
m_isolinesManager.SetEnabled(false /* enable */);
return true;
}
if (query == "?debug-info")
{
m_drapeEngine->ShowDebugInfo(true /* shown */);

View file

@ -9,6 +9,7 @@
#include "map/discovery/discovery_manager.hpp"
#include "map/displacement_mode_manager.hpp"
#include "map/features_fetcher.hpp"
#include "map/isolines_manager.hpp"
#include "map/local_ads_manager.hpp"
#include "map/mwm_url.hpp"
#include "map/notifications/notification_manager.hpp"
@ -238,6 +239,7 @@ protected:
power_management::PowerManager m_powerManager;
TransitReadManager m_transitManager;
IsolinesManager m_isolinesManager;
// Note. |m_routingManager| should be declared before |m_trafficManager|
RoutingManager m_routingManager;
@ -759,6 +761,8 @@ public:
TransitReadManager & GetTransitManager();
IsolinesManager & GetIsolinesManager();
bool LoadTrafficEnabled();
void SaveTrafficEnabled(bool trafficEnabled);
@ -768,8 +772,8 @@ public:
bool LoadTransitSchemeEnabled();
void SaveTransitSchemeEnabled(bool enabled);
void EnableIsolines(bool enable);
bool IsolinesEnabled() const;
bool LoadIsolinesEnabled();
void SaveIsolonesEnabled(bool enabled);
dp::ApiVersion LoadPreferredGraphicsAPI();
void SavePreferredGraphicsAPI(dp::ApiVersion apiVersion);

165
map/isolines_manager.cpp Normal file
View file

@ -0,0 +1,165 @@
#include "map/isolines_manager.hpp"
// TODO: Uncomment later.
//#include "generator/isolines_info.hpp"
#include "drape_frontend/drape_engine.hpp"
#include "drape_frontend/visual_params.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
int constexpr kMinIsolinesZoom = 11;
// TODO: Update value.
int64_t constexpr kMinDataVersion = 0;
IsolinesManager::IsolinesManager(DataSource & dataSource, GetMwmsByRectFn const & getMwmsByRectFn)
: m_dataSource(dataSource)
, m_getMwmsByRectFn(getMwmsByRectFn)
{
CHECK(m_getMwmsByRectFn != nullptr, ());
}
void IsolinesManager::SetStateListener(IsolinesStateChangedFn const & onStateChangedFn)
{
m_onStateChangedFn = onStateChangedFn;
}
void IsolinesManager::ChangeState(IsolinesState newState)
{
if (m_state == newState)
return;
m_state = newState;
if (m_onStateChangedFn != nullptr)
m_onStateChangedFn(newState);
}
void IsolinesManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
{
m_drapeEngine.Set(engine);
}
void IsolinesManager::SetEnabled(bool enabled)
{
ChangeState(enabled ? IsolinesState::Enabled : IsolinesState::Disabled);
m_drapeEngine.SafeCall(&df::DrapeEngine::EnableIsolines, enabled);
if (enabled)
{
Invalidate();
}
else
{
m_lastMwms.clear();
m_mwmCache.clear();
}
}
bool IsolinesManager::IsEnabled() const
{
return m_state != IsolinesState::Disabled;
}
void IsolinesManager::UpdateViewport(ScreenBase const & screen)
{
m_currentModelView.reset(screen);
if (!IsEnabled())
return;
if (df::GetZoomLevel(screen.GetScale()) < kMinIsolinesZoom)
{
ChangeState(IsolinesState::Enabled);
return;
}
auto mwms = m_getMwmsByRectFn(screen.ClipRect());
if (m_lastMwms == mwms)
return;
m_lastMwms = std::move(mwms);
for (auto const & mwmId : m_lastMwms)
{
if (!mwmId.IsAlive())
continue;
auto it = m_mwmCache.find(mwmId);
if (it == m_mwmCache.end())
{
Availability status = Availability::NoData;
if (mwmId.GetInfo()->GetVersion() < kMinDataVersion)
{
status = Availability::ExpiredData;
}
else
{
// TODO: Uncomment later.
//isolines::IsolinesInfo info;
//if (isolines::LoadIsolinesInfo(m_dataSource, mwmId, info))
//{
// LOG(LINFO, ("Isolines min altitude", info.m_minAltitude,
// "max altitude", info.m_maxAltitude, "altitude step", info.m_altStep));
// status = Availability::Available;
//}
}
m_mwmCache.insert(std::make_pair(mwmId, status));
}
}
UpdateState();
}
void IsolinesManager::UpdateState()
{
bool available = false;
bool expired = false;
bool noData = false;
for (auto const & mwmId : m_lastMwms)
{
if (!mwmId.IsAlive())
continue;
auto const it = m_mwmCache.find(mwmId);
CHECK(it != m_mwmCache.end(), ());
switch (it->second)
{
case Availability::Available: available = true; break;
case Availability::ExpiredData: expired = true; break;
case Availability::NoData: noData = true; break;
}
}
if (expired)
ChangeState(IsolinesState::ExpiredData);
else if (!available && noData)
ChangeState(IsolinesState::NoData);
ChangeState(IsolinesState::Enabled);
}
void IsolinesManager::Invalidate()
{
if (!IsEnabled())
return;
m_lastMwms.clear();
if (m_currentModelView)
UpdateViewport(m_currentModelView.get());
}
void IsolinesManager::OnMwmDeregistered(platform::LocalCountryFile const & countryFile)
{
for (auto it = m_mwmCache.begin(); it != m_mwmCache.end(); ++it)
{
if (it->first.IsDeregistered(countryFile))
{
m_mwmCache.erase(it);
break;
}
}
}
std::string DebugPrint(IsolinesManager::IsolinesState state)
{
switch (state)
{
case IsolinesManager::IsolinesState::Disabled: return "Disabled";
case IsolinesManager::IsolinesState::Enabled: return "Enabled";
case IsolinesManager::IsolinesState::ExpiredData: return "ExpiredData";
case IsolinesManager::IsolinesState::NoData: return "NoData";
}
UNREACHABLE();
}

72
map/isolines_manager.hpp Normal file
View file

@ -0,0 +1,72 @@
#pragma once
#include "drape_frontend/drape_engine_safe_ptr.hpp"
#include "indexer/data_source.hpp"
#include "indexer/mwm_set.hpp"
#include "platform/local_country_file.hpp"
#include "geometry/rect2d.hpp"
#include "geometry/screenbase.hpp"
#include <functional>
#include <map>
#include <set>
#include <string>
#include <boost/optional.hpp>
class IsolinesManager final
{
public:
enum class IsolinesState
{
Disabled,
Enabled,
ExpiredData,
NoData
};
using IsolinesStateChangedFn = std::function<void(IsolinesState)>;
using GetMwmsByRectFn = std::function<std::vector<MwmSet::MwmId>(m2::RectD const &)>;
IsolinesManager(DataSource & dataSource, GetMwmsByRectFn const & getMwmsByRectFn);
void SetStateListener(IsolinesStateChangedFn const & onStateChangedFn);
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
void SetEnabled(bool enabled);
bool IsEnabled() const;
void UpdateViewport(ScreenBase const & screen);
void Invalidate();
void OnMwmDeregistered(platform::LocalCountryFile const & countryFile);
private:
void UpdateState();
void ChangeState(IsolinesState newState);
enum class Availability
{
Available,
NoData,
ExpiredData
};
IsolinesState m_state = IsolinesState::Disabled;
IsolinesStateChangedFn m_onStateChangedFn;
DataSource & m_dataSource;
GetMwmsByRectFn m_getMwmsByRectFn;
df::DrapeEngineSafePtr m_drapeEngine;
boost::optional<ScreenBase> m_currentModelView;
std::vector<MwmSet::MwmId> m_lastMwms;
std::map<MwmSet::MwmId, Availability> m_mwmCache;
};
std::string DebugPrint(IsolinesManager::IsolinesState state);

View file

@ -92,13 +92,7 @@ void TrafficManager::SetEnabled(bool enabled)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (enabled == IsEnabled())
{
LOG(LWARNING, ("Invalid attempt to", enabled ? "enable" : "disable",
"traffic manager, it's already", enabled ? "enabled" : "disabled",
", doing nothing."));
return;
}
Clear();
ChangeState(enabled ? TrafficState::Enabled : TrafficState::Disabled);
}