Skip to content

Commit

Permalink
Merged ENC point and areas labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Dec 19, 2024
1 parent b7bb3b6 commit 4e466d1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 87 deletions.
15 changes: 15 additions & 0 deletions src/map/ENC/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapData::Point> *points = (QList<MapData::Point>*)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);
Expand Down Expand Up @@ -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 &param) : _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<QByteArray> &params, uint HUNI) : _type(type), _path(path)
{
Expand Down Expand Up @@ -848,6 +862,7 @@ void MapData::points(const RectC &rect, QList<Point> *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<Line> *lines) const
Expand Down
2 changes: 2 additions & 0 deletions src/map/ENC/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class MapData
public:
Point(uint type, const Coordinates &c, const QString &label,
const QVector<QByteArray> &params);
Point(uint type, const Coordinates &c, const QString &label,
const QVariant &param);

const Coordinates &pos() const {return _pos;}
uint type() const {return _type;}
Expand Down
81 changes: 0 additions & 81 deletions src/map/ENC/rastertile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@ static bool showLabel(const QImage *img, const Range &range, int zoom, int type)
return true;
}

QPointF RasterTile::centroid(const QVector<Coordinates> &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;
Expand Down Expand Up @@ -162,20 +137,6 @@ static void drawArrow(QPainter *painter, const QPolygonF &polygon, uint type)
painter->drawPolygon(polygon);
}

void RasterTile::drawArrows(QPainter *painter,
const QList<MapData::Poly> &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<MapData::Point> &points)
{
Expand Down Expand Up @@ -252,46 +213,6 @@ void RasterTile::drawTextItems(QPainter *painter,
}
}

void RasterTile::processPolygons(const QList<MapData::Poly> &polygons,
QList<TextItem*> &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<MapData::Point> &points,
QList<TextItem*> &textItems, QList<TextItem*> &lights)
{
Expand Down Expand Up @@ -412,7 +333,6 @@ void RasterTile::render()
fetchData(polygons, lines, points);

processPoints(points, textItems, lights);
processPolygons(polygons, textItems);
processLines(lines, textItems);

QPainter painter(&img);
Expand All @@ -422,7 +342,6 @@ void RasterTile::render()

drawPolygons(&painter, polygons);
drawLines(&painter, lines);
drawArrows(&painter, polygons);
drawArrows(&painter, points);

drawTextItems(&painter, lights);
Expand Down
3 changes: 0 additions & 3 deletions src/map/ENC/rastertile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ class RasterTile
QList<TextItem*> &textItems, QList<TextItem *> &lights);
void processLines(const QList<MapData::Line> &lines,
QList<TextItem*> &textItems);
void processPolygons(const QList<MapData::Poly> &polygons,
QList<TextItem*> &textItems);
void drawBitmapPath(QPainter *painter, const QImage &img,
const Polygon &polygon);
void drawArrows(QPainter *painter, const QList<MapData::Poly> &polygons);
void drawArrows(QPainter *painter, const QList<MapData::Point> &points);
void drawPolygons(QPainter *painter, const QList<MapData::Poly> &polygons);
void drawLines(QPainter *painter, const QList<MapData::Line> &lines);
Expand Down
8 changes: 5 additions & 3 deletions src/map/ENC/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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)
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 4e466d1

Please sign in to comment.