HAL
net_endpoint_table.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
9 
10 #include <QApplication>
11 #include <QClipboard>
12 #include <QDebug>
13 #include <QHeaderView>
14 #include <QMenu>
15 
16 namespace hal
17 {
18 
19  NetEndpointTable::NetEndpointTable(EndpointTableModel* model, QWidget* parent) : QTableView(parent), mEndpointModel(model)
20  {
29  verticalHeader()->hide();
30  setModel(mEndpointModel);
31 
33 
34  //connections
36  }
37 
39  {
40  Net* n = gNetlist->get_net_by_id(netID);
41 
42  setNet(n);
43  }
44 
46  {
47  if (!n)
48  return;
49 
50  mEndpointModel->setNet(n);
51 
52  QModelIndex unused;
53 
54  fitSizeToContent();
55 
56  Q_EMIT updateText(mEndpointModel->typeString() + " (" + QString::number(mEndpointModel->rowCount(unused)) + ")");
57  }
58 
60  {
61  mEndpointModel->clear();
62  }
63 
65  {
66  QModelIndex idx = indexAt(pos);
67 
68  if (!idx.isValid())
69  return;
70 
71  u32 gateID = mEndpointModel->getGateIDFromIndex(idx);
72  Gate* gate = gNetlist->get_gate_by_id(gateID);
73  QString pin = mEndpointModel->getPinNameFromIndex(idx);
74  QString desc = mEndpointModel->typeString().toLower();
75  QString netIDStr = QString::number(mEndpointModel->getCurrentNetID());
76  QString gateIDStr = QString::number(gateID);
77 
78  QMenu menu;
79 
80  menu.addAction("Gate pin name to clipboard", [pin](){
82  });
83 
84  QString pythonCommand ="netlist.get_gate_by_id(" + gateIDStr + ").%1(\"" + pin + "\")";
85  pythonCommand = (mEndpointModel->getType() == EndpointTableModel::Type::source) ? pythonCommand.arg("get_fan_out_endpoint") : pythonCommand.arg("get_fan_in_endpoint");
86 
87  menu.addAction(QIcon(":/icons/python"), "Extract endpoint as python code (copy to clipboard)", [pythonCommand](){
88  QApplication::clipboard()->setText(pythonCommand);
89  });
90 
91  ModuleContextMenu::addGateSubmenu(&menu, gateID);
92 
94  {}, std::vector<u32>({gateID}), {});
95 
96  menu.exec(this->viewport()->mapToGlobal(pos));
97  }
98 
99  void NetEndpointTable::fitSizeToContent()
100  {
104 
105  int rows = mEndpointModel->rowCount();
106  int columns = mEndpointModel->columnCount();
107 
108  int w = 0;
109  int h = 0;
110 
111  //necessary to test if the table is empty, otherwise (due to the resizeColumnsToContents function)
112  //is the table's width far too big, so just set 0 as the size
113  if (rows != 0)
114  {
115  w = verticalHeader()->width() + 4; // +4 seems to be needed
116  for (int i = 0; i < columns; i++)
117  w += columnWidth(i); // seems to include gridline
118 
119  h = horizontalHeader()->height() + 4;
120  for (int i = 0; i < rows; i++)
121  h += rowHeight(i);
122 
123  w = w + 5; //no contemporary source exists why 5 is the magic number here (my guess would be it's the width of the hidden scrollbar)
124  }
125  setFixedHeight(h);
126  setMinimumWidth(w);
128  update();
129  updateGeometry();
130  }
131 
132  void NetEndpointTable::addSourceOurDestinationToSelection(u32 gateID, QString pin, bool clearSelection)
133  {
134  //setfocus action??
135  auto gate = gNetlist->get_gate_by_id(gateID);
136  if (!gate)
137  return;
138  if (clearSelection)
140  gSelectionRelay->addGate(gateID);
141  std::vector<std::string> pins;
143 
144  if (mEndpointModel->getType() == EndpointTableModel::Type::source)
145  {
146  pins = gate->get_type()->get_output_pin_names();
148  }
149  else
150  {
151  pins = gate->get_type()->get_input_pin_names();
153  }
154  auto index = std::distance(pins.begin(), std::find(pins.begin(), pins.end(), pin.toStdString()));
157  }
158 } // namespace hal
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
A model to display endpoint data.
u32 getGateIDFromIndex(const QModelIndex &index)
QString getPinNameFromIndex(const QModelIndex &index)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: gate.h:58
static void addPluginSubmenus(QMenu *contextMenu, Netlist *netlist, const std::vector< u32 > &modules, const std::vector< u32 > &gates, const std::vector< u32 > &nets)
static void addGateSubmenu(QMenu *contextMenu, u32 id)
void handleContextMenuRequested(const QPoint &pos)
void updateText(const QString &text)
NetEndpointTable(EndpointTableModel *model, QWidget *parent=nullptr)
Definition: net.h:58
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
void setFocus(ItemType ftype, u32 fid, Subfocus sfoc=Subfocus::None, u32 sfinx=0)
void relaySelectionChanged(void *sender)
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: plugin_gui.cpp:80
n
Definition: test.py:6
quint32 u32
std::vector< PinInformation > pins
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
QWidget * viewport() const const
void setText(const QString &text, QClipboard::Mode mode)
QClipboard * clipboard()
void setStretchLastSection(bool stretch)
QAction * addAction(const QString &text)
QAction * exec()
bool isValid() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)
QString toLower() const const
std::string toStdString() const const
CustomContextMenu
ScrollBarAlwaysOff
int columnWidth(int column) const const
QHeaderView * horizontalHeader() const const
virtual QModelIndex indexAt(const QPoint &pos) const const override
void resizeColumnsToContents()
void resizeRowsToContents()
int rowHeight(int row) const const
virtual void setModel(QAbstractItemModel *model) override
QHeaderView * verticalHeader() const const
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
void customContextMenuRequested(const QPoint &pos)
void setFocusPolicy(Qt::FocusPolicy policy)
void hide()
QPoint mapToGlobal(const QPoint &pos) const const
void setMinimumWidth(int minw)
void setFixedHeight(int h)
void setSizePolicy(QSizePolicy)
void update()
void updateGeometry()