mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-04 08:47:45 +08:00
Fixed old parameters ignored when reading config file from GUI
This commit is contained in:
@@ -733,8 +733,8 @@ void Parameters::readINI(const std::string & configFile, ParametersMap & paramet
|
|||||||
if(addParameter)
|
if(addParameter)
|
||||||
{
|
{
|
||||||
key = oldIter->second.second;
|
key = oldIter->second.second;
|
||||||
UWARN("Parameter migration from \"%s\" to \"%s\" (value=%s).",
|
UWARN("Parameter migration from \"%s\" to \"%s\" (value=%s, default=%s).",
|
||||||
oldIter->first.c_str(), oldIter->second.second.c_str(), iter->second);
|
oldIter->first.c_str(), oldIter->second.second.c_str(), iter->second, Parameters::getDefaultParameters().at(oldIter->second.second).c_str());
|
||||||
}
|
}
|
||||||
else if(oldIter->second.second.empty())
|
else if(oldIter->second.second.empty())
|
||||||
{
|
{
|
||||||
@@ -743,8 +743,8 @@ void Parameters::readINI(const std::string & configFile, ParametersMap & paramet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UWARN("Parameter \"%s\" doesn't exist anymore, you may want to use this similar parameter \"%s\":\"%s\".",
|
UWARN("Parameter \"%s\" (value=%s) doesn't exist anymore, you may want to use this similar parameter \"%s (default=%s): %s\".",
|
||||||
oldIter->first.c_str(), oldIter->second.second.c_str(), Parameters::getDescription(oldIter->second.second).c_str());
|
oldIter->first.c_str(), iter->second, oldIter->second.second.c_str(), Parameters::getDefaultParameters().at(oldIter->second.second).c_str(), Parameters::getDescription(oldIter->second.second).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1819,112 +1819,54 @@ bool PreferencesDialog::readCoreSettings(const QString & filePath)
|
|||||||
QMessageBox::information(this, tr("INI file doesn't exist..."), tr("The configuration file \"%1\" does not exist, it will be created with default parameters.").arg(path));
|
QMessageBox::information(this, tr("INI file doesn't exist..."), tr("The configuration file \"%1\" does not exist, it will be created with default parameters.").arg(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings(path, QSettings::IniFormat);
|
ParametersMap parameters;
|
||||||
|
Parameters::readINI(path.toStdString(), parameters);
|
||||||
|
|
||||||
|
|
||||||
settings.beginGroup("Core");
|
|
||||||
|
|
||||||
// Compare version in ini with the current RTAB-Map version
|
|
||||||
QStringList version = settings.value("Version", "").toString().split('.');
|
|
||||||
if(version.size() == 3)
|
|
||||||
{
|
|
||||||
if(!RTABMAP_VERSION_COMPARE(version[0].toInt(), version[1].toInt(), version[2].toInt()))
|
|
||||||
{
|
|
||||||
if(path.contains(".rtabmap"))
|
|
||||||
{
|
|
||||||
UWARN("Version in the config file \"%s\" is more recent (\"%s\") than "
|
|
||||||
"current RTAB-Map version used (\"%s\"). The config file will be upgraded "
|
|
||||||
"to new version.",
|
|
||||||
path.toStdString().c_str(),
|
|
||||||
settings.value("Version", "").toString().toStdString().c_str(),
|
|
||||||
RTABMAP_VERSION);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UERROR("Version in the config file \"%s\" is more recent (\"%s\") than "
|
|
||||||
"current RTAB-Map version used (\"%s\"). New parameters (if there are some) will "
|
|
||||||
"be ignored.",
|
|
||||||
path.toStdString().c_str(),
|
|
||||||
settings.value("Version", "").toString().toStdString().c_str(),
|
|
||||||
RTABMAP_VERSION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList keys = settings.allKeys();
|
|
||||||
// Get profile
|
|
||||||
const rtabmap::ParametersMap & parameters = Parameters::getDefaultParameters();
|
|
||||||
for(rtabmap::ParametersMap::const_iterator iter = parameters.begin(); iter!=parameters.end(); ++iter)
|
for(rtabmap::ParametersMap::const_iterator iter = parameters.begin(); iter!=parameters.end(); ++iter)
|
||||||
{
|
{
|
||||||
QString key(iter->first.c_str());
|
std::string value = iter->second;
|
||||||
QString value = settings.value(key, "").toString();
|
if(iter->first.compare(Parameters::kRtabmapWorkingDirectory()) == 0)
|
||||||
if(value.isEmpty())
|
|
||||||
{
|
{
|
||||||
// look for old parameter name
|
// The directory should exist if not the default one
|
||||||
rtabmap::ParametersMap::const_iterator oldIter = Parameters::getBackwardCompatibilityMap().find(iter->first);
|
if(!QDir(value.c_str()).exists() && value.compare(Parameters::createDefaultWorkingDirectory().c_str()) != 0)
|
||||||
if(oldIter!=Parameters::getBackwardCompatibilityMap().end())
|
|
||||||
{
|
{
|
||||||
value = settings.value(QString(oldIter->second.c_str()), "").toString();
|
if(QDir(this->getWorkingDirectory().toStdString().c_str()).exists())
|
||||||
if(!value.isEmpty())
|
|
||||||
{
|
{
|
||||||
UWARN("Parameter migration from \"%s\" to \"%s\" (value=%s).",
|
UWARN("Reading config: Not existing working directory \"%s\". Keeping old one (\"%s\").",
|
||||||
oldIter->second.c_str(), oldIter->first.c_str(), value.toStdString().c_str());
|
value.c_str(),
|
||||||
|
this->getWorkingDirectory().toStdString().c_str());
|
||||||
|
value = this->getWorkingDirectory().toStdString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string defaultWorkingDir = Parameters::createDefaultWorkingDirectory();
|
||||||
|
UWARN("Reading config: Not existing working directory \"%s\". Using default one (\"%s\").",
|
||||||
|
value.c_str(),
|
||||||
|
defaultWorkingDir.c_str());
|
||||||
|
value = defaultWorkingDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->setParameter(iter->first, value);
|
||||||
if(!value.isEmpty())
|
|
||||||
{
|
|
||||||
if(key.toStdString().compare(Parameters::kRtabmapWorkingDirectory()) == 0)
|
|
||||||
{
|
|
||||||
// The directory should exist if not the default one
|
|
||||||
if(!QDir(value).exists() && value.compare(Parameters::createDefaultWorkingDirectory().c_str()) != 0)
|
|
||||||
{
|
|
||||||
if(QDir(this->getWorkingDirectory().toStdString().c_str()).exists())
|
|
||||||
{
|
|
||||||
UWARN("Reading config: Not existing working directory \"%s\". Keeping old one (\"%s\").",
|
|
||||||
value.toStdString().c_str(),
|
|
||||||
this->getWorkingDirectory().toStdString().c_str());
|
|
||||||
value = this->getWorkingDirectory();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UWARN("Reading config: Not existing working directory \"%s\". Using default one (\"%s\").",
|
|
||||||
value.toStdString().c_str(),
|
|
||||||
(*iter).second.c_str());
|
|
||||||
value = (*iter).second.c_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->setParameter(key.toStdString(), value.toStdString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Add information about the working directory if not in the config file
|
|
||||||
if(key.toStdString().compare(Parameters::kRtabmapWorkingDirectory()) == 0)
|
|
||||||
{
|
|
||||||
if(!_initialized)
|
|
||||||
{
|
|
||||||
QMessageBox::information(this,
|
|
||||||
tr("Working directory"),
|
|
||||||
tr("RTAB-Map needs a working directory to put the database.\n\n"
|
|
||||||
"By default, the directory \"%1\" is used.\n\n"
|
|
||||||
"The working directory can be changed any time in the "
|
|
||||||
"preferences menu.").arg(
|
|
||||||
Parameters::createDefaultWorkingDirectory().c_str()));
|
|
||||||
}
|
|
||||||
this->setParameter(key.toStdString(), Parameters::createDefaultWorkingDirectory());
|
|
||||||
UDEBUG("key.toStdString()=%s", Parameters::createDefaultWorkingDirectory().c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Use the default value if the key doesn't exist yet
|
|
||||||
this->setParameter(key.toStdString(), (*iter).second);
|
|
||||||
UDEBUG("key.toStdString()=%s", key.toStdString().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
settings.endGroup(); // Core
|
|
||||||
|
// Add information about the working directory if not in the config file
|
||||||
|
if(parameters.find(Parameters::kRtabmapWorkingDirectory()) == parameters.end())
|
||||||
|
{
|
||||||
|
if(!_initialized)
|
||||||
|
{
|
||||||
|
QMessageBox::information(this,
|
||||||
|
tr("Working directory"),
|
||||||
|
tr("RTAB-Map needs a working directory to put the database.\n\n"
|
||||||
|
"By default, the directory \"%1\" is used.\n\n"
|
||||||
|
"The working directory can be changed any time in the "
|
||||||
|
"preferences menu.").arg(
|
||||||
|
Parameters::createDefaultWorkingDirectory().c_str()));
|
||||||
|
}
|
||||||
|
this->setParameter(Parameters::kRtabmapWorkingDirectory(), Parameters::createDefaultWorkingDirectory());
|
||||||
|
UDEBUG("key.toStdString()=%s", Parameters::createDefaultWorkingDirectory().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user