252 lines
9.1 KiB
Diff
252 lines
9.1 KiB
Diff
|
From a0eda8480f32cd38bfb8510a9fe40e8a6d620825 Mon Sep 17 00:00:00 2001
|
||
|
From: John Floyd <jfloyd@bigpond.net.au>
|
||
|
Date: Sat, 23 May 2020 16:10:57 +1000
|
||
|
Subject: [PATCH] [QMS-158] Change Routino Profiles search for
|
||
|
[prefix-]profiles.xml
|
||
|
|
||
|
Changes the Routino profiles search to include
|
||
|
1) dbase-folder/prefix-profiles.xml
|
||
|
2) dbase-folder/profiles.xml
|
||
|
3) routino-shared-system-folder/profiles.xml
|
||
|
|
||
|
Requires parsing the profiles file in the routing functions to allow
|
||
|
changing to a new routing database during a session by calling a new
|
||
|
method loadProfiles. This means that the name of the profiles.xml being
|
||
|
used must be known.
|
||
|
|
||
|
buildDatabaseList method is expanded to check and keep the first
|
||
|
available profiles file for each routing database that is loaded. This
|
||
|
is kept in the UserData item of the UI comboDatabase instance in a map
|
||
|
variable along with the database pointer for each database item.
|
||
|
|
||
|
Includes Latest Changes based on Review
|
||
|
|
||
|
loadProfiles is now called in buildDatabaseList to check if the xml is
|
||
|
OK and when database is changed from gui.
|
||
|
Changelog now sequestial.
|
||
|
|
||
|
More changes to avoid aborts and segmentation errors.
|
||
|
|
||
|
Moved the failure messagebox from loadProfiles to buildDatabaseList.
|
||
|
This allows the database prefix to be referenced in the message. Message
|
||
|
is expanded to notify user that the profiles file needs to be fixed and
|
||
|
that the database associated with the failed profiles is ignored.
|
||
|
|
||
|
Reset currentProfilesPath for test loads!
|
||
|
|
||
|
New Review cleanups
|
||
|
|
||
|
Move 158 entry in changelog to new version!
|
||
|
---
|
||
|
changelog.txt | 1 +
|
||
|
.../gis/rte/router/CRouterRoutino.cpp | 99 ++++++++++++++++---
|
||
|
src/qmapshack/gis/rte/router/CRouterRoutino.h | 2 +
|
||
|
3 files changed, 87 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/src/qmapshack/gis/rte/router/CRouterRoutino.cpp b/src/qmapshack/gis/rte/router/CRouterRoutino.cpp
|
||
|
index 81f37fa4..91ba62c3 100644
|
||
|
--- a/src/qmapshack/gis/rte/router/CRouterRoutino.cpp
|
||
|
+++ b/src/qmapshack/gis/rte/router/CRouterRoutino.cpp
|
||
|
@@ -29,10 +29,8 @@
|
||
|
#include <QtWidgets>
|
||
|
#include <routino.h>
|
||
|
|
||
|
-
|
||
|
QPointer<CProgressDialog> CRouterRoutino::progress;
|
||
|
|
||
|
-
|
||
|
int ProgressFunc(double complete)
|
||
|
{
|
||
|
if(CRouterRoutino::progress.isNull())
|
||
|
@@ -64,15 +62,9 @@ CRouterRoutino::CRouterRoutino(QWidget *parent)
|
||
|
comboMode->addItem(tr("Shortest"));
|
||
|
comboMode->addItem(tr("Quickest"));
|
||
|
|
||
|
+
|
||
|
int res = 0;
|
||
|
IAppSetup *setup = IAppSetup::getPlatformInstance();
|
||
|
- res = Routino_ParseXMLProfiles(setup->routinoPath("profiles.xml").toUtf8());
|
||
|
- if(res)
|
||
|
- {
|
||
|
- QMessageBox::critical(this, "Routino...", xlateRoutinoError(Routino_errno), QMessageBox::Abort);
|
||
|
- return;
|
||
|
- }
|
||
|
-
|
||
|
res = Routino_ParseXMLTranslations(setup->routinoPath("translations.xml").toUtf8());
|
||
|
if(res)
|
||
|
{
|
||
|
@@ -233,6 +225,11 @@ void CRouterRoutino::buildDatabaseList()
|
||
|
QRegExp re("(.*)-segments.mem");
|
||
|
freeDatabaseList();
|
||
|
|
||
|
+ // initialise
|
||
|
+ currentProfilesPath = "";
|
||
|
+
|
||
|
+ IAppSetup *setup = IAppSetup::getPlatformInstance();
|
||
|
+
|
||
|
for(const QString &path : dbPaths)
|
||
|
{
|
||
|
QDir dir(path);
|
||
|
@@ -248,33 +245,98 @@ void CRouterRoutino::buildDatabaseList()
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
+ // qDebug() << "buildDatabase Prefix" << prefix;
|
||
|
+
|
||
|
#ifdef Q_OS_WIN
|
||
|
Routino_Database * data = Routino_LoadDatabase(dir.absolutePath().toLocal8Bit(), prefix.toLocal8Bit());
|
||
|
#else
|
||
|
Routino_Database * data = Routino_LoadDatabase(dir.absolutePath().toUtf8(), prefix.toUtf8());
|
||
|
#endif
|
||
|
- if(data)
|
||
|
+ qDebug() << "Loaded Routino DB" << dir.absolutePath().toUtf8().data() << " " << prefix.toUtf8().data();
|
||
|
+
|
||
|
+ if(data == nullptr)
|
||
|
+ {
|
||
|
+ QMessageBox::critical(this, "Routino ...", xlateRoutinoError(Routino_errno), QMessageBox::Abort);
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+ /* determine the profile to use for each database*/
|
||
|
+ QVariantMap dmap;
|
||
|
+ dmap["db"] = QVariant ((qulonglong)data);
|
||
|
+
|
||
|
+ /* check possible profiles.xml locations and use the first available */
|
||
|
+ int pError = 0;
|
||
|
+ dmap["profilesPath"] = "";
|
||
|
+ QStringList profilesPaths = {
|
||
|
+ dir.filePath(prefix+"-profiles.xml"),
|
||
|
+ dir.filePath("profiles.xml"),
|
||
|
+ setup->routinoPath("profiles.xml").toUtf8()
|
||
|
+ };
|
||
|
+
|
||
|
+ for(const QString& profilePath : profilesPaths)
|
||
|
+ {
|
||
|
+ QFileInfo pinfo(profilePath);
|
||
|
+ if( pinfo.isReadable())
|
||
|
+ {
|
||
|
+ dmap["profilesPath"] = pinfo.filePath();
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ }
|
||
|
+ if( dmap["profilesPath"].toString().isEmpty() )
|
||
|
+ {
|
||
|
+ QMessageBox::critical(this, "Routino...",tr("Could not find a profiles XML file in expected folders. Routino Routing will not function"), QMessageBox::Ok);
|
||
|
+ pError = 1;
|
||
|
+ }
|
||
|
+ else
|
||
|
+ {
|
||
|
+ /* ensure we always reload */
|
||
|
+ currentProfilesPath = "";
|
||
|
+ /* check if profile will load - will abort if not good */
|
||
|
+ pError = loadProfiles(dmap["profilesPath"].toString());
|
||
|
+ }
|
||
|
+ qDebug() << "Profile ... Using \n" << dmap["profilesPath"].toString();
|
||
|
+
|
||
|
+ if( pError == 0 )
|
||
|
{
|
||
|
- comboDatabase->addItem(prefix.replace("_", " "), quint64(data));
|
||
|
+ comboDatabase->addItem(prefix.replace("_", " "), dmap);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
- QMessageBox::critical(this, "Routino...", xlateRoutinoError(Routino_errno), QMessageBox::Abort);
|
||
|
+ const QString& msg = tr(
|
||
|
+ "%1\n"
|
||
|
+ "Error in '%2'\n"
|
||
|
+ "This needs to be fixed\n"
|
||
|
+ "The associated database '%3' is ignored"
|
||
|
+ ).arg(xlateRoutinoError(Routino_errno)).arg(dmap["profilesPath"].toString()).arg(prefix);
|
||
|
+
|
||
|
+ QMessageBox::warning(this, "Routino...", msg, QMessageBox::Ok);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
+ currentProfilesPath = "";
|
||
|
}
|
||
|
|
||
|
void CRouterRoutino::freeDatabaseList()
|
||
|
{
|
||
|
for(int i = 0; i < comboDatabase->count(); i++)
|
||
|
{
|
||
|
- Routino_Database * data = (Routino_Database*)comboDatabase->itemData(i, Qt::UserRole).toULongLong();
|
||
|
+ QVariantMap map = comboDatabase->itemData(i,Qt::UserRole).toMap();
|
||
|
+ Routino_Database * data = (Routino_Database*)(map["db"].toULongLong());
|
||
|
Routino_UnloadDatabase(data);
|
||
|
}
|
||
|
comboDatabase->clear();
|
||
|
}
|
||
|
|
||
|
+int CRouterRoutino::loadProfiles(const QString& profilesPath)
|
||
|
+{
|
||
|
+ int res = 0;
|
||
|
+ if( currentProfilesPath != profilesPath)
|
||
|
+ {
|
||
|
+ currentProfilesPath = profilesPath;
|
||
|
+ res = Routino_ParseXMLProfiles(profilesPath.toUtf8());
|
||
|
+ }
|
||
|
+ return res;
|
||
|
+}
|
||
|
+
|
||
|
void CRouterRoutino::updateHelpText()
|
||
|
{
|
||
|
bool haveDB = (comboDatabase->count() != 0);
|
||
|
@@ -301,12 +363,15 @@ void CRouterRoutino::calcRoute(const IGisItem::key_t& key)
|
||
|
throw QString();
|
||
|
}
|
||
|
|
||
|
- Routino_Database * data = (Routino_Database*)comboDatabase->currentData(Qt::UserRole).toULongLong();
|
||
|
+ QVariantMap map = comboDatabase->currentData(Qt::UserRole).toMap();
|
||
|
+ Routino_Database * data = (Routino_Database*)(map["db"].toULongLong());
|
||
|
if(nullptr == data)
|
||
|
{
|
||
|
throw QString();
|
||
|
}
|
||
|
|
||
|
+ loadProfiles(map["profilesPath"].toString());
|
||
|
+
|
||
|
rte->reset();
|
||
|
|
||
|
QString strProfile = comboProfile->currentData(Qt::UserRole).toString();
|
||
|
@@ -388,18 +453,22 @@ int CRouterRoutino::calcRoute(const QPointF& p1, const QPointF& p2, QPolygonF& c
|
||
|
|
||
|
try
|
||
|
{
|
||
|
- Routino_Database * data = (Routino_Database*)comboDatabase->currentData(Qt::UserRole).toULongLong();
|
||
|
+ QVariantMap map = comboDatabase->currentData(Qt::UserRole).toMap();
|
||
|
+ Routino_Database * data = (Routino_Database*)(map["db"].toULongLong());
|
||
|
if(nullptr == data)
|
||
|
{
|
||
|
throw QString();
|
||
|
}
|
||
|
|
||
|
+ loadProfiles(map["profilesPath"].toString());
|
||
|
+
|
||
|
QString strProfile = comboProfile->currentData(Qt::UserRole).toString();
|
||
|
QString strLanguage = comboLanguage->currentData(Qt::UserRole).toString();
|
||
|
|
||
|
Routino_Profile *profile = Routino_GetProfile(strProfile.toUtf8());
|
||
|
Routino_Translation *translation = Routino_GetTranslation(strLanguage.toUtf8());
|
||
|
|
||
|
+
|
||
|
int res = Routino_ValidateProfile(data, profile);
|
||
|
if(res != 0)
|
||
|
{
|
||
|
diff --git a/src/qmapshack/gis/rte/router/CRouterRoutino.h b/src/qmapshack/gis/rte/router/CRouterRoutino.h
|
||
|
index 13217532..7aae8c83 100644
|
||
|
--- a/src/qmapshack/gis/rte/router/CRouterRoutino.h
|
||
|
+++ b/src/qmapshack/gis/rte/router/CRouterRoutino.h
|
||
|
@@ -57,11 +57,13 @@ private slots:
|
||
|
virtual ~CRouterRoutino();
|
||
|
void buildDatabaseList();
|
||
|
void freeDatabaseList();
|
||
|
+ int loadProfiles(const QString& profilesPath);
|
||
|
void updateHelpText();
|
||
|
QString xlateRoutinoError(int err);
|
||
|
static CRouterRoutino * pSelf;
|
||
|
|
||
|
QStringList dbPaths;
|
||
|
+ QString currentProfilesPath;
|
||
|
|
||
|
QMutex mutex {QMutex::NonRecursive};
|
||
|
};
|