HAL
gate_pins_tree_model.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
6 #include "hal_core/netlist/net.h"
7 
8 #include <QDebug>
9 #include <QVector>
10 
11 namespace hal
12 {
13 
14  GatePinsTreeItem::GatePinsTreeItem(const std::string &pinName, PinDirection pinDirection, PinType pinType, QString netName, int inx)
15  :mPinName(pinName), mPinDirection(pinDirection), mPinType(pinType), mNetName(netName), mIndex(inx)
16  {;}
17 
19  {;}
20 
22  {
23  switch (index)
24  {
25  case 0:
26  return QString::fromStdString(mPinName);
27  case 1:
28  return QString::fromStdString(enum_to_string(mPinDirection));
29  case 2:
30  return QString::fromStdString(enum_to_string(mPinType));
31  case 3:
32  return mNetName;
33  case 4:
34  if (mType == GatePinsTreeItem::Group)
35  return (QString("[%1] %2").arg(getChildCount()).arg(mIndex ? "desc" : "asc"));
36  return mIndex;
37  }
38  return QVariant();
39  }
40 
42  {
43  Q_ASSERT(data.size() >= 5);
44  mPinName = data[0].toString().toStdString();
45  mPinDirection = (PinDirection) data[1].toInt();
46  mPinType = (PinType) data[2].toInt();
47  mNetName = data[3].toString();
48  mIndex = data[4].toInt();
49  }
50 
52  {
53  switch (column)
54  {
55  case 0:
56  mPinName = data.toString().toStdString();
57  break;
58  case 1:
59  mPinDirection = (PinDirection) data.toInt();
60  break;
61  case 2:
62  mPinType = (PinType) data.toInt();
63  break;
64  case 3:
65  mNetName = data.toString();
66  break;
67  case 4:
68  mIndex = data.toInt();
69  break;
70  }
71 
72 
73  }
74 
76 
78  {
79  return 5;
80  }
81 
83  {
84  setHeaderLabels(QStringList() << "Name"
85  << "Direction"
86  << "Type"
87  << "Connected Net"
88  << "Index");
89 
90  //added to store a list of (multiple) net ids in a given treeitem (perhaps dont do this
91  //at all, handle it in the view? (since the gate-id and pin name is accessable, the nets can be evaluated there
92  qRegisterMetaType<QList<int>>();
93  }
94 
96  {
97  delete mRootItem;
98  }
99 
101  {
103  mPinGroupToTreeItem.clear();
104  mGateId = -1;
105  }
106 
108  {
109  clear();
110  mGateId = g->get_id();
111 
112  beginResetModel();
113  GateType* gateType = g->get_type();
114  for (auto pin : gateType->get_pins())
115  {
116  GatePinsTreeItem* pinItem = new GatePinsTreeItem();
117  //get all infos for that pin
118  const PinGroup<GatePin>* pg = pin->get_group().first;
119  const std::string& grpName = pg->get_name();
120  int iDescending = pg->is_ascending() ? 0 : 1;
121  int inx = pin->get_group().second;
122  PinDirection pinDirection = pin->get_direction();
123  PinType pinType = pin->get_type();
124 
125  //evaluate netname (in case of inout multiple possible nets), method depends on pindirection (kind of ugly switch)
126  QString netName = "";
127  QList<u32> netIDs;
128  switch (pinDirection)
129  {
130  case PinDirection::input:
131  if (g->get_fan_in_net(pin))
132  {
133  netName = QString::fromStdString(g->get_fan_in_net(pin)->get_name());
134  netIDs.append(g->get_fan_in_net(pin)->get_id());
135  }
136  break;
137  //netName = (g->get_fan_in_net(pin)) ? QString::fromStdString(g->get_fan_in_net(pin)->get_name()) : "" ; break;
139  if (g->get_fan_out_net(pin))
140  {
141  netName = QString::fromStdString(g->get_fan_out_net(pin)->get_name());
142  netIDs.append(g->get_fan_out_net(pin)->get_id());
143  }
144  break;
145  //netName = (g->get_fan_out_net(pin)) ? QString::fromStdString(g->get_fan_out_net(pin)->get_name()) : "" ; break;
146  case PinDirection::inout: //must take input and output net into account
147  if (g->get_fan_in_net(pin))
148  {
149  netName += QString::fromStdString(g->get_fan_in_net(pin)->get_name());
150  netIDs.append(g->get_fan_in_net(pin)->get_id());
151  }
152  if (g->get_fan_out_net(pin))
153  {
154  if (!netName.isEmpty())
155  netName += " / "; //add / when there is a input net to seperate it from the output net
156  netName += QString::fromStdString(g->get_fan_out_net(pin)->get_name());
157  netIDs.append(g->get_fan_out_net(pin)->get_id());
158  }
159  break;
160  default:
161  break; //none and internal, dont know how to handle internal (whatever an internal pin is)
162  }
163 
164  pinItem->setData(QList<QVariant>()
165  << QString::fromStdString(pin->get_name())
166  << (int) pinDirection
167  << (int) pinType
168  << netName << inx);
169  pinItem->setType(GatePinsTreeItem::Pin);
170  pinItem->setNetIds(netIDs);
171  if (!grpName.empty())
172  {
173  GatePinsTreeItem* pingroupItem = dynamic_cast<GatePinsTreeItem*>(mPinGroupToTreeItem.value(grpName, nullptr)); //since its a map, its okay
174  if (!pingroupItem)
175  {
176  //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types
177  pingroupItem = new GatePinsTreeItem(grpName, pinDirection, pinType, "", iDescending);
178  pingroupItem->setType(GatePinsTreeItem::Group);
179  mRootItem->appendChild(pingroupItem);
180  mPinGroupToTreeItem.insert(grpName, pingroupItem);
181  }
182  pingroupItem->appendChild(pinItem);
183  }
184  else
185  mRootItem->appendChild(pinItem);
186  }
187  endResetModel();
188  }
189 
191  {
192  return mGateId;
193  }
194 
196  {
197  Gate* g = gNetlist->get_gate_by_id(mGateId);
198  if (!g)
199  return 0;
200 
201  return g->get_type()->get_pins().size();
202  }
203 
204 
205 
206 } // namespace hal
virtual int getChildCount() const
virtual void appendChild(BaseTreeItem *child)
The BaseTreeModel implements generic standard functions of a tree model.
RootTreeItem * mRootItem
virtual void clear()
void setHeaderLabels(const QStringList &label)
Definition: gate.h:58
void appendData(QVariant data) override
int getColumnCount() const override
void setDataAtColumn(int column, QVariant &data) override
void setData(QList< QVariant > data) override
QVariant getData(int column) const override
void setNetIds(const QList< u32 > &nids)
GatePinsTreeModel(QObject *parent=nullptr)
std::vector< GatePin * > get_pins(const std::function< bool(GatePin *)> &filter=nullptr) const
Definition: gate_type.cpp:210
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
const std::string & get_name() const
Definition: pin_group.h:150
bool is_ascending() const
Definition: pin_group.h:273
PinDirection
Definition: pin_direction.h:36
Netlist * gNetlist
Definition: plugin_gui.cpp:80
PinType
Definition: pin_type.h:36
std::string enum_to_string(T e)
Definition: enums.h:52
void append(const T &value)
QString fromStdString(const std::string &str)
bool isEmpty() const const