Merge branch 'master' of gitlab.com:SymbioticEDA/nextpnr

This commit is contained in:
David Shah 2018-06-26 15:58:35 +02:00
commit 95de0a36b4
15 changed files with 130 additions and 74 deletions

View File

@ -200,7 +200,7 @@ struct BaseCtx
BaseCtx() BaseCtx()
{ {
assert(IdString::global_ctx == nullptr); //assert(IdString::global_ctx == nullptr);
IdString::global_ctx = this; IdString::global_ctx = this;
idstring_str_to_idx = new std::unordered_map<std::string, int>; idstring_str_to_idx = new std::unordered_map<std::string, int>;

View File

@ -120,7 +120,7 @@ int main(int argc, char *argv[])
#ifndef NO_GUI #ifndef NO_GUI
if (vm.count("gui")) { if (vm.count("gui")) {
Application a(argc, argv); Application a(argc, argv);
MainWindow w(&ctx); MainWindow w;
w.show(); w.show();
rc = a.exec(); rc = a.exec();

View File

@ -36,7 +36,7 @@ static void initBasenameResource() { Q_INIT_RESOURCE(base); }
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) : QMainWindow(parent), ctx(_ctx) BaseMainWindow::BaseMainWindow(QWidget *parent) : QMainWindow(parent), ctx(nullptr)
{ {
initBasenameResource(); initBasenameResource();
qRegisterMetaType<std::string>(); qRegisterMetaType<std::string>();
@ -63,11 +63,13 @@ BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) : QMainWindow(par
setCentralWidget(centralWidget); setCentralWidget(centralWidget);
DesignWidget *designview = new DesignWidget(ctx); DesignWidget *designview = new DesignWidget();
designview->setMinimumWidth(300); designview->setMinimumWidth(300);
designview->setMaximumWidth(300); designview->setMaximumWidth(300);
splitter_h->addWidget(designview); splitter_h->addWidget(designview);
connect(this, SIGNAL(contextChanged(Context*)), designview, SLOT(newContext(Context*)));
connect(designview, SIGNAL(info(std::string)), this, SLOT(writeInfo(std::string))); connect(designview, SIGNAL(info(std::string)), this, SLOT(writeInfo(std::string)));
tabWidget = new QTabWidget(); tabWidget = new QTabWidget();
@ -78,7 +80,10 @@ BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) : QMainWindow(par
tabWidget->addTab(info, "Info"); tabWidget->addTab(info, "Info");
centralTabWidget = new QTabWidget(); centralTabWidget = new QTabWidget();
centralTabWidget->addTab(new FPGAViewWidget(), "Graphics"); FPGAViewWidget *fpgaView = new FPGAViewWidget();
centralTabWidget->addTab(fpgaView, "Graphics");
connect(this, SIGNAL(contextChanged(Context*)), fpgaView, SLOT(newContext(Context*)));
splitter_v->addWidget(centralTabWidget); splitter_v->addWidget(centralTabWidget);
splitter_v->addWidget(tabWidget); splitter_v->addWidget(tabWidget);

View File

@ -39,7 +39,7 @@ class BaseMainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit BaseMainWindow(Context *ctx, QWidget *parent = 0); explicit BaseMainWindow(QWidget *parent = 0);
virtual ~BaseMainWindow(); virtual ~BaseMainWindow();
Context *getContext() { return ctx; } Context *getContext() { return ctx; }
@ -53,6 +53,9 @@ class BaseMainWindow : public QMainWindow
virtual void open_proj() = 0; virtual void open_proj() = 0;
virtual bool save_proj() = 0; virtual bool save_proj() = 0;
Q_SIGNALS:
void contextChanged(Context *ctx);
protected: protected:
Context *ctx; Context *ctx;
QTabWidget *tabWidget; QTabWidget *tabWidget;

View File

@ -82,7 +82,7 @@ class PipTreeItem : public ElementTreeItem
IdString data; IdString data;
}; };
DesignWidget::DesignWidget(Context *_ctx, QWidget *parent) : QWidget(parent), ctx(_ctx) DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr)
{ {
treeWidget = new QTreeWidget(); treeWidget = new QTreeWidget();
@ -92,39 +92,6 @@ DesignWidget::DesignWidget(Context *_ctx, QWidget *parent) : QWidget(parent), ct
treeWidget->setHeaderLabel(QString("Items")); treeWidget->setHeaderLabel(QString("Items"));
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// Add bels to tree
QTreeWidgetItem *bel_root = new QTreeWidgetItem(treeWidget);
bel_root->setText(0, QString("Bels"));
treeWidget->insertTopLevelItem(0, bel_root);
QList<QTreeWidgetItem *> bel_items;
for (auto bel : ctx->getBels()) {
auto name = ctx->getBelName(bel);
bel_items.append(new BelTreeItem(name, ElementType::BEL, QString(name.c_str(ctx))));
}
bel_root->addChildren(bel_items);
// Add wires to tree
QTreeWidgetItem *wire_root = new QTreeWidgetItem(treeWidget);
QList<QTreeWidgetItem *> wire_items;
wire_root->setText(0, QString("Wires"));
treeWidget->insertTopLevelItem(0, wire_root);
for (auto wire : ctx->getWires()) {
auto name = ctx->getWireName(wire);
wire_items.append(new WireTreeItem(name, ElementType::WIRE, QString(name.c_str(ctx))));
}
wire_root->addChildren(wire_items);
// Add pips to tree
QTreeWidgetItem *pip_root = new QTreeWidgetItem(treeWidget);
QList<QTreeWidgetItem *> pip_items;
pip_root->setText(0, QString("Pips"));
treeWidget->insertTopLevelItem(0, pip_root);
for (auto pip : ctx->getPips()) {
auto name = ctx->getPipName(pip);
pip_items.append(new PipTreeItem(name, ElementType::PIP, QString(name.c_str(ctx))));
}
pip_root->addChildren(pip_items);
// Add property view // Add property view
variantManager = new QtVariantPropertyManager(); variantManager = new QtVariantPropertyManager();
variantFactory = new QtVariantEditorFactory(); variantFactory = new QtVariantEditorFactory();
@ -158,6 +125,54 @@ DesignWidget::~DesignWidget()
delete propertyEditor; delete propertyEditor;
} }
void DesignWidget::newContext(Context *ctx)
{
treeWidget->clear();
this->ctx = ctx;
// Add bels to tree
QTreeWidgetItem *bel_root = new QTreeWidgetItem(treeWidget);
bel_root->setText(0, QString("Bels"));
treeWidget->insertTopLevelItem(0, bel_root);
QList<QTreeWidgetItem *> bel_items;
if (ctx)
{
for (auto bel : ctx->getBels()) {
auto name = ctx->getBelName(bel);
bel_items.append(new BelTreeItem(name, ElementType::BEL, QString(name.c_str(ctx))));
}
}
bel_root->addChildren(bel_items);
// Add wires to tree
QTreeWidgetItem *wire_root = new QTreeWidgetItem(treeWidget);
QList<QTreeWidgetItem *> wire_items;
wire_root->setText(0, QString("Wires"));
treeWidget->insertTopLevelItem(0, wire_root);
if (ctx)
{
for (auto wire : ctx->getWires()) {
auto name = ctx->getWireName(wire);
wire_items.append(new WireTreeItem(name, ElementType::WIRE, QString(name.c_str(ctx))));
}
}
wire_root->addChildren(wire_items);
// Add pips to tree
QTreeWidgetItem *pip_root = new QTreeWidgetItem(treeWidget);
QList<QTreeWidgetItem *> pip_items;
pip_root->setText(0, QString("Pips"));
treeWidget->insertTopLevelItem(0, pip_root);
if (ctx)
{
for (auto pip : ctx->getPips()) {
auto name = ctx->getPipName(pip);
pip_items.append(new PipTreeItem(name, ElementType::PIP, QString(name.c_str(ctx))));
}
}
pip_root->addChildren(pip_items);
}
void DesignWidget::addProperty(QtVariantProperty *property, const QString &id) void DesignWidget::addProperty(QtVariantProperty *property, const QString &id)
{ {
propertyToId[property] = id; propertyToId[property] = id;

View File

@ -33,9 +33,8 @@ class DesignWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit DesignWidget(Context *ctx, QWidget *parent = 0); explicit DesignWidget(QWidget *parent = 0);
~DesignWidget(); ~DesignWidget();
Context *getContext() { return ctx; }
private: private:
void addProperty(QtVariantProperty *property, const QString &id); void addProperty(QtVariantProperty *property, const QString &id);
@ -48,6 +47,8 @@ class DesignWidget : public QWidget
void prepareMenu(const QPoint &pos); void prepareMenu(const QPoint &pos);
void onItemClicked(QTreeWidgetItem *item, int); void onItemClicked(QTreeWidgetItem *item, int);
void selectObject(); void selectObject();
public Q_SLOTS:
void newContext(Context *ctx);
private: private:
Context *ctx; Context *ctx;

View File

@ -23,11 +23,11 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent)
{ {
initMainResource(); initMainResource();
std::string title = "nextpnr-dummy - " + ctx->getChipName(); std::string title = "nextpnr-dummy - [EMPTY]";
setWindowTitle(title.c_str()); setWindowTitle(title.c_str());
createMenu(); createMenu();

View File

@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(Context *ctx, QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
virtual ~MainWindow(); virtual ~MainWindow();
public: public:

View File

@ -241,9 +241,8 @@ void LineShader::draw(const LineShaderData &line, const QMatrix4x4 &projection)
} }
FPGAViewWidget::FPGAViewWidget(QWidget *parent) FPGAViewWidget::FPGAViewWidget(QWidget *parent)
: QOpenGLWidget(parent), moveX_(0), moveY_(0), zoom_(10.0f), lineShader_(this) : QOpenGLWidget(parent), moveX_(0), moveY_(0), zoom_(10.0f), lineShader_(this), ctx_(nullptr)
{ {
ctx_ = qobject_cast<BaseMainWindow *>(getMainWindow())->getContext();
auto fmt = format(); auto fmt = format();
fmt.setMajorVersion(3); fmt.setMajorVersion(3);
fmt.setMinorVersion(1); fmt.setMinorVersion(1);
@ -260,17 +259,14 @@ FPGAViewWidget::FPGAViewWidget(QWidget *parent)
} }
} }
QMainWindow *FPGAViewWidget::getMainWindow()
{
QWidgetList widgets = qApp->topLevelWidgets();
for (QWidgetList::iterator i = widgets.begin(); i != widgets.end(); ++i)
if ((*i)->objectName() == "BaseMainWindow")
return (QMainWindow *)(*i);
return NULL;
}
FPGAViewWidget::~FPGAViewWidget() {} FPGAViewWidget::~FPGAViewWidget() {}
void FPGAViewWidget::newContext(Context *ctx)
{
ctx_ = ctx;
update();
}
QSize FPGAViewWidget::minimumSizeHint() const { return QSize(640, 480); } QSize FPGAViewWidget::minimumSizeHint() const { return QSize(640, 480); }
QSize FPGAViewWidget::sizeHint() const { return QSize(640, 480); } QSize FPGAViewWidget::sizeHint() const { return QSize(640, 480); }
@ -359,16 +355,22 @@ void FPGAViewWidget::paintGL()
// Draw Bels. // Draw Bels.
auto bels = LineShaderData(0.02f, QColor("#b000ba")); auto bels = LineShaderData(0.02f, QColor("#b000ba"));
for (auto bel : ctx_->getBels()) { if (ctx_)
for (auto &el : ctx_->getBelGraphics(bel)) {
drawElement(bels, el); for (auto bel : ctx_->getBels()) {
for (auto &el : ctx_->getBelGraphics(bel))
drawElement(bels, el);
}
} }
lineShader_.draw(bels, matrix); lineShader_.draw(bels, matrix);
// Draw Frame Graphics. // Draw Frame Graphics.
auto frames = LineShaderData(0.02f, QColor("#0066ba")); auto frames = LineShaderData(0.02f, QColor("#0066ba"));
for (auto &el : ctx_->getFrameGraphics()) { if (ctx_)
drawElement(frames, el); {
for (auto &el : ctx_->getFrameGraphics()) {
drawElement(frames, el);
}
} }
lineShader_.draw(frames, matrix); lineShader_.draw(frames, matrix);
} }

