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