HAL
net_layout_point.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 <QPoint>
29 #include <QPointF>
30 
31 #include <QList>
32 #include <QMap>
33 #include <QHash>
34 
36 class QGraphicsLineItem;
37 
38 QPointF scenePoint(const QPoint& p);
39 
40 typedef quint32 u32;
41 
42 namespace hal {
43 
48  {
49  public:
50  enum DirectionType {Undefined = -1, Left = 0, Right = 1, Up = 2, Down = 3, MaxDir = 4};
52  NetLayoutDirection(int idir);
53  bool isHorizontal() const { return mDir == Left || mDir == Right; }
54  int iHorizontal() const { return index()/2; }
55  bool isVertical() const { return mDir == Up || mDir == Down; }
56  bool isNull() const { return mDir == Undefined; }
57  QPoint step(bool omitEndpoint=false) const;
58  DirectionType direction() const { return mDir; }
59  u32 toPattern() const { return 1 << mDir; }
62  int index() const { return static_cast<int>(mDir); }
63  bool isLeft() const { return mDir==Left; }
64  bool isUp() const { return mDir==Up; }
65  bool isMax() const { return mDir==MaxDir; }
66  bool operator==(const NetLayoutDirection& other) const { return mDir == other.mDir; }
67  private:
68  static DirectionType numberToDirection(int idir);
69  DirectionType mDir;
70  };
71 
75  class NetLayoutPoint : public QPoint
76  {
77  public:
78  NetLayoutPoint(int x_=INT_MIN, int y_=INT_MIN);
79  NetLayoutPoint(const QPoint& p);
80  QGraphicsEllipseItem* graphicsFactory(float r) const;
81  int distanceTo(const NetLayoutPoint& other) const;
82  int yGrid() const;
83  QPoint gridPoint() const { return QPoint(x(),yGrid()); }
84  bool isEndpoint() const;
85  bool isUndefined() const { return x()==INT_MIN || y()==INT_MIN; }
86  NetLayoutPoint nextPoint(const NetLayoutDirection& dir, bool omitEndpoint=false) const;
87  static NetLayoutPoint fromBox(const QPoint& boxPosition, bool isInput);
89  };
90 
95  {
96  public:
98  NetLayoutWire(const NetLayoutPoint& p, const NetLayoutDirection& dir, bool isEnd);
100 
102  bool isEndpoint() const { return mIsEndpoint; }
103  bool isHorizontal() const { return mDir.isHorizontal(); }
104  bool operator==(const NetLayoutWire& other) const;
105  QString toString() const;
106  private:
107  NetLayoutPoint mPoint;
108  NetLayoutDirection mDir;
109  bool mIsEndpoint;
110  };
111 
115  class NetLayoutConnection : public QList<NetLayoutWire>
116  {
117  public:
119  NetLayoutConnection(const NetLayoutPoint& pa, const NetLayoutPoint& pb);
120  QList<NetLayoutPoint> wayPoints() const { return mWaypointLinks.keys(); }
121  NetLayoutPoint closestPoint(const NetLayoutPoint& pnt) const;
122  void add(const NetLayoutConnection& other, bool atomicNet);
123  private:
124  QHash<NetLayoutPoint,QList<int>> mWaypointLinks;
125 
126  NetLayoutPoint addWire(const NetLayoutPoint& pnt, const NetLayoutDirection& dir, bool omitEndpoint);
127  };
128 
133  {
134  public:
135  NetLayoutMetric(u32 id, const NetLayoutConnection* con);
136  u32 getId() const { return mId; }
137  int firstMoment() const {return mFirst; }
138  int secondMoment() const {return mSecond; }
139  bool operator< (const NetLayoutMetric& other) const;
140  private:
141  void evaluate(const QMap<int,QMap<int,int>>& map);
142  u32 mId;
143  int mFirst;
144  int mSecond;
145  };
146 
151  {
152  public:
153  NetLayoutConnectionFactory(const QList<NetLayoutPoint>& sources, const QList<NetLayoutPoint>& destinations);
154  QList<NetLayoutPoint> points() const { return mPoints; }
156  void dump(const QString& stub) const;
157  private:
158  QList<NetLayoutPoint> mSources;
159  QList<NetLayoutPoint> mDestinations;
160  QList<NetLayoutPoint> mPoints;
161  };
162 
166  class NetLayoutConnectionMetric : public QMap<NetLayoutMetric,NetLayoutConnection*>
167  {
168  public:
171  void clearAll();
172  };
173 
174  uint qHash(const hal::NetLayoutWire& w);
175  uint qHash(const hal::NetLayoutPoint& p);
176 }
177 
178 uint qHash(const QPoint& p);
NetLayoutConnectionFactory(const QList< NetLayoutPoint > &sources, const QList< NetLayoutPoint > &destinations)
void dump(const QString &stub) const
NetLayoutConnection * connection
QList< NetLayoutPoint > points() const
QList< NetLayoutPoint > wayPoints() const
NetLayoutPoint closestPoint(const NetLayoutPoint &pnt) const
void add(const NetLayoutConnection &other, bool atomicNet)
NetLayoutDirection operator++()
NetLayoutDirection(DirectionType dir=Undefined)
bool operator==(const NetLayoutDirection &other) const
QPoint step(bool omitEndpoint=false) const
DirectionType direction() const
NetLayoutMetric(u32 id, const NetLayoutConnection *con)
bool operator<(const NetLayoutMetric &other) const
static QList< NetLayoutPoint > orderByDistance(const QList< NetLayoutPoint > &points)
bool isUndefined() const
QPoint gridPoint() const
NetLayoutPoint nextPoint(const NetLayoutDirection &dir, bool omitEndpoint=false) const
int distanceTo(const NetLayoutPoint &other) const
QGraphicsEllipseItem * graphicsFactory(float r) const
NetLayoutPoint(int x_=INT_MIN, int y_=INT_MIN)
static NetLayoutPoint fromBox(const QPoint &boxPosition, bool isInput)
NetLayoutWire(const NetLayoutPoint &p, const NetLayoutDirection &dir, bool isEnd)
QString toString() const
bool isEndpoint() const
bool isHorizontal() const
NetLayoutPoint endPoint(WirePointType pnt) const
QGraphicsLineItem * graphicsFactory() const
bool operator==(const NetLayoutWire &other) const
uint qHash(const LaneIndex &ri)
QPointF scenePoint(const QPoint &p)
quint32 u32
uint qHash(const QPoint &p)
Definition: node_box.cpp:6
int x() const const
int y() const const