From 4e466d16a112196fdbc68107c744c8782c0184fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 19 Dec 2024 09:50:39 +0100 Subject: [PATCH] Merged ENC point and areas labels --- src/map/ENC/mapdata.cpp | 15 +++++++ src/map/ENC/mapdata.h | 2 + src/map/ENC/rastertile.cpp | 81 -------------------------------------- src/map/ENC/rastertile.h | 3 -- src/map/ENC/style.cpp | 8 ++-- 5 files changed, 22 insertions(+), 87 deletions(-) diff --git a/src/map/ENC/mapdata.cpp b/src/map/ENC/mapdata.cpp index cfa4f7b2..b7d5efcb 100644 --- a/src/map/ENC/mapdata.cpp +++ b/src/map/ENC/mapdata.cpp @@ -170,6 +170,14 @@ static bool polygonCb(const MapData::Poly *polygon, void *context) return true; } +static bool polygonPointCb(const MapData::Poly *polygon, void *context) +{ + QList *points = (QList*)context; + points->append(MapData::Point(polygon->type(), polygon->bounds().center(), + polygon->label(), polygon->param())); + return true; +} + static Coordinates coordinates(int x, int y, uint COMF) { return Coordinates(x / (double)COMF, y / (double)COMF); @@ -290,6 +298,12 @@ MapData::Point::Point(uint type, const Coordinates &c, const QString &label, _param = QVariant(params.at(0).toDouble()); } +MapData::Point::Point(uint type, const Coordinates &c, const QString &label, + const QVariant ¶m) : _type(type), _pos(c), _label(label), _param(param) +{ + _id = ((quint64)order(type))<<32 | (uint)qHash(c); +} + MapData::Poly::Poly(uint type, const Polygon &path, const QString &label, const QVector ¶ms, uint HUNI) : _type(type), _path(path) { @@ -848,6 +862,7 @@ void MapData::points(const RectC &rect, QList *points) const rectcBounds(rect, min, max); _points.Search(min, max, pointCb, points); + _areas.Search(min, max, polygonPointCb, points); } void MapData::lines(const RectC &rect, QList *lines) const diff --git a/src/map/ENC/mapdata.h b/src/map/ENC/mapdata.h index f5f56174..9dc46d33 100644 --- a/src/map/ENC/mapdata.h +++ b/src/map/ENC/mapdata.h @@ -49,6 +49,8 @@ class MapData public: Point(uint type, const Coordinates &c, const QString &label, const QVector ¶ms); + Point(uint type, const Coordinates &c, const QString &label, + const QVariant ¶m); const Coordinates &pos() const {return _pos;} uint type() const {return _type;} diff --git a/src/map/ENC/rastertile.cpp b/src/map/ENC/rastertile.cpp index 491072d5..8d2ac9f2 100644 --- a/src/map/ENC/rastertile.cpp +++ b/src/map/ENC/rastertile.cpp @@ -40,31 +40,6 @@ static bool showLabel(const QImage *img, const Range &range, int zoom, int type) return true; } -QPointF RasterTile::centroid(const QVector &polygon) const -{ - Q_ASSERT(polygon.size() > 3); - Q_ASSERT(polygon.first() == polygon.last()); - - double area = 0; - double cx = 0, cy = 0; - QPointF pi; - QPointF pj(ll2xy(polygon.at(0))); - - for (int i = 0; i < polygon.size() - 1; i++) { - pi = pj; - pj = ll2xy(polygon.at(i + 1)); - - double f = pi.x() * pj.y() - pj.x() * pi.y(); - area += f; - cx += (pi.x() + pj.x()) * f; - cy += (pi.y() + pj.y()) * f; - } - - double factor = 1.0 / (3.0 * area); - - return QPointF(cx * factor, cy * factor); -} - QPainterPath RasterTile::painterPath(const Polygon &polygon) const { QPainterPath path; @@ -162,20 +137,6 @@ static void drawArrow(QPainter *painter, const QPolygonF &polygon, uint type) painter->drawPolygon(polygon); } -void RasterTile::drawArrows(QPainter *painter, - const QList &polygons) -{ - for (int i = 0; i < polygons.size(); i++) { - const MapData::Poly &poly = polygons.at(i); - - if (poly.type()>>16 == TSSLPT || poly.type()>>16 == RCTLPT) { - QPolygonF polygon(tsslptArrow(centroid(poly.path().first()), - deg2rad(poly.param().toDouble()))); - drawArrow(painter, polygon, poly.type()); - } - } -} - void RasterTile::drawArrows(QPainter *painter, const QList &points) { @@ -252,46 +213,6 @@ void RasterTile::drawTextItems(QPainter *painter, } } -void RasterTile::processPolygons(const QList &polygons, - QList &textItems) -{ - for (int i = 0; i < polygons.size(); i++) { - const MapData::Poly &poly = polygons.at(i); - uint type = poly.type()>>16; - const QImage *img = 0; - const QString *label = 0; - const QFont *fnt = 0; - const QColor *color = 0, *hColor = 0; - QPoint offset(0, 0); - - if (!poly.label().isEmpty()) { - const Style::Point &style = _style->point(poly.type()); - fnt = _style->font(style.textFontSize()); - color = &style.textColor(); - hColor = style.haloColor().isValid() ? &style.haloColor() : 0; - label = &poly.label(); - } - if (type == HRBFAC || type == I_TRNBSN - || poly.type() == SUBTYPE(I_BERTHS, 6)) { - const Style::Point &style = _style->point(poly.type()); - img = style.img().isNull() ? 0 : &style.img(); - offset = style.offset(); - } - - if ((!label || !fnt) && !img) - continue; - - TextPointItem *item = new TextPointItem(offset + - centroid(poly.path().first()).toPoint(), label, fnt, img, color, - hColor, 0, 0); - if (item->isValid() && _rect.contains(item->boundingRect().toRect()) - && !item->collides(textItems)) - textItems.append(item); - else - delete item; - } -} - void RasterTile::processPoints(QList &points, QList &textItems, QList &lights) { @@ -412,7 +333,6 @@ void RasterTile::render() fetchData(polygons, lines, points); processPoints(points, textItems, lights); - processPolygons(polygons, textItems); processLines(lines, textItems); QPainter painter(&img); @@ -422,7 +342,6 @@ void RasterTile::render() drawPolygons(&painter, polygons); drawLines(&painter, lines); - drawArrows(&painter, polygons); drawArrows(&painter, points); drawTextItems(&painter, lights); diff --git a/src/map/ENC/rastertile.h b/src/map/ENC/rastertile.h index e253646d..2d17a6dd 100644 --- a/src/map/ENC/rastertile.h +++ b/src/map/ENC/rastertile.h @@ -47,11 +47,8 @@ class RasterTile QList &textItems, QList &lights); void processLines(const QList &lines, QList &textItems); - void processPolygons(const QList &polygons, - QList &textItems); void drawBitmapPath(QPainter *painter, const QImage &img, const Polygon &polygon); - void drawArrows(QPainter *painter, const QList &polygons); void drawArrows(QPainter *painter, const QList &points); void drawPolygons(QPainter *painter, const QList &polygons); void drawLines(QPainter *painter, const QList &lines); diff --git a/src/map/ENC/style.cpp b/src/map/ENC/style.cpp index 0fc49436..43ddd7d1 100644 --- a/src/map/ENC/style.cpp +++ b/src/map/ENC/style.cpp @@ -116,6 +116,7 @@ void Style::polygonStyle() _polygons[TYPE(BERTHS)] = Polygon(Qt::NoBrush, QPen(QColor(0xeb, 0x49, 0xeb), 1, Qt::DashLine)); _polygons[TYPE(I_BERTHS)] = _polygons[TYPE(BERTHS)]; + _polygons[SUBTYPE(I_BERTHS, 6)] = _polygons[TYPE(BERTHS)]; _polygons[TYPE(CONZNE)] = Polygon(Qt::NoBrush, QPen(QColor(0xeb, 0x49, 0xeb), 1, Qt::DashDotLine)); @@ -131,8 +132,8 @@ void Style::polygonStyle() << TYPE(I_PONTON) << TYPE(HULKES) << TYPE(I_HULKES) << TYPE(FLODOC) << TYPE(I_FLODOC) << TYPE(DRYDOC) << TYPE(DAMCON) << TYPE(PYLONS) << TYPE(MORFAC) << TYPE(GATCON) << TYPE(I_GATCON) << TYPE(BERTHS) - << TYPE(I_BERTHS) << TYPE(DMPGRD) << TYPE(TSEZNE) << TYPE(OBSTRN) - << TYPE(UWTROC) << TYPE(DWRTPT) << SUBTYPE(ACHARE, 1) + << TYPE(I_BERTHS) << SUBTYPE(I_BERTHS, 6) << TYPE(DMPGRD) << TYPE(TSEZNE) + << TYPE(OBSTRN) << TYPE(UWTROC) << TYPE(DWRTPT) << SUBTYPE(ACHARE, 1) << SUBTYPE(I_ACHARE, 1) << SUBTYPE(RESARE, 9) << SUBTYPE(RESARE, 2) << SUBTYPE(I_RESARE, 2) << SUBTYPE(RESARE, 17) << SUBTYPE(I_RESARE, 17) << SUBTYPE(RESARE, 12) << SUBTYPE(I_RESARE, 12) << SUBTYPE(RESARE, 1) @@ -325,7 +326,8 @@ void Style::pointStyle(qreal ratio) _points[SUBTYPE(I_RDOCAL, 3)].setTextColor(QColor(0xeb, 0x49, 0xeb)); _points[SUBTYPE(I_RDOCAL, 4)].setTextColor(QColor(0xeb, 0x49, 0xeb)); _points[TYPE(PYLONS)] = Point(QImage(":/marine/pylon.png")); - _points[SUBTYPE(I_BERTHS, 6)] = Point(QImage(":/marine/fleeting-area.png")); + _points[SUBTYPE(I_BERTHS, 6)] = Point(QImage(":/marine/fleeting-area.png"), + Small); _points[SUBTYPE(WATTUR, 1)] = Point(QImage(":/marine/breakers.png")); _points[SUBTYPE(WATTUR, 2)] = Point(QImage(":/marine/eddies.png")); _points[SUBTYPE(WATTUR, 3)] = Point(QImage(":/marine/overfalls.png"));