HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
dataflow_interaction.cpp
Go to the documentation of this file.
2 #include "gui/gui_globals.h"
3 #include "gui/gui_api/gui_api.h"
4 #include <QRegularExpression>
5 #include <QGraphicsView>>
6 #include "QGVCore/QGVNode.h"
7 #include "QGVCore/QGVEdge.h"
8 #include <QMenu>
9 
10 namespace hal {
11  DataflowInteractionRegistration DataflowInteractionRegistration::sRegistration;
12 
13  QGVInteraction* constructDataflowInteraction(QGVScene* parent)
14  {
15  return new DataflowInteraction(parent);
16  }
17 
19  {
20  QGVInteraction::registerConstructorForPlugin("dataflow", constructDataflowInteraction);
21  }
22 
24  : QGVInteraction(parent), mScene(parent)
25  {
26  connect(gSelectionRelay, &SelectionRelay::selectionChanged, this, &DataflowInteraction::handleHALSelectionChanged);
27  connect(gNetlistRelay, &NetlistRelay::moduleNameChanged, this, &DataflowInteraction::handleHALModuleNameChanged);
28  connect(parent, &QGVScene::edgeContextMenu, this, &DataflowInteraction::handleEdgeContextMenu);
29  connect(parent, &QGraphicsScene::selectionChanged, this, &DataflowInteraction::handleQGVSelectionChanged);
30  }
31 
33  {
34  Q_UNUSED(edge);
35  }
36 
38  {
39  QRegularExpression reDot("(\\d+) bit \\(id (\\d+)\\)");
40  QRegularExpressionMatch mDot = reDot.match(node->label());
41  if (mDot.hasMatch())
42  {
43  QRegularExpression reDana("DANA_module_(\\d+)");
44  for (const Module* m : gNetlist->get_modules())
45  {
46  QRegularExpressionMatch mDana = reDana.match(QString::fromStdString(m->get_name()));
47  if (mDana.hasMatch() && mDana.captured(1) == mDot.captured(2))
48  {
49  mModuleHash[m->get_id()] = node;
50  mNodeHash[node] = m->get_id();
51  }
52  }
53  }
54  }
55 
56  void DataflowInteraction::handleQGVSelectionChanged()
57  {
58  if (mDisableHandler) return;
59  mDisableHandler = true;
60  std::vector<u32> modIds;
61  for (QGraphicsItem* it : mScene->selectedItems())
62  {
63  QGVNode* node = dynamic_cast<QGVNode*>(it);
64  if (!node) continue;
65  u32 modId = mNodeHash.value(node,0);
66  if (!modId) continue;
67  modIds.push_back(modId);
68  }
69  gGuiApi->selectModule(modIds,true,true);
70  mDisableHandler = false;
71  }
72 
73  void DataflowInteraction::handleEdgeContextMenu(QGVEdge* edge)
74  {
75  if (!edge->headNode() || !edge->tailNode() || edge->headNode() == edge->tailNode())
76  return;
77 
78  u32 tailModuleId = mNodeHash.value(edge->tailNode(),0);
79  u32 headModuleId = mNodeHash.value(edge->headNode(),0);
80  if (!tailModuleId || !headModuleId || tailModuleId == headModuleId) return;
81  mDisableHandler = true;
82  QMenu menu;
83  QAction* act = menu.addAction(QString("Isolate path from mod_%1 to mod_%2 in new view").arg(tailModuleId).arg(headModuleId));
84  connect(act, &QAction::triggered, this, [tailModuleId,headModuleId](){GuiApiClasses::View::isolateModuleToModulePathInNewView(tailModuleId,headModuleId);});
85  menu.exec(QCursor::pos());
86  mDisableHandler = false;
87  }
88 
89  void DataflowInteraction::handleHALModuleNameChanged(Module* m)
90  {
91  if (!mScene) return;
92  mDisableHandler = true;
93  u32 modId = m->get_id();
94  QString modName = QString::fromStdString(m->get_name());
95  QGVNode* node = mModuleHash.value(modId, nullptr);
96  if (node)
97  {
98  node->setLabel(modName);
99  node->update();
100  }
101  mDisableHandler = false;
102  }
103 
104  void DataflowInteraction::handleHALSelectionChanged(void* sender)
105  {
106  Q_UNUSED(sender);
107  if (!mScene) return;
108 
109  if (mDisableHandler) return;
110  mDisableHandler = true;
111 
112  mScene->clearSelection();
113  for (u32 modId : gSelectionRelay->selectedModulesList())
114  {
115  QGVNode* node = mModuleHash.value(modId, nullptr);
116  if (node)
117  {
118  node->setSelected(true);
119  for (QGraphicsView* gv : mScene->views())
120  gv->ensureVisible(node);
121  }
122  }
123  mDisableHandler = false;
124  }
125 }
void registerNode(QGVNode *node) override
void registerEdge(QGVEdge *scene) override
DataflowInteraction(QGVScene *parent)
static int isolateModuleToModulePathInNewView(u32 fromModId, u32 toModId)
Definition: gui_api.cpp:449
void selectModule(u32 module_id, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:200
const std::vector< Module * > & get_modules() const
Definition: netlist.cpp:624
void moduleNameChanged(Module *m) const
void selectionChanged(void *sender)
QList< u32 > selectedModulesList() const
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
QGVInteraction * constructDataflowInteraction(QGVScene *parent)
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: gui_globals.h:69
NetlistRelay * gNetlistRelay
Definition: gui_globals.h:74
GuiApi * gGuiApi
Definition: plugin_gui.cpp:86
void triggered(bool checked)
QPoint pos()
void selectionChanged()
const T value(const Key &key) const const
QAction * addAction(const QString &text)
QAction * exec()
QRegularExpressionMatch match(const QString &subject, int offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
QString captured(int nth) const const
bool hasMatch() const const
QString fromStdString(const std::string &str)