HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
graph_graphics_view.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
30 #include "gui/gui_globals.h"
34 
35 #include <QGraphicsView>
36 #include <QAction>
37 #include <QMenu>
38 
39 namespace hal
40 {
41  class GraphicsItem;
42  class GraphWidget;
43  class DragController;
44 
48  namespace graph_widget_constants
49  {
50  enum class grid_type;
51  }
52 
57  {
58  Q_OBJECT
59 
60  u32 mOrigin;
61  bool mPickSuccessor;
62  public:
63  GraphGraphicsViewNeighborSelector(u32 orig, bool pickSuc, QObject* parent = nullptr)
64  : GateSelectReceiver(parent), mOrigin(orig), mPickSuccessor(pickSuc) {;}
65  public Q_SLOTS:
66  void handleGatesPicked(const QSet<u32>& gats) override;
67  };
68 
77  {
78  Q_OBJECT
79 
80  friend class GraphWidget;
81  public:
88 
94  void gentleZoom(const qreal factor);
95 
101  void viewportCenterZoom(const qreal factor);
102 
105 
108 
111 
114 
115  Q_SIGNALS:
123 
128 
129  public Q_SLOTS:
137  void handleShortestPathToGrouping(u32 idFrom, Node nodeTo, bool forwardDirection);
138 
142  void handleRemoveFromView();
143 
144  private Q_SLOTS:
145  void conditionalUpdate();
146  void handleIsolationViewAction();
147  void adjustMinScale();
148  void handleAddCommentAction();
149 
150  void handleFoldParentSingle();
151  void handleFoldParentAll();
152  void handleUnfoldSingleAction();
153  void handleUnfoldAllAction();
154 
155  void handleShortestPathToView();
156  void handleQueryShortestPathGate();
157  void handleQueryShortestPathModule();
158  void handleSelectOutputs();
159  void handleSelectInputs();
160 
161  void handleAddModuleToView();
162  void handleAddGateToView();
163 
164  void handleAddSuccessorToView();
165  void handleAddPredecessorToView();
166  void handleAddCommonSuccessorToView();
167  void handleAddCommonPredecessorToView();
168  void handleHighlightSuccessor();
169  void handleHighlightPredecessor();
170  void handleSuccessorDistance();
171  void handlePredecessorDistance();
172  void handleCancelPickMode();
173  void handlePluginContextContributionTriggered();
174  void selectedNodeToItem();
175 
176  protected:
177  void paintEvent(QPaintEvent* event) override;
178  void drawForeground(QPainter* painter, const QRectF& rect) override;
179  void mousePressEvent(QMouseEvent* event) override;
180  void mouseMoveEvent(QMouseEvent* event) override;
181  void mouseReleaseEvent(QMouseEvent *event) override;
182  void mouseDoubleClickEvent(QMouseEvent* event) override;
183  void dragEnterEvent(QDragEnterEvent *event) override;
184  void dragLeaveEvent(QDragLeaveEvent *event) override;
185  void dragMoveEvent(QDragMoveEvent *event) override;
186  void dropEvent(QDropEvent *event) override;
187  void wheelEvent(QWheelEvent* event) override;
188  void keyPressEvent(QKeyEvent* event) override;
189  void keyReleaseEvent(QKeyEvent* event) override;
190  void resizeEvent(QResizeEvent* event) override;
191 
192  private:
193 
194  enum SearchAction {PredecessorGate, SuccessorGate, PredecessorModule, SuccessorModule};
195  void mousePressEventNotItemDrag(QMouseEvent* event);
196  void showContextMenu(const QPoint& pos);
197 
198  void updateMatrix(const int delta);
199 
200  void toggleAntialiasing();
201 
202  bool itemDraggable(GraphicsItem* item);
203 
204  void addSuccessorToView(int maxLevel, bool succ);
205  void addCommonSuccessorToView(int maxLevel, bool succ);
206 
207  void dragPan(float dpx, float dpy);
208 
209  GraphWidget* mGraphWidget;
210 
211  QSet<u32> getSelectableGates();
212  QSet<u32> getNotSelectableModules();
213 
217  struct LayouterPoint
218  {
219  int mIndex;
220  qreal mPos;
221  };
222  QPair<QPoint, QPointF> closestLayouterPos(const QPointF& scene_pos) const;
223  LayouterPoint closestLayouterPoint(qreal scene_pos, int default_spacing, int min_index, QVector<qreal> sections) const;
224 
225  #ifdef GUI_DEBUG_GRID
226  void debugShowLayouterGridpos(const QPoint& mouse_pos);
227  void debugDrawLayouterGridpos(QPainter* painter);
228  QPoint m_debug_gridpos = QPoint(0,0);
229  bool mDebugGridposEnable = true;
230  #endif
231 
232 
233 
234  GraphicsItem* mItem;
235 
236  bool mMinimapEnabled;
237 
238  bool mGridEnabled;
239  bool mGridClustersEnabled;
240  GraphicsScene::GridType mGridType;
241 
242  DragController* mDragController;
243  Qt::KeyboardModifier mDragModifier;
244 
245  QPoint mMovePosition;
246  Qt::KeyboardModifier mPanModifier;
247 
248  Qt::KeyboardModifier mZoomModifier;
249  qreal mZoomFactorBase;
250  QPointF mTargetScenePos;
251  QPointF mTargetViewportPos;
252 
253  qreal mMinScale;
254 
255  template <typename Func1>
256  void recursionLevelMenu(QMenu* menu, bool succ, Func1 slot, bool addUnlimited=false)
257  {
258  QString s = succ ? "successors" : "predecessors";
259  const char* txt[] = {"All %1", "Depth 1 (direct %1)", "Depth 2",
260  "Depth 3", "Depth 4", "Depth 5", nullptr};
261  for (int inx = 1; txt[inx]; inx++)
262  {
263  QAction* act = menu->addAction(inx==1 ? QString(txt[1]).arg(s) : QString(txt[inx]));
264  act->setData(inx);
265  connect(act, &QAction::triggered, this, slot);
266  }
267  if (addUnlimited)
268  {
269  QAction* act = menu->addAction(QString(txt[0]).arg(s));
270  act->setData(0);
271  connect(act, &QAction::triggered, this, slot);
272  }
273  }
274 
275  static const QString sAssignToGrouping;
276  };
277 }
A view to display the rendered graph (needs a GraphicsScene).
void keyPressEvent(QKeyEvent *event) override
void dragLeaveEvent(QDragLeaveEvent *event) override
void setGridType(GraphicsScene::GridType gridType)
void dropEvent(QDropEvent *event) override
void wheelEvent(QWheelEvent *event) override
void setPanModifier(Qt::KeyboardModifier panModifier)
Qt::KeyboardModifier panModifier()
void keyReleaseEvent(QKeyEvent *event) override
void viewportCenterZoom(const qreal factor)
void handleShortestPathToGrouping(u32 idFrom, Node nodeTo, bool forwardDirection)
void setDragModifier(Qt::KeyboardModifier dragModifier)
GraphGraphicsView(GraphWidget *parent)
void paintEvent(QPaintEvent *event) override
void moduleDoubleClicked(u32 id)
void mouseMoveEvent(QMouseEvent *event) override
Qt::KeyboardModifier dragModifier()
void resizeEvent(QResizeEvent *event) override
GraphicsScene::GridType gridType()
void dragEnterEvent(QDragEnterEvent *event) override
void mouseDoubleClickEvent(QMouseEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
void mousePressEvent(QMouseEvent *event) override
void drawForeground(QPainter *painter, const QRectF &rect) override
void gentleZoom(const qreal factor)
void dragMoveEvent(QDragMoveEvent *event) override
GraphGraphicsViewNeighborSelector(u32 orig, bool pickSuc, QObject *parent=nullptr)
void handleGatesPicked(const QSet< u32 > &gats) override
Wraps a GraphContext and a GraphGraphicsView.
Definition: graph_widget.h:55
Superclass for all graphic items used ins the GraphicsScene. It contains information about the underl...
Definition: graphics_item.h:44
The Node class object represents a module or a gate.
Definition: gui_def.h:61
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
void setData(const QVariant &userData)
void triggered(bool checked)
virtual bool event(QEvent *event) override
QAction * addAction(const QString &text)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
KeyboardModifier