From 9388df19d3ab3ca1b127defafe6fa3f71147f451 Mon Sep 17 00:00:00 2001 From: "D. Shah" Date: Fri, 29 Jan 2021 12:58:41 +0000 Subject: refactor: Replace getXName().c_str(ctx) with ctx->nameOfX This makes the ongoing migration to IdStringList easier. Signed-off-by: D. Shah --- gui/designwidget.cc | 22 ++++++++++------------ gui/fpgaviewwidget.cc | 8 ++++---- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'gui') diff --git a/gui/designwidget.cc b/gui/designwidget.cc index f856b5f6..ff79c3a1 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -631,7 +631,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt addProperty(portInfoItem, QVariant::String, "Name", item.c_str(ctx)); addProperty(portInfoItem, QVariant::Int, "Type", int(ctx->getBelPinType(bel, item))); WireId wire = ctx->getBelPinWire(bel, item); - addProperty(portInfoItem, QVariant::String, "Wire", ctx->getWireName(wire).c_str(ctx), ElementType::WIRE); + addProperty(portInfoItem, QVariant::String, "Wire", ctx->nameOfWire(wire), ElementType::WIRE); } } else if (type == ElementType::WIRE) { std::lock_guard lock_ui(ctx->ui_mutex); @@ -644,8 +644,8 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt addProperty(topItem, QVariant::String, "Type", ctx->getWireType(wire).c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkWireAvail(wire)); addProperty(topItem, QVariant::String, "Bound Net", ctx->nameOf(ctx->getBoundWireNet(wire)), ElementType::NET); - addProperty(topItem, QVariant::String, "Conflicting Wire", - ctx->getWireName(ctx->getConflictingWireWire(wire)).c_str(ctx), ElementType::WIRE); + addProperty(topItem, QVariant::String, "Conflicting Wire", ctx->nameOfWire(ctx->getConflictingWireWire(wire)), + ElementType::WIRE); addProperty(topItem, QVariant::String, "Conflicting Net", ctx->nameOf(ctx->getConflictingWireNet(wire)), ElementType::NET); @@ -666,7 +666,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt for (const auto &item : ctx->getWireBelPins(wire)) { QString belname = ""; if (item.bel != BelId()) - belname = ctx->getBelName(item.bel).c_str(ctx); + belname = ctx->nameOfBel(item.bel); QString pinname = item.pin.c_str(ctx); QtProperty *dhItem = addSubGroup(belpinsItem, belname + "-" + pinname); @@ -707,16 +707,15 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt addProperty(topItem, QVariant::Bool, "Available", ctx->checkPipAvail(pip)); addProperty(topItem, QVariant::String, "Bound Net", ctx->nameOf(ctx->getBoundPipNet(pip)), ElementType::NET); if (ctx->getConflictingPipWire(pip) != WireId()) { - addProperty(topItem, QVariant::String, "Conflicting Wire", - ctx->getWireName(ctx->getConflictingPipWire(pip)).c_str(ctx), ElementType::WIRE); + addProperty(topItem, QVariant::String, "Conflicting Wire", ctx->nameOfWire(ctx->getConflictingPipWire(pip)), + ElementType::WIRE); } else { addProperty(topItem, QVariant::String, "Conflicting Wire", "", ElementType::NONE); } addProperty(topItem, QVariant::String, "Conflicting Net", ctx->nameOf(ctx->getConflictingPipNet(pip)), ElementType::NET); - addProperty(topItem, QVariant::String, "Src Wire", ctx->getWireName(ctx->getPipSrcWire(pip)).c_str(ctx), - ElementType::WIRE); - addProperty(topItem, QVariant::String, "Dest Wire", ctx->getWireName(ctx->getPipDstWire(pip)).c_str(ctx), + addProperty(topItem, QVariant::String, "Src Wire", ctx->nameOfWire(ctx->getPipSrcWire(pip)), ElementType::WIRE); + addProperty(topItem, QVariant::String, "Dest Wire", ctx->nameOfWire(ctx->getPipDstWire(pip)), ElementType::WIRE); QtProperty *attrsItem = addSubGroup(topItem, "Attributes"); @@ -769,14 +768,13 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt QtProperty *wiresItem = addSubGroup(topItem, "Wires"); for (auto &item : net->wires) { - auto name = ctx->getWireName(item.first).c_str(ctx); + auto name = ctx->nameOfWire(item.first); QtProperty *wireItem = addSubGroup(wiresItem, name); addProperty(wireItem, QVariant::String, "Wire", name, ElementType::WIRE); if (item.second.pip != PipId()) - addProperty(wireItem, QVariant::String, "Pip", ctx->getPipName(item.second.pip).c_str(ctx), - ElementType::PIP); + addProperty(wireItem, QVariant::String, "Pip", ctx->nameOfPip(item.second.pip), ElementType::PIP); else addProperty(wireItem, QVariant::String, "Pip", "", ElementType::PIP); diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 67ab80fd..9c90e2c5 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -779,22 +779,22 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event) rendererArgs_->x = event->x(); rendererArgs_->y = event->y(); if (closest.type == ElementType::BEL) { - rendererArgs_->hintText = std::string("BEL\n") + ctx_->getBelName(closest.bel).c_str(ctx_); + rendererArgs_->hintText = std::string("BEL\n") + ctx_->getBelName(closest.bel).str(ctx_); CellInfo *cell = ctx_->getBoundBelCell(closest.bel); if (cell != nullptr) rendererArgs_->hintText += std::string("\nCELL\n") + ctx_->nameOf(cell); } else if (closest.type == ElementType::WIRE) { - rendererArgs_->hintText = std::string("WIRE\n") + ctx_->getWireName(closest.wire).c_str(ctx_); + rendererArgs_->hintText = std::string("WIRE\n") + ctx_->getWireName(closest.wire).str(ctx_); NetInfo *net = ctx_->getBoundWireNet(closest.wire); if (net != nullptr) rendererArgs_->hintText += std::string("\nNET\n") + ctx_->nameOf(net); } else if (closest.type == ElementType::PIP) { - rendererArgs_->hintText = std::string("PIP\n") + ctx_->getPipName(closest.pip).c_str(ctx_); + rendererArgs_->hintText = std::string("PIP\n") + ctx_->getPipName(closest.pip).str(ctx_); NetInfo *net = ctx_->getBoundPipNet(closest.pip); if (net != nullptr) rendererArgs_->hintText += std::string("\nNET\n") + ctx_->nameOf(net); } else if (closest.type == ElementType::GROUP) { - rendererArgs_->hintText = std::string("GROUP\n") + ctx_->getGroupName(closest.group).c_str(ctx_); + rendererArgs_->hintText = std::string("GROUP\n") + ctx_->getGroupName(closest.group).str(ctx_); } else rendererArgs_->hintText = ""; -- cgit v1.2.3 From 3ae96bff886911d5629bdee9d48478ee69518551 Mon Sep 17 00:00:00 2001 From: "D. Shah" Date: Mon, 1 Feb 2021 10:49:59 +0000 Subject: Refactor GUI to use IdStringLists The GUI internally had an 'IdStringList' type that I hadn't spotted, to avoid a conflict this is renamed to IdList which also reflects its new purpose better. Signed-off-by: D. Shah --- gui/designwidget.cc | 42 ++++++++++++++++++++---------------------- gui/designwidget.h | 2 +- gui/treemodel.cc | 10 +++++----- gui/treemodel.h | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 50 insertions(+), 51 deletions(-) (limited to 'gui') diff --git a/gui/designwidget.cc b/gui/designwidget.cc index ff79c3a1..a5dc7e3e 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -340,11 +340,9 @@ void DesignWidget::newContext(Context *ctx) } getTreeByElementType(ElementType::CELL) - ->loadData(ctx, - std::unique_ptr(new TreeModel::IdStringList(ElementType::CELL))); + ->loadData(ctx, std::unique_ptr(new TreeModel::IdList(ElementType::CELL))); getTreeByElementType(ElementType::NET) - ->loadData(ctx, - std::unique_ptr(new TreeModel::IdStringList(ElementType::NET))); + ->loadData(ctx, std::unique_ptr(new TreeModel::IdList(ElementType::NET))); } updateTree(); } @@ -357,10 +355,10 @@ void DesignWidget::updateTree() while (i != highlightSelected.end()) { QMap::iterator prev = i; ++i; - if (prev.key()->type() == ElementType::NET && ctx->nets.find(prev.key()->id()) == ctx->nets.end()) { + if (prev.key()->type() == ElementType::NET && ctx->nets.find(prev.key()->id()[0]) == ctx->nets.end()) { highlightSelected.erase(prev); } - if (prev.key()->type() == ElementType::CELL && ctx->cells.find(prev.key()->id()) == ctx->cells.end()) { + if (prev.key()->type() == ElementType::CELL && ctx->cells.find(prev.key()->id()[0]) == ctx->cells.end()) { highlightSelected.erase(prev); } } @@ -369,13 +367,13 @@ void DesignWidget::updateTree() std::lock_guard lock_ui(ctx->ui_mutex); std::lock_guard lock(ctx->mutex); - std::vector cells; + std::vector cells; for (auto &pair : ctx->cells) { - cells.push_back(pair.first); + cells.push_back(IdStringList(pair.first)); } - std::vector nets; + std::vector nets; for (auto &pair : ctx->nets) { - nets.push_back(pair.first); + nets.push_back(IdStringList(pair.first)); } getTreeByElementType(ElementType::CELL)->updateElements(cells); @@ -603,7 +601,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt clearProperties(); - IdString c = clickItem->id(); + IdStringList c = clickItem->id(); Q_EMIT selected(getDecals(type, c), false); if (type == ElementType::BEL) { @@ -613,7 +611,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt BelId bel = ctx->getBelByName(c); QtProperty *topItem = addTopLevelProperty("Bel"); - addProperty(topItem, QVariant::String, "Name", c.c_str(ctx)); + addProperty(topItem, QVariant::String, "Name", ctx->nameOfBel(bel)); addProperty(topItem, QVariant::String, "Type", ctx->getBelType(bel).c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkBelAvail(bel)); addProperty(topItem, QVariant::String, "Bound Cell", ctx->nameOf(ctx->getBoundBelCell(bel)), ElementType::CELL); @@ -640,7 +638,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt WireId wire = ctx->getWireByName(c); QtProperty *topItem = addTopLevelProperty("Wire"); - addProperty(topItem, QVariant::String, "Name", c.c_str(ctx)); + addProperty(topItem, QVariant::String, "Name", ctx->nameOfWire(wire)); addProperty(topItem, QVariant::String, "Type", ctx->getWireType(wire).c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkWireAvail(wire)); addProperty(topItem, QVariant::String, "Bound Net", ctx->nameOf(ctx->getBoundWireNet(wire)), ElementType::NET); @@ -677,7 +675,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt int counter = 0; QtProperty *pipsDownItem = addSubGroup(topItem, "Pips Downhill"); for (const auto &item : ctx->getPipsDownhill(wire)) { - addProperty(pipsDownItem, QVariant::String, "", ctx->getPipName(item).c_str(ctx), ElementType::PIP); + addProperty(pipsDownItem, QVariant::String, "", ctx->nameOfPip(item), ElementType::PIP); counter++; if (counter == 50) { addProperty(pipsDownItem, QVariant::String, "Warning", "Too many items...", ElementType::NONE); @@ -688,7 +686,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt counter = 0; QtProperty *pipsUpItem = addSubGroup(topItem, "Pips Uphill"); for (const auto &item : ctx->getPipsUphill(wire)) { - addProperty(pipsUpItem, QVariant::String, "", ctx->getPipName(item).c_str(ctx), ElementType::PIP); + addProperty(pipsUpItem, QVariant::String, "", ctx->nameOfPip(item), ElementType::PIP); counter++; if (counter == 50) { addProperty(pipsUpItem, QVariant::String, "Warning", "Too many items...", ElementType::NONE); @@ -702,7 +700,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt PipId pip = ctx->getPipByName(c); QtProperty *topItem = addTopLevelProperty("Pip"); - addProperty(topItem, QVariant::String, "Name", c.c_str(ctx)); + addProperty(topItem, QVariant::String, "Name", ctx->nameOfPip(pip)); addProperty(topItem, QVariant::String, "Type", ctx->getPipType(pip).c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkPipAvail(pip)); addProperty(topItem, QVariant::String, "Bound Net", ctx->nameOf(ctx->getBoundPipNet(pip)), ElementType::NET); @@ -734,7 +732,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt std::lock_guard lock_ui(ctx->ui_mutex); std::lock_guard lock(ctx->mutex); - NetInfo *net = ctx->nets.at(c).get(); + NetInfo *net = ctx->nets.at(c[0]).get(); QtProperty *topItem = addTopLevelProperty("Net"); @@ -785,14 +783,14 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt std::lock_guard lock_ui(ctx->ui_mutex); std::lock_guard lock(ctx->mutex); - CellInfo *cell = ctx->cells.at(c).get(); + CellInfo *cell = ctx->cells.at(c[0]).get(); QtProperty *topItem = addTopLevelProperty("Cell"); addProperty(topItem, QVariant::String, "Name", cell->name.c_str(ctx)); addProperty(topItem, QVariant::String, "Type", cell->type.c_str(ctx)); if (cell->bel != BelId()) - addProperty(topItem, QVariant::String, "Bel", ctx->getBelName(cell->bel).c_str(ctx), ElementType::BEL); + addProperty(topItem, QVariant::String, "Bel", ctx->nameOfBel(cell->bel), ElementType::BEL); else addProperty(topItem, QVariant::String, "Bel", "", ElementType::BEL); addProperty(topItem, QVariant::Int, "Bel strength", int(cell->belStrength)); @@ -836,7 +834,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt } } -std::vector DesignWidget::getDecals(ElementType type, IdString value) +std::vector DesignWidget::getDecals(ElementType type, IdStringList value) { std::vector decals; switch (type) { @@ -859,7 +857,7 @@ std::vector DesignWidget::getDecals(ElementType type, IdString value) } } break; case ElementType::NET: { - NetInfo *net = ctx->nets.at(value).get(); + NetInfo *net = ctx->nets.at(value[0]).get(); for (auto &item : net->wires) { decals.push_back(ctx->getWireDecal(item.first)); if (item.second.pip != PipId()) { @@ -868,7 +866,7 @@ std::vector DesignWidget::getDecals(ElementType type, IdString value) } } break; case ElementType::CELL: { - CellInfo *cell = ctx->cells.at(value).get(); + CellInfo *cell = ctx->cells.at(value[0]).get(); if (cell->bel != BelId()) { decals.push_back(ctx->getBelDecal(cell->bel)); } diff --git a/gui/designwidget.h b/gui/designwidget.h index 89c6e702..cde69099 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -71,7 +71,7 @@ class DesignWidget : public QWidget int getElementIndex(ElementType type); void updateButtons(); void addToHistory(int tab, QModelIndex item); - std::vector getDecals(ElementType type, IdString value); + std::vector getDecals(ElementType type, IdStringList value); void updateHighlightGroup(QList item, int group); void clearAllSelectionModels(); Q_SIGNALS: diff --git a/gui/treemodel.cc b/gui/treemodel.cc index 448c9794..cc563202 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -26,7 +26,7 @@ NEXTPNR_NAMESPACE_BEGIN namespace TreeModel { // converts 'aa123bb432' -> ['aa', '123', 'bb', '432'] -std::vector IdStringList::alphaNumSplit(const QString &str) +std::vector IdList::alphaNumSplit(const QString &str) { std::vector res; QString current_part; @@ -53,12 +53,12 @@ std::vector IdStringList::alphaNumSplit(const QString &str) return res; } -void IdStringList::updateElements(Context *ctx, std::vector elements) +void IdList::updateElements(Context *ctx, std::vector elements) { bool changed = false; // For any elements that are not yet in managed_, created them. - std::unordered_set element_set; + std::unordered_set element_set; for (auto elem : elements) { element_set.insert(elem); auto existing = managed_.find(elem); @@ -134,7 +134,7 @@ void IdStringList::updateElements(Context *ctx, std::vector elements) }); } -void IdStringList::search(QList &results, QString text, int limit) +void IdList::search(QList &results, QString text, int limit) { for (const auto &child : children_) { if (limit != -1 && results.size() > limit) @@ -157,7 +157,7 @@ void Model::loadData(Context *ctx, std::unique_ptr data) endResetModel(); } -void Model::updateElements(std::vector elements) +void Model::updateElements(std::vector elements) { if (!ctx_) return; diff --git a/gui/treemodel.h b/gui/treemodel.h index 49168a91..7b599e65 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -95,16 +95,16 @@ class Item int indexOf(Item *child) { return children_.indexOf(child, 0); } // Arch id and type that correspond to this element. - virtual IdString id() const { return IdString(); } + virtual IdStringList id() const { return IdStringList(); } virtual ElementType type() const { return ElementType::NONE; } // Lazy loading methods. virtual bool canFetchMore() const { return false; } virtual void fetchMore() {} - virtual boost::optional getById(IdString id) { return boost::none; } + virtual boost::optional getById(IdStringList id) { return boost::none; } virtual void search(QList &results, QString text, int limit) {} - virtual void updateElements(Context *ctx, std::vector elements) {} + virtual void updateElements(Context *ctx, std::vector elements) {} virtual ~Item() { @@ -118,46 +118,46 @@ class Item class IdStringItem : public Item { private: - IdString id_; + IdStringList id_; ElementType type_; public: - IdStringItem(Context *ctx, IdString str, Item *parent, ElementType type) - : Item(QString(str.c_str(ctx)), parent), id_(str), type_(type) + IdStringItem(Context *ctx, IdStringList str, Item *parent, ElementType type) + : Item(QString(str.str(ctx).c_str()), parent), id_(str), type_(type) { } - virtual IdString id() const override { return id_; } + virtual IdStringList id() const override { return id_; } virtual ElementType type() const override { return type_; } }; -// IdString list is a static list of IdStrings which can be set/updates from +// IdList is a static list of IdStringLists which can be set/updates from // a vector of IdStrings. It will render each IdStrings as a child, with the // list sorted in a smart way. -class IdStringList : public Item +class IdList : public Item { private: // Children that we manage the memory for, stored for quick lookup from // IdString to child. - std::unordered_map> managed_; + std::unordered_map> managed_; // Type of children that the list creates. ElementType child_type_; public: - // Create an IdStringList at given parent that will contain elements of + // Create an IdList at given parent that will contain elements of // the given type. - IdStringList(ElementType type) : Item("root", nullptr), child_type_(type) {} + IdList(ElementType type) : Item("root", nullptr), child_type_(type) {} // Split a name into alpha/non-alpha parts, which is then used for sorting // of children. static std::vector alphaNumSplit(const QString &str); // getById finds a child for the given IdString. - virtual boost::optional getById(IdString id) override { return managed_.at(id).get(); } + virtual boost::optional getById(IdStringList id) override { return managed_.at(id).get(); } // (Re-)create children from a list of IdStrings. - virtual void updateElements(Context *ctx, std::vector elements) override; + virtual void updateElements(Context *ctx, std::vector elements) override; // Find children that contain the given text. virtual void search(QList &results, QString text, int limit) override; @@ -173,7 +173,7 @@ template class ElementList : public Item // A map from tile (X,Y) to list of ElementTs in that tile. using ElementMap = std::map, std::vector>; // A method that converts an ElementT to an IdString. - using ElementGetter = std::function; + using ElementGetter = std::function; private: Context *ctx_; @@ -184,7 +184,7 @@ template class ElementList : public Item ElementGetter getter_; // Children that we manage the memory for, stored for quick lookup from // IdString to child. - std::unordered_map> managed_; + std::unordered_map> managed_; // Type of children that he list creates. ElementType child_type_; @@ -209,9 +209,10 @@ template class ElementList : public Item size_t end = std::min(start + count, elements()->size()); for (size_t i = start; i < end; i++) { auto idstring = getter_(ctx_, elements()->at(i)); - QString name(idstring.c_str(ctx_)); + std::string name_str = idstring.str(ctx_); + QString name(name_str.c_str()); - // Remove X.../Y.../ prefix + // Remove X.../Y.../ prefix - TODO: find a way to use IdStringList splitting here QString prefix = QString("X%1/Y%2/").arg(x_).arg(y_); if (name.startsWith(prefix)) name.remove(0, prefix.size()); @@ -224,7 +225,7 @@ template class ElementList : public Item virtual void fetchMore() override { fetchMore(100); } // getById finds a child for the given IdString. - virtual boost::optional getById(IdString id) override + virtual boost::optional getById(IdStringList id) override { // Search requires us to load all our elements... while (canFetchMore()) @@ -267,7 +268,7 @@ template class ElementXYRoot : public Item // A map from tile (X,Y) to list of ElementTs in that tile. using ElementMap = std::map, std::vector>; // A method that converts an ElementT to an IdString. - using ElementGetter = std::function; + using ElementGetter = std::function; private: Context *ctx_; @@ -319,7 +320,7 @@ template class ElementXYRoot : public Item } // getById finds a child for the given IdString. - virtual boost::optional getById(IdString id) override + virtual boost::optional getById(IdStringList id) override { // For now, scan linearly all ElementLists. // TODO(q3k) fix this once we have tree API from arch @@ -353,7 +354,7 @@ class Model : public QAbstractItemModel ~Model(); void loadData(Context *ctx, std::unique_ptr data); - void updateElements(std::vector elements); + void updateElements(std::vector elements); Item *nodeFromIndex(const QModelIndex &idx) const; QModelIndex indexFromNode(Item *node) { @@ -366,7 +367,7 @@ class Model : public QAbstractItemModel QList search(QString text); - boost::optional nodeForId(IdString id) const { return root_->getById(id); } + boost::optional nodeForId(IdStringList id) const { return root_->getById(id); } // Override QAbstractItemModel methods int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; -- cgit v1.2.3