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 "symbol/symbol_rules.hpp"
14 #include "util/file_version.hpp"
15 #include "common/pin_name_orientation.hpp"
16 
17 namespace horizon {
18 using json = nlohmann::json;
19 
20 class SymbolPin {
21 public:
22  enum class ConnectorStyle { BOX, NONE, NC };
23 
24  SymbolPin(const UUID &uu, const json &j);
25  SymbolPin(UUID uu);
26 
27  UUID uuid;
28  Coord<int64_t> position;
29  uint64_t length = 2.5_mm;
30  bool name_visible = true;
31  bool pad_visible = true;
32 
33  using NameOrientation = PinNameOrientation;
34  NameOrientation name_orientation = NameOrientation::IN_LINE;
35 
36  Orientation orientation = Orientation::RIGHT;
37  Orientation get_orientation_for_placement(const Placement &p) const;
38 
39  class Decoration {
40  public:
41  Decoration();
42  Decoration(const json &j);
43  bool dot = false;
44  bool clock = false;
45  bool schmitt = false;
46  enum class Driver {
47  DEFAULT,
48  OPEN_COLLECTOR,
49  OPEN_COLLECTOR_PULLUP,
50  OPEN_EMITTER,
51  OPEN_EMITTER_PULLDOWN,
52  TRISTATE
53  };
54  Driver driver = Driver::DEFAULT;
55 
56  json serialize() const;
57  };
58  Decoration decoration;
59 
60  // not stored
61  std::string name;
62  std::string pad;
63  ConnectorStyle connector_style = ConnectorStyle::BOX;
64  unsigned int connection_count = 0;
65  UUID net_segment;
66  Pin::Direction direction = Pin::Direction::BIDIRECTIONAL;
67 
68  json serialize() const;
69  UUID get_uuid() const;
70 };
71 
72 class Symbol : public ObjectProvider, public LayerProvider {
73 public:
74  Symbol(const UUID &uu, const json &j, class IPool &pool);
75  Symbol(const UUID &uu);
76  static Symbol new_from_file(const std::string &filename, IPool &pool);
77  static unsigned int get_app_version();
78  std::pair<Coordi, Coordi> get_bbox(bool all = false) const;
79  virtual Junction *get_junction(const UUID &uu) override;
80 
81  json serialize() const;
82 
86  enum class PinDisplayMode { PRIMARY, ALT, BOTH };
87  void expand(PinDisplayMode mode = PinDisplayMode::PRIMARY);
88  Symbol(const Symbol &sym);
89  void operator=(Symbol const &sym);
90 
91  void apply_expand(const Symbol &ref, unsigned int ex);
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  SymbolRules rules;
108  FileVersion version;
109 
110  unsigned int get_required_version() const;
111 
112 private:
113  void update_refs();
114 };
115 } // namespace horizon
Definition: file_version.hpp:9
Definition: ipool.hpp:14
A Junction is a point in 2D-Space.
Definition: junction.hpp:20
Definition: layer_provider.hpp:7
Interface for classes that store objects identified by UUID (e.g. Line or Junction)
Definition: object_provider.hpp:10
Definition: placement.hpp:8
Definition: symbol.hpp:39
Definition: symbol.hpp:20
Definition: symbol_rules.hpp:10
Definition: symbol.hpp:72
PinDisplayMode
fills in information from the referenced unit
Definition: symbol.hpp:86
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: uuid_ptr.hpp:8
a class to store JSON values
Definition: json.hpp:177
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62