Save settings and give nicer names to some

This commit is contained in:
Miodrag Milanovic 2018-08-10 19:11:30 +02:00
parent 93a0d24560
commit e5006d4f2f
6 changed files with 15 additions and 7 deletions

View File

@ -18,6 +18,7 @@
*/
#include "project.h"
#include <algorithm>
#include <boost/filesystem/convenience.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
@ -64,11 +65,18 @@ void ProjectHandler::save(Context *ctx, std::string filename)
root.put("project.name", boost::filesystem::basename(filename));
root.put("project.arch.name", ctx->archId().c_str(ctx));
root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
std::string fn = ctx->settings[ctx->id("project/input/json")];
std::string fn = ctx->settings[ctx->id("input/json")];
root.put("project.input.json", make_relative(fn, proj.parent_path()).string());
root.put("project.params.freq", int(ctx->target_freq / 1e6));
root.put("project.params.seed", ctx->rngstate);
saveArch(ctx, root, proj.parent_path().string());
for(auto const &item : ctx->settings)
{
std::string path = "project.settings.";
path += item.first.c_str(ctx);
std::replace(path.begin(), path.end(), '/', '.');
root.put(path, item.second);
}
pt::write_json(f, root);
} catch (...) {
log_error("Error saving project file.\n");

View File

@ -420,7 +420,7 @@ void BaseMainWindow::disableActions()
actionNew->setEnabled(true);
actionOpen->setEnabled(true);
if (ctx->settings.find(ctx->id("project/input/json")) != ctx->settings.end())
if (ctx->settings.find(ctx->id("input/json")) != ctx->settings.end())
actionSave->setEnabled(true);
else
actionSave->setEnabled(false);

View File

@ -191,7 +191,7 @@ void MainWindow::onRouteFinished() { actionSaveAsc->setEnabled(true); }
void MainWindow::onProjectLoaded()
{
if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end())
if (ctx->settings.find(ctx->id("input/pcf")) != ctx->settings.end())
actionLoadPCF->setEnabled(false);
}

View File

@ -66,7 +66,7 @@ bool apply_pcf(Context *ctx, std::string filename, std::istream &in)
log_error("unsupported pcf command '%s'\n", cmd.c_str());
}
}
ctx->settings.emplace(ctx->id("project/input/pcf"), filename);
ctx->settings.emplace(ctx->id("input/pcf"), filename);
return true;
} catch (log_execution_error_exception) {
return false;

View File

@ -28,8 +28,8 @@ NEXTPNR_NAMESPACE_BEGIN
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path)
{
root.put("project.arch.package", ctx->archArgs().package);
if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end()) {
std::string fn = ctx->settings[ctx->id("project/input/pcf")];
if (ctx->settings.find(ctx->id("input/pcf")) != ctx->settings.end()) {
std::string fn = ctx->settings[ctx->id("input/pcf")];
root.put("project.input.pcf", make_relative(fn, path).string());
}
}

View File

@ -754,7 +754,7 @@ bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
log_info("Checksum: 0x%08x\n", ctx->checksum());
log_break();
ctx->settings.emplace(ctx->id("project/input/json"), filename);
ctx->settings.emplace(ctx->id("input/json"), filename);
return true;
} catch (log_execution_error_exception) {
return false;