add button to stop a run via lammps_force_timeout()
This commit is contained in:
@ -67,6 +67,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
connect(ui->actionUndo, &QAction::triggered, this, &LammpsGui::undo);
|
connect(ui->actionUndo, &QAction::triggered, this, &LammpsGui::undo);
|
||||||
connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo);
|
connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo);
|
||||||
connect(ui->actionRun_Buffer, &QAction::triggered, this, &LammpsGui::run_buffer);
|
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);
|
connect(ui->actionAbout_LAMMPS_GUI, &QAction::triggered, this, &LammpsGui::about);
|
||||||
|
|
||||||
#if !QT_CONFIG(clipboard)
|
#if !QT_CONFIG(clipboard)
|
||||||
@ -237,29 +238,37 @@ void LammpsGui::redo()
|
|||||||
ui->textEdit->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()
|
void LammpsGui::logupdate()
|
||||||
{
|
{
|
||||||
double t_elapsed, t_remain, t_total;
|
double t_elapsed, t_remain, t_total;
|
||||||
int completed = 1000;
|
int completed = 1000;
|
||||||
|
|
||||||
if (is_running) {
|
|
||||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
liblammpsplugin_t *lammps = (liblammpsplugin_t *)plugin_handle;
|
liblammpsplugin_t *lammps = (liblammpsplugin_t *)plugin_handle;
|
||||||
if (lammps->is_running(lammps_handle)) {
|
if (lammps->is_running(lammps_handle)) {
|
||||||
t_elapsed = lammps->get_thermo(lammps_handle, "cpu");
|
t_elapsed = lammps->get_thermo(lammps_handle, "cpu");
|
||||||
t_remain = lammps->get_thermo(lammps_handle, "cpuremain");
|
t_remain = lammps->get_thermo(lammps_handle, "cpuremain");
|
||||||
t_total = t_elapsed + t_remain + 1.0e-10;
|
t_total = t_elapsed + t_remain + 1.0e-10;
|
||||||
completed = t_elapsed / t_total * 1000.0;
|
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
|
|
||||||
}
|
}
|
||||||
|
#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);
|
progress->setValue(completed);
|
||||||
if (logwindow) {
|
if (logwindow) {
|
||||||
const auto text = capturer->GetChunk();
|
const auto text = capturer->GetChunk();
|
||||||
@ -283,7 +292,7 @@ void LammpsGui::run_done()
|
|||||||
logwindow->insertPlainText(log.c_str());
|
logwindow->insertPlainText(log.c_str());
|
||||||
logwindow->moveCursor(QTextCursor::End);
|
logwindow->moveCursor(QTextCursor::End);
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
constexpr int BUFLEN = 1024;
|
constexpr int BUFLEN = 1024;
|
||||||
char errorbuf[BUFLEN];
|
char errorbuf[BUFLEN];
|
||||||
|
|
||||||
@ -345,6 +354,8 @@ void LammpsGui::run_buffer()
|
|||||||
logwindow->setMinimumSize(800, 600);
|
logwindow->setMinimumSize(800, 600);
|
||||||
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), logwindow);
|
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), logwindow);
|
||||||
QObject::connect(shortcut, &QShortcut::activated, logwindow, &QPlainTextEdit::close);
|
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();
|
logwindow->show();
|
||||||
|
|
||||||
logupdater = new QTimer(this);
|
logupdater = new QTimer(this);
|
||||||
|
|||||||
@ -59,6 +59,7 @@ private slots:
|
|||||||
void redo();
|
void redo();
|
||||||
void clear();
|
void clear();
|
||||||
void run_buffer();
|
void run_buffer();
|
||||||
|
void stop_run();
|
||||||
void about();
|
void about();
|
||||||
void logupdate();
|
void logupdate();
|
||||||
|
|
||||||
|
|||||||
@ -68,15 +68,23 @@
|
|||||||
<addaction name="actionCut"/>
|
<addaction name="actionCut"/>
|
||||||
<addaction name="actionPaste"/>
|
<addaction name="actionPaste"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_Run">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Run</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionRun_Buffer"/>
|
||||||
|
<addaction name="actionStop_LAMMPS"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
<addaction name="actionRun_Buffer"/>
|
<addaction name="menu_Run"/>
|
||||||
<addaction name="actionAbout_LAMMPS_GUI"/>
|
<addaction name="actionAbout_LAMMPS_GUI"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
<action name="actionNew">
|
<action name="actionNew">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-new"/>
|
<iconset theme="document-new">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&New</string>
|
<string>&New</string>
|
||||||
@ -93,7 +101,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-open"/>
|
<iconset theme="document-open">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Open</string>
|
<string>&Open</string>
|
||||||
@ -110,7 +119,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSave">
|
<action name="actionSave">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-save"/>
|
<iconset theme="document-save">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Save</string>
|
<string>&Save</string>
|
||||||
@ -127,7 +137,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSave_As">
|
<action name="actionSave_As">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="document-save-as"/>
|
<iconset theme="document-save-as">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save &As</string>
|
<string>Save &As</string>
|
||||||
@ -144,7 +155,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionQuit">
|
<action name="actionQuit">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="application-exit"/>
|
<iconset theme="application-exit">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Quit</string>
|
<string>&Quit</string>
|
||||||
@ -161,7 +173,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCut">
|
<action name="actionCut">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="edit-cut"/>
|
<iconset theme="edit-cut">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>C&ut</string>
|
<string>C&ut</string>
|
||||||
@ -175,7 +188,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCopy">
|
<action name="actionCopy">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="edit-copy"/>
|
<iconset theme="edit-copy">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Copy</string>
|
<string>&Copy</string>
|
||||||
@ -189,7 +203,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionPaste">
|
<action name="actionPaste">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="edit-paste"/>
|
<iconset theme="edit-paste">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Paste</string>
|
<string>&Paste</string>
|
||||||
@ -203,7 +218,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionUndo">
|
<action name="actionUndo">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="edit-undo"/>
|
<iconset theme="edit-undo">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Undo</string>
|
<string>&Undo</string>
|
||||||
@ -217,7 +233,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionRedo">
|
<action name="actionRedo">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="edit-redo"/>
|
<iconset theme="edit-redo">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Redo</string>
|
<string>&Redo</string>
|
||||||
@ -230,6 +247,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRun_Buffer">
|
<action name="actionRun_Buffer">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="emblem-default"/>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Run LAMMPS</string>
|
<string>&Run LAMMPS</string>
|
||||||
</property>
|
</property>
|
||||||
@ -240,6 +260,20 @@
|
|||||||
<string>Ctrl+Return</string>
|
<string>Ctrl+Return</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionStop_LAMMPS">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="process-stop"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&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">
|
<action name="actionAbout_LAMMPS_GUI">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&About</string>
|
<string>&About</string>
|
||||||
|
|||||||
@ -21,16 +21,10 @@ class LineNumberArea : public QWidget {
|
|||||||
public:
|
public:
|
||||||
LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor) {}
|
LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor) {}
|
||||||
|
|
||||||
QSize sizeHint() const override
|
QSize sizeHint() const override { return QSize(codeEditor->lineNumberAreaWidth(), 0); }
|
||||||
{
|
|
||||||
return QSize(codeEditor->lineNumberAreaWidth(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override
|
void paintEvent(QPaintEvent *event) override { codeEditor->lineNumberAreaPaintEvent(event); }
|
||||||
{
|
|
||||||
codeEditor->lineNumberAreaPaintEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CodeEditor *codeEditor;
|
CodeEditor *codeEditor;
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <thread>
|
#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
|
// make stdout unbuffered so that we don't need to flush the stream
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
@ -105,7 +105,7 @@ std::string StdCapture::GetChunk()
|
|||||||
{
|
{
|
||||||
if (!m_capturing) return std::string();
|
if (!m_capturing) return std::string();
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (!eof(m_pipe[READ])) {
|
if (!eof(m_pipe[READ])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user