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 "parameter/program_polygon.hpp"
11 #include "util/uuid.hpp"
12 #include <fstream>
13 #include <map>
14 #include <set>
15 #include <vector>
16 #include "util/file_version.hpp"
17 
18 namespace horizon {
19 using json = nlohmann::json;
20 
21 class Padstack : public LayerProvider {
22 public:
23  class MyParameterProgram : public ParameterProgramPolygon {
24  friend Padstack;
25 
26  protected:
27  std::map<UUID, Polygon> &get_polygons() override;
28 
29  private:
30  ParameterProgram::CommandHandler get_command(const std::string &cmd) override;
31  class Padstack *ps = nullptr;
32 
33  std::pair<bool, std::string> set_shape(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
34  std::pair<bool, std::string> set_hole(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
35 
36  public:
37  MyParameterProgram(class Padstack *p, const std::string &code);
38  };
39 
40  enum class Type { TOP, BOTTOM, THROUGH, VIA, HOLE, MECHANICAL };
41  static const LutEnumStr<Padstack::Type> type_lut;
42 
43  Padstack(const UUID &uu, const json &j);
44  Padstack(const UUID &uu);
45  static Padstack new_from_file(const std::string &filename);
46 
47  json serialize() const;
48 
49  Padstack(const Padstack &ps);
50  void operator=(Padstack const &ps);
51 
52  UUID uuid;
53  std::string name;
54  std::string well_known_name;
55  Type type = Type::TOP;
56  std::map<UUID, Polygon> polygons;
57  std::map<UUID, Hole> holes;
58  std::map<UUID, Shape> shapes;
59 
60  ParameterSet parameter_set;
61  std::set<ParameterID> parameters_required;
62  MyParameterProgram parameter_program;
63 
64  FileVersion version;
65 
66  std::pair<bool, std::string> apply_parameter_set(const ParameterSet &ps);
67 
68  UUID get_uuid() const;
69  std::pair<Coordi, Coordi> get_bbox(bool copper_only = false) const;
70  void expand_inner(unsigned int n_inner);
71  const std::map<int, Layer> &get_layers() const override;
72 
73 private:
74  void update_refs();
75 };
76 } // namespace horizon
MyParameterProgram
Definition: pgm-test.cpp:7
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:166
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61