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