1 #pragma once
2 #include "canvas/appearance.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include <sigc++/sigc++.h>
5 #include <string>
6 #include "imp/action_catalog.hpp"
7 
8 namespace horizon {
9 using json = nlohmann::json;
10 
11 enum class InToolActionID;
12 
13 class CanvasPreferences {
14 public:
15     Appearance appearance;
16     void load_from_json(const json &j);
17     void load_colors_from_json(const json &j);
18     json serialize() const;
19     json serialize_colors() const;
20 };
21 
22 class SchematicPreferences {
23 public:
24     bool show_all_junctions = false;
25     bool drag_start_net_line = true;
26     bool bend_non_ortho = true;
27 
28     void load_from_json(const json &j);
29     json serialize() const;
30 };
31 
32 class BoardPreferences {
33 public:
34     bool drag_start_track = true;
35     bool highlight_on_top = true;
36     bool show_text_in_tracks = true;
37     bool show_text_in_vias = true;
38     bool move_using_router = true;
39 
40     void load_from_json(const json &j);
41     json serialize() const;
42 };
43 
44 class KeySequencesPreferences {
45 public:
46     std::map<ActionToolID, std::map<ActionCatalogItem::Availability, std::vector<KeySequence>>> keys;
47 
48     void load_from_json(const json &j);
49     void append_from_json(const json &j);
50     json serialize() const;
51 };
52 
53 class InToolKeySequencesPreferences {
54 public:
55     std::map<InToolActionID, std::vector<KeySequence>> keys;
56 
57     void load_from_json(const json &j);
58     void append_from_json(const json &j);
59     json serialize() const;
60 };
61 
62 class ZoomPreferences {
63 public:
64     bool smooth_zoom_2d = true;
65     bool smooth_zoom_3d = false;
66     bool touchpad_pan = false;
67     float zoom_factor = 50;
68     bool keyboard_zoom_to_cursor = false;
69 
70     void load_from_json(const json &j);
71     json serialize() const;
72 };
73 
74 class PartInfoPreferences {
75 public:
76     std::string url = "https://dev-partinfo.kitspace.org/graphql";
77     std::string preferred_distributor;
78     bool ignore_moq_gt_1 = true;
79     unsigned int max_price_breaks = 3;
80     unsigned int cache_days = 5;
81 
82     void load_from_json(const json &j);
83     json serialize() const;
84 };
85 
86 class DigiKeyApiPreferences {
87 public:
88     std::string client_id;
89     std::string client_secret;
90     std::string site = "DE";
91     std::string currency = "EUR";
92     unsigned int max_price_breaks = 3;
93 
94     void load_from_json(const json &j);
95     json serialize() const;
96 };
97 
98 class ActionBarPreferences {
99 public:
100     bool enable = true;
101     bool remember = true;
102     bool show_in_tool = true;
103 
104     void load_from_json(const json &j);
105     json serialize() const;
106 };
107 
108 class MousePreferences {
109 public:
110     bool switch_layers = true;
111     bool switch_sheets = true;
112     bool drag_polygon_edges = true;
113     bool drag_to_move = true;
114 
115     void load_from_json(const json &j);
116     json serialize() const;
117 };
118 
119 class Preferences {
120 public:
121     Preferences();
122     void set_filename(const std::string &filename);
123     void load();
124     void load_default();
125     void load_from_json(const json &j);
126     void save();
127     static std::string get_preferences_filename();
128     json serialize() const;
129 
130     CanvasPreferences canvas_non_layer;
131     CanvasPreferences canvas_layer;
132     SchematicPreferences schematic;
133     BoardPreferences board;
134     KeySequencesPreferences key_sequences;
135     ZoomPreferences zoom;
136     bool capture_output = false;
137 
138     enum class StockInfoProviderSel { NONE, PARTINFO, DIGIKEY };
139     StockInfoProviderSel stock_info_provider = StockInfoProviderSel::NONE;
140 
141     PartInfoPreferences partinfo;
142     DigiKeyApiPreferences digikey_api;
143     ActionBarPreferences action_bar;
144     InToolKeySequencesPreferences in_tool_key_sequences;
145     MousePreferences mouse;
146 
147     bool show_pull_request_tools = false;
148     bool hud_debug = false;
149 
150     typedef sigc::signal<void> type_signal_changed;
signal_changed()151     type_signal_changed signal_changed()
152     {
153         return s_signal_changed;
154     }
155 
156 private:
157     std::string filename;
158     type_signal_changed s_signal_changed;
159 };
160 } // namespace horizon
161