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 "step_export_settings.hpp"
25 #include <fstream>
26 #include <map>
27 #include <vector>
28 
29 namespace horizon {
30 using json = nlohmann::json;
31 
32 class Board : public ObjectProvider, public LayerProvider {
33 private:
34  // unsigned int update_nets();
35  void propagate_nets();
36  std::map<int, Layer> layers;
37 
38  void delete_dependants();
39  void vacuum_junctions();
40 
41 public:
42  Board(const UUID &uu, const json &, Block &block, Pool &pool, ViaPadstackProvider &vpp);
43  static Board new_from_file(const std::string &filename, Block &block, Pool &pool, ViaPadstackProvider &vpp);
44  Board(const UUID &uu, Block &block);
45 
46  void expand(bool careful = false);
47  void expand_packages();
48 
49  Board(const Board &brd);
50  void operator=(const Board &brd) = delete;
51  void update_refs();
52  void update_airwires(bool fast = false, const std::set<UUID> &nets = {});
53  void disconnect_package(BoardPackage *pkg);
54 
55  void smash_package(BoardPackage *pkg);
56  void unsmash_package(BoardPackage *pkg);
57  void smash_package_silkscreen_graphics(BoardPackage *pkg);
58 
59  Junction *get_junction(const UUID &uu) override;
60  Polygon *get_polygon(const UUID &uu) override;
61  const std::map<int, Layer> &get_layers() const override;
62  void set_n_inner_layers(unsigned int n);
63  unsigned int get_n_inner_layers() const;
64  void update_plane(Plane *plane, const class CanvasPatch *ca = nullptr,
65  const class CanvasPads *ca_pads = nullptr); // when ca is given, patches will be read from it
66  void update_planes();
67  std::vector<KeepoutContour> get_keepout_contours() const;
68  std::pair<Coordi, Coordi> get_bbox() const;
69  void update_pdf_export_settings(PDFExportSettings &settings);
70 
71  UUID uuid;
72  Block *block;
73  std::string name;
74  std::map<UUID, Polygon> polygons;
75  std::map<UUID, BoardHole> holes;
76  std::map<UUID, BoardPackage> packages;
77  std::map<UUID, Junction> junctions;
78  std::map<UUID, Track> tracks;
79  std::map<UUID, Track> airwires;
80  std::map<UUID, Via> vias;
81  std::map<UUID, Text> texts;
82  std::map<UUID, Line> lines;
83  std::map<UUID, Arc> arcs;
84  std::map<UUID, Plane> planes;
85  std::map<UUID, Keepout> keepouts;
86  std::map<UUID, Dimension> dimensions;
87  std::map<UUID, ConnectionLine> connection_lines;
88 
89  std::vector<Warning> warnings;
90 
91  BoardRules rules;
92  FabOutputSettings fab_output_settings;
93 
94  class StackupLayer {
95  public:
96  StackupLayer(int l, const json &j);
97  StackupLayer(int l);
98  json serialize() const;
99  int layer;
100  uint64_t thickness = 0.035_mm;
101  uint64_t substrate_thickness = .1_mm;
102  };
103  std::map<int, StackupLayer> stackup;
104 
105  class Colors {
106  public:
107  Colors();
108  Color solder_mask;
109  Color substrate;
110  };
111  Colors colors;
112  PDFExportSettings pdf_export_settings;
113  STEPExportSettings step_export_settings;
114 
115  ClipperLib::Paths obstacles;
116  ClipperLib::Path track_path;
117 
118  enum ExpandFlags {
119  EXPAND_ALL = 0xff,
120  EXPAND_PROPAGATE_NETS = (1 << 0),
121  EXPAND_AIRWIRES = (1 << 1),
122  EXPAND_PACKAGES = (1 << 2)
123  };
124 
125  ExpandFlags expand_flags = EXPAND_ALL;
126  std::set<UUID> packages_expand;
127 
128  json serialize() const;
129 
130 private:
131  unsigned int n_inner_layers = 0;
132  ClipperLib::Paths get_thermals(class Plane *plane, const class CanvasPads *ca) const;
133  void flip_package_layer(int &layer) const;
134 };
135 } // 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:32
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:94
horizon::STEPExportSettings
Definition: step_export_settings.hpp:10
horizon::Board::Colors
Definition: board.hpp:105
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:165
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