Skip to content

Commit

Permalink
Added basic support for marine lights to IMG maps
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Sep 15, 2024
1 parent 524ac83 commit d412390
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 32 deletions.
1 change: 0 additions & 1 deletion gpxsee.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
<!-- marine stuff (IMG & ENC style) -->
<qresource prefix="/marine">
<file alias="light-major.png">icons/map/marine/light-major.png</file>
<file alias="light-platform.png">icons/map/marine/light-platform.png</file>
<file alias="buoy.png">icons/map/marine/buoy.png</file>
<file alias="beacon.png">icons/map/marine/beacon.png</file>
<file alias="rock-exposed.png">icons/map/marine/rock-exposed.png</file>
Expand Down
Binary file modified icons/map/marine/light-major.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/map/marine/light-platform.png
Binary file not shown.
12 changes: 9 additions & 3 deletions src/map/IMG/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ class MapData
};

struct Point {
Point() : id(0), classLabel(false) {}
Point() : id(0), flags(0) {}

enum Flags {
NoFlag = 0,
ClassLabel = 1,
Light = 2
};

Coordinates coordinates;
Label label;
quint32 type;
quint64 id;
bool classLabel;
quint32 type;
quint32 flags;

bool operator<(const Point &other) const
{return id < other.id;}
Expand Down
29 changes: 17 additions & 12 deletions src/map/IMG/rastertile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,31 +418,36 @@ void RasterTile::processPoints(QList<MapData::Point> &points,

for (int i = 0; i < points.size(); i++) {
const MapData::Point &point = points.at(i);
const Style::Point &style = _data->style()->point(point.type);
const Style *style = _data->style();
const Style::Point &ps = style->point(point.type);
bool poi = Style::isPOI(point.type);

const QString *label = point.label.text().isEmpty()
? 0 : &(point.label.text());
const QImage *img = style.img().isNull() ? 0 : &style.img();
const QImage *img = ps.img().isNull() ? 0 : &ps.img();
const QFont *fnt = poi
? poiFont(style.text().size(), _zoom, point.classLabel)
: _data->style()->font(style.text().size());
const QColor *color = style.text().color().isValid()
? &style.text().color() : &textColor;
? poiFont(ps.text().size(), _zoom, point.flags
& MapData::Point::ClassLabel)
: style->font(ps.text().size());
const QColor *color = ps.text().color().isValid()
? &ps.text().color() : &textColor;
const QColor *hcolor = Style::isDepthPoint(point.type)
? 0 : &haloColor;

if ((!label || !fnt) && !img)
continue;

QPoint offset = img ? style.offset() : QPoint(0, 0);
QPoint pos(point.coordinates.lon(), point.coordinates.lat());
QPoint offset = img ? ps.offset() : QPoint(0, 0);

TextPointItem *item = new TextPointItem(QPoint(point.coordinates.lon(),
point.coordinates.lat()) + offset, label, fnt, img, color, hcolor, 0,
ICON_PADDING);
if (item->isValid() && !item->collides(textItems))
TextPointItem *item = new TextPointItem(pos + offset, label, fnt, img,
color, hcolor, 0, ICON_PADDING);
if (item->isValid() && !item->collides(textItems)) {
textItems.append(item);
else
if (point.flags & MapData::Point::Light)
textItems.append(new TextPointItem(pos + style->lightOffset(),
0, 0, style->light(), 0, 0, 0, 0));
} else
delete item;
}
}
Expand Down
32 changes: 29 additions & 3 deletions src/map/IMG/rgnfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ bool RGNFile::readObstructionInfo(Handle &hdl, quint8 flags, quint32 size,
return true;
}

bool RGNFile::readBuoyInfo(Handle &hdl, quint8 flags, MapData::Point *point) const
{
quint16 val;
quint8 lc;

if ((flags & 0xe0) != 0xe0)
return true;

if (!readUInt16(hdl, val))
return false;

lc = (val >> 10) & 0x0f;
if (!lc)
lc = (val >> 6) & 7;

if (lc)
point->flags |= MapData::Point::Light;

return true;
}

bool RGNFile::readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl,
quint8 flags, quint32 size, MapData::Point *point) const
{
Expand All @@ -116,7 +137,7 @@ bool RGNFile::readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl,
return false;

point->label = lbl->label(lblHdl, this, hdl, size);
point->classLabel = true;
point->flags |= MapData::Point::ClassLabel;

return true;
}
Expand Down Expand Up @@ -154,12 +175,17 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType,

if (poly && Style::isRaster(poly->type))
readRasterInfo(hdl, lbl, rs, poly);
if (point && !Style::isMarinePoint(point->type))
readLabel(hdl, lbl, lblHdl, flags, rs, point);

