File indexing completed on 2024-07-14 03:50:09

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2016 Akshat Tandon <akshat.tandon@research.iiit.ac.in>
0004 //
0005 
0006 #include "WayChunk.h"
0007 
0008 #include <QVector>
0009 #include <QDebug>
0010 
0011 #include "GeoDataCoordinates.h"
0012 #include "GeoDataLineString.h"
0013 #include "OsmPlacemarkData.h"
0014 
0015 namespace Marble {
0016 
0017 WayChunk::WayChunk(const PlacemarkPtr &placemark, qint64 first, qint64 last) :
0018     m_first(first),
0019     m_last(last),
0020     m_visualCategory(placemark->visualCategory()),
0021     m_isTunnel(isTunnel(placemark->osmData()))
0022 {
0023     m_wayList.append(placemark);
0024 }
0025 
0026 WayChunk::~WayChunk()
0027 {
0028 
0029 }
0030 
0031 qint64 WayChunk::first() const
0032 {
0033     return m_first;
0034 }
0035 
0036 qint64 WayChunk::last() const
0037 {
0038     return m_last;
0039 }
0040 
0041 void WayChunk::append(const PlacemarkPtr &placemark, qint64 last)
0042 {
0043     m_wayList.append(placemark);
0044     m_last = last;
0045 
0046 }
0047 
0048 void WayChunk::prepend(const PlacemarkPtr &placemark, qint64 first)
0049 {
0050     m_wayList.prepend(placemark);
0051     m_first = first;
0052 
0053 }
0054 
0055 void WayChunk::append(const WayChunk::Ptr &chunk)
0056 {
0057     m_wayList << chunk->m_wayList;
0058     m_last = chunk->last();
0059 }
0060 
0061 WayChunk::PlacemarkPtr WayChunk::merge()
0062 {
0063     Q_ASSERT(!m_wayList.isEmpty());
0064 
0065     PlacemarkPtr placemark = PlacemarkPtr(new GeoDataPlacemark(*(m_wayList.first())));
0066     GeoDataLineString *line = static_cast<GeoDataLineString*>(placemark->geometry());
0067     QVector<PlacemarkPtr>::iterator itr = m_wayList.begin();
0068     QVector<PlacemarkPtr>::iterator itrEnd = m_wayList.end();
0069     ++itr;
0070     for (; itr != itrEnd; ++itr) {
0071         GeoDataLineString *currentLine = static_cast<GeoDataLineString*>( (*itr)->geometry() );
0072         currentLine->remove(0);
0073         (*line) << *currentLine;
0074     }
0075     return placemark;
0076 }
0077 
0078 void WayChunk::reverse()
0079 {
0080     std::reverse(m_wayList.begin(), m_wayList.end());
0081     QVector<PlacemarkPtr>::iterator itr = m_wayList.begin();
0082     for (; itr != m_wayList.end(); ++itr) {
0083         GeoDataLineString *line = static_cast<GeoDataLineString*>((*itr)->geometry());
0084         line->reverse();
0085     }
0086     qSwap(m_first, m_last);
0087 }
0088 
0089 int WayChunk::size() const
0090 {
0091     return m_wayList.size();
0092 }
0093 
0094 bool WayChunk::concatPossible(const GeoDataPlacemark &placemark) const
0095 {
0096     const GeoDataPlacemark::GeoDataVisualCategory category = placemark.visualCategory();
0097     return category == m_visualCategory && isTunnel(placemark.osmData()) == m_isTunnel;
0098 }
0099 
0100 bool WayChunk::isTunnel(const OsmPlacemarkData &osmData) const
0101 {
0102     if (osmData.containsTagKey(QStringLiteral("tunnel")) &&
0103             !osmData.containsTag(QStringLiteral("tunnel"), QStringLiteral("no"))) {
0104         return true;
0105     }
0106 
0107     return osmData.containsTag(QStringLiteral("covered"), QStringLiteral("yes"));
0108 }
0109 
0110 }