diff --git a/gpxsee.pro b/gpxsee.pro index 29183b9e..7dfebcaa 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -118,7 +118,7 @@ HEADERS += src/common/config.h \ src/data/gpsdumpparser.h \ src/data/style.h \ src/data/twonavparser.h \ - src/map/IMG/lights.h \ + src/map/IMG/light.h \ src/map/downloader.h \ src/map/demloader.h \ src/map/ENC/attributes.h \ diff --git a/src/map/IMG/lights.h b/src/map/IMG/light.h similarity index 54% rename from src/map/IMG/lights.h rename to src/map/IMG/light.h index c1265801..00c8fc0e 100644 --- a/src/map/IMG/lights.h +++ b/src/map/IMG/light.h @@ -1,18 +1,18 @@ -#ifndef IMG_LIGHTS_H -#define IMG_LIGHTS_H +#ifndef IMG_LIGHT_H +#define IMG_LIGHT_H #include #include namespace IMG { -class Lights +struct Light { -public: enum Color {None, Red, Green, White, Blue, Yellow, Violet, Amber}; struct Sector { + public: Sector() : color(None), angle(0), range(0) {} Sector(Color color, quint32 angle, quint32 range) : color(color), angle(angle), range(range) {} @@ -22,9 +22,10 @@ public: quint32 range; }; - Lights() : color(None), range(0) {} - bool isSectorLight() const - {return ((color && range > 6) || !sectors.isEmpty());} + Light() : color(None), range(0) {} + Light(Color color, quint32 range) : color(color), range(range) {} + Light(const QVector §ors) + : color(None), range(0), sectors(sectors) {} Color color; quint32 range; @@ -34,19 +35,19 @@ public: } #ifndef QT_NO_DEBUG -inline QDebug operator<<(QDebug dbg, const IMG::Lights::Sector §or) +inline QDebug operator<<(QDebug dbg, const IMG::Light::Sector §or) { dbg.nospace() << "Sector(" << sector.color << ", " << sector.angle << ", " << sector.range << ")"; return dbg.space(); } -inline QDebug operator<<(QDebug dbg, const IMG::Lights &lights) +inline QDebug operator<<(QDebug dbg, const IMG::Light &light) { - dbg.nospace() << "Lights(" << lights.color << ", " << lights.range << ", " - << lights.sectors << ")"; + dbg.nospace() << "Light(" << light.color << ", " << light.range << ", " + << light.sectors << ")"; return dbg.space(); } #endif // QT_NO_DEBUG -#endif // IMG_LIGHTS_H +#endif // IMG_LIGHT_H diff --git a/src/map/IMG/mapdata.h b/src/map/IMG/mapdata.h index 4f591e98..3920ef24 100644 --- a/src/map/IMG/mapdata.h +++ b/src/map/IMG/mapdata.h @@ -14,7 +14,7 @@ #include "map/matrix.h" #include "label.h" #include "raster.h" -#include "lights.h" +#include "light.h" #include "zoom.h" namespace IMG { @@ -56,7 +56,7 @@ public: Coordinates coordinates; Label label; - Lights lights; + QVector lights; quint64 id; quint32 type; quint32 flags; diff --git a/src/map/IMG/rastertile.cpp b/src/map/IMG/rastertile.cpp index 82664113..7a49ee17 100644 --- a/src/map/IMG/rastertile.cpp +++ b/src/map/IMG/rastertile.cpp @@ -19,6 +19,7 @@ using namespace IMG; #define TEXT_EXTENT 160 #define ICON_PADDING 2 #define RANGE_FACTOR 4 +#define RANGE_MIN 6 #define ROAD 0 #define WATER 1 @@ -228,8 +229,8 @@ void RasterTile::drawTextItems(QPainter *painter, static QRect lightRect(const QPoint &pos, quint32 range) { - return QRect(pos.x() - range * RANGE_FACTOR, pos.y() - range * RANGE_FACTOR, - 2*range * RANGE_FACTOR, 2*range * RANGE_FACTOR); + quint32 r = qMin(range * RANGE_FACTOR, (quint32)TEXT_EXTENT); + return QRect(pos.x() - r, pos.y() - r, 2 * r, 2 * r); } void RasterTile::drawSectorLights(QPainter *painter, @@ -239,48 +240,54 @@ void RasterTile::drawSectorLights(QPainter *painter, const MapData::Point *p = lights.at(i); QPoint pos(p->coordinates.lon(), p->coordinates.lat()); - if (p->lights.sectors.size()) { - for (int j = 0; j < p->lights.sectors.size(); j++) { - const Lights::Sector &start = p->lights.sectors.at(j); - const Lights::Sector &end = (j == p->lights.sectors.size() - 1) - ? p->lights.sectors.at(0) : p->lights.sectors.at(j+1); + for (int j = 0; j < p->lights.size(); j++) { + const Light &l = p->lights.at(j); - if (start.color) { - double a1 = -(end.angle / 10.0 + 90.0); - double a2 = -(start.angle / 10.0 + 90.0); - if (a1 > a2) - a2 += 360; - double as = (a2 - a1); - if (as == 0) - as = 360; + if (l.sectors.size()) { + for (int k = 0; k < l.sectors.size(); k++) { + const Light::Sector &start = l.sectors.at(k); + const Light::Sector &end = (k == l.sectors.size() - 1) + ? l.sectors.at(0) : l.sectors.at(k+1); - QRect rect(lightRect(pos, start.range ? start.range : 6)); + if (start.color) { + double a1 = -(end.angle / 10.0 + 90.0); + double a2 = -(start.angle / 10.0 + 90.0); + if (a1 > a2) + a2 += 360; + double as = (a2 - a1); + if (as == 0) + as = 360; - painter->setPen(QPen(Qt::black, 6, Qt::SolidLine, - Qt::FlatCap)); - painter->drawArc(rect, a1 * 16, as * 16); - painter->setPen(QPen(Style::color(start.color), 4, - Qt::SolidLine, Qt::FlatCap)); - painter->drawArc(rect, a1 * 16, as * 16); + QRect rect(lightRect(pos, start.range + ? start.range : RANGE_MIN)); - if (a2 - a1 != 0) { - QLineF ln(pos, QPointF(pos.x() + rect.width(), pos.y())); - ln.setAngle(a1); - painter->setPen(QPen(Qt::black, 1, Qt::DashLine)); - painter->drawLine(ln); - ln.setAngle(a2); - painter->drawLine(ln); + painter->setPen(QPen(Qt::black, 6, Qt::SolidLine, + Qt::FlatCap)); + painter->drawArc(rect, a1 * 16, as * 16); + painter->setPen(QPen(Style::color(start.color), 4, + Qt::SolidLine, Qt::FlatCap)); + painter->drawArc(rect, a1 * 16, as * 16); + + if (a2 - a1 != 0) { + QLineF ln(pos, QPointF(pos.x() + rect.width(), + pos.y())); + ln.setAngle(a1); + painter->setPen(QPen(Qt::black, 1, Qt::DashLine)); + painter->drawLine(ln); + ln.setAngle(a2); + painter->drawLine(ln); + } } } - } - } else { - QRect rect(lightRect(pos, p->lights.range)); + } else if (l.range > RANGE_MIN) { + QRect rect(lightRect(pos, l.range)); - painter->setPen(QPen(Qt::black, 6, Qt::SolidLine, Qt::FlatCap)); - painter->drawArc(rect, 0, 360 * 16); - painter->setPen(QPen(Style::color(p->lights.color), 4, - Qt::SolidLine, Qt::FlatCap)); - painter->drawArc(rect, 0, 360 * 16); + painter->setPen(QPen(Qt::black, 6, Qt::SolidLine, Qt::FlatCap)); + painter->drawArc(rect, 0, 360 * 16); + painter->setPen(QPen(Style::color(l.color), 4, Qt::SolidLine, + Qt::FlatCap)); + painter->drawArc(rect, 0, 360 * 16); + } } } } @@ -456,6 +463,17 @@ void RasterTile::processShields(const QList &lines, } } +static bool showAsSector(const QVector &lights) +{ + for (int i = 0; i < lights.size(); i++) { + const Light &l = lights.at(i); + if ((l.color && l.range > RANGE_MIN) || !l.sectors.isEmpty()) + return true; + } + + return false; +} + void RasterTile::processPoints(QList &points, QList &textItems, QList &lights) { @@ -466,8 +484,9 @@ void RasterTile::processPoints(QList &points, const Style *style = _data->style(); const Style::Point &ps = style->point(point.type); bool poi = Style::isPOI(point.type); + bool sl = showAsSector(point.lights); - if (point.lights.isSectorLight()) + if (sl) lights.append(&point); const QString *label = point.label.text().isEmpty() @@ -490,12 +509,16 @@ void RasterTile::processPoints(QList &points, TextPointItem *item = new TextPointItem(pos + offset, label, fnt, img, color, hcolor, 0, ICON_PADDING); - if (item->isValid() && (point.lights.isSectorLight() - || !item->collides(textItems))) { + if (item->isValid() && (sl || !item->collides(textItems))) { textItems.append(item); - if (point.lights.color && !point.lights.isSectorLight()) - textItems.append(new TextPointItem(pos + style->lightOffset(), - 0, 0, style->light(point.lights.color), 0, 0, 0, 0)); + for (int j = 0; j < point.lights.size(); j++) { + const Light &l = point.lights.at(j); + if (l.color && l.range <= RANGE_MIN) { + textItems.append(new TextPointItem(pos + style->lightOffset(), + 0, 0, style->light(l.color), 0, 0, 0, 0)); + break; + } + } } else delete item; } diff --git a/src/map/IMG/rgnfile.cpp b/src/map/IMG/rgnfile.cpp index 06760059..0deb400a 100644 --- a/src/map/IMG/rgnfile.cpp +++ b/src/map/IMG/rgnfile.cpp @@ -124,7 +124,7 @@ bool RGNFile::readBuoyInfo(Handle &hdl, quint8 flags, quint32 size, lc = (val >> 6) & 7; if (lc) - point->lights.color = (Lights::Color)lc; + point->lights.append(Light((Light::Color)lc, 0)); return true; } @@ -190,6 +190,7 @@ bool RGNFile::readLightInfo(Handle &hdl, quint8 flags, quint32 size, if (flags1 & 0x800) { quint16 la; quint8 cf, range = 0; + QVector sectors; do { if (!(size >= 2 && readUInt16(hdl, la))) @@ -197,14 +198,16 @@ bool RGNFile::readLightInfo(Handle &hdl, quint8 flags, quint32 size, size -= 2; cf = la >> 8; - Lights::Color c = (Lights::Color)(cf >> 4 & 7); + Light::Color c = (Light::Color)(cf >> 4 & 7); if (c) { if (!(size >= 1 && readUInt8(hdl, range))) return false; size--; } - point->lights.sectors.append(Lights::Sector(c, la & 0xfff, range)); + sectors.append(Light::Sector(c, la & 0xfff, range)); } while (!(cf >> 7)); + + point->lights.append(Light(sectors)); } else { quint8 v1, v2, range; @@ -220,8 +223,7 @@ bool RGNFile::readLightInfo(Handle &hdl, quint8 flags, quint32 size, range += v2; } - point->lights.color = (Lights::Color)(v1 >> 5); - point->lights.range = range; + point->lights.append(Light((Light::Color)(v1 >> 5), range)); } return true; @@ -289,8 +291,153 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, return seek(hdl, off + rs); } -bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const +bool RGNFile::readLclNavaid(Handle &hdl, quint32 size, + MapData::Point *point) const { + quint32 unused, flags; + + if (!(size >= 4 && readUInt32(hdl, flags))) + return false; + size -= 4; + if (flags & 1) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + } + if (flags & 2) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + } + if (flags & 4) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + } + if (flags & 8) { + if (!(size >= 3 && readUInt24(hdl, unused))) + return false; + size -= 3; + } + if (flags & 0x10) { + if (!(size >= 3 && readUInt24(hdl, unused))) + return false; + size -= 3; + } + if (flags & 0x20) { + if (!(size >= 3 && readUInt24(hdl, unused))) + return false; + size -= 3; + } + if (flags & 0x200) { + quint8 b; + do { + if (!(size >= 1 && readUInt8(hdl, b))) + return false; + size--; + } while (b & 0x80); + } + + quint8 lights = (flags >> 6) & 7; + + for (quint32 i = 0; i < lights; i ++) { + quint32 fs, vs, lflags; + Light light; + + if (!(readVUInt32(hdl, fs, &vs) && size >= vs)) + return false; + size -= vs; + if (!(size >= 4 && readUInt32(hdl, lflags))) + return false; + size -= 4; + if (lflags >> 0x11 & 3) { + if (!(size >= (lflags >> 0x11 & 3) + && readVUInt32(hdl, lflags >> 0x11 & 3, unused))) + return false; + size -= (lflags >> 0x11 & 3); + } + if (lflags & 0x3000) { + if (lflags & 0x2000) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + unused |= (lflags >> 4) & 0x100; + } else { + if (!(size >= 2 && readUInt16(hdl, unused))) + return false; + size -= 2; + } + } + if (lflags & 0x100000) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + if (unused & 0x80) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + } + } + + quint8 sectors = lflags & 0x1f; + + for (quint32 j = 0; j < sectors; j++) { + quint32 cf, range = 0; + + if (!(size >= 1 && readUInt8(hdl, cf))) + return false; + size--; + if (cf >> 6) { + if (!(size >= (cf >> 6) && readVUInt32(hdl, cf >> 6, range))) + return false; + size -= (cf >> 6); + } + + if (sectors > 1) { + quint32 angle; + + if (!(size >= 2 && readUInt16(hdl, angle))) + return false; + size -= 2; + if ((lflags >> 0x13) & 1) { + quint32 sflags; + + if (!(size >= 1 && readUInt8(hdl, sflags))) + return false; + size--; + if (0x3f < sflags) { + if (sflags & 0x80) { + if (!(size >= 1 && readUInt8(hdl, unused))) + return false; + size--; + unused |= (sflags & 0x40) << 2; + } else { + if (!(size >= 2 && readUInt16(hdl, unused))) + return false; + size -= 2; + } + } + } + + light.sectors.append(Light::Sector((Light::Color)(cf & 0x7), + angle, range)); + } else { + light.color = (Light::Color)(cf & 0x7); + light.range = range; + } + } + + point->lights.append(light); + } + + return (size == 0); +} + +bool RGNFile::readLclFields(Handle &hdl, const quint32 flags[3], + SegmentType segmentType, void *object) const +{ + MapData::Point *point = (segmentType == Point) + ? (MapData::Point *) object : 0; quint32 bitfield = 0xFFFFFFFF; if (flags[0] & 0x20000000) @@ -302,14 +449,21 @@ bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const if (bitfield & 1) { quint32 m = flags[(j >> 4) + 1] >> ((j * 2) & 0x1e) & 3; - quint32 skip = 0; + quint32 size = 0; if (m == 3) { - if (!readVUInt32(hdl, skip)) + if (!readVUInt32(hdl, size)) return false; } else - skip = m + 1; - if (!seek(hdl, pos(hdl) + skip)) - return false; + size = m + 1; + + if (i == 2 && point) { + point->lights.clear(); + if (!readLclNavaid(hdl, size, point)) + return false; + } else { + if (!seek(hdl, pos(hdl) + size)) + return false; + } } bitfield >>= 1; j++; @@ -563,8 +717,8 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, if (subtype & 0x80 && !readClassFields(hdl, segmentType, &poly, lbl, lblHdl)) return false; - if (subtype & 0x40 && !skipLclFields(hdl, segmentType == Line - ? _linesLclFlags : _polygonsLclFlags)) + if (subtype & 0x40 && !readLclFields(hdl, segmentType == Line + ? _linesLclFlags : _polygonsLclFlags, segmentType, &poly)) return false; quint32 gblFlags = (segmentType == Line) ? _linesGblFlags : _polygonsGblFlags; @@ -654,7 +808,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv, return false; if (subtype & 0x80 && !readClassFields(hdl, Point, &point, lbl, lblHdl)) return false; - if (subtype & 0x40 && !skipLclFields(hdl, _pointsLclFlags)) + if (subtype & 0x40 && !readLclFields(hdl, _pointsLclFlags, Point, &point)) return false; if (_pointsGblFlags && !skipGblFields(hdl, _pointsGblFlags)) return false; diff --git a/src/map/IMG/rgnfile.h b/src/map/IMG/rgnfile.h index fc739010..fd19b97a 100644 --- a/src/map/IMG/rgnfile.h +++ b/src/map/IMG/rgnfile.h @@ -56,7 +56,8 @@ private: bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const; bool readClassFields(Handle &hdl, SegmentType segmentType, void *object, LBLFile *lbl, Handle &lblHdl) const; - bool skipLclFields(Handle &hdl, const quint32 flags[3]) const; + bool readLclFields(Handle &hdl, const quint32 flags[3], + SegmentType segmentType, void *object) const; bool skipGblFields(Handle &hdl, quint32 flags) const; bool readRasterInfo(Handle &hdl, const LBLFile *lbl, quint32 size, MapData::Poly *poly) const; @@ -70,6 +71,8 @@ private: MapData::Point *point) const; bool readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl, quint8 flags, quint32 size, MapData::Point *point) const; + bool readLclNavaid(Handle &hdl, quint32 size, + MapData::Point *point) const; HuffmanTable *_huffmanTable; Section _base, _dict, _polygons, _lines, _points; diff --git a/src/map/IMG/style.cpp b/src/map/IMG/style.cpp index 1c215dce..3c5fb7ff 100644 --- a/src/map/IMG/style.cpp +++ b/src/map/IMG/style.cpp @@ -1377,34 +1377,34 @@ const QFont *Style::font(Style::FontSize size, Style::FontSize defaultSize) cons } } -const QImage *Style::light(Lights::Color color) const +const QImage *Style::light(Light::Color color) const { switch (color) { - case Lights::Red: + case Light::Red: return &_lightRed; - case Lights::Green: + case Light::Green: return &_lightGreen; - case Lights::White: + case Light::White: return &_lightWhite; - case Lights::Yellow: - case Lights::Amber: + case Light::Yellow: + case Light::Amber: return &_lightYellow; default: return &_light; } } -QColor Style::color(Lights::Color c) +QColor Style::color(Light::Color c) { switch (c) { - case Lights::Red: + case Light::Red: return Qt::red; - case Lights::Green: + case Light::Green: return Qt::green; - case Lights::White: + case Light::White: return Qt::white; - case Lights::Yellow: - case Lights::Amber: + case Light::Yellow: + case Light::Amber: return Qt::yellow; default: return Qt::magenta; diff --git a/src/map/IMG/style.h b/src/map/IMG/style.h index a3f21fad..944f5468 100644 --- a/src/map/IMG/style.h +++ b/src/map/IMG/style.h @@ -5,7 +5,7 @@ #include #include #include -#include "lights.h" +#include "light.h" #include "subfile.h" #define TYPE(t) ((t)<<8) @@ -113,7 +113,7 @@ public: const QList &drawOrder() const {return _drawOrder;} const QFont *font(Style::FontSize size, Style::FontSize defaultSize = Style::Normal) const; - const QImage *light(Lights::Color color) const; + const QImage *light(Light::Color color) const; const QPoint &lightOffset() const {return _lightOffset;} static bool isPOI(quint32 type) @@ -157,7 +157,7 @@ public: static bool isMarina(quint32 type) {return type == 0x10703;} - static QColor color(Lights::Color c); + static QColor color(Light::Color c); private: struct Section { diff --git a/src/map/IMG/subfile.cpp b/src/map/IMG/subfile.cpp index 90576774..2c4d71a1 100644 --- a/src/map/IMG/subfile.cpp +++ b/src/map/IMG/subfile.cpp @@ -41,7 +41,7 @@ bool SubFile::seek(Handle &handle, quint32 pos) const return true; } -bool SubFile::readVUInt32(Handle &hdl, quint32 &val) const +bool SubFile::readVUInt32(Handle &hdl, quint32 &val, quint32 *size) const { quint8 bytes, shift, b; @@ -69,6 +69,9 @@ bool SubFile::readVUInt32(Handle &hdl, quint32 &val) const val |= (((quint32)b) << (i * 8)) >> (8 - shift); } + if (size) + *size = 1 + bytes; + return true; } diff --git a/src/map/IMG/subfile.h b/src/map/IMG/subfile.h index 167fee74..5bea6058 100644 --- a/src/map/IMG/subfile.h +++ b/src/map/IMG/subfile.h @@ -169,7 +169,7 @@ public: return true; } - bool readVUInt32(Handle &hdl, quint32 &val) const; + bool readVUInt32(Handle &hdl, quint32 &val, quint32 *size = 0) const; bool readVUInt32(Handle &hdl, quint32 bytes, quint32 &val) const; bool readVBitfield32(Handle &hdl, quint32 &bitfield) const;