Horizon
imp.hpp
1 #pragma once
2 #include "core/clipboard.hpp"
3 #include "core/core.hpp"
4 #include "core/cores.hpp"
5 #include "imp_interface.hpp"
6 #include "keyseq_dialog.hpp"
7 #include "main_window.hpp"
8 #include "pool/pool.hpp"
9 #include "preferences/preferences.hpp"
10 #include "selection_filter_dialog.hpp"
11 #include "util/window_state_store.hpp"
12 #include "widgets/spin_button_dim.hpp"
13 #include "widgets/warnings_box.hpp"
14 #include "action.hpp"
15 #include <zmq.hpp>
16 
17 #ifdef G_OS_WIN32
18 #undef DELETE
19 #undef DUPLICATE
20 #undef ERROR
21 #endif
22 
23 namespace horizon {
24 
25 class PoolParams {
26 public:
27  PoolParams(const std::string &bp, const std::string &cp = "") : base_path(bp), cache_path(cp)
28  {
29  }
30  std::string base_path;
31  std::string cache_path;
32 };
33 
34 std::unique_ptr<Pool> make_pool(const PoolParams &params);
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 
50  std::set<ObjectRef> highlights;
51  virtual void update_highlights(){};
52 
54  public:
56  {
57  }
58  SelectionFilterInfo(const std::vector<int> &l, bool o) : layers(l), has_others(o)
59  {
60  }
61  std::vector<int> layers;
62  bool has_others = false;
63  };
64 
65  virtual std::map<ObjectType, SelectionFilterInfo> get_selection_filter_info() const;
66 
67 protected:
68  MainWindow *main_window;
69  class CanvasGL *canvas;
70  class PropertyPanels *panels;
71  WarningsBox *warnings_box;
72  class ToolPopover *tool_popover;
73  Gtk::Menu *context_menu = nullptr;
74  SpinButtonDim *grid_spin_button;
75  std::unique_ptr<SelectionFilterDialog> selection_filter_dialog;
76 
77  std::unique_ptr<Pool> pool;
78  Cores core;
79  std::unique_ptr<ClipboardManager> clipboard = nullptr;
80  std::unique_ptr<KeySequenceDialog> key_sequence_dialog = nullptr;
81  std::unique_ptr<ImpInterface> imp_interface = nullptr;
82  Glib::RefPtr<Glib::Binding> grid_spacing_binding;
83 
84  std::map<std::pair<ActionID, ToolID>, ActionConnection> action_connections;
85  ActionConnection &connect_action(ToolID tool_id, std::function<void(const ActionConnection &)> cb);
86  ActionConnection &connect_action(ToolID tool_id);
87  ActionConnection &connect_action(ActionID action_id, std::function<void(const ActionConnection &)> cb);
88 
89  class RulesWindow *rules_window = nullptr;
90 
91  zmq::context_t zctx;
92  zmq::socket_t sock_broadcast_rx;
93  zmq::socket_t sock_project;
94  bool sockets_connected = false;
95  int mgr_pid = -1;
96  bool no_update = false;
97 
98  virtual void canvas_update() = 0;
99  void sc(void);
100  bool handle_key_press(GdkEventKey *key_event);
101  void handle_cursor_move(const Coordi &pos);
102  bool handle_click(GdkEventButton *button_event);
103  bool handle_click_release(GdkEventButton *button_event);
104  bool handle_context_menu(GdkEventButton *button_event);
105  void tool_process(ToolResponse &resp);
106  void tool_begin(ToolID id, bool override_selection = false, const std::set<SelectableRef> &sel = {},
107  std::unique_ptr<ToolData> data = nullptr);
108  void add_tool_button(ToolID id, const std::string &label, bool left = true);
109  void handle_warning_selected(const Coordi &pos);
110  virtual bool handle_broadcast(const json &j);
111  bool handle_close(GdkEventAny *ev);
112  json send_json(const json &j);
113 
114  bool trigger_action(const std::pair<ActionID, ToolID> &action);
115  bool trigger_action(ActionID aid);
116  bool trigger_action(ToolID tid);
117 
118  void add_tool_action(ToolID tid, const std::string &action);
119  void add_hamburger_menu();
120 
121  Preferences preferences;
122 
123  virtual CanvasPreferences *get_canvas_preferences()
124  {
125  return &preferences.canvas_non_layer;
126  }
127  virtual void apply_preferences();
128 
129  std::unique_ptr<WindowStateStore> state_store = nullptr;
130 
131  virtual void handle_maybe_drag();
132 
133  virtual ActionCatalogItem::Availability get_editor_type_for_action() const = 0;
134  virtual ObjectType get_editor_type() const = 0;
135 
136  void layer_up_down(bool up);
137  void goto_layer(int layer);
138 
139  Gtk::Button *create_action_button(std::pair<ActionID, ToolID> action);
140 
141  void set_action_sensitive(std::pair<ActionID, ToolID>, bool v);
142  bool get_action_sensitive(std::pair<ActionID, ToolID>) const;
143  virtual void update_action_sensitivity();
144 
145  typedef sigc::signal<void> type_signal_action_sensitive;
146  type_signal_action_sensitive signal_action_sensitive()
147  {
148  return s_signal_action_sensitive;
149  }
150 
151  virtual std::string get_hud_text(std::set<SelectableRef> &sel);
152  std::string get_hud_text_for_component(const Component *comp);
153  std::string get_hud_text_for_net(const Net *net);
154 
155  void set_monitor_files(const std::set<std::string> &files);
156  void set_monitor_items(const std::set<std::pair<ObjectType, UUID>> &items);
157  virtual void update_monitor()
158  {
159  }
160  void edit_pool_item(ObjectType type, const UUID &uu);
161 
162  void parameter_window_add_polygon_expand(class ParameterWindow *parameter_window);
163 
164  bool read_only = false;
165 
166  void tool_update_data(std::unique_ptr<ToolData> &data);
167 
168  virtual void search_center(const Core::SearchResult &res);
169  virtual std::pair<ActionID, ToolID> get_doubleclick_action(ObjectType type, const UUID &uu);
170 
171  Glib::RefPtr<Gio::Menu> hamburger_menu;
172 
173 private:
174  void fix_cursor_pos();
175  Glib::RefPtr<Gio::FileMonitor> preferences_monitor;
176  void handle_drag(bool ctrl);
177  void update_selection_label();
178  std::string get_tool_settings_filename(ToolID id);
179 
180  void hud_update();
181 
182  std::map<std::string, Glib::RefPtr<Gio::FileMonitor>> file_monitors;
183 
184  void handle_file_changed(const Glib::RefPtr<Gio::File> &file1, const Glib::RefPtr<Gio::File> &file2,
185  Gio::FileMonitorEvent ev);
186 
187  ActionConnection &connect_action(ActionID action_id, ToolID tool_id,
188  std::function<void(const ActionConnection &)> cb);
189 
190  void create_context_menu(Gtk::Menu *parent, const std::set<SelectableRef> &sel);
191 
192  KeySequence keys_current;
193  bool handle_action_key(GdkEventKey *ev);
194  void handle_tool_action(const ActionConnection &conn);
195 
196  void handle_search();
197  void search_go(int dir);
198  std::list<Core::SearchResult> search_results;
199  unsigned int search_result_current = 0;
200  void update_search_markers();
201  void update_search_types_label();
202  void set_search_mode(bool enabled, bool focus = true);
203  std::map<ObjectType, Gtk::CheckButton *> search_check_buttons;
204 
205  class LogWindow *log_window = nullptr;
206  std::set<SelectableRef> selection_for_drag_move;
207  Coordf cursor_pos_drag_begin;
208  Coordi cursor_pos_grid_drag_begin;
209 
210  std::map<std::pair<ActionID, ToolID>, bool> action_sensitivity;
211  type_signal_action_sensitive s_signal_action_sensitive;
212 
213  GdkModifierType grid_fine_modifier = GDK_MOD1_MASK;
214 
215  bool property_panel_has_focus();
216 
217  sigc::connection initial_view_all_conn;
218 
219  bool sockets_broken = false;
220  void show_sockets_broken_dialog(const std::string &msg = "");
221  bool needs_autosave = false;
222  bool queue_autosave = false;
223 };
224 } // namespace horizon
horizon::ImpBase::SelectionFilterInfo
Definition: imp.hpp:53
horizon::ToolPopover
Definition: tool_popover.hpp:9
horizon::ImpInterface
Definition: imp_interface.hpp:7
horizon::RulesWindow
Definition: rules_window.hpp:13
horizon::CanvasGL
Definition: canvas_gl.hpp:15
horizon::MainWindow
Definition: main_window.hpp:7
horizon::Cores
Tools use this class to actually access the core.
Definition: cores.hpp:13
horizon::SpinButtonDim
Definition: spin_button_dim.hpp:5
horizon::WarningsBox
Definition: warnings_box.hpp:7
horizon::Preferences
Definition: preferences.hpp:73
horizon::Coord< int64_t >
horizon::PoolParams
Definition: imp.hpp:25
horizon::CanvasPreferences
Definition: preferences.hpp:13
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
horizon::ToolResponse
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: core.hpp:52
horizon::ImpBase
Definition: imp.hpp:36
horizon::ActionConnection
Definition: action.hpp:106
horizon::PropertyPanels
Definition: property_panels.hpp:8