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 };
25 
26  SymbolPin(const UUID &uu, const json &j);
27  SymbolPin(UUID uu);
28 
29  const UUID uuid;
30  Coord<int64_t> position;
31  uint64_t length;
32  bool name_visible;
33  bool pad_visible;
34  Orientation orientation;
35  Orientation get_orientation_for_placement(const Placement &p) const;
36 
37  class Decoration {
38  public:
39  Decoration();
40  Decoration(const json &j);
41  bool dot = false;
42  bool clock = false;
43  bool schmitt = false;
44  enum class Driver {
45  DEFAULT,
46  OPEN_COLLECTOR,
47  OPEN_COLLECTOR_PULLUP,
48  OPEN_EMITTER,
49  OPEN_EMITTER_PULLDOWN,
50  TRISTATE
51  };
52  Driver driver = Driver::DEFAULT;
53 
54  json serialize() const;
55  };
56  Decoration decoration;
57 
58  // not stored
59  std::string name;
60  std::string pad;
61  ConnectorStyle connector_style = ConnectorStyle::BOX;
62  std::map<UUID, class LineNet *> connected_net_lines;
63  UUID net_segment;
64  Pin::Direction direction = Pin::Direction::BIDIRECTIONAL;
65 
66  json serialize() const;
67  virtual UUID get_uuid() const;
68 };
69 
70 class Symbol : public ObjectProvider, public LayerProvider {
71 public:
72  Symbol(const UUID &uu, const json &j, class Pool &pool);
73  Symbol(const UUID &uu);
74  static Symbol new_from_file(const std::string &filename, Pool &pool);
75  std::pair<Coordi, Coordi> get_bbox(bool all = false) const;
76  virtual Junction *get_junction(const UUID &uu);
77  virtual SymbolPin *get_symbol_pin(const UUID &uu);
78 
79  json serialize() const;
80 
84  void expand();
85  Symbol(const Symbol &sym);
86  void operator=(Symbol const &sym);
87 
88  UUID uuid;
90  std::string name;
91  std::map<UUID, SymbolPin> pins;
92  std::map<UUID, Junction> junctions;
93  std::map<UUID, Line> lines;
94  std::map<UUID, Arc> arcs;
95  std::map<UUID, Text> texts;
96  std::map<UUID, Polygon> polygons;
97 
98  std::map<std::tuple<int, bool, UUID>, Placement> text_placements;
99  void apply_placement(const Placement &p);
100 
101 private:
102  void update_refs();
103 };
104 } // 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:37
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:70
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:18
Definition: block.cpp:7
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
A Junction is a point in 2D-Space.
Definition: junction.hpp:25