Horizon
rules.hpp
1 #pragma once
2 #include "clipper/clipper.hpp"
3 #include "common/common.hpp"
4 #include "nlohmann/json_fwd.hpp"
5 #include "rule.hpp"
6 #include "util/uuid.hpp"
7 #include <deque>
8 #include <set>
9 #include <functional>
10 
11 namespace horizon {
12 using json = nlohmann::json;
13 
14 enum class RulesCheckErrorLevel { NOT_RUN, PASS, WARN, FAIL, DISABLED };
15 
16 Color rules_check_error_level_to_color(RulesCheckErrorLevel lev);
17 std::string rules_check_error_level_to_string(RulesCheckErrorLevel lev);
18 
20 public:
21  RulesCheckError(RulesCheckErrorLevel lev);
22 
23  RulesCheckErrorLevel level = RulesCheckErrorLevel::NOT_RUN;
24  UUID sheet;
25  Coordi location;
26  std::string comment;
27  bool has_location = false;
28  ClipperLib::Paths error_polygons;
29 };
30 
32 public:
33  void clear();
34  void update();
35 
36  RulesCheckErrorLevel level = RulesCheckErrorLevel::NOT_RUN;
37  std::string comment;
38 
39  std::deque<RulesCheckError> errors;
40 };
41 
42 typedef std::function<void(const std::string &)> check_status_cb_t;
43 
44 class Rules {
45 public:
46  Rules();
47  virtual void load_from_json(const json &j) = 0;
48  virtual json serialize() const = 0;
49  virtual std::set<RuleID> get_rule_ids() const = 0;
50  virtual Rule *get_rule(RuleID id) = 0;
51  virtual Rule *get_rule(RuleID id, const UUID &uu) = 0;
52  virtual std::map<UUID, Rule *> get_rules(RuleID id) = 0;
53  std::vector<Rule *> get_rules_sorted(RuleID id);
54  virtual void remove_rule(RuleID id, const UUID &uu) = 0;
55  virtual Rule *add_rule(RuleID id) = 0;
56  void move_rule(RuleID id, const UUID &uu, int dir);
57 
58  virtual ~Rules();
59 
60 protected:
61  void fix_order(RuleID id);
62 };
63 } // namespace horizon
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::Rules
Definition: rules.hpp:44
horizon::Rule
Definition: rule.hpp:26
horizon::RulesCheckError
Definition: rules.hpp:19
horizon::Coord< int64_t >
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::RulesCheckResult
Definition: rules.hpp:31