From 3cd12e3671e5ee108f039cb4350bf885164a8cf5 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:11:22 +0200 Subject: Add ability to terminate running tasks --- gui/ice40/mainwindow.cc | 14 ++++++++++---- gui/ice40/worker.cc | 42 ++++++++++++++++++++++++++++++++++++------ gui/ice40/worker.h | 13 ++++++++++++- 3 files changed, 58 insertions(+), 11 deletions(-) (limited to 'gui/ice40') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 934798bb..e36464a0 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -17,18 +17,24 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); - createMenu(); - task = new TaskManager(_ctx); connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string))); + + createMenu(); } -MainWindow::~MainWindow() {} +MainWindow::~MainWindow() { delete task; } void MainWindow::createMenu() { QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); menuBar->addAction(menu_Custom->menuAction()); + + QAction *actionTerminate = new QAction("Terminate", this); + actionTerminate->setStatusTip("Terminate running task"); + connect(actionTerminate, SIGNAL(triggered()), task, + SLOT(terminate_thread())); + menu_Custom->addAction(actionTerminate); } void MainWindow::open() @@ -39,7 +45,7 @@ void MainWindow::open() tabWidget->setCurrentWidget(info); std::string fn = fileName.toStdString(); - task->parsejson(fn); + Q_EMIT task->parsejson(fn); } } bool MainWindow::save() { return false; } \ No newline at end of file diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 5702137b..a309f868 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,9 +10,19 @@ #include "route.h" #include "timing.h" -Worker::Worker(Context *_ctx) : ctx(_ctx) +struct WorkerInterruptionRequested { - log_write_function = [this](std::string text) { Q_EMIT log(text); }; +}; + +Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) +{ + log_write_function = [this, parent](std::string text) { + Q_EMIT log(text); + if (parent->shouldTerminate()) { + parent->clearTerminate(); + throw WorkerInterruptionRequested(); + } + }; } void Worker::parsejson(const std::string &filename) @@ -32,14 +42,16 @@ void Worker::parsejson(const std::string &filename) log_error("Placing design failed.\n"); if (!route_design(ctx)) log_error("Routing design failed.\n"); - Q_EMIT log("done"); + Q_EMIT log("DONE\n"); } catch (log_execution_error_exception) { + } catch (WorkerInterruptionRequested) { + Q_EMIT log("CANCELED\n"); } } -TaskManager::TaskManager(Context *ctx) +TaskManager::TaskManager(Context *ctx) : toTerminate(false) { - Worker *worker = new Worker(ctx); + Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &TaskManager::parsejson, worker, &Worker::parsejson); @@ -53,4 +65,22 @@ TaskManager::~TaskManager() workerThread.wait(); } -void TaskManager::info(const std::string &result) { Q_EMIT log(result); } \ No newline at end of file +void TaskManager::info(const std::string &result) { Q_EMIT log(result); } + +void TaskManager::terminate_thread() +{ + QMutexLocker locker(&mutex); + toTerminate = true; +} + +bool TaskManager::shouldTerminate() +{ + QMutexLocker locker(&mutex); + return toTerminate; +} + +void TaskManager::clearTerminate() +{ + QMutexLocker locker(&mutex); + toTerminate = false; +} \ No newline at end of file diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 12d740dd..a2d220bd 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -1,17 +1,20 @@ #ifndef WORKER_H #define WORKER_H +#include #include #include "nextpnr.h" // FIXME USING_NEXTPNR_NAMESPACE +class TaskManager; + class Worker : public QObject { Q_OBJECT public: - Worker(Context *ctx); + Worker(Context *ctx, TaskManager *parent); public Q_SLOTS: void parsejson(const std::string &filename); Q_SIGNALS: @@ -29,11 +32,19 @@ class TaskManager : public QObject public: TaskManager(Context *ctx); ~TaskManager(); + bool shouldTerminate(); + void clearTerminate(); public Q_SLOTS: void info(const std::string &text); + void terminate_thread(); Q_SIGNALS: + void terminate(); void parsejson(const std::string &); void log(const std::string &text); + + private: + QMutex mutex; + bool toTerminate; }; #endif // WORKER_H -- cgit v1.2.3 From 5cb893aebdfdf711755b9bf610b36b8ff2d942ff Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:24:50 +0200 Subject: terminate on close --- gui/ice40/worker.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gui/ice40') diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index a309f868..4b101e7e 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -61,6 +61,8 @@ TaskManager::TaskManager(Context *ctx) : toTerminate(false) TaskManager::~TaskManager() { + if (workerThread.isRunning()) + terminate_thread(); workerThread.quit(); workerThread.wait(); } -- cgit v1.2.3 From 11d99853ab4514b1f6b87c5beb87c91f50e702a6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:49:20 +0200 Subject: more task control --- gui/ice40/mainwindow.cc | 35 ++++++++++++++++++++++++++++++---- gui/ice40/nextpnr.qrc | 7 +++++++ gui/ice40/resources/control_pause.png | Bin 0 -> 598 bytes gui/ice40/resources/control_play.png | Bin 0 -> 592 bytes gui/ice40/resources/control_stop.png | Bin 0 -> 403 bytes gui/ice40/worker.cc | 22 ++++++++++++++++++++- gui/ice40/worker.h | 4 ++++ 7 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 gui/ice40/nextpnr.qrc create mode 100644 gui/ice40/resources/control_pause.png create mode 100644 gui/ice40/resources/control_play.png create mode 100644 gui/ice40/resources/control_stop.png (limited to 'gui/ice40') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index e36464a0..9ce7f41e 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -14,6 +14,8 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) { + Q_INIT_RESOURCE(nextpnr); + std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); @@ -30,11 +32,36 @@ void MainWindow::createMenu() QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); menuBar->addAction(menu_Custom->menuAction()); - QAction *actionTerminate = new QAction("Terminate", this); - actionTerminate->setStatusTip("Terminate running task"); - connect(actionTerminate, SIGNAL(triggered()), task, + QAction *actionPlay = new QAction("Play", this); + QIcon icon1; + icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); + actionPlay->setIcon(icon1); + actionPlay->setStatusTip("Continue running task"); + connect(actionPlay, SIGNAL(triggered()), task, + SLOT(continue_thread())); + + QAction *actionPause = new QAction("Pause", this); + QIcon icon2; + icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); + actionPause->setIcon(icon2); + actionPause->setStatusTip("Pause running task"); + connect(actionPause, SIGNAL(triggered()), task, + SLOT(pause_thread())); + + QAction *actionStop = new QAction("Stop", this); + QIcon icon3; + icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); + actionStop->setIcon(icon3); + actionStop->setStatusTip("Stop running task"); + connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); - menu_Custom->addAction(actionTerminate); + + QToolBar *taskToolBar = new QToolBar(); + addToolBar(Qt::TopToolBarArea, taskToolBar); + + taskToolBar->addAction(actionPlay); + taskToolBar->addAction(actionPause); + taskToolBar->addAction(actionStop); } void MainWindow::open() diff --git a/gui/ice40/nextpnr.qrc b/gui/ice40/nextpnr.qrc new file mode 100644 index 00000000..cbdb8b26 --- /dev/null +++ b/gui/ice40/nextpnr.qrc @@ -0,0 +1,7 @@ + + + resources/control_play.png + resources/control_pause.png + resources/control_stop.png + + diff --git a/gui/ice40/resources/control_pause.png b/gui/ice40/resources/control_pause.png new file mode 100644 index 00000000..2d9ce9c4 Binary files /dev/null and b/gui/ice40/resources/control_pause.png differ diff --git a/gui/ice40/resources/control_play.png b/gui/ice40/resources/control_play.png new file mode 100644 index 00000000..0846555d Binary files /dev/null and b/gui/ice40/resources/control_play.png differ diff --git a/gui/ice40/resources/control_stop.png b/gui/ice40/resources/control_stop.png new file mode 100644 index 00000000..893bb60e Binary files /dev/null and b/gui/ice40/resources/control_stop.png differ diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 4b101e7e..3854c67f 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -22,6 +22,9 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } + while (parent->isPaused()){ + QThread::sleep(1); + } }; } @@ -49,7 +52,7 @@ void Worker::parsejson(const std::string &filename) } } -TaskManager::TaskManager(Context *ctx) : toTerminate(false) +TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) { Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); @@ -85,4 +88,21 @@ void TaskManager::clearTerminate() { QMutexLocker locker(&mutex); toTerminate = false; +} + +void TaskManager::pause_thread() +{ + QMutexLocker locker(&mutex); + toPause = true; +} + +void TaskManager::continue_thread() +{ + QMutexLocker locker(&mutex); + toPause = false; +} +bool TaskManager::isPaused() +{ + QMutexLocker locker(&mutex); + return toPause; } \ No newline at end of file diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index a2d220bd..49d1df4d 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -34,9 +34,12 @@ class TaskManager : public QObject ~TaskManager(); bool shouldTerminate(); void clearTerminate(); + bool isPaused(); public Q_SLOTS: void info(const std::string &text); void terminate_thread(); + void pause_thread(); + void continue_thread(); Q_SIGNALS: void terminate(); void parsejson(const std::string &); @@ -45,6 +48,7 @@ class TaskManager : public QObject private: QMutex mutex; bool toTerminate; + bool toPause; }; #endif // WORKER_H -- cgit v1.2.3 From 7f368282700172925428e45f23b8b61e0bf39f94 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 13:10:27 +0200 Subject: fixed namespace for gui section --- gui/ice40/mainwindow.cc | 22 +++++++++++++--------- gui/ice40/mainwindow.h | 5 +++-- gui/ice40/worker.cc | 10 +++++++--- gui/ice40/worker.h | 5 +++-- 4 files changed, 26 insertions(+), 16 deletions(-) (limited to 'gui/ice40') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 9ce7f41e..4c7bc18f 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -11,11 +11,15 @@ #include "place_sa.h" #include "route.h" +static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } + +NEXTPNR_NAMESPACE_BEGIN + MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) { - Q_INIT_RESOURCE(nextpnr); - + initMainResource(); + std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); @@ -37,24 +41,21 @@ void MainWindow::createMenu() icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); actionPlay->setIcon(icon1); actionPlay->setStatusTip("Continue running task"); - connect(actionPlay, SIGNAL(triggered()), task, - SLOT(continue_thread())); + connect(actionPlay, SIGNAL(triggered()), task, SLOT(continue_thread())); QAction *actionPause = new QAction("Pause", this); QIcon icon2; icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); actionPause->setIcon(icon2); actionPause->setStatusTip("Pause running task"); - connect(actionPause, SIGNAL(triggered()), task, - SLOT(pause_thread())); + connect(actionPause, SIGNAL(triggered()), task, SLOT(pause_thread())); QAction *actionStop = new QAction("Stop", this); QIcon icon3; icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); actionStop->setIcon(icon3); actionStop->setStatusTip("Stop running task"); - connect(actionStop, SIGNAL(triggered()), task, - SLOT(terminate_thread())); + connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); QToolBar *taskToolBar = new QToolBar(); addToolBar(Qt::TopToolBarArea, taskToolBar); @@ -75,4 +76,7 @@ void MainWindow::open() Q_EMIT task->parsejson(fn); } } -bool MainWindow::save() { return false; } \ No newline at end of file + +bool MainWindow::save() { return false; } + +NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index fd65f9ae..712f341a 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -4,8 +4,7 @@ #include "../basewindow.h" #include "worker.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class MainWindow : public BaseMainWindow { @@ -26,4 +25,6 @@ class MainWindow : public BaseMainWindow TaskManager *task; }; +NEXTPNR_NAMESPACE_END + #endif // MAINWINDOW_H diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 3854c67f..9549f659 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,6 +10,8 @@ #include "route.h" #include "timing.h" +NEXTPNR_NAMESPACE_BEGIN + struct WorkerInterruptionRequested { }; @@ -22,7 +24,7 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } - while (parent->isPaused()){ + while (parent->isPaused()) { QThread::sleep(1); } }; @@ -64,7 +66,7 @@ TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) TaskManager::~TaskManager() { - if (workerThread.isRunning()) + if (workerThread.isRunning()) terminate_thread(); workerThread.quit(); workerThread.wait(); @@ -105,4 +107,6 @@ bool TaskManager::isPaused() { QMutexLocker locker(&mutex); return toPause; -} \ No newline at end of file +} + +NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 49d1df4d..181fafa3 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -5,8 +5,7 @@ #include #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class TaskManager; @@ -51,4 +50,6 @@ class TaskManager : public QObject bool toPause; }; +NEXTPNR_NAMESPACE_END + #endif // WORKER_H -- cgit v1.2.3 From 56c09fc5e5f7fb5c299f7a0b52e839556146615d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 15:35:07 +0200 Subject: routing flow supported in gui --- gui/ice40/mainwindow.cc | 153 ++++++++++++++++++++++++++++++---- gui/ice40/mainwindow.h | 16 ++++ gui/ice40/nextpnr.qrc | 3 + gui/ice40/resources/control_pause.png | Bin 598 -> 721 bytes gui/ice40/resources/control_play.png | Bin 592 -> 717 bytes gui/ice40/resources/control_stop.png | Bin 403 -> 695 bytes gui/ice40/resources/pack.png | Bin 0 -> 853 bytes gui/ice40/resources/place.png | Bin 0 -> 825 bytes gui/ice40/resources/route.png | Bin 0 -> 683 bytes gui/ice40/worker.cc | 74 +++++++++++++--- gui/ice40/worker.h | 26 +++++- 11 files changed, 241 insertions(+), 31 deletions(-) create mode 100644 gui/ice40/resources/pack.png create mode 100644 gui/ice40/resources/place.png create mode 100644 gui/ice40/resources/route.png (limited to 'gui/ice40') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 4c7bc18f..0a248938 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -26,6 +26,15 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) task = new TaskManager(_ctx); connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string))); + connect(task, SIGNAL(loadfile_finished(bool)), this, SLOT(loadfile_finished(bool))); + connect(task, SIGNAL(pack_finished(bool)), this, SLOT(pack_finished(bool))); + connect(task, SIGNAL(place_finished(bool)), this, SLOT(place_finished(bool))); + connect(task, SIGNAL(route_finished(bool)), this, SLOT(route_finished(bool))); + + connect(task, SIGNAL(taskCanceled()), this, SLOT(taskCanceled())); + connect(task, SIGNAL(taskStarted()), this, SLOT(taskStarted())); + connect(task, SIGNAL(taskPaused()), this, SLOT(taskPaused())); + createMenu(); } @@ -33,29 +42,67 @@ MainWindow::~MainWindow() { delete task; } void MainWindow::createMenu() { - QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); - menuBar->addAction(menu_Custom->menuAction()); - - QAction *actionPlay = new QAction("Play", this); - QIcon icon1; - icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); - actionPlay->setIcon(icon1); + QMenu *menu_Design = new QMenu("&Design", menuBar); + menuBar->addAction(menu_Design->menuAction()); + + actionPack = new QAction("Pack", this); + QIcon iconPack; + iconPack.addFile(QStringLiteral(":/icons/resources/pack.png")); + actionPack->setIcon(iconPack); + actionPack->setStatusTip("Pack current design"); + connect(actionPack, SIGNAL(triggered()), task, SIGNAL(pack())); + actionPack->setEnabled(false); + + actionPlace = new QAction("Place", this); + QIcon iconPlace; + iconPlace.addFile(QStringLiteral(":/icons/resources/place.png")); + actionPlace->setIcon(iconPlace); + actionPlace->setStatusTip("Place current design"); + connect(actionPlace, SIGNAL(triggered()), task, SIGNAL(place())); + actionPlace->setEnabled(false); + + actionRoute = new QAction("Route", this); + QIcon iconRoute; + iconRoute.addFile(QStringLiteral(":/icons/resources/route.png")); + actionRoute->setIcon(iconRoute); + actionRoute->setStatusTip("Route current design"); + connect(actionRoute, SIGNAL(triggered()), task, SIGNAL(route())); + actionRoute->setEnabled(false); + + QToolBar *taskFPGABar = new QToolBar(); + addToolBar(Qt::TopToolBarArea, taskFPGABar); + + taskFPGABar->addAction(actionPack); + taskFPGABar->addAction(actionPlace); + taskFPGABar->addAction(actionRoute); + + menu_Design->addAction(actionPack); + menu_Design->addAction(actionPlace); + menu_Design->addAction(actionRoute); + + actionPlay = new QAction("Play", this); + QIcon iconPlay; + iconPlay.addFile(QStringLiteral(":/icons/resources/control_play.png")); + actionPlay->setIcon(iconPlay); actionPlay->setStatusTip("Continue running task"); connect(actionPlay, SIGNAL(triggered()), task, SLOT(continue_thread())); + actionPlay->setEnabled(false); - QAction *actionPause = new QAction("Pause", this); - QIcon icon2; - icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); - actionPause->setIcon(icon2); + actionPause = new QAction("Pause", this); + QIcon iconPause; + iconPause.addFile(QStringLiteral(":/icons/resources/control_pause.png")); + actionPause->setIcon(iconPause); actionPause->setStatusTip("Pause running task"); connect(actionPause, SIGNAL(triggered()), task, SLOT(pause_thread())); + actionPause->setEnabled(false); - QAction *actionStop = new QAction("Stop", this); - QIcon icon3; - icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); - actionStop->setIcon(icon3); + actionStop = new QAction("Stop", this); + QIcon iconStop; + iconStop.addFile(QStringLiteral(":/icons/resources/control_stop.png")); + actionStop->setIcon(iconStop); actionStop->setStatusTip("Stop running task"); connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); + actionStop->setEnabled(false); QToolBar *taskToolBar = new QToolBar(); addToolBar(Qt::TopToolBarArea, taskToolBar); @@ -73,10 +120,84 @@ void MainWindow::open() tabWidget->setCurrentWidget(info); std::string fn = fileName.toStdString(); - Q_EMIT task->parsejson(fn); + disableActions(); + Q_EMIT task->loadfile(fn); } } bool MainWindow::save() { return false; } +void MainWindow::disableActions() +{ + actionPack->setEnabled(false); + actionPlace->setEnabled(false); + actionRoute->setEnabled(false); + + actionPlay->setEnabled(false); + actionPause->setEnabled(false); + actionStop->setEnabled(false); +} + +void MainWindow::loadfile_finished(bool status) +{ + disableActions(); + if (status) { + log("Loading design successful.\n"); + actionPack->setEnabled(true); + } + else { + log("Loading design failed.\n"); + } +} +void MainWindow::pack_finished(bool status) +{ + disableActions(); + if (status) { + log("Packing design successful.\n"); + actionPlace->setEnabled(true); + } + else { + log("Packing design failed.\n"); + } +} +void MainWindow::place_finished(bool status) +{ + disableActions(); + if (status) { + log("Placing design successful.\n"); + actionRoute->setEnabled(true); + } + else { + log("Placing design failed.\n"); + } +} +void MainWindow::route_finished(bool status) +{ + disableActions(); + if (status) + log("Routing design successful.\n"); + else + log("Routing design failed.\n"); +} + +void MainWindow::taskCanceled() +{ + log("CANCELED\n"); + disableActions(); +} + +void MainWindow::taskStarted() +{ + disableActions(); + actionPause->setEnabled(true); + actionStop->setEnabled(true); +} + +void MainWindow::taskPaused() +{ + disableActions(); + actionPlay->setEnabled(true); + actionStop->setEnabled(true); +} + NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index 712f341a..9083ed8a 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -20,9 +20,25 @@ class MainWindow : public BaseMainWindow protected Q_SLOTS: virtual void open(); virtual bool save(); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: + void disableActions(); + TaskManager *task; + QAction *actionPack; + QAction *actionPlace; + QAction *actionRoute; + QAction *actionPlay; + QAction *actionPause; + QAction *actionStop; }; NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/nextpnr.qrc b/gui/ice40/nextpnr.qrc index cbdb8b26..3bc68978 100644 --- a/gui/ice40/nextpnr.qrc +++ b/gui/ice40/nextpnr.qrc @@ -3,5 +3,8 @@ resources/control_play.png resources/control_pause.png resources/control_stop.png + resources/pack.png + resources/place.png + resources/route.png diff --git a/gui/ice40/resources/control_pause.png b/gui/ice40/resources/control_pause.png index 2d9ce9c4..ec61099b 100644 Binary files a/gui/ice40/resources/control_pause.png and b/gui/ice40/resources/control_pause.png differ diff --git a/gui/ice40/resources/control_play.png b/gui/ice40/resources/control_play.png index 0846555d..f8c8ec68 100644 Binary files a/gui/ice40/resources/control_play.png and b/gui/ice40/resources/control_play.png differ diff --git a/gui/ice40/resources/control_stop.png b/gui/ice40/resources/control_stop.png index 893bb60e..e6f75d23 100644 Binary files a/gui/ice40/resources/control_stop.png and b/gui/ice40/resources/control_stop.png differ diff --git a/gui/ice40/resources/pack.png b/gui/ice40/resources/pack.png new file mode 100644 index 00000000..da3c2a2d Binary files /dev/null and b/gui/ice40/resources/pack.png differ diff --git a/gui/ice40/resources/place.png b/gui/ice40/resources/place.png new file mode 100644 index 00000000..0905f933 Binary files /dev/null and b/gui/ice40/resources/place.png differ diff --git a/gui/ice40/resources/route.png b/gui/ice40/resources/route.png new file mode 100644 index 00000000..258c16c6 Binary files /dev/null and b/gui/ice40/resources/route.png differ diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 9549f659..9df24f65 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -24,43 +24,88 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } + if (parent->isPaused()) + { + Q_EMIT taskPaused(); + } while (parent->isPaused()) { + if (parent->shouldTerminate()) { + parent->clearTerminate(); + throw WorkerInterruptionRequested(); + } QThread::sleep(1); } }; } -void Worker::parsejson(const std::string &filename) +void Worker::loadfile(const std::string &filename) { + Q_EMIT taskStarted(); std::string fn = filename; std::ifstream f(fn); try { - if (!parse_json_file(f, fn, ctx)) - log_error("Loading design failed.\n"); - if (!pack_design(ctx)) - log_error("Packing design failed.\n"); + Q_EMIT loadfile_finished(parse_json_file(f, fn, ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} + +void Worker::pack() +{ + Q_EMIT taskStarted(); + try { + Q_EMIT pack_finished(pack_design(ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} + +void Worker::place() +{ + Q_EMIT taskStarted(); + try { double freq = 50e6; assign_budget(ctx, freq); print_utilisation(ctx); + Q_EMIT place_finished(place_design_sa(ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} - if (!place_design_sa(ctx)) - log_error("Placing design failed.\n"); - if (!route_design(ctx)) - log_error("Routing design failed.\n"); - Q_EMIT log("DONE\n"); - } catch (log_execution_error_exception) { +void Worker::route() +{ + Q_EMIT taskStarted(); + try { + Q_EMIT route_finished(route_design(ctx)); } catch (WorkerInterruptionRequested) { - Q_EMIT log("CANCELED\n"); + Q_EMIT taskCanceled(); } } + TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) { Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); + connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); - connect(this, &TaskManager::parsejson, worker, &Worker::parsejson); + + connect(this, &TaskManager::loadfile, worker, &Worker::loadfile); + connect(this, &TaskManager::pack, worker, &Worker::pack); + connect(this, &TaskManager::place, worker, &Worker::place); + connect(this, &TaskManager::route, worker, &Worker::route); + connect(worker, &Worker::log, this, &TaskManager::info); + connect(worker, &Worker::loadfile_finished, this, &TaskManager::loadfile_finished); + connect(worker, &Worker::pack_finished, this, &TaskManager::pack_finished); + connect(worker, &Worker::place_finished, this, &TaskManager::place_finished); + connect(worker, &Worker::route_finished, this, &TaskManager::route_finished); + + connect(worker, &Worker::taskCanceled, this, &TaskManager::taskCanceled); + connect(worker, &Worker::taskStarted, this, &TaskManager::taskStarted); + connect(worker, &Worker::taskPaused, this, &TaskManager::taskPaused); + workerThread.start(); } @@ -77,6 +122,7 @@ void TaskManager::info(const std::string &result) { Q_EMIT log(result); } void TaskManager::terminate_thread() { QMutexLocker locker(&mutex); + toPause = false; toTerminate = true; } @@ -102,7 +148,9 @@ void TaskManager::continue_thread() { QMutexLocker locker(&mutex); toPause = false; + Q_EMIT taskStarted(); } + bool TaskManager::isPaused() { QMutexLocker locker(&mutex); diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 181fafa3..320dc94c 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -15,9 +15,19 @@ class Worker : public QObject public: Worker(Context *ctx, TaskManager *parent); public Q_SLOTS: - void parsejson(const std::string &filename); + void loadfile(const std::string &); + void pack(); + void place(); + void route(); Q_SIGNALS: void log(const std::string &text); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: Context *ctx; @@ -41,8 +51,20 @@ class TaskManager : public QObject void continue_thread(); Q_SIGNALS: void terminate(); - void parsejson(const std::string &); + void loadfile(const std::string &); + void pack(); + void place(); + void route(); + + // redirected signals void log(const std::string &text); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: QMutex mutex; -- cgit v1.2.3