1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

ISO8211 API cleanup

This commit is contained in:
Martin Tůma 2023-01-19 10:08:17 +01:00
parent ee73908231
commit ab76521990
3 changed files with 36 additions and 42 deletions

View File

@ -188,12 +188,16 @@ bool ISO8211::readDDA(QFile &file, const FieldDefinition &def, SubFields &fields
return true;
}
bool ISO8211::readDDR(QFile &file)
bool ISO8211::readDDR()
{
QVector<FieldDefinition> fields;
qint64 pos = file.pos();
int len = readDR(file, fields);
if (!_file.open(QIODevice::ReadOnly)) {
_errorString = _file.errorString();
return false;
}
int len = readDR(_file, fields);
if (len < 0) {
_errorString = "Not a ISO8211 file";
return false;
@ -201,7 +205,7 @@ bool ISO8211::readDDR(QFile &file)
for (int i = 0; i < fields.size(); i++) {
SubFields def;
if (!readDDA(file, fields.at(i), def)) {
if (!readDDA(_file, fields.at(i), def)) {
_errorString = QString("Error reading %1 DDA field")
.arg(QString(fields.at(i).tag));
return false;
@ -209,7 +213,7 @@ bool ISO8211::readDDR(QFile &file)
_map.insert(fields.at(i).tag, def);
}
if (file.pos() != pos + len || fields.size() < 2) {
if (_file.pos() != len || fields.size() < 2) {
_errorString = "DDR format error";
return false;
}
@ -231,6 +235,7 @@ bool ISO8211::readUDA(QFile &file, quint64 pos, const FieldDefinition &def,
const char *dp = ba.constData();
const char *ep = ba.constData() + ba.size() - 1;
data.clear();
data.setFields(&fields);
do {
@ -287,11 +292,14 @@ bool ISO8211::readUDA(QFile &file, quint64 pos, const FieldDefinition &def,
return true;
}
bool ISO8211::readRecord(QFile &file, Record &record)
bool ISO8211::readRecord(Record &record)
{
if (_file.atEnd())
return false;
QVector<FieldDefinition> fields;
qint64 pos = file.pos();
int len = readDR(file, fields);
qint64 pos = _file.pos();
int len = readDR(_file, fields);
if (len < 0) {
_errorString = "Error reading DR";
@ -313,7 +321,7 @@ bool ISO8211::readRecord(QFile &file, Record &record)
f.setTag(def.tag);
if (!readUDA(file, pos, def, it.value(), f.rdata())) {
if (!readUDA(_file, pos, def, it.value(), f.rdata())) {
_errorString = QString("Error reading %1 record")
.arg(QString(def.tag));
return false;

View File

@ -1,12 +1,11 @@
#ifndef ENC_ISO8211_H
#define ENC_ISO8211_H
#include <QFile>
#include <QByteArray>
#include <QVariant>
#include <QDebug>
class QFile;
#define UINT32(x) \
(((quint32)*(const uchar*)(x)) \
| ((quint32)(*((const uchar*)(x) + 1)) << 8) \
@ -102,8 +101,9 @@ public:
}
};
bool readDDR(QFile &file);
bool readRecord(QFile &file, Record &record);
ISO8211(const QString &path) : _file(path) {}
bool readDDR();
bool readRecord(Record &record);
const QString &errorString() const {return _errorString;}
@ -118,6 +118,7 @@ private:
bool readUDA(QFile &file, quint64 pos, const FieldDefinition &def,
const SubFields &fields, Data &data) const;
QFile _file;
FieldsMap _map;
QString _errorString;
};

View File

@ -1,4 +1,3 @@
#include <QFile>
#include "common/util.h"
#include "objects.h"
#include "attributes.h"
@ -751,31 +750,25 @@ bool MapData::bounds(const QVector<ISO8211::Record> &gv, Rect &b)
MapData::MapData(const QString &path): _fileName(path)
{
QFile file(_fileName);
QVector<ISO8211::Record> gv;
ISO8211 ddf;
ISO8211 ddf(_fileName);
ISO8211::Record record;
uint COMF = 1;
if (!file.open(QIODevice::ReadOnly)) {
_errorString = file.errorString();
return;
}
if (!ddf.readDDR(file)) {
if (!ddf.readDDR()) {
_errorString = ddf.errorString();
return;
}
while (!file.atEnd()) {
ISO8211::Record record;
if (!ddf.readRecord(file, record)) {
_errorString = ddf.errorString();
return;
}
while (ddf.readRecord(record)) {
if (!processRecord(record, gv, COMF, _name)) {
_errorString = "Invalid S-57 record";
return;
}
}
if (!ddf.errorString().isNull()) {
_errorString = ddf.errorString();
return;
}
Rect b;
if (!bounds(gv, b)) {
@ -807,30 +800,22 @@ MapData::~MapData()
void MapData::load()
{
QFile file(_fileName);
RecordMap vi, vc, ve, vf;
QVector<ISO8211::Record> fe;
uint COMF = 1, SOMF = 1;
ISO8211 ddf;
uint PRIM, OBJL;
ISO8211 ddf(_fileName);
ISO8211::Record record;
uint PRIM, OBJL, COMF = 1, SOMF = 1;
Poly *poly;
Line *line;
Point *point;
double min[2], max[2];
if (!file.open(QIODevice::ReadOnly))
if (!ddf.readDDR())
return;
if (!ddf.readDDR(file))
return;
while (!file.atEnd()) {
ISO8211::Record record;
if (!ddf.readRecord(file, record))
return;
while (ddf.readRecord(record))
if (!processRecord(record, fe, vi, vc, ve, vf, COMF, SOMF))
return;
}
qWarning("Invalid S-57 record");
for (int i = 0; i < fe.size(); i++) {
const ISO8211::Record &r = fe.at(i);