1 #include "rule_track_width.hpp"
2 #include "util/util.hpp"
3 #include <sstream>
4 #include "nlohmann/json.hpp"
5 
6 namespace horizon {
Widths()7 RuleTrackWidth::Widths::Widths()
8 {
9 }
Widths(const json & j)10 RuleTrackWidth::Widths::Widths(const json &j) : min(j.at("min")), max(j.at("max")), def(j.at("def"))
11 {
12 }
serialize() const13 json RuleTrackWidth::Widths::serialize() const
14 {
15     json j;
16     j["min"] = min;
17     j["max"] = max;
18     j["def"] = def;
19     return j;
20 }
21 
RuleTrackWidth(const UUID & uu)22 RuleTrackWidth::RuleTrackWidth(const UUID &uu) : Rule(uu)
23 {
24     id = RuleID::TRACK_WIDTH;
25 }
26 
RuleTrackWidth(const UUID & uu,const json & j,const RuleImportMap & import_map)27 RuleTrackWidth::RuleTrackWidth(const UUID &uu, const json &j, const RuleImportMap &import_map)
28     : Rule(uu, j, import_map), match(j.at("match"), import_map)
29 {
30     id = RuleID::TRACK_WIDTH;
31     {
32         const json &o = j["widths"];
33         for (auto it = o.cbegin(); it != o.cend(); ++it) {
34             int layer = std::stoi(it.key());
35             widths.emplace(std::piecewise_construct, std::forward_as_tuple(layer), std::forward_as_tuple(it.value()));
36         }
37     }
38 }
39 
serialize() const40 json RuleTrackWidth::serialize() const
41 {
42     json j = Rule::serialize();
43     j["match"] = match.serialize();
44     j["widths"] = json::object();
45     for (const auto &it : widths) {
46         j["widths"][std::to_string(it.first)] = it.second.serialize();
47     }
48     // j["diameter_min"] = diameter_min;
49     // j["diameter_max"] = diameter_max;
50     return j;
51 }
52 
get_brief(const class Block * block) const53 std::string RuleTrackWidth::get_brief(const class Block *block) const
54 {
55     return "Match " + match.get_brief(block);
56 }
57 
is_match_all() const58 bool RuleTrackWidth::is_match_all() const
59 {
60     return match.mode == RuleMatch::Mode::ALL;
61 }
62 
can_export() const63 bool RuleTrackWidth::can_export() const
64 {
65     return match.can_export();
66 }
67 
68 } // namespace horizon
69