PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Loaders/DSN.hpp Source File

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
13 struct 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
23 BBox get_bounding_box(const std::vector<double> &xy, double expansion);
24
25 struct 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
36 struct 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
60 struct Segment
61{
62 double x0, y0, x1, y1;
63 double w;
64 int z;
65};
66
67 struct Via
68{
69 double dia;
70 double drill;
71 double x, y;
72 int z0, z1;
73};
74
75 struct 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
87 struct Connection
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
103 struct 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
119 struct 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
130 struct 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
145 struct Padstack
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
155 struct 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
172 struct 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
183 struct Structure
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
195 struct Placement
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
210 struct 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
dsn::BBox
Definition DSN.hpp:14
dsn::Connection
Definition DSN.hpp:88
dsn::Data
Definition DSN.hpp:211
dsn::Image
Definition DSN.hpp:173
dsn::Layer
Definition DSN.hpp:37
dsn::Net
Definition DSN.hpp:104
dsn::PCB
Definition DSN.hpp:26
dsn::Padstack
Definition DSN.hpp:146
dsn::Path
Definition DSN.hpp:120
dsn::Pin
Definition DSN.hpp:156
dsn::Placement
Definition DSN.hpp:196
dsn::Segment
Definition DSN.hpp:61
dsn::Shape
Definition DSN.hpp:131
dsn::Structure
Definition DSN.hpp:184
dsn::Track
Definition DSN.hpp:76
dsn::Via
Definition DSN.hpp:68