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 
16 namespace horizon {
17 using json = nlohmann::json;
18 
19 class SymbolPin {
20 public:
21  enum class ConnectorStyle { BOX, NONE, NC };
22 
23  SymbolPin(const UUID &uu, const json &j);
24  SymbolPin(UUID uu);
25 
26  UUID uuid;
27  Coord<int64_t> position;
28  uint64_t length = 2.5_mm;
29  bool name_visible = true;
30  bool pad_visible = true;
31 
32  enum class NameOrientation { IN_LINE, PERPENDICULAR, HORIZONTAL };
33  NameOrientation name_orientation = NameOrientation::IN_LINE;
34 
35  Orientation orientation = Orientation::RIGHT;
36  Orientation get_orientation_for_placement(const Placement &p) const;
37 
38  class Decoration {
39  public:
40  Decoration();
41  Decoration(const json &j);
42  bool dot = false;
43  bool clock = false;
44  bool schmitt = false;
45  enum class Driver {
46  DEFAULT,
47  OPEN_COLLECTOR,
48  OPEN_COLLECTOR_PULLUP,
49  OPEN_EMITTER,
50  OPEN_EMITTER_PULLDOWN,
51  TRISTATE
52  };
53  Driver driver = Driver::DEFAULT;
54 
55  json serialize() const;
56  };
57  Decoration decoration;
58 
59  // not stored
60  std::string name;
61  std::string pad;
62  ConnectorStyle connector_style = ConnectorStyle::BOX;
63  std::map<UUID, class LineNet *> connected_net_lines;
64  UUID net_segment;
65  Pin::Direction direction = Pin::Direction::BIDIRECTIONAL;
66 
67  json serialize() const;
68  UUID get_uuid() const;
69 };
70 
71 class Symbol : public ObjectProvider, public LayerProvider {
72 public:
73  Symbol(const UUID &uu, const json &j, class IPool &pool);
74  Symbol(const UUID &uu);
75  static Symbol new_from_file(const std::string &filename, IPool &pool);
76  static unsigned int get_app_version();
77  std::pair<Coordi, Coordi> get_bbox(bool all = false) const;
78  virtual Junction *get_junction(const UUID &uu) override;
79 
80  json serialize() const;
81 
85  enum class PinDisplayMode { PRIMARY, ALT, BOTH };
86  void expand(PinDisplayMode mode = PinDisplayMode::PRIMARY);
87  Symbol(const Symbol &sym);
88  void operator=(Symbol const &sym);
89 
90  void apply_expand(const Symbol &ref, unsigned int ex);
91 
92  UUID uuid;
94  std::string name;
95  std::map<UUID, SymbolPin> pins;
96  std::map<UUID, Junction> junctions;
97  std::map<UUID, Line> lines;
98  std::map<UUID, Arc> arcs;
99  std::map<UUID, Text> texts;
100  std::map<UUID, Polygon> polygons;
101  bool can_expand = false;
102 
103  std::map<std::tuple<int, bool, UUID>, Placement> text_placements;
104  void apply_placement(const Placement &p);
105 
106  SymbolRules rules;
107  FileVersion version;
108 
109 private:
110  void update_refs();
111 };
112 } // namespace horizon
Definition: file_version.hpp:8
Definition: ipool.hpp:12
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:38
Definition: symbol.hpp:19
Definition: symbol_rules.hpp:10
Definition: symbol.hpp:71
PinDisplayMode
fills in information from the referenced unit
Definition: symbol.hpp:85
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:166
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61