1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2023-05-15
 * Description : geolocation engine based on Marble.
 *               (c) 2007-2022 Marble Team
 *               https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
 *
 * SPDX-FileCopyrightText: 2023-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * ============================================================ */

#include "GeoDataBuilding.h"
#include "GeoDataBuilding_p.h"

// Local includes

#include "GeoDataTypes.h"

namespace Marble
{

GeoDataBuilding::GeoDataBuilding()
    : GeoDataGeometry(new GeoDataBuildingPrivate),
      d              (new GeoDataBuildingPrivate)
{
}

GeoDataBuilding::GeoDataBuilding(const GeoDataGeometry& other)
    : GeoDataGeometry(other),
      d              (new GeoDataBuildingPrivate)
{
}

GeoDataBuilding::GeoDataBuilding(const GeoDataBuilding& other)
    : GeoDataGeometry(other),
      d              (new GeoDataBuildingPrivate(*other.d))
{
}

GeoDataBuilding::~GeoDataBuilding()
{
    delete d;
}

GeoDataBuilding& GeoDataBuilding::operator=(const GeoDataBuilding& other)
{
    GeoDataGeometry::operator=(other);
    *d = *other.d;
    return *this;
}

const char* GeoDataBuilding::nodeType() const
{
    return GeoDataTypes::GeoDataBuildingType;
}

EnumGeometryId GeoDataBuilding::geometryId() const
{
    return GeoDataBuildingId;
}

GeoDataGeometry* GeoDataBuilding::copy() const
{
    return new GeoDataBuilding(*this);
}

double GeoDataBuilding::height() const
{
    return d->m_height;
}

void GeoDataBuilding::setHeight(double height)<--- Shadow argument
{
    d->m_height = height;
}

int GeoDataBuilding::minLevel() const
{
    return d->m_minLevel;
}

void GeoDataBuilding::setMinLevel(int minLevel)<--- Shadow argument
{
    d->m_minLevel = minLevel;
}

int GeoDataBuilding::maxLevel() const
{
    return d->m_maxLevel;
}

void GeoDataBuilding::setMaxLevel(int maxLevel)<--- Shadow argument
{
    d->m_maxLevel = maxLevel;
}

QVector<int> GeoDataBuilding::nonExistentLevels() const
{
    return d->m_nonExistentLevels;
}

void GeoDataBuilding::setNonExistentLevels(const QVector<int>& nonExistentLevels)<--- Shadow argument
{
    d->m_nonExistentLevels = nonExistentLevels;
}

GeoDataMultiGeometry* GeoDataBuilding::multiGeometry() const
{
    return &d->m_multiGeometry;
}

const GeoDataLatLonAltBox& GeoDataBuilding::latLonAltBox() const
{
    // @todo: This is temporary, for only when we have just one child

    Q_ASSERT(d->m_multiGeometry.size() == 1);

    return static_cast<const GeoDataMultiGeometry>(d->m_multiGeometry).at(0).latLonAltBox();
}

QString GeoDataBuilding::name() const
{
    return d->m_name;
}

void GeoDataBuilding::setName(const QString& name)<--- Shadow argument
{
    d->m_name = name;
}

QVector<GeoDataBuilding::NamedEntry> GeoDataBuilding::entries() const
{
    return d->m_entries;
}

void GeoDataBuilding::setEntries(const QVector<GeoDataBuilding::NamedEntry>& entries)<--- Shadow argument
{
    d->m_entries = entries;
}

double GeoDataBuilding::parseBuildingHeight(const QString& buildingHeight)
{
    double height          = 8.0;<--- Shadow local variable

    // check first for unitless value

    bool converted         = false;
    double convertedHeight = buildingHeight.toDouble(&converted);

    if (converted)
    {
        return convertedHeight;
    }

    if (
        buildingHeight.endsWith(QLatin1Char('m'))        ||
        buildingHeight.endsWith(QLatin1String("meter"))  ||
        buildingHeight.endsWith(QLatin1String("meters")) ||
        buildingHeight.endsWith(QLatin1String("metre"))  ||
        buildingHeight.endsWith(QLatin1String("metres"))
       )
    {
        QString const heightValue = QString(buildingHeight).remove(QStringLiteral("meters"))
                                    .remove(QStringLiteral("meter")).remove(QStringLiteral("metres"))
                                    .remove(QStringLiteral("metre")).remove(QLatin1Char('m')).trimmed();
        bool extracted            = false;
        double extractedHeight    = heightValue.toDouble(&extracted);

        if (extracted)
        {
            height = extractedHeight;
        }
    }
    else     // feet and inches
    {
        double extractedHeight = 0.0; // in inches, converted to meters in the end

        if      (buildingHeight.contains(QLatin1Char('\'')))
        {
            double heightInches          = 0.0;
            QStringList const feetInches = buildingHeight.split(QLatin1Char('\''));
            bool okFeet                  = false;
            double feet                  = feetInches[0].trimmed().toDouble(&okFeet);

            if (okFeet)
            {
                heightInches = feet * FT2IN;
            }

            if (!feetInches[1].isEmpty())   // has inches as unit as well
            {
                bool okInches = false;
                double inches = QString(feetInches[1]).remove(QLatin1Char('\"')).trimmed().toDouble(&okInches);

                if (okInches)
                {
                    heightInches += inches;
                }
            }

            extractedHeight = heightInches;
        }
        else if (buildingHeight.endsWith(QLatin1String("feet")))
        {
            bool ok     = false;
            double feet = QString(buildingHeight).remove(QStringLiteral("feet")).trimmed().toDouble(&ok);

            if (ok)
            {
                extractedHeight = feet * FT2IN;
            }
        }

        if (extractedHeight > 0.0)
        {
            height = extractedHeight * IN2M; // convert inches to meters
        }
    }

    return height;
}

} // namespace Marble