From dcdf9a8ec150cdd1cccc11bc7565b90eea021d1b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 12 Jul 2020 21:06:03 +0200 Subject: [PATCH] WIP: paths for tree model too --- .../laybasic/layNetlistBrowserModel.h | 3 ++ .../laybasic/layNetlistBrowserPage.cc | 10 ++--- .../laybasic/layNetlistBrowserTreeModel.cc | 40 +++++++++++++++++++ .../laybasic/layNetlistBrowserTreeModel.h | 2 + 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/laybasic/laybasic/layNetlistBrowserModel.h b/src/laybasic/laybasic/layNetlistBrowserModel.h index 16496e471..1fd624ce8 100644 --- a/src/laybasic/laybasic/layNetlistBrowserModel.h +++ b/src/laybasic/laybasic/layNetlistBrowserModel.h @@ -183,6 +183,9 @@ private: */ struct LAYBASIC_PUBLIC NetlistObjectPath { + typedef std::list > path_type; + typedef path_type::const_iterator path_iterator; + NetlistObjectPath () { } bool operator== (const NetlistObjectPath &other) const diff --git a/src/laybasic/laybasic/layNetlistBrowserPage.cc b/src/laybasic/laybasic/layNetlistBrowserPage.cc index d0cb92b98..9f9de9fcb 100644 --- a/src/laybasic/laybasic/layNetlistBrowserPage.cc +++ b/src/laybasic/laybasic/layNetlistBrowserPage.cc @@ -323,6 +323,7 @@ NetlistBrowserPage::current_tree_index_changed (const QModelIndex &index) return; } + // TODO: this could give a path ... std::pair circuits = tree_model->circuits_from_index (index); QModelIndex circuit_index = netlist_model->index_from_circuit (circuits); @@ -346,8 +347,8 @@ NetlistBrowserPage::current_index_changed (const QModelIndex &index) add_to_history (index, true); - std::pair circuits = netlist_model->circuit_from_index (index); - QModelIndex circuit_index = tree_model->index_from_circuits (circuits); + NetlistObjectPath path = netlist_model->netpath_from_index (index); + QModelIndex circuit_index = tree_model->index_from_netpath (path); m_signals_enabled = false; hierarchy_tree->setCurrentIndex (circuit_index); @@ -516,9 +517,8 @@ NetlistBrowserPage::navigate_to (const QModelIndex &index, bool fwd) return; } - // @@@ with path! - std::pair circuits = netlist_model->circuit_from_index (index); - QModelIndex circuit_index = tree_model->index_from_circuits (circuits); + lay::NetlistObjectPath path = netlist_model->netpath_from_index (index); + QModelIndex circuit_index = tree_model->index_from_netpath (path); hierarchy_tree->setCurrentIndex (circuit_index); } catch (...) { diff --git a/src/laybasic/laybasic/layNetlistBrowserTreeModel.cc b/src/laybasic/laybasic/layNetlistBrowserTreeModel.cc index 24cfb3c34..db47fad4b 100644 --- a/src/laybasic/laybasic/layNetlistBrowserTreeModel.cc +++ b/src/laybasic/laybasic/layNetlistBrowserTreeModel.cc @@ -24,6 +24,7 @@ #include "layNetlistBrowserTreeModel.h" #include "layIndexedNetlistModel.h" #include "layNetlistCrossReferenceModel.h" +#include "layNetlistBrowserModel.h" #include #include @@ -257,6 +258,45 @@ NetlistBrowserTreeModel::build_circuits_to_index (size_t nprod, const std::pair< } } +static bool is_compatible (const std::pair &a, const std::pair &b) +{ + if (a.first && b.first && a.first == b.first) { + return true; + } else if (a.second && b.second && a.second == b.second) { + return true; + } else { + return false; + } +} + +QModelIndex +NetlistBrowserTreeModel::index_from_netpath (const NetlistObjectPath &path) const +{ + QModelIndex idx; + + idx = index_from_circuits (path.root); + + for (NetlistObjectPath::path_iterator p = path.path.begin (); p != path.path.end () && idx.isValid (); ++p) { + + std::pair sc (p->first ? p->first->circuit_ref () : 0, p->second ? p->second->circuit_ref (): 0); + std::pair circuit = circuits_from_index (idx); + + size_t count = mp_indexer->child_circuit_count (circuit); + for (size_t n = count; n > 0; ) { + --n; + std::pair cc = mp_indexer->child_circuit_from_index (circuit, n).first; + if (is_compatible (sc, cc)) { + circuit = cc; + idx = index (n, 0, idx); + break; + } + } + + } + + return idx; +} + QModelIndex NetlistBrowserTreeModel::index_from_circuits (const std::pair &circuits) const { diff --git a/src/laybasic/laybasic/layNetlistBrowserTreeModel.h b/src/laybasic/laybasic/layNetlistBrowserTreeModel.h index 3ecff81f1..c4fe0696d 100644 --- a/src/laybasic/laybasic/layNetlistBrowserTreeModel.h +++ b/src/laybasic/laybasic/layNetlistBrowserTreeModel.h @@ -42,6 +42,7 @@ namespace lay { class IndexedNetlistModel; +struct NetlistObjectPath; // ---------------------------------------------------------------------------------- // NetlistBrowserTreeModel definition @@ -77,6 +78,7 @@ public: std::pair circuits_from_index (const QModelIndex &index) const; QModelIndex index_from_circuits (const std::pair &circuits) const; + QModelIndex index_from_netpath (const NetlistObjectPath &path) const; private: NetlistBrowserTreeModel (const NetlistBrowserTreeModel &);