Horizon
board.hpp
1 #pragma once
2 #include "block/block.hpp"
3 #include "board_hole.hpp"
4 #include "board_package.hpp"
5 #include "board_rules.hpp"
6 #include "clipper/clipper.hpp"
7 #include "common/dimension.hpp"
8 #include "common/hole.hpp"
9 #include "common/junction.hpp"
10 #include "common/layer_provider.hpp"
11 #include "common/polygon.hpp"
12 #include "common/keepout.hpp"
13 #include "common/pdf_export_settings.hpp"
14 #include "fab_output_settings.hpp"
15 #include "nlohmann/json_fwd.hpp"
16 #include "plane.hpp"
17 #include "pool/pool.hpp"
18 #include "track.hpp"
19 #include "util/uuid.hpp"
20 #include "util/warning.hpp"
21 #include "via.hpp"
22 #include "via_padstack_provider.hpp"
23 #include "connection_line.hpp"
24 #include <fstream>
25 #include <map>
26 #include <vector>
27 
28 namespace horizon {
29 using json = nlohmann::json;
30 
31 class Board : public ObjectProvider, public LayerProvider {
32 private:
33  // unsigned int update_nets();
34  void propagate_nets();
35  std::map<int, Layer> layers;
36 
37  void delete_dependants();
38  void vacuum_junctions();
39 
40 public:
41  Board(const UUID &uu, const json &, Block &block, Pool &pool, ViaPadstackProvider &vpp);
42  static Board new_from_file(const std::string &filename, Block &block, Pool &pool, ViaPadstackProvider &vpp);
43  Board(const UUID &uu, Block &block);
44 
45  void expand(bool careful = false);
46  void expand_packages();
47 
48  Board(const Board &brd);
49  void operator=(const Board &brd) = delete;
50  void update_refs();
51  void update_airwires(bool fast = false, const std::set<UUID> &nets = {});
52  void disconnect_package(BoardPackage *pkg);
53 
54  void smash_package(BoardPackage *pkg);
55  void unsmash_package(BoardPackage *pkg);
56  void smash_package_silkscreen_graphics(BoardPackage *pkg);
57 
58  Junction *get_junction(const UUID &uu) override;
59  Polygon *get_polygon(const UUID &uu) override;
60  const std::map<int, Layer> &get_layers() const override;
61  void set_n_inner_layers(unsigned int n);
62  unsigned int get_n_inner_layers() const;
63  void update_plane(Plane *plane, const class CanvasPatch *ca = nullptr,
64  const class CanvasPads *ca_pads = nullptr); // when ca is given, patches will be read from it
65  void update_planes();
66  std::vector<KeepoutContour> get_keepout_contours() const;
67  std::pair<Coordi, Coordi> get_bbox() const;
68  void update_pdf_export_settings(PDFExportSettings &settings);
69 
70  UUID uuid;
71  Block *block;
72  std::string name;
73  std::map<UUID, Polygon> polygons;
74  std::map<UUID, BoardHole> holes;
75  std::map<UUID, BoardPackage> packages;
76  std::map<UUID, Junction> junctions;
77  std::map<UUID, Track> tracks;
78  std::map<UUID, Track> airwires;
79  std::map<UUID, Via> vias;
80  std::map<UUID, Text> texts;
81  std::map<UUID, Line> lines;
82  std::map<UUID, Arc> arcs;
83  std::map<UUID, Plane> planes;
84  std::map<UUID, Keepout> keepouts;
85  std::map<UUID, Dimension> dimensions;
86  std::map<UUID, ConnectionLine> connection_lines;
87 
88  std::vector<Warning> warnings;
89 
90  BoardRules rules;
91  FabOutputSettings fab_output_settings;
92 
93  class StackupLayer {
94  public:
95  StackupLayer(int l, const json &j);
96  StackupLayer(int l);
97  json serialize() const;
98  int layer;
99  uint64_t thickness = 0.035_mm;
100  uint64_t substrate_thickness = .1_mm;
101  };
102  std::map<int, StackupLayer> stackup;
103 
104  class Colors {
105  public:
106  Colors();
107  Color solder_mask;
108  Color substrate;
109  };
110  Colors colors;
111  PDFExportSettings pdf_export_settings;
112 
113  ClipperLib::Paths obstacles;
114  ClipperLib::Path track_path;
115 
116  enum ExpandFlags {
117  EXPAND_ALL = 0xff,
118  EXPAND_PROPAGATE_NETS = (1 << 0),
119  EXPAND_AIRWIRES = (1 << 1),
120  EXPAND_PACKAGES = (1 << 2)
121  };
122 
123  ExpandFlags expand_flags = EXPAND_ALL;
124  std::set<UUID> packages_expand;
125 
126  json serialize() const;
127 
128 private:
129  unsigned int n_inner_layers = 0;
130  ClipperLib::Paths get_thermals(class Plane *plane, const class CanvasPads *ca) const;
131  void flip_package_layer(int &layer) const;
132 };
133 } // namespace horizon
horizon::CanvasPads
Definition: canvas_pads.hpp:7
horizon::Polygon
Polygon used in Padstack, Package and Board for specifying filled Regions.
Definition: polygon.hpp:27
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
libzip::uint64_t
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
horizon::BoardRules
Definition: board_rules.hpp:20
horizon::CanvasPatch
Definition: canvas_patch.hpp:6
horizon::Board
Definition: board.hpp:31
horizon::ViaPadstackProvider
Definition: via_padstack_provider.hpp:13
horizon::Color
Definition: common.hpp:213
horizon::Block
A block is one level of hierarchy in the netlist.
Definition: block.hpp:26
horizon::LayerProvider
Definition: layer_provider.hpp:7
horizon::BoardPackage
Definition: board_package.hpp:17
horizon::Board::StackupLayer
Definition: board.hpp:93
horizon::Board::Colors
Definition: board.hpp:104
horizon::FabOutputSettings
Definition: fab_output_settings.hpp:10
horizon::Junction
A Junction is a point in 2D-Space.
Definition: junction.hpp:25
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
horizon::ObjectProvider
Interface for classes that store objects identified by UUID (e.g. Line or Junction)
Definition: object_provider.hpp:10
horizon::Plane
Definition: plane.hpp:39
horizon::PDFExportSettings
Definition: pdf_export_settings.hpp:9