Merge branch 'master' of gitlab.com:SymbioticEDA/nextpnr
This commit is contained in:
commit
44726a1785
@ -86,6 +86,7 @@ BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, QWidget *parent
|
|||||||
connect(fpgaView, SIGNAL(clickedBel(BelId, bool)), designview, SLOT(onClickedBel(BelId, bool)));
|
connect(fpgaView, SIGNAL(clickedBel(BelId, bool)), designview, SLOT(onClickedBel(BelId, bool)));
|
||||||
connect(fpgaView, SIGNAL(clickedWire(WireId, bool)), designview, SLOT(onClickedWire(WireId, bool)));
|
connect(fpgaView, SIGNAL(clickedWire(WireId, bool)), designview, SLOT(onClickedWire(WireId, bool)));
|
||||||
connect(fpgaView, SIGNAL(clickedPip(PipId, bool)), designview, SLOT(onClickedPip(PipId, bool)));
|
connect(fpgaView, SIGNAL(clickedPip(PipId, bool)), designview, SLOT(onClickedPip(PipId, bool)));
|
||||||
|
connect(designview, SIGNAL(zoomSelected()), fpgaView, SLOT(zoomSelected()));
|
||||||
|
|
||||||
connect(designview, SIGNAL(highlight(std::vector<DecalXY>, int)), fpgaView,
|
connect(designview, SIGNAL(highlight(std::vector<DecalXY>, int)), fpgaView,
|
||||||
SLOT(onHighlightGroupChanged(std::vector<DecalXY>, int)));
|
SLOT(onHighlightGroupChanged(std::vector<DecalXY>, int)));
|
||||||
|
@ -30,48 +30,14 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class ElementTreeItem : public QTreeWidgetItem
|
DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), selectionModel(nullptr)
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
ElementTreeItem(ElementType t, QString str, QTreeWidgetItem *parent)
|
|
||||||
: QTreeWidgetItem(parent, QStringList(str)), type(t)
|
|
||||||
{
|
|
||||||
this->setFlags(this->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
}
|
|
||||||
virtual ~ElementTreeItem(){};
|
|
||||||
|
|
||||||
ElementType getType() { return type; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
ElementType type;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IdStringTreeItem : public ElementTreeItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IdStringTreeItem(IdString d, ElementType t, QString str, QTreeWidgetItem *parent) : ElementTreeItem(t, str, parent)
|
|
||||||
{
|
|
||||||
this->setFlags(this->flags() | Qt::ItemIsSelectable);
|
|
||||||
this->data = d;
|
|
||||||
}
|
|
||||||
virtual ~IdStringTreeItem(){};
|
|
||||||
|
|
||||||
IdString getData() { return this->data; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
IdString data;
|
|
||||||
};
|
|
||||||
|
|
||||||
DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), nets_root(nullptr), cells_root(nullptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
treeWidget = new QTreeWidget();
|
|
||||||
|
|
||||||
// Add tree view
|
// Add tree view
|
||||||
treeWidget->setColumnCount(1);
|
treeView = new QTreeView();
|
||||||
treeWidget->setHeaderLabel("Items");
|
treeModel = new ContextTreeModel();
|
||||||
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
treeView->setModel(treeModel);
|
||||||
treeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
|
||||||
// Add property view
|
// Add property view
|
||||||
variantManager = new QtVariantPropertyManager(this);
|
variantManager = new QtVariantPropertyManager(this);
|
||||||
@ -96,7 +62,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
connect(actionFirst, &QAction::triggered, this, [this] {
|
connect(actionFirst, &QAction::triggered, this, [this] {
|
||||||
history_ignore = true;
|
history_ignore = true;
|
||||||
history_index = 0;
|
history_index = 0;
|
||||||
treeWidget->setCurrentItem(history.at(history_index));
|
selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -106,7 +72,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
connect(actionPrev, &QAction::triggered, this, [this] {
|
connect(actionPrev, &QAction::triggered, this, [this] {
|
||||||
history_ignore = true;
|
history_ignore = true;
|
||||||
history_index--;
|
history_index--;
|
||||||
treeWidget->setCurrentItem(history.at(history_index));
|
selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -116,7 +82,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
connect(actionNext, &QAction::triggered, this, [this] {
|
connect(actionNext, &QAction::triggered, this, [this] {
|
||||||
history_ignore = true;
|
history_ignore = true;
|
||||||
history_index++;
|
history_index++;
|
||||||
treeWidget->setCurrentItem(history.at(history_index));
|
selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -126,7 +92,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
connect(actionLast, &QAction::triggered, this, [this] {
|
connect(actionLast, &QAction::triggered, this, [this] {
|
||||||
history_ignore = true;
|
history_ignore = true;
|
||||||
history_index = int(history.size() - 1);
|
history_index = int(history.size() - 1);
|
||||||
treeWidget->setCurrentItem(history.at(history_index));
|
selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -136,11 +102,11 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
connect(actionClear, &QAction::triggered, this, [this] {
|
connect(actionClear, &QAction::triggered, this, [this] {
|
||||||
history_index = -1;
|
history_index = -1;
|
||||||
history.clear();
|
history.clear();
|
||||||
QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0);
|
QModelIndex index = selectionModel->selectedIndexes().at(0);
|
||||||
if (clickItem->parent()) {
|
if (index.isValid()) {
|
||||||
ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
|
ElementType type = treeModel->nodeFromIndex(index)->type();
|
||||||
if (type != ElementType::NONE)
|
if (type != ElementType::NONE)
|
||||||
addToHistory(treeWidget->selectedItems().at(0));
|
addToHistory(index);
|
||||||
}
|
}
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
@ -158,7 +124,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
vbox1->setSpacing(5);
|
vbox1->setSpacing(5);
|
||||||
vbox1->setContentsMargins(0, 0, 0, 0);
|
vbox1->setContentsMargins(0, 0, 0, 0);
|
||||||
vbox1->addWidget(lineEdit);
|
vbox1->addWidget(lineEdit);
|
||||||
vbox1->addWidget(treeWidget);
|
vbox1->addWidget(treeView);
|
||||||
|
|
||||||
QWidget *toolbarWidget = new QWidget();
|
QWidget *toolbarWidget = new QWidget();
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
@ -192,8 +158,11 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
|
|||||||
&DesignWidget::prepareMenuProperty);
|
&DesignWidget::prepareMenuProperty);
|
||||||
connect(propertyEditor->treeWidget(), &QTreeWidget::itemDoubleClicked, this, &DesignWidget::onItemDoubleClicked);
|
connect(propertyEditor->treeWidget(), &QTreeWidget::itemDoubleClicked, this, &DesignWidget::onItemDoubleClicked);
|
||||||
|
|
||||||
connect(treeWidget, SIGNAL(itemSelectionChanged()), SLOT(onItemSelectionChanged()));
|
connect(treeView, &QTreeView::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
|
||||||
connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
|
connect(treeView, &QTreeView::doubleClicked, this, &DesignWidget::onDoubleClicked);
|
||||||
|
selectionModel = treeView->selectionModel();
|
||||||
|
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
|
||||||
|
SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
|
||||||
|
|
||||||
history_index = -1;
|
history_index = -1;
|
||||||
history_ignore = false;
|
history_ignore = false;
|
||||||
@ -219,7 +188,7 @@ void DesignWidget::updateButtons()
|
|||||||
actionLast->setEnabled(history_index < (count - 1));
|
actionLast->setEnabled(history_index < (count - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::addToHistory(QTreeWidgetItem *item)
|
void DesignWidget::addToHistory(QModelIndex item)
|
||||||
{
|
{
|
||||||
if (!history_ignore) {
|
if (!history_ignore) {
|
||||||
int count = int(history.size());
|
int count = int(history.size());
|
||||||
@ -234,194 +203,38 @@ void DesignWidget::addToHistory(QTreeWidgetItem *item)
|
|||||||
|
|
||||||
void DesignWidget::newContext(Context *ctx)
|
void DesignWidget::newContext(Context *ctx)
|
||||||
{
|
{
|
||||||
|
if (!ctx)
|
||||||
|
return;
|
||||||
|
|
||||||
highlightSelected.clear();
|
highlightSelected.clear();
|
||||||
treeWidget->clear();
|
|
||||||
// reset pointers since they are not valid after clear
|
|
||||||
nets_root = nullptr;
|
|
||||||
cells_root = nullptr;
|
|
||||||
history_ignore = false;
|
history_ignore = false;
|
||||||
history_index = -1;
|
history_index = -1;
|
||||||
history.clear();
|
history.clear();
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
highlightSelected.clear();
|
||||||
nameToItem[i].clear();
|
|
||||||
|
|
||||||
this->ctx = ctx;
|
this->ctx = ctx;
|
||||||
|
treeModel->loadData(ctx);
|
||||||
// Add bels to tree
|
|
||||||
QTreeWidgetItem *bel_root = new QTreeWidgetItem(treeWidget);
|
|
||||||
QMap<QString, QTreeWidgetItem *> bel_items;
|
|
||||||
bel_root->setText(0, "Bels");
|
|
||||||
bel_root->setFlags(bel_root->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
treeWidget->insertTopLevelItem(0, bel_root);
|
|
||||||
if (ctx) {
|
|
||||||
for (auto bel : ctx->getBels()) {
|
|
||||||
auto id = ctx->getBelName(bel);
|
|
||||||
QStringList items = QString(id.c_str(ctx)).split("/");
|
|
||||||
QString name;
|
|
||||||
QTreeWidgetItem *parent = nullptr;
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
if (!name.isEmpty())
|
|
||||||
name += "/";
|
|
||||||
name += items.at(i);
|
|
||||||
if (!bel_items.contains(name)) {
|
|
||||||
if (i == items.size() - 1)
|
|
||||||
nameToItem[0].insert(name, new IdStringTreeItem(id, ElementType::BEL, items.at(i), parent));
|
|
||||||
else
|
|
||||||
bel_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
|
|
||||||
}
|
|
||||||
parent = bel_items[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto bel : bel_items.toStdMap()) {
|
|
||||||
bel_root->addChild(bel.second);
|
|
||||||
}
|
|
||||||
for (auto bel : nameToItem[0].toStdMap()) {
|
|
||||||
bel_root->addChild(bel.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add wires to tree
|
|
||||||
QTreeWidgetItem *wire_root = new QTreeWidgetItem(treeWidget);
|
|
||||||
QMap<QString, QTreeWidgetItem *> wire_items;
|
|
||||||
wire_root->setText(0, "Wires");
|
|
||||||
wire_root->setFlags(wire_root->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
treeWidget->insertTopLevelItem(0, wire_root);
|
|
||||||
if (ctx) {
|
|
||||||
for (auto wire : ctx->getWires()) {
|
|
||||||
auto id = ctx->getWireName(wire);
|
|
||||||
QStringList items = QString(id.c_str(ctx)).split("/");
|
|
||||||
QString name;
|
|
||||||
QTreeWidgetItem *parent = nullptr;
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
if (!name.isEmpty())
|
|
||||||
name += "/";
|
|
||||||
name += items.at(i);
|
|
||||||
if (!wire_items.contains(name)) {
|
|
||||||
if (i == items.size() - 1)
|
|
||||||
nameToItem[1].insert(name, new IdStringTreeItem(id, ElementType::WIRE, items.at(i), parent));
|
|
||||||
else
|
|
||||||
wire_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
|
|
||||||
}
|
|
||||||
parent = wire_items[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto wire : wire_items.toStdMap()) {
|
|
||||||
wire_root->addChild(wire.second);
|
|
||||||
}
|
|
||||||
for (auto wire : nameToItem[1].toStdMap()) {
|
|
||||||
wire_root->addChild(wire.second);
|
|
||||||
}
|
|
||||||
// Add pips to tree
|
|
||||||
QTreeWidgetItem *pip_root = new QTreeWidgetItem(treeWidget);
|
|
||||||
QMap<QString, QTreeWidgetItem *> pip_items;
|
|
||||||
pip_root->setText(0, "Pips");
|
|
||||||
pip_root->setFlags(pip_root->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
treeWidget->insertTopLevelItem(0, pip_root);
|
|
||||||
#ifndef ARCH_ECP5
|
|
||||||
if (ctx) {
|
|
||||||
for (auto pip : ctx->getPips()) {
|
|
||||||
auto id = ctx->getPipName(pip);
|
|
||||||
QStringList items = QString(id.c_str(ctx)).split("/");
|
|
||||||
QString name;
|
|
||||||
QTreeWidgetItem *parent = nullptr;
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
if (!name.isEmpty())
|
|
||||||
name += "/";
|
|
||||||
name += items.at(i);
|
|
||||||
if (!pip_items.contains(name)) {
|
|
||||||
if (i == items.size() - 1)
|
|
||||||
nameToItem[2].insert(name, new IdStringTreeItem(id, ElementType::PIP, items.at(i), parent));
|
|
||||||
else
|
|
||||||
pip_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
|
|
||||||
}
|
|
||||||
parent = pip_items[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto pip : pip_items.toStdMap()) {
|
|
||||||
pip_root->addChild(pip.second);
|
|
||||||
}
|
|
||||||
for (auto pip : nameToItem[2].toStdMap()) {
|
|
||||||
pip_root->addChild(pip.second);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nets_root = new QTreeWidgetItem(treeWidget);
|
|
||||||
nets_root->setText(0, "Nets");
|
|
||||||
nets_root->setFlags(nets_root->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
treeWidget->insertTopLevelItem(0, nets_root);
|
|
||||||
|
|
||||||
cells_root = new QTreeWidgetItem(treeWidget);
|
|
||||||
cells_root->setText(0, "Cells");
|
|
||||||
cells_root->setFlags(cells_root->flags() & ~Qt::ItemIsSelectable);
|
|
||||||
treeWidget->insertTopLevelItem(0, cells_root);
|
|
||||||
|
|
||||||
updateTree();
|
updateTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::updateTree()
|
void DesignWidget::updateTree()
|
||||||
{
|
{
|
||||||
if (!ctx)
|
|
||||||
return;
|
|
||||||
|
|
||||||
clearProperties();
|
clearProperties();
|
||||||
|
|
||||||
// treeWidget->setSortingEnabled(false);
|
QMap<ContextTreeItem *, int>::iterator i = highlightSelected.begin();
|
||||||
|
while (i != highlightSelected.end()) {
|
||||||
// Remove nets not existing any more
|
QMap<ContextTreeItem *, int>::iterator prev = i;
|
||||||
QMap<QString, QTreeWidgetItem *>::iterator i = nameToItem[3].begin();
|
|
||||||
while (i != nameToItem[3].end()) {
|
|
||||||
QMap<QString, QTreeWidgetItem *>::iterator prev = i;
|
|
||||||
++i;
|
++i;
|
||||||
if (ctx->nets.find(ctx->id(prev.key().toStdString())) == ctx->nets.end()) {
|
if (prev.key()->type() == ElementType::NET && ctx->nets.find(prev.key()->id()) == ctx->nets.end()) {
|
||||||
if (treeWidget->currentItem() == prev.value())
|
highlightSelected.erase(prev);
|
||||||
treeWidget->setCurrentItem(nets_root);
|
|
||||||
if (highlightSelected.contains(prev.value()))
|
|
||||||
highlightSelected.remove(prev.value());
|
|
||||||
delete prev.value();
|
|
||||||
nameToItem[3].erase(prev);
|
|
||||||
}
|
}
|
||||||
}
|
if (prev.key()->type() == ElementType::CELL && ctx->cells.find(prev.key()->id()) == ctx->cells.end()) {
|
||||||
// Add nets to tree
|
highlightSelected.erase(prev);
|
||||||
for (auto &item : ctx->nets) {
|
|
||||||
auto id = item.first;
|
|
||||||
QString name = QString(id.c_str(ctx));
|
|
||||||
if (!nameToItem[3].contains(name)) {
|
|
||||||
IdStringTreeItem *newItem = new IdStringTreeItem(id, ElementType::NET, name, nullptr);
|
|
||||||
nets_root->addChild(newItem);
|
|
||||||
nameToItem[3].insert(name, newItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove cells not existing any more
|
treeModel->updateData(ctx);
|
||||||
i = nameToItem[4].begin();
|
|
||||||
while (i != nameToItem[4].end()) {
|
|
||||||
QMap<QString, QTreeWidgetItem *>::iterator prev = i;
|
|
||||||
++i;
|
|
||||||
if (ctx->cells.find(ctx->id(prev.key().toStdString())) == ctx->cells.end()) {
|
|
||||||
if (treeWidget->currentItem() == prev.value())
|
|
||||||
treeWidget->setCurrentItem(cells_root);
|
|
||||||
if (highlightSelected.contains(prev.value()))
|
|
||||||
highlightSelected.remove(prev.value());
|
|
||||||
delete prev.value();
|
|
||||||
nameToItem[4].erase(prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add cells to tree
|
|
||||||
for (auto &item : ctx->cells) {
|
|
||||||
auto id = item.first;
|
|
||||||
QString name = QString(id.c_str(ctx));
|
|
||||||
if (!nameToItem[4].contains(name)) {
|
|
||||||
IdStringTreeItem *newItem = new IdStringTreeItem(id, ElementType::CELL, name, nullptr);
|
|
||||||
cells_root->addChild(newItem);
|
|
||||||
nameToItem[4].insert(name, newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// treeWidget->sortByColumn(0, Qt::AscendingOrder);
|
|
||||||
// treeWidget->setSortingEnabled(true);
|
|
||||||
}
|
}
|
||||||
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
|
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
|
||||||
{
|
{
|
||||||
@ -460,21 +273,6 @@ QString DesignWidget::getElementTypeName(ElementType type)
|
|||||||
return "CELL";
|
return "CELL";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int DesignWidget::getElementIndex(ElementType type)
|
|
||||||
{
|
|
||||||
if (type == ElementType::BEL)
|
|
||||||
return 0;
|
|
||||||
if (type == ElementType::WIRE)
|
|
||||||
return 1;
|
|
||||||
if (type == ElementType::PIP)
|
|
||||||
return 2;
|
|
||||||
if (type == ElementType::NET)
|
|
||||||
return 3;
|
|
||||||
if (type == ElementType::CELL)
|
|
||||||
return 4;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementType DesignWidget::getElementTypeByName(QString type)
|
ElementType DesignWidget::getElementTypeByName(QString type)
|
||||||
{
|
{
|
||||||
if (type == "BEL")
|
if (type == "BEL")
|
||||||
@ -510,59 +308,58 @@ QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name)
|
|||||||
|
|
||||||
void DesignWidget::onClickedBel(BelId bel, bool keep)
|
void DesignWidget::onClickedBel(BelId bel, bool keep)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::BEL)].value(ctx->getBelName(bel).c_str(ctx));
|
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::BEL, ctx->getBelName(bel).c_str(ctx));
|
||||||
treeWidget->setCurrentItem(item);
|
selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
|
||||||
|
keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
|
||||||
Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel)), keep);
|
Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel)), keep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::onClickedWire(WireId wire, bool keep)
|
void DesignWidget::onClickedWire(WireId wire, bool keep)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::WIRE)].value(ctx->getWireName(wire).c_str(ctx));
|
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::WIRE, ctx->getWireName(wire).c_str(ctx));
|
||||||
treeWidget->setCurrentItem(item);
|
selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
|
||||||
|
keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
|
||||||
Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep);
|
Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::onClickedPip(PipId pip, bool keep)
|
void DesignWidget::onClickedPip(PipId pip, bool keep)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::PIP)].value(ctx->getPipName(pip).c_str(ctx));
|
ContextTreeItem *item = treeModel->nodeForIdType(ElementType::PIP, ctx->getPipName(pip).c_str(ctx));
|
||||||
treeWidget->setCurrentItem(item);
|
selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
|
||||||
|
keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
|
||||||
Q_EMIT selected(getDecals(ElementType::PIP, ctx->getPipName(pip)), keep);
|
Q_EMIT selected(getDecals(ElementType::PIP, ctx->getPipName(pip)), keep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::onItemSelectionChanged()
|
void DesignWidget::onSelectionChanged(const QItemSelection &, const QItemSelection &)
|
||||||
{
|
{
|
||||||
if (treeWidget->selectedItems().size() == 0)
|
if (selectionModel->selectedIndexes().size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (treeWidget->selectedItems().size() > 1) {
|
if (selectionModel->selectedIndexes().size() > 1) {
|
||||||
std::vector<DecalXY> decals;
|
std::vector<DecalXY> decals;
|
||||||
for (auto clickItem : treeWidget->selectedItems()) {
|
for (auto index : selectionModel->selectedIndexes()) {
|
||||||
IdString value = static_cast<IdStringTreeItem *>(clickItem)->getData();
|
ContextTreeItem *item = treeModel->nodeFromIndex(index);
|
||||||
ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
|
std::vector<DecalXY> d = getDecals(item->type(), item->id());
|
||||||
std::vector<DecalXY> d = getDecals(type, value);
|
|
||||||
std::move(d.begin(), d.end(), std::back_inserter(decals));
|
std::move(d.begin(), d.end(), std::back_inserter(decals));
|
||||||
}
|
}
|
||||||
Q_EMIT selected(decals, false);
|
Q_EMIT selected(decals, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QModelIndex index = selectionModel->selectedIndexes().at(0);
|
||||||
QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0);
|
if (!index.isValid())
|
||||||
|
|
||||||
if (!clickItem->parent())
|
|
||||||
return;
|
return;
|
||||||
|
ContextTreeItem *clickItem = treeModel->nodeFromIndex(index);
|
||||||
|
|
||||||
ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
|
ElementType type = clickItem->type();
|
||||||
if (type == ElementType::NONE) {
|
if (type == ElementType::NONE)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<DecalXY> decals;
|
std::vector<DecalXY> decals;
|
||||||
|
|
||||||
addToHistory(clickItem);
|
addToHistory(index);
|
||||||
|
|
||||||
clearProperties();
|
clearProperties();
|
||||||
|
|
||||||
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
|
IdString c = clickItem->id();
|
||||||
Q_EMIT selected(getDecals(type, c), false);
|
Q_EMIT selected(getDecals(type, c), false);
|
||||||
|
|
||||||
if (type == ElementType::BEL) {
|
if (type == ElementType::BEL) {
|
||||||
@ -799,7 +596,7 @@ std::vector<DecalXY> DesignWidget::getDecals(ElementType type, IdString value)
|
|||||||
return decals;
|
return decals;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int group)
|
void DesignWidget::updateHighlightGroup(QList<ContextTreeItem *> items, int group)
|
||||||
{
|
{
|
||||||
const bool shouldClear = items.size() == 1;
|
const bool shouldClear = items.size() == 1;
|
||||||
for (auto item : items) {
|
for (auto item : items) {
|
||||||
@ -814,9 +611,7 @@ void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int grou
|
|||||||
std::vector<DecalXY> decals[8];
|
std::vector<DecalXY> decals[8];
|
||||||
|
|
||||||
for (auto it : highlightSelected.toStdMap()) {
|
for (auto it : highlightSelected.toStdMap()) {
|
||||||
ElementType type = static_cast<ElementTreeItem *>(it.first)->getType();
|
std::vector<DecalXY> d = getDecals(it.first->type(), it.first->id());
|
||||||
IdString value = static_cast<IdStringTreeItem *>(it.first)->getData();
|
|
||||||
std::vector<DecalXY> d = getDecals(type, value);
|
|
||||||
std::move(d.begin(), d.end(), std::back_inserter(decals[it.second]));
|
std::move(d.begin(), d.end(), std::back_inserter(decals[it.second]));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
@ -826,7 +621,7 @@ void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int grou
|
|||||||
void DesignWidget::prepareMenuProperty(const QPoint &pos)
|
void DesignWidget::prepareMenuProperty(const QPoint &pos)
|
||||||
{
|
{
|
||||||
QTreeWidget *tree = propertyEditor->treeWidget();
|
QTreeWidget *tree = propertyEditor->treeWidget();
|
||||||
QList<QTreeWidgetItem *> items;
|
QList<ContextTreeItem *> items;
|
||||||
for (auto itemContextMenu : tree->selectedItems()) {
|
for (auto itemContextMenu : tree->selectedItems()) {
|
||||||
QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
|
QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
|
||||||
if (!browserItem)
|
if (!browserItem)
|
||||||
@ -836,11 +631,11 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos)
|
|||||||
if (type == ElementType::NONE)
|
if (type == ElementType::NONE)
|
||||||
continue;
|
continue;
|
||||||
IdString value = ctx->id(selectedProperty->valueText().toStdString());
|
IdString value = ctx->id(selectedProperty->valueText().toStdString());
|
||||||
items.append(nameToItem[getElementIndex(type)].value(value.c_str(ctx)));
|
items.append(treeModel->nodeForIdType(type, value.c_str(ctx)));
|
||||||
}
|
}
|
||||||
int selectedIndex = -1;
|
int selectedIndex = -1;
|
||||||
if (items.size() == 1) {
|
if (items.size() == 1) {
|
||||||
QTreeWidgetItem *item = items.at(0);
|
ContextTreeItem *item = items.at(0);
|
||||||
if (highlightSelected.contains(item))
|
if (highlightSelected.contains(item))
|
||||||
selectedIndex = highlightSelected[item];
|
selectedIndex = highlightSelected[item];
|
||||||
}
|
}
|
||||||
@ -850,9 +645,7 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos)
|
|||||||
connect(selectAction, &QAction::triggered, this, [this, items] {
|
connect(selectAction, &QAction::triggered, this, [this, items] {
|
||||||
std::vector<DecalXY> decals;
|
std::vector<DecalXY> decals;
|
||||||
for (auto clickItem : items) {
|
for (auto clickItem : items) {
|
||||||
IdString value = static_cast<IdStringTreeItem *>(clickItem)->getData();
|
std::vector<DecalXY> d = getDecals(clickItem->type(), clickItem->id());
|
||||||
ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
|
|
||||||
std::vector<DecalXY> d = getDecals(type, value);
|
|
||||||
std::move(d.begin(), d.end(), std::back_inserter(decals));
|
std::move(d.begin(), d.end(), std::back_inserter(decals));
|
||||||
}
|
}
|
||||||
Q_EMIT selected(decals, false);
|
Q_EMIT selected(decals, false);
|
||||||
@ -878,12 +671,18 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos)
|
|||||||
|
|
||||||
void DesignWidget::prepareMenuTree(const QPoint &pos)
|
void DesignWidget::prepareMenuTree(const QPoint &pos)
|
||||||
{
|
{
|
||||||
if (treeWidget->selectedItems().size() == 0)
|
|
||||||
return;
|
|
||||||
int selectedIndex = -1;
|
int selectedIndex = -1;
|
||||||
QList<QTreeWidgetItem *> items = treeWidget->selectedItems();
|
|
||||||
if (treeWidget->selectedItems().size() == 1) {
|
if (selectionModel->selectedIndexes().size() == 0)
|
||||||
QTreeWidgetItem *item = treeWidget->selectedItems().at(0);
|
return;
|
||||||
|
|
||||||
|
QList<ContextTreeItem *> items;
|
||||||
|
for (auto index : selectionModel->selectedIndexes()) {
|
||||||
|
ContextTreeItem *item = treeModel->nodeFromIndex(index);
|
||||||
|
items.append(item);
|
||||||
|
}
|
||||||
|
if (items.size() == 1) {
|
||||||
|
ContextTreeItem *item = items.at(0);
|
||||||
if (highlightSelected.contains(item))
|
if (highlightSelected.contains(item))
|
||||||
selectedIndex = highlightSelected[item];
|
selectedIndex = highlightSelected[item];
|
||||||
}
|
}
|
||||||
@ -902,17 +701,17 @@ void DesignWidget::prepareMenuTree(const QPoint &pos)
|
|||||||
action->setChecked(true);
|
action->setChecked(true);
|
||||||
connect(action, &QAction::triggered, this, [this, i, items] { updateHighlightGroup(items, i); });
|
connect(action, &QAction::triggered, this, [this, i, items] { updateHighlightGroup(items, i); });
|
||||||
}
|
}
|
||||||
menu.exec(treeWidget->mapToGlobal(pos));
|
menu.exec(treeView->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
|
void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||||
{
|
{
|
||||||
QtProperty *selectedProperty = propertyEditor->itemToBrowserItem(item)->property();
|
QtProperty *selectedProperty = propertyEditor->itemToBrowserItem(item)->property();
|
||||||
ElementType type = getElementTypeByName(selectedProperty->propertyId());
|
ElementType type = getElementTypeByName(selectedProperty->propertyId());
|
||||||
QString value = selectedProperty->valueText();
|
ContextTreeItem *it = treeModel->nodeForIdType(type, selectedProperty->valueText());
|
||||||
int index = getElementIndex(type);
|
if (it)
|
||||||
if (type != ElementType::NONE && nameToItem[index].contains(value))
|
selectionModel->setCurrentIndex(treeModel->indexFromNode(it), QItemSelectionModel::ClearAndSelect);
|
||||||
treeWidget->setCurrentItem(nameToItem[index].value(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesignWidget::onDoubleClicked(const QModelIndex &index) { Q_EMIT zoomSelected(); }
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
@ -20,27 +20,17 @@
|
|||||||
#ifndef DESIGNWIDGET_H
|
#ifndef DESIGNWIDGET_H
|
||||||
#define DESIGNWIDGET_H
|
#define DESIGNWIDGET_H
|
||||||
|
|
||||||
#include <QTreeWidget>
|
#include <QTreeView>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include "nextpnr.h"
|
#include "nextpnr.h"
|
||||||
#include "qtgroupboxpropertybrowser.h"
|
#include "qtgroupboxpropertybrowser.h"
|
||||||
#include "qtpropertymanager.h"
|
#include "qtpropertymanager.h"
|
||||||
#include "qttreepropertybrowser.h"
|
#include "qttreepropertybrowser.h"
|
||||||
#include "qtvariantproperty.h"
|
#include "qtvariantproperty.h"
|
||||||
|
#include "treemodel.h"
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
enum class ElementType
|
|
||||||
{
|
|
||||||
NONE,
|
|
||||||
BEL,
|
|
||||||
WIRE,
|
|
||||||
PIP,
|
|
||||||
NET,
|
|
||||||
CELL,
|
|
||||||
GROUP
|
|
||||||
};
|
|
||||||
|
|
||||||
class DesignWidget : public QWidget
|
class DesignWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -59,19 +49,21 @@ class DesignWidget : public QWidget
|
|||||||
ElementType getElementTypeByName(QString type);
|
ElementType getElementTypeByName(QString type);
|
||||||
int getElementIndex(ElementType type);
|
int getElementIndex(ElementType type);
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
void addToHistory(QTreeWidgetItem *item);
|
void addToHistory(QModelIndex item);
|
||||||
std::vector<DecalXY> getDecals(ElementType type, IdString value);
|
std::vector<DecalXY> getDecals(ElementType type, IdString value);
|
||||||
void updateHighlightGroup(QList<QTreeWidgetItem *> item, int group);
|
void updateHighlightGroup(QList<ContextTreeItem *> item, int group);
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void info(std::string text);
|
void info(std::string text);
|
||||||
void selected(std::vector<DecalXY> decal, bool keep);
|
void selected(std::vector<DecalXY> decal, bool keep);
|
||||||
void highlight(std::vector<DecalXY> decal, int group);
|
void highlight(std::vector<DecalXY> decal, int group);
|
||||||
|
void zoomSelected();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void prepareMenuProperty(const QPoint &pos);
|
void prepareMenuProperty(const QPoint &pos);
|
||||||
void prepareMenuTree(const QPoint &pos);
|
void prepareMenuTree(const QPoint &pos);
|
||||||
void onItemSelectionChanged();
|
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void onItemDoubleClicked(QTreeWidgetItem *item, int column);
|
void onItemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||||
|
void onDoubleClicked(const QModelIndex &index);
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void newContext(Context *ctx);
|
void newContext(Context *ctx);
|
||||||
void updateTree();
|
void updateTree();
|
||||||
@ -82,8 +74,9 @@ class DesignWidget : public QWidget
|
|||||||
private:
|
private:
|
||||||
Context *ctx;
|
Context *ctx;
|
||||||
|
|
||||||
QTreeWidget *treeWidget;
|
QTreeView *treeView;
|
||||||
|
QItemSelectionModel *selectionModel;
|
||||||
|
ContextTreeModel *treeModel;
|
||||||
QtVariantPropertyManager *variantManager;
|
QtVariantPropertyManager *variantManager;
|
||||||
QtVariantPropertyManager *readOnlyManager;
|
QtVariantPropertyManager *readOnlyManager;
|
||||||
QtGroupPropertyManager *groupManager;
|
QtGroupPropertyManager *groupManager;
|
||||||
@ -93,14 +86,10 @@ class DesignWidget : public QWidget
|
|||||||
QMap<QtProperty *, QString> propertyToId;
|
QMap<QtProperty *, QString> propertyToId;
|
||||||
QMap<QString, QtProperty *> idToProperty;
|
QMap<QString, QtProperty *> idToProperty;
|
||||||
|
|
||||||
QMap<QString, QTreeWidgetItem *> nameToItem[6];
|
std::vector<QModelIndex> history;
|
||||||
std::vector<QTreeWidgetItem *> history;
|
|
||||||
int history_index;
|
int history_index;
|
||||||
bool history_ignore;
|
bool history_ignore;
|
||||||
|
|
||||||
QTreeWidgetItem *nets_root;
|
|
||||||
QTreeWidgetItem *cells_root;
|
|
||||||
|
|
||||||
QAction *actionFirst;
|
QAction *actionFirst;
|
||||||
QAction *actionPrev;
|
QAction *actionPrev;
|
||||||
QAction *actionNext;
|
QAction *actionNext;
|
||||||
@ -108,7 +97,7 @@ class DesignWidget : public QWidget
|
|||||||
QAction *actionClear;
|
QAction *actionClear;
|
||||||
|
|
||||||
QColor highlightColors[8];
|
QColor highlightColors[8];
|
||||||
QMap<QTreeWidgetItem *, int> highlightSelected;
|
QMap<ContextTreeItem *, int> highlightSelected;
|
||||||
};
|
};
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
329
gui/treemodel.cc
Normal file
329
gui/treemodel.cc
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "treemodel.h"
|
||||||
|
|
||||||
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
static bool contextTreeItemLessThan(const ContextTreeItem *v1, const ContextTreeItem *v2)
|
||||||
|
{
|
||||||
|
return v1->name() < v2->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeItem::ContextTreeItem() { parentNode = nullptr; }
|
||||||
|
|
||||||
|
ContextTreeItem::ContextTreeItem(QString name)
|
||||||
|
: parentNode(nullptr), itemId(IdString()), itemType(ElementType::NONE), itemName(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeItem::ContextTreeItem(IdString id, ElementType type, QString name)
|
||||||
|
: parentNode(nullptr), itemId(id), itemType(type), itemName(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeItem::~ContextTreeItem()
|
||||||
|
{
|
||||||
|
if (parentNode)
|
||||||
|
parentNode->children.removeOne(this);
|
||||||
|
qDeleteAll(children);
|
||||||
|
}
|
||||||
|
void ContextTreeItem::addChild(ContextTreeItem *item)
|
||||||
|
{
|
||||||
|
item->parentNode = this;
|
||||||
|
children.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContextTreeItem::sort()
|
||||||
|
{
|
||||||
|
for (auto item : children)
|
||||||
|
if (item->count()>1) item->sort();
|
||||||
|
qSort(children.begin(), children.end(), contextTreeItemLessThan);
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeModel::ContextTreeModel(QObject *parent) : QAbstractItemModel(parent) { root = new ContextTreeItem(); }
|
||||||
|
|
||||||
|
ContextTreeModel::~ContextTreeModel() { delete root; }
|
||||||
|
|
||||||
|
void ContextTreeModel::loadData(Context *ctx)
|
||||||
|
{
|
||||||
|
if (!ctx)
|
||||||
|
return;
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
|
delete root;
|
||||||
|
root = new ContextTreeItem();
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
nameToItem[i].clear();
|
||||||
|
|
||||||
|
IdString none;
|
||||||
|
|
||||||
|
ContextTreeItem *bels_root = new ContextTreeItem("Bels");
|
||||||
|
root->addChild(bels_root);
|
||||||
|
QMap<QString, ContextTreeItem *> bel_items;
|
||||||
|
|
||||||
|
// Add bels to tree
|
||||||
|
for (auto bel : ctx->getBels()) {
|
||||||
|
IdString id = ctx->getBelName(bel);
|
||||||
|
QStringList items = QString(id.c_str(ctx)).split("/");
|
||||||
|
QString name;
|
||||||
|
ContextTreeItem *parent = bels_root;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
if (!name.isEmpty())
|
||||||
|
name += "/";
|
||||||
|
name += items.at(i);
|
||||||
|
if (!bel_items.contains(name)) {
|
||||||
|
if (i == items.size() - 1) {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(id, ElementType::BEL, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
nameToItem[0].insert(name, item);
|
||||||
|
} else {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
bel_items.insert(name, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent = bel_items[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bels_root->sort();
|
||||||
|
|
||||||
|
ContextTreeItem *wire_root = new ContextTreeItem("Wires");
|
||||||
|
root->addChild(wire_root);
|
||||||
|
QMap<QString, ContextTreeItem *> wire_items;
|
||||||
|
|
||||||
|
// Add wires to tree
|
||||||
|
for (auto wire : ctx->getWires()) {
|
||||||
|
auto id = ctx->getWireName(wire);
|
||||||
|
QStringList items = QString(id.c_str(ctx)).split("/");
|
||||||
|
QString name;
|
||||||
|
ContextTreeItem *parent = wire_root;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
if (!name.isEmpty())
|
||||||
|
name += "/";
|
||||||
|
name += items.at(i);
|
||||||
|
if (!wire_items.contains(name)) {
|
||||||
|
if (i == items.size() - 1) {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(id, ElementType::WIRE, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
nameToItem[1].insert(name, item);
|
||||||
|
} else {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
wire_items.insert(name, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent = wire_items[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wire_root->sort();
|
||||||
|
|
||||||
|
ContextTreeItem *pip_root = new ContextTreeItem("Pips");
|
||||||
|
root->addChild(pip_root);
|
||||||
|
QMap<QString, ContextTreeItem *> pip_items;
|
||||||
|
|
||||||
|
// Add pips to tree
|
||||||
|
for (auto pip : ctx->getPips()) {
|
||||||
|
auto id = ctx->getPipName(pip);
|
||||||
|
QStringList items = QString(id.c_str(ctx)).split("/");
|
||||||
|
QString name;
|
||||||
|
ContextTreeItem *parent = pip_root;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
if (!name.isEmpty())
|
||||||
|
name += "/";
|
||||||
|
name += items.at(i);
|
||||||
|
if (!pip_items.contains(name)) {
|
||||||
|
if (i == items.size() - 1) {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(id, ElementType::PIP, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
nameToItem[2].insert(name, item);
|
||||||
|
} else {
|
||||||
|
ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i));
|
||||||
|
parent->addChild(item);
|
||||||
|
pip_items.insert(name, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent = pip_items[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pip_root->sort();
|
||||||
|
|
||||||
|
nets_root = new ContextTreeItem("Nets");
|
||||||
|
root->addChild(nets_root);
|
||||||
|
|
||||||
|
cells_root = new ContextTreeItem("Cells");
|
||||||
|
root->addChild(cells_root);
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContextTreeModel::updateData(Context *ctx)
|
||||||
|
{
|
||||||
|
if (!ctx)
|
||||||
|
return;
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
|
//QModelIndex nets_index = indexFromNode(nets_root);
|
||||||
|
// Remove nets not existing any more
|
||||||
|
QMap<QString, ContextTreeItem *>::iterator i = nameToItem[3].begin();
|
||||||
|
while (i != nameToItem[3].end()) {
|
||||||
|
QMap<QString, ContextTreeItem *>::iterator prev = i;
|
||||||
|
++i;
|
||||||
|
if (ctx->nets.find(ctx->id(prev.key().toStdString())) == ctx->nets.end()) {
|
||||||
|
//int pos = prev.value()->parent()->indexOf(prev.value());
|
||||||
|
//beginRemoveRows(nets_index, pos, pos);
|
||||||
|
delete prev.value();
|
||||||
|
nameToItem[3].erase(prev);
|
||||||
|
//endRemoveRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add nets to tree
|
||||||
|
for (auto &item : ctx->nets) {
|
||||||
|
auto id = item.first;
|
||||||
|
QString name = QString(id.c_str(ctx));
|
||||||
|
if (!nameToItem[3].contains(name)) {
|
||||||
|
//beginInsertRows(nets_index, nets_root->count() + 1, nets_root->count() + 1);
|
||||||
|
ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::NET, name);
|
||||||
|
nets_root->addChild(newItem);
|
||||||
|
nameToItem[3].insert(name, newItem);
|
||||||
|
//endInsertRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nets_root->sort();
|
||||||
|
|
||||||
|
//QModelIndex cell_index = indexFromNode(cells_root);
|
||||||
|
// Remove cells not existing any more
|
||||||
|
i = nameToItem[4].begin();
|
||||||
|
while (i != nameToItem[4].end()) {
|
||||||
|
QMap<QString, ContextTreeItem *>::iterator prev = i;
|
||||||
|
++i;
|
||||||
|
if (ctx->cells.find(ctx->id(prev.key().toStdString())) == ctx->cells.end()) {
|
||||||
|
//int pos = prev.value()->parent()->indexOf(prev.value());
|
||||||
|
//beginRemoveRows(cell_index, pos, pos);
|
||||||
|
delete prev.value();
|
||||||
|
nameToItem[4].erase(prev);
|
||||||
|
//endRemoveRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add cells to tree
|
||||||
|
for (auto &item : ctx->cells) {
|
||||||
|
auto id = item.first;
|
||||||
|
QString name = QString(id.c_str(ctx));
|
||||||
|
if (!nameToItem[4].contains(name)) {
|
||||||
|
//beginInsertRows(cell_index, cells_root->count() + 1, cells_root->count() + 1);
|
||||||
|
ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::CELL, name);
|
||||||
|
cells_root->addChild(newItem);
|
||||||
|
nameToItem[4].insert(name, newItem);
|
||||||
|
//endInsertRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cells_root->sort();
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ContextTreeModel::rowCount(const QModelIndex &parent) const { return nodeFromIndex(parent)->count(); }
|
||||||
|
|
||||||
|
int ContextTreeModel::columnCount(const QModelIndex &parent) const { return 1; }
|
||||||
|
|
||||||
|
QModelIndex ContextTreeModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
ContextTreeItem *node = nodeFromIndex(parent);
|
||||||
|
if (row >= node->count())
|
||||||
|
return QModelIndex();
|
||||||
|
return createIndex(row, column, node->at(row));
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex ContextTreeModel::parent(const QModelIndex &child) const
|
||||||
|
{
|
||||||
|
ContextTreeItem *parent = nodeFromIndex(child)->parent();
|
||||||
|
if (parent == root)
|
||||||
|
return QModelIndex();
|
||||||
|
ContextTreeItem *node = parent->parent();
|
||||||
|
return createIndex(node->indexOf(parent), 0, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ContextTreeModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.column() != 0)
|
||||||
|
return QVariant();
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
ContextTreeItem *node = nodeFromIndex(index);
|
||||||
|
return node->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ContextTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(section);
|
||||||
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
|
return QString("Items");
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeItem *ContextTreeModel::nodeFromIndex(const QModelIndex &idx) const
|
||||||
|
{
|
||||||
|
if (idx.isValid())
|
||||||
|
return (ContextTreeItem *)idx.internalPointer();
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getElementIndex(ElementType type)
|
||||||
|
{
|
||||||
|
if (type == ElementType::BEL)
|
||||||
|
return 0;
|
||||||
|
if (type == ElementType::WIRE)
|
||||||
|
return 1;
|
||||||
|
if (type == ElementType::PIP)
|
||||||
|
return 2;
|
||||||
|
if (type == ElementType::NET)
|
||||||
|
return 3;
|
||||||
|
if (type == ElementType::CELL)
|
||||||
|
return 4;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextTreeItem *ContextTreeModel::nodeForIdType(const ElementType type, const QString name) const
|
||||||
|
{
|
||||||
|
int index = getElementIndex(type);
|
||||||
|
if (type != ElementType::NONE && nameToItem[index].contains(name))
|
||||||
|
return nameToItem[index].value(name);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex ContextTreeModel::indexFromNode(ContextTreeItem *node)
|
||||||
|
{
|
||||||
|
ContextTreeItem *parent = node->parent();
|
||||||
|
if (parent == root)
|
||||||
|
return QModelIndex();
|
||||||
|
return createIndex(parent->indexOf(node), 0, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags ContextTreeModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
ContextTreeItem *node = nodeFromIndex(index);
|
||||||
|
return Qt::ItemIsEnabled | (node->type() != ElementType::NONE ? Qt::ItemIsSelectable : Qt::NoItemFlags);
|
||||||
|
}
|
||||||
|
NEXTPNR_NAMESPACE_END
|
93
gui/treemodel.h
Normal file
93
gui/treemodel.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TREEMODEL_H
|
||||||
|
#define TREEMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include "nextpnr.h"
|
||||||
|
|
||||||
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
enum class ElementType
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
BEL,
|
||||||
|
WIRE,
|
||||||
|
PIP,
|
||||||
|
NET,
|
||||||
|
CELL,
|
||||||
|
GROUP
|
||||||
|
};
|
||||||
|
|
||||||
|
class ContextTreeItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ContextTreeItem();
|
||||||
|
ContextTreeItem(QString name);
|
||||||
|
ContextTreeItem(IdString id, ElementType type, QString name);
|
||||||
|
~ContextTreeItem();
|
||||||
|
|
||||||
|
void addChild(ContextTreeItem *item);
|
||||||
|
int indexOf(ContextTreeItem *n) const { return children.indexOf(n); }
|
||||||
|
ContextTreeItem *at(int idx) const { return children.at(idx); }
|
||||||
|
int count() const { return children.count(); }
|
||||||
|
ContextTreeItem *parent() const { return parentNode; }
|
||||||
|
IdString id() const { return itemId; }
|
||||||
|
ElementType type() const { return itemType; }
|
||||||
|
QString name() const { return itemName; }
|
||||||
|
void sort();
|
||||||
|
private:
|
||||||
|
ContextTreeItem *parentNode;
|
||||||
|
QList<ContextTreeItem *> children;
|
||||||
|
IdString itemId;
|
||||||
|
ElementType itemType;
|
||||||
|
QString itemName;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ContextTreeModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ContextTreeModel(QObject *parent = nullptr);
|
||||||
|
~ContextTreeModel();
|
||||||
|
|
||||||
|
void loadData(Context *ctx);
|
||||||
|
void updateData(Context *ctx);
|
||||||
|
ContextTreeItem *nodeFromIndex(const QModelIndex &idx) const;
|
||||||
|
QModelIndex indexFromNode(ContextTreeItem *node);
|
||||||
|
ContextTreeItem *nodeForIdType(const ElementType type, const QString name) const;
|
||||||
|
// Override QAbstractItemModel methods
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ContextTreeItem *root;
|
||||||
|
QMap<QString, ContextTreeItem *> nameToItem[6];
|
||||||
|
ContextTreeItem *nets_root;
|
||||||
|
ContextTreeItem *cells_root;
|
||||||
|
};
|
||||||
|
|
||||||
|
NEXTPNR_NAMESPACE_END
|
||||||
|
|
||||||
|
#endif // TREEMODEL_H
|
Loading…
Reference in New Issue
Block a user