1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Use the info we already have for calibration file type distinction

This commit is contained in:
Martin Tůma 2023-12-31 10:05:02 +01:00
parent 2541797e7d
commit 7860ce8acc
4 changed files with 46 additions and 32 deletions

View File

@ -27,19 +27,25 @@ static bool yCmp(OziMap *m1, OziMap *m2)
return TL(m1).y() > TL(m2).y(); return TL(m1).y() > TL(m2).y();
} }
static QString calibrationFile(const QString &path) static QString calibrationFile(const QString &path, OziMap::CalibrationType &type)
{ {
QDir dir(path); QDir dir(path);
QFileInfoList files = dir.entryInfoList(QDir::Files); QFileInfoList files(dir.entryInfoList(QDir::Files));
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
const QFileInfo &fi = files.at(i); const QFileInfo &fi = files.at(i);
QString suffix(fi.suffix().toLower()); QString suffix(fi.suffix().toLower());
if (suffix == "map" || suffix == "gmi") if (suffix == "map") {
type = OziMap::MAP;
return fi.absoluteFilePath(); return fi.absoluteFilePath();
} else if (suffix == "gmi") {
type = OziMap::GMI;
return fi.absoluteFilePath();
}
} }
type = OziMap::Unknown;
return QString(); return QString();
} }
@ -141,16 +147,19 @@ Atlas::Atlas(const QString &fileName, bool TAR, const Projection &proj,
QFileInfoList maps = zdir.entryInfoList(QDir::Dirs QFileInfoList maps = zdir.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot); | QDir::NoDotAndDotDot);
for (int i = 0; i < maps.count(); i++) { for (int i = 0; i < maps.count(); i++) {
QString path(maps.at(i).absoluteFilePath());
OziMap *map; OziMap *map;
if (TAR) if (TAR)
map = new OziMap(maps.at(i).absoluteFilePath(), tar, proj, this); map = new OziMap(path, tar, proj, this);
else { else {
QString cf(calibrationFile(maps.at(i).absoluteFilePath())); OziMap::CalibrationType type;
QString cf(calibrationFile(path, type));
if (cf.isNull()) { if (cf.isNull()) {
_errorString = "No calibration file found"; qWarning("%s: no calibration file found", qPrintable(path));
return; continue;
} }
map = new OziMap(cf, proj, this); map = new OziMap(cf, type, proj, this);
} }
if (map->isValid()) if (map->isValid())

View File

@ -43,7 +43,7 @@ MapList::ParserMap MapList::parsers()
map.insert("rtmap", &RMap::create); map.insert("rtmap", &RMap::create);
map.insert("map", &MapsforgeMap::create); map.insert("map", &MapsforgeMap::create);
map.insert("map", &OziMap::createMAP); map.insert("map", &OziMap::createMAP);
map.insert("gmi", &OziMap::createMAP); map.insert("gmi", &OziMap::createGMI);
map.insert("kap", &BSBMap::create); map.insert("kap", &BSBMap::create);
map.insert("kmz", &KMZMap::create); map.insert("kmz", &KMZMap::create);
map.insert("aqm", &AQMMap::create); map.insert("aqm", &AQMMap::create);

View File

@ -54,16 +54,12 @@ QString OziMap::calibrationFile(const QStringList &files, const QString path,
return QString(); return QString();
} }
OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent) OziMap::OziMap(const QString &fileName, CalibrationType type,
: Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), const Projection &proj, QObject *parent) : Map(fileName, parent), _img(0),
_valid(false) _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false)
{ {
QFileInfo fi(fileName); // TAR maps
QString suffix(fi.suffix().toLower()); if (type == Unknown) {
if (suffix == "tar") {
CalibrationType type;
_tar = new Tar(fileName); _tar = new Tar(fileName);
if (!_tar->open()) { if (!_tar->open()) {
_errorString = "Error reading tar file: " + _tar->errorString(); _errorString = "Error reading tar file: " + _tar->errorString();
@ -110,10 +106,12 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
return; return;
_tar->close(); _tar->close();
// regular MAP or GMI maps
} else { } else {
QFile file(fileName); QFile file(fileName);
if (suffix == "map") { if (type == MAP) {
MapFile mf(file); MapFile mf(file);
if (!mf.isValid()) { if (!mf.isValid()) {
_errorString = mf.errorString(); _errorString = mf.errorString();
@ -125,7 +123,7 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
_projection = mf.projection(); _projection = mf.projection();
_transform = mf.transform(); _transform = mf.transform();
} }
} else if (suffix == "gmi") { } else if (type == GMI) {
GmiFile gmi(file); GmiFile gmi(file);
if (!gmi.isValid()) { if (!gmi.isValid()) {
_errorString = gmi.errorString(); _errorString = gmi.errorString();
@ -138,11 +136,9 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
_projection = proj; _projection = proj;
computeTransform(); computeTransform();
} }
} else {
_errorString = "Unknown file type";
return;
} }
QFileInfo fi(fileName);
QDir set(fi.absolutePath() + "/" + "set"); QDir set(fi.absolutePath() + "/" + "set");
if (set.exists()) { if (set.exists()) {
if (!setTileInfo(set.entryList(), set.absolutePath())) if (!setTileInfo(set.entryList(), set.absolutePath()))
@ -373,8 +369,7 @@ void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
pixmap = QPixmap(tileName); pixmap = QPixmap(tileName);
if (pixmap.isNull()) if (pixmap.isNull())
qWarning("%s: error loading tile image", qPrintable( qWarning("%s: error loading tile image", qPrintable(tileName));
_tile.path.arg(QString::number(x), QString::number(y))));
else { else {
pixmap.setDevicePixelRatio(_mapRatio); pixmap.setDevicePixelRatio(_mapRatio);
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height()); QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
@ -512,7 +507,7 @@ Map *OziMap::createTAR(const QString &path, const Projection &proj, bool *isDir)
if (isDir) if (isDir)
*isDir = false; *isDir = false;
return new OziMap(path, proj); return new OziMap(path, Unknown, proj);
} }
Map *OziMap::createMAP(const QString &path, const Projection &proj, bool *isDir) Map *OziMap::createMAP(const QString &path, const Projection &proj, bool *isDir)
@ -520,5 +515,13 @@ Map *OziMap::createMAP(const QString &path, const Projection &proj, bool *isDir)
if (isDir) if (isDir)
*isDir = false; *isDir = false;
return new OziMap(path, proj); return new OziMap(path, MAP, proj);
}
Map *OziMap::createGMI(const QString &path, const Projection &proj, bool *isDir)
{
if (isDir)
*isDir = false;
return new OziMap(path, GMI, proj);
} }

View File

@ -15,7 +15,11 @@ class OziMap : public Map
Q_OBJECT Q_OBJECT
public: public:
OziMap(const QString &fileName, const Projection &proj, enum CalibrationType {
Unknown, MAP, GMI
};
OziMap(const QString &fileName, CalibrationType type, const Projection &proj,
QObject *parent = 0); QObject *parent = 0);
OziMap(const QString &dirName, Tar &tar, const Projection &proj, OziMap(const QString &dirName, Tar &tar, const Projection &proj,
QObject *parent = 0); QObject *parent = 0);
@ -54,12 +58,10 @@ public:
bool *isDir); bool *isDir);
static Map *createMAP(const QString &path, const Projection &proj, static Map *createMAP(const QString &path, const Projection &proj,
bool *isDir); bool *isDir);
static Map *createGMI(const QString &path, const Projection &proj,
bool *isDir);
private: private:
enum CalibrationType {
Unknown, MAP, GMI
};
struct ImageInfo { struct ImageInfo {
QSize size; QSize size;
QString path; QString path;