Horizon
block.hpp
1 #pragma once
2 #include "bus.hpp"
3 #include "component.hpp"
4 #include "nlohmann/json_fwd.hpp"
5 #include "net.hpp"
6 #include "net_class.hpp"
7 #include "util/uuid.hpp"
8 #include "bom_export_settings.hpp"
9 #include <fstream>
10 #include <map>
11 #include <set>
12 #include <vector>
13 
14 namespace horizon {
15 using json = nlohmann::json;
16 
25 class Block {
26 public:
27  Block(const UUID &uu, const json &, class IPool &pool);
28  Block(const UUID &uu);
29  static Block new_from_file(const std::string &filename, IPool &pool);
30  static std::map<std::string, std::string> peek_project_meta(const std::string &filename);
31  Net *get_net(const UUID &uu);
32  UUID uuid;
33  std::string name;
34  std::map<UUID, Net> nets;
35  std::map<UUID, Bus> buses;
36  std::map<UUID, Component> components;
37  std::map<UUID, NetClass> net_classes;
38  uuid_ptr<NetClass> net_class_default = nullptr;
39 
40  std::map<UUID, std::string> group_names;
41  std::map<UUID, std::string> tag_names;
42  std::map<std::string, std::string> project_meta;
43  std::string get_group_name(const UUID &uu) const;
44  std::string get_tag_name(const UUID &uu) const;
45 
46  BOMExportSettings bom_export_settings;
47  std::map<const class Part *, BOMRow> get_BOM(const BOMExportSettings &settings) const;
48 
49  bool can_swap_gates(const UUID &comp, const UUID &g1, const UUID &g2) const;
50  void swap_gates(const UUID &comp, const UUID &g1, const UUID &g2);
51 
52  Block(const Block &block);
53  void operator=(const Block &block);
54 
55  void merge_nets(Net *net, Net *into);
56 
60  void vacuum_nets();
61  void vacuum_group_tag_names();
62 
68  Net *extract_pins(const std::set<UUIDPath<3>> &pins, Net *net = nullptr);
69 
70  void update_connection_count();
71 
72  void update_diffpairs();
73 
78  Net *insert_net();
79 
80  std::string get_net_name(const UUID &uu) const;
81 
82  json serialize();
83 
84 private:
85  void update_refs();
86 };
87 } // namespace horizon
horizon::uuid_ptr
Definition: uuid_ptr.hpp:8
horizon::Block::vacuum_nets
void vacuum_nets()
deletes unreferenced nets
Definition: block.cpp:170
horizon::Net
Definition: net.hpp:15
horizon::Block
A block is one level of hierarchy in the netlist.
Definition: block.hpp:25
horizon::IPool
Definition: ipool.hpp:12
horizon::UUIDPath
Stores a sequence of up to 3 UUIDs.
Definition: uuid_path.hpp:13
horizon::Block::extract_pins
Net * extract_pins(const std::set< UUIDPath< 3 >> &pins, Net *net=nullptr)
Takes pins specified by pins and moves them over to net.
Definition: block.cpp:283
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:166
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::Block::insert_net
Net * insert_net()
creates new net
Definition: block.cpp:131
horizon::BOMExportSettings
Definition: bom_export_settings.hpp:11