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 "nlohmann/json_fwd.hpp"
12 #include "package/package_rules.hpp"
13 #include "package/pad.hpp"
14 #include "util/uuid.hpp"
15 #include "util/uuid_provider.hpp"
16 #include "util/warning.hpp"
17 #include <fstream>
18 #include <map>
19 #include <set>
20 #include <vector>
21 
22 namespace horizon {
23 using json = nlohmann::json;
24 
25 class Package : public ObjectProvider, public LayerProvider, public UUIDProvider {
26 public:
28  friend Package;
29 
30  private:
31  ParameterProgram::CommandHandler get_command(const std::string &cmd) override;
32  class Package *pkg = nullptr;
33 
34  std::pair<bool, std::string> set_polygon(const ParameterProgram::TokenCommand *cmd, std::deque<int64_t> &stack);
35  std::pair<bool, std::string> expand_polygon(const ParameterProgram::TokenCommand *cmd,
36  std::deque<int64_t> &stack);
37 
38  public:
39  MyParameterProgram(class Package *p, const std::string &code);
40  };
41 
42  class Model {
43  public:
44  Model(const UUID &uu, const std::string &filename);
45  Model(const UUID &uu, const json &j);
46 
47  UUID uuid;
48  std::string filename;
49 
50  int64_t x = 0;
51  int64_t y = 0;
52  int64_t z = 0;
53 
54  int roll = 0;
55  int pitch = 0;
56  int yaw = 0;
57 
58  json serialize() const;
59  };
60 
61  Package(const UUID &uu, const json &j, class Pool &pool);
62  Package(const UUID &uu);
63  static Package new_from_file(const std::string &filename, class Pool &pool);
64 
65  json serialize() const;
66  virtual Junction *get_junction(const UUID &uu);
67  std::pair<Coordi, Coordi> get_bbox() const;
68  const std::map<int, Layer> &get_layers() const override;
69  std::pair<bool, std::string> apply_parameter_set(const ParameterSet &ps);
70 
71  UUID get_uuid() const;
72 
73  Package(const Package &pkg);
74  void operator=(Package const &pkg);
75 
76  UUID uuid;
77  std::string name;
78  std::string manufacturer;
79  std::set<std::string> tags;
80 
81  std::map<UUID, Junction> junctions;
82  std::map<UUID, Line> lines;
83  std::map<UUID, Arc> arcs;
84  std::map<UUID, Text> texts;
85  std::map<UUID, Pad> pads;
86  std::map<UUID, Polygon> polygons;
87 
88  ParameterSet parameter_set;
89  MyParameterProgram parameter_program;
90  PackageRules rules;
91 
92  std::map<UUID, Model> models;
93  UUID default_model;
94  const Model *get_model(const UUID &uu = UUID()) const;
95 
96  const class Package *alternate_for = nullptr;
97 
98  std::vector<Warning> warnings;
99 
100 private:
101  void update_refs();
102 };
103 } // namespace horizon
Interface for classes that store objects identified by UUID (e.g. Line or Junction) ...
Definition: object_provider.hpp:10
Definition: package.hpp:42
a class to store JSON values
Definition: json.hpp:161
Definition: program.hpp:11
Definition: package.hpp:27
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
Definition: package.hpp:25
Definition: package_rules.hpp:10
Definition: layer_provider.hpp:7
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:18
Definition: block.cpp:7
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
A Junction is a point in 2D-Space.
Definition: junction.hpp:25
Definition: program.hpp:48