mirror of https://github.com/KLayout/klayout.git
WIP: paths for tree model too
This commit is contained in:
parent
27d1f2fac1
commit
dcdf9a8ec1
|
|
@ -183,6 +183,9 @@ private:
|
|||
*/
|
||||
struct LAYBASIC_PUBLIC NetlistObjectPath
|
||||
{
|
||||
typedef std::list<std::pair<const db::SubCircuit *, const db::SubCircuit *> > path_type;
|
||||
typedef path_type::const_iterator path_iterator;
|
||||
|
||||
NetlistObjectPath () { }
|
||||
|
||||
bool operator== (const NetlistObjectPath &other) const
|
||||
|
|
|
|||
|
|
@ -323,6 +323,7 @@ NetlistBrowserPage::current_tree_index_changed (const QModelIndex &index)
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: this could give a path ...
|
||||
std::pair<const db::Circuit *, const db::Circuit *> 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<const db::Circuit *, const db::Circuit *> 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<const db::Circuit *, const db::Circuit *> 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 (...) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "layNetlistBrowserTreeModel.h"
|
||||
#include "layIndexedNetlistModel.h"
|
||||
#include "layNetlistCrossReferenceModel.h"
|
||||
#include "layNetlistBrowserModel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
|
|
@ -257,6 +258,45 @@ NetlistBrowserTreeModel::build_circuits_to_index (size_t nprod, const std::pair<
|
|||
}
|
||||
}
|
||||
|
||||
static bool is_compatible (const std::pair<const db::Circuit *, const db::Circuit *> &a, const std::pair<const db::Circuit *, const db::Circuit *> &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<const db::Circuit *, const db::Circuit *> sc (p->first ? p->first->circuit_ref () : 0, p->second ? p->second->circuit_ref (): 0);
|
||||
std::pair<const db::Circuit *, const db::Circuit *> circuit = circuits_from_index (idx);
|
||||
|
||||
size_t count = mp_indexer->child_circuit_count (circuit);
|
||||
for (size_t n = count; n > 0; ) {
|
||||
--n;
|
||||
std::pair<const db::Circuit *, const db::Circuit *> 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<const db::Circuit *, const db::Circuit *> &circuits) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ namespace lay
|
|||
{
|
||||
|
||||
class IndexedNetlistModel;
|
||||
struct NetlistObjectPath;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// NetlistBrowserTreeModel definition
|
||||
|
|
@ -77,6 +78,7 @@ public:
|
|||
|
||||
std::pair<const db::Circuit *, const db::Circuit *> circuits_from_index (const QModelIndex &index) const;
|
||||
QModelIndex index_from_circuits (const std::pair<const db::Circuit *, const db::Circuit *> &circuits) const;
|
||||
QModelIndex index_from_netpath (const NetlistObjectPath &path) const;
|
||||
|
||||
private:
|
||||
NetlistBrowserTreeModel (const NetlistBrowserTreeModel &);
|
||||
|
|
|
|||
Loading…
Reference in New Issue