Horizon
db.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/placement.hpp"
4 #include "util/uuid.hpp"
5 #include <list>
6 #include <set>
7 #include <variant>
8 #include "attributes.hpp"
9 #include "clipper/clipper.hpp"
10 #include "board/plane.hpp"
11 #include "eda_data.hpp"
12 #include "attribute_util.hpp"
13 #include "features.hpp"
14 #include "components.hpp"
15 #include "symbol.hpp"
16 
17 namespace horizon {
18 class TreeWriter;
19 class Padstack;
20 class Shape;
21 class Polygon;
22 class Package;
23 class Pad;
24 class BoardPackage;
25 } // namespace horizon
26 
27 namespace horizon::ODB {
28 
29 class Symbol;
30 
31 enum class Polarity { POSITIVE, NEGATIVE };
32 
33 class Step {
34 public:
35  std::map<std::string, Features> layer_features;
36  std::optional<Features> profile;
37 
38  std::optional<Components> comp_top;
39  std::optional<Components> comp_bot;
40 
41  EDAData eda_data;
42 
43  Components::Component &add_component(const BoardPackage &pkg);
44 
45  void write(TreeWriter &writer) const;
46 };
47 
48 class Matrix {
49 public:
50  std::map<std::string, unsigned int> steps; // step name -> column
51 
52  class Layer {
53  public:
54  Layer(unsigned int r, const std::string &n) : row(r), name(n)
55  {
56  }
57 
58  const unsigned int row;
59  const std::string name;
60 
61  enum class Context { BOARD, MISC };
62  Context context;
63 
64  enum class Type {
65  SIGNAL,
66  SOLDER_MASK,
67  SILK_SCREEN,
68  SOLDER_PASTE,
69  DRILL,
70  ROUT,
71  DOCUMENT,
72  COMPONENT,
73  };
74  Type type;
75  struct Span {
76  std::string start;
77  std::string end;
78  };
79  std::optional<Span> span;
80 
81  Polarity polarity = Polarity::POSITIVE;
82  };
83  std::vector<Layer> layers;
84 
85  Layer &add_layer(const std::string &name);
86  void add_step(const std::string &name);
87 
88  void write(std::ostream &ost) const;
89 
90 private:
91  unsigned int row = 1;
92  unsigned int col = 1;
93 };
94 
95 class Job {
96 public:
97  Matrix matrix;
98  Matrix::Layer &add_matrix_layer(const std::string &name);
99  Step &add_step(const std::string &name);
100 
101  std::string job_name = "board";
102  std::map<std::string, Step> steps;
103 
104  using SymbolKey = std::tuple<UUID, int, std::string>; // padstack UUID, layer, content hash
105  std::map<SymbolKey, Symbol> symbols;
106  std::set<std::string> symbol_names;
107 
108  std::string get_or_create_symbol(const Padstack &ps, int layer);
109 
110  void write(TreeWriter &writer) const;
111 };
112 
113 std::string enum_to_string(Polarity);
114 std::string enum_to_string(Matrix::Layer::Type);
115 std::string enum_to_string(Matrix::Layer::Context);
116 
117 
118 } // namespace horizon::ODB
Definition: board_package.hpp:13
Definition: components.hpp:25
Definition: eda_data.hpp:17
Definition: db.hpp:95
Definition: db.hpp:52
Definition: db.hpp:48
Definition: db.hpp:33
Definition: padstack.hpp:19
Definition: tree_writer.hpp:7