add button to stop a run via lammps_force_timeout()

This commit is contained in:
Axel Kohlmeyer
2023-07-27 03:21:34 -04:00
parent da0669d988
commit f81ee57c97
5 changed files with 78 additions and 38 deletions

View File

@ -67,6 +67,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->actionStop_LAMMPS, &QAction::triggered, this, &LammpsGui::stop_run);
connect(ui->actionAbout_LAMMPS_GUI, &QAction::triggered, this, &LammpsGui::about);
#if !QT_CONFIG(clipboard)
@ -237,29 +238,37 @@ void LammpsGui::redo()
ui->textEdit->redo();
}
void LammpsGui::stop_run()
{
#if defined(LAMMPS_GUI_USE_PLUGIN)
((liblammpsplugin_t *)plugin_handle)->force_timeout(lammps_handle);
#else
lammps_force_timeout(lammps_handle);
#endif
}
void LammpsGui::logupdate()
{
double t_elapsed, t_remain, t_total;
int completed = 1000;
if (is_running) {
#if defined(LAMMPS_GUI_USE_PLUGIN)
liblammpsplugin_t *lammps = (liblammpsplugin_t *)plugin_handle;
if (lammps->is_running(lammps_handle)) {
t_elapsed = lammps->get_thermo(lammps_handle, "cpu");
t_remain = lammps->get_thermo(lammps_handle, "cpuremain");
t_total = t_elapsed + t_remain + 1.0e-10;
completed = t_elapsed / t_total * 1000.0;
}
#else
if (lammps_is_running(lammps_handle)) {
t_elapsed = lammps_get_thermo(lammps_handle, "cpu");
t_remain = lammps_get_thermo(lammps_handle, "cpuremain");
t_total = t_elapsed + t_remain + 1.0e-10;
completed = t_elapsed / t_total * 1000.0;
}
#endif
liblammpsplugin_t *lammps = (liblammpsplugin_t *)plugin_handle;
if (lammps->is_running(lammps_handle)) {
t_elapsed = lammps->get_thermo(lammps_handle, "cpu");
t_remain = lammps->get_thermo(lammps_handle, "cpuremain");
t_total = t_elapsed + t_remain + 1.0e-10;
completed = t_elapsed / t_total * 1000.0;
}
#else
if (lammps_is_running(lammps_handle)) {
t_elapsed = lammps_get_thermo(lammps_handle, "cpu");
t_remain = lammps_get_thermo(lammps_handle, "cpuremain");
t_total = t_elapsed + t_remain + 1.0e-10;
completed = t_elapsed / t_total * 1000.0;
}
#endif
progress->setValue(completed);
if (logwindow) {
const auto text = capturer->GetChunk();
@ -283,7 +292,7 @@ void LammpsGui::run_done()
logwindow->insertPlainText(log.c_str());
logwindow->moveCursor(QTextCursor::End);
bool success = true;
bool success = true;
constexpr int BUFLEN = 1024;
char errorbuf[BUFLEN];
@ -345,6 +354,8 @@ void LammpsGui::run_buffer()
logwindow->setMinimumSize(800, 600);
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), logwindow);
QObject::connect(shortcut, &QShortcut::activated, logwindow, &QPlainTextEdit::close);
shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Slash), logwindow);
QObject::connect(shortcut, &QShortcut::activated, this, &LammpsGui::stop_run);
logwindow->show();
logupdater = new QTimer(this);

View File

@ -59,6 +59,7 @@ private slots:
void redo();
void clear();
void run_buffer();
void stop_run();
void about();
void logupdate();

View File

