Use ProjectHandler from gui as well
This commit is contained in:
parent
fffaaa613f
commit
b0741e292c
@ -24,13 +24,13 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
#include "bitstream.h"
|
#include "bitstream.h"
|
||||||
#include "design_utils.h"
|
#include "design_utils.h"
|
||||||
#include "jsonparse.h"
|
#include "jsonparse.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "pcf.h"
|
#include "pcf.h"
|
||||||
|
#include "project.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
||||||
|
|
||||||
@ -168,79 +168,16 @@ void MainWindow::newContext(Context *ctx)
|
|||||||
|
|
||||||
void MainWindow::open_proj()
|
void MainWindow::open_proj()
|
||||||
{
|
{
|
||||||
QMap<std::string, int> 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"));
|
QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj"));
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
namespace pt = boost::property_tree;
|
ProjectHandler proj;
|
||||||
|
|
||||||
std::string fn = fileName.toStdString();
|
|
||||||
currentProj = fn;
|
|
||||||
disableActions();
|
disableActions();
|
||||||
|
ctx = proj.load(fileName.toStdString());
|
||||||
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<int>("project.version");
|
|
||||||
if (version != 1)
|
|
||||||
log_error("Wrong project format version.\n");
|
|
||||||
|
|
||||||
std::string arch_name = root.get<std::string>("project.arch.name");
|
|
||||||
if (arch_name != "ice40")
|
|
||||||
log_error("Unsuported project architecture.\n");
|
|
||||||
|
|
||||||
std::string arch_type = root.get<std::string>("project.arch.type");
|
|
||||||
std::string arch_package = root.get<std::string>("project.arch.package");
|
|
||||||
|
|
||||||
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(arch_type);
|
|
||||||
chipArgs.package = arch_package;
|
|
||||||
ctx = std::unique_ptr<Context>(new Context(chipArgs));
|
|
||||||
Q_EMIT contextChanged(ctx.get());
|
Q_EMIT contextChanged(ctx.get());
|
||||||
|
log_info("Loaded project %s...\n", fileName.toStdString().c_str());
|
||||||
QFileInfo fi(fileName);
|
updateJsonLoaded();
|
||||||
QDir::setCurrent(fi.absoluteDir().absolutePath());
|
actionLoadPCF->setEnabled(false);
|
||||||
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<std::string>("json");
|
|
||||||
if (input.count("pcf"))
|
|
||||||
pcf = input.get<std::string>("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);
|
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,22 +200,8 @@ bool MainWindow::save_proj()
|
|||||||
currentProj = fileName.toStdString();
|
currentProj = fileName.toStdString();
|
||||||
}
|
}
|
||||||
if (!currentProj.empty()) {
|
if (!currentProj.empty()) {
|
||||||
namespace pt = boost::property_tree;
|
ProjectHandler proj;
|
||||||
QFileInfo fi(currentProj.c_str());
|
proj.save(ctx.get(), currentProj);
|
||||||
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());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user