Horizon
eda_data.hpp
1 #pragma once
2 #include <list>
3 #include <memory>
4 #include "common/common.hpp"
5 #include "util/uuid.hpp"
6 #include "attribute_util.hpp"
7 #include "surface_data.hpp"
8 
9 namespace horizon {
10 class Net;
11 class Pad;
12 class Package;
13 } // namespace horizon
14 
15 namespace horizon::ODB {
16 
17 class EDAData : public AttributeProvider {
18 public:
19  EDAData();
20 
21  void write(std::ostream &ost) const;
22 
23  class FeatureID {
24  friend EDAData;
25 
26  public:
27  enum class Type { COPPER, LAMINATE, HOLE };
28 
29  FeatureID(Type t, unsigned int l, unsigned int fid) : type(t), layer(l), feature_id(fid)
30  {
31  }
32 
33  Type type;
34  unsigned int layer;
35  unsigned int feature_id;
36 
37  void write(std::ostream &ost) const;
38  };
39 
40  class Subnet {
41  public:
42  Subnet(unsigned int i) : index(i)
43  {
44  }
45  const unsigned int index;
46  void write(std::ostream &ost) const;
47 
48  std::list<FeatureID> feature_ids;
49 
50  virtual ~Subnet() = default;
51 
52  protected:
53  virtual void write_subnet(std::ostream &ost) const = 0;
54  };
55 
56  class SubnetVia : public Subnet {
57  public:
58  using Subnet::Subnet;
59  void write_subnet(std::ostream &ost) const override;
60  };
61 
62  class SubnetTrace : public Subnet {
63  public:
64  using Subnet::Subnet;
65  void write_subnet(std::ostream &ost) const override;
66  };
67 
68  class SubnetPlane : public Subnet {
69  public:
70  enum class FillType { SOLID, OUTLINE };
71  enum class CutoutType { CIRCLE, RECT, OCTAGON, EXACT };
72 
73  SubnetPlane(unsigned int i, FillType ft, CutoutType ct, double fs)
74  : Subnet(i), fill_type(ft), cutout_type(ct), fill_size(fs)
75  {
76  }
77 
78  FillType fill_type;
79  CutoutType cutout_type;
80  double fill_size;
81 
82  void write_subnet(std::ostream &ost) const override;
83  };
84 
85  class SubnetToeprint : public Subnet {
86  public:
87  enum class Side { TOP, BOTTOM };
88 
89  SubnetToeprint(unsigned int i, Side s, unsigned int c, unsigned int t)
90  : Subnet(i), side(s), comp_num(c), toep_num(t)
91  {
92  }
93 
94  Side side;
95 
96  unsigned int comp_num;
97  unsigned int toep_num;
98 
99  void write_subnet(std::ostream &ost) const override;
100  };
101 
102  void add_feature_id(Subnet &subnet, FeatureID::Type type, const std::string &layer, unsigned int feature_id);
103 
104  class Net : public RecordWithAttributes {
105  public:
106  template <typename T> using check_type = attribute::is_net<T>;
107 
108  Net(unsigned int index, const std::string &name);
109  const unsigned int index;
110 
111  std::string name;
112 
113  std::list<std::unique_ptr<Subnet>> subnets;
114 
115  template <typename T, typename... Args> T &add_subnet(Args &&...args)
116  {
117  auto f = std::make_unique<T>(subnets.size(), std::forward<Args>(args)...);
118  auto &r = *f;
119  subnets.push_back(std::move(f));
120  return r;
121  }
122 
123  void write(std::ostream &ost) const;
124  };
125 
126  Net &add_net(const horizon::Net &net);
127  Net &get_net(const UUID &uu)
128  {
129  return nets_map.at(uu);
130  }
131 
132  class Outline {
133  public:
134  virtual void write(std::ostream &ost) const = 0;
135 
136  virtual ~Outline() = default;
137  };
138 
139  class OutlineRectangle : public Outline {
140  public:
141  OutlineRectangle(const Coordi &l, uint64_t w, uint64_t h) : lower(l), width(w), height(h)
142  {
143  }
144  OutlineRectangle(const std::pair<Coordi, Coordi> &bb)
145  : OutlineRectangle(bb.first, bb.second.x - bb.first.x, bb.second.y - bb.first.y)
146  {
147  }
148 
149  Coordi lower;
150  uint64_t width;
151  uint64_t height;
152 
153  void write(std::ostream &ost) const override;
154  };
155 
156  class OutlineContour : public Outline {
157  public:
158  SurfaceData data;
159 
160  void write(std::ostream &ost) const override;
161  };
162 
163  class OutlineSquare : public Outline {
164  public:
165  OutlineSquare(const Coordi &c, uint64_t s) : center(c), half_side(s)
166  {
167  }
168  Coordi center;
169  uint64_t half_side;
170 
171  void write(std::ostream &ost) const override;
172  };
173 
174  class OutlineCircle : public Outline {
175  public:
176  OutlineCircle(const Coordi &c, uint64_t r) : center(c), radius(r)
177  {
178  }
179  Coordi center;
180  uint64_t radius;
181 
182  void write(std::ostream &ost) const override;
183  };
184 
185  class Pin {
186  public:
187  Pin(unsigned int i, const std::string &n);
188  std::string name;
189  const unsigned int index;
190 
191  Coordi center;
192 
193  enum class Type { THROUGH_HOLE, BLIND, SURFACE };
194  Type type = Type::SURFACE;
195 
196  enum class ElectricalType { ELECTRICAL, MECHANICAL, UNDEFINED };
197  ElectricalType etype = ElectricalType::UNDEFINED;
198 
199  enum class MountType {
200  SMT,
201  SMT_RECOMMENDED,
202  THROUGH_HOLE,
203  THROUGH_RECOMMENDED,
204  PRESSFIT,
205  NON_BOARD,
206  HOLE,
207  UNDEFINED
208  };
209  MountType mtype = MountType::UNDEFINED;
210 
211  std::list<std::unique_ptr<Outline>> outline;
212 
213  void write(std::ostream &ost) const;
214  };
215 
216  class Package : public RecordWithAttributes {
217  public:
218  template <typename T> using check_type = attribute::is_pkg<T>;
219 
220  Package(const unsigned int i, const std::string &n);
221  const unsigned int index;
222  std::string name;
223 
224  uint64_t pitch;
225  int64_t xmin, ymin, xmax, ymax;
226 
227  std::list<std::unique_ptr<Outline>> outline;
228 
229  Pin &add_pin(const horizon::Pad &pad);
230  const Pin &get_pin(const UUID &uu) const
231  {
232  return pins_map.at(uu);
233  }
234 
235  void write(std::ostream &ost) const;
236 
237 
238  private:
239  std::map<UUID, Pin> pins_map;
240  std::list<const Pin *> pins;
241  };
242 
243  Package &add_package(const horizon::Package &pkg);
244  const Package &get_package(const UUID &uu) const
245  {
246  return packages_map.at(uu);
247  }
248 
249 private:
250  std::map<UUID, Net> nets_map;
251  std::list<const Net *> nets;
252 
253  std::map<UUID, Package> packages_map;
254  std::list<const Package *> packages;
255 
256  unsigned int get_or_create_layer(const std::string &l);
257 
258  std::map<std::string, unsigned int> layers_map;
259  std::vector<std::string> layers;
260 };
261 } // namespace horizon::ODB
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33
Definition: net.hpp:11
Definition: attribute_util.hpp:10
Definition: eda_data.hpp:23
Definition: eda_data.hpp:104
Definition: eda_data.hpp:174
Definition: eda_data.hpp:156
Definition: eda_data.hpp:139
Definition: eda_data.hpp:163
Definition: eda_data.hpp:132
Definition: eda_data.hpp:216
Definition: eda_data.hpp:185
Definition: eda_data.hpp:68
Definition: eda_data.hpp:85
Definition: eda_data.hpp:62
Definition: eda_data.hpp:56
Definition: eda_data.hpp:40
Definition: eda_data.hpp:17
Definition: attribute_util.hpp:56
Definition: surface_data.hpp:17
Definition: package.hpp:29
Definition: pad.hpp:12
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: attributes.hpp:53
Definition: attributes.hpp:55