HAL
pin_tree_model.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
6 #include "hal_core/netlist/net.h"
8 
9 #include <QDebug>
10 #include <QVector>
11 
12 namespace hal
13 {
14 
15  PinTreeItem::PinTreeItem(const std::string &pinName, QString pinDirection, QString pinType, QString netName)
16  :mPinName(pinName), mPinDirection(pinDirection), mPinType(pinType), mNetName(netName)
17  {;}
18 
20  {;}
21 
22  QVariant PinTreeItem::getData(int index) const
23  {
24  switch (index)
25  {
26  case 0: {
27  QVariant qvPinName = QVariant(QString::fromStdString(mPinName));
28  return qvPinName;
29  break;}
30  case 1: {
31  QVariant qvPinDirection = QVariant(mPinDirection);
32  return qvPinDirection;
33  break;}
34  case 2: {
35  QVariant qvPinType = QVariant(mPinType);
36  return qvPinType;
37  break;}
38  case 3: {
39  QVariant qvNetName = QVariant(mNetName);
40  return qvNetName;
41  break;}
42  }
43  return QVariant();
44  }
45 
47  {
48  mPinName = data[0].toString().toStdString();
49  mPinDirection = data[1].toString();
50  mPinType = data[2].toString();
51  mNetName = data[3].toString();
52  }
53 
54  void PinTreeItem::setDataAtIndex(int index, QVariant &data)
55  {
56  switch (index)
57  {
58  case 0: {
59  mPinName = data.toString().toStdString();
60  break;}
61  case 1: {
62  mPinDirection = data.toString();
63  break;}
64  case 2: {
65  mPinType = data.toString();
66  break;}
67  case 3: {
68  mNetName = data.toString();
69  break;}
70  }
71 
72 
73  }
74 
76 
78  {
79  return 4;
80  }
81 
83  {
84  setHeaderLabels(QStringList() << "Name"
85  << "Direction"
86  << "Type"
87  << "Connected Net");
88 
89  //added to store a list of (multiple) net ids in a given treeitem (perhaps dont do this
90  //at all, handle it in the view? (since the gate-id and pin name is accessable, the nets can be evaluated there
91  qRegisterMetaType<QList<int>>();
92  }
93 
95  {
96  delete mRootItem;
97  }
98 
100  {
102  mPinGroupToTreeItem.clear();
103  mGateId = -1;
104  }
105 
107  {
108  clear();
109  mGateId = g->get_id();
110 
111  beginResetModel();
112  GateType* gateType = g->get_type();
113  for (auto pin : gateType->get_pins())
114  {
115  PinTreeItem* pinItem = new PinTreeItem();
116  //get all infos for that pin
117  const std::string& grouping = pin->get_group().first->get_name();
118  PinDirection direction = pin->get_direction();
120  QString pinType = QString::fromStdString(enum_to_string(pin->get_type()));
121 
122  //evaluate netname (in case of inout multiple possible nets), method depends on pindirection (kind of ugly switch)
123  QString netName = "";
124  QList<u32> netIDs;
125  switch (direction)
126  {
127  case PinDirection::input:
128  if (g->get_fan_in_net(pin))
129  {
130  netName = QString::fromStdString(g->get_fan_in_net(pin)->get_name());
131  netIDs.append(g->get_fan_in_net(pin)->get_id());
132  }
133  break;
134  //netName = (g->get_fan_in_net(pin)) ? QString::fromStdString(g->get_fan_in_net(pin)->get_name()) : "" ; break;
136  if (g->get_fan_out_net(pin))
137  {
138  netName = QString::fromStdString(g->get_fan_out_net(pin)->get_name());
139  netIDs.append(g->get_fan_out_net(pin)->get_id());
140  }
141  break;
142  //netName = (g->get_fan_out_net(pin)) ? QString::fromStdString(g->get_fan_out_net(pin)->get_name()) : "" ; break;
143  case PinDirection::inout: //must take input and output net into account
144  if (g->get_fan_in_net(pin))
145  {
146  netName += QString::fromStdString(g->get_fan_in_net(pin)->get_name());
147  netIDs.append(g->get_fan_in_net(pin)->get_id());
148  }
149  if (g->get_fan_out_net(pin))
150  {
151  if (!netName.isEmpty())
152  netName += " / "; //add / when there is a input net to seperate it from the output net
153  netName += QString::fromStdString(g->get_fan_out_net(pin)->get_name());
154  netIDs.append(g->get_fan_out_net(pin)->get_id());
155  }
156  break;
157  default:
158  break; //none and internal, dont know how to handle internal (whatever an internal pin is)
159  }
160 
161  pinItem->setData(QList<QVariant>() << QString::fromStdString(pin->get_name()) << pinDirection << pinType << netName);
162  pinItem->setType(PinTreeItem::Pin);
163  pinItem->setNetIds(netIDs);
164  if (!grouping.empty())
165  {
166  PinTreeItem* pingroupItem = dynamic_cast<PinTreeItem*>(mPinGroupToTreeItem.value(grouping, nullptr)); //since its a map, its okay
167  if (!pingroupItem)
168  {
169  //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types
170  pingroupItem = new PinTreeItem(grouping, pinDirection, pinType, "");
171  pingroupItem->setType(PinTreeItem::Group);
172  mRootItem->appendChild(pingroupItem);
173  mPinGroupToTreeItem.insert(grouping, pingroupItem);
174  }
175  pingroupItem->appendChild(pinItem);
176  }
177  else
178  mRootItem->appendChild(pinItem);
179  }
180  endResetModel();
181  }
182 
184  {
185  return mGateId;
186  }
187 
189  {
190  Gate* g = gNetlist->get_gate_by_id(mGateId);
191  if (!g)
192  return 0;
193 
194  return g->get_type()->get_pins().size();
195  }
196 
197 
198 
199 } // 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
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
void setNetIds(const QList< u32 > &nids)
QVariant getData(int column) const override
int getColumnCount() const override
void setDataAtIndex(int index, QVariant &data) override
void setType(Type tp)
void appendData(QVariant data) override
void setData(QList< QVariant > data) override
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