Make loading works nice and use settings
This commit is contained in:
parent
bc378fc3e4
commit
5dd7a74b87
@ -168,12 +168,16 @@ int CommandHandler::executeMain(std::unique_ptr<Context> ctx)
|
||||
if (vm.count("json")) {
|
||||
std::string filename = vm["json"].as<std::string>();
|
||||
std::ifstream f(filename);
|
||||
w.notifyChangeContext();
|
||||
if (!parse_json_file(f, filename, w.getContext()))
|
||||
log_error("Loading design failed.\n");
|
||||
|
||||
customAfterLoad(w.getContext());
|
||||
w.updateJsonLoaded();
|
||||
}
|
||||
w.updateLoaded();
|
||||
} else if (vm.count("load")) {
|
||||
w.projectLoad(vm["load"].as<std::string>());
|
||||
} else
|
||||
w.notifyChangeContext();
|
||||
} catch (log_execution_error_exception) {
|
||||
// show error is handled by gui itself
|
||||
}
|
||||
@ -247,7 +251,7 @@ int CommandHandler::exec()
|
||||
return 0;
|
||||
|
||||
std::unique_ptr<Context> ctx;
|
||||
if (vm.count("load")) {
|
||||
if (vm.count("load") && vm.count("gui") == 0) {
|
||||
ctx = project.load(vm["load"].as<std::string>());
|
||||
} else {
|
||||
ctx = createContext();
|
||||
|
@ -298,12 +298,11 @@ void BaseMainWindow::createMenusAndBars()
|
||||
void BaseMainWindow::load_json(std::string filename)
|
||||
{
|
||||
disableActions();
|
||||
currentJson = filename;
|
||||
std::ifstream f(filename);
|
||||
if (parse_json_file(f, filename, ctx.get())) {
|
||||
log("Loading design successful.\n");
|
||||
Q_EMIT updateTreeView();
|
||||
updateJsonLoaded();
|
||||
updateLoaded();
|
||||
} else {
|
||||
actionLoadJSON->setEnabled(true);
|
||||
log("Loading design failed.\n");
|
||||
@ -420,35 +419,42 @@ void BaseMainWindow::disableActions()
|
||||
|
||||
actionNew->setEnabled(true);
|
||||
actionOpen->setEnabled(true);
|
||||
actionSave->setEnabled(!currentJson.empty());
|
||||
|
||||
if (ctx->settings.find(ctx->id("project/input/json")) != ctx->settings.end())
|
||||
actionSave->setEnabled(true);
|
||||
else
|
||||
actionSave->setEnabled(false);
|
||||
|
||||
onDisableActions();
|
||||
}
|
||||
|
||||
void BaseMainWindow::updateJsonLoaded()
|
||||
void BaseMainWindow::updateLoaded()
|
||||
{
|
||||
disableActions();
|
||||
actionPack->setEnabled(true);
|
||||
onJsonLoaded();
|
||||
onProjectLoaded();
|
||||
}
|
||||
|
||||
void BaseMainWindow::projectLoad(std::string filename)
|
||||
{
|
||||
ProjectHandler proj;
|
||||
disableActions();
|
||||
ctx = proj.load(filename);
|
||||
Q_EMIT contextChanged(ctx.get());
|
||||
log_info("Loaded project %s...\n", filename.c_str());
|
||||
updateLoaded();
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
projectLoad(fileName.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void BaseMainWindow::notifyChangeContext() { Q_EMIT contextChanged(ctx.get()); }
|
||||
void BaseMainWindow::save_proj()
|
||||
{
|
||||
if (currentProj.empty()) {
|
||||
|
@ -48,7 +48,9 @@ class BaseMainWindow : public QMainWindow
|
||||
explicit BaseMainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent = 0);
|
||||
virtual ~BaseMainWindow();
|
||||
Context *getContext() { return ctx.get(); }
|
||||
void updateJsonLoaded();
|
||||
void updateLoaded();
|
||||
void projectLoad(std::string filename);
|
||||
void notifyChangeContext();
|
||||
|
||||
protected:
|
||||
void createMenusAndBars();
|
||||
@ -95,7 +97,6 @@ class BaseMainWindow : public QMainWindow
|
||||
std::unique_ptr<Context> ctx;
|
||||
TaskManager *task;
|
||||
bool timing_driven;
|
||||
std::string currentJson;
|
||||
std::string currentProj;
|
||||
|
||||
// main widgets
|
||||
|
@ -40,7 +40,6 @@ MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget
|
||||
connect(this, &BaseMainWindow::contextChanged, this, &MainWindow::newContext);
|
||||
|
||||
createMenu();
|
||||
Q_EMIT contextChanged(ctx.get());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {}
|
||||
@ -115,7 +114,6 @@ void MainWindow::new_proj()
|
||||
|
||||
if (ok && !item.isEmpty()) {
|
||||
currentProj = "";
|
||||
currentJson = "";
|
||||
disableActions();
|
||||
chipArgs.package = package.toStdString().c_str();
|
||||
ctx = std::unique_ptr<Context>(new Context(chipArgs));
|
||||
|
@ -34,7 +34,6 @@ MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget
|
||||
connect(this, &BaseMainWindow::contextChanged, this, &MainWindow::newContext);
|
||||
|
||||
createMenu();
|
||||
Q_EMIT contextChanged(ctx.get());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {}
|
||||
|
@ -46,8 +46,6 @@ MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget
|
||||
connect(this, &BaseMainWindow::contextChanged, this, &MainWindow::newContext);
|
||||
|
||||
createMenu();
|
||||
|
||||
Q_EMIT contextChanged(ctx.get());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {}
|
||||
@ -133,8 +131,6 @@ void MainWindow::new_proj()
|
||||
|
||||
if (ok && !item.isEmpty()) {
|
||||
currentProj = "";
|
||||
currentJson = "";
|
||||
currentPCF = "";
|
||||
disableActions();
|
||||
chipArgs.package = package.toStdString().c_str();
|
||||
ctx = std::unique_ptr<Context>(new Context(chipArgs));
|
||||
@ -148,7 +144,6 @@ void MainWindow::new_proj()
|
||||
void MainWindow::load_pcf(std::string filename)
|
||||
{
|
||||
disableActions();
|
||||
currentPCF = filename;
|
||||
std::ifstream f(filename);
|
||||
if (apply_pcf(ctx.get(), filename, f)) {
|
||||
log("Loading PCF successful.\n");
|
||||
@ -193,6 +188,11 @@ void MainWindow::onDisableActions()
|
||||
|
||||
void MainWindow::onJsonLoaded() { actionLoadPCF->setEnabled(true); }
|
||||
void MainWindow::onRouteFinished() { actionSaveAsc->setEnabled(true); }
|
||||
void MainWindow::onProjectLoaded() { actionLoadPCF->setEnabled(false); }
|
||||
|
||||
void MainWindow::onProjectLoaded()
|
||||
{
|
||||
if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end())
|
||||
actionLoadPCF->setEnabled(false);
|
||||
}
|
||||
|
||||
NEXTPNR_NAMESPACE_END
|
||||
|
@ -54,8 +54,6 @@ class MainWindow : public BaseMainWindow
|
||||
private:
|
||||
QAction *actionLoadPCF;
|
||||
QAction *actionSaveAsc;
|
||||
|
||||
std::string currentPCF;
|
||||
};
|
||||
|
||||
NEXTPNR_NAMESPACE_END
|
||||
|
Loading…
Reference in New Issue
Block a user