From e7df1b8e016490450c25bd4f7b85ccbaa6e3e85f Mon Sep 17 00:00:00 2001 From: Mikhail Gorbushin Date: Fri, 1 Mar 2019 16:03:05 +0300 Subject: [PATCH] [routing] add routing options for UI --- routing/CMakeLists.txt | 2 + routing/route.hpp | 5 ++ routing/routing_options.cpp | 75 +++++++++++++++++++ routing/routing_options.hpp | 42 +++++++++++ .../routing/routing.xcodeproj/project.pbxproj | 8 ++ 5 files changed, 132 insertions(+) create mode 100644 routing/routing_options.cpp create mode 100644 routing/routing_options.hpp diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index a45f433be0..a4dadd147e 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -105,6 +105,8 @@ set( routing_exceptions.hpp routing_helpers.cpp routing_helpers.hpp + routing_options.cpp + routing_options.hpp routing_result_graph.hpp routing_session.cpp routing_session.hpp diff --git a/routing/route.hpp b/routing/route.hpp index 89a0aa5d31..bc687d7a26 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -1,6 +1,7 @@ #pragma once #include "routing/road_graph.hpp" +#include "routing/routing_options.hpp" #include "routing/routing_settings.hpp" #include "routing/segment.hpp" #include "routing/transit_info.hpp" @@ -101,6 +102,8 @@ public: void SetSpeedCameraInfo(std::vector && data) { m_speedCameras = std::move(data); } bool IsRealSegment() const { return m_segment.IsRealSegment(); } std::vector const & GetSpeedCams() const { return m_speedCameras; } + RoutingOptions::Road GetRoadType() const { return m_roadType; } + void SetRoadType(RoutingOptions::Road road) { m_roadType = road; } private: Segment m_segment; @@ -133,6 +136,8 @@ private: // Stored coefficients where they placed at the segment (numbers from 0 to 1) // and theirs' max speed. std::vector m_speedCameras; + + RoutingOptions::Road m_roadType = RoutingOptions::Road::Usual; }; class Route diff --git a/routing/routing_options.cpp b/routing/routing_options.cpp new file mode 100644 index 0000000000..5d2863189f --- /dev/null +++ b/routing/routing_options.cpp @@ -0,0 +1,75 @@ +#include "routing/routing_options.hpp" + +#include "platform/settings.hpp" + +#include "base/assert.hpp" +#include "base/logging.hpp" +#include "base/macros.hpp" + +#include + +namespace routing +{ +std::string const RoutingOptions::kAvoidRoutingOptionSettings = "avoid_routing_options"; + +// static +RoutingOptions RoutingOptions::LoadFromSettings() +{ + RoadType mode = 0; + UNUSED_VALUE(settings::Get(kAvoidRoutingOptionSettings, mode)); + + return RoutingOptions(mode); +} + +void RoutingOptions::Add(RoutingOptions::Road type) +{ + m_options |= static_cast(type); +} + +void RoutingOptions::Remove(RoutingOptions::Road type) +{ + m_options &= ~static_cast(type); +} + +bool RoutingOptions::Has(RoutingOptions::Road type) const +{ + return (m_options & static_cast(type)) != 0; +} + +std::string DebugPrint(RoutingOptions const & routingOptions) +{ + std::ostringstream ss; + ss << "RoutingOptions: {"; + + if (routingOptions.Has(RoutingOptions::Road::Usual)) + ss << " | " << DebugPrint(RoutingOptions::Road::Usual); + + if (routingOptions.Has(RoutingOptions::Road::Toll)) + ss << " | " << DebugPrint(RoutingOptions::Road::Toll); + + if (routingOptions.Has(RoutingOptions::Road::Motorway)) + ss << " | " << DebugPrint(RoutingOptions::Road::Motorway); + + if (routingOptions.Has(RoutingOptions::Road::Ferry)) + ss << " | " << DebugPrint(RoutingOptions::Road::Ferry); + + if (routingOptions.Has(RoutingOptions::Road::Dirty)) + ss << " | " << DebugPrint(RoutingOptions::Road::Dirty); + + ss << "}"; + return ss.str(); +} +std::string DebugPrint(RoutingOptions::Road type) +{ + switch (type) + { + case RoutingOptions::Road::Toll: return "toll"; + case RoutingOptions::Road::Motorway: return "motorway"; + case RoutingOptions::Road::Ferry: return "ferry"; + case RoutingOptions::Road::Dirty: return "dirty"; + case RoutingOptions::Road::Usual: return "usual"; + } + + UNREACHABLE(); +} +} // namespace routing diff --git a/routing/routing_options.hpp b/routing/routing_options.hpp new file mode 100644 index 0000000000..0402a18019 --- /dev/null +++ b/routing/routing_options.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +namespace routing +{ +class RoutingOptions +{ +public: + static std::string const kAvoidRoutingOptionSettings; + + enum class Road : uint8_t + { + Usual = 1u << 0, + Toll = 1u << 1, + Motorway = 1u << 2, + Ferry = 1u << 3, + Dirty = 1u << 4 + }; + + using RoadType = std::underlying_type::type; + + RoutingOptions() = default; + explicit RoutingOptions(RoadType mask) : m_options(mask) {} + + static RoutingOptions LoadFromSettings(); + + void Add(Road type); + void Remove(Road type); + bool Has(Road type) const; + + RoadType GetOptions() const { return m_options; } + +private: + RoadType m_options = 0; +}; + +std::string DebugPrint(RoutingOptions const & routingOptions); +std::string DebugPrint(RoutingOptions::Road type); +} // namespace routing diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index 2bb0744486..aaa22292b9 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -84,6 +84,8 @@ 4408A63E21F1E7F0008171B8 /* joint_segment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4408A63A21F1E7F0008171B8 /* joint_segment.cpp */; }; 44AE4A12214FBB8E006321F5 /* speed_camera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44AE4A10214FBB8D006321F5 /* speed_camera.cpp */; }; 44AE4A13214FBB8E006321F5 /* speed_camera.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 44AE4A11214FBB8D006321F5 /* speed_camera.hpp */; }; + 44C56C0A22296498006C2A1D /* routing_options.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 44C56C0822296498006C2A1D /* routing_options.hpp */; }; + 44C56C0B22296498006C2A1D /* routing_options.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44C56C0922296498006C2A1D /* routing_options.cpp */; }; 44E5574A2136EEC900B01439 /* speed_camera_ser_des.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 44E557492136EEC800B01439 /* speed_camera_ser_des.hpp */; }; 44E5574C2136EED000B01439 /* speed_camera_ser_des.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44E5574B2136EED000B01439 /* speed_camera_ser_des.cpp */; }; 44EB88C4214007AD004E2863 /* speed_camera_notification.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44EB88C2214007A9004E2863 /* speed_camera_notification.cpp */; }; @@ -380,6 +382,8 @@ 4408A63A21F1E7F0008171B8 /* joint_segment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = joint_segment.cpp; sourceTree = ""; }; 44AE4A10214FBB8D006321F5 /* speed_camera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = speed_camera.cpp; sourceTree = ""; }; 44AE4A11214FBB8D006321F5 /* speed_camera.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = speed_camera.hpp; sourceTree = ""; }; + 44C56C0822296498006C2A1D /* routing_options.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = routing_options.hpp; sourceTree = ""; }; + 44C56C0922296498006C2A1D /* routing_options.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_options.cpp; sourceTree = ""; }; 44E557492136EEC800B01439 /* speed_camera_ser_des.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = speed_camera_ser_des.hpp; sourceTree = ""; }; 44E5574B2136EED000B01439 /* speed_camera_ser_des.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = speed_camera_ser_des.cpp; sourceTree = ""; }; 44EB88C2214007A9004E2863 /* speed_camera_notification.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = speed_camera_notification.cpp; sourceTree = ""; }; @@ -816,6 +820,8 @@ 675343FA1A3F640D00A0A8C3 /* routing */ = { isa = PBXGroup; children = ( + 44C56C0922296498006C2A1D /* routing_options.cpp */, + 44C56C0822296498006C2A1D /* routing_options.hpp */, 5610731A221ABF96008447B2 /* speed_camera_prohibition.cpp */, 56107319221ABF96008447B2 /* speed_camera_prohibition.hpp */, 4408A63721F1E7F0008171B8 /* index_graph_starter_joints.cpp */, @@ -1030,6 +1036,7 @@ 0C090C821E4E274000D52AFD /* index_graph_loader.hpp in Headers */, 670EE5721B664796001E8064 /* directions_engine.hpp in Headers */, 56C439291E93BF8C00998E29 /* cross_mwm_graph.hpp in Headers */, + 44C56C0A22296498006C2A1D /* routing_options.hpp in Headers */, 4408A63C21F1E7F0008171B8 /* joint_segment.hpp in Headers */, 0C81E1541F02589800DC66DF /* traffic_stash.hpp in Headers */, 40A111D01F2F9704005E6AD5 /* astar_weight.hpp in Headers */, @@ -1278,6 +1285,7 @@ 0C5FEC641DDE192A0017688C /* joint.cpp in Sources */, 0C090C871E4E276700D52AFD /* world_graph.cpp in Sources */, 4408A63B21F1E7F0008171B8 /* index_graph_starter_joints.cpp in Sources */, + 44C56C0B22296498006C2A1D /* routing_options.cpp in Sources */, 0C5F5D201E798B0400307B98 /* cross_mwm_connector_serialization.cpp in Sources */, 56CA09E71E30E73B00D05C9A /* restriction_test.cpp in Sources */, 0C5BC9D11E28FD4E0071BFDD /* index_road_graph.cpp in Sources */,