From 875004d300eb4b85e13c026378e39b31b6922f93 Mon Sep 17 00:00:00 2001 From: gatecat Date: Mon, 7 Jun 2021 21:02:43 +0100 Subject: gui: Don't destroy context when loading JSON Signed-off-by: gatecat --- common/command.cc | 21 +++++++++++++-------- common/command.h | 2 +- gui/basewindow.cc | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/common/command.cc b/common/command.cc index 27e59260..3341b521 100644 --- a/common/command.cc +++ b/common/command.cc @@ -473,19 +473,24 @@ int CommandHandler::exec() } } -std::unique_ptr CommandHandler::load_json(std::string filename) +void CommandHandler::load_json(Context *ctx, std::string filename) { - dict values; - std::unique_ptr ctx = createContext(values); - setupContext(ctx.get()); - setupArchContext(ctx.get()); + ctx->cells.clear(); + ctx->nets.clear(); + ctx->net_aliases.clear(); + ctx->ports.clear(); + ctx->hierarchy.clear(); + ctx->settings.erase(ctx->id("pack")); + ctx->settings.erase(ctx->id("place")); + ctx->settings.erase(ctx->id("route")); + + setupContext(ctx); + setupArchContext(ctx); { std::ifstream f(filename); - if (!parse_json(f, filename, ctx.get())) + if (!parse_json(f, filename, ctx)) log_error("Loading design failed.\n"); } - customAfterLoad(ctx.get()); - return ctx; } void CommandHandler::clear() { vm.clear(); } diff --git a/common/command.h b/common/command.h index ba606ea2..c82bcd3a 100644 --- a/common/command.h +++ b/common/command.h @@ -37,7 +37,7 @@ class CommandHandler virtual ~CommandHandler(){}; int exec(); - std::unique_ptr load_json(std::string filename); + void load_json(Context *ctx, std::string filename); void clear(); protected: diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 08cbafe4..50eb2e52 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -30,6 +30,7 @@ #include #include "designwidget.h" #include "fpgaviewwidget.h" +#include "json_frontend.h" #include "jsonwrite.h" #include "log.h" #include "mainwindow.h" @@ -364,8 +365,7 @@ void BaseMainWindow::open_json() QString fileName = QFileDialog::getOpenFileName(this, QString("Open JSON"), QString(), QString("*.json")); if (!fileName.isEmpty()) { disableActions(); - ctx = handler->load_json(fileName.toStdString()); - Q_EMIT contextChanged(ctx.get()); + handler->load_json(ctx.get(), fileName.toStdString()); Q_EMIT updateTreeView(); log("Loading design successful.\n"); updateActions(); -- cgit v1.2.3