From 82159cb74e45b02aec59e9a2053c5e86365a7a52 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 8 Jun 2017 21:32:03 +0300 Subject: [PATCH] Intermediate route point adding. --- android/jni/com/mapswithme/maps/Framework.cpp | 6 +- iphone/Maps/Core/Routing/MWMRouter.mm | 6 +- iphone/Maps/UI/PlacePage/MWMPlacePageData.h | 4 ++ iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 2 + .../Maps/UI/PlacePage/MWMPlacePageManager.mm | 8 ++- .../ActionBar/MWMPlacePageActionBar.mm | 3 +- map/CMakeLists.txt | 2 + map/framework.cpp | 20 +++++- map/place_page_info.hpp | 4 ++ map/routing_manager.cpp | 61 +++++++++++++++++-- map/routing_manager.hpp | 4 +- map/routing_mark.cpp | 14 ++++- map/routing_mark.hpp | 10 ++- xcode/map/map.xcodeproj/project.pbxproj | 8 +++ 14 files changed, 130 insertions(+), 22 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 21263389f9..517b2f711e 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1146,15 +1146,17 @@ 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().RemoveRoutePoint(RouteMarkType::Start); frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)), - static_cast(valid), RouteMarkType::Start); + 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().RemoveRoutePoint(RouteMarkType::Finish); frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)), - static_cast(valid), RouteMarkType::Finish); + 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 74d4f381a6..ac240bea0e 100644 --- a/iphone/Maps/Core/Routing/MWMRouter.mm +++ b/iphone/Maps/Core/Routing/MWMRouter.mm @@ -202,8 +202,10 @@ 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().AddRoutePoint(startPoint, isMarkerPoint(self.startPoint), RouteMarkType::Start); - f.GetRoutingManager().AddRoutePoint(finishPoint, isMarkerPoint(self.finishPoint), RouteMarkType::Finish); + if (self.startPoint.isValid) + f.GetRoutingManager().AddRoutePoint(startPoint, self.startPoint.isMyPosition, RouteMarkType::Start); + if (self.finishPoint.isValid) + f.GetRoutingManager().AddRoutePoint(finishPoint, self.finishPoint.isMyPosition, RouteMarkType::Finish); [mapViewControlsManager onRouteRebuild]; } diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index 0c8f628dbc..8a8e43cdea 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -145,6 +145,10 @@ using BannerIsReady = void (^)(); - (NSURL *)URLToAllReviews; - (NSArray *)photos; +// Route points +- (RouteMarkType)routeMarkType; +- (int8_t)intermediateIndex; + // Banner - (id)nativeAd; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index 120c7209c3..e9b1979c35 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -517,6 +517,8 @@ using namespace place_page; #pragma mark - Getters +- (RouteMarkType)routeMarkType { return m_info.m_routeMarkType; } +- (int8_t)intermediateIndex { return m_info.m_intermediateIndex; } - (NSString *)address { return @(m_info.GetAddress().c_str()); } - (NSString *)apiURL { return @(m_info.GetApiUrl().c_str()); } - (vector const &)sections { return m_sections; } diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index 2a22f5584f..97ee724352 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -276,13 +276,15 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) - (void)addStop { - // TODO: Implement adding a routing point. - // self.data contains all point's data. + GetFramework().GetRoutingManager().AddRoutePoint(self.data.mercator, false /* isMyPosition */, + RouteMarkType::Intermediate, 0); + [self close]; } - (void)removeStop { - // TODO: Implement removing a routing point. + GetFramework().GetRoutingManager().RemoveRoutePoint(self.data.routeMarkType, self.data.intermediateIndex); + [self close]; } - (void)taxiTo diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm index 73a004e88e..23ff819c7c 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm @@ -64,8 +64,7 @@ extern NSString * const kAlohalyticsTapEventKey; BOOL const isP2P = self.isPrepareRouteMode; BOOL const isMyPosition = data.isMyPosition; BOOL const isRoutePoint = data.isRoutePoint; - BOOL const isNeedToAddIntermediatePoint = GetFramework().GetRoutingManager().IsRoutingActive() - /* && there is no intermediate point yet */; + BOOL const isNeedToAddIntermediatePoint = GetFramework().GetRoutingManager().CouldAddIntermediatePoint(); EButton sponsoredButton = EButton::BookingSearch; if (isBooking) diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt index 64345ffe77..096f553145 100644 --- a/map/CMakeLists.txt +++ b/map/CMakeLists.txt @@ -56,6 +56,8 @@ set( reachable_by_taxi_checker.hpp routing_manager.cpp routing_manager.hpp + routing_mark.cpp + routing_mark.hpp track.cpp track.hpp traffic_manager.cpp diff --git a/map/framework.cpp b/map/framework.cpp index 1b724497d1..f1e8a2627a 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -948,15 +948,29 @@ void Framework::FillRouteMarkInfo(RouteMarkPoint const & rmp, place_page::Info & FillPointInfo(rmp.GetPivot(), "", info); info.m_isRoutePoint = true; - switch (rmp.GetRoutePointType()) + std::string title; + RouteMarkType const type = rmp.GetRoutePointType(); + int8_t const intermediateIndex = rmp.GetIntermediateIndex(); + switch (type) { case RouteMarkType::Start: - info.m_customName = "Start"; + title = "Start"; + break; + case RouteMarkType::Intermediate: + if (intermediateIndex == 0) + title = "First stop A"; + else if (intermediateIndex == 1) + title = "Second stop B"; + else + title = "Third stop C"; break; case RouteMarkType::Finish: - info.m_customName = "Finish"; + title = "Finish"; break; } + info.m_customName = title; + info.m_routeMarkType = type; + info.m_intermediateIndex = intermediateIndex; } void Framework::ShowBookmark(BookmarkAndCategory const & bnc) diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index 8788628e58..1054e9c714 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -1,6 +1,7 @@ #pragma once #include "map/bookmark.hpp" +#include "map/routing_mark.hpp" #include "storage/index.hpp" @@ -148,6 +149,9 @@ public: storage::TCountriesVec m_topmostCountryIds; bool m_isRoutePoint = false; + RouteMarkType m_routeMarkType; + int8_t m_intermediateIndex = 0; + 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 8d4581104c..7eec516e28 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -300,7 +300,49 @@ void RoutingManager::HideRoutePoint(RouteMarkType type, int8_t intermediateIndex } } -void RoutingManager::AddRoutePoint(m2::PointD const & pt, bool isVisible, +void RoutingManager::UpdateRoute() +{ + if (!IsRoutingActive()) + return; + + bool isValid = false; + + m2::PointD startPt; + m2::PointD finishPt; + { + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + RouteMarkPoint * start = routePoints.GetRoutePoint(RouteMarkType::Start); + RouteMarkPoint * finish = routePoints.GetRoutePoint(RouteMarkType::Finish); + if (start != nullptr && finish != nullptr) + { + startPt = start->GetPivot(); + finishPt = finish->GetPivot(); + isValid = true; + } + } + + if (isValid) + { + RemoveRoute(true /* deactivateFollowing */); + m_routingSession.SetUserCurrentPosition(startPt); + m_routingSession.BuildRoute(startPt, finishPt, 0 /* timeoutSec */); + } + else + { + CloseRouting(); + } +} + +bool RoutingManager::CouldAddIntermediatePoint() const +{ + if (!IsRoutingActive()) + return false; + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + return guard.m_controller.GetUserMarkCount() < RoutePointsLayout::kMaxIntermediatePointsCount + 2; +} + +void RoutingManager::AddRoutePoint(m2::PointD const & pt, bool isMyPosition, RouteMarkType type, int8_t intermediateIndex) { ASSERT(m_bmManager != nullptr, ()); @@ -308,15 +350,22 @@ void RoutingManager::AddRoutePoint(m2::PointD const & pt, bool isVisible, RoutePointsLayout routePoints(guard.m_controller); RouteMarkPoint * mark = routePoints.AddRoutePoint(pt, type, intermediateIndex); if (mark != nullptr) - mark->SetIsVisible(isVisible); + { + mark->SetIsVisible(!isMyPosition); + mark->SetIsMyPosition(isMyPosition); + } + // TODO(@darina) Update route. } void RoutingManager::RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex) { ASSERT(m_bmManager != nullptr, ()); - UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); - RoutePointsLayout routePoints(guard.m_controller); - routePoints.RemoveRoutePoint(type, intermediateIndex); + { + UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK); + RoutePointsLayout routePoints(guard.m_controller); + routePoints.RemoveRoutePoint(type, intermediateIndex); + } + //UpdateRoute(); } void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex, @@ -327,6 +376,8 @@ void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentInt RoutePointsLayout routePoints(guard.m_controller); routePoints.MoveRoutePoint(currentType, currentIntermediateIndex, targetType, targetIntermediateIndex); + + // TODO(@darina) Update route. } void RoutingManager::GenerateTurnNotifications(std::vector & turnNotifications) diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp index 71096946af..1a0418d733 100644 --- a/map/routing_manager.hpp +++ b/map/routing_manager.hpp @@ -161,11 +161,12 @@ public: /// GenerateTurnNotifications shall be called by the client when a new position is available. void GenerateTurnNotifications(std::vector & turnNotifications); - void AddRoutePoint(m2::PointD const & pt, bool isVisible, RouteMarkType type, int8_t intermediateIndex = 0); + void AddRoutePoint(m2::PointD const & pt, bool isMyPosition, 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); + bool CouldAddIntermediatePoint() const; void SetRouterImpl(routing::RouterType type); void RemoveRoute(bool deactivateFollowing); @@ -211,6 +212,7 @@ private: bool IsTrackingReporterEnabled() const; void MatchLocationToRoute(location::GpsInfo & info, location::RouteMatchingInfo & routeMatchingInfo) const; + void UpdateRoute(); RouteBuildingCallback m_routingCallback = nullptr; Callbacks m_callbacks; diff --git a/map/routing_mark.cpp b/map/routing_mark.cpp index 5b2c067e14..8d5ee58658 100644 --- a/map/routing_mark.cpp +++ b/map/routing_mark.cpp @@ -2,8 +2,6 @@ #include -static int8_t const kMaxIntermediatePointsCount = 3; - RouteMarkPoint::RouteMarkPoint(const m2::PointD & ptOrg, UserMarkContainer * container) : UserMark(ptOrg, container) {} @@ -18,6 +16,16 @@ void RouteMarkPoint::SetIsVisible(bool isVisible) m_isVisible = isVisible; } +void RouteMarkPoint::SetIsMyPosition(bool isMyPosition) +{ + m_isMyPosition = isMyPosition; +} + +bool RouteMarkPoint::IsMyPosition() const +{ + return m_isMyPosition; +} + std::string RouteMarkPoint::GetSymbolName() const { switch (m_pointType) @@ -153,10 +161,12 @@ bool RoutePointsLayout::MoveRoutePoint(RouteMarkType currentType, int8_t current m2::PointD const pt = point->GetPivot(); bool const isVisible = point->IsVisible(); + bool const isMyPosition = point->IsMyPosition(); RemoveRoutePoint(currentType, currentIntermediateIndex); RouteMarkPoint * point2 = AddRoutePoint(pt, destType, destIntermediateIndex); point2->SetIsVisible(isVisible); + point2->SetIsMyPosition(isMyPosition); return true; } diff --git a/map/routing_mark.hpp b/map/routing_mark.hpp index 5ca157fd15..90cd726b84 100644 --- a/map/routing_mark.hpp +++ b/map/routing_mark.hpp @@ -27,12 +27,16 @@ public: void SetRoutePointType(RouteMarkType type) { m_pointType = type; } void SetIntermediateIndex(int8_t index) { m_intermediateIndex = index; } - int8_t GetIntermediateIndex() { return m_intermediateIndex; } + int8_t GetIntermediateIndex() const { return m_intermediateIndex; } + + void SetIsMyPosition(bool isMyPosition); + bool IsMyPosition() const; private: RouteMarkType m_pointType; int8_t m_intermediateIndex = 0; bool m_isVisible = true; + bool m_isMyPosition = false; }; class RouteUserMarkContainer : public UserMarkContainer @@ -46,9 +50,11 @@ protected: class RoutePointsLayout { public: + static int8_t const kMaxIntermediatePointsCount = 1; + RoutePointsLayout(UserMarksController & routeMarks); - RouteMarkPoint * GetRoutePoint(RouteMarkType type, int8_t intermediateIndex); + RouteMarkPoint * GetRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0); RouteMarkPoint * AddRoutePoint(m2::PointD const & ptOrg, RouteMarkType type, int8_t intermediateIndex = 0); bool RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0); bool MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex, diff --git a/xcode/map/map.xcodeproj/project.pbxproj b/xcode/map/map.xcodeproj/project.pbxproj index 98d059feb5..fc6def5c55 100644 --- a/xcode/map/map.xcodeproj/project.pbxproj +++ b/xcode/map/map.xcodeproj/project.pbxproj @@ -97,6 +97,8 @@ 67F183831BD5049500AB1840 /* libminizip.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 67F1837F1BD5049500AB1840 /* libminizip.a */; }; 67F183841BD5049500AB1840 /* libtess2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 67F183801BD5049500AB1840 /* libtess2.a */; }; BB421D6C1E8C0031005BFA4D /* transliteration_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB421D6A1E8C0026005BFA4D /* transliteration_test.cpp */; }; + BBD9E2C61EE9D01900DF189A /* routing_mark.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BBD9E2C41EE9D01900DF189A /* routing_mark.cpp */; }; + BBD9E2C71EE9D01900DF189A /* routing_mark.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BBD9E2C51EE9D01900DF189A /* routing_mark.hpp */; }; F627BFC41E8E89B600B1CBF4 /* librouting_common.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F627BFC31E8E89B600B1CBF4 /* librouting_common.a */; }; F63421F81DF9BF9100A96868 /* reachable_by_taxi_checker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */; }; F63421F91DF9BF9100A96868 /* reachable_by_taxi_checker.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */; }; @@ -226,6 +228,8 @@ 67F183851BD504ED00AB1840 /* libsystem_configuration.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsystem_configuration.tbd; path = usr/lib/system/libsystem_configuration.tbd; sourceTree = SDKROOT; }; 67F183871BD5050900AB1840 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; BB421D6A1E8C0026005BFA4D /* transliteration_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transliteration_test.cpp; sourceTree = ""; }; + BBD9E2C41EE9D01900DF189A /* routing_mark.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_mark.cpp; sourceTree = ""; }; + BBD9E2C51EE9D01900DF189A /* routing_mark.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = routing_mark.hpp; sourceTree = ""; }; F627BFC31E8E89B600B1CBF4 /* librouting_common.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = librouting_common.a; path = "/Users/v.mikhaylenko/mapsme/omim/xcode/routing_common/../../../omim-build/xcode/Debug/librouting_common.a"; sourceTree = ""; }; F63421F61DF9BF9100A96868 /* reachable_by_taxi_checker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reachable_by_taxi_checker.cpp; sourceTree = ""; }; F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = reachable_by_taxi_checker.hpp; sourceTree = ""; }; @@ -424,6 +428,8 @@ F63421F71DF9BF9100A96868 /* reachable_by_taxi_checker.hpp */, F6D2CE7C1EDEB7F500636DFD /* routing_manager.cpp */, F6D2CE7D1EDEB7F500636DFD /* routing_manager.hpp */, + BBD9E2C41EE9D01900DF189A /* routing_mark.cpp */, + BBD9E2C51EE9D01900DF189A /* routing_mark.hpp */, 347B60741DD9926D0050FA24 /* traffic_manager.cpp */, 347B60751DD9926D0050FA24 /* traffic_manager.hpp */, 348AB57A1D7EE0C6009F8301 /* chart_generator.cpp */, @@ -504,6 +510,7 @@ F6D2CE7F1EDEB7F500636DFD /* routing_manager.hpp in Headers */, 670E39411C46C5C700E9C0A6 /* gps_tracker.hpp in Headers */, 45580ABF1E2CBD5E00CD535D /* benchmark_tools.hpp in Headers */, + BBD9E2C71EE9D01900DF189A /* routing_mark.hpp in Headers */, 342D833B1D5233E8000D8AEA /* displacement_mode_manager.hpp in Headers */, F6B283041C1B03320081957A /* gps_track_collection.hpp in Headers */, ); @@ -634,6 +641,7 @@ 670E39401C46C5C700E9C0A6 /* gps_tracker.cpp in Sources */, 6753464A1A4054E800A0A8C3 /* bookmark.cpp in Sources */, 45580ABE1E2CBD5E00CD535D /* benchmark_tools.cpp in Sources */, + BBD9E2C61EE9D01900DF189A /* routing_mark.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };