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  json serialize() const;
31 };
32 
34 public:
35  void clear();
36  void update();
37  json serialize() const;
38 
39  RulesCheckErrorLevel level = RulesCheckErrorLevel::NOT_RUN;
40  std::string comment;
41 
42  std::deque<RulesCheckError> errors;
43 };
44 
45 typedef std::function<void(const std::string &)> check_status_cb_t;
46 
47 class Rules {
48 public:
49  Rules();
50  virtual void load_from_json(const json &j) = 0;
51  virtual json serialize() const = 0;
52  virtual std::set<RuleID> get_rule_ids() const = 0;
53  virtual Rule *get_rule(RuleID id) = 0;
54  virtual Rule *get_rule(RuleID id, const UUID &uu) = 0;
55  virtual std::map<UUID, Rule *> get_rules(RuleID id) = 0;
56  std::vector<Rule *> get_rules_sorted(RuleID id);
57  virtual void remove_rule(RuleID id, const UUID &uu) = 0;
58  virtual Rule *add_rule(RuleID id) = 0;
59  void move_rule(RuleID id, const UUID &uu, int dir);
60 
61  virtual ~Rules();
62 
63 protected:
64  void fix_order(RuleID id);
65 };
66 } // namespace horizon
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::Rules
Definition: rules.hpp:47
horizon::Rule
Definition: rule.hpp:29
horizon::RulesCheckError
Definition: rules.hpp:19
horizon::Coord< int64_t >
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:165
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:33