1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

Added bridge clearance rendering

This commit is contained in:
Martin Tůma 2024-06-18 18:12:43 +02:00
parent c7f76f3009
commit ef7b863003
4 changed files with 47 additions and 17 deletions

View File

@ -26,6 +26,7 @@
#define RESTRN 131 #define RESTRN 131
#define TRAFIC 172 #define TRAFIC 172
#define VALDCO 174 #define VALDCO 174
#define VERCLR 181
#define WATLEV 187 #define WATLEV 187
#define I_CATACH 17000 #define I_CATACH 17000

View File

@ -1,3 +1,4 @@
#include "GUI/units.h"
#include "objects.h" #include "objects.h"
#include "attributes.h" #include "attributes.h"
#include "mapdata.h" #include "mapdata.h"
@ -288,12 +289,20 @@ MapData::Point::Point(uint type, const Coordinates &c, const QString &label,
} }
MapData::Poly::Poly(uint type, const Polygon &path, MapData::Poly::Poly(uint type, const Polygon &path,
const QVector<QByteArray> &params) : _type(type), _path(path) const QVector<QByteArray> &params, uint HUNI) : _type(type), _path(path)
{ {
if (type == TYPE(DEPARE) && params.size()) if (type == TYPE(DEPARE) && params.size())
_type = SUBTYPE(DEPARE, depthLevel(params.at(0))); _type = SUBTYPE(DEPARE, depthLevel(params.at(0)));
else if (type == TYPE(TSSLPT) && params.size()) else if (type == TYPE(TSSLPT) && params.size())
_param = QVariant(params.at(0).toDouble()); _param = QVariant(params.at(0).toDouble());
else if ((type == TYPE(BRIDGE) || type == TYPE(I_BRIDGE))
&& params.size()) {
double clr = params.at(0).toDouble();
if (clr > 0) {
_label = QString::fromUtf8("\xE2\x86\x95") + UNIT_SPACE
+ QString::number(clr) + UNIT_SPACE + hUnits(HUNI);
}
}
} }
MapData::Line::Line(uint type, const QVector<Coordinates> &path, MapData::Line::Line(uint type, const QVector<Coordinates> &path,
@ -657,6 +666,9 @@ MapData::Attr MapData::polyAttr(const ISO8211::Record &r, uint OBJL)
if ((OBJL == TSSLPT && key == ORIENT) if ((OBJL == TSSLPT && key == ORIENT)
|| (OBJL == DEPARE && key == DRVAL1)) || (OBJL == DEPARE && key == DRVAL1))
params[0] = av.at(1).toByteArray(); params[0] = av.at(1).toByteArray();
if ((OBJL == BRIDGE && key == VERCLR)
|| (OBJL == I_BRIDGE && key == VERCLR))
params[0] = av.at(1).toByteArray();
} }
return Attr(subtype, label, params); return Attr(subtype, label, params);
@ -689,18 +701,18 @@ MapData::Line *MapData::lineObject(const ISO8211::Record &r,
} }
MapData::Poly *MapData::polyObject(const ISO8211::Record &r, MapData::Poly *MapData::polyObject(const ISO8211::Record &r,
const RecordMap &vc, const RecordMap &ve, uint COMF, uint OBJL) const RecordMap &vc, const RecordMap &ve, uint COMF, uint OBJL, uint HUNI)
{ {
Polygon path(polyGeometry(r, vc, ve, COMF)); Polygon path(polyGeometry(r, vc, ve, COMF));
Attr attr(polyAttr(r, OBJL)); Attr attr(polyAttr(r, OBJL));
return (path.isEmpty() ? 0 : new Poly(SUBTYPE(OBJL, attr.subtype()), path, return (path.isEmpty() ? 0 : new Poly(SUBTYPE(OBJL, attr.subtype()), path,
attr.params())); attr.params(), HUNI));
} }
bool MapData::processRecord(const ISO8211::Record &record, bool MapData::processRecord(const ISO8211::Record &record,
QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve, QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve,
RecordMap &vf, uint &COMF, uint &SOMF) RecordMap &vf, uint &COMF, uint &SOMF, uint &HUNI)
{ {
if (record.size() < 2) if (record.size() < 2)
return false; return false;
@ -735,6 +747,8 @@ bool MapData::processRecord(const ISO8211::Record &record,
} else if (ba == "DSPM") { } else if (ba == "DSPM") {
if (!(f.subfield("COMF", &COMF) && f.subfield("SOMF", &SOMF))) if (!(f.subfield("COMF", &COMF) && f.subfield("SOMF", &SOMF)))
return false; return false;
if (!f.subfield("HUNI", &HUNI))
return false;
} }
return true; return true;
@ -746,7 +760,7 @@ MapData::MapData(const QString &path)
QVector<ISO8211::Record> fe; QVector<ISO8211::Record> fe;
ISO8211 ddf(path); ISO8211 ddf(path);
ISO8211::Record record; ISO8211::Record record;
uint PRIM, OBJL, COMF = 1, SOMF = 1; uint PRIM, OBJL, COMF = 1, SOMF = 1, HUNI = 1;
Poly *poly; Poly *poly;
Line *line; Line *line;
Point *point; Point *point;
@ -756,7 +770,7 @@ MapData::MapData(const QString &path)
if (!ddf.readDDR()) if (!ddf.readDDR())
return; return;
while (ddf.readRecord(record)) while (ddf.readRecord(record))
if (!processRecord(record, fe, vi, vc, ve, vf, COMF, SOMF)) if (!processRecord(record, fe, vi, vc, ve, vf, COMF, SOMF, HUNI))
qWarning("Invalid S-57 record"); qWarning("Invalid S-57 record");
for (int i = 0; i < fe.size(); i++) { for (int i = 0; i < fe.size(); i++) {
@ -793,7 +807,7 @@ MapData::MapData(const QString &path)
warning(f, PRIM); warning(f, PRIM);
break; break;
case PRIM_A: case PRIM_A:
if ((poly = polyObject(r, vc, ve, COMF, OBJL))) { if ((poly = polyObject(r, vc, ve, COMF, OBJL, HUNI))) {
rectcBounds(poly->bounds(), min, max); rectcBounds(poly->bounds(), min, max);
_areas.Insert(min, max, poly); _areas.Insert(min, max, poly);
} else } else

View File

@ -13,16 +13,19 @@ class MapData
public: public:
class Poly { class Poly {
public: public:
Poly(uint type, const Polygon &path, const QVector<QByteArray> &params); Poly(uint type, const Polygon &path, const QVector<QByteArray> &params,
uint HUNI);
RectC bounds() const {return _path.boundingRect();} RectC bounds() const {return _path.boundingRect();}
const Polygon &path() const {return _path;} const Polygon &path() const {return _path;}
uint type() const {return _type;} uint type() const {return _type;}
const QString &label() const {return _label;}
const QVariant &param() const {return _param;} const QVariant &param() const {return _param;}
private: private:
uint _type; uint _type;
Polygon _path; Polygon _path;
QString _label;
QVariant _param; QVariant _param;
}; };
@ -121,11 +124,11 @@ private:
static Line *lineObject(const ISO8211::Record &r, const RecordMap &vc, static Line *lineObject(const ISO8211::Record &r, const RecordMap &vc,
const RecordMap &ve, uint COMF, uint OBJL); const RecordMap &ve, uint COMF, uint OBJL);
static Poly *polyObject(const ISO8211::Record &r, const RecordMap &vc, static Poly *polyObject(const ISO8211::Record &r, const RecordMap &vc,
const RecordMap &ve, uint COMF,uint OBJL); const RecordMap &ve, uint COMF, uint OBJL, uint HUNI);
static bool processRecord(const ISO8211::Record &record, static bool processRecord(const ISO8211::Record &record,
QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve, QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve,
RecordMap &vf, uint &COMF, uint &SOMF); RecordMap &vf, uint &COMF, uint &SOMF, uint &HUNI);
PolygonTree _areas; PolygonTree _areas;
LineTree _lines; LineTree _lines;

View File

@ -241,18 +241,30 @@ void RasterTile::processPolygons(const QList<MapData::Poly> &polygons,
for (int i = 0; i < polygons.size(); i++) { for (int i = 0; i < polygons.size(); i++) {
const MapData::Poly &poly = polygons.at(i); const MapData::Poly &poly = polygons.at(i);
uint type = poly.type()>>16; uint type = poly.type()>>16;
const QImage *img = 0;
const QString *label = 0;
const QFont *fnt = 0;
const QColor *color = 0, *hColor = 0;
if (!(type == HRBFAC || type == I_TRNBSN if (!poly.label().isEmpty()) {
|| poly.type() == SUBTYPE(I_BERTHS, 6))) const Style::Point &style = _style->point(poly.type());
continue; fnt = _style->font(style.textFontSize());
const Style::Point &style = _style->point(poly.type()); color = &style.textColor();
const QImage *img = style.img().isNull() ? 0 : &style.img(); hColor = style.haloColor().isValid() ? &style.haloColor() : 0;
if (!img) 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();
}
if ((!label || !fnt) && !img)
continue; continue;
TextPointItem *item = new TextPointItem( TextPointItem *item = new TextPointItem(
ll2xy(centroid(poly.path().first())).toPoint(), ll2xy(centroid(poly.path().first())).toPoint(),
0, 0, img, 0, 0, 0, 0); label, fnt, img, color, hColor, 0, 0);
if (item->isValid() && !item->collides(textItems)) if (item->isValid() && !item->collides(textItems))
textItems.append(item); textItems.append(item);
else else