Using route marks in the routing manager.

This commit is contained in:
Daria Volvenkova 2017-06-08 17:01:56 +03:00
parent d455c04c3b
commit b55dd4c1ae
9 changed files with 79 additions and 76 deletions

View file

@ -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<bool>(valid));
frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)),
static_cast<bool>(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<bool>(valid));
frm()->GetRoutingManager().AddRoutePoint(m2::PointD(MercatorBounds::FromLatLon(lat, lon)),
static_cast<bool>(valid), RouteMarkType::Finish);
}
JNIEXPORT void JNICALL

View file

@ -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];
}

View file

@ -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();
}

View file

@ -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<SearchMarkPoint const *>(mark), outInfo);
break;
case UserMark::Type::ROUTING:
FillRouteMarkInfo(*static_cast<RouteMarkPoint const *>(mark), outInfo);
break;
default:
ASSERT(false, ("FindNearestUserMark returned invalid mark."));
}

View file

@ -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;

View file

@ -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();

View file

@ -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.

View file

@ -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<int>(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<Bookmark const *>(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<std::string> & turnNotifications)

View file

@ -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<std::string> & 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<dp::DrapeID> m_drapeSubroutes;