Horizon
Loading...
Searching...
No Matches
imp.hpp
1#pragma once
2#include "core/core.hpp"
3#include "imp_interface.hpp"
4#include "keyseq_dialog.hpp"
5#include "main_window.hpp"
6#include "pool/pool.hpp"
7#include "preferences/preferences.hpp"
8#include "selection_filter_dialog.hpp"
9#include "util/window_state_store.hpp"
10#include "widgets/spin_button_dim.hpp"
11#include "widgets/warnings_box.hpp"
12#include "action.hpp"
13#include "nlohmann/json.hpp"
14#include "search/searcher.hpp"
15#include <zmq.hpp>
16#include "util/item_set.hpp"
17#include "canvas/canvas_gl.hpp"
18#include "grid_controller.hpp"
19#include "util/action_label.hpp"
20#include <optional>
21#include "core/clipboard/clipboard.hpp"
22#include "clipboard_handler.hpp"
23#include "util/win32_undef.hpp"
24#include "logger/log_dispatcher.hpp"
25
26namespace horizon {
27
28class PoolParams {
29public:
30 PoolParams(const std::string &bp) : base_path(bp)
31 {
32 }
33 std::string base_path;
34};
35
36class ImpBase {
37 friend class ImpInterface;
38
39public:
40 ImpBase(const PoolParams &params);
41 void run(int argc, char *argv[]);
42 virtual void handle_tool_change(ToolID id);
43 virtual void construct() = 0;
44 void canvas_update_from_pp();
45 virtual ~ImpBase()
46 {
47 }
48 void set_read_only(bool v);
49 void set_suggested_filename(const std::string &s);
50 enum class TempMode { YES, NO };
51
52 class SelectionFilterInfo {
53 public:
54 enum class Flag {
55 DEFAULT,
56 HAS_OTHERS,
57 WORK_LAYER_ONLY_ENABLED,
58 };
59 SelectionFilterInfo()
60 {
61 }
62 SelectionFilterInfo(const std::vector<int> &l, Flag fl) : layers(l), flags(fl)
63 {
64 }
65 std::vector<int> layers;
66 Flag flags = Flag::DEFAULT;
67 };
68
69 virtual std::map<ObjectType, SelectionFilterInfo> get_selection_filter_info() const;
70 virtual bool is_layered() const
71 {
72 return false;
73 };
74 LayerProvider &get_layer_provider() const;
75
76protected:
77 MainWindow *main_window;
78 CanvasGL *canvas;
79 class PropertyPanels *panels;
80 WarningsBox *warnings_box;
81 class ToolPopover *tool_popover;
82 Gtk::Menu *context_menu = nullptr;
83 std::unique_ptr<SelectionFilterDialog> selection_filter_dialog;
84 std::optional<GridController> grid_controller;
85 class GridsWindow *grids_window = nullptr;
86
87 std::unique_ptr<Pool> pool;
88
89private:
90 std::unique_ptr<Pool> real_pool_caching;
91
92protected:
93 Pool *pool_caching;
94 class Core *core = nullptr;
95 std::unique_ptr<ClipboardBase> clipboard = nullptr;
96 std::unique_ptr<ClipboardHandler> clipboard_handler = nullptr;
97 std::unique_ptr<KeySequenceDialog> key_sequence_dialog = nullptr;
98 std::unique_ptr<ImpInterface> imp_interface = nullptr;
99 Glib::RefPtr<Glib::Binding> grid_spacing_binding;
100
101 std::map<ActionToolID, ActionConnection> action_connections;
102
103 ActionConnection &connect_action(ToolID tool_id);
104 ActionConnection &connect_action(ActionToolID id, std::function<void(const ActionConnection &)> cb);
105 ActionConnection &connect_action_with_source(ActionToolID id,
106 std::function<void(const ActionConnection &, ActionSource)> cb);
107
108 class RulesWindow *rules_window = nullptr;
109
110 zmq::context_t zctx;
111 zmq::socket_t sock_broadcast_rx;
112 zmq::socket_t sock_project;
113 bool sockets_connected = false;
114 int mgr_pid = -1;
115 UUID ipc_cookie;
116 bool no_update = false;
117 bool distraction_free = false;
118
119 virtual void canvas_update() = 0;
120 virtual void expand_selection_for_property_panel(std::set<SelectableRef> &sel_extra,
121 const std::set<SelectableRef> &sel);
122 void handle_selection_changed(void);
123 virtual void handle_selection_cross_probe()
124 {
125 }
126 bool handle_key_press(const GdkEventKey *key_event);
127 void handle_cursor_move(const Coordi &pos);
128 bool handle_click(const GdkEventButton *button_event);
129 virtual void handle_extra_button(const GdkEventButton *button_event)
130 {
131 }
132 bool handle_click_release(const GdkEventButton *button_event);
133 bool handle_context_menu(const GdkEventButton *button_event);
134 void tool_process(ToolResponse &resp);
135 void tool_begin(ToolID id, bool override_selection = false, const std::set<SelectableRef> &sel = {},
136 std::unique_ptr<ToolData> data = nullptr);
137 void add_tool_button(ToolID id, const std::string &label, bool left = true);
138 void handle_warning_selected(const Coordi &pos);
139 virtual bool handle_broadcast(const json &j);
140 bool handle_close(const GdkEventAny *ev);
141 json send_json(const json &j);
142
143 bool trigger_action(ActionToolID action, ActionSource source = ActionSource::UNKNOWN);
144
145 void connect_go_to_project_manager_action();
146
147 void add_tool_action(ActionToolID id, const std::string &action);
148 void add_hamburger_menu();
149
150 Preferences preferences;
151
152 virtual const CanvasPreferences &get_canvas_preferences()
153 {
154 return preferences.canvas_non_layer;
155 }
156 virtual void apply_preferences();
157
158 std::unique_ptr<WindowStateStore> state_store = nullptr;
159
160 virtual void handle_maybe_drag(bool ctrl);
161
162 virtual ActionCatalogItem::Availability get_editor_type_for_action() const = 0;
163 ObjectType get_editor_type() const;
164
165 void layer_up_down(bool up);
166 void goto_layer(int layer);
167
168 Gtk::Button *create_action_button(ActionToolID action);
169 void attach_action_button(Gtk::Button &button, ActionToolID action);
170
171 void set_action_sensitive(ActionID, bool v);
172 bool get_action_sensitive(ActionID) const;
173 virtual void update_action_sensitivity();
174
175 typedef sigc::signal<void> type_signal_action_sensitive;
176 type_signal_action_sensitive signal_action_sensitive()
177 {
178 return s_signal_action_sensitive;
179 }
180
181 virtual std::string get_hud_text(std::set<SelectableRef> &sel);
182 std::string get_hud_text_for_component(const Component *comp);
183 virtual const Block &get_block_for_group_tag_names();
184 std::string get_hud_text_for_net(const Net *net);
185 std::string get_hud_text_for_layers(const std::set<int> &layers);
186
187 void set_monitor_files(const std::set<std::string> &files);
188 void set_monitor_items(const ItemSet &items);
189 virtual void update_monitor()
190 {
191 }
192 void edit_pool_item(ObjectType type, const UUID &uu);
193
194 void parameter_window_add_polygon_expand(class ParameterWindow *parameter_window);
195
196 bool read_only = false;
197
198 void tool_update_data(std::unique_ptr<ToolData> data);
199
200 virtual void search_center(const Searcher::SearchResult &res);
201 virtual ActionToolID get_doubleclick_action(ObjectType type, const UUID &uu);
202
203 Glib::RefPtr<Gio::Menu> hamburger_menu;
204
205 json m_meta;
206 void load_meta();
207 static const std::string meta_suffix;
208
209 virtual void get_save_meta(json &j)
210 {
211 }
212
213 virtual void set_window_title(const std::string &s);
214 void set_window_title_from_block();
215
216 void update_view_hints();
217 virtual std::vector<std::string> get_view_hints();
218
219 Gtk::Box *view_options_menu = nullptr;
220 void view_options_menu_append_action(const std::string &label, const std::string &action);
221
222 virtual Searcher *get_searcher_ptr()
223 {
224 return nullptr;
225 }
226
227 bool has_searcher()
228 {
229 return get_searcher_ptr();
230 }
231
232 Searcher &get_searcher()
233 {
234 auto s = get_searcher_ptr();
235 if (!s)
236 throw std::runtime_error("not implemented");
237 return *s;
238 }
239
240 class ActionButton &add_action_button(ActionToolID action);
241 class ActionButtonMenu &add_action_button_menu(const char *icon_name);
242 class ActionButton &add_action_button_polygon();
243 class ActionButton &add_action_button_line();
244
245 virtual ToolID get_tool_for_drag_move(bool ctrl, const std::set<SelectableRef> &sel) const;
246 bool force_end_tool();
247 void reset_tool_hint_label();
248
249 std::set<ObjectRef> highlights;
250
251 virtual void update_highlights()
252 {
253 }
254 virtual void clear_highlights();
255
256 enum class ShowInPoolManagerPool { CURRENT, LAST };
257 void show_in_pool_manager(ObjectType type, const UUID &uu, ShowInPoolManagerPool p);
258
259 virtual bool uses_dynamic_version() const
260 {
261 return false;
262 }
263
264 virtual unsigned int get_required_version() const
265 {
266 throw std::runtime_error("not implemented");
267 }
268
269 bool temp_mode = false;
270 std::string suggested_filename;
271
272 void selection_load(const HistoryManager::HistoryItem &it);
273 bool selection_loading = false;
274
275 static void selection_push(HistoryManager &mgr, const std::set<SelectableRef> &selection);
276
277private:
278 void fix_cursor_pos();
279 Glib::RefPtr<Gio::FileMonitor> preferences_monitor;
280 void handle_drag();
281 void update_selection_label();
282 std::string get_tool_settings_filename(ToolID id);
283
284 void hud_update();
285
286 std::map<std::string, Glib::RefPtr<Gio::FileMonitor>> file_monitors;
287 sigc::connection file_monitor_delay_connection;
288
289 void handle_file_changed(const Glib::RefPtr<Gio::File> &file1, const Glib::RefPtr<Gio::File> &file2,
290 Gio::FileMonitorEvent ev);
291
292 void create_context_menu(Gtk::Menu *parent, const std::set<SelectableRef> &sel);
293 Gtk::MenuItem *create_context_menu_item(ActionToolID act);
294
295 KeySequence keys_current;
296 KeyMatchResult keys_match(const KeySequence &keys) const;
297 bool handle_action_key(const GdkEventKey *ev);
298 void handle_tool_action(const ActionConnection &conn);
299 void handle_select_polygon(const ActionConnection &a);
300
301 void handle_search();
302 void search_go(int dir);
303 std::list<Searcher::SearchResult> search_results;
304 unsigned int search_result_current = 0;
305 void update_search_markers();
306 void update_search_types_label();
307 void set_search_mode(bool enabled, bool focus = true);
308 std::map<Searcher::Type, Gtk::CheckButton *> search_check_buttons;
309
310 LogDispatcher log_dispatcher;
311 class LogWindow *log_window = nullptr;
312 std::set<SelectableRef> selection_for_drag_move;
313 ToolID drag_tool;
314 Coordf cursor_pos_drag_begin;
315 Coordi cursor_pos_grid_drag_begin;
316
317 std::map<ActionID, bool> action_sensitivity;
318 type_signal_action_sensitive s_signal_action_sensitive;
319
320 bool property_panel_has_focus();
321
322 sigc::connection initial_view_all_conn;
323
324 bool sockets_broken = false;
325 void show_sockets_broken_dialog(const std::string &msg = "");
326 bool needs_autosave = false;
327 bool queue_autosave = false;
328
329 void update_property_panels();
330 std::map<CanvasGL::SelectionTool, CanvasGL::SelectionQualifier> selection_qualifiers;
331 std::list<class ActionButtonBase *> action_buttons;
332
333 Glib::RefPtr<Gio::SimpleAction> bottom_view_action;
334 Glib::RefPtr<Gio::SimpleAction> distraction_free_action;
335 Glib::RefPtr<Gio::SimpleAction> show_pictures_action;
336
337 int left_panel_width = 0;
338
339 void tool_bar_set_actions(const std::vector<ActionLabelInfo> &labels);
340 void tool_bar_append_action(InToolActionID action1, InToolActionID action2, const std::string &s);
341 void tool_bar_clear_actions();
342 InToolKeySequencesPreferences in_tool_key_sequeces_preferences;
343 std::vector<ActionLabelInfo> in_tool_action_label_infos;
344
345 void tool_process_one();
346
347 void show_preferences(std::optional<std::string> page = std::nullopt);
348
349 void init_search();
350 void init_key();
351 void init_action();
352
353 void handle_pan_action(const ActionConnection &c);
354 void handle_zoom_action(const ActionConnection &c);
355
356 std::string get_complete_display_name(const SelectableRef &sr);
357
358 void set_flip_view(bool flip);
359 void apply_arrow_keys();
360 void check_version();
361
362 void update_cursor(ToolID tool_id);
363
364 std::set<SelectableRef> last_canvas_selection;
365
366 Gtk::Button *undo_button = nullptr;
367 Gtk::Button *redo_button = nullptr;
368
369 void selection_undo();
370 void selection_redo();
371
372 HistoryManager selection_history_manager;
373 virtual HistoryManager &get_selection_history_manager();
374
375 unsigned int saved_version = 0;
376
377 class MSDTuningWindow *msd_tuning_window = nullptr;
378
379 Gtk::Button *save_button = nullptr;
380 virtual bool set_filename();
381};
382} // namespace horizon
Definition action.hpp:87
Definition canvas_gl.hpp:20
Where Tools and and documents meet.
Definition core.hpp:42
Definition grids_window.hpp:14
Definition layer_provider.hpp:8
Definition main_window.hpp:7
Definition imp.hpp:28
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition pool.hpp:18
Definition property_panels.hpp:8
Definition rules_window.hpp:13
Definition tool_popover.hpp:8
This class encapsulates a UUID and allows it to be uses as a value type.
Definition uuid.hpp:16
Definition warnings_box.hpp:7
basic_json<> json
default JSON class
Definition json_fwd.hpp:62
Definition action.hpp:13