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