View File

@ -240,8 +240,8 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
void drawElement(LineShaderData &data, const GraphicElement &el); void drawElement(LineShaderData &data, const GraphicElement &el);
QMainWindow *getMainWindow(); public Q_SLOTS:
void newContext(Context *ctx);
private: private:
QPoint lastPos_; QPoint lastPos_;
float moveX_; float moveX_;

View File

@ -36,14 +36,14 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent), timing_driven(false) MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent), timing_driven(false)
{ {
initMainResource(); initMainResource();
std::string title = "nextpnr-ice40 - " + ctx->getChipName(); std::string title = "nextpnr-ice40 - [EMPTY]";
setWindowTitle(title.c_str()); setWindowTitle(title.c_str());
task = new TaskManager(_ctx); task = new TaskManager();
connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string))); connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string)));
connect(task, SIGNAL(loadfile_finished(bool)), this, SLOT(loadfile_finished(bool))); connect(task, SIGNAL(loadfile_finished(bool)), this, SLOT(loadfile_finished(bool)));
@ -58,6 +58,9 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, pa
connect(task, SIGNAL(taskStarted()), this, SLOT(taskStarted())); connect(task, SIGNAL(taskStarted()), this, SLOT(taskStarted()));
connect(task, SIGNAL(taskPaused()), this, SLOT(taskPaused())); connect(task, SIGNAL(taskPaused()), this, SLOT(taskPaused()));
connect(this, SIGNAL(contextChanged(Context*)), this, SLOT(newContext(Context*)));
connect(this, SIGNAL(contextChanged(Context*)), task, SIGNAL(contextChanged(Context*)));
createMenu(); createMenu();
} }
@ -178,12 +181,27 @@ void MainWindow::createMenu()
void MainWindow::new_proj() void MainWindow::new_proj()
{ {
disableActions(); disableActions();
ArchArgs chipArgs;
chipArgs.type = ArchArgs::HX1K;
chipArgs.package = "tq144";
if (ctx)
delete ctx;
ctx = new Context(chipArgs);
Q_EMIT contextChanged(ctx);
actionLoadJSON->setEnabled(true); actionLoadJSON->setEnabled(true);
} }
void MainWindow::newContext(Context *ctx)
{
std::string title = "nextpnr-ice40 - " + ctx->getChipName();
setWindowTitle(title.c_str());
}
void MainWindow::open_proj() void MainWindow::open_proj()
{ {
QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.npnr")); QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
tabWidget->setCurrentWidget(info); tabWidget->setCurrentWidget(info);

View File

@ -30,7 +30,7 @@ class MainWindow : public BaseMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(Context *ctx, QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
virtual ~MainWindow(); virtual ~MainWindow();
public: public:
@ -59,6 +59,8 @@ class MainWindow : public BaseMainWindow
void taskStarted(); void taskStarted();
void taskPaused(); void taskPaused();
void newContext(Context *ctx);
private: private:
void disableActions(); void disableActions();

View File

@ -35,7 +35,7 @@ struct WorkerInterruptionRequested
{ {
}; };
Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) Worker::Worker(TaskManager *parent) : ctx(nullptr)
{ {
log_write_function = [this, parent](std::string text) { log_write_function = [this, parent](std::string text) {
Q_EMIT log(text); Q_EMIT log(text);
@ -56,6 +56,11 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx)
}; };
} }
void Worker::newContext(Context *ctx_)
{
ctx = ctx_;
}
void Worker::loadfile(const std::string &filename) void Worker::loadfile(const std::string &filename)
{ {
Q_EMIT taskStarted(); Q_EMIT taskStarted();
@ -136,9 +141,9 @@ void Worker::route()
} }
} }
TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) TaskManager::TaskManager() : toTerminate(false), toPause(false)
{ {
Worker *worker = new Worker(ctx, this); Worker *worker = new Worker(this);
worker->moveToThread(&workerThread); worker->moveToThread(&workerThread);
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
@ -151,6 +156,9 @@ TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false)
connect(this, &TaskManager::place, worker, &Worker::place); connect(this, &TaskManager::place, worker, &Worker::place);
connect(this, &TaskManager::route, worker, &Worker::route); connect(this, &TaskManager::route, worker, &Worker::route);
connect(this, &TaskManager::contextChanged, worker, &Worker::newContext);
connect(worker, &Worker::log, this, &TaskManager::info); connect(worker, &Worker::log, this, &TaskManager::info);
connect(worker, &Worker::loadfile_finished, this, &TaskManager::loadfile_finished); connect(worker, &Worker::loadfile_finished, this, &TaskManager::loadfile_finished);
connect(worker, &Worker::loadpcf_finished, this, &TaskManager::loadpcf_finished); connect(worker, &Worker::loadpcf_finished, this, &TaskManager::loadpcf_finished);

View File

@ -32,8 +32,9 @@ class Worker : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Worker(Context *ctx, TaskManager *parent); explicit Worker(TaskManager *parent);
public Q_SLOTS: public Q_SLOTS:
void newContext(Context *);
void loadfile(const std::string &); void loadfile(const std::string &);
void loadpcf(const std::string &); void loadpcf(const std::string &);
void saveasc(const std::string &); void saveasc(const std::string &);
@ -64,7 +65,7 @@ class TaskManager : public QObject
QThread workerThread; QThread workerThread;
public: public:
TaskManager(Context *ctx); explicit TaskManager();
~TaskManager(); ~TaskManager();
bool shouldTerminate(); bool shouldTerminate();
void clearTerminate(); void clearTerminate();
@ -75,6 +76,7 @@ class TaskManager : public QObject
void pause_thread(); void pause_thread();
void continue_thread(); void continue_thread();
Q_SIGNALS: Q_SIGNALS:
void contextChanged(Context *ctx);
void terminate(); void terminate();
void loadfile(const std::string &); void loadfile(const std::string &);
void loadpcf(const std::string &); void loadpcf(const std::string &);

View File

@ -399,7 +399,7 @@ int main(int argc, char *argv[])
#ifndef NO_GUI #ifndef NO_GUI
if (vm.count("gui")) { if (vm.count("gui")) {
Application a(argc, argv); Application a(argc, argv);
MainWindow w(&ctx); MainWindow w;
w.show(); w.show();
rc = a.exec(); rc = a.exec();