Horizon
rule.hpp
1 #pragma once
2 #include "nlohmann/json_fwd.hpp"
3 #include "rule_match.hpp"
4 #include "util/uuid.hpp"
5 #include "common/lut.hpp"
6 
7 namespace horizon {
8 using json = nlohmann::json;
9 
10 enum class RuleID {
11  NONE,
12  HOLE_SIZE,
13  CLEARANCE_SILKSCREEN_EXPOSED_COPPER,
14  TRACK_WIDTH,
15  CLEARANCE_COPPER,
16  SINGLE_PIN_NET,
17  PARAMETERS,
18  VIA,
19  CLEARANCE_COPPER_OTHER,
20  PLANE,
21  DIFFPAIR,
22  PACKAGE_CHECKS,
23  SHORTED_PADS,
24  PREFLIGHT_CHECKS,
25  CLEARANCE_COPPER_KEEPOUT,
26  LAYER_PAIR,
27  CLEARANCE_SAME_NET,
28  SYMBOL_CHECKS,
29  CLEARANCE_PACKAGE,
30 };
31 
32 extern const LutEnumStr<RuleID> rule_id_lut;
33 
35 public:
36  virtual UUID get_net_class(const UUID &uu) const
37  {
38  return uu;
39  }
40  virtual int get_order(int order) const
41  {
42  return order;
43  }
44  virtual bool is_imported() const
45  {
46  return false;
47  }
48 
49  virtual ~RuleImportMap()
50  {
51  }
52 };
53 
54 class Rule {
55  friend class Rules;
56 
57 public:
58  Rule(const UUID &uu);
59  Rule(const json &j);
60  Rule(const json &j, const RuleImportMap &import_map);
61  Rule(const UUID &uu, const json &j);
62  Rule(const UUID &uu, const json &j, const RuleImportMap &import_map);
63  UUID uuid;
64  virtual RuleID get_id() const = 0;
65  bool enabled = true;
66  bool imported = false;
67  int get_order() const
68  {
69  return order;
70  }
71 
72  virtual json serialize() const;
73  virtual std::string get_brief(const class Block *block = nullptr, class IPool *pool = nullptr) const = 0;
74  virtual bool is_match_all() const
75  {
76  return false;
77  }
78 
79  virtual bool can_export() const
80  {
81  return false;
82  }
83 
84  virtual ~Rule();
85 
86  enum class SerializeMode { SERIALIZE, EXPORT };
87 
88 protected:
89  Rule();
90 
91  static std::string layer_to_string(int layer);
92 
93 private:
94  int order = -1;
95 };
96 } // namespace horizon
A block is one level of hierarchy in the netlist.
Definition: block.hpp:29
Definition: ipool.hpp:14
Definition: rule.hpp:34
Definition: rule.hpp:54
Definition: rules.hpp:51
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62