HAL
graphics_scene.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 
30 #include "gui/gui_globals.h"
33 #include "hal_core/defines.h"
34 #include "hal_core/netlist/gate.h"
36 
37 #include <QGraphicsScene>
38 #include <QPair>
39 #include <QVector>
40 
41 namespace hal
42 {
43  class GraphicsGate;
44  class GraphicsItem;
45  class GraphicsModule;
46  class GraphicsNet;
47  class DragController;
48 
59  {
60  Q_OBJECT
61 
62  public:
63  enum GridType
64  {
67  Lines
68  };
70 
77  static void setLod(const qreal& lod);
78 
84  static void setGridEnabled(const bool& value);
85 
92  static void setGridClustersEnabled(const bool& value);
93 
99  static void setGridType(const GridType& gridType);
100 
108  static QPointF snapToGrid(const QPointF& pos) Q_DECL_DEPRECATED;
109 
115  GraphicsScene(QObject* parent = nullptr);
116 
121  ~GraphicsScene();
122 
129 
135  void addGraphItem(GraphicsItem* item);
136 
142  void removeGraphItem(GraphicsItem* item);
143 
147  void deleteAllItems();
148 
152  void connectAll();
153 
157  void disconnectAll();
158 
164  void updateVisuals(const GraphShader::Shading& s);
165 
170  void moveNetsToBackground();
171 
179  const GraphicsGate* getGateItem(const u32 id) const;
180 
188  const GraphicsNet* getNetItem(const u32 id) const;
189 
197  const GraphicsModule* getModuleItem(const u32 id) const;
198 
203  void setMousePressed(bool isPressed);
204 
205 #ifdef GUI_DEBUG_GRID
206  void debugSetLayouterGrid(const QVector<qreal>& debug_x_lines, const QVector<qreal>& debug_y_lines, qreal debug_default_height, qreal debug_default_width);
207  void setDebugGridEnabled(bool enabled);
208  bool debugGridEnabled();
209 #endif
210 
211  public Q_SLOTS:
216 
224 
231 
237  void handleHighlight(const QVector<const ModuleItem*>& highlightItems);
238 
246  void handleGroupingAssignModule(Grouping* grp, u32 id);
247 
255  void handleGroupingAssignGate(Grouping* grp, u32 id);
256 
264  void handleGroupingAssignNet(Grouping* grp, u32 id);
265 
273 
277  void updateAllItems();
278 
284 
285  protected:
292 
293  private:
294  static qreal sLod;
295 
296  static const qreal sGridFadeStart;
297  static const qreal sGridFadeEnd;
298 
299  static bool sGridEnabled;
300  static bool sGridClustersEnabled;
301  static GraphicsScene::GridType sGridType;
302 
303  // using QGraphicsScene::addItem;
304  // using QGraphicsScene::removeItem;
305  using QGraphicsScene::clear;
306 
307  void drawBackground(QPainter* painter, const QRectF& rect) override;
308 
309  QVector<GraphicsModule*> mModuleItems;
310  QVector<GraphicsGate*> mGateItems;
311  QVector<GraphicsNet*> mNetItems;
312 
313 #ifdef GUI_DEBUG_GRID
314  void debugDrawLayouterGrid(QPainter* painter, const int x_from, const int x_to, const int y_from, const int y_to);
315  QVector<qreal> mDebugXLines;
316  QVector<qreal> mDebugYLines;
317  qreal mDebugDefaultWidth;
318  qreal mDebugDefaultHeight;
319  bool mDebugGridEnable;
320  DragController* mDragController;
321  enum RubberBandSelectionStatus
322  {
323  NotPressed,
324  BeginPressed,
325  SelectionChanged,
326  EndPressed
327  } mSelectionStatus;
328 #endif
329  };
330 } // namespace hal
Abstract base class for gates.
Definition: graphics_gate.h:48
Superclass for all graphic items used ins the GraphicsScene. It contains information about the underl...
Definition: graphics_item.h:44
Abstract base class for modules.
The basic net class all other nets inherit from.
Definition: graphics_net.h:43
Container for a GraphGraphicsView containing gates, nets, and modules.
void removeGraphItem(GraphicsItem *item)
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
const GraphicsGate * getGateItem(const u32 id) const
void updateVisuals(const GraphShader::Shading &s)
static void setLod(const qreal &lod)
void handleGroupingAssignNet(Grouping *grp, u32 id)
void setMousePressed(bool isPressed)
void handleGroupingAssignModule(Grouping *grp, u32 id)
const GraphicsModule * getModuleItem(const u32 id) const
void handleHighlight(const QVector< const ModuleItem * > &highlightItems)
void handleGroupingAssignGate(Grouping *grp, u32 id)
void handleExternSelectionChanged(void *sender)
static void setGridEnabled(const bool &value)
void handleGroupingColorChanged(Grouping *grp)
static void setGridType(const GridType &gridType)
void addGraphItem(GraphicsItem *item)
void handleInternSelectionChanged()
const GraphicsNet * getNetItem(const u32 id) const
static QPointF snapToGrid(const QPointF &pos) Q_DECL_DEPRECATED
QPointF dropTarget()
void handleExternSubfocusChanged(void *sender)
void setDragController(DragController *dc)
static void setGridClustersEnabled(const bool &value)
GraphicsScene(QObject *parent=nullptr)
quint32 u32
virtual bool event(QEvent *event) override
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
QObject * sender() const const