HAL
net_info_table.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 <QInputDialog>
9 #include <QMenu>
10 
11 namespace hal
12 {
13  const QString NetInfoTable::nameRowKey = "Name";
14  const QString NetInfoTable::idRowKey = "ID";
15  const QString NetInfoTable::typeRowKey = "Type";
16  const QString NetInfoTable::noOfSrcRowKey = "Number of Sources";
17  const QString NetInfoTable::noOfDstRowKey = "Number of Destinations";
18 
19  NetInfoTable::NetInfoTable(QWidget* parent) : GeneralTableWidget(parent), mNet(nullptr)
20  {
21  mNameEntryContextMenu = new QMenu();
22  mNameEntryContextMenu->addAction("Name to clipboard", std::bind(&NetInfoTable::copyName, this));
23  mNameEntryContextMenu->addSection("Misc");
24  mNameEntryContextMenu->addAction("Change name", std::bind(&NetInfoTable::changeName, this));
25  mNameEntryContextMenu->addSection("Phyton");
26  mNameEntryContextMenu->addAction(QIcon(":/icons/python"), "Get name", std::bind(&NetInfoTable::pyCopyName, this));
27 
28  mIdEntryContextMenu = new QMenu();
29  mIdEntryContextMenu->addAction("ID to clipboard", std::bind(&NetInfoTable::copyId, this));
30  mIdEntryContextMenu->addSection("Python");
31  mIdEntryContextMenu->addAction(QIcon(":/icons/python"), "Get ID", std::bind(&NetInfoTable::pyCopyId, this));
32 
33  mTypeEntryContextMenu = new QMenu();
34  mTypeEntryContextMenu->addAction("Type to clipboard", std::bind(&NetInfoTable::copyType, this));
35  mTypeEntryContextMenu->addSection("Python");
36  mTypeEntryContextMenu->addAction(QIcon(":/icons/python"), "Get type", std::bind(&NetInfoTable::pyCopyType, this));
37 
38  mNumSrcsEntryContextMenu = new QMenu();
39  mNumSrcsEntryContextMenu->addAction("Number of sources to clipboard", std::bind(&NetInfoTable::copyNumberOfSrcs, this));
40  mNumSrcsEntryContextMenu->addSection("Python");
41  mNumSrcsEntryContextMenu->addAction(QIcon(":/icons/python"), "Get sources", std::bind(&NetInfoTable::pyCopySrcs, this));
42 
43  mNumDstsEntryContextMenu = new QMenu();
44  mNumDstsEntryContextMenu->addAction("Number of destinations to clipboard", std::bind(&NetInfoTable::copyNumberOfDsts, this));
45  mNumDstsEntryContextMenu->addSection("Python");
46  mNumDstsEntryContextMenu->addAction(QIcon(":/icons/python"), "Get destinations", std::bind(&NetInfoTable::pyCopyDsts, this));
47 
48  connect(gNetlistRelay, &NetlistRelay::netRemoved, this, &NetInfoTable::handleNetRemoved);
49  connect(gNetlistRelay, &NetlistRelay::netNameChanged, this, &NetInfoTable::handleNetNameChanged);
50  connect(gNetlistRelay, &NetlistRelay::netSourceAdded, this, &NetInfoTable::handleSrcDstChanged);
51  connect(gNetlistRelay, &NetlistRelay::netSourceRemoved, this, &NetInfoTable::handleSrcDstChanged);
52  connect(gNetlistRelay, &NetlistRelay::netDestinationAdded, this, &NetInfoTable::handleSrcDstChanged);
53  connect(gNetlistRelay, &NetlistRelay::netDestinationRemoved, this, &NetInfoTable::handleSrcDstChanged);
54  connect(gNetlistRelay, &NetlistRelay::netlistMarkedGlobalInput, this, &NetInfoTable::handleNetTypeChanged);
55  connect(gNetlistRelay, &NetlistRelay::netlistUnmarkedGlobalInput, this, &NetInfoTable::handleNetTypeChanged);
56  connect(gNetlistRelay, &NetlistRelay::netlistMarkedGlobalOutput, this, &NetInfoTable::handleNetTypeChanged);
57  connect(gNetlistRelay, &NetlistRelay::netlistUnmarkedGlobalOutput, this, &NetInfoTable::handleNetTypeChanged);
58  }
59 
61  {
63  {
64  mNet = net;
65 
66  setRow(nameRowKey, name(), mNameEntryContextMenu);
67  setRow(idRowKey, id(), mIdEntryContextMenu);
68  setRow(typeRowKey, type(), mTypeEntryContextMenu);
69  setRow(noOfSrcRowKey, numberOfSrcs(), mNumSrcsEntryContextMenu);
70  setRow(noOfDstRowKey, numberOfDsts(), mNumDstsEntryContextMenu);
71 
72  adjustSize();
73  }
74  }
75 
76  QString NetInfoTable::name() const
77  {
78  return QString::fromStdString(mNet->get_name());
79  }
80 
81  QString NetInfoTable::id() const
82  {
83  return QString::number(mNet->get_id());
84  }
85 
86  QString NetInfoTable::type() const
87  {
88  QString type = "";
89 
90  if (mNet->is_global_input_net())
91  type = "Global input";
92  else if (mNet->is_global_output_net())
93  type = "Global output";
94  else if (mNet->is_unrouted())
95  type = "Unrouted";
96  else
97  type = "Internal";
98 
99  return type;
100  }
101 
102  QString NetInfoTable::numberOfSrcs() const
103  {
104  return QString::number(mNet->get_num_of_sources());
105  }
106 
107  QString NetInfoTable::numberOfDsts() const
108  {
110  }
111 
112  void NetInfoTable::changeName()
113  {
114  QString oldName = QString::fromStdString(mNet->get_name());
115  QString prompt = "Change net name";
116 
117  bool confirm;
118  QString newName = QInputDialog::getText(this, prompt, "New name:", QLineEdit::Normal, oldName, &confirm);
119 
120  if (confirm)
121  {
122  ActionRenameObject* act = new ActionRenameObject(newName);
123  act->setObject(UserActionObject(mNet->get_id(), UserActionObjectType::ObjectType::Net));
124  act->exec();
125  }
126  }
127 
128  void NetInfoTable::copyName() const
129  {
130  copyToClipboard(name());
131  }
132 
133  void NetInfoTable::pyCopyName() const
134  {
136  }
137 
138  void NetInfoTable::copyId() const
139  {
140  copyToClipboard(id());
141  }
142 
143  void NetInfoTable::pyCopyId() const
144  {
146  }
147 
148  void NetInfoTable::copyType() const
149  {
151  }
152 
153  void NetInfoTable::pyCopyType() const
154  {
156  }
157 
158  void NetInfoTable::copyNumberOfSrcs() const
159  {
160  copyToClipboard(numberOfSrcs());
161  }
162 
163  void NetInfoTable::pyCopySrcs() const
164  {
166  }
167 
168  void NetInfoTable::copyNumberOfDsts() const
169  {
170  copyToClipboard(numberOfDsts());
171  }
172 
173  void NetInfoTable::pyCopyDsts() const
174  {
176  }
177 
178  void NetInfoTable::handleNetRemoved(Net* net)
179  {
180  if (mNet == net)
181  {
182  mNet = nullptr;
183 
184  const QString notification("Displayed net has been removed.");
185 
186  setRow(nameRowKey, notification, nullptr);
187  setRow(idRowKey, notification, nullptr);
188  setRow(typeRowKey, notification, nullptr);
189  setRow(noOfSrcRowKey, notification, nullptr);
190  setRow(noOfDstRowKey, notification, nullptr);
191 
192  adjustSize();
193  }
194  }
195 
196  void NetInfoTable::handleNetNameChanged(Net* net)
197  {
198  if (mNet == net)
199  refresh();
200  }
201 
202  void NetInfoTable::handleNetTypeChanged(Netlist* netlist, const u32 netId)
203  {
204  Q_UNUSED(netlist)
205 
206  if(!mNet)
207  return;
208 
209  if (mNet->get_id() == netId)
210  refresh();
211  }
212 
213  void NetInfoTable::handleSrcDstChanged(Net* net, u32 srcDstGateId)
214  {
215  Q_UNUSED(srcDstGateId)
216 
217  if (mNet == net)
218  refresh();
219  }
220 
221  void NetInfoTable::refresh()
222  {
223  setNet(mNet);
224  }
225 } // namespace hal
void setRow(const QString &key, const QString &val, QMenu *contextMenu=nullptr, std::function< void()> doubleClickAction=nullptr)
void copyToClipboard(const QString &text) const
Definition: net.h:58
u32 get_num_of_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:246
u32 get_id() const
Definition: net.cpp:88
const std::string & get_name() const
Definition: net.cpp:98
bool is_unrouted() const
Definition: net.cpp:445
bool is_global_output_net() const
Definition: net.cpp:485
u32 get_num_of_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
Definition: net.cpp:408
bool is_global_input_net() const
Definition: net.cpp:480
NetInfoTable(QWidget *parent=nullptr)
void setNet(Net *net)
bool is_net_in_netlist(const Net *net) const
Definition: netlist.cpp:348
void netDestinationRemoved(Net *n, const u32 dst_gate_id) const
void netlistUnmarkedGlobalOutput(Netlist *n, const u32 associated_data) const
void netlistUnmarkedGlobalInput(Netlist *n, const u32 associated_data) const
void netSourceAdded(Net *n, const u32 src_gate_id) const
void netSourceRemoved(Net *n, const u32 src_gate_id) const
void netlistMarkedGlobalInput(Netlist *n, const u32 associated_data) const
void netRemoved(Net *n) const
void netlistMarkedGlobalOutput(Netlist *n, const u32 associated_data) const
void netDestinationAdded(Net *n, const u32 dst_gate_id) const
void netNameChanged(Net *n) const
static QString pyCodeNetSources(u32 netId)
static QString pyCodeNetType(u32 netId)
static QString pyCodeNetId(u32 netId)
static QString pyCodeNetDestinations(u32 netId)
static QString pyCodeNetName(u32 netId)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
NetlistRelay * gNetlistRelay
Definition: plugin_gui.cpp:81
quint32 u32
PinType type
Net * net
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
QAction * addAction(const QString &text)
QAction * addSection(const QString &text)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString fromStdString(const std::string &str)
QString number(int n, int base)