1 #include "net.hpp"
2 #include "block.hpp"
3 #include "common/lut.hpp"
4 #include "nlohmann/json.hpp"
5
6
7 namespace horizon {
8
9 static const LutEnumStr<Net::PowerSymbolStyle> power_symbol_style_lut = {
10 {"gnd", Net::PowerSymbolStyle::GND},
11 {"earth", Net::PowerSymbolStyle::EARTH},
12 {"dot", Net::PowerSymbolStyle::DOT},
13 {"antenna", Net::PowerSymbolStyle::ANTENNA},
14 };
15
Net(const UUID & uu,const json & j,Block & block)16 Net::Net(const UUID &uu, const json &j, Block &block) : Net(uu, j)
17 {
18 net_class = &block.net_classes.at(j.at("net_class").get<std::string>());
19 }
Net(const UUID & uu,const json & j)20 Net::Net(const UUID &uu, const json &j)
21 : uuid(uu), name(j.at("name").get<std::string>()), is_power(j.value("is_power", false)),
22 power_symbol_name_visible(j.value("power_symbol_name_visible", true))
23 {
24 net_class.uuid = j.at("net_class").get<std::string>();
25 if (j.count("diffpair")) {
26 UUID diffpair_uuid(j.at("diffpair").get<std::string>());
27 if (diffpair_uuid) {
28 diffpair.uuid = diffpair_uuid;
29 diffpair_master = true;
30 }
31 }
32 if (j.count("power_symbol_style"))
33 power_symbol_style = power_symbol_style_lut.lookup(j.at("power_symbol_style"));
34 }
35
Net(const UUID & uu)36 Net::Net(const UUID &uu) : uuid(uu){};
37
get_uuid() const38 UUID Net::get_uuid() const
39 {
40 return uuid;
41 }
42
serialize() const43 json Net::serialize() const
44 {
45 json j;
46 j["name"] = name;
47 j["is_power"] = is_power;
48 j["net_class"] = net_class->uuid;
49 j["power_symbol_name_visible"] = power_symbol_name_visible;
50 j["power_symbol_style"] = power_symbol_style_lut.lookup_reverse(power_symbol_style);
51 if (diffpair_master)
52 j["diffpair"] = diffpair->uuid;
53 return j;
54 }
55
is_named() const56 bool Net::is_named() const
57 {
58 return name.size() > 0;
59 }
60 } // namespace horizon
61