From 9510c444c93fdb8923d77651562fb698e59dea5f Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 5 Aug 2018 18:02:33 +0200 Subject: Disable menu options on json load --- gui/basewindow.cc | 10 ++++++++-- gui/basewindow.h | 6 +++--- gui/ice40/mainwindow.h | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'gui') diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 53720156..98dc9e20 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -302,8 +302,7 @@ void BaseMainWindow::load_json(std::string filename) if (parse_json_file(f, filename, ctx.get())) { log("Loading design successful.\n"); Q_EMIT updateTreeView(); - actionPack->setEnabled(true); - onJsonLoaded(); + updateJsonLoaded(); } else { actionLoadJSON->setEnabled(true); log("Loading design failed.\n"); @@ -425,4 +424,11 @@ void BaseMainWindow::disableActions() onDisableActions(); } +void BaseMainWindow::updateJsonLoaded() +{ + disableActions(); + actionPack->setEnabled(true); + onJsonLoaded(); +} + NEXTPNR_NAMESPACE_END diff --git a/gui/basewindow.h b/gui/basewindow.h index 341cc8e2..67f39ac2 100644 --- a/gui/basewindow.h +++ b/gui/basewindow.h @@ -48,12 +48,12 @@ class BaseMainWindow : public QMainWindow explicit BaseMainWindow(std::unique_ptr context, ArchArgs args, QWidget *parent = 0); virtual ~BaseMainWindow(); Context *getContext() { return ctx.get(); } - - void load_json(std::string filename); - + void updateJsonLoaded(); protected: void createMenusAndBars(); void disableActions(); + void load_json(std::string filename); + virtual void onDisableActions(){}; virtual void onJsonLoaded(){}; virtual void onPackFinished(){}; diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index 829375e2..c235f0a4 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -34,9 +34,10 @@ class MainWindow : public BaseMainWindow public: void createMenu(); - void load_pcf(std::string filename); protected: + void load_pcf(std::string filename); + void onDisableActions() override; void onJsonLoaded() override; void onRouteFinished() override; -- cgit v1.2.3 From b0741e292c7ec7191f2c92fe7695e34018469b67 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 6 Aug 2018 19:47:01 +0200 Subject: Use ProjectHandler from gui as well --- gui/ice40/mainwindow.cc | 95 +++++-------------------------------------------- 1 file changed, 9 insertions(+), 86 deletions(-) (limited to 'gui') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 40b863e9..9870cb0d 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -24,13 +24,13 @@ #include #include #include -#include -#include #include "bitstream.h" #include "design_utils.h" #include "jsonparse.h" #include "log.h" #include "pcf.h" +#include "project.h" +#include static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } @@ -168,79 +168,16 @@ void MainWindow::newContext(Context *ctx) void MainWindow::open_proj() { - QMap arch; -#ifdef ICE40_HX1K_ONLY - arch.insert("hx1k", ArchArgs::HX1K); -#else - arch.insert("lp384", ArchArgs::LP384); - arch.insert("lp1k", ArchArgs::LP1K); - arch.insert("hx1k", ArchArgs::HX1K); - arch.insert("up5k", ArchArgs::UP5K); - arch.insert("lp8k", ArchArgs::LP8K); - arch.insert("hx8k", ArchArgs::HX8K); -#endif - QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj")); if (!fileName.isEmpty()) { try { - namespace pt = boost::property_tree; - - std::string fn = fileName.toStdString(); - currentProj = fn; + ProjectHandler proj; disableActions(); - - pt::ptree root; - std::string filename = fileName.toStdString(); - pt::read_json(filename, root); - log_info("Loading project %s...\n", filename.c_str()); - log_break(); - - int version = root.get("project.version"); - if (version != 1) - log_error("Wrong project format version.\n"); - - std::string arch_name = root.get("project.arch.name"); - if (arch_name != "ice40") - log_error("Unsuported project architecture.\n"); - - std::string arch_type = root.get("project.arch.type"); - std::string arch_package = root.get("project.arch.package"); - - chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(arch_type); - chipArgs.package = arch_package; - ctx = std::unique_ptr(new Context(chipArgs)); + ctx = proj.load(fileName.toStdString()); Q_EMIT contextChanged(ctx.get()); - - QFileInfo fi(fileName); - QDir::setCurrent(fi.absoluteDir().absolutePath()); - log_info("Setting current dir to %s...\n", fi.absoluteDir().absolutePath().toStdString().c_str()); - log_info("Loading project %s...\n", filename.c_str()); - log_info("Context changed to %s (%s)\n", arch_type.c_str(), arch_package.c_str()); - - auto project = root.get_child("project"); - std::string json; - std::string pcf; - if (project.count("input")) { - auto input = project.get_child("input"); - if (input.count("json")) - json = input.get("json"); - if (input.count("pcf")) - pcf = input.get("pcf"); - } - - if (!(QFileInfo::exists(json.c_str()) && QFileInfo(json.c_str()).isFile())) { - log_error("Json file does not exist.\n"); - } - if (!pcf.empty()) { - if (!(QFileInfo::exists(pcf.c_str()) && QFileInfo(pcf.c_str()).isFile())) { - log_error("PCF file does not exist.\n"); - } - } - - log_info("Loading json: %s...\n", json.c_str()); - load_json(json); - if (!pcf.empty()) - load_pcf(json); + log_info("Loaded project %s...\n", fileName.toStdString().c_str()); + updateJsonLoaded(); + actionLoadPCF->setEnabled(false); } catch (log_execution_error_exception) { } } @@ -263,22 +200,8 @@ bool MainWindow::save_proj() currentProj = fileName.toStdString(); } if (!currentProj.empty()) { - namespace pt = boost::property_tree; - QFileInfo fi(currentProj.c_str()); - QDir dir(fi.absoluteDir().absolutePath()); - std::ofstream f(currentProj); - pt::ptree root; - root.put("project.version", 1); - root.put("project.name", fi.baseName().toStdString()); - root.put("project.arch.name", ctx->archId().c_str(ctx.get())); - root.put("project.arch.type", ctx->archArgsToId(chipArgs).c_str(ctx.get())); - root.put("project.arch.package", chipArgs.package); - if (!currentJson.empty()) - root.put("project.input.json", dir.relativeFilePath(currentJson.c_str()).toStdString()); - if (!currentPCF.empty()) - root.put("project.input.pcf", dir.relativeFilePath(currentPCF.c_str()).toStdString()); - pt::write_json(f, root); - log_info("Project %s saved...\n", fi.baseName().toStdString().c_str()); + ProjectHandler proj; + proj.save(ctx.get(), currentProj); return true; } return false; -- cgit v1.2.3 From ecc21caa77b09075a97d131890019f6b97281928 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 8 Aug 2018 18:14:22 +0200 Subject: move load/save proj to base --- gui/basewindow.cc | 33 +++++++++++++++++++++++++++++++++ gui/basewindow.h | 7 +++++-- gui/ice40/mainwindow.cc | 35 +---------------------------------- gui/ice40/mainwindow.h | 4 +--- 4 files changed, 40 insertions(+), 39 deletions(-) (limited to 'gui') diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 98dc9e20..98315ee9 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -31,6 +31,7 @@ #include "jsonparse.h" #include "log.h" #include "mainwindow.h" +#include "project.h" #include "pythontab.h" static void initBasenameResource() { Q_INIT_RESOURCE(base); } @@ -431,4 +432,36 @@ void BaseMainWindow::updateJsonLoaded() onJsonLoaded(); } +void BaseMainWindow::open_proj() +{ + QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj")); + if (!fileName.isEmpty()) { + try { + ProjectHandler proj; + disableActions(); + ctx = proj.load(fileName.toStdString()); + Q_EMIT contextChanged(ctx.get()); + log_info("Loaded project %s...\n", fileName.toStdString().c_str()); + updateJsonLoaded(); + onProjectLoaded(); + } catch (log_execution_error_exception) { + } + } +} + +void BaseMainWindow::save_proj() +{ + if (currentProj.empty()) { + QString fileName = QFileDialog::getSaveFileName(this, QString("Save Project"), QString(), QString("*.proj")); + if (fileName.isEmpty()) + return; + currentProj = fileName.toStdString(); + } + if (!currentProj.empty()) { + ProjectHandler proj; + proj.save(ctx.get(), currentProj); + } +} + + NEXTPNR_NAMESPACE_END diff --git a/gui/basewindow.h b/gui/basewindow.h index 67f39ac2..ef3e252c 100644 --- a/gui/basewindow.h +++ b/gui/basewindow.h @@ -56,6 +56,7 @@ class BaseMainWindow : public QMainWindow virtual void onDisableActions(){}; virtual void onJsonLoaded(){}; + virtual void onProjectLoaded(){}; virtual void onPackFinished(){}; virtual void onBudgetFinished(){}; virtual void onPlaceFinished(){}; @@ -66,8 +67,9 @@ class BaseMainWindow : public QMainWindow void closeTab(int index); virtual void new_proj() = 0; - virtual void open_proj() = 0; - virtual bool save_proj() = 0; + + void open_proj(); + void save_proj(); void open_json(); void budget(); @@ -93,6 +95,7 @@ class BaseMainWindow : public QMainWindow TaskManager *task; bool timing_driven; std::string currentJson; + std::string currentProj; // main widgets QTabWidget *tabWidget; diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 9870cb0d..4a2eaaa9 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -29,7 +29,6 @@ #include "jsonparse.h" #include "log.h" #include "pcf.h" -#include "project.h" #include static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } @@ -166,23 +165,6 @@ void MainWindow::newContext(Context *ctx) setWindowTitle(title.c_str()); } -void MainWindow::open_proj() -{ - QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj")); - if (!fileName.isEmpty()) { - try { - ProjectHandler proj; - disableActions(); - ctx = proj.load(fileName.toStdString()); - Q_EMIT contextChanged(ctx.get()); - log_info("Loaded project %s...\n", fileName.toStdString().c_str()); - updateJsonLoaded(); - actionLoadPCF->setEnabled(false); - } catch (log_execution_error_exception) { - } - } -} - void MainWindow::open_pcf() { QString fileName = QFileDialog::getOpenFileName(this, QString("Open PCF"), QString(), QString("*.pcf")); @@ -191,22 +173,6 @@ void MainWindow::open_pcf() } } -bool MainWindow::save_proj() -{ - if (currentProj.empty()) { - QString fileName = QFileDialog::getSaveFileName(this, QString("Save Project"), QString(), QString("*.proj")); - if (fileName.isEmpty()) - return false; - currentProj = fileName.toStdString(); - } - if (!currentProj.empty()) { - ProjectHandler proj; - proj.save(ctx.get(), currentProj); - return true; - } - return false; -} - void MainWindow::save_asc() { QString fileName = QFileDialog::getSaveFileName(this, QString("Save ASC"), QString(), QString("*.asc")); @@ -227,5 +193,6 @@ void MainWindow::onDisableActions() void MainWindow::onJsonLoaded() { actionLoadPCF->setEnabled(true); } void MainWindow::onRouteFinished() { actionSaveAsc->setEnabled(true); } +void MainWindow::onProjectLoaded() { actionLoadPCF->setEnabled(false); } NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index c235f0a4..201bf1b1 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -41,11 +41,10 @@ class MainWindow : public BaseMainWindow void onDisableActions() override; void onJsonLoaded() override; void onRouteFinished() override; + void onProjectLoaded() override; protected Q_SLOTS: virtual void new_proj(); - virtual void open_proj(); - virtual bool save_proj(); void open_pcf(); void save_asc(); @@ -56,7 +55,6 @@ class MainWindow : public BaseMainWindow QAction *actionLoadPCF; QAction *actionSaveAsc; - std::string currentProj; std::string currentPCF; }; -- cgit v1.2.3 From fc5cee6fb896bc4d7a8b79dcde789e03c787bd89 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 8 Aug 2018 18:17:34 +0200 Subject: clangformat --- gui/basewindow.cc | 1 - gui/basewindow.h | 1 + gui/ecp5/mainwindow.cc | 12 +++++++----- gui/ecp5/mainwindow.h | 1 + gui/generic/mainwindow.cc | 3 ++- gui/ice40/mainwindow.cc | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) (limited to 'gui') diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 98315ee9..857919ea 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -463,5 +463,4 @@ void BaseMainWindow::save_proj() } } - NEXTPNR_NAMESPACE_END diff --git a/gui/basewindow.h b/gui/basewindow.h index ef3e252c..6e8f8587 100644 --- a/gui/basewindow.h +++ b/gui/basewindow.h @@ -49,6 +49,7 @@ class BaseMainWindow : public QMainWindow virtual ~BaseMainWindow(); Context *getContext() { return ctx.get(); } void updateJsonLoaded(); + protected: void createMenusAndBars(); void disableActions(); diff --git a/gui/ecp5/mainwindow.cc b/gui/ecp5/mainwindow.cc index efaad364..e5a5f1ba 100644 --- a/gui/ecp5/mainwindow.cc +++ b/gui/ecp5/mainwindow.cc @@ -29,7 +29,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } NEXTPNR_NAMESPACE_BEGIN -MainWindow::MainWindow(std::unique_ptr context, ArchArgs args, QWidget *parent) : BaseMainWindow(std::move(context), args, parent) +MainWindow::MainWindow(std::unique_ptr context, ArchArgs args, QWidget *parent) + : BaseMainWindow(std::move(context), args, parent) { initMainResource(); @@ -50,7 +51,8 @@ void MainWindow::newContext(Context *ctx) setWindowTitle(title.c_str()); } -void MainWindow::createMenu() { +void MainWindow::createMenu() +{ // Add arch specific actions actionLoadBase = new QAction("Open Base Config", this); actionLoadBase->setIcon(QIcon(":/icons/resources/open_base.png")); @@ -71,7 +73,7 @@ void MainWindow::createMenu() { menuDesign->addSeparator(); menuDesign->addAction(actionLoadBase); - menuDesign->addAction(actionSaveConfig); + menuDesign->addAction(actionSaveConfig); } static const ChipInfoPOD *get_chip_info(const RelPtr *ptr) { return ptr->get(); } @@ -96,8 +98,8 @@ static QStringList getSupportedPackages(ArchArgs::ArchArgsTypes chip) return packages; } - -void MainWindow::new_proj() { +void MainWindow::new_proj() +{ QMap arch; arch.insert("Lattice ECP5 25K", ArchArgs::LFE5U_25F); arch.insert("Lattice ECP5 45K", ArchArgs::LFE5U_45F); diff --git a/gui/ecp5/mainwindow.h b/gui/ecp5/mainwindow.h index d1d5a5a2..9460913c 100644 --- a/gui/ecp5/mainwindow.h +++ b/gui/ecp5/mainwindow.h @@ -47,6 +47,7 @@ class MainWindow : public BaseMainWindow void newContext(Context *ctx); void open_base(); void save_config(); + private: QAction *actionLoadBase; QAction *actionSaveConfig; diff --git a/gui/generic/mainwindow.cc b/gui/generic/mainwindow.cc index 050c0fb8..01eeb4ef 100644 --- a/gui/generic/mainwindow.cc +++ b/gui/generic/mainwindow.cc @@ -23,7 +23,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } NEXTPNR_NAMESPACE_BEGIN -MainWindow::MainWindow(std::unique_ptr context, ArchArgs args, QWidget *parent) : BaseMainWindow(std::move(context), args, parent) +MainWindow::MainWindow(std::unique_ptr context, ArchArgs args, QWidget *parent) + : BaseMainWindow(std::move(context), args, parent) { initMainResource(); diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 4a2eaaa9..35ad5768 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -24,12 +24,12 @@ #include #include #include +#include #include "bitstream.h" #include "design_utils.h" #include "jsonparse.h" #include "log.h" #include "pcf.h" -#include static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } -- cgit v1.2.3