try to free resources allocated by inspecting restart files
This commit is contained in:
@ -6,7 +6,6 @@ LAMMPS-GUI TODO list:
|
|||||||
- figure out stacking order of frames and whether it can be more flexible
|
- figure out stacking order of frames and whether it can be more flexible
|
||||||
- figure out how to avoid corrupted cached thermo data while reading it.
|
- figure out how to avoid corrupted cached thermo data while reading it.
|
||||||
- implement a timed "Auto-Save" feature that saves after some idle time. set timeout in Editor preferences.
|
- implement a timed "Auto-Save" feature that saves after some idle time. set timeout in Editor preferences.
|
||||||
- bundle or download? LAMMPS tutorial input files
|
|
||||||
- add a "Colors" menu to the image viewer to adjust color settings for the
|
- add a "Colors" menu to the image viewer to adjust color settings for the
|
||||||
current image (unlike the defaults in the perferences). Support color by
|
current image (unlike the defaults in the perferences). Support color by
|
||||||
property (e.g. scan computes or fixes with per-atom data), define colormaps etc.
|
property (e.g. scan computes or fixes with per-atom data), define colormaps etc.
|
||||||
|
|||||||
@ -87,6 +87,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
current_dir = QDir(".").absolutePath();
|
current_dir = QDir(".").absolutePath();
|
||||||
// use $HOME if we get dropped to "/" like on macOS
|
// use $HOME if we get dropped to "/" like on macOS
|
||||||
if (current_dir == "/") current_dir = QDir::homePath();
|
if (current_dir == "/") current_dir = QDir::homePath();
|
||||||
|
inspectList.clear();
|
||||||
|
|
||||||
#define stringify(x) myxstr(x)
|
#define stringify(x) myxstr(x)
|
||||||
#define myxstr(x) #x
|
#define myxstr(x) #x
|
||||||
@ -585,6 +586,7 @@ void LammpsGui::update_variables()
|
|||||||
// open file and switch CWD to path of file
|
// open file and switch CWD to path of file
|
||||||
void LammpsGui::open_file(const QString &fileName)
|
void LammpsGui::open_file(const QString &fileName)
|
||||||
{
|
{
|
||||||
|
purge_inspect_list();
|
||||||
if (ui->textEdit->document()->isModified()) {
|
if (ui->textEdit->document()->isModified()) {
|
||||||
QMessageBox msg;
|
QMessageBox msg;
|
||||||
msg.setWindowTitle("Unsaved Changes");
|
msg.setWindowTitle("Unsaved Changes");
|
||||||
@ -675,12 +677,44 @@ void LammpsGui::view_file(const QString &fileName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LammpsGui::purge_inspect_list()
|
||||||
|
{
|
||||||
|
for (auto item : inspectList) {
|
||||||
|
if (item->info) {
|
||||||
|
if (!item->info->isVisible()) {
|
||||||
|
delete item->info;
|
||||||
|
item->info = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item->data) {
|
||||||
|
if (!item->data->isVisible()) {
|
||||||
|
delete item->data;
|
||||||
|
item->data = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item->image) {
|
||||||
|
if (!item->image->isVisible()) {
|
||||||
|
delete item->image;
|
||||||
|
item->image = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!item->image && !item->data && !item->info) inspectList.removeOne(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// read restart file into LAMMPS instance and launch image viewer
|
// read restart file into LAMMPS instance and launch image viewer
|
||||||
void LammpsGui::inspect_file(const QString &fileName)
|
void LammpsGui::inspect_file(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
auto shortName = QFileInfo(fileName).fileName();
|
auto shortName = QFileInfo(fileName).fileName();
|
||||||
|
|
||||||
|
purge_inspect_list();
|
||||||
|
auto ilist = new InspectData;
|
||||||
|
ilist->info = nullptr;
|
||||||
|
ilist->data = nullptr;
|
||||||
|
ilist->image = nullptr;
|
||||||
|
inspectList.append(ilist);
|
||||||
|
|
||||||
if (file.size() > 262144000L) {
|
if (file.size() > 262144000L) {
|
||||||
QMessageBox msg;
|
QMessageBox msg;
|
||||||
msg.setWindowTitle(" Warning: Large Restart File ");
|
msg.setWindowTitle(" Warning: Large Restart File ");
|
||||||
@ -724,6 +758,7 @@ void LammpsGui::inspect_file(const QString &fileName)
|
|||||||
|
|
||||||
// LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running a simulation
|
// LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running a simulation
|
||||||
if (!lammps.is_running()) {
|
if (!lammps.is_running()) {
|
||||||
|
|
||||||
start_lammps();
|
start_lammps();
|
||||||
lammps.command("clear");
|
lammps.command("clear");
|
||||||
lammps.command(QString("read_restart %1").arg(fileName).toLocal8Bit());
|
lammps.command(QString("read_restart %1").arg(fileName).toLocal8Bit());
|
||||||
@ -740,15 +775,18 @@ void LammpsGui::inspect_file(const QString &fileName)
|
|||||||
auto *infoviewer =
|
auto *infoviewer =
|
||||||
new FileViewer(infolog, QString("LAMMPS-GUI: restart info for %1").arg(shortName));
|
new FileViewer(infolog, QString("LAMMPS-GUI: restart info for %1").arg(shortName));
|
||||||
infoviewer->show();
|
infoviewer->show();
|
||||||
|
ilist->info = infoviewer;
|
||||||
dumpinfo.remove();
|
dumpinfo.remove();
|
||||||
lammps.command(QString("write_data %1 pair ij noinit").arg(infodata).toLocal8Bit());
|
lammps.command(QString("write_data %1 pair ij noinit").arg(infodata).toLocal8Bit());
|
||||||
auto *dataviewer =
|
auto *dataviewer =
|
||||||
new FileViewer(infodata, QString("LAMMPS-GUI: data file for %1").arg(shortName));
|
new FileViewer(infodata, QString("LAMMPS-GUI: data file for %1").arg(shortName));
|
||||||
dataviewer->show();
|
dataviewer->show();
|
||||||
|
ilist->data = dataviewer;
|
||||||
QFile(infodata).remove();
|
QFile(infodata).remove();
|
||||||
auto *inspect_image = new ImageViewer(
|
auto *inspect_image = new ImageViewer(
|
||||||
fileName, &lammps, QString("LAMMPS-GUI: Image for %1").arg(shortName));
|
fileName, &lammps, QString("LAMMPS-GUI: Image for %1").arg(shortName));
|
||||||
inspect_image->show();
|
inspect_image->show();
|
||||||
|
ilist->image = inspect_image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -782,6 +820,7 @@ void LammpsGui::write_file(const QString &fileName)
|
|||||||
|
|
||||||
void LammpsGui::save()
|
void LammpsGui::save()
|
||||||
{
|
{
|
||||||
|
purge_inspect_list();
|
||||||
QString fileName = current_file;
|
QString fileName = current_file;
|
||||||
// If we don't have a filename from before, get one.
|
// If we don't have a filename from before, get one.
|
||||||
if (fileName.isEmpty()) fileName = QFileDialog::getSaveFileName(this, "Save");
|
if (fileName.isEmpty()) fileName = QFileDialog::getSaveFileName(this, "Save");
|
||||||
@ -1095,6 +1134,7 @@ void LammpsGui::do_run(bool use_buffer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
purge_inspect_list();
|
||||||
autoSave();
|
autoSave();
|
||||||
if (!use_buffer && ui->textEdit->document()->isModified()) {
|
if (!use_buffer && ui->textEdit->document()->isModified()) {
|
||||||
QMessageBox msg;
|
QMessageBox msg;
|
||||||
|
|||||||
@ -48,6 +48,7 @@ class QLabel;
|
|||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
class Highlighter;
|
class Highlighter;
|
||||||
class StdCapture;
|
class StdCapture;
|
||||||
@ -78,6 +79,7 @@ protected:
|
|||||||
void run_done();
|
void run_done();
|
||||||
void setDocver();
|
void setDocver();
|
||||||
void autoSave();
|
void autoSave();
|
||||||
|
void purge_inspect_list();
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -136,6 +138,13 @@ private:
|
|||||||
QLabel *lammpsstatus;
|
QLabel *lammpsstatus;
|
||||||
QLabel *varwindow;
|
QLabel *varwindow;
|
||||||
|
|
||||||
|
struct InspectData {
|
||||||
|
QWidget *info;
|
||||||
|
QWidget *data;
|
||||||
|
QWidget *image;
|
||||||
|
};
|
||||||
|
QList<InspectData *> inspectList;
|
||||||
|
|
||||||
QString current_file;
|
QString current_file;
|
||||||
QString current_dir;
|
QString current_dir;
|
||||||
QList<QString> recent;
|
QList<QString> recent;
|
||||||
|
|||||||
Reference in New Issue
Block a user