Make worker generic
This commit is contained in:
parent
7f7cb6601e
commit
a761b772c8
@ -47,9 +47,6 @@ MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget
|
||||
task = new TaskManager();
|
||||
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(loadpcf_finished(bool)), this, SLOT(loadpcf_finished(bool)));
|
||||
connect(task, SIGNAL(saveasc_finished(bool)), this, SLOT(saveasc_finished(bool)));
|
||||
connect(task, SIGNAL(pack_finished(bool)), this, SLOT(pack_finished(bool)));
|
||||
connect(task, SIGNAL(budget_finish(bool)), this, SLOT(budget_finish(bool)));
|
||||
connect(task, SIGNAL(place_finished(bool)), this, SLOT(place_finished(bool)));
|
||||
@ -238,19 +235,34 @@ void MainWindow::new_proj()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::load_json(std::string filename, std::string pcf)
|
||||
void MainWindow::load_json(std::string filename)
|
||||
{
|
||||
disableActions();
|
||||
currentJson = filename;
|
||||
currentPCF = pcf;
|
||||
Q_EMIT task->loadfile(filename);
|
||||
std::ifstream f(filename);
|
||||
if (parse_json_file(f, filename, ctx.get())) {
|
||||
log("Loading design successful.\n");
|
||||
actionLoadPCF->setEnabled(true);
|
||||
actionPack->setEnabled(true);
|
||||
Q_EMIT updateTreeView();
|
||||
} else {
|
||||
actionLoadJSON->setEnabled(true);
|
||||
log("Loading design failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::load_pcf(std::string filename)
|
||||
{
|
||||
disableActions();
|
||||
currentPCF = filename;
|
||||
Q_EMIT task->loadpcf(filename);
|
||||
std::ifstream f(filename);
|
||||
if (apply_pcf(ctx.get(), f)) {
|
||||
log("Loading PCF successful.\n");
|
||||
actionPack->setEnabled(true);
|
||||
} else {
|
||||
actionLoadPCF->setEnabled(true);
|
||||
log("Loading PCF failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::newContext(Context *ctx)
|
||||
@ -331,7 +343,9 @@ void MainWindow::open_proj()
|
||||
}
|
||||
|
||||
log_info("Loading json: %s...\n", json.c_str());
|
||||
load_json(json, pcf);
|
||||
load_json(json);
|
||||
if (!pcf.empty())
|
||||
load_pcf(json);
|
||||
} catch (log_execution_error_exception) {
|
||||
}
|
||||
}
|
||||
@ -341,7 +355,7 @@ void MainWindow::open_json()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, QString("Open JSON"), QString(), QString("*.json"));
|
||||
if (!fileName.isEmpty()) {
|
||||
load_json(fileName.toStdString(), "");
|
||||
load_json(fileName.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,7 +403,9 @@ void MainWindow::save_asc()
|
||||
if (!fileName.isEmpty()) {
|
||||
std::string fn = fileName.toStdString();
|
||||
disableActions();
|
||||
Q_EMIT task->saveasc(fn);
|
||||
std::ofstream f(fn);
|
||||
write_asc(ctx.get(), f);
|
||||
log("Saving ASC successful.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,43 +428,6 @@ void MainWindow::disableActions()
|
||||
actionSave->setEnabled(!currentJson.empty());
|
||||
}
|
||||
|
||||
void MainWindow::loadfile_finished(bool status)
|
||||
{
|
||||
disableActions();
|
||||
if (status) {
|
||||
log("Loading design successful.\n");
|
||||
actionLoadPCF->setEnabled(true);
|
||||
actionPack->setEnabled(true);
|
||||
if (!currentPCF.empty())
|
||||
load_pcf(currentPCF);
|
||||
Q_EMIT updateTreeView();
|
||||
} else {
|
||||
log("Loading design failed.\n");
|
||||
currentPCF = "";
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadpcf_finished(bool status)
|
||||
{
|
||||
disableActions();
|
||||
if (status) {
|
||||
log("Loading PCF successful.\n");
|
||||
actionPack->setEnabled(true);
|
||||
} else {
|
||||
log("Loading PCF failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveasc_finished(bool status)
|
||||
{
|
||||
disableActions();
|
||||
if (status) {
|
||||
log("Saving ASC successful.\n");
|
||||
} else {
|
||||
log("Saving ASC failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::pack_finished(bool status)
|
||||
{
|
||||
disableActions();
|
||||
|
@ -35,7 +35,7 @@ class MainWindow : public BaseMainWindow
|
||||
|
||||
public:
|
||||
void createMenu();
|
||||
void load_json(std::string filename, std::string pcf);
|
||||
void load_json(std::string filename);
|
||||
void load_pcf(std::string filename);
|
||||
protected Q_SLOTS:
|
||||
virtual void new_proj();
|
||||
@ -48,9 +48,6 @@ class MainWindow : public BaseMainWindow
|
||||
void place();
|
||||
void save_asc();
|
||||
|
||||
void loadfile_finished(bool status);
|
||||
void loadpcf_finished(bool status);
|
||||
void saveasc_finished(bool status);
|
||||
void pack_finished(bool status);
|
||||
void budget_finish(bool status);
|
||||
void place_finished(bool status);
|
||||
|
@ -19,11 +19,8 @@
|
||||
|
||||
#include "worker.h"
|
||||
#include <fstream>
|
||||
#include "bitstream.h"
|
||||
#include "design_utils.h"
|
||||
#include "jsonparse.h"
|
||||
#include "log.h"
|
||||
#include "pcf.h"
|
||||
#include "timing.h"
|
||||
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
@ -55,43 +52,6 @@ Worker::Worker(TaskManager *parent) : ctx(nullptr)
|
||||
|
||||
void Worker::newContext(Context *ctx_) { ctx = ctx_; }
|
||||
|
||||
void Worker::loadfile(const std::string &filename)
|
||||
{
|
||||
Q_EMIT taskStarted();
|
||||
std::string fn = filename;
|
||||
std::ifstream f(fn);
|
||||
try {
|
||||
Q_EMIT loadfile_finished(parse_json_file(f, fn, ctx));
|
||||
} catch (WorkerInterruptionRequested) {
|
||||
Q_EMIT taskCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
void Worker::loadpcf(const std::string &filename)
|
||||
{
|
||||
Q_EMIT taskStarted();
|
||||
std::string fn = filename;
|
||||
std::ifstream f(fn);
|
||||
try {
|
||||
Q_EMIT loadpcf_finished(apply_pcf(ctx, f));
|
||||
} catch (WorkerInterruptionRequested) {
|
||||
Q_EMIT taskCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
void Worker::saveasc(const std::string &filename)
|
||||
{
|
||||
Q_EMIT taskStarted();
|
||||
std::string fn = filename;
|
||||
std::ofstream f(fn);
|
||||
try {
|
||||
write_asc(ctx, f);
|
||||
Q_EMIT saveasc_finished(true);
|
||||
} catch (WorkerInterruptionRequested) {
|
||||
Q_EMIT taskCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
void Worker::pack()
|
||||
{
|
||||
Q_EMIT taskStarted();
|
||||
@ -144,9 +104,6 @@ TaskManager::TaskManager() : toTerminate(false), toPause(false)
|
||||
|
||||
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
|
||||
|
||||
connect(this, &TaskManager::loadfile, worker, &Worker::loadfile);
|
||||
connect(this, &TaskManager::loadpcf, worker, &Worker::loadpcf);
|
||||
connect(this, &TaskManager::saveasc, worker, &Worker::saveasc);
|
||||
connect(this, &TaskManager::pack, worker, &Worker::pack);
|
||||
connect(this, &TaskManager::budget, worker, &Worker::budget);
|
||||
connect(this, &TaskManager::place, worker, &Worker::place);
|
||||
@ -155,9 +112,6 @@ TaskManager::TaskManager() : toTerminate(false), toPause(false)
|
||||
connect(this, &TaskManager::contextChanged, worker, &Worker::newContext);
|
||||
|
||||
connect(worker, &Worker::log, this, &TaskManager::info);
|
||||
connect(worker, &Worker::loadfile_finished, this, &TaskManager::loadfile_finished);
|
||||
connect(worker, &Worker::loadpcf_finished, this, &TaskManager::loadpcf_finished);
|
||||
connect(worker, &Worker::saveasc_finished, this, &TaskManager::saveasc_finished);
|
||||
connect(worker, &Worker::pack_finished, this, &TaskManager::pack_finished);
|
||||
connect(worker, &Worker::budget_finish, this, &TaskManager::budget_finish);
|
||||
connect(worker, &Worker::place_finished, this, &TaskManager::place_finished);
|
@ -35,18 +35,12 @@ class Worker : public QObject
|
||||
explicit Worker(TaskManager *parent);
|
||||
public Q_SLOTS:
|
||||
void newContext(Context *);
|
||||
void loadfile(const std::string &);
|
||||
void loadpcf(const std::string &);
|
||||
void saveasc(const std::string &);
|
||||
void pack();
|
||||
void budget(double freq);
|
||||
void place(bool timing_driven);
|
||||
void route();
|
||||
Q_SIGNALS:
|
||||
void log(const std::string &text);
|
||||
void loadfile_finished(bool status);
|
||||
void loadpcf_finished(bool status);
|
||||
void saveasc_finished(bool status);
|
||||
void pack_finished(bool status);
|
||||
void budget_finish(bool status);
|
||||
void place_finished(bool status);
|
||||
@ -78,9 +72,6 @@ class TaskManager : public QObject
|
||||
Q_SIGNALS:
|
||||
void contextChanged(Context *ctx);
|
||||
void terminate();
|
||||
void loadfile(const std::string &);
|
||||
void loadpcf(const std::string &);
|
||||
void saveasc(const std::string &);
|
||||
void pack();
|
||||
void budget(double freq);
|
||||
void place(bool timing_driven);
|
||||
@ -88,9 +79,6 @@ class TaskManager : public QObject
|
||||
|
||||
// redirected signals
|
||||
void log(const std::string &text);
|
||||
void loadfile_finished(bool status);
|
||||
void loadpcf_finished(bool status);
|
||||
void saveasc_finished(bool status);
|
||||
void pack_finished(bool status);
|
||||
void budget_finish(bool status);
|
||||
void place_finished(bool status);
|
@ -406,9 +406,11 @@ int main(int argc, char *argv[])
|
||||
if (vm.count("json")) {
|
||||
std::string filename = vm["json"].as<std::string>();
|
||||
std::string pcf = "";
|
||||
if (vm.count("pcf"))
|
||||
w.load_json(filename);
|
||||
if (vm.count("pcf")) {
|
||||
pcf = vm["pcf"].as<std::string>();
|
||||
w.load_json(filename, pcf);
|
||||
w.load_pcf(pcf);
|
||||
}
|
||||
}
|
||||
w.show();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user