Files
comaps/libs/routing/routing_callbacks.hpp
mvglasow f7882636cd [traffic] Documentation
Signed-off-by: mvglasow <michael -at- vonglasow.com>
2025-11-08 16:28:34 +02:00

157 lines
5.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "routing/turns.hpp"
#include "geometry/latlon.hpp"
#include "geometry/point2d.hpp"
#include "base/assert.hpp"
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <string>
namespace routing
{
class Route;
/// Routing possible statuses enumeration.
/// \warning this enum has JNI mirror!
/// \see android/src/app/organicmaps/maps/routing/ResultCodesHelper.java
// TODO(bykoianko): Items become obsolete now should be removed from the enum.
enum class RouterResultCode
{
NoError = 0,
Cancelled = 1,
NoCurrentPosition = 2,
InconsistentMWMandRoute = 3,
RouteFileNotExist = 4,
StartPointNotFound = 5,
EndPointNotFound = 6,
PointsInDifferentMWM = 7,
RouteNotFound = 8,
NeedMoreMaps = 9,
InternalError = 10,
FileTooOld = 11,
IntermediatePointNotFound = 12,
TransitRouteNotFoundNoNetwork = 13,
TransitRouteNotFoundTooLongPedestrian = 14,
RouteNotFoundRedressRouteError = 15,
HasWarnings = 16,
};
enum class SessionState
{
/**
* No valid route: no route after application launching, or the route was removed.
*
* This is the initial state at launch; in order to get out of it, a destination must be set AND
* the current location must be obtained.
*/
NoValidRoute,
/**
* We have requested a route and are waiting for it to be built. User may be following the previous route.
*/
RouteBuilding,
/**
* Route is built but the user isn't on it.
*/
RouteNotStarted,
/**
* User is following the route.
*/
OnRoute,
/**
* User has left the route.
*/
RouteNeedRebuild,
/**
* Destination point has been reached but the session isnt closed yet.
*/
RouteFinished,
/**
* Route has been built but following mode has been disabled.
*/
RouteNoFollowing,
/**
* We have requested a route rebuild and are waiting for it to be rebuilt. User may be following
* the previous route.
*/
RouteRebuilding,
};
/*
* NoValidRoute -> RouteBuilding // start route building
* RouteBuilding -> RouteNotStarted // route is built in case of building a new route
* RouteRebuilding -> RouteNotStarted // route is built in case of rebuilding
* RouteNotStarted -> OnRoute // user started following the route
* RouteNotStarted -> RouteNeedRebuild // user doesn't like the route.
* OnRoute -> RouteNeedRebuild // user moves away from route - need to rebuild
* RouteNeedRebuild -> RouteRebuilding // the route is in process of rebuilding or
* // while rebuilding an error happens
* RouteRebuilding -> OnRoute // following along route after rebuilding
* OnRoute -> RouteNoFollowing // following mode was disabled. Router doesn't track position
* OnRoute -> RouteFinished // user reached the end of route
* OnRoute -> RouteBuilding // while moving along a route user makes a new route
*/
using CheckpointCallback = std::function<void(size_t passedCheckpointIdx)>;
using NeedMoreMapsCallback = std::function<void(uint64_t, std::set<std::string> const &)>;
using PointCheckCallback = std::function<void(ms::LatLon const &)>;
using ProgressCallback = std::function<void(float)>;
using ReadyCallback = std::function<void(Route const &, RouterResultCode)>;
using ReadyCallbackOwnership = std::function<void(std::shared_ptr<Route>, RouterResultCode)>;
using RemoveRouteCallback = std::function<void(RouterResultCode)>;
using RouteCallback = std::function<void(Route const &)>;
using ChangeSessionStateCallback = std::function<void(SessionState previous, SessionState current)>;
using SpeedCameraShowCallback = std::function<void(m2::PointD const & point, double cameraSpeedKmPH)>;
using SpeedCameraClearCallback = std::function<void()>;
using OnNewTurn = std::function<void()>;
inline std::string ToString(RouterResultCode code)
{
switch (code)
{
case RouterResultCode::NoError: return "NoError";
case RouterResultCode::Cancelled: return "Cancelled";
case RouterResultCode::NoCurrentPosition: return "NoCurrentPosition";
case RouterResultCode::InconsistentMWMandRoute: return "InconsistentMWMandRoute";
case RouterResultCode::RouteFileNotExist: return "RouteFileNotExist";
case RouterResultCode::StartPointNotFound: return "StartPointNotFound";
case RouterResultCode::EndPointNotFound: return "EndPointNotFound";
case RouterResultCode::PointsInDifferentMWM: return "PointsInDifferentMWM";
case RouterResultCode::RouteNotFound: return "RouteNotFound";
case RouterResultCode::InternalError: return "InternalError";
case RouterResultCode::NeedMoreMaps: return "NeedMoreMaps";
case RouterResultCode::FileTooOld: return "FileTooOld";
case RouterResultCode::IntermediatePointNotFound: return "IntermediatePointNotFound";
case RouterResultCode::TransitRouteNotFoundNoNetwork: return "TransitRouteNotFoundNoNetwork";
case RouterResultCode::TransitRouteNotFoundTooLongPedestrian: return "TransitRouteNotFoundTooLongPedestrian";
case RouterResultCode::RouteNotFoundRedressRouteError: return "RouteNotFoundRedressRouteError";
case RouterResultCode::HasWarnings: return "HasWarnings";
}
std::string result = "Unknown RouterResultCode: " + std::to_string(static_cast<int>(code));
ASSERT(false, (result));
return result;
}
inline std::string DebugPrint(RouterResultCode code)
{
return ToString(code);
}
// This define should be set to see the spread of A* waves on the map.
// #define SHOW_ROUTE_DEBUG_MARKS
} // namespace routing