add support to run LAMMPS on the file instead of the edit buffer
This commit is contained in:
@ -211,6 +211,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
connect(ui->actionUndo, &QAction::triggered, this, &LammpsGui::undo);
|
||||
connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo);
|
||||
connect(ui->actionRun_Buffer, &QAction::triggered, this, &LammpsGui::run_buffer);
|
||||
connect(ui->actionRun_File, &QAction::triggered, this, &LammpsGui::run_file);
|
||||
connect(ui->actionStop_LAMMPS, &QAction::triggered, this, &LammpsGui::stop_run);
|
||||
connect(ui->actionSet_Variables, &QAction::triggered, this, &LammpsGui::edit_variables);
|
||||
connect(ui->actionImage, &QAction::triggered, this, &LammpsGui::render_image);
|
||||
@ -810,13 +811,34 @@ void LammpsGui::run_done()
|
||||
dirstatus->show();
|
||||
}
|
||||
|
||||
void LammpsGui::run_buffer()
|
||||
void LammpsGui::do_run(bool use_buffer)
|
||||
{
|
||||
if (lammps.is_running()) {
|
||||
QMessageBox::warning(this, "LAMMPS GUI Error",
|
||||
"Must stop current run before starting a new run");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!use_buffer && ui->textEdit->document()->isModified()) {
|
||||
QMessageBox msg;
|
||||
msg.setWindowTitle("Unsaved Changes");
|
||||
msg.setWindowIcon(windowIcon());
|
||||
msg.setText(QString("The buffer ") + current_file + " has changes");
|
||||
msg.setInformativeText("Do you want to save the buffer before running LAMMPS?");
|
||||
msg.setIcon(QMessageBox::Question);
|
||||
msg.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
||||
int rv = msg.exec();
|
||||
switch (rv) {
|
||||
case QMessageBox::Yes:
|
||||
save();
|
||||
break;
|
||||
case QMessageBox::Cancel: // falthrough
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
progress->setValue(0);
|
||||
dirstatus->hide();
|
||||
@ -836,12 +858,17 @@ void LammpsGui::run_buffer()
|
||||
clear();
|
||||
capturer->BeginCapture();
|
||||
|
||||
runner = new LammpsRunner(this);
|
||||
is_running = true;
|
||||
if (use_buffer) {
|
||||
// always add final newline since the text edit widget does not
|
||||
char *input = mystrdup(ui->textEdit->toPlainText().toStdString() + "\n");
|
||||
is_running = true;
|
||||
runner->setup_run(&lammps, input, nullptr);
|
||||
} else {
|
||||
char *fname = mystrdup(current_file.toStdString());
|
||||
runner->setup_run(&lammps, nullptr, fname);
|
||||
}
|
||||
|
||||
runner = new LammpsRunner(this);
|
||||
runner->setup_run(&lammps, input);
|
||||
connect(runner, &LammpsRunner::resultReady, this, &LammpsGui::run_done);
|
||||
connect(runner, &LammpsRunner::finished, runner, &QObject::deleteLater);
|
||||
runner->start();
|
||||
@ -852,8 +879,12 @@ void LammpsGui::run_buffer()
|
||||
logwindow->setReadOnly(true);
|
||||
logwindow->setCenterOnScroll(true);
|
||||
logwindow->moveCursor(QTextCursor::End);
|
||||
if (use_buffer)
|
||||
logwindow->setWindowTitle("LAMMPS-GUI - Output from running LAMMPS on buffer - " +
|
||||
current_file);
|
||||
else
|
||||
logwindow->setWindowTitle("LAMMPS-GUI - Output from running LAMMPS on file - " +
|
||||
current_file);
|
||||
logwindow->setWindowIcon(QIcon(":/lammps-icon-128x128.png"));
|
||||
QFont text_font;
|
||||
text_font.fromString(settings.value("textfont", text_font.toString()).toString());
|
||||
@ -872,8 +903,12 @@ void LammpsGui::run_buffer()
|
||||
// if configured, delete old log window before opening new one
|
||||
if (settings.value("chartreplace", false).toBool()) delete chartwindow;
|
||||
chartwindow = new ChartWindow(current_file);
|
||||
if (use_buffer)
|
||||
chartwindow->setWindowTitle("LAMMPS-GUI - Thermo charts from running LAMMPS on buffer - " +
|
||||
current_file);
|
||||
else
|
||||
chartwindow->setWindowTitle("LAMMPS-GUI - Thermo charts from running LAMMPS on file - " +
|
||||
current_file);
|
||||
chartwindow->setWindowIcon(QIcon(":/lammps-icon-128x128.png"));
|
||||
chartwindow->setMinimumSize(400, 300);
|
||||
shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), chartwindow);
|
||||
|
||||
@ -60,6 +60,7 @@ protected:
|
||||
void write_file(const QString &filename);
|
||||
void update_recents(const QString &filename = "");
|
||||
void update_variables();
|
||||
void do_run(bool use_buffer);
|
||||
void start_lammps();
|
||||
void run_done();
|
||||
|
||||
@ -77,7 +78,9 @@ private slots:
|
||||
void undo();
|
||||
void redo();
|
||||
void clear();
|
||||
void run_buffer();
|
||||
void run_buffer() { do_run(true); }
|
||||
void run_file() { do_run(false); }
|
||||
|
||||
void stop_run();
|
||||
void edit_variables();
|
||||
void render_image();
|
||||
|
||||
@ -1,48 +1,49 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>lammps-icon-128x128.png</file>
|
||||
<file>help_index.table</file>
|
||||
<file>system-help.png</file>
|
||||
<file>help-browser.png</file>
|
||||
<file>gtk-zoom-in.png</file>
|
||||
<file>gtk-zoom-out.png</file>
|
||||
<file>gtk-zoom-fit.png</file>
|
||||
<file>edit-delete.png</file>
|
||||
<file>object-rotate-right.png</file>
|
||||
<file>object-rotate-left.png</file>
|
||||
<file>gtk-go-up.png</file>
|
||||
<file>gtk-go-down.png</file>
|
||||
<file>document-save-as.png</file>
|
||||
<file>antialias.png</file>
|
||||
<file>application-calc.png</file>
|
||||
<file>application-exit.png</file>
|
||||
<file>application-plot.png</file>
|
||||
<file>axes-img.png</file>
|
||||
<file>document-new.png</file>
|
||||
<file>document-open-recent.png</file>
|
||||
<file>document-open.png</file>
|
||||
<file>document-new.png</file>
|
||||
<file>edit-undo.png</file>
|
||||
<file>edit-redo.png</file>
|
||||
<file>edit-paste.png</file>
|
||||
<file>edit-cut.png</file>
|
||||
<file>edit-copy.png</file>
|
||||
<file>application-exit.png</file>
|
||||
<file>utilities-terminal.png</file>
|
||||
<file>x-office-drawing.png</file>
|
||||
<file>document-save.png</file>
|
||||
<file>document-revert.png</file>
|
||||
<file>preferences-desktop.png</file>
|
||||
<file>preferences-desktop-personal.png</file>
|
||||
<file>preferences-desktop-font.png</file>
|
||||
<file>help-faq.png</file>
|
||||
<file>help-about.png</file>
|
||||
<file>document-save-as.png</file>
|
||||
<file>document-save.png</file>
|
||||
<file>edit-copy.png</file>
|
||||
<file>edit-cut.png</file>
|
||||
<file>edit-delete.png</file>
|
||||
<file>edit-paste.png</file>
|
||||
<file>edit-redo.png</file>
|
||||
<file>edit-undo.png</file>
|
||||
<file>emblem-photos.png</file>
|
||||
<file>process-stop.png</file>
|
||||
<file>system-run.png</file>
|
||||
<file>window-close.png</file>
|
||||
<file>application-plot.png</file>
|
||||
<file>application-calc.png</file>
|
||||
<file>system-box.png</file>
|
||||
<file>axes-img.png</file>
|
||||
<file>gtk-go-down.png</file>
|
||||
<file>gtk-go-up.png</file>
|
||||
<file>gtk-zoom-fit.png</file>
|
||||
<file>gtk-zoom-in.png</file>
|
||||
<file>gtk-zoom-out.png</file>
|
||||
<file>hd-img.png</file>
|
||||
<file>antialias.png</file>
|
||||
<file>help-about.png</file>
|
||||
<file>help-browser.png</file>
|
||||
<file>help-faq.png</file>
|
||||
<file>help_index.table</file>
|
||||
<file>object-rotate-left.png</file>
|
||||
<file>object-rotate-right.png</file>
|
||||
<file>ovito.png</file>
|
||||
<file>vmd.png</file>
|
||||
<file>preferences-desktop-font.png</file>
|
||||
<file>preferences-desktop-personal.png</file>
|
||||
<file>preferences-desktop.png</file>
|
||||
<file>process-stop.png</file>
|
||||
<file>run-file.png</file>
|
||||
<file>system-box.png</file>
|
||||
<file>system-help.png</file>
|
||||
<file>system-run.png</file>
|
||||
<file>utilities-terminal.png</file>
|
||||
<file>vdw-style.png</file>
|
||||
<file>vmd.png</file>
|
||||
<file>window-close.png</file>
|
||||
<file>x-office-drawing.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
<string>&Run</string>
|
||||
</property>
|
||||
<addaction name="actionRun_Buffer"/>
|
||||
<addaction name="actionRun_File"/>
|
||||
<addaction name="actionStop_LAMMPS"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSet_Variables"/>
|
||||
@ -215,12 +216,23 @@
|
||||
<iconset theme=":/system-run.png"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Run LAMMPS</string>
|
||||
<string>&Run LAMMPS from Editor Buffer</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Return</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRun_File">
|
||||
<property name="icon">
|
||||
<iconset theme=":/run-file.png"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Run LAMMPS from File</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+Return</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStop_LAMMPS">
|
||||
<property name="icon">
|
||||
<iconset theme=":/process-stop.png"/>
|
||||
|
||||
@ -27,16 +27,22 @@ public:
|
||||
// execute LAMMPS in runner thread
|
||||
void run() override
|
||||
{
|
||||
if (input) {
|
||||
lammps->commands_string(input);
|
||||
delete[] input;
|
||||
} else if (file) {
|
||||
lammps->file(file);
|
||||
delete[] file;
|
||||
}
|
||||
emit resultReady();
|
||||
}
|
||||
|
||||
// transfer info to worker thread and reset LAMMPS instance
|
||||
void setup_run(LammpsWrapper *_lammps, const char *_input)
|
||||
void setup_run(LammpsWrapper *_lammps, const char *_input, const char *_file = nullptr)
|
||||
{
|
||||
lammps = _lammps;
|
||||
input = _input;
|
||||
file = _file;
|
||||
lammps->command("clear");
|
||||
}
|
||||
|
||||
@ -46,6 +52,7 @@ signals:
|
||||
private:
|
||||
LammpsWrapper *lammps;
|
||||
const char *input;
|
||||
const char *file;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -147,6 +147,17 @@ void LammpsWrapper::command(const char *input)
|
||||
}
|
||||
}
|
||||
|
||||
void LammpsWrapper::file(const char *filename)
|
||||
{
|
||||
if (lammps_handle) {
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
((liblammpsplugin_t *)plugin_handle)->file(lammps_handle, filename);
|
||||
#else
|
||||
lammps_file(lammps_handle, filename);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void LammpsWrapper::commands_string(const char *input)
|
||||
{
|
||||
if (lammps_handle) {
|
||||
|
||||
@ -23,6 +23,7 @@ public:
|
||||
void close();
|
||||
void finalize();
|
||||
|
||||
void file(const char *);
|
||||
void command(const char *);
|
||||
void commands_string(const char *);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user