diff --git a/map/framework.cpp b/map/framework.cpp index 1db99db17d..8fa92eac94 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -11,6 +11,7 @@ #include "../defines.hpp" #include "../routing/route.hpp" +#include "../routing/dijkstra_router.hpp" #include "../search/search_engine.hpp" #include "../search/result.hpp" @@ -60,8 +61,6 @@ using namespace storage; -static void RestoreSesame(routing::RoutingEngine &); - #ifdef FIXED_LOCATION Framework::FixedPosition::FixedPosition() { @@ -266,7 +265,7 @@ Framework::Framework() #endif // Restore temporary states from persistent Settings storage - RestoreSesame(m_routingEngine); + RestoreSesame(); } Framework::~Framework() @@ -1201,23 +1200,36 @@ void Framework::OnRouteCalculated(routing::Route const & route) routeColor = graphics::Color::Red(); else if (source == ROUTER_OSRM) routeColor = graphics::Color::Blue(); + else if (source == ROUTER_MAPSME) + routeColor = graphics::Color::Green(); + track.SetColor(routeColor); cat->AddTrack(track); } -static void RestoreSesame(routing::RoutingEngine & re) +void Framework::DeleteRoutes() +{ + /// @todo +} + +routing::IRouter * Framework::CreateRouter() +{ + return new routing::DijkstraRouter(&m_model.GetIndex()); +} + +void Framework::RestoreSesame() { bool enable = false; if (Settings::Get(ROUTER_HELICOPTER, enable) && enable) - re.AddRouter(ROUTER_HELICOPTER); - if (Settings::Get(ROUTER_OSRM, enable) && enable) - re.AddRouter(ROUTER_OSRM); + m_routingEngine.AddRouter(ROUTER_HELICOPTER); +// if (Settings::Get(ROUTER_OSRM, enable) && enable) +// m_routingEngine.AddRouter(ROUTER_OSRM); if (Settings::Get(ROUTER_MAPSME, enable) && enable) - re.AddRouter(ROUTER_MAPSME); + m_routingEngine.AddRouter(ROUTER_MAPSME, CreateRouter()); } /// Activates hidden features via search queries -static bool SesameOpen(search::SearchParams const & params, routing::RoutingEngine & r) +bool Framework::SesameOpen(search::SearchParams const & params) { // Quick check string const & q = params.m_query; @@ -1227,62 +1239,64 @@ static bool SesameOpen(search::SearchParams const & params, routing::RoutingEngi char const * searchResult = 0; if (params.m_query == "?routing on") { - r.AddRouter(ROUTER_HELICOPTER); - r.AddRouter(ROUTER_OSRM); -// r.AddRouter(ROUTER_MAPSME); + m_routingEngine.AddRouter(ROUTER_HELICOPTER); + m_routingEngine.AddRouter(ROUTER_OSRM); + m_routingEngine.AddRouter(ROUTER_MAPSME, CreateRouter()); + // Enable all other engines here Settings::Set(ROUTER_HELICOPTER, true); Settings::Set(ROUTER_OSRM, true); -// Settings::Set(ROUTER_MAPSME, true); + Settings::Set(ROUTER_MAPSME, true); searchResult = "All routing engines activated"; } else if (params.m_query == "?routing off") { - r.RemoveRouter(ROUTER_HELICOPTER); - r.RemoveRouter(ROUTER_OSRM); -// r.RemoveRouter(ROUTER_MAPSME); + m_routingEngine.RemoveRouter(ROUTER_HELICOPTER); + m_routingEngine.RemoveRouter(ROUTER_OSRM); + m_routingEngine.RemoveRouter(ROUTER_MAPSME); + // Disable all other engines here Settings::Set(ROUTER_HELICOPTER, false); Settings::Set(ROUTER_OSRM, false); -// Settings::Set(ROUTER_MAPSME, false); + Settings::Set(ROUTER_MAPSME, false); searchResult = "All routing engines disabled"; } else if (params.m_query == "?heli on") { - r.AddRouter(ROUTER_HELICOPTER); + m_routingEngine.AddRouter(ROUTER_HELICOPTER); Settings::Set(ROUTER_HELICOPTER, true); searchResult = "Helicopter routing activated"; } else if (params.m_query == "?heli off") { - r.RemoveRouter(ROUTER_HELICOPTER); + m_routingEngine.RemoveRouter(ROUTER_HELICOPTER); Settings::Set(ROUTER_HELICOPTER, false); searchResult = "Helicopter routing disabled"; } else if (params.m_query == "?online on" || params.m_query == "?osrm on") { - r.AddRouter(ROUTER_OSRM); + m_routingEngine.AddRouter(ROUTER_OSRM); Settings::Set(ROUTER_OSRM, true); searchResult = "OSRM routing activated"; } else if (params.m_query == "?online off" || params.m_query == "?osrm off") { - r.RemoveRouter(ROUTER_OSRM); + m_routingEngine.RemoveRouter(ROUTER_OSRM); Settings::Set(ROUTER_OSRM, false); searchResult = "OSRM routing disabled"; } -// else if (params.m_query == "?routeme on") -// { -// r.AddRouter(ROUTER_MAPSME); -// Settings::Set(ROUTER_MAPSME, true); -// searchResult = "maps.me routing activated"; -// } -// else if (params.m_query == "?routeme off") -// { -// r.RemoveRouter(ROUTER_MAPSME); -// Settings::Set(ROUTER_MAPSME, false); -// searchResult = "maps.me routing disabled"; -// } + else if (params.m_query == "?routeme on") + { + m_routingEngine.AddRouter(ROUTER_MAPSME, CreateRouter()); + Settings::Set(ROUTER_MAPSME, true); + searchResult = "maps.me routing activated"; + } + else if (params.m_query == "?routeme off") + { + m_routingEngine.RemoveRouter(ROUTER_MAPSME); + Settings::Set(ROUTER_MAPSME, false); + searchResult = "maps.me routing disabled"; + } if (searchResult) { @@ -1300,7 +1314,7 @@ static bool SesameOpen(search::SearchParams const & params, routing::RoutingEngi bool Framework::Search(search::SearchParams const & params) { // Activate hidden features - if (SesameOpen(params, m_routingEngine)) + if (SesameOpen(params)) return true; #ifdef FIXED_LOCATION diff --git a/map/framework.hpp b/map/framework.hpp index 8daedb7eb3..326764a3cd 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -94,6 +94,9 @@ protected: mutable scoped_ptr m_pSearchEngine; routing::RoutingEngine m_routingEngine; + routing::IRouter * CreateRouter(); + void RestoreSesame(); + bool SesameOpen(search::SearchParams const & params); model::FeaturesFetcher m_model; ScalesProcessor m_scales; @@ -492,6 +495,7 @@ public: bool IsRoutingEnabled() const; void SetRouteStart(m2::PointD const & mercatorStart); void SetRouteEnd(m2::PointD const & mercatorEnd); + void DeleteRoutes(); void OnRouteCalculated(routing::Route const & route); //@} }; diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index d0fde0689a..6ce06f5ad1 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -80,7 +80,8 @@ namespace qt m_isRotate(false), //m_redrawInterval(100), m_ratio(1.0), - m_pScale(0) + m_pScale(0), + m_routingMode(0) { // Initialize with some stubs for test. PinClickManager & manager = GetBalloonManager(); @@ -385,6 +386,26 @@ namespace qt setCursor(Qt::CrossCursor); m_isRotate = true; } + else if (e->modifiers() & Qt::ShiftModifier) + { + m2::PointD const mercPoint = m_framework->PtoG(pt); + + switch (m_routingMode) + { + case 0: + m_framework->SetRouteStart(mercPoint); + break; + case 1: + m_framework->SetRouteEnd(mercPoint); + break; + default: + m_routingMode = -1; + m_framework->DeleteRoutes(); + break; + } + + ++m_routingMode; + } else { // init press task params diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp index 1a695b6377..3ccab8d681 100644 --- a/qt/draw_widget.hpp +++ b/qt/draw_widget.hpp @@ -143,6 +143,8 @@ namespace qt m2::PointD m_taskPoint; bool m_wasLongClick, m_isCleanSingleClick; + int m_routingMode; + PinClickManager & GetBalloonManager() { return m_framework->GetBalloonManager(); } }; } diff --git a/routing/routing_engine.cpp b/routing/routing_engine.cpp index 54994980a3..aa086c147d 100644 --- a/routing/routing_engine.cpp +++ b/routing/routing_engine.cpp @@ -1,11 +1,14 @@ #include "routing_engine.hpp" #include "route.hpp" + #include "helicopter_router.hpp" #include "osrm_router.hpp" +#include "dijkstra_router.hpp" #include "../base/stl_add.hpp" #include "../base/logging.hpp" + namespace routing { @@ -24,12 +27,18 @@ void RoutingEngine::AddRouter(string const & name) if (!FindRouter(name)) { if (name == "helicopter") - m_routers.push_back(new HelicopterRouter); + m_routers.push_back(new HelicopterRouter()); else if (name == "osrm") - m_routers.push_back(new OsrmRouter); + m_routers.push_back(new OsrmRouter()); } } +void RoutingEngine::AddRouter(string const & name, IRouter * pRouter) +{ + if (!FindRouter(name)) + m_routers.push_back(pRouter); +} + void RoutingEngine::RemoveRouter(string const & name) { for (TRouters::iterator it = m_routers.begin(); it != m_routers.end(); ++it) diff --git a/routing/routing_engine.hpp b/routing/routing_engine.hpp index df485caafa..c3693e775c 100644 --- a/routing/routing_engine.hpp +++ b/routing/routing_engine.hpp @@ -17,6 +17,7 @@ public: ~RoutingEngine(); void AddRouter(string const & name); + void AddRouter(string const & name, IRouter * pRouter); void RemoveRouter(string const & name); bool IsRoutingEnabled() const;