PreferencesDialogROS: load/save local working directory for the GUI

This commit is contained in:
matlabbe
2016-04-13 11:59:46 -04:00
parent fded3685af
commit 157ae27e2f
2 changed files with 73 additions and 28 deletions
+72 -27
View File
@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/core/RtabmapEvent.h> #include <rtabmap/core/RtabmapEvent.h>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <ros/exceptions.h> #include <ros/exceptions.h>
#include <rtabmap/utilite/UStl.h>
using namespace rtabmap; using namespace rtabmap;
@@ -76,19 +77,42 @@ QString PreferencesDialogROS::getParamMessage()
bool PreferencesDialogROS::readCoreSettings(const QString & filePath) bool PreferencesDialogROS::readCoreSettings(const QString & filePath)
{ {
if(filePath.isEmpty() || filePath.compare(getTmpIniFilePath()) == 0) QString path = getIniFilePath();
if(!filePath.isEmpty())
{ {
ros::NodeHandle nh; path = filePath;
ROS_INFO("%s", this->getParamMessage().toStdString().c_str()); }
bool validParameters = true;
int readCount = 0; ros::NodeHandle nh;
rtabmap::ParametersMap parameters = rtabmap::Parameters::getDefaultParameters(); ROS_INFO("%s", this->getParamMessage().toStdString().c_str());
for(rtabmap::ParametersMap::iterator i=parameters.begin(); i!=parameters.end(); ++i) bool validParameters = true;
int readCount = 0;
rtabmap::ParametersMap parameters = rtabmap::Parameters::getDefaultParameters();
for(rtabmap::ParametersMap::iterator i=parameters.begin(); i!=parameters.end(); ++i)
{
if(i->first.compare(rtabmap::Parameters::kRtabmapWorkingDirectory()) == 0)
{
// use working directory of the GUI, not the one on rosparam server
QSettings settings(path, QSettings::IniFormat);
settings.beginGroup("Core");
QString value = settings.value(rtabmap::Parameters::kRtabmapWorkingDirectory().c_str(), "").toString();
if(!value.isEmpty() && QDir(value).exists())
{
this->setParameter(rtabmap::Parameters::kRtabmapWorkingDirectory(), value.toStdString());
}
else
{
// use default one
this->setParameter(rtabmap::Parameters::kRtabmapWorkingDirectory(), (QDir::homePath()+"/.ros").toStdString());
}
settings.endGroup();
}
else
{ {
std::string value; std::string value;
if(nh.getParam((*i).first,value)) if(nh.getParam(i->first,value))
{ {
PreferencesDialog::setParameter((*i).first, value); PreferencesDialog::setParameter(i->first, value);
++readCount; ++readCount;
} }
else else
@@ -96,29 +120,50 @@ bool PreferencesDialogROS::readCoreSettings(const QString & filePath)
validParameters = false; validParameters = false;
} }
} }
}
ROS_INFO("Parameters read = %d", readCount); ROS_INFO("Parameters read = %d", readCount);
if(validParameters) if(validParameters)
{ {
ROS_INFO("Parameters successfully read."); ROS_INFO("Parameters successfully read.");
}
else
{
if(this->isVisible())
{
QString warning = tr("Failed to get some RTAB-Map parameters from ROS server, the rtabmap node may be not started or some parameters won't work...");
ROS_WARN("%s", warning.toStdString().c_str());
QMessageBox::warning(this, tr("Can't read parameters from ROS server."), warning);
}
return false;
}
return true;
} }
else else
{ {
return PreferencesDialog::readCoreSettings(filePath); if(this->isVisible())
{
QString warning = tr("Failed to get some RTAB-Map parameters from ROS server, the rtabmap node may be not started or some parameters won't work...");
ROS_WARN("%s", warning.toStdString().c_str());
QMessageBox::warning(this, tr("Can't read parameters from ROS server."), warning);
}
return false;
}
return true;
}
void PreferencesDialogROS::writeCoreSettings(const QString & filePath) const
{
QString path = getIniFilePath();
if(!filePath.isEmpty())
{
path = filePath;
}
if(QFile::exists(path))
{
rtabmap::ParametersMap parameters = this->getAllParameters();
std::string workingDir = uValue(parameters, Parameters::kRtabmapWorkingDirectory(), std::string(""));
if(!workingDir.empty())
{
//Just update GUI working directory
QSettings settings(path, QSettings::IniFormat);
settings.beginGroup("Core");
settings.remove("");
settings.setValue(Parameters::kRtabmapWorkingDirectory().c_str(), workingDir.c_str());
settings.endGroup();
}
} }
} }
+1 -1
View File
@@ -48,7 +48,7 @@ protected:
virtual void readCameraSettings(const QString & filePath); virtual void readCameraSettings(const QString & filePath);
virtual bool readCoreSettings(const QString & filePath); virtual bool readCoreSettings(const QString & filePath);
virtual void writeCameraSettings(const QString & filePath) const {} virtual void writeCameraSettings(const QString & filePath) const {}
virtual void writeCoreSettings(const QString & filePath) const {} virtual void writeCoreSettings(const QString & filePath) const;
private: private:
QString configFile_; QString configFile_;