nextpnr/gui/designwidget.cc

676 lines
26 KiB
C++
Raw Normal View History

2018-06-22 22:21:20 +08:00
/*
* nextpnr -- Next Generation Place and Route
*
* Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
2018-06-15 02:03:59 +08:00
#include "designwidget.h"
#include <QAction>
#include <QGridLayout>
#include <QLineEdit>
2018-06-15 02:03:59 +08:00
#include <QMenu>
#include <QSplitter>
#include <QToolBar>
2018-06-15 02:03:59 +08:00
#include <QTreeWidgetItem>
#include "fpgaviewwidget.h"
2018-06-22 19:10:27 +08:00
NEXTPNR_NAMESPACE_BEGIN
2018-06-15 02:03:59 +08:00
enum class ElementType
{
NONE,
2018-06-15 02:03:59 +08:00
BEL,
WIRE,
PIP,
NET,
CELL
2018-06-15 02:03:59 +08:00
};
class ElementTreeItem : public QTreeWidgetItem
{
public:
2018-07-07 01:19:18 +08:00
ElementTreeItem(ElementType t, QString str, QTreeWidgetItem *parent)
: QTreeWidgetItem(parent, QStringList(str)), type(t)
{
}
2018-06-15 02:03:59 +08:00
virtual ~ElementTreeItem(){};
ElementType getType() { return type; };
private:
ElementType type;
};
class IdStringTreeItem : public ElementTreeItem
2018-06-15 02:03:59 +08:00
{
public:
2018-07-07 01:19:18 +08:00
IdStringTreeItem(IdString d, ElementType t, QString str, QTreeWidgetItem *parent) : ElementTreeItem(t, str, parent)
{
this->data = d;
}
virtual ~IdStringTreeItem(){};
2018-06-15 02:03:59 +08:00
IdString getData() { return this->data; };
private:
IdString data;
};
2018-07-06 02:06:12 +08:00
DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), nets_root(nullptr), cells_root(nullptr)
2018-06-15 02:03:59 +08:00
{
treeWidget = new QTreeWidget();
// Add tree view
treeWidget->setColumnCount(1);
treeWidget->setHeaderLabel("Items");
2018-06-15 02:03:59 +08:00
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// Add property view
2018-07-06 14:15:39 +08:00
variantManager = new QtVariantPropertyManager(this);
2018-07-06 02:35:47 +08:00
readOnlyManager = new QtVariantPropertyManager(this);
2018-07-06 03:51:17 +08:00
groupManager = new QtGroupPropertyManager(this);
2018-07-06 14:15:39 +08:00
variantFactory = new QtVariantEditorFactory(this);
propertyEditor = new QtTreePropertyBrowser(this);
2018-06-15 02:03:59 +08:00
propertyEditor->setFactoryForManager(variantManager, variantFactory);
propertyEditor->setPropertiesWithoutValueMarked(true);
propertyEditor->show();
const QIcon searchIcon(":/icons/resources/zoom.png");
QLineEdit* lineEdit = new QLineEdit();
lineEdit->setClearButtonEnabled(true);
lineEdit->addAction(searchIcon, QLineEdit::LeadingPosition);
lineEdit->setPlaceholderText("Search...");
QAction *actionFirst = new QAction("", this);
QIcon iconFirst(QStringLiteral(":/icons/resources/resultset_first.png"));
actionFirst->setIcon(iconFirst);
QAction *actionPrev = new QAction("", this);
QIcon iconPrev(QStringLiteral(":/icons/resources/resultset_previous.png"));
actionPrev->setIcon(iconPrev);
QAction *actionNext = new QAction("", this);
QIcon iconNext(QStringLiteral(":/icons/resources/resultset_next.png"));
actionNext->setIcon(iconNext);
QAction *actionLast = new QAction("", this);
QIcon iconLast(QStringLiteral(":/icons/resources/resultset_last.png"));
actionLast->setIcon(iconLast);
QToolBar *toolbar = new QToolBar();
toolbar->addAction(actionFirst);
toolbar->addAction(actionPrev);
toolbar->addAction(actionNext);
toolbar->addAction(actionLast);
2018-07-12 00:15:25 +08:00
QWidget *topWidget = new QWidget();
QVBoxLayout *vbox1 = new QVBoxLayout();
topWidget->setLayout(vbox1);
vbox1->setSpacing(5);
vbox1->setContentsMargins(0, 0, 0, 0);
vbox1->addWidget(lineEdit);
vbox1->addWidget(treeWidget);
QWidget *toolbarWidget = new QWidget();
QHBoxLayout *hbox = new QHBoxLayout;
hbox->setAlignment(Qt::AlignCenter);
toolbarWidget->setLayout(hbox);
2018-07-12 00:25:48 +08:00
hbox->setSpacing(0);
hbox->setContentsMargins(0, 0, 0, 0);
2018-07-12 00:15:25 +08:00
hbox->addWidget(toolbar);
QWidget *btmWidget = new QWidget();
QVBoxLayout *vbox2 = new QVBoxLayout();
btmWidget->setLayout(vbox2);
2018-07-12 00:25:48 +08:00
vbox2->setSpacing(0);
2018-07-12 00:15:25 +08:00
vbox2->setContentsMargins(0, 0, 0, 0);
vbox2->addWidget(toolbarWidget);
vbox2->addWidget(propertyEditor);
2018-06-15 02:03:59 +08:00
QSplitter *splitter = new QSplitter(Qt::Vertical);
2018-07-12 00:15:25 +08:00
splitter->addWidget(topWidget);
splitter->addWidget(btmWidget);
2018-06-15 02:03:59 +08:00
QGridLayout *mainLayout = new QGridLayout();
2018-06-15 02:24:05 +08:00
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
2018-06-15 02:03:59 +08:00
mainLayout->addWidget(splitter);
setLayout(mainLayout);
// Connection
2018-06-23 22:06:49 +08:00
connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, &DesignWidget::prepareMenu);
2018-06-15 02:03:59 +08:00
2018-06-23 22:06:49 +08:00
connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), SLOT(onItemClicked(QTreeWidgetItem *, int)));
2018-06-15 02:03:59 +08:00
}
2018-07-07 01:19:18 +08:00
DesignWidget::~DesignWidget() {}
2018-06-15 02:03:59 +08:00
2018-06-26 21:47:22 +08:00
void DesignWidget::newContext(Context *ctx)
{
treeWidget->clear();
this->ctx = ctx;
// Add bels to tree
QTreeWidgetItem *bel_root = new QTreeWidgetItem(treeWidget);
QMap<QString, QTreeWidgetItem *> bel_items;
bel_root->setText(0, "Bels");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, bel_root);
2018-06-29 00:06:31 +08:00
if (ctx) {
2018-06-26 21:47:22 +08:00
for (auto bel : ctx->getBels()) {
auto id = ctx->getBelName(bel);
QStringList items = QString(id.c_str(ctx)).split("/");
QString name;
QTreeWidgetItem *parent = nullptr;
2018-07-07 01:19:18 +08:00
for (int i = 0; i < items.size(); i++) {
if (!name.isEmpty())
name += "/";
name += items.at(i);
if (!bel_items.contains(name)) {
2018-07-07 01:19:18 +08:00
if (i == items.size() - 1)
bel_items.insert(name, new IdStringTreeItem(id, ElementType::BEL, items.at(i), parent));
else
2018-07-07 01:19:18 +08:00
bel_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
}
parent = bel_items[name];
}
2018-06-26 21:47:22 +08:00
}
}
2018-07-07 01:19:18 +08:00
for (auto bel : bel_items.toStdMap()) {
bel_root->addChild(bel.second);
}
2018-06-26 21:47:22 +08:00
// Add wires to tree
QTreeWidgetItem *wire_root = new QTreeWidgetItem(treeWidget);
QMap<QString, QTreeWidgetItem *> wire_items;
wire_root->setText(0, "Wires");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, wire_root);
2018-06-29 00:06:31 +08:00
if (ctx) {
2018-06-26 21:47:22 +08:00
for (auto wire : ctx->getWires()) {
auto id = ctx->getWireName(wire);
QStringList items = QString(id.c_str(ctx)).split("/");
QString name;
QTreeWidgetItem *parent = nullptr;
2018-07-07 01:19:18 +08:00
for (int i = 0; i < items.size(); i++) {
if (!name.isEmpty())
name += "/";
name += items.at(i);
if (!wire_items.contains(name)) {
2018-07-07 01:19:18 +08:00
if (i == items.size() - 1)
wire_items.insert(name, new IdStringTreeItem(id, ElementType::WIRE, items.at(i), parent));
else
2018-07-07 01:19:18 +08:00
wire_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
}
parent = wire_items[name];
}
2018-06-26 21:47:22 +08:00
}
}
2018-07-07 01:19:18 +08:00
for (auto wire : wire_items.toStdMap()) {
wire_root->addChild(wire.second);
}
2018-06-26 21:47:22 +08:00
// Add pips to tree
QTreeWidgetItem *pip_root = new QTreeWidgetItem(treeWidget);
QMap<QString, QTreeWidgetItem *> pip_items;
pip_root->setText(0, "Pips");
2018-06-26 21:47:22 +08:00
treeWidget->insertTopLevelItem(0, pip_root);
2018-06-29 00:06:31 +08:00
if (ctx) {
2018-06-26 21:47:22 +08:00
for (auto pip : ctx->getPips()) {
auto id = ctx->getPipName(pip);
QStringList items = QString(id.c_str(ctx)).split("/");
QString name;
QTreeWidgetItem *parent = nullptr;
2018-07-07 01:19:18 +08:00
for (int i = 0; i < items.size(); i++) {
if (!name.isEmpty())
name += "/";
name += items.at(i);
if (!pip_items.contains(name)) {
2018-07-07 01:19:18 +08:00
if (i == items.size() - 1)
pip_items.insert(name, new IdStringTreeItem(id, ElementType::PIP, items.at(i), parent));
else
2018-07-07 01:19:18 +08:00
pip_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
}
parent = pip_items[name];
}
2018-06-26 21:47:22 +08:00
}
}
2018-07-07 01:19:18 +08:00
for (auto pip : pip_items.toStdMap()) {
pip_root->addChild(pip.second);
}
2018-07-06 02:06:12 +08:00
// Add nets to tree
nets_root = new QTreeWidgetItem(treeWidget);
nets_root->setText(0, "Nets");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, nets_root);
2018-07-06 02:06:12 +08:00
// Add cells to tree
cells_root = new QTreeWidgetItem(treeWidget);
cells_root->setText(0, "Cells");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, cells_root);
2018-07-06 02:06:12 +08:00
}
void DesignWidget::updateTree()
{
2018-07-06 03:51:17 +08:00
clearProperties();
2018-07-06 02:06:12 +08:00
delete nets_root;
delete cells_root;
// Add nets to tree
nets_root = new QTreeWidgetItem(treeWidget);
QMap<QString, QTreeWidgetItem *> nets_items;
nets_root->setText(0, "Nets");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, nets_root);
2018-07-06 02:06:12 +08:00
if (ctx) {
2018-07-07 01:19:18 +08:00
for (auto &item : ctx->nets) {
2018-07-06 02:06:12 +08:00
auto id = item.first;
QString name = QString(id.c_str(ctx));
nets_items.insert(name, new IdStringTreeItem(id, ElementType::NET, name, nullptr));
2018-07-06 02:06:12 +08:00
}
}
2018-07-07 01:19:18 +08:00
for (auto item : nets_items.toStdMap()) {
2018-07-06 02:06:12 +08:00
nets_root->addChild(item.second);
2018-07-07 01:19:18 +08:00
}
2018-07-06 02:06:12 +08:00
// Add cells to tree
cells_root = new QTreeWidgetItem(treeWidget);
QMap<QString, QTreeWidgetItem *> cells_items;
cells_root->setText(0, "Cells");
2018-07-07 01:19:18 +08:00
treeWidget->insertTopLevelItem(0, cells_root);
2018-07-06 02:06:12 +08:00
if (ctx) {
2018-07-07 01:19:18 +08:00
for (auto &item : ctx->cells) {
2018-07-06 02:06:12 +08:00
auto id = item.first;
QString name = QString(id.c_str(ctx));
2018-07-07 01:19:18 +08:00
cells_items.insert(name, new IdStringTreeItem(id, ElementType::CELL, name, nullptr));
2018-07-06 02:06:12 +08:00
}
}
2018-07-07 01:19:18 +08:00
for (auto item : cells_items.toStdMap()) {
2018-07-06 02:06:12 +08:00
cells_root->addChild(item.second);
2018-07-07 01:19:18 +08:00
}
2018-06-26 21:47:22 +08:00
}
2018-07-06 03:51:17 +08:00
void DesignWidget::addProperty(QtProperty *property, const QString &id)
2018-06-15 02:03:59 +08:00
{
propertyToId[property] = id;
idToProperty[id] = property;
2018-06-21 03:01:09 +08:00
propertyEditor->addProperty(property);
2018-06-15 02:03:59 +08:00
}
void DesignWidget::clearProperties()
{
2018-06-23 22:06:49 +08:00
QMap<QtProperty *, QString>::ConstIterator itProp = propertyToId.constBegin();
2018-06-15 02:03:59 +08:00
while (itProp != propertyToId.constEnd()) {
delete itProp.key();
itProp++;
}
propertyToId.clear();
idToProperty.clear();
}
void DesignWidget::onItemClicked(QTreeWidgetItem *clickItem, int pos)
2018-06-15 02:03:59 +08:00
{
if (!clickItem->parent())
2018-06-15 02:03:59 +08:00
return;
ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
if (type == ElementType::NONE) {
return;
}
2018-07-07 01:19:18 +08:00
clearProperties();
2018-06-15 02:03:59 +08:00
if (type == ElementType::BEL) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
BelId bel = ctx->getBelByName(c);
2018-06-24 02:25:10 +08:00
QtProperty *topItem = groupManager->addProperty("Bel");
addProperty(topItem, "Bel");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(c.c_str(ctx));
topItem->addSubProperty(nameItem);
QtVariantProperty *typeItem = readOnlyManager->addProperty(QVariant::String, "Type");
typeItem->setValue(ctx->belTypeToId(ctx->getBelType(bel)).c_str(ctx));
topItem->addSubProperty(typeItem);
2018-06-24 02:25:10 +08:00
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available");
availItem->setValue(ctx->checkBelAvail(bel));
topItem->addSubProperty(availItem);
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Cell");
cellItem->setValue(ctx->getBoundBelCell(bel).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Cell");
conflictItem->setValue(ctx->getConflictingBelCell(bel).c_str(ctx));
topItem->addSubProperty(conflictItem);
2018-06-15 02:03:59 +08:00
} else if (type == ElementType::WIRE) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
WireId wire = ctx->getWireByName(c);
2018-06-15 02:03:59 +08:00
2018-07-07 01:19:18 +08:00
QtProperty *topItem = groupManager->addProperty("Wire");
addProperty(topItem, "Wire");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(c.c_str(ctx));
topItem->addSubProperty(nameItem);
2018-06-15 02:03:59 +08:00
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available");
availItem->setValue(ctx->checkWireAvail(wire));
topItem->addSubProperty(availItem);
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Net");
cellItem->setValue(ctx->getBoundWireNet(wire).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Net");
conflictItem->setValue(ctx->getConflictingWireNet(wire).c_str(ctx));
topItem->addSubProperty(conflictItem);
BelPin uphill = ctx->getBelPinUphill(wire);
QtProperty *belpinItem = groupManager->addProperty("BelPin Uphill");
topItem->addSubProperty(belpinItem);
QtVariantProperty *belUphillItem = readOnlyManager->addProperty(QVariant::String, "Bel");
if (uphill.bel != BelId())
belUphillItem->setValue(ctx->getBelName(uphill.bel).c_str(ctx));
else
belUphillItem->setValue("");
belpinItem->addSubProperty(belUphillItem);
QtVariantProperty *portUphillItem = readOnlyManager->addProperty(QVariant::String, "PortPin");
portUphillItem->setValue(ctx->portPinToId(uphill.pin).c_str(ctx));
belpinItem->addSubProperty(portUphillItem);
QtProperty *downhillItem = groupManager->addProperty("BelPins Downhill");
topItem->addSubProperty(downhillItem);
for (const auto &item : ctx->getBelPinsDownhill(wire)) {
QString belname = "";
if (item.bel != BelId())
belname = ctx->getBelName(item.bel).c_str(ctx);
QString pinname = ctx->portPinToId(item.pin).c_str(ctx);
QtProperty *dhItem = groupManager->addProperty(belname + "-" + pinname);
downhillItem->addSubProperty(dhItem);
QtVariantProperty *belItem = readOnlyManager->addProperty(QVariant::String, "Bel");
belItem->setValue(belname);
dhItem->addSubProperty(belItem);
QtVariantProperty *portItem = readOnlyManager->addProperty(QVariant::String, "PortPin");
portItem->setValue(pinname);
dhItem->addSubProperty(portItem);
}
QtProperty *pipsDownItem = groupManager->addProperty("Pips Downhill");
topItem->addSubProperty(pipsDownItem);
for (const auto &item : ctx->getPipsDownhill(wire)) {
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, "");
pipItem->setValue(ctx->getPipName(item).c_str(ctx));
pipsDownItem->addSubProperty(pipItem);
}
QtProperty *pipsUpItem = groupManager->addProperty("Pips Uphill");
topItem->addSubProperty(pipsUpItem);
for (const auto &item : ctx->getPipsUphill(wire)) {
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, "");
pipItem->setValue(ctx->getPipName(item).c_str(ctx));
pipsUpItem->addSubProperty(pipItem);
}
2018-06-15 02:03:59 +08:00
} else if (type == ElementType::PIP) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
PipId pip = ctx->getPipByName(c);
2018-07-07 01:19:18 +08:00
QtProperty *topItem = groupManager->addProperty("Pip");
addProperty(topItem, "Pip");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(c.c_str(ctx));
topItem->addSubProperty(nameItem);
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available");
availItem->setValue(ctx->checkPipAvail(pip));
topItem->addSubProperty(availItem);
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Net");
cellItem->setValue(ctx->getBoundPipNet(pip).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Net");
conflictItem->setValue(ctx->getConflictingPipNet(pip).c_str(ctx));
topItem->addSubProperty(conflictItem);
QtVariantProperty *srcWireItem = readOnlyManager->addProperty(QVariant::String, "Src Wire");
srcWireItem->setValue(ctx->getWireName(ctx->getPipSrcWire(pip)).c_str(ctx));
topItem->addSubProperty(srcWireItem);
QtVariantProperty *destWireItem = readOnlyManager->addProperty(QVariant::String, "Dest Wire");
destWireItem->setValue(ctx->getWireName(ctx->getPipDstWire(pip)).c_str(ctx));
topItem->addSubProperty(destWireItem);
DelayInfo delay = ctx->getPipDelay(pip);
QtProperty *delayItem = groupManager->addProperty("Delay");
topItem->addSubProperty(delayItem);
QtVariantProperty *raiseDelayItem = readOnlyManager->addProperty(QVariant::Double, "Raise");
raiseDelayItem->setValue(delay.raiseDelay());
delayItem->addSubProperty(raiseDelayItem);
QtVariantProperty *fallDelayItem = readOnlyManager->addProperty(QVariant::Double, "Fall");
fallDelayItem->setValue(delay.fallDelay());
delayItem->addSubProperty(fallDelayItem);
QtVariantProperty *avgDelayItem = readOnlyManager->addProperty(QVariant::Double, "Average");
avgDelayItem->setValue(delay.avgDelay());
delayItem->addSubProperty(avgDelayItem);
} else if (type == ElementType::NET) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
2018-07-06 03:51:17 +08:00
NetInfo *net = ctx->nets.at(c).get();
2018-07-07 01:19:18 +08:00
QtProperty *topItem = groupManager->addProperty("Net");
addProperty(topItem, "Net");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(net->name.c_str(ctx));
topItem->addSubProperty(nameItem);
2018-07-07 01:19:18 +08:00
QtProperty *driverItem = groupManager->addProperty("Driver");
topItem->addSubProperty(driverItem);
QtVariantProperty *portItem = readOnlyManager->addProperty(QVariant::String, "Port");
portItem->setValue(net->driver.port.c_str(ctx));
driverItem->addSubProperty(portItem);
2018-07-07 01:19:18 +08:00
QtVariantProperty *budgetItem = readOnlyManager->addProperty(QVariant::Double, "Budget");
2018-07-06 03:51:17 +08:00
budgetItem->setValue(net->driver.budget);
driverItem->addSubProperty(budgetItem);
2018-07-06 03:51:17 +08:00
2018-07-07 01:19:18 +08:00
QtVariantProperty *cellNameItem = readOnlyManager->addProperty(QVariant::String, "Cell");
if (net->driver.cell)
cellNameItem->setValue(net->driver.cell->name.c_str(ctx));
else
cellNameItem->setValue("");
driverItem->addSubProperty(cellNameItem);
QtProperty *usersItem = groupManager->addProperty("Users");
topItem->addSubProperty(usersItem);
2018-07-07 01:19:18 +08:00
for (auto &item : net->users) {
QtProperty *portItem = groupManager->addProperty(item.port.c_str(ctx));
usersItem->addSubProperty(portItem);
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Port");
nameItem->setValue(item.port.c_str(ctx));
portItem->addSubProperty(nameItem);
QtVariantProperty *budgetItem = readOnlyManager->addProperty(QVariant::Double, "Budget");
budgetItem->setValue(item.budget);
portItem->addSubProperty(budgetItem);
QtVariantProperty *userItem = readOnlyManager->addProperty(QVariant::String, "Cell");
if (item.cell)
userItem->setValue(item.cell->name.c_str(ctx));
else
userItem->setValue("");
portItem->addSubProperty(userItem);
}
2018-07-06 03:51:17 +08:00
2018-07-07 01:19:18 +08:00
QtProperty *attrsItem = groupManager->addProperty("Attributes");
topItem->addSubProperty(attrsItem);
2018-07-07 01:19:18 +08:00
for (auto &item : net->attrs) {
QtVariantProperty *attrItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx));
attrItem->setValue(item.second.c_str());
attrsItem->addSubProperty(attrItem);
}
2018-07-06 03:51:17 +08:00
2018-07-07 01:19:18 +08:00
QtProperty *wiresItem = groupManager->addProperty("Wires");
topItem->addSubProperty(wiresItem);
2018-07-07 01:19:18 +08:00
for (auto &item : net->wires) {
auto name = ctx->getWireName(item.first).c_str(ctx);
2018-07-07 01:19:18 +08:00
QtProperty *wireItem = groupManager->addProperty(name);
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(name);
wireItem->addSubProperty(nameItem);
2018-07-07 01:19:18 +08:00
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, "Pip");
2018-07-07 01:19:18 +08:00
if (item.second.pip != PipId())
pipItem->setValue(ctx->getPipName(item.second.pip).c_str(ctx));
else
pipItem->setValue("");
wireItem->addSubProperty(pipItem);
QtVariantProperty *strengthItem = readOnlyManager->addProperty(QVariant::Int, "Strength");
strengthItem->setValue((int)item.second.strength);
wireItem->addSubProperty(strengthItem);
2018-07-07 01:19:18 +08:00
wiresItem->addSubProperty(wireItem);
}
2018-07-06 03:51:17 +08:00
} else if (type == ElementType::CELL) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
CellInfo *cell = ctx->cells.at(c).get();
2018-07-06 03:51:17 +08:00
2018-07-07 01:19:18 +08:00
QtProperty *topItem = groupManager->addProperty("Cell");
addProperty(topItem, "Cell");
2018-07-06 03:51:17 +08:00
QtVariantProperty *cellNameItem = readOnlyManager->addProperty(QVariant::String, "Name");
cellNameItem->setValue(cell->name.c_str(ctx));
topItem->addSubProperty(cellNameItem);
2018-07-06 03:51:17 +08:00
QtVariantProperty *cellTypeItem = readOnlyManager->addProperty(QVariant::String, "Type");
cellTypeItem->setValue(cell->type.c_str(ctx));
topItem->addSubProperty(cellTypeItem);
2018-07-07 01:19:18 +08:00
QtVariantProperty *cellBelItem = readOnlyManager->addProperty(QVariant::String, "Bel");
2018-07-07 01:19:18 +08:00
if (cell->bel != BelId())
cellBelItem->setValue(ctx->getBelName(cell->bel).c_str(ctx));
else
cellBelItem->setValue("");
topItem->addSubProperty(cellBelItem);
QtVariantProperty *cellBelStrItem = readOnlyManager->addProperty(QVariant::Int, "Bel strength");
cellBelStrItem->setValue(int(cell->belStrength));
topItem->addSubProperty(cellBelStrItem);
QtProperty *cellPortsItem = groupManager->addProperty("Ports");
topItem->addSubProperty(cellPortsItem);
2018-07-07 01:19:18 +08:00
for (auto &item : cell->ports) {
PortInfo p = item.second;
2018-07-07 01:19:18 +08:00
QtProperty *portInfoItem = groupManager->addProperty(p.name.c_str(ctx));
QtVariantProperty *portInfoNameItem = readOnlyManager->addProperty(QVariant::String, "Name");
portInfoNameItem->setValue(p.name.c_str(ctx));
portInfoItem->addSubProperty(portInfoNameItem);
QtVariantProperty *portInfoTypeItem = readOnlyManager->addProperty(QVariant::Int, "Type");
portInfoTypeItem->setValue(int(p.type));
portInfoItem->addSubProperty(portInfoTypeItem);
QtVariantProperty *portInfoNetItem = readOnlyManager->addProperty(QVariant::String, "Net");
if (p.net)
portInfoNetItem->setValue(p.net->name.c_str(ctx));
2018-07-07 01:19:18 +08:00
else
portInfoNetItem->setValue("");
portInfoItem->addSubProperty(portInfoNetItem);
cellPortsItem->addSubProperty(portInfoItem);
}
2018-07-06 03:51:17 +08:00
QtProperty *cellAttrItem = groupManager->addProperty("Attributes");
topItem->addSubProperty(cellAttrItem);
2018-07-07 01:19:18 +08:00
for (auto &item : cell->attrs) {
QtVariantProperty *attrItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx));
attrItem->setValue(item.second.c_str());
cellAttrItem->addSubProperty(attrItem);
}
2018-07-06 03:51:17 +08:00
QtProperty *cellParamsItem = groupManager->addProperty("Parameters");
topItem->addSubProperty(cellParamsItem);
2018-07-07 01:19:18 +08:00
for (auto &item : cell->params) {
QtVariantProperty *paramItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx));
paramItem->setValue(item.second.c_str());
cellParamsItem->addSubProperty(paramItem);
2018-07-06 03:51:17 +08:00
}
QtProperty *cellPinsItem = groupManager->addProperty("Pins");
topItem->addSubProperty(cellPinsItem);
2018-07-07 01:19:18 +08:00
for (auto &item : cell->pins) {
std::string cell_port = item.first.c_str(ctx);
std::string bel_pin = item.second.c_str(ctx);
QtProperty *pinGroupItem = groupManager->addProperty((cell_port + " -> " + bel_pin).c_str());
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Cell");
cellItem->setValue(cell_port.c_str());
pinGroupItem->addSubProperty(cellItem);
QtVariantProperty *belItem = readOnlyManager->addProperty(QVariant::String, "Bel");
belItem->setValue(bel_pin.c_str());
pinGroupItem->addSubProperty(belItem);
cellPinsItem->addSubProperty(pinGroupItem);
2018-07-07 01:19:18 +08:00
}
2018-06-15 02:03:59 +08:00
}
}
void DesignWidget::prepareMenu(const QPoint &pos)
{
QTreeWidget *tree = treeWidget;
itemContextMenu = tree->itemAt(pos);
QAction *selectAction = new QAction("&Select", this);
selectAction->setStatusTip("Select item on view");
2018-06-15 17:10:11 +08:00
2018-06-15 02:03:59 +08:00
connect(selectAction, SIGNAL(triggered()), this, SLOT(selectObject()));
QMenu menu(this);
menu.addAction(selectAction);
menu.exec(tree->mapToGlobal(pos));
}
2018-06-23 22:06:49 +08:00
void DesignWidget::selectObject() { Q_EMIT info("selected " + itemContextMenu->text(0).toStdString() + "\n"); }
2018-06-22 19:10:27 +08:00
NEXTPNR_NAMESPACE_END