if (point && Style::isDepthPoint(point->type))
readDepthInfo(hdl, flags, rs, point);
if (point && Style::isObstructionPoint(point->type))
readObstructionInfo(hdl, flags, rs, point);
if (point && !Style::isMarinePoint(point->type))
readLabel(hdl, lbl, lblHdl, flags, rs, point);
if (point && Style::isBuoy(point->type))
readBuoyInfo(hdl, flags, point);
if (point && Style::isLight(point->type))
point->flags |= MapData::Point::Light;

return seek(hdl, off + rs);
}
Expand Down
1 change: 1 addition & 0 deletions src/map/IMG/rgnfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RGNFile : public SubFile
MapData::Point *point) const;
bool readObstructionInfo(Handle &hdl, quint8 flags, quint32 size,
MapData::Point *point) const;
bool readBuoyInfo(Handle &hdl, quint8 flags, MapData::Point *point) const;
bool readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl,
quint8 flags, quint32 size, MapData::Point *point) const;

Expand Down
28 changes: 15 additions & 13 deletions src/map/IMG/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,17 @@ void Style::defaultPointStyle(qreal ratio)
_points[0x11108] = _points[0x3008];

// Marine stuff
_points[0x10100] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10101] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10102] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10103] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10104] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10105] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10106] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10107] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10108] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10109] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x1010a] = Point(QImage(":/marine/light-major.png"), QPoint(8, -8));
_points[0x10100] = Point(QImage(":/marine/light-major.png"));
_points[0x10101] = Point(QImage(":/marine/light-major.png"));
_points[0x10102] = Point(QImage(":/marine/light-major.png"));
_points[0x10103] = Point(QImage(":/marine/light-major.png"));
_points[0x10104] = Point(QImage(":/marine/light-major.png"));
_points[0x10105] = Point(QImage(":/marine/light-major.png"));
_points[0x10106] = Point(QImage(":/marine/light-major.png"));
_points[0x10107] = Point(QImage(":/marine/light-major.png"));
_points[0x10108] = Point(QImage(":/marine/light-major.png"));
_points[0x10109] = Point(QImage(":/marine/light-major.png"));
_points[0x1010a] = Point(QImage(":/marine/light-major.png"));
_points[0x10200] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
_points[0x10201] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
_points[0x10202] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
Expand All @@ -699,8 +699,7 @@ void Style::defaultPointStyle(qreal ratio)
_points[0x1020a] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
_points[0x1020b] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
_points[0x1020c] = Point(QImage(":/marine/buoy.png"), QPoint(6, -6));
_points[0x1020d] = Point(QImage(":/marine/light-platform.png"),
QPoint(8, -8));
_points[0x1020d] = Point(QImage(":/marine/platform.png"));
_points[0x1020e] = Point(QImage(":/marine/beacon.png"), QPoint(0, -8));
_points[0x1020f] = Point(QImage(":/marine/beacon.png"), QPoint(0, -8));
_points[0x10210] = Point(QImage(":/marine/beacon.png"), QPoint(0, -8));
Expand Down Expand Up @@ -1278,6 +1277,9 @@ Style::Style(qreal ratio, SubFile *typ)
_small = pixelSizeFont(12);
_extraSmall = pixelSizeFont(10);

_light = QImage(":/marine/light.png");
_lightOffset = QPoint(11, 11);

defaultLineStyle(ratio);
defaultPolygonStyle();
defaultPointStyle(ratio);
Expand Down
10 changes: 10 additions & 0 deletions src/map/IMG/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class Style
const QFont *font(Style::FontSize size, Style::FontSize defaultSize
= Style::Normal) const;

const QImage *light() const {return &_light;}
const QPoint &lightOffset() const {return _lightOffset;}

static bool isPOI(quint32 type)
{return !((type >= TYPE(0x01) && type <= TYPE(0x1f))
|| (type >= 0x11400 && type < 0x11500));}
Expand Down Expand Up @@ -143,6 +146,10 @@ class Style
{return (type == 0x10301);}
static bool isObstructionPoint(quint32 type)
{return (type >= 0x10400 && type <= 0x10401);}
static bool isBuoy(quint32 type)
{return (type >= 0x10200 && type < 0x10300);}
static bool isLight(quint32 type)
{return (type >= 0x10100 && type < 0x10200);}
static bool isMarinePoint(quint32 type)
{return type >= 0x10100 && type < 0x10a00;}
static bool isMarina(quint32 type)
Expand Down Expand Up @@ -193,6 +200,9 @@ class Style

/* Fonts and images must be initialized after QGuiApplication! */
QFont _large, _normal, _small, _extraSmall;

QImage _light;
QPoint _lightOffset;
};

}
Expand Down

0 comments on commit d412390

Please sign in to comment.