PCB Environment 2

Loading...
Searching...
No Matches
Connection.hpp
1#ifndef GYM_PCB_CONNECTION_H
2#define GYM_PCB_CONNECTION_H
3
4#include "Py.hpp"
5#include "Defs.hpp"
6#include "Color.hpp"
7#include "Pin.hpp"
8
9 class CloneEnv;
10 class Component;
11 class Net;
12 class Track;
13 class UniformGrid25;
14 class NavGrid;
15
16 class Connection
17{
18 constexpr static const bool EndpointsOnMaskedLayersOK = true;
19 public:
20 Connection *clone(CloneEnv&) const;
21 Connection(Net *, const Point_25 &source, Pin *sourcePin, const Point_25 &target, Pin *targetPin);
22 Connection(const Connection&, const Point_25 &source, const Point_25 &target);
23 ~Connection();
24
25 void setId(int id) { mId = id; }
26 int id() const { return mId; }
27 std::string name() const;
28 bool hasNet() const { return !!mNet; }
29 Net *net() const { return mNet; }
30
31 const Point_25& source() const { return mSource; }
32 const Point_25& target() const { return mTarget; }
33 Pin *sourcePin() const { return mSourcePin; }
34 Pin *targetPin() const { return mTargetPin; }
35 Pin *otherPin(const Pin *) const;
36
37 Component *sourceComponent() const { return mSourcePin ? mSourcePin->getParent() : 0; }
38 Component *targetComponent() const { return mTargetPin ? mTargetPin->getParent() : 0; }
39
40 Vector_2 vector2() const { return target().xy() - source().xy(); }
41 Segment_2 segment2() const { return Segment_2(source().xy(), target().xy()); }
42
43 void detachSourcePin();
44 void detachTargetPin();
45
46 void forceEndpointsToGrid(const UniformGrid25&);
47
48 bool hasTracks() const { return !mTracks.empty(); }
49 uint numTracks() const { return mTracks.size(); }
50 const std::vector<Track *>& getTracks() const { return mTracks; }
51 Track& getTrack(uint i) const { return *mTracks.at(i); }
52 Track *getTrackAt(const Point_25&) const;
53 Track *newTrack(const Point_25 &start);
54 Track *popTrack(uint index);
55 void clearTracks();
56
57 bool isRouted() const { return mIsRouted; }
58 bool _isRouted() const;
59 void setRouted(bool b) { mIsRouted = b; }
60 bool checkRouted() { setRouted(_isRouted()); return isRouted(); }
61
65 void forceRouted();
66
67 bool isLocked() const { return mLocked; }
68 void setLocked(bool b) { mLocked = b; }
69
74 void setTrack(Track *);
75 void setTrack(Track&&);
76 void setTrack(const Track&);
77
82 void appendTrack(Track *T);
83 void appendTrack(const Track &T);
84
85 void reverse();
86
94 void makeDirectTrack45(Real minSquaredLen, uint viaLocation, float bendLocation);
95 void makeDirectTrack(Real minSquaredLen, uint viaLocation);
96
103 bool updateForRemovedLayers(uint removedZMin, uint removedZMax);
104
109 std::vector<std::pair<Point_25, Point_25>> getRatsNest() const;
110
111 bool arePinsOnNet(const Net *) const;
112
113 Real clearance() const { return mClearance; }
114 Real defaultWidth() const { return mWidth; }
115 Real defaultViaDiameter() const { return mViaDiameter; }
116 Real defaultViaRadius() const { return mViaDiameter * 0.5; }
117
118 void setClearance(Real c) { mClearance = c; }
119 void setDefaultWidth(float w) { mWidth = w; }
120 void setDefaultViaDiameter(Real d) { mViaDiameter = d; }
121
122 bool canRouteOnLayer(uint n) const { return mLayerMask & (1 << n); }
123 uint32_t getLayerMask() const { return mLayerMask; }
124
125 void setLayerMask(uint32_t);
126
127 void setParametersFrom(const Connection&);
128
129 float referenceLen() const { return mReferenceLen; }
130 void setReferenceLen(float v) { assert(mReferenceLen == 0.0f && v > 0.0f); mReferenceLen = v; }
131
132 Bbox_2 tracksBbox() const;
133 Bbox_2 bbox() const;
134 Bbox_2 bboxAroundComps() const;
135
136 Real squared_distance() const { return CGAL::squared_distance(mSource.xy(), mTarget.xy()); }
137 Real distance() const { return std::sqrt(squared_distance()); }
138 Real distance45() const { return geo::distance45(mSource.xy(), mTarget.xy()); }
139
140 bool isOrderedXMajor() const;
141
142 uint numNecessaryVias() const;
143
144 template<class Container> static void sort_name(Container&);
145
150 bool intersects(const Connection&) const;
151
156 bool isRasterized_allOrNone() const;
157
161 bool checkRasterization(const NavGrid&) const;
162
163 void setColor(Color c) { mColor = c; }
164 Color getColor() const;
165
166 std::string str() const;
167
171 PyObject *getEndsPy() const;
175 PyObject *getTracksPy(bool asNumpy) const;
176 PyObject *getPy(uint depth, bool asNumpy) const;
177 private:
178 Point_25 mSource;
179 Point_25 mTarget;
180 Pin *mSourcePin;
181 Pin *mTargetPin;
182 Net *const mNet;
183 std::vector<Track *> mTracks;
184 Real mClearance;
185 Real mWidth;
186 Real mViaDiameter;
187 uint32_t mLayerMask{0xffffffff};
188 int mId{-1};
189 bool mIsRouted{false};
190 bool mLocked{false};
191 float mReferenceLen{0.0f};
192 Color mColor{Color::TRANSPARENT};
193
194 private:
195 void mergeTrack(Track *);
196 void deleteEmptyTracks();
197 void updateEndpointForLayerMask(bool target);
198};
199
200 inline void Connection::setParametersFrom(const Connection &X)
201{
202 setClearance(X.clearance());
203 setDefaultWidth(X.defaultWidth());
204 setDefaultViaDiameter(X.defaultViaDiameter());
205 setLayerMask(X.getLayerMask());
206}
207 inline Pin *Connection::otherPin(const Pin *P) const
208{
209 assert(mSourcePin == P || mTargetPin == P);
210 return (mSourcePin == P) ? mTargetPin : mSourcePin;
211}
212
213 inline Track *Connection::popTrack(uint index)
214{
215 setRouted(false);
216 const auto T = mTracks.at(index);
217 mTracks.erase(mTracks.begin() + index);
218 return T;
219}
220
221 template<class Container> void Connection::sort_name(Container &A)
222{
223 std::sort(A.begin(),
224 A.end(),
225 [](const Connection *const L, const Connection *const R) -> bool { return L->name() < R->name(); });
226}
227
228#endif // GYM_PCB_CONNECTION_H
CloneEnv
Definition Clone.hpp:17
Color
Definition Color.hpp:9
Component
Definition Component.hpp:18
Connection
Definition Connection.hpp:17
Connection::appendTrack
void appendTrack(Track *T)
Connection::getEndsPy
PyObject * getEndsPy() const
Connection::getRatsNest
std::vector< std::pair< Point_25, Point_25 > > getRatsNest() const
Connection::setTrack
void setTrack(Track *)
Connection::getTracksPy
PyObject * getTracksPy(bool asNumpy) const
Connection::numNecessaryVias
uint numNecessaryVias() const
Connection::arePinsOnNet
bool arePinsOnNet(const Net *) const
Connection::getPy
PyObject * getPy(uint depth, bool asNumpy) const
Connection::isOrderedXMajor
bool isOrderedXMajor() const
Connection::makeDirectTrack45
void makeDirectTrack45(Real minSquaredLen, uint viaLocation, float bendLocation)
Connection::intersects
bool intersects(const Connection &) const
Connection::forceRouted
void forceRouted()
Connection::reverse
void reverse()
Connection::setColor
void setColor(Color c)
Definition Connection.hpp:163
Connection::checkRasterization
bool checkRasterization(const NavGrid &) const
Connection::isRasterized_allOrNone
bool isRasterized_allOrNone() const
Connection::updateForRemovedLayers
bool updateForRemovedLayers(uint removedZMin, uint removedZMax)
NavGrid
The grid-representation of the board.
Definition NavGrid.hpp:61
Net
Definition Net.hpp:19
Pin
Definition Pin.hpp:18
Point_25
Definition Geometry.hpp:131
Track
Definition Track.hpp:21
UniformGrid25
Definition UniformGrid25.hpp:9