extract YAML format thermo data from output window text
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
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_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|||||||
@ -2,7 +2,6 @@ LAMMPS-GUI TODO list:
|
|||||||
|
|
||||||
# Short term goals (v1.x)
|
# 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.
|
- add "export to YAML" to chart viewer.
|
||||||
|
|
||||||
- implement indenting regions for (nested) loops?
|
- implement indenting regions for (nested) loops?
|
||||||
|
|||||||
@ -59,5 +59,6 @@
|
|||||||
<file>icons/vmd.png</file>
|
<file>icons/vmd.png</file>
|
||||||
<file>icons/window-close.png</file>
|
<file>icons/window-close.png</file>
|
||||||
<file>icons/x-office-drawing.png</file>
|
<file>icons/x-office-drawing.png</file>
|
||||||
|
<file>icons/yaml-file-icon.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -37,6 +38,8 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) :
|
|||||||
|
|
||||||
auto *action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this);
|
auto *action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this);
|
||||||
connect(action, &QShortcut::activated, this, &LogWindow::save_as);
|
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);
|
action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this);
|
||||||
connect(action, &QShortcut::activated, this, &LogWindow::quit);
|
connect(action, &QShortcut::activated, this, &LogWindow::quit);
|
||||||
action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), this);
|
action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), this);
|
||||||
@ -94,6 +97,31 @@ void LogWindow::save_as()
|
|||||||
file.close();
|
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)
|
void LogWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
// show augmented context menu
|
// show augmented context menu
|
||||||
@ -103,6 +131,10 @@ void LogWindow::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
action->setIcon(QIcon(":/icons/document-save-as.png"));
|
action->setIcon(QIcon(":/icons/document-save-as.png"));
|
||||||
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
|
||||||
connect(action, &QAction::triggered, this, &LogWindow::save_as);
|
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 = menu->addAction("&Close Window", this, &QWidget::close);
|
||||||
action->setIcon(QIcon(":/icons/window-close.png"));
|
action->setIcon(QIcon(":/icons/window-close.png"));
|
||||||
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W));
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W));
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public:
|
|||||||
LogWindow(const QString &filename, QWidget *parent = nullptr);
|
LogWindow(const QString &filename, QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void extract_yaml();
|
||||||
void quit();
|
void quit();
|
||||||
void save_as();
|
void save_as();
|
||||||
void stop_run();
|
void stop_run();
|
||||||
|
|||||||
Reference in New Issue
Block a user