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