Horizon
package.hpp
1 #pragma once
2 #include "common/arc.hpp"
3 #include "common/common.hpp"
4 #include "common/hole.hpp"
5 #include "common/junction.hpp"
6 #include "common/layer_provider.hpp"
7 #include "common/line.hpp"
8 #include "common/object_provider.hpp"
9 #include "common/polygon.hpp"
10 #include "common/text.hpp"
11 #include "common/keepout.hpp"
12 #include "common/dimension.hpp"
13 #include "nlohmann/json_fwd.hpp"
14 #include "package/package_rules.hpp"
15 #include "package/pad.hpp"
16 #include "util/uuid.hpp"
17 #include "util/warning.hpp"
18 #include "parameter/program_polygon.hpp"
19 #include "common/picture.hpp"
20 #include <fstream>
21 #include <map>
22 #include <set>
23 #include <vector>
24 #include "util/file_version.hpp"
25 
26 namespace horizon {
27 using json = nlohmann::json;
28 
29 class Package : public ObjectProvider, public LayerProvider {
30 public:
31  class MyParameterProgram : public ParameterProgramPolygon {
32  friend Package;
33 
34  protected:
35  std::map<UUID, Polygon> &get_polygons() override;
36 
37  private:
38  ParameterProgram::CommandHandler get_command(const std::string &cmd) override;
39  class Package *pkg = nullptr;
40 
41  public:
42  MyParameterProgram(class Package *p, const std::string &code);
43  };
44 
45  class Model {
46  public:
47  Model(const UUID &uu, const std::string &filename);
48  Model(const UUID &uu, const json &j);
49 
50  UUID uuid;
51  std::string filename;
52 
53  int64_t x = 0;
54  int64_t y = 0;
55  int64_t z = 0;
56 
57  int roll = 0;
58  int pitch = 0;
59  int yaw = 0;
60 
61  json serialize() const;
62  };
63 
64  Package(const UUID &uu, const json &j, class IPool &pool);
65  Package(const UUID &uu);
66  static Package new_from_file(const std::string &filename, class IPool &pool);
67 
68  json serialize() const;
69  Junction *get_junction(const UUID &uu) override;
70  Polygon *get_polygon(const UUID &uu) override;
71  std::pair<Coordi, Coordi> get_bbox() const;
72  const std::map<int, Layer> &get_layers() const override;
73  std::pair<bool, std::string> apply_parameter_set(const ParameterSet &ps);
74  void expand();
75  void update_warnings();
76  int get_max_pad_name() const;
77 
78  UUID get_uuid() const;
79 
80  Package(const Package &pkg);
81  void operator=(Package const &pkg);
82 
83  UUID uuid;
84  std::string name;
85  std::string manufacturer;
86  std::set<std::string> tags;
87 
88  std::map<UUID, Junction> junctions;
89  std::map<UUID, Line> lines;
90  std::map<UUID, Arc> arcs;
91  std::map<UUID, Text> texts;
92  std::map<UUID, Pad> pads;
93  std::map<UUID, Polygon> polygons;
94  std::map<UUID, Keepout> keepouts;
95  std::map<UUID, Dimension> dimensions;
96  std::map<UUID, Picture> pictures;
97 
98  ParameterSet parameter_set;
99  MyParameterProgram parameter_program;
100  PackageRules rules;
101 
102  std::map<UUID, Model> models;
103  UUID default_model;
104  const Model *get_model(const UUID &uu = UUID()) const;
105 
106  const class Package *alternate_for = nullptr;
107 
108  FileVersion version;
109 
110  std::vector<Warning> warnings;
111 
112  void update_refs(class IPool &pool);
113 
114  void save_pictures(const std::string &dir) const;
115  void load_pictures(const std::string &dir);
116 
117 private:
118  void update_refs();
119 };
120 } // namespace horizon
MyParameterProgram
Definition: pgm-test.cpp:7
libzip::int64_t
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103
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