1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 03:42:09 +01:00

Merged ENC point and areas labels

This commit is contained in:
Martin Tůma 2024-12-19 09:50:39 +01:00
parent b7bb3b649a
commit 4e466d16a1
5 changed files with 22 additions and 87 deletions

View File

@ -170,6 +170,14 @@ static bool polygonCb(const MapData::Poly *polygon, void *context)
return true; 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) static Coordinates coordinates(int x, int y, uint COMF)
{ {
return Coordinates(x / (double)COMF, y / (double)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()); _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, MapData::Poly::Poly(uint type, const Polygon &path, const QString &label,
const QVector<QByteArray> &params, uint HUNI) : _type(type), _path(path) const QVector<QByteArray> &params, uint HUNI) : _type(type), _path(path)
{ {
@ -848,6 +862,7 @@ void MapData::points(const RectC &rect, QList<Point> *points) const
rectcBounds(rect, min, max); rectcBounds(rect, min, max);
_points.Search(min, max, pointCb, points); _points.Search(min, max, pointCb, points);
_areas.Search(min, max, polygonPointCb, points);
} }
void MapData::lines(const RectC &rect, QList<Line> *lines) const void MapData::lines(const RectC &rect, QList<Line> *lines) const

View File

@ -49,6 +49,8 @@ public:
public: public:
Point(uint type, const Coordinates &c, const QString &label, Point(uint type, const Coordinates &c, const QString &label,
const QVector<QByteArray> &params); const QVector<QByteArray> &params);
Point(uint type, const Coordinates &c, const QString &label,
const QVariant &param);
const Coordinates &pos() const {return _pos;} const Coordinates &pos() const {return _pos;}
uint type() const {return _type;} uint type() const {return _type;}

View File

@ -40,31 +40,6 @@ static bool showLabel(const QImage *img, const Range &range, int zoom, int type)
return true; 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 RasterTile::painterPath(const Polygon &polygon) const
{ {
QPainterPath path; QPainterPath path;
@ -162,20 +137,6 @@ static void drawArrow(QPainter *painter, const QPolygonF &polygon, uint type)
painter->drawPolygon(polygon); 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, void RasterTile::drawArrows(QPainter *painter,
const QList<MapData::Point> &points) const QList<MapData::Point> &points)
{ {
@ -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, void RasterTile::processPoints(QList<MapData::Point> &points,
QList<TextItem*> &textItems, QList<TextItem*> &lights) QList<TextItem*> &textItems, QList<TextItem*> &lights)
{ {
@ -412,7 +333,6 @@ void RasterTile::render()
fetchData(polygons, lines, points); fetchData(polygons, lines, points);
processPoints(points, textItems, lights); processPoints(points, textItems, lights);
processPolygons(polygons, textItems);
processLines(lines, textItems); processLines(lines, textItems);
QPainter painter(&img); QPainter painter(&img);
@ -422,7 +342,6 @@ void RasterTile::render()
drawPolygons(&painter, polygons); drawPolygons(&painter, polygons);
drawLines(&painter, lines); drawLines(&painter, lines);
drawArrows(&painter, polygons);
drawArrows(&painter, points); drawArrows(&painter, points);
drawTextItems(&painter, lights); drawTextItems(&painter, lights);

View File

@ -47,11 +47,8 @@ private:
QList<TextItem*> &textItems, QList<TextItem *> &lights); QList<TextItem*> &textItems, QList<TextItem *> &lights);
void processLines(const QList<MapData::Line> &lines, void processLines(const QList<MapData::Line> &lines,
QList<TextItem*> &textItems); QList<TextItem*> &textItems);
void processPolygons(const QList<MapData::Poly> &polygons,
QList<TextItem*> &textItems);
void drawBitmapPath(QPainter *painter, const QImage &img, void drawBitmapPath(QPainter *painter, const QImage &img,
const Polygon &polygon); const Polygon &polygon);
void drawArrows(QPainter *painter, const QList<MapData::Poly> &polygons);
void drawArrows(QPainter *painter, const QList<MapData::Point> &points); void drawArrows(QPainter *painter, const QList<MapData::Point> &points);
void drawPolygons(QPainter *painter, const QList<MapData::Poly> &polygons); void drawPolygons(QPainter *painter, const QList<MapData::Poly> &polygons);
void drawLines(QPainter *painter, const QList<MapData::Line> &lines); void drawLines(QPainter *painter, const QList<MapData::Line> &lines);

View File

@ -116,6 +116,7 @@ void Style::polygonStyle()
_polygons[TYPE(BERTHS)] = Polygon(Qt::NoBrush, QPen(QColor(0xeb, 0x49, 0xeb), _polygons[TYPE(BERTHS)] = Polygon(Qt::NoBrush, QPen(QColor(0xeb, 0x49, 0xeb),
1, Qt::DashLine)); 1, Qt::DashLine));
_polygons[TYPE(I_BERTHS)] = _polygons[TYPE(BERTHS)]; _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), _polygons[TYPE(CONZNE)] = Polygon(Qt::NoBrush, QPen(QColor(0xeb, 0x49, 0xeb),
1, Qt::DashDotLine)); 1, Qt::DashDotLine));
@ -131,8 +132,8 @@ void Style::polygonStyle()
<< TYPE(I_PONTON) << TYPE(HULKES) << TYPE(I_HULKES) << TYPE(FLODOC) << TYPE(I_PONTON) << TYPE(HULKES) << TYPE(I_HULKES) << TYPE(FLODOC)
<< TYPE(I_FLODOC) << TYPE(DRYDOC) << TYPE(DAMCON) << TYPE(PYLONS) << TYPE(I_FLODOC) << TYPE(DRYDOC) << TYPE(DAMCON) << TYPE(PYLONS)
<< TYPE(MORFAC) << TYPE(GATCON) << TYPE(I_GATCON) << TYPE(BERTHS) << TYPE(MORFAC) << TYPE(GATCON) << TYPE(I_GATCON) << TYPE(BERTHS)
<< TYPE(I_BERTHS) << TYPE(DMPGRD) << TYPE(TSEZNE) << TYPE(OBSTRN) << TYPE(I_BERTHS) << SUBTYPE(I_BERTHS, 6) << TYPE(DMPGRD) << TYPE(TSEZNE)
<< TYPE(UWTROC) << TYPE(DWRTPT) << SUBTYPE(ACHARE, 1) << TYPE(OBSTRN) << TYPE(UWTROC) << TYPE(DWRTPT) << SUBTYPE(ACHARE, 1)
<< SUBTYPE(I_ACHARE, 1) << SUBTYPE(RESARE, 9) << SUBTYPE(RESARE, 2) << SUBTYPE(I_ACHARE, 1) << SUBTYPE(RESARE, 9) << SUBTYPE(RESARE, 2)
<< SUBTYPE(I_RESARE, 2) << SUBTYPE(RESARE, 17) << SUBTYPE(I_RESARE, 17) << SUBTYPE(I_RESARE, 2) << SUBTYPE(RESARE, 17) << SUBTYPE(I_RESARE, 17)
<< SUBTYPE(RESARE, 12) << SUBTYPE(I_RESARE, 12) << SUBTYPE(RESARE, 1) << 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, 3)].setTextColor(QColor(0xeb, 0x49, 0xeb));
_points[SUBTYPE(I_RDOCAL, 4)].setTextColor(QColor(0xeb, 0x49, 0xeb)); _points[SUBTYPE(I_RDOCAL, 4)].setTextColor(QColor(0xeb, 0x49, 0xeb));
_points[TYPE(PYLONS)] = Point(QImage(":/marine/pylon.png")); _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, 1)] = Point(QImage(":/marine/breakers.png"));
_points[SUBTYPE(WATTUR, 2)] = Point(QImage(":/marine/eddies.png")); _points[SUBTYPE(WATTUR, 2)] = Point(QImage(":/marine/eddies.png"));
_points[SUBTYPE(WATTUR, 3)] = Point(QImage(":/marine/overfalls.png")); _points[SUBTYPE(WATTUR, 3)] = Point(QImage(":/marine/overfalls.png"));