TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
overrides.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// The user override file (design doc 15 §3.5 level 1, §6.3): the user disables rules, forces or forbids a
4// category on a part, or changes a rule parameter. The engine reads JSON (it has no YAML parser, like the
5// catalogue); the YAML form of doc 15 §6.3 maps 1:1 to it and scripts/crules_override.py converts it.
6//
7// {
8// "version": 1,
9// "disable": ["USB2-04@J2", "XTAL-04", "mounting_hole", "crystal@Y2"],
10// "assert": {"J5": "usb2"}, // or [{"category": "usb2", "ref": "J5"}]
11// "deny": {"U7": "buck"}, // or [{"category": "buck", "ref": "U7"}]
12// "set": [{"rule": "XTAL-02", "param": "max_mm", "value": 5},
13// {"rule": "XTAL-01@Y1", "param": "max_mm", "value": 8}]
14// }
15//
16// Everything is validated against the catalogue when the file is read: unknown keys, rule ids, categories,
17// parameters and value types are errors, never ignored (a typo must not silently drop an override). References
18// are validated against the board by check_override_refs (detect() calls it).
19#include <cstdint>
20#include <string>
21#include <string_view>
22#include <vector>
23
24#include <nlohmann/json.hpp>
25
26#include "crules/catalogue.hpp"
27#include "model/board.hpp"
28
29namespace tmk::crules {
30
32 enum class Kind : std::uint8_t { Disable, Assert, Deny, Set };
34 std::string rule; // Disable (one rule) and Set: the rule id
35 std::string category; // the category id (for rule entries: the rule's category)
36 std::string ref; // anchor reference; empty = every instance (Disable, Set)
37 std::string param; // Set: parameter name
38 nlohmann::ordered_json value; // Set: new value
39 std::string text; // the entry as the report shows it, e.g. "disable XTAL-04@Y1"
40};
41
42struct Overrides {
43 std::string source; // file name (messages and report)
44 std::vector<OverrideEntry> entries; // file order: disable, assert, deny, set
45 bool empty() const { return entries.empty(); }
46};
47
48// Parses and validates an override file. Throws std::runtime_error with a message that names the source and the
49// offending entry.
50Overrides parse_overrides(std::string_view json_text, const Catalogue& cat, const std::string& source = "rules override");
51// Reads a JSON file; a .yaml/.yml file is refused with the conversion command.
52Overrides load_overrides_file(const std::string& path, const Catalogue& cat);
53// Every reference must name a footprint of the board (throws otherwise, listing the unknown ones).
54void check_override_refs(const Overrides& ov, const model::Board& b);
55
56} // namespace tmk::crules
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
Component-rule catalogue (design doc 15 §6.1): categories of components with their detectors,...
Overrides parse_overrides(std::string_view json_text, const Catalogue &cat, const std::string &source="rules override")
Parses and validates an override file.
Overrides load_overrides_file(const std::string &path, const Catalogue &cat)
Reads a JSON file; a .yaml/.yml file is refused with the conversion command.
void check_override_refs(const Overrides &ov, const model::Board &b)
Every reference must name a footprint of the board (throws otherwise, listing the unknown ones).
std::string text
the entry as the report shows it, e.g. "disable XTAL-04\@Y1"
Definition overrides.hpp:39
nlohmann::ordered_json value
Set: new value.
Definition overrides.hpp:38
std::string param
Set: parameter name.
Definition overrides.hpp:37
std::string category
the category id (for rule entries: the rule's category)
Definition overrides.hpp:35
std::string ref
anchor reference; empty = every instance (Disable, Set)
Definition overrides.hpp:36
std::string rule
Disable (one rule) and Set: the rule id.
Definition overrides.hpp:34
std::vector< OverrideEntry > entries
file order: disable, assert, deny, set
Definition overrides.hpp:44
std::string source
file name (messages and report)
Definition overrides.hpp:43