From e5bd4764b27c86fa804700b18bcac5cf18815314 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 16:48:56 +0200 Subject: Added custom QApplication implementation --- CMakeLists.txt | 2 +- dummy/main.cc | 3 ++- gui/application.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ gui/application.h | 38 ++++++++++++++++++++++++++++++++++++++ gui/ice40/mainwindow.cc | 24 ++++++++++++------------ gui/ice40/mainwindow.h | 4 ++-- gui/ice40/worker.cc | 19 ++++++++++--------- ice40/main.cc | 3 ++- 8 files changed, 114 insertions(+), 26 deletions(-) create mode 100644 gui/application.cc create mode 100644 gui/application.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a64369f..1b05d296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ foreach (family ${FAMILIES}) include(${family}/family.cmake) foreach (target ${family_targets}) # Include family-specific source files to all family targets and set defines appropriately - target_include_directories(${target} PRIVATE ${family}/ generated/ gui/${family}/) + target_include_directories(${target} PRIVATE ${family}/ generated/ gui/${family}/ gui/) target_compile_definitions(${target} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family} ARCH_${ufamily} ARCHNAME=${family} QT_NO_KEYWORDS) target_link_libraries(${target} LINK_PUBLIC gui_${family} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${GUI_LIBRARY_FILES_${ufamily}}) endforeach (target) diff --git a/dummy/main.cc b/dummy/main.cc index b6caa4c1..fa1259d4 100644 --- a/dummy/main.cc +++ b/dummy/main.cc @@ -22,6 +22,7 @@ #include #include #include +#include "application.h" #include "log.h" #include "mainwindow.h" #include "nextpnr.h" @@ -107,7 +108,7 @@ int main(int argc, char *argv[]) } if (vm.count("gui")) { - QApplication a(argc, argv); + Application a(argc, argv); MainWindow w(&ctx); w.show(); diff --git a/gui/application.cc b/gui/application.cc new file mode 100644 index 00000000..eaabeefb --- /dev/null +++ b/gui/application.cc @@ -0,0 +1,47 @@ + +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Miodrag Milanovic + * Copyright (C) 2018 Serge Bazanski + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include "application.h" +#include +#include +#include + +NEXTPNR_NAMESPACE_BEGIN + +Application::Application(int &argc, char **argv) : QApplication(argc, argv) +{ + QSurfaceFormat fmt; + fmt.setSamples(10); + QSurfaceFormat::setDefaultFormat(fmt); +} + +bool Application::notify(QObject *receiver, QEvent *event) +{ + bool retVal = true; + try { + retVal = QApplication::notify(receiver, event); + } catch (...) { + QMessageBox::critical(0, "Error", "Fatal error !!!"); + } + return retVal; +} + +NEXTPNR_NAMESPACE_END diff --git a/gui/application.h b/gui/application.h new file mode 100644 index 00000000..321f6b65 --- /dev/null +++ b/gui/application.h @@ -0,0 +1,38 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Miodrag Milanovic + * Copyright (C) 2018 Serge Bazanski + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef APPLICATION_H +#define APPLICATION_H + +#include +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN + +class Application : public QApplication +{ + public: + Application(int &argc, char **argv); + bool notify(QObject *receiver, QEvent *event); +}; + +NEXTPNR_NAMESPACE_END + +#endif // APPLICATION_H \ No newline at end of file diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index bd7cb091..a0739f92 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -45,14 +45,17 @@ 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(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(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())); + connect(task, SIGNAL(taskPaused()), this, SLOT(taskPaused())); createMenu(); } @@ -146,7 +149,7 @@ void MainWindow::open() bool MainWindow::save() { return false; } -void MainWindow::disableActions() +void MainWindow::disableActions() { actionPack->setEnabled(false); actionPlace->setEnabled(false); @@ -163,8 +166,7 @@ void MainWindow::loadfile_finished(bool status) if (status) { log("Loading design successful.\n"); actionPack->setEnabled(true); - } - else { + } else { log("Loading design failed.\n"); } } @@ -174,8 +176,7 @@ void MainWindow::pack_finished(bool status) if (status) { log("Packing design successful.\n"); actionPlace->setEnabled(true); - } - else { + } else { log("Packing design failed.\n"); } } @@ -185,8 +186,7 @@ void MainWindow::place_finished(bool status) if (status) { log("Placing design successful.\n"); actionRoute->setEnabled(true); - } - else { + } else { log("Placing design failed.\n"); } } @@ -216,7 +216,7 @@ void MainWindow::taskPaused() { disableActions(); actionPlay->setEnabled(true); - actionStop->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 376cb901..c0c4bef8 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -43,7 +43,7 @@ class MainWindow : public BaseMainWindow void pack_finished(bool status); void place_finished(bool status); void route_finished(bool status); - + void taskCanceled(); void taskStarted(); void taskPaused(); @@ -57,7 +57,7 @@ class MainWindow : public BaseMainWindow QAction *actionRoute; QAction *actionPlay; QAction *actionPause; - QAction *actionStop; + QAction *actionStop; }; NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 0c0f800c..ecf473ce 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -43,8 +43,7 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } - if (parent->isPaused()) - { + if (parent->isPaused()) { Q_EMIT taskPaused(); } while (parent->isPaused()) { @@ -102,25 +101,27 @@ void Worker::route() } } - 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::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::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::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); diff --git a/ice40/main.cc b/ice40/main.cc index 8db95e73..8ae9ccf0 100644 --- a/ice40/main.cc +++ b/ice40/main.cc @@ -24,6 +24,7 @@ #include #include #include +#include "application.h" #include "bitstream.h" #include "design_utils.h" #include "jsonparse.h" @@ -329,7 +330,7 @@ int main(int argc, char *argv[]) } if (vm.count("gui")) { - QApplication a(argc, argv); + Application a(argc, argv); MainWindow w(&ctx); w.show(); -- cgit v1.2.3