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 QString RouteSegment::earthDirection() const
48 qDebug() << __PRETTY_FUNCTION__;
50 return m_earthDirection;
53 QString RouteSegment::instruction() const
55 qDebug() << __PRETTY_FUNCTION__;
60 qreal RouteSegment::length() const
62 qDebug() << __PRETTY_FUNCTION__;
67 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(QString direction)
90 qDebug() << __PRETTY_FUNCTION__;
92 m_earthDirection = direction;
95 void RouteSegment::setInstruction(QString instruction)
97 qDebug() << __PRETTY_FUNCTION__;
99 m_instruction = instruction;
102 void RouteSegment::setLength(qreal meters)
104 qDebug() << __PRETTY_FUNCTION__;
109 void RouteSegment::setLengthCaption(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(QString type)
139 qDebug() << __PRETTY_FUNCTION__;
144 QString RouteSegment::street() const
146 qDebug() << __PRETTY_FUNCTION__;
148 // regular expressions for matching/replacing instructions
149 const QString REGEXP_1ST_SEGMENT
150 = "^Head (north|northeast|east|southeast|south|southwest|west|northwest)";
151 const QString REGEXP_CONTINUE = "^Continue";
152 const QString REGEXP_ROUNDABOUT
153 = "^At the roundabout, take the \\d(st|nd|rd|th) exit";
154 const QString REGEXP_TURNS = "^(Turn|Slight|Sharp) (left|right)";
155 const QString REGEXP_U_TURN = "^Make a U-turn";
157 QString result = m_instruction;
159 // cut beginning of the instruction
160 // (but only if it matches with the expected value)
162 if (m_turnType == "") {
163 // first segment (without turn type code)
164 QRegExp regexp(REGEXP_1ST_SEGMENT);
165 result.replace(regexp, "");
167 } else if (m_turnType == "C") {
169 QRegExp regexp(REGEXP_CONTINUE);
170 result.replace(regexp, "");
172 } else if ((m_turnType == "TL") || (m_turnType == "TSLL")
173 || (m_turnType == "TSHL") || (m_turnType == "TR")
174 || (m_turnType == "TSLR") || (m_turnType == "TSHR")) {
176 QRegExp regexp(REGEXP_TURNS);
177 result.replace(regexp, "");
179 } else if (m_turnType == "TU") {
181 QRegExp regexp(REGEXP_U_TURN);
182 result.replace(regexp, "");
184 } else if (m_turnType.startsWith("EXIT")) {
186 QRegExp regexp(REGEXP_ROUNDABOUT);
187 result.replace(regexp, "");
190 // no match, parsing failed
191 qCritical() << __PRETTY_FUNCTION__ << "PARSING FAILED! ( turn type:"
192 << m_turnType << "instruction:" << m_instruction << ")";
195 // replace on/at/onto words at the beginning of the result
196 // with zero or one leading space and one following space
197 QRegExp regexp("^ ?(on|at|onto) ");
198 result.replace(regexp, "");
203 int RouteSegment::time() const
205 qDebug() << __PRETTY_FUNCTION__;
207 return m_timeSeconds;
210 qreal RouteSegment::turnAngle() const
212 qDebug() << __PRETTY_FUNCTION__;
217 QString RouteSegment::turnType() const
219 qDebug() << __PRETTY_FUNCTION__;