HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
clock_tree_extractor_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  ClockTreeExtractorInteractionRegistration ClockTreeExtractorInteractionRegistration::sRegistration;
12 
13  QGVInteraction* constructClockTreeExtractorInteraction(QGVScene* parent)
14  {
15  return new ClockTreeExtractorInteraction(parent);
16  }
17 
19  {
20  QGVInteraction::registerConstructorForPlugin("clock_tree_extractor", constructClockTreeExtractorInteraction);
21  }
22 
24  : QGVInteraction(parent), mScene(parent)
25  {
26  connect(gSelectionRelay, &SelectionRelay::selectionChanged, this, &ClockTreeExtractorInteraction::handleHALSelectionChanged);
27  connect(parent, &QGraphicsScene::selectionChanged, this, &ClockTreeExtractorInteraction::handleQGVSelectionChanged);
28  }
29 
31  {
32  Q_UNUSED(edge);
33  }
34 
36  {
37  bool ok = false;
38 
39  if (node->getShape() == "circle")
40  {
41  // global Input
42  bool assigned = false;
43  for (Net* n : gNetlist->get_global_input_nets())
44  {
45  if (n->get_name() == node->label().trimmed().toStdString())
46  {
47  mNetHash[n->get_id()] = node;
48  mGlobalInputHash[node] = n->get_id();
49  assigned = true;
50  break;
51  }
52  }
53  if (!assigned)
54  log_warning("dot_viewer", "Cannot assign circle with label='{}' to global input.", node->label().toStdString());
55  return;
56  }
57  u32 gateId = node->label().trimmed().toInt(&ok);
58  if (!ok)
59  {
60  log_warning("dot_viewer", "Cannot parse gate ID from string '{}'.", node->label().toStdString());
61  return;
62  }
63 
64  Gate* g = gNetlist->get_gate_by_id(gateId);
65  if (!g)
66  {
67  log_warning("dot_viewer", "Gate with ID={} not found in netlist.", gateId);
68  return;
69  }
70 
71  mGateHash[gateId] = node;
72  mNodeHash[node] = gateId;
73  }
74 
75  void ClockTreeExtractorInteraction::handleQGVSelectionChanged()
76  {
77  if (mDisableHandler) return;
78  mDisableHandler = true;
79  std::vector<u32> gatIds;
80  std::vector<u32> netIds;
81  for (QGraphicsItem* it : mScene->selectedItems())
82  {
83  QGVNode* node = dynamic_cast<QGVNode*>(it);
84  if (!node) continue;
85  if (node->getShape() == "circle")
86  {
87  u32 netId = mGlobalInputHash.value(node,0);
88  if (netId) netIds.push_back(netId);
89  }
90  else
91  {
92  u32 gatId = mNodeHash.value(node,0);
93  if (gatId) gatIds.push_back(gatId);
94  }
95  }
96  gGuiApi->selectGate(gatIds,true,true);
97  if (!netIds.empty())
98  gGuiApi->selectNet(netIds,false,true);
99  mDisableHandler = false;
100  }
101 
102  void ClockTreeExtractorInteraction::handleHALSelectionChanged(void* sender)
103  {
104  Q_UNUSED(sender);
105  if (!mScene) return;
106 
107  if (mDisableHandler) return;
108  mDisableHandler = true;
109 
110  mScene->clearSelection();
111  for (u32 gatId : gSelectionRelay->selectedGatesList())
112  {
113  QGVNode* node = mGateHash.value(gatId, nullptr);
114  if (node)
115  {
116  node->setSelected(true);
117  for (QGraphicsView* gv : mScene->views())
118  gv->ensureVisible(node);
119  }
120  }
121 
122  for (u32 netId : gSelectionRelay->selectedNetsList())
123  {
124  QGVNode* node = mNetHash.value(netId, nullptr);
125  if (node)
126  {
127  node->setSelected(true);
128  for (QGraphicsView* gv : mScene->views())
129  gv->ensureVisible(node);
130  }
131  }
132  mDisableHandler = false;
133  }
134 }
Definition: gate.h:58
void selectNet(u32 netId, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:149
void selectGate(u32 gate_id, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:98
Definition: net.h:58
const std::vector< Net * > & get_global_input_nets() const
Definition: netlist.cpp:519
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
void selectionChanged(void *sender)
QList< u32 > selectedNetsList() const
QList< u32 > selectedGatesList() const
uint32_t u32
Definition: defines.h:41
#define log_warning(channel,...)
Definition: log.h:76
Definition: defines.h:45
QGVInteraction * constructClockTreeExtractorInteraction(QGVScene *parent)
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: gui_globals.h:69
GuiApi * gGuiApi
Definition: plugin_gui.cpp:86
void selectionChanged()
const T value(const Key &key) const const