add export to YAML to chart viewer
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(lammps-gui VERSION 1.6.3 LANGUAGES CXX)
|
||||
project(lammps-gui VERSION 1.6.4 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
@ -2,8 +2,7 @@ LAMMPS-GUI TODO list:
|
||||
|
||||
# Short term goals (v1.x)
|
||||
|
||||
- add a "file viewer", also view file option in editor context menu if word under cursor is a file
|
||||
- add "export to YAML" to chart viewer.
|
||||
- bundle LAMMPS tutorial input files
|
||||
|
||||
- implement indenting regions for (nested) loops?
|
||||
- implement data file manager GUI with the following features:
|
||||
|
||||
@ -36,7 +36,9 @@
|
||||
using namespace QtCharts;
|
||||
|
||||
ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
||||
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")), filename(_filename)
|
||||
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")),
|
||||
saveAsAct(nullptr), exportCsvAct(nullptr), exportDatAct(nullptr), exportYamlAct(nullptr),
|
||||
closeAct(nullptr), stopAct(nullptr), quitAct(nullptr), filename(_filename)
|
||||
{
|
||||
auto *top = new QHBoxLayout;
|
||||
menu->addMenu(file);
|
||||
@ -61,6 +63,8 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
||||
exportCsvAct->setIcon(QIcon(":/icons/application-calc.png"));
|
||||
exportDatAct = file->addAction("Export data to &Gnuplot...", this, &ChartWindow::exportDat);
|
||||
exportDatAct->setIcon(QIcon(":/icons/application-plot.png"));
|
||||
exportYamlAct = file->addAction("Export data to &YAML...", this, &ChartWindow::exportYaml);
|
||||
exportYamlAct->setIcon(QIcon(":/icons/yaml-file-icon.png"));
|
||||
file->addSeparator();
|
||||
stopAct = file->addAction("Stop &Run", this, &ChartWindow::stop_run);
|
||||
stopAct->setIcon(QIcon(":/icons/process-stop.png"));
|
||||
@ -227,6 +231,40 @@ void ChartWindow::exportCsv()
|
||||
}
|
||||
}
|
||||
}
|
||||
void ChartWindow::exportYaml()
|
||||
{
|
||||
if (charts.empty()) return;
|
||||
QString defaultname = filename + ".yaml";
|
||||
if (filename.isEmpty()) defaultname = "lammpsdata.yaml";
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "Save Chart as YAML data", defaultname,
|
||||
"Image Files (*.yaml, *.yml)");
|
||||
if (!fileName.isEmpty()) {
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out.setRealNumberPrecision(8);
|
||||
out << "---\n";
|
||||
|
||||
out << "keywords: ['Step'";
|
||||
for (auto &c : charts)
|
||||
out << ", " << c->get_title();
|
||||
out << "]\n";
|
||||
|
||||
out << "data: \n";
|
||||
int lines = charts[0]->get_count();
|
||||
for (int i = 0; i < lines; ++i) {
|
||||
// timestep
|
||||
out << " - [" << charts[0]->get_step(i);
|
||||
// data
|
||||
for (auto &c : charts)
|
||||
out << ", " << c->get_data(i);
|
||||
out << "]\n";
|
||||
}
|
||||
out << "...\n";
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChartWindow::change_chart(int)
|
||||
{
|
||||
|
||||
@ -50,6 +50,7 @@ private slots:
|
||||
void saveAs();
|
||||
void exportDat();
|
||||
void exportCsv();
|
||||
void exportYaml();
|
||||
|
||||
void change_chart(int index);
|
||||
|
||||
@ -61,7 +62,7 @@ private:
|
||||
QMenuBar *menu;
|
||||
QMenu *file;
|
||||
QComboBox *columns;
|
||||
QAction *saveAsAct, *exportCsvAct, *exportDatAct;
|
||||
QAction *saveAsAct, *exportCsvAct, *exportDatAct, *exportYamlAct;
|
||||
QAction *closeAct, *stopAct, *quitAct;
|
||||
|
||||
QString filename;
|
||||
|
||||
BIN
tools/lammps-gui/icons/application-yaml.png
Normal file
BIN
tools/lammps-gui/icons/application-yaml.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@ -9,6 +9,7 @@
|
||||
<file>icons/application-calc.png</file>
|
||||
<file>icons/application-exit.png</file>
|
||||
<file>icons/application-plot.png</file>
|
||||
<file>icons/application-yaml.png</file>
|
||||
<file>icons/axes-img.png</file>
|
||||
<file>icons/document-new.png</file>
|
||||
<file>icons/document-open-recent.png</file>
|
||||
|
||||
Reference in New Issue
Block a user