From 5d5324c073a2795689410a2baabff5cd1f0ff9a8 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 20 Oct 2018 15:15:23 +0200 Subject: Split tree models and make other features work with it --- gui/treemodel.cc | 97 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'gui/treemodel.cc') diff --git a/gui/treemodel.cc b/gui/treemodel.cc index 33dd6a96..d26738d6 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -154,7 +154,7 @@ Model::Model(QObject *parent) : QAbstractItemModel(parent), root_(new Item("Elem Model::~Model() {} -void Model::loadContext(Context *ctx) +void Model::loadContext(ElementType type, Context *ctx) { if (!ctx) return; @@ -166,50 +166,59 @@ void Model::loadContext(Context *ctx) // cross-arch. So we only do this for ICE40 by querying the ChipDB // directly. // TODO(q3k): once AnyId and the tree API land in Arch, move this over. -#ifdef ARCH_ICE40 { - std::map, std::vector> belMap; - for (auto bel : ctx->getBels()) { - auto loc = ctx->getBelLocation(bel); - belMap[std::pair(loc.x, loc.y)].push_back(bel); + if (type==ElementType::BEL) + { + std::map, std::vector> belMap; + for (auto bel : ctx->getBels()) { + auto loc = ctx->getBelLocation(bel); + belMap[std::pair(loc.x, loc.y)].push_back(bel); + } + auto belGetter = [](Context *ctx, BelId id) { return ctx->getBelName(id); }; + root_ = std::unique_ptr>( + new ElementXYRoot(ctx, "Bels", nullptr, belMap, belGetter, ElementType::BEL)); } - auto belGetter = [](Context *ctx, BelId id) { return ctx->getBelName(id); }; - bel_root_ = std::unique_ptr( - new BelXYRoot(ctx, "Bels", root_.get(), belMap, belGetter, ElementType::BEL)); - - std::map, std::vector> wireMap; - for (int i = 0; i < ctx->chip_info->num_wires; i++) { - const auto wire = &ctx->chip_info->wire_data[i]; - WireId wireid; - wireid.index = i; - wireMap[std::pair(wire->x, wire->y)].push_back(wireid); +#ifdef ARCH_ICE40 + if (type==ElementType::WIRE) + { + std::map, std::vector> wireMap; + for (int i = 0; i < ctx->chip_info->num_wires; i++) { + const auto wire = &ctx->chip_info->wire_data[i]; + WireId wireid; + wireid.index = i; + wireMap[std::pair(wire->x, wire->y)].push_back(wireid); + } + auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); }; + root_ = std::unique_ptr>( + new ElementXYRoot(ctx, "Wires", nullptr, wireMap, wireGetter, ElementType::WIRE)); } - auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); }; - wire_root_ = std::unique_ptr( - new WireXYRoot(ctx, "Wires", root_.get(), wireMap, wireGetter, ElementType::WIRE)); - - std::map, std::vector> pipMap; - for (int i = 0; i < ctx->chip_info->num_pips; i++) { - const auto pip = &ctx->chip_info->pip_data[i]; - PipId pipid; - pipid.index = i; - pipMap[std::pair(pip->x, pip->y)].push_back(pipid); + + if (type==ElementType::PIP) + { + std::map, std::vector> pipMap; + for (int i = 0; i < ctx->chip_info->num_pips; i++) { + const auto pip = &ctx->chip_info->pip_data[i]; + PipId pipid; + pipid.index = i; + pipMap[std::pair(pip->x, pip->y)].push_back(pipid); + } + auto pipGetter = [](Context *ctx, PipId id) { return ctx->getPipName(id); }; + root_ = std::unique_ptr>( + new ElementXYRoot(ctx, "Pips", nullptr, pipMap, pipGetter, ElementType::PIP)); } - auto pipGetter = [](Context *ctx, PipId id) { return ctx->getPipName(id); }; - pip_root_ = std::unique_ptr( - new PipXYRoot(ctx, "Pips", root_.get(), pipMap, pipGetter, ElementType::PIP)); - } #endif + } - cell_root_ = std::unique_ptr(new IdStringList(QString("Cells"), root_.get(), ElementType::CELL)); - net_root_ = std::unique_ptr(new IdStringList(QString("Nets"), root_.get(), ElementType::NET)); + if (type==ElementType::CELL) root_ = std::unique_ptr(new IdStringList(QString("Cells"), nullptr, ElementType::CELL)); + if (type==ElementType::NET) root_ = std::unique_ptr(new IdStringList(QString("Nets"), nullptr, ElementType::NET)); endResetModel(); - updateCellsNets(ctx); + if (type==ElementType::CELL) updateCells(ctx); + if (type==ElementType::NET) updateNets(ctx); } -void Model::updateCellsNets(Context *ctx) +void Model::updateCells(Context *ctx) { if (!ctx) return; @@ -220,13 +229,23 @@ void Model::updateCellsNets(Context *ctx) for (auto &pair : ctx->cells) { cells.push_back(pair.first); } - cell_root_->updateElements(ctx, cells); + root_->updateElements(ctx, cells); + + endResetModel(); +} + +void Model::updateNets(Context *ctx) +{ + if (!ctx) + return; + + beginResetModel(); std::vector nets; for (auto &pair : ctx->nets) { nets.push_back(pair.first); } - net_root_->updateElements(ctx, nets); + root_->updateElements(ctx, nets); endResetModel(); } @@ -302,11 +321,7 @@ QList Model::search(QString text) { const int limit = 500; QList list; - cell_root_->search(list, text, limit); - net_root_->search(list, text, limit); - bel_root_->search(list, text, limit); - wire_root_->search(list, text, limit); - pip_root_->search(list, text, limit); + root_->search(list, text, limit); QList res; for (auto i : list) { -- cgit v1.2.3 From ba0ab7cb3069b76c2f6644afb211f66c54c7208c Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 20 Oct 2018 16:52:38 +0200 Subject: simplify and move arround --- gui/treemodel.cc | 61 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 59 deletions(-) (limited to 'gui/treemodel.cc') diff --git a/gui/treemodel.cc b/gui/treemodel.cc index d26738d6..ee18dd57 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -154,68 +154,11 @@ Model::Model(QObject *parent) : QAbstractItemModel(parent), root_(new Item("Elem Model::~Model() {} -void Model::loadContext(ElementType type, Context *ctx) +void Model::loadData(std::unique_ptr data) { - if (!ctx) - return; - ctx_ = ctx; - beginResetModel(); - - // Currently we lack an API to get a proper hierarchy of bels/pip/wires - // cross-arch. So we only do this for ICE40 by querying the ChipDB - // directly. - // TODO(q3k): once AnyId and the tree API land in Arch, move this over. - { - if (type==ElementType::BEL) - { - std::map, std::vector> belMap; - for (auto bel : ctx->getBels()) { - auto loc = ctx->getBelLocation(bel); - belMap[std::pair(loc.x, loc.y)].push_back(bel); - } - auto belGetter = [](Context *ctx, BelId id) { return ctx->getBelName(id); }; - root_ = std::unique_ptr>( - new ElementXYRoot(ctx, "Bels", nullptr, belMap, belGetter, ElementType::BEL)); - } -#ifdef ARCH_ICE40 - if (type==ElementType::WIRE) - { - std::map, std::vector> wireMap; - for (int i = 0; i < ctx->chip_info->num_wires; i++) { - const auto wire = &ctx->chip_info->wire_data[i]; - WireId wireid; - wireid.index = i; - wireMap[std::pair(wire->x, wire->y)].push_back(wireid); - } - auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); }; - root_ = std::unique_ptr>( - new ElementXYRoot(ctx, "Wires", nullptr, wireMap, wireGetter, ElementType::WIRE)); - } - - if (type==ElementType::PIP) - { - std::map, std::vector> pipMap; - for (int i = 0; i < ctx->chip_info->num_pips; i++) { - const auto pip = &ctx->chip_info->pip_data[i]; - PipId pipid; - pipid.index = i; - pipMap[std::pair(pip->x, pip->y)].push_back(pipid); - } - auto pipGetter = [](Context *ctx, PipId id) { return ctx->getPipName(id); }; - root_ = std::unique_ptr>( - new ElementXYRoot(ctx, "Pips", nullptr, pipMap, pipGetter, ElementType::PIP)); - } -#endif - } - - if (type==ElementType::CELL) root_ = std::unique_ptr(new IdStringList(QString("Cells"), nullptr, ElementType::CELL)); - if (type==ElementType::NET) root_ = std::unique_ptr(new IdStringList(QString("Nets"), nullptr, ElementType::NET)); - + root_ = std::move(data); endResetModel(); - - if (type==ElementType::CELL) updateCells(ctx); - if (type==ElementType::NET) updateNets(ctx); } void Model::updateCells(Context *ctx) -- cgit v1.2.3 From f43ee265e8d303d7b41b9b79036c3c2ba433877b Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 20 Oct 2018 17:04:49 +0200 Subject: Cleanup --- gui/treemodel.cc | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'gui/treemodel.cc') diff --git a/gui/treemodel.cc b/gui/treemodel.cc index ee18dd57..ab7dc263 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -161,35 +161,13 @@ void Model::loadData(std::unique_ptr data) endResetModel(); } -void Model::updateCells(Context *ctx) +void Model::updateElements(Context *ctx, std::vector elements) { if (!ctx) return; beginResetModel(); - - std::vector cells; - for (auto &pair : ctx->cells) { - cells.push_back(pair.first); - } - root_->updateElements(ctx, cells); - - endResetModel(); -} - -void Model::updateNets(Context *ctx) -{ - if (!ctx) - return; - - beginResetModel(); - - std::vector nets; - for (auto &pair : ctx->nets) { - nets.push_back(pair.first); - } - root_->updateElements(ctx, nets); - + root_->updateElements(ctx, elements); endResetModel(); } -- cgit v1.2.3 From b8870bb99c24d2998ca5bb5245589dd9d0703ea4 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 11 Nov 2018 10:53:48 +0100 Subject: Propagate proper ctx, fixes fetchMore --- gui/treemodel.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'gui/treemodel.cc') diff --git a/gui/treemodel.cc b/gui/treemodel.cc index ab7dc263..b834c682 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -154,20 +154,21 @@ Model::Model(QObject *parent) : QAbstractItemModel(parent), root_(new Item("Elem Model::~Model() {} -void Model::loadData(std::unique_ptr data) +void Model::loadData(Context *ctx, std::unique_ptr data) { beginResetModel(); + ctx_ = ctx; root_ = std::move(data); endResetModel(); } -void Model::updateElements(Context *ctx, std::vector elements) +void Model::updateElements(std::vector elements) { - if (!ctx) + if (!ctx_) return; beginResetModel(); - root_->updateElements(ctx, elements); + root_->updateElements(ctx_, elements); endResetModel(); } -- cgit v1.2.3