PCB Environment 2
Loading...
Searching...
No Matches
DSN.hpp
1#ifndef GYM_PCB_LOADERS_DSN_H
2#define GYM_PCB_LOADERS_DSN_H
3
4#include <map>
5#include <set>
6#include <string>
7#include <vector>
8
9namespace dsn {
10
11struct Placement;
12
13struct BBox
14{
15 double xmin;
16 double ymin;
17 double xmax;
18 double ymax;
19 double minExtent() const { return std::min(xmax - xmin, ymax - ymin); }
20 double maxExtent() const { return std::max(xmax - xmin, ymax - ymin); }
21};
22
23BBox get_bounding_box(const std::vector<double> &xy, double expansion);
24
25struct PCB
26{
27 std::string str() const;
28
29 std::string name;
30 int unit_ex;
31 int resolution_ex;
32 double unit{1.0};
33 double resolution;
34};
35
36struct Layer
37{
38 std::string str() const;
39
40 std::string name;
41 std::string type;
42 int copper_index{-1};
43 int kicad_index{-1};
44 char side{'m'};
45
46 bool operator<(const Layer &L) const
47 {
48 if (side == 't' && L.side != 't')
49 return true;
50 if (side == 'b' && L.side != 'b')
51 return false;
52 if (side == 'i' && L.side != 'i')
53 return L.side == 'b';
54 if (kicad_index != L.kicad_index)
55 return kicad_index < L.kicad_index;
56 return name < L.name;
57 }
58};
59
60struct Segment
61{
62 double x0, y0, x1, y1;
63 double w;
64 int z;
65};
66
67struct Via
68{
69 double dia;
70 double drill;
71 double x, y;
72 int z0, z1;
73};
74
75struct Track
76{
77 double start_x, start_y;
78 double end_x, end_y;
79 int start_z;
80 int end_z;
81 double default_width;
82 double default_via_diameter;
83 std::vector<Segment> segments;
84 std::vector<Via> vias;
85};
86
88{
89 std::string src_pin;
90 std::string dst_pin;
91 bool has_src_pin{false};
92 bool has_dst_pin{false};
93 bool has_src{false};
94 bool has_dst{false};
95 double x0, y0;
96 double x1, y1;
97 int z0, z1;
98 double clearance;
99 double ref_len{0.0};
100 std::vector<Track> tracks;
101};
102
103struct Net
104{
105 std::string str() const;
106
107 std::string name;
108 std::string klass;
109 int index{-1};
110 std::set<std::string> pins;
111 double clearance{0.0};
112 double via_diameter{0.0};
113 double width{0.0};
114 std::vector<Segment> segments;
115 std::vector<Via> vias;
116 std::vector<Connection> connections;
117};
118
119struct Path
120{
121 BBox bbox() const;
122 bool operator==(const Path&) const;
123 std::string str(bool verbose = false) const;
124
125 double aperture_width{0.0};
126 std::vector<double> xy;
127 int z{-1};
128};
129
130struct Shape
131{
132 double minExtent() const;
133 double maxExtent() const;
134 bool operator==(const Shape&) const;
135 std::string str(bool verbose = false) const;
136
137 std::string geometry;
138 std::vector<double> values; // circle stores diameter not radius
139 int z;
140 Path path;
141
142 void recenter();
143};
144
146{
147 std::string str(bool verbose = false) const;
148
149 std::string name;
150 std::string type;
151 std::vector<Shape> shapes;
152 bool attach;
153};
154
155struct Pin
156{
157 std::string str() const;
158
159 Padstack *padstack{0};
160 std::string name;
161 std::string net;
162 int index;
163 int angle{0};
164 double x, y;
165 int z0 = std::numeric_limits<int>::max();
166 int z1 = -1;
167 double clearance{0.0};
168 bool has_net{false};
169 std::optional<std::string> compound;
170};
171
172struct Image
173{
174 std::string str() const;
175
176 std::string name;
177 std::vector<Pin> pins;
178 dsn::Shape footprint;
179
180 std::vector<Placement *> placements;
181};
182
184{
185 std::string str() const;
186
187 std::vector<Layer *> copper_layers;
188 std::vector<Layer> layers;
189 Path boundary;
190 std::map<std::string, std::string> via;
191 std::map<std::string, double> width;
192 std::map<std::string, double> clearance;
193};
194
196{
197 std::string str() const;
198
199 std::string name;
200 dsn::Image *image{0};
201 double x, pinref_x;
202 double y, pinref_y;
203 int z;
204 int angle{0};
205 double clearance{0};
206 bool via_ok{true};
207 bool can_route{false};
208};
209
210struct Data
211{
212 static bool parseDSN(dsn::Data&, const std::string&);
213 static bool parseJSON(dsn::Data&, const std::string&);
214 static bool parseKiCAD(dsn::Data&, const std::string&);
215 std::string str() const;
216
217 dsn::PCB pcb;
218 dsn::Structure structure;
219 std::map<std::string, dsn::Image> images;
220 std::map<std::string, dsn::Padstack> padstacks;
221 std::map<std::string, dsn::Net> nets;
222 std::vector<dsn::Placement> placements;
223
224 void renamePinsWithSharedNames();
225 void inferMissingNetWidths();
226 void printNetWidths() const;
227};
228
229} // namespace dsn
230
231#endif // GYM_PCB_LOADERS_DSN_H
Definition DSN.hpp:14
Definition DSN.hpp:88
Definition DSN.hpp:211
Definition DSN.hpp:173
Definition DSN.hpp:37
Definition DSN.hpp:104
Definition DSN.hpp:26
Definition DSN.hpp:146
Definition DSN.hpp:120
Definition DSN.hpp:156
Definition DSN.hpp:196
Definition DSN.hpp:61
Definition DSN.hpp:131
Definition DSN.hpp:184
Definition DSN.hpp:76
Definition DSN.hpp:68