Horizon
symbol.hpp
1 #pragma once
2 #include "common/arc.hpp"
3 #include "common/common.hpp"
4 #include "common/junction.hpp"
5 #include "common/layer_provider.hpp"
6 #include "common/line.hpp"
7 #include "common/object_provider.hpp"
8 #include "common/polygon.hpp"
9 #include "common/text.hpp"
10 #include "nlohmann/json_fwd.hpp"
11 #include "unit.hpp"
12 #include "util/uuid.hpp"
13 #include "util/uuid_provider.hpp"
14 #include <fstream>
15 #include <map>
16 #include <set>
17 #include <vector>
18 
19 namespace horizon {
20 using json = nlohmann::json;
21 
22 class SymbolPin : public UUIDProvider {
23 public:
24  enum class ConnectorStyle { BOX, NONE, NC };
25 
26  SymbolPin(const UUID &uu, const json &j);
27  SymbolPin(UUID uu);
28 
29  UUID uuid;
30  Coord<int64_t> position;
31  uint64_t length = 2.5_mm;
32  bool name_visible = true;
33  bool pad_visible = true;
34 
35  enum class NameOrientation { IN_LINE, PERPENDICULAR, HORIZONTAL };
36  NameOrientation name_orientation = NameOrientation::IN_LINE;
37 
38  Orientation orientation = Orientation::RIGHT;
39  Orientation get_orientation_for_placement(const Placement &p) const;
40 
41  class Decoration {
42  public:
43  Decoration();
44  Decoration(const json &j);
45  bool dot = false;
46  bool clock = false;
47  bool schmitt = false;
48  enum class Driver {
49  DEFAULT,
50  OPEN_COLLECTOR,
51  OPEN_COLLECTOR_PULLUP,
52  OPEN_EMITTER,
53  OPEN_EMITTER_PULLDOWN,
54  TRISTATE
55  };
56  Driver driver = Driver::DEFAULT;
57 
58  json serialize() const;
59  };
60  Decoration decoration;
61 
62  // not stored
63  std::string name;
64  std::string pad;
65  ConnectorStyle connector_style = ConnectorStyle::BOX;
66  std::map<UUID, class LineNet *> connected_net_lines;
67  UUID net_segment;
68  Pin::Direction direction = Pin::Direction::BIDIRECTIONAL;
69 
70  json serialize() const;
71  virtual UUID get_uuid() const;
72 };
73 
74 class Symbol : public ObjectProvider, public LayerProvider {
75 public:
76  Symbol(const UUID &uu, const json &j, class Pool &pool);
77  Symbol(const UUID &uu);
78  static Symbol new_from_file(const std::string &filename, Pool &pool);
79  std::pair<Coordi, Coordi> get_bbox(bool all = false) const;
80  virtual Junction *get_junction(const UUID &uu);
81  virtual SymbolPin *get_symbol_pin(const UUID &uu);
82 
83  json serialize() const;
84 
88  enum class PinDisplayMode { PRIMARY, ALT, BOTH };
89  void expand(PinDisplayMode mode = PinDisplayMode::PRIMARY);
90  Symbol(const Symbol &sym);
91  void operator=(Symbol const &sym);
92 
93  UUID uuid;
95  std::string name;
96  std::map<UUID, SymbolPin> pins;
97  std::map<UUID, Junction> junctions;
98  std::map<UUID, Line> lines;
99  std::map<UUID, Arc> arcs;
100  std::map<UUID, Text> texts;
101  std::map<UUID, Polygon> polygons;
102  bool can_expand = false;
103 
104  std::map<std::tuple<int, bool, UUID>, Placement> text_placements;
105  void apply_placement(const Placement &p);
106 
107 private:
108  void update_refs();
109 };
110 } // namespace horizon
horizon::uuid_ptr
Definition: uuid_ptr.hpp:9
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::SymbolPin::Decoration
Definition: symbol.hpp:41
libzip::uint64_t
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
horizon::LayerProvider
Definition: layer_provider.hpp:7
horizon::Coord< int64_t >
horizon::Symbol
Definition: symbol.hpp:74
horizon::SymbolPin
Definition: symbol.hpp:22
horizon::Junction
A Junction is a point in 2D-Space.
Definition: junction.hpp:25
horizon::Symbol::PinDisplayMode
PinDisplayMode
fills in information from the referenced unit
Definition: symbol.hpp:88
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::UUIDProvider
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
horizon::Placement
Definition: placement.hpp:8
horizon::ObjectProvider
Interface for classes that store objects identified by UUID (e.g. Line or Junction)
Definition: object_provider.hpp:10