1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-04-20 20:29:10 +02:00

Compare commits

..

No commits in common. "ab7652199058b715a836677c042db8751c82f6f8" and "3af98b67858f2b749b18c8bddac81b8b71272e9b" have entirely different histories.

4 changed files with 44 additions and 38 deletions

View File

@ -188,16 +188,12 @@ bool ISO8211::readDDA(QFile &file, const FieldDefinition &def, SubFields &fields
return true;
}
bool ISO8211::readDDR()
bool ISO8211::readDDR(QFile &file)
{
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;
@ -205,7 +201,7 @@ bool ISO8211::readDDR()
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;
@ -213,7 +209,7 @@ bool ISO8211::readDDR()
_map.insert(fields.at(i).tag, def);
}
if (_file.pos() != len || fields.size() < 2) {
if (file.pos() != pos + len || fields.size() < 2) {
_errorString = "DDR format error";
return false;
}
@ -235,7 +231,6 @@ 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 {
@ -292,14 +287,11 @@ bool ISO8211::readUDA(QFile &file, quint64 pos, const FieldDefinition &def,
return true;
}
bool ISO8211::readRecord(Record &record)
bool ISO8211::readRecord(QFile &file, 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";
@ -321,7 +313,7 @@ bool ISO8211::readRecord(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,11 +1,12 @@
#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) \
@ -101,9 +102,8 @@ public:
}
};
ISO8211(const QString &path) : _file(path) {}
bool readDDR();
bool readRecord(Record &record);
bool readDDR(QFile &file);
bool readRecord(QFile &file, Record &record);
const QString &errorString() const {return _errorString;}
@ -118,7 +118,6 @@ 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,3 +1,4 @@
#include <QFile>
#include "common/util.h"
#include "objects.h"
#include "attributes.h"
@ -750,25 +751,31 @@ 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(_fileName);
ISO8211::Record record;
ISO8211 ddf;
uint COMF = 1;
if (!ddf.readDDR()) {
if (!file.open(QIODevice::ReadOnly)) {
_errorString = file.errorString();
return;
}
if (!ddf.readDDR(file)) {
_errorString = ddf.errorString();
return;
}
while (ddf.readRecord(record)) {
while (!file.atEnd()) {
ISO8211::Record record;
if (!ddf.readRecord(file, record)) {
_errorString = ddf.errorString();
return;
}
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)) {
@ -800,22 +807,30 @@ MapData::~MapData()
void MapData::load()
{
QFile file(_fileName);
RecordMap vi, vc, ve, vf;
QVector<ISO8211::Record> fe;
ISO8211 ddf(_fileName);
ISO8211::Record record;
uint PRIM, OBJL, COMF = 1, SOMF = 1;
uint COMF = 1, SOMF = 1;
ISO8211 ddf;
uint PRIM, OBJL;
Poly *poly;
Line *line;
Point *point;
double min[2], max[2];
if (!ddf.readDDR())
if (!file.open(QIODevice::ReadOnly))
return;
while (ddf.readRecord(record))
if (!ddf.readDDR(file))
return;
while (!file.atEnd()) {
ISO8211::Record record;
if (!ddf.readRecord(file, record))
return;
if (!processRecord(record, fe, vi, vc, ve, vf, COMF, SOMF))
qWarning("Invalid S-57 record");
return;
}
for (int i = 0; i < fe.size(); i++) {
const ISO8211::Record &r = fe.at(i);

View File

@ -381,7 +381,7 @@ void OziMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
Map *OziMap::createTAR(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;
*isDir = true;
return new OziMap(path, true);
}
@ -389,7 +389,7 @@ Map *OziMap::createTAR(const QString &path, const Projection &, bool *isDir)
Map *OziMap::createMAP(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;
*isDir = true;
return new OziMap(path, false);
}