diff --git a/src/map/ENC/attributes.h b/src/map/ENC/attributes.h index 01ee9b91..167a0ad5 100644 --- a/src/map/ENC/attributes.h +++ b/src/map/ENC/attributes.h @@ -3,6 +3,7 @@ #define CATACH 8 #define CATBUA 10 +#define CATCOV 18 #define CATDIS 21 #define CATHAF 30 #define CATLMK 35 diff --git a/src/map/ENC/mapdata.cpp b/src/map/ENC/mapdata.cpp index fad38bc4..210bfa4e 100644 --- a/src/map/ENC/mapdata.cpp +++ b/src/map/ENC/mapdata.cpp @@ -425,6 +425,8 @@ MapData::Poly::Poly(uint type, const Polygon &path, const Attributes &attr, subtype = CATMFA; else if (type == I_BERTHS) subtype = I_CATBRT; + else if (type == M_COVR) + subtype = CATCOV; switch (type) { case DEPARE: diff --git a/src/map/ENC/rastertile.cpp b/src/map/ENC/rastertile.cpp index 2788bb9e..a9dbb3fa 100644 --- a/src/map/ENC/rastertile.cpp +++ b/src/map/ENC/rastertile.cpp @@ -257,17 +257,15 @@ void RasterTile::drawSectorLights(QPainter *painter, } } -void RasterTile::processPoints(QList &points, +void RasterTile::processPoints(const QList &points, QList &textItems, QList &lights, - QList §orLights, bool overZoom) + QList §orLights, bool overZoom) const { LightMap lightsMap; SignalSet signalsSet; QSet slMap; int i; - std::sort(points.begin(), points.end()); - /* Lights & Signals */ for (i = 0; i < points.size(); i++) { const Data::Point &point = points.at(i); @@ -328,7 +326,7 @@ void RasterTile::processPoints(QList &points, } void RasterTile::processLines(const QList &lines, - QList &textItems) + QList &textItems) const { for (int i = 0; i < lines.size(); i++) { const Data::Line &line = lines.at(i); @@ -351,19 +349,45 @@ void RasterTile::processLines(const QList &lines, } } -void RasterTile::render() +void RasterTile::drawLevels(QPainter *painter, const QList &levels) { - QImage img(_rect.width() * _ratio, _rect.height() * _ratio, - QImage::Format_ARGB32_Premultiplied); + for (int i = levels.size() - 1; i >= 0; i--) { + QList textItems, lights; + QList sectorLights; + const Level &l = levels.at(i); - img.setDevicePixelRatio(_ratio); - img.fill(Qt::transparent); + processPoints(l.points, textItems, lights, sectorLights, l.overZoom); + processLines(l.lines, textItems); - QPainter painter(&img); - painter.setRenderHint(QPainter::SmoothPixmapTransform); - painter.setRenderHint(QPainter::Antialiasing); - painter.translate(-_rect.x(), -_rect.y()); + drawPolygons(painter, l.polygons); + drawLines(painter, l.lines); + drawArrows(painter, l.points); + drawTextItems(painter, lights); + drawSectorLights(painter, sectorLights); + drawTextItems(painter, textItems); + + qDeleteAll(textItems); + qDeleteAll(lights); + } +} + +QPainterPath RasterTile::shape(const QList &polygons) const +{ + QPainterPath shp; + + for (int i = 0; i < polygons.size(); i++) { + const Data::Poly &p = polygons.at(i); + if (p.type() == SUBTYPE(M_COVR, 1)) + shp.addPath(painterPath(p.path())); + } + + return shp; +} + +QList RasterTile::fetchLevels() +{ + QList list; QPoint ttl(_rect.topLeft()); QRectF polyRect(ttl, QPointF(ttl.x() + _rect.width(), ttl.y() + _rect.height())); @@ -378,31 +402,41 @@ void RasterTile::render() RectC pointRectC(pointRectD.toRectC(_proj, 20)); for (int i = 0; i < _data.size(); i++) { - QList lines; - QList polygons; - QList points; - QList textItems, lights; - QList sectorLights; + Level level; - _data.at(i)->polys(polyRectC, &polygons, &lines); - _data.at(i)->points(pointRectC, &points); + _data.at(i)->polys(polyRectC, &level.polygons, &level.lines); + _data.at(i)->points(pointRectC, &level.points); + level.overZoom = i > 0; - processPoints(points, textItems, lights, sectorLights, - _data.size() > 1 && i == 0); - processLines(lines, textItems); + std::sort(level.points.begin(), level.points.end()); - drawPolygons(&painter, polygons); - drawLines(&painter, lines); - drawArrows(&painter, points); + if (!level.isNull()) + list.append(level); - drawTextItems(&painter, lights); - drawSectorLights(&painter, sectorLights); - drawTextItems(&painter, textItems); - - qDeleteAll(textItems); - qDeleteAll(lights); + if (shape(level.polygons).contains(_rect)) + break; } + return list; +} + +void RasterTile::render() +{ + QList levels(fetchLevels()); + + QImage img(_rect.width() * _ratio, _rect.height() * _ratio, + QImage::Format_ARGB32_Premultiplied); + + img.setDevicePixelRatio(_ratio); + img.fill(Qt::transparent); + + QPainter painter(&img); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(QPainter::Antialiasing); + painter.translate(-_rect.x(), -_rect.y()); + + drawLevels(&painter, levels); + //painter.setPen(Qt::red); //painter.setBrush(Qt::NoBrush); //painter.setRenderHint(QPainter::Antialiasing, false); diff --git a/src/map/ENC/rastertile.h b/src/map/ENC/rastertile.h index 9ca53107..3287896e 100644 --- a/src/map/ENC/rastertile.h +++ b/src/map/ENC/rastertile.h @@ -51,6 +51,16 @@ private: double end; }; + struct Level { + QList lines; + QList polygons; + QList points; + bool overZoom; + + bool isNull() const + {return lines.isEmpty() && polygons.isEmpty() && points.isEmpty();} + }; + typedef QMap LightMap; typedef QSet SignalSet; @@ -61,16 +71,20 @@ private: QVector polylineM(const QVector &path) const; QPolygonF tsslptArrow(const QPointF &p, qreal angle) const; QPointF centroid(const QVector &polygon) const; - void processPoints(QList &points, + void processPoints(const QList &points, QList &textItems, QList &lights, - QList §orLights, bool overZoom); - void processLines(const QList &lines, QList &textItems); + QList §orLights, bool overZoom) const; + void processLines(const QList &lines, + QList &textItems) const; void drawArrows(QPainter *painter, const QList &points) const; void drawPolygons(QPainter *painter, const QList &polygons) const; void drawLines(QPainter *painter, const QList &lines) const; void drawTextItems(QPainter *painter, const QList &textItems) const; void drawSectorLights(QPainter *painter, const QList &lights) const; bool showLabel(const QImage *img, int type) const; + void drawLevels(QPainter *painter, const QList &levels); + QList fetchLevels(); + QPainterPath shape(const QList &polygons) const; Projection _proj; Transform _transform; diff --git a/src/map/encatlas.cpp b/src/map/encatlas.cpp index dab827d9..52cf2ee3 100644 --- a/src/map/encatlas.cpp +++ b/src/map/encatlas.cpp @@ -350,9 +350,9 @@ QList ENCAtlas::levels() const QList list; QMap::const_iterator it = _data.find(_usage); - list.append(it.value()); - if (it != _data.cbegin()) - list.prepend((--it).value()); + do { + list.append(it.value()); + } while (it-- != _data.cbegin()); return list; }