HAL
module_table_model.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
5 #include "hal_core/netlist/net.h"
6 
7 #include <QDebug>
8 
9 namespace hal
10 {
12  {
13  //connections
16  }
17 
19  {
21  mEntries.clear();
22  endResetModel();
23 
24  mModIds.clear();
25  }
26 
27  int ModuleTableModel::rowCount(const QModelIndex& parent) const
28  {
29  Q_UNUSED(parent)
30 
31  return mEntries.size();
32  }
33 
34  int ModuleTableModel::columnCount(const QModelIndex& parent) const
35  {
36  Q_UNUSED(parent)
37 
38  return 4;
39  }
40 
41  QVariant ModuleTableModel::data(const QModelIndex& index, int role) const
42  {
43  if (index.row() < mEntries.size() && index.column() < 4)
44  {
45  if (role == Qt::DisplayRole)
46  {
47  switch (index.column())
48  {
49  case 0:
50  return mEntries[index.row()].name;
51  case 1:
52  return mEntries[index.row()].id;
53  case 2:
54  return mEntries[index.row()].type;
55  case 3:
56  return mEntries[index.row()].used_port;
57  }
58  }
59  }
60 
61  return QVariant();
62  }
63 
64  QVariant ModuleTableModel::headerData(int section, Qt::Orientation orientation, int role) const
65  {
66  if (role != Qt::DisplayRole)
67  return QVariant();
68 
69  if (orientation == Qt::Horizontal)
70  {
71  switch (section)
72  {
73  case 0:
74  return "Name";
75  case 1:
76  return "ID";
77  case 2:
78  return "Type";
79  case 3:
80  return "Used Port";
81  default:
82  return QVariant();
83  }
84  }
85 
86  return section + 1;
87  }
88 
90  {
91  if (net == nullptr)
92  return;
93 
94  mNetId = net->get_id();
95  mModIds.clear();
96  QList<Entry> newEntryList;
97 
98  //1. variant: simple brute force through all modules
99  //2. variant: more complex algorithm:
100  // use net sources/destinations, crawl through parent-modules, keep track of already
101  // visited modules to not list modules (ports) twice
102 
103  //1.variant
104  for (auto const& m : gNetlist->get_modules())
105  {
106  if (const auto pin = m->get_pin_by_net(net); pin != nullptr)
107  {
108  Entry newEntry;
109 
110  newEntry.name = QString::fromStdString(m->get_name());
111  newEntry.id = m->get_id();
112  newEntry.type = QString::fromStdString(m->get_type());
113  newEntry.used_port = QString::fromStdString(pin->get_name());
114  newEntry.pinId = pin->get_id();
115  newEntryList.append(newEntry);
116  mModIds.insert((int)m->get_id());
117  }
118  }
119 
120  beginResetModel();
121  mEntries = newEntryList;
122  endResetModel();
123 
124  // auto portMap = m->get_input_port_names();
125  // auto it = portMap.find(net);
126  // if(it != portMap.end())
127  // {
128  // Entry newEntry;
129 
130  // newEntry.name = QString::fromStdString(m->get_name());
131  // newEntry.id = m->get_id();
132  // newEntry.type = QString::fromStdString(m->get_type());
133  // newEntry.used_port = QString::fromStdString(it->second);
134 
135  // newEntryList.append(newEntry);
136 
137  // }
138 
139  // portMap = m->get_output_port_names();
140  // it = portMap.find(net);
141  // if(it != portMap.end())
142  // {
143  // Entry newEntry;
144 
145  // newEntry.name = QString::fromStdString(m->get_name());
146  // newEntry.id = m->get_id();
147  // newEntry.type = QString::fromStdString(m->get_type());
148  // newEntry.used_port = QString::fromStdString(it->second);
149 
150  // newEntryList.append(newEntry);
151 
152  // }
153  // }
154  }
155 
157  {
158  return mNetId;
159  }
160 
162  {
163  return mEntries[index.row()].id;
164  }
165 
167  {
168  return mEntries[index.row()].used_port;
169  }
170 
172  {
173  return mEntries[index.row()].pinId;
174  }
175 
177  {
178  return mEntries[index.row()].name;
179  }
180 
182  {
183  Q_UNUSED(pev);
184  Q_UNUSED(pgid);
185  if (mModIds.find((int)m->get_id()) != mModIds.end())
186  {
187  Net* net = gNetlist->get_net_by_id(mNetId);
188  if (net != nullptr)
189  {
190  std::unordered_set<Net*> inputNets = m->get_input_nets();
191  std::unordered_set<Net*> outputNets = m->get_output_nets();
192  if (inputNets.find(net) != inputNets.end() || outputNets.find(net) != outputNets.end())
193  {
194  setNet(net);
195  }
196  }
197  }
198  }
199 
201  {
202  if (mModIds.find((int)m->get_id()) != mModIds.end())
203  {
204  Net* net = gNetlist->get_net_by_id(mNetId);
205  if (net != nullptr)
206  {
207  setNet(net);
208  }
209  }
210  }
211 } // namespace hal
const std::unordered_set< Net * > & get_input_nets() const
Definition: module.cpp:540
const std::unordered_set< Net * > & get_output_nets() const
Definition: module.cpp:545
u32 get_id() const
Definition: module.cpp:82
u32 getPinIDFromIndex(const QModelIndex &index)
QVariant data(const QModelIndex &index, int role) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
ModuleTableModel(QObject *parent=nullptr)
QString getModuleNameFromIndex(const QModelIndex &index)
void handleModulePortsChanged(Module *m, PinEvent pev, u32 pgid)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QString getPortNameFromIndex(const QModelIndex &index)
u32 getModuleIDFromIndex(const QModelIndex &index)
void handleModuleRemoved(Module *m)
Definition: net.h:58
const std::vector< Module * > & get_modules() const
Definition: netlist.cpp:624
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
void moduleRemoved(Module *m) const
void modulePortsChanged(Module *m, PinEvent pev, u32 pgid) const
PinEvent
Definition: pin_event.h:42
Netlist * gNetlist
Definition: plugin_gui.cpp:80
NetlistRelay * gNetlistRelay
Definition: plugin_gui.cpp:81
quint32 u32
Net * net
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void append(const T &value)
void clear()
int size() const const
int column() const const
int row() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void clear()
QSet::iterator end()
QSet::iterator find(const T &value)
QSet::iterator insert(const T &value)
QString fromStdString(const std::string &str)
DisplayRole
Orientation