diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt
index 2a29f69933..381799bfb4 100644
--- a/tools/lammps-gui/CMakeLists.txt
+++ b/tools/lammps-gui/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)
-project(lammps-gui VERSION 1.6.0 LANGUAGES CXX)
+project(lammps-gui VERSION 1.6.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
diff --git a/tools/lammps-gui/TODO.md b/tools/lammps-gui/TODO.md
index 7af2a4a4c6..323c46fc57 100644
--- a/tools/lammps-gui/TODO.md
+++ b/tools/lammps-gui/TODO.md
@@ -2,7 +2,6 @@ LAMMPS-GUI TODO list:
# Short term goals (v1.x)
-- add "export YAML data" to Output viewer, if YAML thermo data is detected.
- add "export to YAML" to chart viewer.
- implement indenting regions for (nested) loops?
diff --git a/tools/lammps-gui/lammpsgui.qrc b/tools/lammps-gui/lammpsgui.qrc
index 8b8f7f950e..fe1129a4a3 100644
--- a/tools/lammps-gui/lammpsgui.qrc
+++ b/tools/lammps-gui/lammpsgui.qrc
@@ -59,5 +59,6 @@
icons/vmd.png
icons/window-close.png
icons/x-office-drawing.png
+ icons/yaml-file-icon.png
diff --git a/tools/lammps-gui/logwindow.cpp b/tools/lammps-gui/logwindow.cpp
index 05887c329c..9997f51bfc 100644
--- a/tools/lammps-gui/logwindow.cpp
+++ b/tools/lammps-gui/logwindow.cpp
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -37,6 +38,8 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) :
auto *action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this);
connect(action, &QShortcut::activated, this, &LogWindow::save_as);
+ action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Y), this);
+ connect(action, &QShortcut::activated, this, &LogWindow::extract_yaml);
action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this);
connect(action, &QShortcut::activated, this, &LogWindow::quit);
action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), this);
@@ -94,6 +97,31 @@ void LogWindow::save_as()
file.close();
}
+void LogWindow::extract_yaml()
+{
+ QString defaultname = filename + ".yaml";
+ if (filename.isEmpty()) defaultname = "lammps.yaml";
+ QString yamlFileName = QFileDialog::getSaveFileName(this, "Save YAML data to File", defaultname,
+ "YAML files (*.yaml *.yml)");
+ if (yamlFileName.isEmpty()) return;
+
+ QFileInfo path(yamlFileName);
+ QFile file(path.absoluteFilePath());
+
+ if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
+ return;
+ }
+
+ QRegularExpression is_yaml("^(keywords:.*$|data:$|---$|\\.\\.\\.$| - \\[.*\\]$)");
+ QTextStream out(&file);
+ QStringList lines = toPlainText().split('\n');
+ for (const auto &line : lines) {
+ if (is_yaml.match(line).hasMatch()) out << line << '\n';
+ }
+ file.close();
+}
+
void LogWindow::contextMenuEvent(QContextMenuEvent *event)
{
// show augmented context menu
@@ -103,6 +131,10 @@ void LogWindow::contextMenuEvent(QContextMenuEvent *event)
action->setIcon(QIcon(":/icons/document-save-as.png"));
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
connect(action, &QAction::triggered, this, &LogWindow::save_as);
+ action = menu->addAction(QString("&Export YAML Data to File ..."));
+ action->setIcon(QIcon(":/icons/yaml-file-icon.png"));
+ action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Y));
+ connect(action, &QAction::triggered, this, &LogWindow::extract_yaml);
action = menu->addAction("&Close Window", this, &QWidget::close);
action->setIcon(QIcon(":/icons/window-close.png"));
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W));
diff --git a/tools/lammps-gui/logwindow.h b/tools/lammps-gui/logwindow.h
index ad0691d0cc..93ba06fbe7 100644
--- a/tools/lammps-gui/logwindow.h
+++ b/tools/lammps-gui/logwindow.h
@@ -23,6 +23,7 @@ public:
LogWindow(const QString &filename, QWidget *parent = nullptr);
private slots:
+ void extract_yaml();
void quit();
void save_as();
void stop_run();