GUI: updated Source menu check behavior, checking if "rtabmap.tmp.db" exists before deleting it (in case of another RTAB-Map is running in the same working directory)

This commit is contained in:
Mathieu Labbe
2015-03-01 19:41:03 -05:00
parent 34f4b3132d
commit ee7a5f591a
4 changed files with 142 additions and 142 deletions

View File

@@ -206,9 +206,7 @@ private:
void createAndAddScanToMap(int nodeId, const Transform & pose, int mapId); void createAndAddScanToMap(int nodeId, const Transform & pose, int mapId);
void drawKeypoints(const std::multimap<int, cv::KeyPoint> & refWords, const std::multimap<int, cv::KeyPoint> & loopWords); void drawKeypoints(const std::multimap<int, cv::KeyPoint> & refWords, const std::multimap<int, cv::KeyPoint> & loopWords);
void setupMainLayout(bool vertical); void setupMainLayout(bool vertical);
void updateSelectSourceImageMenu(bool used, PreferencesDialog::Src src); void updateSelectSourceMenu();
void updateSelectSourceDatabase(bool used);
void updateSelectSourceRGBDMenu(bool used, PreferencesDialog::Src src);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr getAssembledCloud( pcl::PointCloud<pcl::PointXYZRGB>::Ptr getAssembledCloud(
const std::map<int, Transform> & poses, const std::map<int, Transform> & poses,

View File

@@ -212,9 +212,9 @@ public slots:
void setDetectionRate(double value); void setDetectionRate(double value);
void setTimeLimit(float value); void setTimeLimit(float value);
void setSLAMMode(bool enabled); void setSLAMMode(bool enabled);
void selectSourceImage(Src src = kSrcUndef, bool checked = true); void selectSourceImage(Src src = kSrcUndef);
void selectSourceDatabase(bool user = false, bool checked = true); void selectSourceDatabase(bool user = false);
void selectSourceRGBD(Src src = kSrcUndef, bool checked = true); void selectSourceRGBD(Src src = kSrcUndef);
private slots: private slots:
void closeDialog ( QAbstractButton * button ); void closeDialog ( QAbstractButton * button );

View File

@@ -339,13 +339,10 @@ MainWindow::MainWindow(PreferencesDialog * prefDialog, QWidget * parent) :
#endif #endif
//Settings menu //Settings menu
this->updateSelectSourceImageMenu(_preferencesDialog->isSourceImageUsed(), _preferencesDialog->getSourceImageType());
connect(_ui->actionImageFiles, SIGNAL(triggered()), this, SLOT(selectImages())); connect(_ui->actionImageFiles, SIGNAL(triggered()), this, SLOT(selectImages()));
connect(_ui->actionVideo, SIGNAL(triggered()), this, SLOT(selectVideo())); connect(_ui->actionVideo, SIGNAL(triggered()), this, SLOT(selectVideo()));
connect(_ui->actionUsbCamera, SIGNAL(triggered()), this, SLOT(selectStream())); connect(_ui->actionUsbCamera, SIGNAL(triggered()), this, SLOT(selectStream()));
this->updateSelectSourceDatabase(_preferencesDialog->isSourceDatabaseUsed());
connect(_ui->actionDatabase, SIGNAL(triggered()), this, SLOT(selectDatabase())); connect(_ui->actionDatabase, SIGNAL(triggered()), this, SLOT(selectDatabase()));
this->updateSelectSourceRGBDMenu(_preferencesDialog->isSourceOpenniUsed(), _preferencesDialog->getSourceRGBD());
connect(_ui->actionOpenNI_PCL, SIGNAL(triggered()), this, SLOT(selectOpenni())); connect(_ui->actionOpenNI_PCL, SIGNAL(triggered()), this, SLOT(selectOpenni()));
connect(_ui->actionOpenNI_PCL_ASUS, SIGNAL(triggered()), this, SLOT(selectOpenni())); connect(_ui->actionOpenNI_PCL_ASUS, SIGNAL(triggered()), this, SLOT(selectOpenni()));
connect(_ui->actionFreenect, SIGNAL(triggered()), this, SLOT(selectFreenect())); connect(_ui->actionFreenect, SIGNAL(triggered()), this, SLOT(selectFreenect()));
@@ -360,6 +357,7 @@ MainWindow::MainWindow(PreferencesDialog * prefDialog, QWidget * parent) :
_ui->actionOpenNI2_Sense->setEnabled(CameraOpenNI2::available()); _ui->actionOpenNI2_Sense->setEnabled(CameraOpenNI2::available());
connect(_ui->actionOpenNI2_kinect, SIGNAL(triggered()), this, SLOT(selectOpenni2())); connect(_ui->actionOpenNI2_kinect, SIGNAL(triggered()), this, SLOT(selectOpenni2()));
_ui->actionOpenNI2_kinect->setEnabled(CameraOpenNI2::available()); _ui->actionOpenNI2_kinect->setEnabled(CameraOpenNI2::available());
this->updateSelectSourceMenu();
connect(_ui->actionSave_state, SIGNAL(triggered()), this, SLOT(saveFigures())); connect(_ui->actionSave_state, SIGNAL(triggered()), this, SLOT(saveFigures()));
connect(_ui->actionLoad_state, SIGNAL(triggered()), this, SLOT(loadFigures())); connect(_ui->actionLoad_state, SIGNAL(triggered()), this, SLOT(loadFigures()));
@@ -1750,7 +1748,9 @@ void MainWindow::processRtabmapEventInit(int status, const QString & info)
if(_databaseUpdated) if(_databaseUpdated)
{ {
if(!_newDatabasePath.isEmpty() && !_newDatabasePathOutput.isEmpty()) if(!_newDatabasePath.isEmpty())
{
if(!_newDatabasePathOutput.isEmpty())
{ {
if(QFile::rename(_newDatabasePath, _newDatabasePathOutput)) if(QFile::rename(_newDatabasePath, _newDatabasePathOutput))
{ {
@@ -1765,6 +1765,16 @@ void MainWindow::processRtabmapEventInit(int status, const QString & info)
QMessageBox::critical(this, tr("Closing failed!"), QString(msg.c_str())); QMessageBox::critical(this, tr("Closing failed!"), QString(msg.c_str()));
} }
} }
else if(QFile::remove(_newDatabasePath))
{
UINFO("Deleted temporary database \"%s\".", _newDatabasePath.toStdString().c_str());
}
else
{
UERROR("Temporary database \"%s\" could not be deleted.", _newDatabasePath.toStdString().c_str());
}
}
else if(!_openedDatabasePath.isEmpty()) else if(!_openedDatabasePath.isEmpty())
{ {
std::string msg = uFormat("Database \"%s\" updated.", _openedDatabasePath.toStdString().c_str()); std::string msg = uFormat("Database \"%s\" updated.", _openedDatabasePath.toStdString().c_str());
@@ -1772,6 +1782,18 @@ void MainWindow::processRtabmapEventInit(int status, const QString & info)
QMessageBox::information(this, tr("Database updated!"), QString(msg.c_str())); QMessageBox::information(this, tr("Database updated!"), QString(msg.c_str()));
} }
} }
else if(!_newDatabasePath.isEmpty())
{
// just remove temporary database;
if(QFile::remove(_newDatabasePath))
{
UINFO("Deleted temporary database \"%s\".", _newDatabasePath.toStdString().c_str());
}
else
{
UERROR("Temporary database \"%s\" could not be deleted.", _newDatabasePath.toStdString().c_str());
}
}
_openedDatabasePath.clear(); _openedDatabasePath.clear();
_newDatabasePath.clear(); _newDatabasePath.clear();
_newDatabasePathOutput.clear(); _newDatabasePathOutput.clear();
@@ -1877,9 +1899,7 @@ void MainWindow::applyPrefSettings(PreferencesDialog::PANEL_FLAGS flags)
{ {
// Camera settings... // Camera settings...
_ui->doubleSpinBox_stats_imgRate->setValue(_preferencesDialog->getGeneralInputRate()); _ui->doubleSpinBox_stats_imgRate->setValue(_preferencesDialog->getGeneralInputRate());
this->updateSelectSourceImageMenu(_preferencesDialog->isSourceImageUsed(), _preferencesDialog->getSourceImageType()); this->updateSelectSourceMenu();
this->updateSelectSourceDatabase(_preferencesDialog->isSourceDatabaseUsed());
this->updateSelectSourceRGBDMenu(_preferencesDialog->isSourceOpenniUsed(), _preferencesDialog->getSourceRGBD());
QString src; QString src;
if(_preferencesDialog->isSourceImageUsed()) if(_preferencesDialog->isSourceImageUsed())
{ {
@@ -2205,28 +2225,22 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
return QWidget::eventFilter(obj, event); return QWidget::eventFilter(obj, event);
} }
void MainWindow::updateSelectSourceImageMenu(bool used, PreferencesDialog::Src src) void MainWindow::updateSelectSourceMenu()
{ {
_ui->actionUsbCamera->setChecked(used && src == PreferencesDialog::kSrcUsbDevice); _ui->actionUsbCamera->setChecked(_preferencesDialog->isSourceImageUsed() && _preferencesDialog->getSourceImageType() == PreferencesDialog::kSrcUsbDevice);
_ui->actionImageFiles->setChecked(used && src == PreferencesDialog::kSrcImages); _ui->actionImageFiles->setChecked(_preferencesDialog->isSourceImageUsed() && _preferencesDialog->getSourceImageType() == PreferencesDialog::kSrcImages);
_ui->actionVideo->setChecked(used && src == PreferencesDialog::kSrcVideo); _ui->actionVideo->setChecked(_preferencesDialog->isSourceImageUsed() && _preferencesDialog->getSourceImageType() == PreferencesDialog::kSrcVideo);
}
void MainWindow::updateSelectSourceDatabase(bool used) _ui->actionDatabase->setChecked(_preferencesDialog->isSourceDatabaseUsed());
{
_ui->actionDatabase->setChecked(used);
}
void MainWindow::updateSelectSourceRGBDMenu(bool used, PreferencesDialog::Src src) _ui->actionOpenNI_PCL->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI_PCL);
{ _ui->actionOpenNI_PCL_ASUS->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI_PCL);
_ui->actionOpenNI_PCL->setChecked(used && src == PreferencesDialog::kSrcOpenNI_PCL); _ui->actionFreenect->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcFreenect);
_ui->actionOpenNI_PCL_ASUS->setChecked(used && src == PreferencesDialog::kSrcOpenNI_PCL); _ui->actionOpenNI_CV->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI_CV);
_ui->actionFreenect->setChecked(used && src == PreferencesDialog::kSrcFreenect); _ui->actionOpenNI_CV_ASUS->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI_CV_ASUS);
_ui->actionOpenNI_CV->setChecked(used && src == PreferencesDialog::kSrcOpenNI_CV); _ui->actionOpenNI2->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI2);
_ui->actionOpenNI_CV_ASUS->setChecked(used && src == PreferencesDialog::kSrcOpenNI_CV_ASUS); _ui->actionOpenNI2_Sense->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI2);
_ui->actionOpenNI2->setChecked(used && src == PreferencesDialog::kSrcOpenNI2); _ui->actionOpenNI2_kinect->setChecked(_preferencesDialog->isSourceOpenniUsed() && _preferencesDialog->getSourceRGBD() == PreferencesDialog::kSrcOpenNI2);
_ui->actionOpenNI2_Sense->setChecked(used && src == PreferencesDialog::kSrcOpenNI2);
_ui->actionOpenNI2_kinect->setChecked(used && src == PreferencesDialog::kSrcOpenNI2);
} }
void MainWindow::changeImgRateSetting() void MainWindow::changeImgRateSetting()
@@ -2314,16 +2328,31 @@ void MainWindow::newDatabase()
_databaseUpdated = false; _databaseUpdated = false;
ULOGGER_DEBUG(""); ULOGGER_DEBUG("");
this->clearTheCache(); this->clearTheCache();
std::string databasePath = (_preferencesDialog->getWorkingDirectory()+QDir::separator()+Parameters::getDefaultDatabaseName().c_str()).toStdString(); std::string databasePath = (_preferencesDialog->getWorkingDirectory()+QDir::separator()+QString("rtabmap.tmp.db")).toStdString();
if(QFile::exists(databasePath.c_str())) if(QFile::exists(databasePath.c_str()))
{
int r = QMessageBox::question(this,
tr("Creating temporary database"),
tr("Cannot create a new database because the temporary database \"%1\" already exists. "
"There may be another instance of RTAB-Map running with the same Working Directory or "
"the last time RTAB-Map was not closed correctly. "
"Do you want to continue (the database will be deleted to create the new one)?").arg(databasePath.c_str()),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if(r == QMessageBox::Yes)
{ {
if(QFile::remove(databasePath.c_str())) if(QFile::remove(databasePath.c_str()))
{ {
UINFO("Deleted database \"%s\".", databasePath.c_str()); UINFO("Deleted temporary database \"%s\".", databasePath.c_str());
}
else
{
UERROR("Temporary database \"%s\" could not be deleted!", databasePath.c_str());
return;
}
} }
else else
{ {
UERROR("Cannot create a new database because the temporary database \"%s\" cannot be deleted.", databasePath.c_str());
return; return;
} }
} }
@@ -3491,55 +3520,47 @@ void MainWindow::updateEditMenu()
void MainWindow::selectImages() void MainWindow::selectImages()
{ {
_preferencesDialog->selectSourceImage(PreferencesDialog::kSrcImages, _ui->actionImageFiles->isChecked()); _preferencesDialog->selectSourceImage(PreferencesDialog::kSrcImages);
} }
void MainWindow::selectVideo() void MainWindow::selectVideo()
{ {
_preferencesDialog->selectSourceImage(PreferencesDialog::kSrcVideo, _ui->actionVideo->isChecked()); _preferencesDialog->selectSourceImage(PreferencesDialog::kSrcVideo);
} }
void MainWindow::selectStream() void MainWindow::selectStream()
{ {
_preferencesDialog->selectSourceImage(PreferencesDialog::kSrcUsbDevice, _ui->actionUsbCamera->isChecked()); _preferencesDialog->selectSourceImage(PreferencesDialog::kSrcUsbDevice);
} }
void MainWindow::selectDatabase() void MainWindow::selectDatabase()
{ {
_preferencesDialog->selectSourceDatabase(true, _ui->actionDatabase->isChecked()); _preferencesDialog->selectSourceDatabase(true);
} }
void MainWindow::selectOpenni() void MainWindow::selectOpenni()
{ {
_preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_PCL, _preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_PCL);
_ui->actionOpenNI_PCL->isChecked() ||
_ui->actionOpenNI_PCL_ASUS->isChecked());
} }
void MainWindow::selectFreenect() void MainWindow::selectFreenect()
{ {
_preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcFreenect, _preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcFreenect);
_ui->actionFreenect->isChecked());
} }
void MainWindow::selectOpenniCv() void MainWindow::selectOpenniCv()
{ {
_preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_CV, _preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_CV);
_ui->actionOpenNI_CV->isChecked());
} }
void MainWindow::selectOpenniCvAsus() void MainWindow::selectOpenniCvAsus()
{ {
_preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_CV_ASUS, _preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI_CV_ASUS);
_ui->actionOpenNI_CV_ASUS->isChecked());
} }
void MainWindow::selectOpenni2() void MainWindow::selectOpenni2()
{ {
_preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI2, _preferencesDialog->selectSourceRGBD(PreferencesDialog::kSrcOpenNI2);
_ui->actionOpenNI2->isChecked() ||
_ui->actionOpenNI2_Sense->isChecked() ||
_ui->actionOpenNI2_kinect->isChecked());
} }

