Save settings and give nicer names to some
This commit is contained in:
parent
93a0d24560
commit
e5006d4f2f
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include <algorithm>
|
||||||
#include <boost/filesystem/convenience.hpp>
|
#include <boost/filesystem/convenience.hpp>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
#include <fstream>
|
#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.name", boost::filesystem::basename(filename));
|
||||||
root.put("project.arch.name", ctx->archId().c_str(ctx));
|
root.put("project.arch.name", ctx->archId().c_str(ctx));
|
||||||
root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).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.input.json", make_relative(fn, proj.parent_path()).string());
|
||||||
root.put("project.params.freq", int(ctx->target_freq / 1e6));
|
root.put("project.params.freq", int(ctx->target_freq / 1e6));
|
||||||
root.put("project.params.seed", ctx->rngstate);
|
root.put("project.params.seed", ctx->rngstate);
|
||||||
saveArch(ctx, root, proj.parent_path().string());
|
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);
|
pt::write_json(f, root);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
log_error("Error saving project file.\n");
|
log_error("Error saving project file.\n");
|
||||||
|
@ -420,7 +420,7 @@ void BaseMainWindow::disableActions()
|
|||||||
actionNew->setEnabled(true);
|
actionNew->setEnabled(true);
|
||||||
actionOpen->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);
|
actionSave->setEnabled(true);
|
||||||
else
|
else
|
||||||
actionSave->setEnabled(false);
|
actionSave->setEnabled(false);
|
||||||
|
@ -191,7 +191,7 @@ void MainWindow::onRouteFinished() { actionSaveAsc->setEnabled(true); }
|
|||||||
|
|
||||||
void MainWindow::onProjectLoaded()
|
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);
|
actionLoadPCF->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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());
|
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;
|
return true;
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -28,8 +28,8 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path)
|
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path)
|
||||||
{
|
{
|
||||||
root.put("project.arch.package", ctx->archArgs().package);
|
root.put("project.arch.package", ctx->archArgs().package);
|
||||||
if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end()) {
|
if (ctx->settings.find(ctx->id("input/pcf")) != ctx->settings.end()) {
|
||||||
std::string fn = ctx->settings[ctx->id("project/input/pcf")];
|
std::string fn = ctx->settings[ctx->id("input/pcf")];
|
||||||
root.put("project.input.pcf", make_relative(fn, path).string());
|
root.put("project.input.pcf", make_relative(fn, path).string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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_info("Checksum: 0x%08x\n", ctx->checksum());
|
||||||
log_break();
|
log_break();
|
||||||
ctx->settings.emplace(ctx->id("project/input/json"), filename);
|
ctx->settings.emplace(ctx->id("input/json"), filename);
|
||||||
return true;
|
return true;
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user