diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 7a9ae5d835..21263389f9 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1146,17 +1146,15 @@ Java_com_mapswithme_maps_Framework_nativeGetBestRouter(JNIEnv * env, jclass, jdo JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetRouteStartPoint(JNIEnv * env, jclass, jdouble lat, jdouble lon, jboolean valid) { - frm()->GetRoutingManager().SetRouteStartPoint(frm()->GetBookmarkManager(), - m2::PointD(MercatorBounds::FromLatLon(lat, lon)), - static_cast(valid)); + frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)), + static_cast(valid), RouteMarkType::Start); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeSetRouteEndPoint(JNIEnv * env, jclass, jdouble lat, jdouble lon, jboolean valid) { - frm()->GetRoutingManager().SetRouteFinishPoint(frm()->GetBookmarkManager(), - m2::PointD(MercatorBounds::FromLatLon(lat, lon)), - static_cast(valid)); + frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)), + static_cast(valid), RouteMarkType::Finish); } JNIEXPORT void JNICALL diff --git a/iphone/Maps/Core/Routing/MWMRouter.mm b/iphone/Maps/Core/Routing/MWMRouter.mm index b459171276..74d4f381a6 100644 --- a/iphone/Maps/Core/Routing/MWMRouter.mm +++ b/iphone/Maps/Core/Routing/MWMRouter.mm @@ -202,8 +202,8 @@ bool isMarkerPoint(MWMRoutePoint * point) { return point.isValid && !point.isMyP self.type = routerType(GetFramework().GetRoutingManager().GetBestRouter(startPoint, finishPoint)); f.GetRoutingManager().BuildRoute(startPoint, finishPoint, isP2P, 0 /* timeoutSec */); - f.GetRoutingManager().SetRouteStartPoint(f.GetBookmarkManager(), startPoint, isMarkerPoint(self.startPoint)); - f.GetRoutingManager().SetRouteFinishPoint(f.GetBookmarkManager(), finishPoint, isMarkerPoint(self.finishPoint)); + f.GetRoutingManager().AddRoutePoint(startPoint, isMarkerPoint(self.startPoint), RouteMarkType::Start); + f.GetRoutingManager().AddRoutePoint(finishPoint, isMarkerPoint(self.finishPoint), RouteMarkType::Finish); [mapViewControlsManager onRouteRebuild]; } diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 14703d3f7f..852969eba0 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -231,6 +231,7 @@ UserMark const * BookmarkManager::FindNearestUserMark(TTouchRectHolder const & h for_each(m_categories.begin(), m_categories.end(), ref(finder)); finder(FindUserMarksContainer(UserMarkType::API_MARK)); finder(FindUserMarksContainer(UserMarkType::SEARCH_MARK)); + finder(FindUserMarksContainer(UserMarkType::ROUTING_MARK)); return finder.GetFindedMark(); } diff --git a/map/framework.cpp b/map/framework.cpp index f07544087c..1b724497d1 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -414,6 +414,7 @@ Framework::Framework(FrameworkParams const & params) m_connectToGpsTrack = GpsTracker::Instance().IsEnabled(); m_ParsedMapApi.SetBookmarkManager(&m_bmManager); + m_routingManager.SetBookmarkManager(&m_bmManager); // Init strings bundle. // @TODO. There are hardcoded strings below which are defined in strings.txt as well. @@ -942,6 +943,22 @@ void Framework::FillMyPositionInfo(place_page::Info & info) const info.m_customName = m_stringsBundle.GetString("my_position"); } +void Framework::FillRouteMarkInfo(RouteMarkPoint const & rmp, place_page::Info & info) const +{ + FillPointInfo(rmp.GetPivot(), "", info); + info.m_isRoutePoint = true; + + switch (rmp.GetRoutePointType()) + { + case RouteMarkType::Start: + info.m_customName = "Start"; + break; + case RouteMarkType::Finish: + info.m_customName = "Finish"; + break; + } +} + void Framework::ShowBookmark(BookmarkAndCategory const & bnc) { StopLocationFollow(); @@ -2417,6 +2434,9 @@ df::SelectionShape::ESelectedObject Framework::OnTapEventImpl(TapEvent const & t case UserMark::Type::SEARCH: FillSearchResultInfo(*static_cast(mark), outInfo); break; + case UserMark::Type::ROUTING: + FillRouteMarkInfo(*static_cast(mark), outInfo); + break; default: ASSERT(false, ("FindNearestUserMark returned invalid mark.")); } diff --git a/map/framework.hpp b/map/framework.hpp index fb18b5a624..13e40a6b71 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -10,6 +10,7 @@ #include "map/mwm_url.hpp" #include "map/place_page_info.hpp" #include "map/routing_manager.hpp" +#include "map/routing_mark.hpp" #include "map/track.hpp" #include "map/traffic_manager.hpp" @@ -676,6 +677,7 @@ private: void FillApiMarkInfo(ApiMarkPoint const & api, place_page::Info & info) const; void FillSearchResultInfo(SearchMarkPoint const & smp, place_page::Info & info) const; void FillMyPositionInfo(place_page::Info & info) const; + void FillRouteMarkInfo(RouteMarkPoint const & rmp, place_page::Info & info) const; public: void FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const & bac, place_page::Info & info) const; diff --git a/map/place_page_info.cpp b/map/place_page_info.cpp index b756123a75..fc97d0fc88 100644 --- a/map/place_page_info.cpp +++ b/map/place_page_info.cpp @@ -22,18 +22,13 @@ char const * const Info::kPricingSymbol = "$"; bool Info::IsFeature() const { return m_featureID.IsValid(); } bool Info::IsBookmark() const { return m_bac.IsValid(); } bool Info::IsMyPosition() const { return m_isMyPosition; } +bool Info::IsRoutePoint() const { return m_isRoutePoint; } bool Info::IsSponsored() const { return m_sponsoredType != SponsoredType::None; } bool Info::IsNotEditableSponsored() const { return m_sponsoredType != SponsoredType::None && m_sponsoredType != SponsoredType::Opentable; } -bool Info::IsRoutePoint() const -{ - //TODO(@darina) Implement checker - return m_bac.IsValid() && m_bookmarkCategoryName == "TMP_Routing_Points"; -} - bool Info::ShouldShowAddPlace() const { auto const isPointOrBuilding = IsPointType() || IsBuilding(); diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index ddc54c5994..8788628e58 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -147,6 +147,7 @@ public: /// one part of the country (or several countries for disputed territories). storage::TCountriesVec m_topmostCountryIds; + bool m_isRoutePoint = false; bool m_isMyPosition = false; /// True if editing of a selected point is allowed by basic logic. /// See initialization in framework. diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 0bc1b59f98..8d4581104c 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -1,6 +1,7 @@ #include "routing_manager.hpp" #include "map/chart_generator.hpp" +#include "map/routing_mark.hpp" #include "map/mwm_tree.hpp" #include "private.h" @@ -64,6 +65,11 @@ RoutingManager::RoutingManager(Callbacks && callbacks, Delegate & delegate) [this](Route const & route, IRouter::ResultCode code) { OnRebuildRouteReady(route, code); }); } +void RoutingManager::SetBookmarkManager(BookmarkManager * bmManager) +{ + m_bmManager = bmManager; +} + void RoutingManager::OnBuildRouteReady(Route const & route, IRouter::ResultCode code) { // Hide preview. @@ -257,7 +263,7 @@ void RoutingManager::FollowRoute() m_delegate.OnRouteFollow(m_currentRouterType); - // TODO(@darina) Hide start point user mark + HideRoutePoint(RouteMarkType::Start); } void RoutingManager::CloseRouting() @@ -273,7 +279,8 @@ void RoutingManager::CloseRouting() m_routingSession.Reset(); RemoveRoute(true /* deactivateFollowing */); - //TODO (@darina) Remove route points + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + guard.m_controller.Clear(); } void RoutingManager::SetLastUsedRouter(RouterType type) @@ -281,71 +288,45 @@ void RoutingManager::SetLastUsedRouter(RouterType type) settings::Set(kRouterTypeKey, routing::ToString(type)); } -// TODO(@darina) Remove me -// TEMPORARY { -void TempAddBookmarkAsRoutePoint(BookmarkManager & bm, std::string const & name, - std::string const & bookmarkSymbol, - m2::PointD const & pt, bool isValid) +void RoutingManager::HideRoutePoint(RouteMarkType type, int8_t intermediateIndex) { - std::string categoryName = "TMP_Routing_Points"; - int categoryIndex = -1; - for (size_t i = 0; i < bm.GetBmCategoriesCount(); ++i) + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + RouteMarkPoint * mark = routePoints.GetRoutePoint(type, intermediateIndex); + if (mark != nullptr) { - if (bm.GetBmCategory(i)->GetName() == categoryName) - { - categoryIndex = static_cast(i); - break; - } - } - if (categoryIndex == -1) - categoryIndex = bm.CreateBmCategory(categoryName); - - if (!isValid) - { - BookmarkCategory * cat = bm.GetBmCategory(categoryIndex); - BookmarkCategory::Guard guard(*cat); - int indexToDelete = -1; - for (size_t i = 0; i < guard.m_controller.GetUserMarkCount(); ++i) - { - Bookmark const * bookmark = static_cast(guard.m_controller.GetUserMark(i)); - if (bookmark->GetName() == name) - { - indexToDelete = i; - break; - } - } - if (indexToDelete >= 0) - guard.m_controller.DeleteUserMark(indexToDelete); - } - else - { - BookmarkData dat(name, bookmarkSymbol); - bm.AddBookmark(categoryIndex, pt, dat); - } - - { - BookmarkCategory * cat = bm.GetBmCategory(categoryIndex); - cat->SaveToKMLFile(); + mark->SetIsVisible(false); + guard.m_controller.Update(); } } -// } TEMPORARY -void RoutingManager::SetRouteStartPoint(BookmarkManager & bm, m2::PointD const & pt, bool isValid) +void RoutingManager::AddRoutePoint(m2::PointD const & pt, bool isVisible, + RouteMarkType type, int8_t intermediateIndex) { - // TODO(@darina) Implement on new user marks - // TEMPORARY { - //TempAddBookmarkAsRoutePoint(bm, "Route start point", "placemark-blue", - // pt, isValid); - // } TEMPORARY + ASSERT(m_bmManager != nullptr, ()); + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + RouteMarkPoint * mark = routePoints.AddRoutePoint(pt, type, intermediateIndex); + if (mark != nullptr) + mark->SetIsVisible(isVisible); } -void RoutingManager::SetRouteFinishPoint(BookmarkManager & bm, m2::PointD const & pt, bool isValid) +void RoutingManager::RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex) { - // TODO(@darina) Implement on new user marks - // TEMPORARY { - //TempAddBookmarkAsRoutePoint(bm, "Route end point", "placemark-green", - // pt, isValid); - // } TEMPORARY + ASSERT(m_bmManager != nullptr, ()); + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + routePoints.RemoveRoutePoint(type, intermediateIndex); +} + +void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex, + RouteMarkType targetType, int8_t targetIntermediateIndex) +{ + ASSERT(m_bmManager != nullptr, ()); + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + routePoints.MoveRoutePoint(currentType, currentIntermediateIndex, + targetType, targetIntermediateIndex); } void RoutingManager::GenerateTurnNotifications(std::vector & turnNotifications) diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp index 35766bf2a6..71096946af 100644 --- a/map/routing_manager.hpp +++ b/map/routing_manager.hpp @@ -1,7 +1,7 @@ #pragma once -// TODO (@darina) TEMPORARY Remove me #include "map/bookmark_manager.hpp" +#include "map/routing_mark.hpp" #include "routing/route.hpp" #include "routing/routing_session.hpp" @@ -75,6 +75,8 @@ public: RoutingManager(Callbacks && callbacks, Delegate & delegate); + void SetBookmarkManager(BookmarkManager * bmManager); + routing::RoutingSession const & RoutingSession() const { return m_routingSession; } routing::RoutingSession & RoutingSession() { return m_routingSession; } void SetRouter(routing::RouterType type); @@ -159,9 +161,11 @@ public: /// GenerateTurnNotifications shall be called by the client when a new position is available. void GenerateTurnNotifications(std::vector & turnNotifications); - // TODO (@darina) Change interface to add/remove route point - void SetRouteStartPoint(BookmarkManager & bm, m2::PointD const & pt, bool isValid); - void SetRouteFinishPoint(BookmarkManager & bm, m2::PointD const & pt, bool isValid); + void AddRoutePoint(m2::PointD const & pt, bool isVisible, RouteMarkType type, int8_t intermediateIndex = 0); + void RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0); + void MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex, + RouteMarkType targetType, int8_t targetIntermediateIndex); + void HideRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0); void SetRouterImpl(routing::RouterType type); void RemoveRoute(bool deactivateFollowing); @@ -215,6 +219,7 @@ private: routing::RoutingSession m_routingSession; Delegate & m_delegate; tracking::Reporter m_trackingReporter; + BookmarkManager * m_bmManager = nullptr; std::vector m_drapeSubroutes;