File indexing completed on 2024-05-12 03:50:41

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_ROUTINGINSTRUCTION_H
0007 #define MARBLE_ROUTINGINSTRUCTION_H
0008 
0009 #include "RoutingWaypoint.h"
0010 #include "RoutingPoint.h"
0011 #include "marble_export.h"
0012 
0013 #include <QVector>
0014 #include <QMetaType>
0015 
0016 class QTextStream;
0017 
0018 namespace Marble
0019 {
0020 
0021 /**
0022   * Stores data related to one instruction: Road name, angle to predecessor,
0023   * associated waypoints etc. Can be streamed directly to a QTextStream.
0024   */
0025 class MARBLE_EXPORT RoutingInstruction
0026 {
0027 public:
0028     enum TurnType {
0029         Unknown = 0,
0030         Continue = 13 /** Continue on the next street */,
0031         Merge = 14,
0032         Straight = 1,
0033         SlightRight = 2,
0034         Right = 3,
0035         SharpRight = 4,
0036         TurnAround = 5 /** Perform a u-turn */,
0037         SharpLeft = 6,
0038         Left = 7,
0039         SlightLeft = 8,
0040         RoundaboutFirstExit = 9 /** Enter the roundabout and leave at the first exit */,
0041         RoundaboutSecondExit = 10 /** Enter the roundabout and leave at the second exit */,
0042         RoundaboutThirdExit = 11 /** Enter the roundabout and leave at the third exit */,
0043         RoundaboutExit = 12 /** At the point where the roundabout should be exited */,
0044         ExitLeft = 15,
0045         ExitRight = 16
0046     };
0047 
0048     /** Constructor */
0049     explicit RoutingInstruction( const RoutingWaypoint &item = RoutingWaypoint() );
0050 
0051     /**
0052       * Append data of the given item, returns true if item's street
0053       * name matches instructions street name
0054       */
0055     bool append( const RoutingWaypoint &item, int angle );
0056 
0057     /** Name of the road to turn into */
0058     QString roadName() const;
0059 
0060     /** OSM type of the road to turn into */
0061     QString roadType() const;
0062 
0063     /** Estimated number of seconds to the route destination */
0064     int secondsLeft() const;
0065 
0066     /** Waypoints from the last instruction to this instruction */
0067     QVector<RoutingWaypoint> points() const;
0068 
0069     /**
0070       * Contains the intersection point and points near it on the previous and current road.
0071       * Near is taken as that waypoint with the largest different to the intersection point
0072       * that does not exceed 50 meter.
0073       */
0074     QVector<RoutingPoint> intersectionPoints() const;
0075 
0076     /** The angle between the two turn roads, in radians */
0077     qreal angleToPredecssor() const;
0078 
0079     /** Previous turn road. Will be 0 for the first one (route start) */
0080     RoutingInstruction* predecessor();
0081 
0082     /** Const overload for #predecessor */
0083     const RoutingInstruction* predecessor() const;
0084 
0085     /** Change the predecessor */
0086     void setPredecessor( RoutingInstruction* predecessor );
0087 
0088     /** Next turn road. Will be 0 for the last one (destination) */
0089     RoutingInstruction* successor();
0090 
0091     /** Const overload for #successor */
0092     const RoutingInstruction* successor() const;
0093 
0094     /** Change the successor */
0095     void setSuccessor( RoutingInstruction* successor );
0096 
0097     /** The accumulated distance of all waypoints belonging to this instruction */
0098     qreal distance() const;
0099 
0100     /** The distance from the route start */
0101     qreal distanceFromStart() const;
0102 
0103     /** The distance to the route end. Includes the own distance */
0104     qreal distanceToEnd() const;
0105 
0106     TurnType turnType() const;
0107 
0108     /** Formats the instruction (road name) for a human reader */
0109     QString nextRoadInstruction() const;
0110 
0111     /** Formats the instruction (distance to next instruction) for a human reader */
0112     QString nextDistanceInstruction() const;
0113 
0114     /** Formats the instruction (duration to destination) for a human reader */
0115     QString totalDurationRemaining() const;
0116 
0117     /** Formats the instruction for a human reader */
0118     QString instructionText() const;
0119 
0120     static QString generateRoadInstruction( TurnType turnType, const QString &roadName );
0121 
0122 protected:
0123     int roundaboutExitNumber() const;
0124 
0125 private:
0126     void calculateAngle();
0127 
0128     void calculateTurnType();
0129 
0130     QVector<RoutingWaypoint> m_points;
0131 
0132     QVector<RoutingPoint> m_intersectionPoints;
0133 
0134     QString m_roadName;
0135 
0136     QString m_roadType;
0137 
0138     int m_secondsLeft;
0139 
0140     qreal m_angleToPredecessor;
0141 
0142     TurnType m_turnType;
0143 
0144     int m_roundaboutExit;
0145 
0146     RoutingInstruction* m_predecessor;
0147 
0148     RoutingInstruction* m_successor;
0149 };
0150 
0151 QTextStream& operator<<( QTextStream& stream, const RoutingInstruction &i );
0152 
0153 using RoutingInstructions = QVector<RoutingInstruction>;
0154 
0155 } // namespace Marble
0156 
0157 Q_DECLARE_METATYPE( Marble::RoutingInstruction::TurnType )
0158 
0159 #endif // MARBLE_ROUTINGINSTRUCTION_H