1#ifndef GYM_PCB_NAVPOINT_H
2#define GYM_PCB_NAVPOINT_H
5#include "GridDirection.hpp"
6#include "UniformGrid25.hpp"
20#ifndef GYM_PCB_NAVPOINT_NUM_COST_TERMS
21#define GYM_PCB_NAVPOINT_NUM_COST_TERMS 2
25#define NAV_POINT_FLAG_BLOCKED_TEMPORARY (1 << 0)
26#define NAV_POINT_FLAG_BLOCKED_PERMANENT (1 << 8)
27#define NAV_POINT_FLAG_NO_VIAS (1 << 1)
28#define NAV_POINT_FLAG_INSIDE_PIN (1 << 2)
29#define NAV_POINT_FLAG_INSIDE_COMPONENT (1 << 3)
30#define NAV_POINT_FLAG_PIN_TRACK_CLEARANCE (1 << 4)
31#define NAV_POINT_FLAG_PIN_VIA_CLEARANCE (1 << 5)
32#define NAV_POINT_FLAG_ROUTE_TRACK_CLEARANCE (1 << 6)
33#define NAV_POINT_FLAG_ROUTE_VIA_CLEARANCE (1 << 7)
34#define NAV_POINT_FLAG_SOURCE (1 << 9)
35#define NAV_POINT_FLAG_TARGET (1 << 10)
36#define NAV_POINT_FLAG_ROUTE_GUARD (1 << 11)
39#define NAV_POINT_FLAGS_PIN_CLEARANCE 0x030
40#define NAV_POINT_FLAGS_ROUTE_CLEARANCE 0x0c0
41#define NAV_POINT_FLAGS_TRACK_CLEARANCE 0x050
42#define NAV_POINT_FLAGS_VIA_CLEARANCE 0x0a0
43#define NAV_POINT_FLAGS_CLEARANCE 0x0f0
44#define NAV_POINT_FLAGS_TRACKS_BLOCKED 0x951
45#define NAV_POINT_FLAGS_VIAS_BLOCKED 0x9f3
46#define NAV_POINT_FLAGS_VIAS_BLOCKED_P 0x9f2
47#define NAV_POINT_FLAGS_ENDPOINT 0x600
48#define NAV_POINT_FLAGS_ALL 0xfff
55 void reset() { mSeq = 0; }
56 void setOpen(uint16_t seq) { mSeq = seq; }
57 void setDone(uint16_t seq) { assert(isOpen(seq)); mSeq = seq | 0x8000; }
58 bool isSeen(uint16_t seq)
const {
return (mSeq & 0x7fff) == seq; }
59 bool isOpen(uint16_t seq)
const {
return mSeq == seq; }
60 bool isDone(uint16_t seq)
const {
return mSeq == (seq | 0x8000); }
72 void setPin(int8_t n) { _RouteTracks = 0; _RouteVias = 0; _PinTracks = n; _PinVias = n; Sum = 2 * n; }
73 void setPin(int8_t n, int8_t m) { _RouteTracks = 0; _RouteVias = 0; _PinTracks = n; _PinVias = m; Sum = n + m; }
74 void setPinTracks(int8_t n) { _RouteTracks = 0; _RouteVias = 0; _PinTracks = n; _PinVias = 0; Sum = n; }
75 void setPinVias(int8_t n) { _RouteTracks = 0; _RouteVias = 0; _PinTracks = 0; _PinVias = n; Sum = n; }
76 void setRoute(int8_t n) { _RouteTracks = n; _RouteVias = n; _PinTracks = 0; _PinVias = 0; Sum = 2 * n; }
77 void setRoute(int8_t n, int8_t m) { _RouteTracks = n; _RouteVias = m; _PinTracks = 0; _PinVias = 0; Sum = n + m; }
78 void setRouteTracks(int8_t n) { _RouteTracks = n; _RouteVias = 0; _PinTracks = 0; _PinVias = 0; Sum = n; }
79 void setRouteVias(int8_t n) { _RouteTracks = 0; _RouteVias = n; _PinTracks = 0; _PinVias = 0; Sum = n; }
80 void reset() { _RouteTracks = 0; _RouteVias = 0; _PinTracks = 0; _PinVias = 0; Sum = 0; }
81 bool isZero()
const {
return _RouteTracks == 0 && _RouteVias == 0 && _PinTracks == 0 && _PinVias == 0 && RRRTrack == 0; }
82 int8_t _RouteTracks{0};
106inline bool NavRasterizeParams::isNoop()
const
118 void setRefPoint(
int x,
int y,
int z) { mRefX = x; mRefY = y; mLayer = z; assert(x >= 0 && x <= 32767); assert(y >= 0 && y <= 32767); assert(z >= 0 && z <= 65535); }
120 Point_2 getRefPoint(
const UniformGrid25 *nav)
const {
return nav->MidPoint(mRefX, mRefY); }
122 uint8_t getLayer()
const {
return mLayer; }
124 bool hasEdge(
GridDirection d)
const {
return mEdgeMask & (1 << d.n()); }
132 void resetKO() { mKOCount.reset(); clearFlags(NAV_POINT_FLAGS_CLEARANCE); }
133 bool canRoute()
const {
return !(mFlags & NAV_POINT_FLAGS_TRACKS_BLOCKED); }
134 bool canPlaceVia()
const {
return !(mFlags & NAV_POINT_FLAGS_VIAS_BLOCKED); }
135 bool canPlaceViaEver()
const {
return !(mFlags & NAV_POINT_FLAGS_VIAS_BLOCKED_P); }
136 bool canAddVia(
const NavPoint &to)
const;
137 bool canAddViaEver(
const NavPoint &to)
const;
138 bool insidePin()
const {
return (mFlags & NAV_POINT_FLAG_INSIDE_PIN); }
139 bool hasFlags(uint16_t mask)
const {
return !!(mFlags & mask); }
140 uint16_t getFlags()
const {
return mFlags; }
141 void setFlags(uint16_t mask) { mFlags |= mask; }
142 void clearFlags(uint16_t mask) { mFlags &= ~mask; }
143 void saveFlags() { mFlagsSaved = mFlags; }
144 void restoreFlags() { mFlags = mFlagsSaved; }
149 float getCost(uint term)
const {
return mCosts[term]; }
150 void setCost(uint term,
float cost) { mCosts[term] = cost; }
151 float getScore()
const {
return mScore; }
152 void setScore(
float score) { mScore = score; }
154 NavPoint *getBackEdge(
NavGrid &nav)
const {
return getEdge(nav, mBackDir); }
161 uint16_t getWriteSeq()
const {
return mWriteSeq; }
162 void setWriteSeq(uint16_t v) { mWriteSeq = v; }
164 std::string str(
const NavGrid *)
const;
168 float mCosts[GYM_PCB_NAVPOINT_NUM_COST_TERMS]{1.0f};
171 uint16_t mFlagsSaved{0};
172 uint16_t mEdgeMask{0};
177 uint16_t mWriteSeq{0};
181inline bool NavPoint::canAddVia(
const NavPoint &to)
const
183 return canPlaceVia() && to.canPlaceVia() && !((mFlags ^ to.mFlags) & NAV_POINT_FLAG_INSIDE_PIN);
185inline bool NavPoint::canAddViaEver(
const NavPoint &to)
const
187 return canPlaceViaEver() && to.canPlaceViaEver() && !((mFlags ^ to.mFlags) & NAV_POINT_FLAG_INSIDE_PIN);
193 mEdgeMask |= 1 << d.n();
194 else mEdgeMask &= ~(1 << d.n());
197inline void NavPoint::copyFrom(
const NavPoint &nav)
199 assert(mRefX == nav.mRefX && mRefY == nav.mRefY && mLayer == nav.mLayer);
200 for (uint i = 0; i < GYM_PCB_NAVPOINT_NUM_COST_TERMS; ++i)
201 mCosts[i] = nav.mCosts[i];
203 mKOCount = nav.mKOCount;
211 mFlags &= ~NAV_POINT_FLAGS_CLEARANCE;
212 if (mKOCount._RouteTracks += data.KOCount._RouteTracks) mFlags |= NAV_POINT_FLAG_ROUTE_TRACK_CLEARANCE;
213 if (mKOCount._RouteVias += data.KOCount._RouteVias) mFlags |= NAV_POINT_FLAG_ROUTE_VIA_CLEARANCE;
214 if (mKOCount._PinTracks += data.KOCount._PinTracks) mFlags |= NAV_POINT_FLAG_PIN_TRACK_CLEARANCE;
215 if (mKOCount._PinVias += data.KOCount._PinVias) mFlags |= NAV_POINT_FLAG_PIN_VIA_CLEARANCE;
Definition NavPoint.hpp:53
Definition GridDirection.hpp:6
The grid-representation of the board.
Definition NavGrid.hpp:61
Definition NavPoint.hpp:116
Definition Geometry.hpp:131
Definition Geometry.hpp:155
Definition NavPoint.hpp:71
Definition NavPoint.hpp:93
uint16_t FlagsAnd
Skip all operations for points with hasFlags(IgnoreMask).
Definition NavPoint.hpp:96
uint16_t IgnoreMask
Expand shapes outward by this amount (ignored with AutoExpand).
Definition NavPoint.hpp:95
uint16_t FlagsOr
Clear flags not set here (may remove CLEARANCE).
Definition NavPoint.hpp:97
int8_t TrackRasterCount
Added to NavPoint's counts to determine CLEARANCE flags.
Definition NavPoint.hpp:102
bool AutoIncrementWriteSeq
Whether to rasterize the track & via clearance areas (assumes KOCount.Tracks != 0).
Definition NavPoint.hpp:100
bool AutoExpand
Used to prevent writing overlapping points of track segments/joints twice.
Definition NavPoint.hpp:99
uint16_t WriteSeq
Set these flags (after FlagsAnd).
Definition NavPoint.hpp:98