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  void expand();
89  Symbol(const Symbol &sym);
90  void operator=(Symbol const &sym);
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 
102  std::map<std::tuple<int, bool, UUID>, Placement> text_placements;
103  void apply_placement(const Placement &p);
104 
105 private:
106  void update_refs();
107 };
108 } // namespace horizon
Interface for classes that store objects identified by UUID (e.g. Line or Junction) ...
Definition: object_provider.hpp:10
Definition: symbol.hpp:22
a class to store JSON values
Definition: json.hpp:161
Definition: placement.hpp:8
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
Definition: symbol.hpp:41
Definition: uuid_ptr.hpp:9
Definition: layer_provider.hpp:7
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: symbol.hpp:74
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:19
Definition: block.cpp:9
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
A Junction is a point in 2D-Space.
Definition: junction.hpp:25