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