HAL
node_box.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 <QVector>
29 #include <QPoint>
30 #include <QHash>
31 #include <QSet>
32 #include "gui/gui_def.h"
33 #include "hal_core/netlist/gate.h"
34 
35 uint qHash(const QPoint& p);
36 
37 namespace hal {
38  class GraphicsNode;
39 
49  class NodeBox
50  {
51  Node mNode;
52  GraphicsNode* mItem;
53 
54  int mX;
55  int mY;
56 
57  qreal mInputPadding;
58  qreal mOutputPadding;
59 
60  static const int sMinimumGateIoPadding = 60;
61 
62  public:
69  NodeBox(const Node& n, int px, int py);
70 
75  Node getNode() const { return mNode; }
76 
81  Node::NodeType type() const { return mNode.type(); }
82 
87  u32 id() const { return mNode.id(); }
88 
93  int x() const { return mX; }
94 
99  int y() const { return mY; }
100 
105  QPoint gridPosition() const { return QPoint(mX,mY); }
106 
111  void setItem(GraphicsNode* item_) { mItem = item_; }
112 
118  void setItemPosition(qreal xpos, qreal ypos);
119 
124  GraphicsNode* item() const { return mItem; }
125 
130  qreal inputPadding() const { return mInputPadding; }
131 
136  qreal outputPadding() const { return mOutputPadding; }
137  };
138 
149  class NodeBoxes : public QVector<NodeBox*>
150  {
151  public:
155  NodeBoxes() {;}
156 
160  ~NodeBoxes();
161 
168  void addBox(const Node& nd, int px, int py);
169 
173  void clearBoxes();
174 
184  NodeBox* boxForGate(const Gate* g) const { return mGateHash.value(g); }
185 
191  NodeBox* boxForPoint(const QPoint& p) const { return mPointHash.value(p); }
192 
200  NodeBox* boxForNode(const Node& n) const { return mNodeHash.value(n); }
201 
209  NodeBox* boxForItem(GraphicsNode* item) const { return mItemHash.value(item); }
210 
211  QSet<u32> filterNotInView(const QSet<u32>& gats) const;
212  private:
213  QHash<const Gate*,NodeBox*> mGateHash;
214  QHash<QPoint,NodeBox*> mPointHash;
215  QHash<Node,NodeBox*> mNodeHash;
217  };
218 }
Definition: gate.h:58
Abstract base class for nodes (e.g. gates, modules)
Definition: graphics_node.h:41
The NodeBox class represents a node placed at a grid position within a hal view.
Definition: node_box.h:50
void setItem(GraphicsNode *item_)
setItem
Definition: node_box.h:111
qreal inputPadding() const
inputPadding distance from top edge to first input net
Definition: node_box.h:130
qreal outputPadding() const
outputPadding distance from top edge to first output net
Definition: node_box.h:136
GraphicsNode * item() const
item getter for graphics item object
Definition: node_box.h:124
NodeBox(const Node &n, int px, int py)
NodeBox constructor creates graphic item.
Definition: node_box.cpp:16
int x() const
x getter for X-grid position
Definition: node_box.h:93
void setItemPosition(qreal xpos, qreal ypos)
setItemPosition place item on scene at real position
Definition: node_box.cpp:37
int y() const
y getter for Y-grid position
Definition: node_box.h:99
Node getNode() const
getNode getter for node information
Definition: node_box.h:75
Node::NodeType type() const
type getter for type information
Definition: node_box.h:81
QPoint gridPosition() const
Definition: node_box.h:105
u32 id() const
id getter for ID information
Definition: node_box.h:87
The NodeBoxes class owns all NodeBox'es from hal view.
Definition: node_box.h:150
void addBox(const Node &nd, int px, int py)
addBox call NodeBox constructor and store pointer in vector
Definition: node_box.cpp:61
NodeBox * boxForNode(const Node &n) const
boxForNode find NodeBox by node
Definition: node_box.h:200
NodeBox * boxForPoint(const QPoint &p) const
boxForPoint find NodeBox by grid position
Definition: node_box.h:191
NodeBox * boxForGate(const Gate *g) const
boxForGate find NodeBox by Gate pointer.
Definition: node_box.h:184
NodeBox * boxForItem(GraphicsNode *item) const
boxForItem find NodeBox by graphics item
Definition: node_box.h:209
QSet< u32 > filterNotInView(const QSet< u32 > &gats) const
Definition: node_box.cpp:83
void clearBoxes()
clearBoxes delete all NodeBox'es and clear vector.
Definition: node_box.cpp:50
The Node class object represents a module or a gate.
Definition: gui_def.h:61
NodeType type() const
type getter for type information
Definition: gui_def.h:71
u32 id() const
id getter for ID information
Definition: gui_def.h:77
n
Definition: test.py:6
quint32 u32
uint qHash(const QPoint &p)
Definition: node_box.cpp:6