View File

@@ -1968,7 +1968,7 @@ QString PreferencesDialog::loadCustomConfig(const QString & section, const QStri
return value; return value;
} }
void PreferencesDialog::selectSourceImage(Src src, bool ckecked) void PreferencesDialog::selectSourceImage(Src src)
{ {
ULOGGER_DEBUG(""); ULOGGER_DEBUG("");
@@ -1992,8 +1992,6 @@ void PreferencesDialog::selectSourceImage(Src src, bool ckecked)
} }
if(!fromPrefDialog) if(!fromPrefDialog)
{
if(ckecked)
{ {
if(_ui->general_checkBox_activateRGBD->isChecked()) if(_ui->general_checkBox_activateRGBD->isChecked())
{ {
@@ -2009,11 +2007,6 @@ void PreferencesDialog::selectSourceImage(Src src, bool ckecked)
} }
} }
_ui->groupBox_sourceImage->setChecked(false);
}
if(ckecked)
{
if(src == kSrcImages) if(src == kSrcImages)
{ {
QString path = QFileDialog::getExistingDirectory(this, QString(), _ui->source_images_lineEdit_path->text()); QString path = QFileDialog::getExistingDirectory(this, QString(), _ui->source_images_lineEdit_path->text());
@@ -2056,7 +2049,6 @@ void PreferencesDialog::selectSourceImage(Src src, bool ckecked)
_ui->source_comboBox_image_type->setCurrentIndex(0); _ui->source_comboBox_image_type->setCurrentIndex(0);
_ui->groupBox_sourceImage->setChecked(true); _ui->groupBox_sourceImage->setChecked(true);
} }
}
if(_ui->groupBox_sourceImage->isChecked()) if(_ui->groupBox_sourceImage->isChecked())
{ {
@@ -2080,17 +2072,10 @@ void PreferencesDialog::selectSourceImage(Src src, bool ckecked)
} }
} }
void PreferencesDialog::selectSourceDatabase(bool user, bool ckecked) void PreferencesDialog::selectSourceDatabase(bool user)
{ {
ULOGGER_DEBUG(""); ULOGGER_DEBUG("");
if(user)
{
_ui->groupBox_sourceDatabase->setChecked(false);
}
if(ckecked)
{
QString dir = _ui->source_database_lineEdit_path->text(); QString dir = _ui->source_database_lineEdit_path->text();
if(dir.isEmpty()) if(dir.isEmpty())
{ {
@@ -2107,7 +2092,6 @@ void PreferencesDialog::selectSourceDatabase(bool user, bool ckecked)
_ui->source_database_lineEdit_path->setText(path); _ui->source_database_lineEdit_path->setText(path);
_ui->source_spinBox_databaseStartPos->setValue(0); _ui->source_spinBox_databaseStartPos->setValue(0);
} }
}
if(_ui->groupBox_sourceDatabase->isChecked()) if(_ui->groupBox_sourceDatabase->isChecked())
{ {
@@ -2131,12 +2115,10 @@ void PreferencesDialog::selectSourceDatabase(bool user, bool ckecked)
} }
} }
void PreferencesDialog::selectSourceRGBD(Src src, bool ckecked) void PreferencesDialog::selectSourceRGBD(Src src)
{ {
ULOGGER_DEBUG(""); ULOGGER_DEBUG("");
if(ckecked)
{
if(!_ui->general_checkBox_activateRGBD->isChecked()) if(!_ui->general_checkBox_activateRGBD->isChecked())
{ {
int button = QMessageBox::information(this, int button = QMessageBox::information(this,
@@ -2149,9 +2131,8 @@ void PreferencesDialog::selectSourceRGBD(Src src, bool ckecked)
_ui->general_checkBox_activateRGBD->setChecked(true); _ui->general_checkBox_activateRGBD->setChecked(true);
} }
} }
}
_ui->groupBox_sourceOpenni->setChecked(ckecked); _ui->groupBox_sourceOpenni->setChecked(true);
_ui->radioButton_opennipcl->setChecked(src == kSrcOpenNI_PCL); _ui->radioButton_opennipcl->setChecked(src == kSrcOpenNI_PCL);
_ui->radioButton_freenect->setChecked(src == kSrcFreenect); _ui->radioButton_freenect->setChecked(src == kSrcFreenect);
_ui->radioButton_opennicv->setChecked(src == kSrcOpenNI_CV); _ui->radioButton_opennicv->setChecked(src == kSrcOpenNI_CV);