HAL
node_box.cpp
Go to the documentation of this file.
4 #include "gui/gui_globals.h"
5 
6 uint qHash(const QPoint& p)
7 {
8  uint retval = ( p.x() << 16);
9  retval |= ( p.y() & 0xFFFF);
10  return retval;
11 }
12 
13 namespace hal
14 {
15 
16  NodeBox::NodeBox(const Node &n, int px, int py)
17  : mNode(n), mX(px), mY(py),
18  // GATE IO SPACING SHOULD BE CALCULATED HERE, FOR NOW IT IS JUST ASSUMED TO BE THE MINIMUM ACROSS THE BORD
19  mInputPadding(sMinimumGateIoPadding),
20  mOutputPadding(sMinimumGateIoPadding)
21  {
22  switch (type())
23  {
24  case Node::Module: {
26  break;
27  }
28  case Node::Gate: {
30  break;
31  }
32  default:
33  break;
34  }
35  }
36 
37  void NodeBox::setItemPosition(qreal xpos, qreal ypos)
38  {
39  Q_ASSERT(mItem);
40  mItem->setPos(xpos,ypos);
41  }
42 
43 //------- QVector<NodeBox*> -----------------------
45  {
46  for (NodeBox* nb : *this)
47  delete nb;
48  }
49 
51  {
52  for (NodeBox* nb : *this)
53  delete nb;
54  clear();
55  mGateHash.clear();
56  mPointHash.clear();
57  mNodeHash.clear();
58  mItemHash.clear();
59  }
60 
61  void NodeBoxes::addBox(const Node &nd, int px, int py)
62  {
63  NodeBox* nbox = new NodeBox(nd,px,py);
64 
65  mNodeHash.insert(nd,nbox);
66  mPointHash.insert(QPoint(px,py),nbox);
67  mItemHash.insert(nbox->item(),nbox);
68  append(nbox);
69  if (nbox->getNode().isGate())
70  {
71  Gate* g = gNetlist->get_gate_by_id(nbox->id());
72  if (g) mGateHash.insert(g,nbox);
73  }
74  else if (nbox->getNode().isModule())
75  {
76  Module* m = gNetlist->get_module_by_id(nbox->id());
77  if (!m) return;
78  for (Gate* ig : m->get_gates(nullptr, true))
79  if (ig) mGateHash.insert(ig,nbox);
80  }
81  }
82 
84  {
85  QSet<u32> retval;
86  for (u32 gateId : gats)
87  {
88  if (!mNodeHash.value(Node(gateId,Node::Gate)))
89  retval.insert(gateId);
90  }
91  return retval;
92  }
93 
94  uint qHash(const Node &n)
95  {
96  uint retval = ( n.id() << 1);
97  if (n.type() == Node::Module) ++retval;
98  return retval;
99  }
100 
101 }
Definition: gate.h:58
const std::vector< Gate * > & get_gates() const
Definition: module.cpp:391
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
The NodeBox class represents a node placed at a grid position within a hal view.
Definition: node_box.h:50
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
void setItemPosition(qreal xpos, qreal ypos)
setItemPosition place item on scene at real position
Definition: node_box.cpp:37
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
u32 id() const
id getter for ID information
Definition: node_box.h:87
void addBox(const Node &nd, int px, int py)
addBox call NodeBox constructor and store pointer in vector
Definition: node_box.cpp:61
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
bool isModule() const
isModule test wheter node is a module
Definition: gui_def.h:95
bool isGate() const
isGate test whether node is a gate
Definition: gui_def.h:89
@ Module
Definition: gui_def.h:63
@ Gate
Definition: gui_def.h:63
GraphicsModule * createGraphicsModule(Module *m, const int type)
GraphicsGate * createGraphicsGate(Gate *g, const int type)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
uint qHash(const LaneIndex &ri)
n
Definition: test.py:6
quint32 u32
uint qHash(const QPoint &p)
Definition: node_box.cpp:6
void setPos(const QPointF &pos)
int x() const const
int y() const const
QSet::iterator insert(const T &value)
void append(const T &value)