@ -68,15 +68,23 @@
<addaction name="actionCut"/>
<addaction name="actionPaste"/>
</widget>
<widget class="QMenu" name="menu_Run">
<property name="title">
<string>&amp;Run</string>
</property>
<addaction name="actionRun_Buffer"/>
<addaction name="actionStop_LAMMPS"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="actionRun_Buffer"/>
<addaction name="menu_Run"/>
<addaction name="actionAbout_LAMMPS_GUI"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionNew">
<property name="icon">
<iconset theme="document-new"/>
<iconset theme="document-new">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;New</string>
@ -93,7 +101,8 @@
</action>
<action name="actionOpen">
<property name="icon">
<iconset theme="document-open"/>
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Open</string>
@ -110,7 +119,8 @@
</action>
<action name="actionSave">
<property name="icon">
<iconset theme="document-save"/>
<iconset theme="document-save">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Save</string>
@ -127,7 +137,8 @@
</action>
<action name="actionSave_As">
<property name="icon">
<iconset theme="document-save-as"/>
<iconset theme="document-save-as">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Save &amp;As</string>
@ -144,7 +155,8 @@
</action>
<action name="actionQuit">
<property name="icon">
<iconset theme="application-exit"/>
<iconset theme="application-exit">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Quit</string>
@ -161,7 +173,8 @@
</action>
<action name="actionCut">
<property name="icon">
<iconset theme="edit-cut"/>
<iconset theme="edit-cut">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>C&amp;ut</string>
@ -175,7 +188,8 @@
</action>
<action name="actionCopy">
<property name="icon">
<iconset theme="edit-copy"/>
<iconset theme="edit-copy">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Copy</string>
@ -189,7 +203,8 @@
</action>
<action name="actionPaste">
<property name="icon">
<iconset theme="edit-paste"/>
<iconset theme="edit-paste">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Paste</string>
@ -203,7 +218,8 @@
</action>
<action name="actionUndo">
<property name="icon">
<iconset theme="edit-undo"/>
<iconset theme="edit-undo">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Undo</string>
@ -217,7 +233,8 @@
</action>
<action name="actionRedo">
<property name="icon">
<iconset theme="edit-redo"/>
<iconset theme="edit-redo">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Redo</string>
@ -230,6 +247,9 @@
</property>
</action>
<action name="actionRun_Buffer">
<property name="icon">
<iconset theme="emblem-default"/>
</property>
<property name="text">
<string>&amp;Run LAMMPS</string>
</property>
@ -240,6 +260,20 @@
<string>Ctrl+Return</string>
</property>
</action>
<action name="actionStop_LAMMPS">
<property name="icon">
<iconset theme="process-stop"/>
</property>
<property name="text">
<string>&amp;Stop LAMMPS</string>
</property>
<property name="toolTip">
<string>Stop LAMMPS Process</string>
</property>
<property name="shortcut">
<string>Ctrl+/</string>
</property>
</action>
<action name="actionAbout_LAMMPS_GUI">
<property name="text">
<string>&amp;About</string>

View File

@ -21,16 +21,10 @@ class LineNumberArea : public QWidget {
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor) {}
QSize sizeHint() const override
{
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
QSize sizeHint() const override { return QSize(codeEditor->lineNumberAreaWidth(), 0); }
protected:
void paintEvent(QPaintEvent *event) override
{
codeEditor->lineNumberAreaPaintEvent(event);
}
void paintEvent(QPaintEvent *event) override { codeEditor->lineNumberAreaPaintEvent(event); }
private:
CodeEditor *codeEditor;

View File

@ -35,7 +35,7 @@
#include <fcntl.h>
#include <thread>
StdCapture::StdCapture() : m_oldStdOut(0), m_capturing(false)
StdCapture::StdCapture() : m_oldStdOut(0), m_capturing(false)
{
// make stdout unbuffered so that we don't need to flush the stream
setvbuf(stdout, NULL, _IONBF, 0);
@ -105,7 +105,7 @@ std::string StdCapture::GetChunk()
{
if (!m_capturing) return std::string();
int bytesRead = 0;
buf[0] = '\0';
buf[0] = '\0';
#ifdef _WIN32
if (!eof(m_pipe[READ])) {