2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "routingcommon.h"
27 #include "routesegment.h"
29 RouteSegment::RouteSegment()
30 : m_timeSeconds(ROUTING_VALUE_UNDEFINED),
31 m_positionIndex(ROUTING_VALUE_UNDEFINED),
32 m_azimuth(ROUTING_VALUE_UNDEFINED),
33 m_length(ROUTING_VALUE_UNDEFINED),
34 m_turnAngle(ROUTING_VALUE_UNDEFINED)
36 qDebug() << __PRETTY_FUNCTION__;
39 qreal RouteSegment::azimuth() const
41 qDebug() << __PRETTY_FUNCTION__;
46 const QString& RouteSegment::earthDirection() const
48 qDebug() << __PRETTY_FUNCTION__;
50 return m_earthDirection;
53 const QString& RouteSegment::instruction() const
55 qDebug() << __PRETTY_FUNCTION__;
60 qreal RouteSegment::length() const
62 qDebug() << __PRETTY_FUNCTION__;
67 const QString& RouteSegment::lengthCaption() const
69 qDebug() << __PRETTY_FUNCTION__;
71 return m_lengthCaption;
74 int RouteSegment::positionIndex() const
76 qDebug() << __PRETTY_FUNCTION__;
78 return m_positionIndex;
81 void RouteSegment::setAzimuth(qreal azimuth)
83 qDebug() << __PRETTY_FUNCTION__;
88 void RouteSegment::setEarthDirection(const QString &direction)
90 qDebug() << __PRETTY_FUNCTION__;
92 m_earthDirection = direction;
95 void RouteSegment::setInstruction(const QString &instruction)
97 qDebug() << __PRETTY_FUNCTION__;
99 m_instruction = instruction;
102 void RouteSegment::setLength(qreal meters)
104 qDebug() << __PRETTY_FUNCTION__;
109 void RouteSegment::setLengthCaption(const QString &length)
111 qDebug() << __PRETTY_FUNCTION__;
113 m_lengthCaption = length;
116 void RouteSegment::setPositionIndex(int index)
118 qDebug() << __PRETTY_FUNCTION__;
120 m_positionIndex = index;
123 void RouteSegment::setTime(int seconds)
125 qDebug() << __PRETTY_FUNCTION__;
127 m_timeSeconds = seconds;
130 void RouteSegment::setTurnAngle(qreal degrees)
132 qDebug() << __PRETTY_FUNCTION__;
134 m_turnAngle = degrees;
137 void RouteSegment::setTurnType(const QString &type)
139 qDebug() << __PRETTY_FUNCTION__;
144 QString RouteSegment::street() const
146 qDebug() << __PRETTY_FUNCTION__;
149 const QString TURN_TYPE_CONTINUE = "C";
150 const QString TURN_TYPE_LEFT = "TL";
151 const QString TURN_TYPE_SLIGHT_LEFT = "TSLL";
152 const QString TURN_TYPE_SHARP_LEFT = "TSHL";
153 const QString TURN_TYPE_RIGHT = "TR";
154 const QString TURN_TYPE_SLIGHT_RIGHT = "TSLR";
155 const QString TURN_TYPE_SHARP_RIGHT = "TSHR";
156 const QString TURN_TYPE_U_TURN = "TU";
157 const QString TURN_TYPE_ROUNDABOUT = "EXIT";
159 // regular expressions for matching/replacing instructions
160 const QString REGEXP_1ST_SEGMENT
161 = "^Head (north|northeast|east|southeast|south|southwest|west|northwest)";
162 const QString REGEXP_CONTINUE = "^Continue";
163 const QString REGEXP_ROUNDABOUT
164 = "^At the roundabout, take the \\d(st|nd|rd|th) exit";
165 const QString REGEXP_TURNS = "^(Turn|Slight|Sharp) (left|right)";
166 const QString REGEXP_U_TURN = "^Make a U-turn";
168 QString result = m_instruction;
170 // cut beginning of the instruction
171 // (but only if it matches with the expected value)
173 if (m_turnType.isEmpty()) {
174 // first segment (without turn type code)
175 QRegExp regexp(REGEXP_1ST_SEGMENT);
176 result.replace(regexp, "");
178 } else if (m_turnType == TURN_TYPE_CONTINUE) {
180 QRegExp regexp(REGEXP_CONTINUE);
181 result.replace(regexp, "");
183 } else if ((m_turnType == TURN_TYPE_LEFT) || (m_turnType == TURN_TYPE_SLIGHT_LEFT)
184 || (m_turnType == TURN_TYPE_SHARP_LEFT) || (m_turnType == TURN_TYPE_RIGHT)
185 || (m_turnType == TURN_TYPE_SLIGHT_RIGHT) || (m_turnType == TURN_TYPE_SHARP_RIGHT)) {
187 QRegExp regexp(REGEXP_TURNS);
188 result.replace(regexp, "");
190 } else if (m_turnType == TURN_TYPE_U_TURN) {
192 QRegExp regexp(REGEXP_U_TURN);
193 result.replace(regexp, "");
195 } else if (m_turnType.startsWith(TURN_TYPE_ROUNDABOUT)) {
197 QRegExp regexp(REGEXP_ROUNDABOUT);
198 result.replace(regexp, "");
203 // replace on/at/onto words at the beginning of the result
204 // with zero or one leading space and one following space
205 QRegExp regexp("^ ?(on|at|onto) ");
206 result.replace(regexp, "");
211 int RouteSegment::time() const
213 qDebug() << __PRETTY_FUNCTION__;
215 return m_timeSeconds;
218 qreal RouteSegment::turnAngle() const
220 qDebug() << __PRETTY_FUNCTION__;
225 const QString& RouteSegment::turnType() const
227 qDebug() << __PRETTY_FUNCTION__;