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, QString pinDirection, QString 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 mPinDirection;
29  case 2:
30  return mPinType;
31  case 3:
32  return mNetName;
33  case 4:
34  if (mType == GatePinsTreeItem::Group)
35  return (mIndex ? "descending" : "ascending");
36  return mIndex;
37  }
38  return QVariant();
39  }
40 
42  {
43  Q_ASSERT(data.size() >= 5);
44  mPinName = data[0].toString().toStdString();
45  mPinDirection = data[1].toString();
46  mPinType = data[2].toString();
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 = data.toString();
60  break;
61  case 2:
62  mPinType = data.toString();
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 direction = pin->get_direction();
124  QString pinType = QString::fromStdString(enum_to_string(pin->get_type()));
125 
126  //evaluate netname (in case of inout multiple possible nets), method depends on pindirection (kind of ugly switch)
127  QString netName = "";
128  QList<u32> netIDs;
129  switch (direction)
130  {
131  case PinDirection::input:
132  if (g->get_fan_in_net(pin))
133  {
134  netName = QString::fromStdString(g->get_fan_in_net(pin)->get_name());
135  netIDs.append(g->get_fan_in_net(pin)->get_id());
136  }
137  break;
138  //netName = (g->get_fan_in_net(pin)) ? QString::fromStdString(g->get_fan_in_net(pin)->get_name()) : "" ; break;
140  if (g->get_fan_out_net(pin))
141  {
142  netName = QString::fromStdString(g->get_fan_out_net(pin)->get_name());
143  netIDs.append(g->get_fan_out_net(pin)->get_id());
144  }
145  break;
146  //netName = (g->get_fan_out_net(pin)) ? QString::fromStdString(g->get_fan_out_net(pin)->get_name()) : "" ; break;
147  case PinDirection::inout: //must take input and output net into account
148  if (g->get_fan_in_net(pin))
149  {
150  netName += QString::fromStdString(g->get_fan_in_net(pin)->get_name());
151  netIDs.append(g->get_fan_in_net(pin)->get_id());
152  }
153  if (g->get_fan_out_net(pin))
154  {
155  if (!netName.isEmpty())
156  netName += " / "; //add / when there is a input net to seperate it from the output net
157  netName += QString::fromStdString(g->get_fan_out_net(pin)->get_name());
158  netIDs.append(g->get_fan_out_net(pin)->get_id());
159  }
160  break;
161  default:
162  break; //none and internal, dont know how to handle internal (whatever an internal pin is)
163  }
164 
165  pinItem->setData(QList<QVariant>() << QString::fromStdString(pin->get_name()) << pinDirection << pinType << netName << inx);
166  pinItem->setType(GatePinsTreeItem::Pin);
167  pinItem->setNetIds(netIDs);
168  if (!grpName.empty())
169  {
170  GatePinsTreeItem* pingroupItem = dynamic_cast<GatePinsTreeItem*>(mPinGroupToTreeItem.value(grpName, nullptr)); //since its a map, its okay
171  if (!pingroupItem)
172  {
173  //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types
174  pingroupItem = new GatePinsTreeItem(grpName, pinDirection, pinType, "", iDescending);
175  pingroupItem->setType(GatePinsTreeItem::Group);
176  mRootItem->appendChild(pingroupItem);
177  mPinGroupToTreeItem.insert(grpName, pingroupItem);
178  }
179  pingroupItem->appendChild(pinItem);
180  }
181  else
182  mRootItem->appendChild(pinItem);
183  }
184  endResetModel();
185  }
186 
188  {
189  return mGateId;
190  }
191 
193  {
194  Gate* g = gNetlist->get_gate_by_id(mGateId);
195  if (!g)
196  return 0;
197 
198  return g->get_type()->get_pins().size();
199  }
200 
201 
202 
203 } // namespace hal
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
std::string enum_to_string(T e)
Definition: enums.h:52
PinDirection direction
void append(const T &value)
QString fromStdString(const std::string &str)
bool isEmpty() const const