Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map/bookmark.cpp30
-rw-r--r--map/bookmark.hpp6
-rw-r--r--map/bookmark_manager.cpp133
-rw-r--r--map/bookmark_manager.hpp54
-rw-r--r--map/framework.cpp21
-rw-r--r--map/map_tests/bookmarks_test.cpp31
-rw-r--r--map/map_tests/kmz_unarchive_test.cpp3
-rw-r--r--map/routing_manager.cpp15
-rw-r--r--map/user_mark.cpp3
-rw-r--r--map/user_mark_container.cpp55
-rw-r--r--map/user_mark_container.hpp39
-rw-r--r--qt/draw_widget.cpp2
12 files changed, 212 insertions, 180 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp
index 026b5385b8..534175fb66 100644
--- a/map/bookmark.cpp
+++ b/map/bookmark.cpp
@@ -1,8 +1,7 @@
#include "map/bookmark.hpp"
+#include "map/api_mark_point.hpp"
#include "map/track.hpp"
-#include "map/framework.hpp"
-
#include "base/scope_guard.hpp"
#include "geometry/mercator.hpp"
@@ -30,14 +29,12 @@
Bookmark::Bookmark(m2::PointD const & ptOrg, UserMarkContainer * container)
: TBase(ptOrg, container)
-{
-}
+{}
Bookmark::Bookmark(BookmarkData const & data, m2::PointD const & ptOrg, UserMarkContainer * container)
: TBase(ptOrg, container)
, m_data(data)
-{
-}
+{}
void Bookmark::SetData(BookmarkData const & data)
{
@@ -138,11 +135,10 @@ Track const * BookmarkCategory::GetTrack(size_t index) const
return (index < m_tracks.size() ? m_tracks[index].get() : 0);
}
-BookmarkCategory::BookmarkCategory(std::string const & name, Framework & framework)
- : TBase(0.0 /* bookmarkDepth */, UserMark::Type::BOOKMARK, framework)
+BookmarkCategory::BookmarkCategory(std::string const & name)
+ : TBase(0.0 /* bookmarkDepth */, UserMark::Type::BOOKMARK)
, m_name(name)
-{
-}
+{}
BookmarkCategory::~BookmarkCategory()
{
@@ -565,21 +561,21 @@ bool BookmarkCategory::LoadFromKML(ReaderPtr<Reader> const & reader)
{
ReaderSource<ReaderPtr<Reader> > src(reader);
KMLParser parser(*this);
- if (ParseXML(src, parser, true))
- return true;
- else
+ if (!ParseXML(src, parser, true))
{
LOG(LERROR, ("XML read error. Probably, incorrect file encoding."));
return false;
}
+ return true;
}
-BookmarkCategory * BookmarkCategory::CreateFromKMLFile(std::string const & file, Framework & framework)
+// static
+std::unique_ptr<BookmarkCategory> BookmarkCategory::CreateFromKMLFile(std::string const & file)
{
- std::auto_ptr<BookmarkCategory> cat(new BookmarkCategory("", framework));
+ auto cat = my::make_unique<BookmarkCategory>("");
try
{
- if (cat->LoadFromKML(make_unique<FileReader>(file)))
+ if (cat->LoadFromKML(my::make_unique<FileReader>(file)))
cat->m_file = file;
else
cat.reset();
@@ -590,7 +586,7 @@ BookmarkCategory * BookmarkCategory::CreateFromKMLFile(std::string const & file,
cat.reset();
}
- return cat.release();
+ return cat;
}
namespace
diff --git a/map/bookmark.hpp b/map/bookmark.hpp
index 630251e4e9..b0490abf89 100644
--- a/map/bookmark.hpp
+++ b/map/bookmark.hpp
@@ -118,7 +118,7 @@ class BookmarkCategory : public UserMarkContainer
std::string m_file;
public:
- BookmarkCategory(std::string const & name, Framework & framework);
+ explicit BookmarkCategory(std::string const & name);
~BookmarkCategory() override;
size_t GetUserLineCount() const override;
@@ -150,8 +150,8 @@ public:
/// creates unique file name on first save and uses it every time.
bool SaveToKMLFile();
- /// @return 0 in the case of error
- static BookmarkCategory * CreateFromKMLFile(std::string const & file, Framework & framework);
+ /// @return nullptr in the case of error
+ static std::unique_ptr<BookmarkCategory> CreateFromKMLFile(std::string const & file);
/// Get valid file name from input (remove illegal symbols).
static std::string RemoveInvalidSymbols(std::string const & name);
diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp
index 4ea87292d9..fa44dc2c1d 100644
--- a/map/bookmark_manager.cpp
+++ b/map/bookmark_manager.cpp
@@ -1,14 +1,20 @@
#include "map/bookmark_manager.hpp"
-#include "map/framework.hpp"
+#include "map/api_mark_point.hpp"
#include "map/local_ads_mark.hpp"
#include "map/routing_mark.hpp"
+#include "map/search_mark.hpp"
#include "map/user_mark.hpp"
+#include "drape_frontend/drape_engine.hpp"
+#include "drape_frontend/visual_params.hpp"
+
#include "platform/platform.hpp"
#include "platform/settings.hpp"
#include "indexer/scales.hpp"
+#include "coding/file_writer.hpp"
+
#include "geometry/transformations.hpp"
#include "base/macros.hpp"
@@ -18,25 +24,35 @@
#include <algorithm>
+namespace
+{
+char const * BOOKMARK_CATEGORY = "LastBookmarkCategory";
+char const * BOOKMARK_TYPE = "LastBookmarkType";
+
using SearchUserMarkContainer = SpecifiedUserMarkContainer<SearchMarkPoint, UserMark::Type::SEARCH>;
using ApiUserMarkContainer = SpecifiedUserMarkContainer<ApiMarkPoint, UserMark::Type::API>;
using DebugUserMarkContainer = SpecifiedUserMarkContainer<DebugMarkPoint, UserMark::Type::DEBUG_MARK>;
using RouteUserMarkContainer = SpecifiedUserMarkContainer<RouteMarkPoint, UserMark::Type::ROUTING>;
using LocalAdsMarkContainer = SpecifiedUserMarkContainer<LocalAdsMark, UserMark::Type::LOCAL_ADS>;
using StaticUserMarkContainer = SpecifiedUserMarkContainer<SearchMarkPoint, UserMark::Type::STATIC>;
+} // namespace
-BookmarkManager::BookmarkManager(Framework & f)
- : m_framework(f)
+BookmarkManager::BookmarkManager(GetStringsBundleFn && getStringsBundleFn)
+ : m_getStringsBundle(std::move(getStringsBundleFn))
{
+ ASSERT(m_getStringsBundle != nullptr, ());
+
m_userMarkLayers.reserve(6);
- m_userMarkLayers.emplace_back(my::make_unique<SearchUserMarkContainer>(m_framework));
- m_userMarkLayers.emplace_back(my::make_unique<ApiUserMarkContainer>(m_framework));
- m_userMarkLayers.emplace_back(my::make_unique<DebugUserMarkContainer>(m_framework));
- m_userMarkLayers.emplace_back(my::make_unique<RouteUserMarkContainer>(m_framework));
- m_userMarkLayers.emplace_back(my::make_unique<LocalAdsMarkContainer>(m_framework));
-
- auto staticMarksContainer = my::make_unique<StaticUserMarkContainer>(m_framework);
- UserMarkContainer::InitStaticMarks(staticMarksContainer.get());
+ m_userMarkLayers.emplace_back(my::make_unique<SearchUserMarkContainer>());
+ m_userMarkLayers.emplace_back(my::make_unique<ApiUserMarkContainer>());
+ m_userMarkLayers.emplace_back(my::make_unique<DebugUserMarkContainer>());
+ m_userMarkLayers.emplace_back(my::make_unique<RouteUserMarkContainer>());
+ m_userMarkLayers.emplace_back(my::make_unique<LocalAdsMarkContainer>());
+
+ auto staticMarksContainer = my::make_unique<StaticUserMarkContainer>();
+ m_selectionMark = my::make_unique<StaticMarkPoint>(staticMarksContainer.get());
+ m_myPositionMark = my::make_unique<MyPositionMarkPoint>(staticMarksContainer.get());
+
m_userMarkLayers.emplace_back(std::move(staticMarksContainer));
}
@@ -47,10 +63,20 @@ BookmarkManager::~BookmarkManager()
ClearCategories();
}
-namespace
+void BookmarkManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
{
-char const * BOOKMARK_CATEGORY = "LastBookmarkCategory";
-char const * BOOKMARK_TYPE = "LastBookmarkType";
+ m_drapeEngine.Set(engine);
+
+ for (auto & userMarkLayer : m_userMarkLayers)
+ userMarkLayer->SetDrapeEngine(engine);
+
+ for (auto & category : m_categories)
+ category->SetDrapeEngine(engine);
+}
+
+void BookmarkManager::UpdateViewport(ScreenBase const & screen)
+{
+ m_viewport = screen;
}
void BookmarkManager::SaveState() const
@@ -74,21 +100,27 @@ void BookmarkManager::LoadBookmarks()
{
ClearCategories();
- string const dir = GetPlatform().SettingsDir();
+ std::string const dir = GetPlatform().SettingsDir();
Platform::FilesList files;
Platform::GetFilesByExt(dir, BOOKMARKS_FILE_EXTENSION, files);
- for (size_t i = 0; i < files.size(); ++i)
- LoadBookmark(dir + files[i]);
+ for (auto const & file : files)
+ LoadBookmark(dir + file);
LoadState();
}
-void BookmarkManager::LoadBookmark(string const & filePath)
+void BookmarkManager::LoadBookmark(std::string const & filePath)
{
- std::unique_ptr<BookmarkCategory> cat(BookmarkCategory::CreateFromKMLFile(filePath, m_framework));
- if (cat)
+ auto cat = BookmarkCategory::CreateFromKMLFile(filePath);
+ if (cat != nullptr)
+ {
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (lock)
+ cat->SetDrapeEngine(lock.Get());
+
m_categories.emplace_back(std::move(cat));
+ }
}
void BookmarkManager::InitBookmarks()
@@ -100,11 +132,11 @@ void BookmarkManager::InitBookmarks()
size_t BookmarkManager::AddBookmark(size_t categoryIndex, m2::PointD const & ptOrg, BookmarkData & bm)
{
bm.SetTimeStamp(time(0));
- bm.SetScale(m_framework.GetDrawScale());
+ bm.SetScale(df::GetDrawTileScale(m_viewport));
BookmarkCategory & cat = *m_categories[categoryIndex];
- Bookmark * bookmark = static_cast<Bookmark *>(cat.CreateUserMark(ptOrg));
+ auto bookmark = static_cast<Bookmark *>(cat.CreateUserMark(ptOrg));
bookmark->SetData(bm);
cat.SetIsVisible(true);
cat.SaveToKMLFile();
@@ -123,8 +155,8 @@ size_t BookmarkManager::MoveBookmark(size_t bmIndex, size_t curCatIndex, size_t
BookmarkData data;
m2::PointD ptOrg;
- BookmarkCategory * cat = m_framework.GetBmCategory(curCatIndex);
- Bookmark const * bm = static_cast<Bookmark const *>(cat->GetUserMark(bmIndex));
+ BookmarkCategory * cat = GetBmCategory(curCatIndex);
+ auto bm = static_cast<Bookmark const *>(cat->GetUserMark(bmIndex));
data = bm->GetData();
ptOrg = bm->GetPivot();
@@ -155,7 +187,7 @@ size_t BookmarkManager::LastEditedBMCategory()
}
if (m_categories.empty())
- CreateBmCategory(m_framework.GetStringsBundle().GetString("my_places"));
+ CreateBmCategory(m_getStringsBundle().GetString("my_places"));
return 0;
}
@@ -172,7 +204,11 @@ BookmarkCategory * BookmarkManager::GetBmCategory(size_t index) const
size_t BookmarkManager::CreateBmCategory(std::string const & name)
{
- m_categories.emplace_back(new BookmarkCategory(name, m_framework));
+ m_categories.emplace_back(new BookmarkCategory(name));
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (lock)
+ m_categories.back()->SetDrapeEngine(lock.Get());
+
return (m_categories.size() - 1);
}
@@ -186,13 +222,11 @@ void BookmarkManager::DeleteBmCategory(CategoryIter it)
bool BookmarkManager::DeleteBmCategory(size_t index)
{
- if (index < m_categories.size())
- {
- DeleteBmCategory(m_categories.begin() + index);
- return true;
- }
- else
+ if (index >= m_categories.size())
return false;
+
+ DeleteBmCategory(m_categories.begin() + index);
+ return true;
}
namespace
@@ -258,8 +292,8 @@ UserMarksController & BookmarkManager::GetUserMarksController(UserMark::Type typ
UserMarkContainer const * BookmarkManager::FindUserMarksContainer(UserMark::Type type) const
{
- auto const iter = find_if(m_userMarkLayers.begin(), m_userMarkLayers.end(),
- [&type](unique_ptr<UserMarkContainer> const & cont)
+ auto const iter = std::find_if(m_userMarkLayers.begin(), m_userMarkLayers.end(),
+ [&type](std::unique_ptr<UserMarkContainer> const & cont)
{
return cont->GetType() == type;
});
@@ -269,8 +303,8 @@ UserMarkContainer const * BookmarkManager::FindUserMarksContainer(UserMark::Type
UserMarkContainer * BookmarkManager::FindUserMarksContainer(UserMark::Type type)
{
- auto iter = find_if(m_userMarkLayers.begin(), m_userMarkLayers.end(),
- [&type](unique_ptr<UserMarkContainer> const & cont)
+ auto iter = std::find_if(m_userMarkLayers.begin(), m_userMarkLayers.end(),
+ [&type](std::unique_ptr<UserMarkContainer> const & cont)
{
return cont->GetType() == type;
});
@@ -278,11 +312,34 @@ UserMarkContainer * BookmarkManager::FindUserMarksContainer(UserMark::Type type)
return iter->get();
}
-UserMarkNotificationGuard::UserMarkNotificationGuard(BookmarkManager & mng, UserMark::Type type)
- : m_controller(mng.GetUserMarksController(type))
+std::unique_ptr<StaticMarkPoint> & BookmarkManager::SelectionMark()
+{
+ ASSERT(m_selectionMark != nullptr, ());
+ return m_selectionMark;
+}
+
+std::unique_ptr<MyPositionMarkPoint> & BookmarkManager::MyPositionMark()
+{
+ ASSERT(m_myPositionMark != nullptr, ());
+ return m_myPositionMark;
+}
+
+std::unique_ptr<StaticMarkPoint> const & BookmarkManager::SelectionMark() const
+{
+ ASSERT(m_selectionMark != nullptr, ());
+ return m_selectionMark;
+}
+
+std::unique_ptr<MyPositionMarkPoint> const & BookmarkManager::MyPositionMark() const
{
+ ASSERT(m_myPositionMark != nullptr, ());
+ return m_myPositionMark;
}
+UserMarkNotificationGuard::UserMarkNotificationGuard(BookmarkManager & mng, UserMark::Type type)
+ : m_controller(mng.GetUserMarksController(type))
+{}
+
UserMarkNotificationGuard::~UserMarkNotificationGuard()
{
m_controller.NotifyChanges();
diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp
index bf92ea97a6..95c5134198 100644
--- a/map/bookmark_manager.hpp
+++ b/map/bookmark_manager.hpp
@@ -3,44 +3,39 @@
#include "map/bookmark.hpp"
#include "map/user_mark_container.hpp"
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
+
#include "geometry/any_rect2d.hpp"
+#include "geometry/screenbase.hpp"
+
+#include "base/macros.hpp"
+#include "base/strings_bundle.hpp"
#include <functional>
#include <memory>
#include <string>
#include <vector>
-class Framework;
-class PaintEvent;
-
-class BookmarkManager : private noncopyable
+class BookmarkManager final
{
using CategoriesCollection = std::vector<std::unique_ptr<BookmarkCategory>>;
using CategoryIter = CategoriesCollection::iterator;
using UserMarkLayers = std::vector<std::unique_ptr<UserMarkContainer>>;
-
- CategoriesCollection m_categories;
-
- std::string m_lastCategoryUrl;
- std::string m_lastType;
-
- Framework & m_framework;
-
- UserMarkLayers m_userMarkLayers;
-
- void SaveState() const;
- void LoadState();
+ using GetStringsBundleFn = std::function<StringsBundle const &()>;
public:
- BookmarkManager(Framework & f);
+ explicit BookmarkManager(GetStringsBundleFn && getStringsBundleFn);
~BookmarkManager();
+ void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
+ void UpdateViewport(ScreenBase const & screen);
+
void ClearCategories();
/// Scans and loads all kml files with bookmarks in WritableDir.
void LoadBookmarks();
- void LoadBookmark(string const & filePath);
+ void LoadBookmark(std::string const & filePath);
void InitBookmarks();
@@ -74,9 +69,32 @@ public:
bool UserMarksIsVisible(UserMark::Type type) const;
UserMarksController & GetUserMarksController(UserMark::Type type);
+ std::unique_ptr<StaticMarkPoint> & SelectionMark();
+ std::unique_ptr<StaticMarkPoint> const & SelectionMark() const;
+ std::unique_ptr<MyPositionMarkPoint> & MyPositionMark();
+ std::unique_ptr<MyPositionMarkPoint> const & MyPositionMark() const;
+
private:
UserMarkContainer const * FindUserMarksContainer(UserMark::Type type) const;
UserMarkContainer * FindUserMarksContainer(UserMark::Type type);
+
+ void SaveState() const;
+ void LoadState();
+
+ GetStringsBundleFn m_getStringsBundle;
+ df::DrapeEngineSafePtr m_drapeEngine;
+
+ ScreenBase m_viewport;
+
+ CategoriesCollection m_categories;
+ std::string m_lastCategoryUrl;
+ std::string m_lastType;
+ UserMarkLayers m_userMarkLayers;
+
+ std::unique_ptr<StaticMarkPoint> m_selectionMark;
+ std::unique_ptr<MyPositionMarkPoint> m_myPositionMark;
+
+ DISALLOW_COPY_AND_MOVE(BookmarkManager);
};
class UserMarkNotificationGuard
diff --git a/map/framework.cpp b/map/framework.cpp
index 4db417be31..c22e7ac934 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -267,8 +267,7 @@ LocalAdsManager & Framework::GetLocalAdsManager()
void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosition)
{
- MyPositionMarkPoint * myPosition = UserMarkContainer::UserMarkForMyPostion();
- myPosition->SetUserPosition(position, hasPosition);
+ m_bmManager.MyPositionMark()->SetUserPosition(position, hasPosition);
m_routingManager.SetUserCurrentPosition(position);
m_trafficManager.UpdateMyPosition(TrafficManager::MyPosition(position));
}
@@ -279,6 +278,7 @@ void Framework::OnViewportChanged(ScreenBase const & screen)
GetSearchAPI().OnViewportChanged(GetCurrentViewport());
+ m_bmManager.UpdateViewport(m_currentModelView);
m_trafficManager.UpdateViewport(m_currentModelView);
m_localAdsManager.UpdateViewport(m_currentModelView);
@@ -360,7 +360,7 @@ void Framework::Migrate(bool keepDownloaded)
Framework::Framework(FrameworkParams const & params)
: m_startForegroundTime(0.0)
, m_storage(platform::migrate::NeedMigrate() ? COUNTRIES_OBSOLETE_FILE : COUNTRIES_FILE)
- , m_bmManager(*this)
+ , m_bmManager([this]() -> StringsBundle const & { return m_stringsBundle; })
, m_isRenderingEnabled(true)
, m_routingManager(RoutingManager::Callbacks([this]() -> Index & { return m_model.GetIndex(); },
[this]() -> storage::CountryInfoGetter & { return GetCountryInfoGetter(); },
@@ -1526,7 +1526,7 @@ void Framework::SelectSearchResult(search::Result const & result, bool animation
if (m_drapeEngine != nullptr)
m_drapeEngine->SetModelViewCenter(center, scale, animation, true /* trackVisibleViewport */);
- UserMarkContainer::UserMarkForPoi()->SetPtOrg(center);
+ m_bmManager.SelectionMark()->SetPtOrg(center);
ActivateMapSelection(false, df::SelectionShape::OBJECT_POI, info);
m_lastTapEvent = MakeTapEvent(center, info.GetID(), TapEvent::Source::Search);
}
@@ -1787,8 +1787,6 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
OnSize(params.m_surfaceWidth, params.m_surfaceHeight);
- InvalidateUserMarks();
-
Allow3dMode(allow3d, allow3dBuildings);
LoadViewport();
@@ -1797,12 +1795,15 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
if (m_connectToGpsTrack)
GpsTracker::Instance().Connect(bind(&Framework::OnUpdateGpsTrackPointsCallback, this, _1, _2));
+ m_bmManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_drapeApi.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));
m_searchMarks.SetDrapeEngine(make_ref(m_drapeEngine));
+ InvalidateUserMarks();
+
benchmark::RunGraphicsBenchmark(this);
}
@@ -1842,6 +1843,7 @@ void Framework::DestroyDrapeEngine()
m_trafficManager.SetDrapeEngine(nullptr);
m_localAdsManager.SetDrapeEngine(nullptr);
m_searchMarks.SetDrapeEngine(nullptr);
+ m_bmManager.SetDrapeEngine(nullptr);
m_trafficManager.Teardown();
m_localAdsManager.Teardown();
@@ -2026,7 +2028,7 @@ bool Framework::ShowMapForURL(string const & url)
}
else
{
- UserMarkContainer::UserMarkForPoi()->SetPtOrg(point);
+ m_bmManager.SelectionMark()->SetPtOrg(point);
FillPointInfo(point, name, info);
ActivateMapSelection(false, df::SelectionShape::OBJECT_POI, info);
}
@@ -2360,7 +2362,7 @@ df::SelectionShape::ESelectedObject Framework::OnTapEventImpl(TapEvent const & t
if (showMapSelection)
{
- UserMarkContainer::UserMarkForPoi()->SetPtOrg(outInfo.GetMercator());
+ m_bmManager.SelectionMark()->SetPtOrg(outInfo.GetMercator());
return df::SelectionShape::OBJECT_POI;
}
@@ -3145,8 +3147,7 @@ void Framework::ClearViewportSearchResults()
boost::optional<m2::PointD> Framework::GetCurrentPosition() const
{
- m2::PointD position;
- MyPositionMarkPoint * myPosMark = UserMarkContainer::UserMarkForMyPostion();
+ auto const & myPosMark = m_bmManager.MyPositionMark();
if (!myPosMark->HasPosition())
return {};
return myPosMark->GetPivot();
diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp
index 0332a63cd5..b9a55784fd 100644
--- a/map/map_tests/bookmarks_test.cpp
+++ b/map/map_tests/bookmarks_test.cpp
@@ -157,10 +157,7 @@ char const * kmlString =
UNIT_TEST(Bookmarks_ImportKML)
{
- Framework framework(kFrameworkParams);
- df::VisualParams::Init(1.0, 1024);
-
- BookmarkCategory cat("Default", framework);
+ BookmarkCategory cat("Default");
TEST(cat.LoadFromKML(make_unique<MemReader>(kmlString, strlen(kmlString))), ());
CheckBookmarks(cat);
@@ -174,10 +171,7 @@ UNIT_TEST(Bookmarks_ExportKML)
{
char const * BOOKMARKS_FILE_NAME = "UnitTestBookmarks.kml";
- Framework framework(kFrameworkParams);
- df::VisualParams::Init(1.0, 1024);
-
- BookmarkCategory cat("Default", framework);
+ BookmarkCategory cat("Default");
TEST(cat.LoadFromKML(make_unique<MemReader>(kmlString, strlen(kmlString))), ());
CheckBookmarks(cat);
@@ -197,7 +191,7 @@ UNIT_TEST(Bookmarks_ExportKML)
CheckBookmarks(cat);
TEST_EQUAL(cat.IsVisible(), true, ());
- unique_ptr<BookmarkCategory> cat2(BookmarkCategory::CreateFromKMLFile(BOOKMARKS_FILE_NAME, framework));
+ auto cat2 = BookmarkCategory::CreateFromKMLFile(BOOKMARKS_FILE_NAME);
CheckBookmarks(*cat2);
TEST(cat2->SaveToKMLFile(), ());
@@ -207,7 +201,7 @@ UNIT_TEST(Bookmarks_ExportKML)
// MapName is the <name> tag in test kml data.
string const catFileName = GetPlatform().SettingsDir() + "MapName.kml";
- cat2.reset(BookmarkCategory::CreateFromKMLFile(catFileName, framework));
+ cat2 = BookmarkCategory::CreateFromKMLFile(catFileName);
CheckBookmarks(*cat2);
TEST(my::DeleteFileX(catFileName), ());
}
@@ -542,8 +536,7 @@ char const * kmlString2 =
UNIT_TEST(Bookmarks_InnerFolder)
{
- Framework framework(kFrameworkParams);
- BookmarkCategory cat("Default", framework);
+ BookmarkCategory cat("Default");
TEST(cat.LoadFromKML(make_unique<MemReader>(kmlString2, strlen(kmlString2))), ());
TEST_EQUAL(cat.GetUserMarkCount(), 1, ());
@@ -551,8 +544,7 @@ UNIT_TEST(Bookmarks_InnerFolder)
UNIT_TEST(BookmarkCategory_EmptyName)
{
- Framework framework(kFrameworkParams);
- unique_ptr<BookmarkCategory> pCat(new BookmarkCategory("", framework));
+ unique_ptr<BookmarkCategory> pCat(new BookmarkCategory(""));
static_cast<Bookmark *>(pCat->CreateUserMark(m2::PointD(0, 0)))->SetData(BookmarkData("", "placemark-red"));
TEST(pCat->SaveToKMLFile(), ());
@@ -601,14 +593,13 @@ char const * kmlString3 =
UNIT_TEST(Bookmarks_SpecialXMLNames)
{
- Framework framework(kFrameworkParams);
- BookmarkCategory cat1("", framework);
+ BookmarkCategory cat1("");
TEST(cat1.LoadFromKML(make_unique<MemReader>(kmlString3, strlen(kmlString3))), ());
TEST_EQUAL(cat1.GetUserMarkCount(), 1, ());
TEST(cat1.SaveToKMLFile(), ());
- unique_ptr<BookmarkCategory> const cat2(BookmarkCategory::CreateFromKMLFile(cat1.GetFileName(), framework));
+ unique_ptr<BookmarkCategory> const cat2(BookmarkCategory::CreateFromKMLFile(cat1.GetFileName()));
TEST(cat2.get(), ());
TEST_EQUAL(cat2->GetUserMarkCount(), 1, ());
@@ -625,9 +616,8 @@ UNIT_TEST(Bookmarks_SpecialXMLNames)
UNIT_TEST(TrackParsingTest_1)
{
- Framework framework(kFrameworkParams);
string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-kml.test");
- BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(kmlFile, framework);
+ auto cat = BookmarkCategory::CreateFromKMLFile(kmlFile);
TEST(cat, ("Category can't be created"));
TEST_EQUAL(cat->GetTracksCount(), 4, ());
@@ -651,9 +641,8 @@ UNIT_TEST(TrackParsingTest_1)
UNIT_TEST(TrackParsingTest_2)
{
- Framework framework(kFrameworkParams);
string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-from-google-earth.test");
- BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(kmlFile, framework);
+ auto cat = BookmarkCategory::CreateFromKMLFile(kmlFile);
TEST(cat, ("Category can't be created"));
TEST_EQUAL(cat->GetTracksCount(), 1, ());
diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp
index 4aaa3a83ed..85c4cbcdb3 100644
--- a/map/map_tests/kmz_unarchive_test.cpp
+++ b/map/map_tests/kmz_unarchive_test.cpp
@@ -35,8 +35,7 @@ UNIT_TEST(KMZ_UnzipTest)
MY_SCOPE_GUARD(fileGuard, bind(&FileWriter::DeleteFileX, kmlFile));
ZipFileReader::UnzipFile(kmzFile, "doc.kml", kmlFile);
- Framework framework(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */));
- BookmarkCategory cat("Default", framework);
+ BookmarkCategory cat("Default");
TEST(cat.LoadFromKML(make_unique<FileReader>(kmlFile)), ());
TEST_EQUAL(files.size(), 6, ("KMZ file wrong number of files"));
diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp
index ebbcc4c95f..b60f768298 100644
--- a/map/routing_manager.cpp
+++ b/map/routing_manager.cpp
@@ -100,7 +100,7 @@ void FillTransitStyleForRendering(vector<RouteSegment> const & segments,
}
}
-RouteMarkData GetLastPassedPoint(vector<RouteMarkData> const & points)
+RouteMarkData GetLastPassedPoint(BookmarkManager * bmManager, vector<RouteMarkData> const & points)
{
ASSERT_GREATER_OR_EQUAL(points.size(), 2, ());
ASSERT(points[0].m_pointType == RouteMarkType::Start, ());
@@ -120,8 +120,7 @@ RouteMarkData GetLastPassedPoint(vector<RouteMarkData> const & points)
data.m_intermediateIndex = 0;
if (data.m_isMyPosition)
{
- MyPositionMarkPoint * myPosMark = UserMarkContainer::UserMarkForMyPostion();
- data.m_position = myPosMark->GetPivot();
+ data.m_position = bmManager->MyPositionMark()->GetPivot();
data.m_isMyPosition = false;
}
@@ -156,14 +155,14 @@ RouteMarkData DeserializeRoutePoint(json_t * node)
return data;
}
-string SerializeRoutePoints(vector<RouteMarkData> const & points)
+string SerializeRoutePoints(BookmarkManager * bmManager, vector<RouteMarkData> const & points)
{
ASSERT_GREATER_OR_EQUAL(points.size(), 2, ());
auto pointsNode = my::NewJSONArray();
// Save last passed point. It will be used on points loading if my position
// isn't determined.
- auto lastPassedPoint = GetLastPassedPoint(points);
+ auto lastPassedPoint = GetLastPassedPoint(bmManager, points);
auto lastPassedNode = my::NewJSONObject();
SerializeRoutePoint(lastPassedNode.get(), lastPassedPoint);
json_array_append_new(pointsNode.get(), lastPassedNode.release());
@@ -761,7 +760,7 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec)
if (!p.m_isMyPosition)
continue;
- MyPositionMarkPoint * myPosition = UserMarkContainer::UserMarkForMyPostion();
+ auto const & myPosition = m_bmManager->MyPositionMark();
if (!myPosition->HasPosition())
{
CallRouteBuilded(IRouter::NoCurrentPosition, storage::TCountriesVec());
@@ -1104,7 +1103,7 @@ bool RoutingManager::LoadRoutePoints()
return false;
// If we have found my position, we use my position as start point.
- MyPositionMarkPoint * myPosMark = UserMarkContainer::UserMarkForMyPostion();
+ auto const & myPosMark = m_bmManager->MyPositionMark();
ASSERT(m_bmManager != nullptr, ());
m_bmManager->GetUserMarksController(UserMark::Type::ROUTING).Clear();
for (auto & p : points)
@@ -1144,7 +1143,7 @@ void RoutingManager::SaveRoutePoints() const
{
auto const fileName = GetPlatform().SettingsPathForFile(kRoutePointsFile);
FileWriter writer(fileName);
- string const pointsData = SerializeRoutePoints(points);
+ string const pointsData = SerializeRoutePoints(m_bmManager, points);
writer.Write(pointsData.c_str(), pointsData.length());
}
catch (RootException const & ex)
diff --git a/map/user_mark.cpp b/map/user_mark.cpp
index 0ce33a84ec..a5eff5c297 100644
--- a/map/user_mark.cpp
+++ b/map/user_mark.cpp
@@ -9,8 +9,7 @@
UserMark::UserMark(m2::PointD const & ptOrg, UserMarkContainer * container)
: m_ptOrg(ptOrg), m_container(container)
-{
-}
+{}
m2::PointD const & UserMark::GetPivot() const
{
diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp
index e7224ce4c3..2bc5ce429c 100644
--- a/map/user_mark_container.cpp
+++ b/map/user_mark_container.cpp
@@ -1,5 +1,4 @@
#include "map/user_mark_container.hpp"
-#include "map/framework.hpp"
#include "map/search_mark.hpp"
#include "drape_frontend/drape_engine.hpp"
@@ -9,7 +8,8 @@
#include "base/scope_guard.hpp"
#include "base/stl_add.hpp"
-#include "std/algorithm.hpp"
+#include <algorithm>
+#include <utility>
namespace
{
@@ -53,9 +53,8 @@ df::MarkGroupID GenerateMarkGroupId(UserMarkContainer const * cont)
}
} // namespace
-UserMarkContainer::UserMarkContainer(double layerDepth, UserMark::Type type, Framework & fm)
- : m_framework(fm)
- , m_layerDepth(layerDepth)
+UserMarkContainer::UserMarkContainer(double layerDepth, UserMark::Type type)
+ : m_layerDepth(layerDepth)
, m_type(type)
{
m_flags.set();
@@ -67,6 +66,11 @@ UserMarkContainer::~UserMarkContainer()
NotifyChanges();
}
+void UserMarkContainer::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
+{
+ m_drapeEngine.Set(engine);
+}
+
UserMark const * UserMarkContainer::FindMarkInRect(m2::AnyRectD const & rect, double & d) const
{
UserMark * mark = nullptr;
@@ -82,43 +86,17 @@ UserMark const * UserMarkContainer::FindMarkInRect(m2::AnyRectD const & rect, do
return mark;
}
-namespace
-{
-// TODO: refactor it, get rid of global pointers.
-unique_ptr<StaticMarkPoint> g_selectionUserMark;
-unique_ptr<MyPositionMarkPoint> g_myPosition;
-} // namespace
-
-void UserMarkContainer::InitStaticMarks(UserMarkContainer * container)
-{
- if (g_selectionUserMark == NULL)
- g_selectionUserMark.reset(new StaticMarkPoint(container));
-
- if (g_myPosition == NULL)
- g_myPosition.reset(new MyPositionMarkPoint(container));
-}
-
-StaticMarkPoint * UserMarkContainer::UserMarkForPoi()
-{
- ASSERT(g_selectionUserMark != NULL, ());
- return g_selectionUserMark.get();
-}
-
-MyPositionMarkPoint * UserMarkContainer::UserMarkForMyPostion()
-{
- ASSERT(g_myPosition != NULL, ());
- return g_myPosition.get();
-}
-
void UserMarkContainer::NotifyChanges()
{
if (!IsDirty())
return;
- ref_ptr<df::DrapeEngine> engine = m_framework.GetDrapeEngine();
- if (engine == nullptr)
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (!lock)
return;
+ auto engine = lock.Get();
+
df::MarkGroupID const groupId = GenerateMarkGroupId(this);
engine->ChangeVisibilityUserMarksGroup(groupId, IsVisible() && IsDrawable());
@@ -159,7 +137,7 @@ df::UserLineMark const * UserMarkContainer::GetUserLineMark(size_t index) const
float UserMarkContainer::GetPointDepth() const
{
- return m_layerDepth;
+ return static_cast<float>(m_layerDepth);
}
bool UserMarkContainer::IsVisible() const
@@ -204,11 +182,10 @@ UserMark * UserMarkContainer::GetUserMarkForEdit(size_t index)
return m_userMarks[index].get();
}
-void UserMarkContainer::Clear(size_t skipCount/* = 0*/)
+void UserMarkContainer::Clear()
{
SetDirty();
- if (skipCount < m_userMarks.size())
- m_userMarks.erase(m_userMarks.begin(), m_userMarks.end() - skipCount);
+ m_userMarks.clear();
}
void UserMarkContainer::SetIsDrawable(bool isDrawable)
diff --git a/map/user_mark_container.hpp b/map/user_mark_container.hpp
index 6750dc4aad..c523bea5d2 100644
--- a/map/user_mark_container.hpp
+++ b/map/user_mark_container.hpp
@@ -2,19 +2,18 @@
#include "map/user_mark.hpp"
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
#include "drape_frontend/user_marks_provider.hpp"
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
#include "geometry/any_rect2d.hpp"
-#include "std/deque.hpp"
-#include "std/bitset.hpp"
+#include <base/macros.hpp>
-#include "std/noncopyable.hpp"
-#include "std/unique_ptr.hpp"
-
-class Framework;
+#include <bitset>
+#include <deque>
+#include <memory>
class UserMarksController
{
@@ -28,30 +27,27 @@ public:
virtual UserMark const * GetUserMark(size_t index) const = 0;
virtual UserMark * GetUserMarkForEdit(size_t index) = 0;
virtual void DeleteUserMark(size_t index) = 0;
- virtual void Clear(size_t skipCount = 0) = 0;
+ virtual void Clear() = 0;
virtual void Update() = 0;
virtual void NotifyChanges() = 0;
};
class UserMarkContainer : public df::UserMarksProvider
, public UserMarksController
- , private noncopyable
{
public:
- using TUserMarksList = deque<unique_ptr<UserMark>>;
+ using TUserMarksList = std::deque<std::unique_ptr<UserMark>>;
+
+ UserMarkContainer(double layerDepth, UserMark::Type type);
+ ~UserMarkContainer() override;
- UserMarkContainer(double layerDepth, UserMark::Type type, Framework & fm);
- virtual ~UserMarkContainer();
+ void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
// If not found mark on rect result is nullptr.
// If mark is found in "d" return distance from rect center.
// In multiple select choose mark with min(d).
UserMark const * FindMarkInRect(m2::AnyRectD const & rect, double & d) const;
- static void InitStaticMarks(UserMarkContainer * container);
- static StaticMarkPoint * UserMarkForPoi();
- static MyPositionMarkPoint * UserMarkForMyPostion();
-
// UserMarksProvider implementation.
size_t GetUserPointCount() const override;
df::UserPointMark const * GetUserPointMark(size_t index) const override;
@@ -77,7 +73,7 @@ public:
UserMark * CreateUserMark(m2::PointD const & ptOrg) override;
UserMark * GetUserMarkForEdit(size_t index) override;
void DeleteUserMark(size_t index) override;
- void Clear(size_t skipCount = 0) override;
+ void Clear() override;
void SetIsDrawable(bool isDrawable) override;
void SetIsVisible(bool isVisible) override;
void Update() override;
@@ -88,24 +84,25 @@ protected:
virtual UserMark * AllocateUserMark(m2::PointD const & ptOrg) = 0;
- Framework & m_framework;
-
private:
- bitset<4> m_flags;
+ df::DrapeEngineSafePtr m_drapeEngine;
+ std::bitset<4> m_flags;
double m_layerDepth;
TUserMarksList m_userMarks;
UserMark::Type m_type;
df::MarkIDCollection m_createdMarks;
df::MarkIDCollection m_removedMarks;
bool m_isDirty = false;
+
+ DISALLOW_COPY_AND_MOVE(UserMarkContainer);
};
template<typename MarkPointClassType, UserMark::Type UserMarkType>
class SpecifiedUserMarkContainer : public UserMarkContainer
{
public:
- explicit SpecifiedUserMarkContainer(Framework & framework)
- : UserMarkContainer(0.0 /* layer depth */, UserMarkType, framework)
+ explicit SpecifiedUserMarkContainer()
+ : UserMarkContainer(0.0 /* layer depth */, UserMarkType)
{}
protected:
diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp
index 5db6bb0329..7999667147 100644
--- a/qt/draw_widget.cpp
+++ b/qt/draw_widget.cpp
@@ -154,8 +154,8 @@ void DrawWidget::ChoosePositionModeDisable()
void DrawWidget::initializeGL()
{
- MapWidget::initializeGL();
m_framework.LoadBookmarks();
+ MapWidget::initializeGL();
auto & routingManager = m_framework.GetRoutingManager();
if (routingManager.LoadRoutePoints())