Commit 4d06a20b authored by Tobias WEBER's avatar Tobias WEBER
Browse files

small update: added progress dialog

parent b7db68d0
......@@ -14,6 +14,9 @@
#include <vector>
#include <string>
// for progress callback
#include <boost/signals2/signal.hpp>
#include "libs/file.h"
#include "libs/str.h"
......@@ -133,9 +136,6 @@ class MolDyn
return 0;
}
// clear old data
Clear();
std::size_t filesize = tl2::get_file_size(ifstr);
std::cout << "File size: " << filesize / 1024 / 1024 << " MB." << std::endl;
......@@ -270,6 +270,11 @@ class MolDyn
std::size_t filepos = tl2::get_file_pos(ifstr);
percentage = t_real{filepos*100} / t_real{filesize};
if(!*m_sigLoadProgress(percentage))
{
std::cerr << "\nLoading cancelled." << std::endl;
return 0;
}
}
std::cout << "\rRead " << iNumConfigs << " configurations. " << " " << std::endl;
......@@ -277,11 +282,18 @@ class MolDyn
}
template<class subscriber> void SubscribeToLoadProgress(const subscriber& subs)
{
m_sigLoadProgress.connect(subs);
}
void Clear()
{
m_vecAtoms.clear();
m_vecAtomNums.clear();
m_frames.clear();
m_sigLoadProgress.disconnect_all_slots();
}
......@@ -294,6 +306,8 @@ class MolDyn
std::vector<unsigned int> m_vecAtomNums;
std::vector<MolFrame<t_real, t_vec>> m_frames;
boost::signals2::signal<bool (t_real)> m_sigLoadProgress;
};
......
......@@ -14,6 +14,7 @@
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QProgressDialog>
#include <iostream>
#include <tuple>
......@@ -278,9 +279,23 @@ void MolDynDlg::Load()
m_sett->setValue("dir", QFileInfo(filename).path());
New();
std::shared_ptr<QProgressDialog> dlgProgress = std::make_shared<QProgressDialog>(
"Loading \"" + QFileInfo(filename).fileName() + "\"...", "Cancel", 0, 1000, this);
bool bCancelled = 0;
m_mol.SubscribeToLoadProgress([dlgProgress, &bCancelled](t_real percentage) -> bool
{
dlgProgress->setValue(int(percentage*10));
bCancelled = dlgProgress->wasCanceled();
return !bCancelled;
});
dlgProgress->setWindowModality(Qt::WindowModal);
if(!m_mol.LoadFile(filename.toStdString(), filedlg->GetFrameSkip()))
{
QMessageBox::critical(this, "Molecular Dynamics", "Error loading file.");
// only show error if not explicitely cancelled
if(!bCancelled)
QMessageBox::critical(this, "Molecular Dynamics", "Error loading file.");
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment