HAL
net_layout_junction.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QPoint>
4 #include <QPointF>
5 
6 #include <QList>
7 #include <QHash>
8 #include <QColor>
9 #include <QRect>
11 
12 // #define JUNCTION_DEBUG = 1
13 
15 class QGraphicsLineItem;
16 class QGraphicsScene;
17 
18 const int DELTA = 20;
19 const int FIRST = 400;
20 const int GAP = 200;
21 
22 namespace hal {
23 
29  class LaneIndex
30  {
31  friend uint qHash(const LaneIndex& ri);
32  int mIndex;
33  public:
35 
41  LaneIndex(HVIndex ihv, int ilane) : mIndex(ihv | (ilane << 1)) {;}
42 
46  operator int () const { return mIndex; }
47 
52  LaneIndex& operator++() { mIndex += 2; return *this; }
53 
58  LaneIndex& operator--() { mIndex -= 2; return *this; }
59 
64  HVIndex hvIndex() const { return (HVIndex) (mIndex & 1); }
65 
70  int laneIndex() const { return (mIndex >> 1); }
71 
76  bool isHorizontal() const { return hvIndex() == Horizontal; }
77 
82  bool isVertical() const { return hvIndex() == Vertical; }
83 
88  static LaneIndex horizontal(int ilane) { return LaneIndex(Horizontal,ilane); }
89 
94  static LaneIndex vertical(int ilane) { return LaneIndex(Vertical,ilane); }
95  };
96 
97  class NetLayoutJunctionWire;
98 
106  {
107  u32 mNetId;
108  int mFirst;
109  int mLast;
110  public:
111  static const int MinInf = -32767;
112  static const int MaxInf = 32767;
113 
114  NetLayoutJunctionRange(u32 netId_, int first, int last);
115 
121  bool conflict(const NetLayoutJunctionRange& other) const;
122 
128  bool contains(int pos) const { return mFirst <= pos && pos <= mLast; }
129 
135  bool innerPos(int pos) const { return mFirst < pos && pos < mLast; }
136 
142  bool canJoin(const NetLayoutJunctionRange& other) const;
143 
149  bool isEntry(int iTestMax) const;
150 
154  bool operator==(const NetLayoutJunctionRange& other) const;
155 
159  bool operator==(const NetLayoutJunctionWire& wire) const;
160 
165  u32 netId() const { return mNetId; }
166 
171  int first() const { return mFirst; }
172 
177  void setFirst(int fst) { mFirst = fst; }
178 
183  int last() const { return mLast; }
184 
189  void setLast(int lst) { mLast = lst; }
190 
195  int length() const { return mLast-mFirst; }
196 
202  int endPosition(int iGetLast) const;
203 
208  void expand(const NetLayoutJunctionRange& other);
209 
214  QString toString() const { return QString("<%1|%2..%3>").arg(mNetId).arg(mFirst).arg(mLast); }
215 
224  };
225 
232  {
233  public:
238 
243 
248  : mIndex(li), mRange(rng) {;}
249 
254  bool isEntry() const;
255  };
256 
261  {
262  public:
267 
274  u32 id(NetLayoutDirection dir, int ilane) const { return mEntries[dir.index()].at(ilane); }
275 
279  QString toString() const;
280 
285  void dumpToFile(const QPoint& pnt) const;
286 
287  static QString gridPointName(const QPoint& p);
288 
293  bool isTrivial() const;
294 
298  static void resetFile();
299  };
300 
305  {
306  public:
310  int mLane;
311 
316 
321  };
322 
323 
331  {
332  u32 mPattern; // binary pattern
333  int mLaneIndex[4]; // index: Left = 0, Right = 1, Up = 2, Down = 3 value: -1 = unused
334  int mEntries;
335  bool mPlaced;
336  public:
339 
341  void addEntry(NetLayoutDirection dir, int laneInx);
342  QString toString() const;
343 
349  bool hasPattern(u32 searchPattern) const;
350  int laneIndex(NetLayoutDirection dir) const { return mLaneIndex[dir.index()]; }
351  int numberEntries() const { return mEntries; }
352  u32 pattern() const { return mPattern; }
353  void setPattern(u32 pat) { mPattern = pat; }
354  bool isPlaced() const { return mPlaced; }
356  void setPlaced() { mPlaced = true; }
357  void addWire(const NetLayoutJunctionWire& wire) { mWires.append(wire); }
358  void replaceWire(const NetLayoutJunctionRange& rng, const NetLayoutJunctionWire& wire);
359  QList<QPoint> junctionKnots() const { return mKnots; }
360  };
361 
365  class NetLayoutJunctionOccupied : public QList<NetLayoutJunctionRange>
366  {
367  public:
368  bool conflict(const NetLayoutJunctionRange& test) const;
369  bool canJoin(u32 netId, int pos) const;
370  };
371 
375  class NetLayoutJunctionOccupiedHash : public QHash<LaneIndex,NetLayoutJunctionOccupied>
376  {
377  public:
384  {
385  public:
389  AddOrMerge() : mType(Added), mOldRange(nullptr), mNewRange(nullptr) {;}
391  {
392  if (mOldRange) delete mOldRange;
393  if (mNewRange) delete mNewRange;
394  }
395  };
396 
403  AddOrMerge addOrMerge(const LaneIndex &ri, const NetLayoutJunctionRange& rng);
404 
405 #ifdef JUNCTION_DEBUG
407 #endif
408  };
409 
414  {
415  public:
418  QRect rect() const { return mRect; }
419  NetLayoutJunctionNet netById(u32 id) const { return mNets.value(id); }
420 
422  ErrorType lastError() const { return mError; }
423 
424 #ifdef JUNCTION_DEBUG
425  void toScene(QGraphicsScene* scene) const;
426  void toSceneStep(QGraphicsScene* scene, int istep);
427  int numberSteps() const { return mOccupied.mHistory.size(); }
428 #endif
429  private:
430  void routeT();
431  void routeAllStraight(NetLayoutDirection dirFrom, NetLayoutDirection dirTo);
432  void routeAllCorner(NetLayoutDirection dirHoriz, NetLayoutDirection dirVertic);
433  void routeSingleStraight(u32 netId, int iMain, int iroadIn, int iroadOut);
434  void routeSingleSwap(u32 netId, int iMain, int iroadIn, int iroadOut);
435  void routeSingleCorner(u32 netId, NetLayoutDirection dirHoriz, NetLayoutDirection dirVertic);
436 
441  void routeAllMultiPin(NetLayoutDirection leftOrRight);
442 
449  void routeSingleMultiPin(u32 netId, NetLayoutDirection leftOrRight, const NetLayoutJunctionMultiPin &nmpin);
450  void findJunctions();
451  void calculateRect();
452  bool conflict(const LaneIndex& ri, const NetLayoutJunctionRange& testRng) const;
453  void place(const LaneIndex& ri, const NetLayoutJunctionRange& range);
454  bool canJoin(const LaneIndex& ri, u32 netId, int pos) const;
455 
456  QRect mRect;
457  NetLayoutJunctionEntries mEntries;
459  NetLayoutJunctionOccupiedHash mOccupied;
460  int maxRoad[2];
461  ErrorType mError;
462  };
463 
464  class NetLayoutJunctionHash : public QHash<NetLayoutPoint,NetLayoutJunction*>
465  {
466  public:
469  void clearAll();
470  };
471 
472  uint qHash(const LaneIndex& ri);
473 }
474 
475 #ifdef JUNCTION_DEBUG
476  void setColorMap(const hal::NetLayoutJunctionEntries& entries);
477  QColor colorFromId(u32 netId);
478 #endif
479 
int laneIndex() const
LaneIndex(HVIndex ihv, int ilane)
static LaneIndex horizontal(int ilane)
LaneIndex & operator--()
LaneIndex & operator++()
bool isHorizontal() const
static LaneIndex vertical(int ilane)
friend uint qHash(const LaneIndex &ri)
bool isVertical() const
HVIndex hvIndex() const
static QString gridPointName(const QPoint &p)
u32 id(NetLayoutDirection dir, int ilane) const
void dumpToFile(const QPoint &pnt) const
NetLayoutJunctionNet netById(u32 id) const
ErrorType lastError() const
NetLayoutJunction(const NetLayoutJunctionEntries &entries)
Single net to be routed through the junction.
QList< QPoint > junctionKnots() const
QList< NetLayoutJunctionWire > wireAtPos(int pos, LaneIndex::HVIndex hvi)
QList< NetLayoutJunctionWire > mWires
int laneIndex(NetLayoutDirection dir) const
void addWire(const NetLayoutJunctionWire &wire)
void addEntry(NetLayoutDirection dir, int laneInx)
void replaceWire(const NetLayoutJunctionRange &rng, const NetLayoutJunctionWire &wire)
bool hasPattern(u32 searchPattern) const
enum hal::NetLayoutJunctionOccupiedHash::AddOrMerge::Type mType
AddOrMerge addOrMerge(const LaneIndex &ri, const NetLayoutJunctionRange &rng)
bool conflict(const NetLayoutJunctionRange &test) const
bool canJoin(u32 netId, int pos) const
int endPosition(int iGetLast) const
bool conflict(const NetLayoutJunctionRange &other) const
void expand(const NetLayoutJunctionRange &other)
bool canJoin(const NetLayoutJunctionRange &other) const
static NetLayoutJunctionRange entryRange(NetLayoutDirection dir, int ilane, u32 netId)
NetLayoutJunctionRange(u32 netId_, int first, int last)
bool operator==(const NetLayoutJunctionRange &other) const
bool isEntry(int iTestMax) const
NetLayoutJunctionRange mRange
NetLayoutJunctionWire(const NetLayoutJunctionRange &rng, const LaneIndex &li)
uint qHash(const LaneIndex &ri)
Definition: test.py:1
const int GAP
const int DELTA
const int FIRST
quint32 u32
int size() const const
const T & at(int i) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const