Horizon
padstack.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "common/hole.hpp"
4 #include "common/layer_provider.hpp"
5 #include "common/lut.hpp"
6 #include "common/polygon.hpp"
7 #include "common/shape.hpp"
8 #include "nlohmann/json_fwd.hpp"
9 #include "parameter/program.hpp"
10 #include "util/uuid.hpp"
11 #include "util/uuid_provider.hpp"
12 #include <fstream>
13 #include <map>
14 #include <set>
15 #include <vector>
16 
17 namespace horizon {
18 using json = nlohmann::json;
19 
20 class Padstack : public UUIDProvider, public LayerProvider {
21 public:
23  friend Padstack;
24 
25  private:
26  ParameterProgram::CommandHandler get_command(const std::string &cmd) override;
27  class Padstack *ps = nullptr;
28 
29  std::pair<bool, std::string> set_shape(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
30  std::pair<bool, std::string> set_hole(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
31  std::pair<bool, std::string> set_polygon(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
32 
33  public:
34  MyParameterProgram(class Padstack *p, const std::string &code);
35  };
36 
37  enum class Type { TOP, BOTTOM, THROUGH, VIA, HOLE, MECHANICAL };
38  static const LutEnumStr<Padstack::Type> type_lut;
39 
40  Padstack(const UUID &uu, const json &j);
41  Padstack(const UUID &uu);
42  static Padstack new_from_file(const std::string &filename);
43 
44  json serialize() const;
45 
46  Padstack(const Padstack &ps);
47  void operator=(Padstack const &ps);
48 
49  UUID uuid;
50  std::string name;
51  Type type = Type::TOP;
52  std::map<UUID, Polygon> polygons;
53  std::map<UUID, Hole> holes;
54  std::map<UUID, Shape> shapes;
55 
56  ParameterSet parameter_set;
57  MyParameterProgram parameter_program;
58  std::pair<bool, std::string> apply_parameter_set(const ParameterSet &ps);
59 
60  UUID get_uuid() const override;
61  std::pair<Coordi, Coordi> get_bbox(bool copper_only = false) const;
62  void expand_inner(unsigned int n_inner);
63  const std::map<int, Layer> &get_layers() const override;
64 
65 private:
66  void update_refs();
67 };
68 } // namespace horizon
a class to store JSON values
Definition: json.hpp:161
Definition: program.hpp:11
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
Definition: padstack.hpp:20
Definition: layer_provider.hpp:7
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: block.cpp:7
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
Definition: program.hpp:48
Definition: padstack.hpp:22