Horizon
imp.hpp
1 #pragma once
2 #include "core/clipboard.hpp"
3 #include "core/core_package.hpp"
4 #include "core/core_padstack.hpp"
5 #include "core/core_schematic.hpp"
6 #include "core/core_symbol.hpp"
7 #include "core/cores.hpp"
8 #include "imp_interface.hpp"
9 #include "keyseq_dialog.hpp"
10 #include "main_window.hpp"
11 #include "pool/pool.hpp"
12 #include "preferences/preferences.hpp"
13 #include "selection_filter_dialog.hpp"
14 #include "util/window_state_store.hpp"
15 #include "widgets/spin_button_dim.hpp"
16 #include "widgets/warnings_box.hpp"
17 #include "action.hpp"
18 #include <zmq.hpp>
19 
20 #ifdef G_OS_WIN32
21 #undef DELETE
22 #undef DUPLICATE
23 #endif
24 
25 namespace horizon {
26 
27 class PoolParams {
28 public:
29  PoolParams(const std::string &bp, const std::string &cp = "") : base_path(bp), cache_path(cp)
30  {
31  }
32  std::string base_path;
33  std::string cache_path;
34 };
35 
36 std::unique_ptr<Pool> make_pool(const PoolParams &params);
37 
38 class ImpBase : public sigc::trackable {
39  friend class ImpInterface;
40 
41 public:
42  ImpBase(const PoolParams &params);
43  void run(int argc, char *argv[]);
44  virtual void handle_tool_change(ToolID id);
45  virtual void construct() = 0;
46  void canvas_update_from_pp();
47  virtual ~ImpBase()
48  {
49  }
50  void set_read_only(bool v);
51 
52  std::set<ObjectRef> highlights;
53  virtual void update_highlights(){};
54 
55 protected:
56  MainWindow *main_window;
57  class CanvasGL *canvas;
58  class PropertyPanels *panels;
59  WarningsBox *warnings_box;
60  class ToolPopover *tool_popover;
61  Gtk::Menu *context_menu = nullptr;
62  SpinButtonDim *grid_spin_button;
63  std::unique_ptr<SelectionFilterDialog> selection_filter_dialog;
64 
65  std::unique_ptr<Pool> pool;
66  Cores core;
67  std::unique_ptr<ClipboardManager> clipboard = nullptr;
68  std::unique_ptr<KeySequenceDialog> key_sequence_dialog = nullptr;
69  std::unique_ptr<ImpInterface> imp_interface = nullptr;
70  Glib::RefPtr<Glib::Binding> grid_spacing_binding;
71 
72  std::map<std::pair<ActionID, ToolID>, ActionConnection> action_connections;
73  ActionConnection &connect_action(ToolID tool_id, std::function<void(const ActionConnection &)> cb);
74  ActionConnection &connect_action(ToolID tool_id);
75  ActionConnection &connect_action(ActionID action_id, std::function<void(const ActionConnection &)> cb);
76 
77  class RulesWindow *rules_window = nullptr;
78 
79  zmq::context_t zctx;
80  zmq::socket_t sock_broadcast_rx;
81  zmq::socket_t sock_project;
82  bool sockets_connected = false;
83  int mgr_pid = -1;
84  bool no_update = false;
85 
86  virtual void canvas_update() = 0;
87  void sc(void);
88  bool handle_key_press(GdkEventKey *key_event);
89  void handle_cursor_move(const Coordi &pos);
90  bool handle_click(GdkEventButton *button_event);
91  bool handle_click_release(GdkEventButton *button_event);
92  bool handle_context_menu(GdkEventButton *button_event);
93  void tool_process(const ToolResponse &resp);
94  void tool_begin(ToolID id, bool override_selection = false, const std::set<SelectableRef> &sel = {});
95  void add_tool_button(ToolID id, const std::string &label, bool left = true);
96  void handle_warning_selected(const Coordi &pos);
97  virtual bool handle_broadcast(const json &j);
98  bool handle_close(GdkEventAny *ev);
99  json send_json(const json &j);
100 
101  bool trigger_action(const std::pair<ActionID, ToolID> &action);
102  bool trigger_action(ActionID aid);
103  bool trigger_action(ToolID tid);
104 
105  void add_tool_action(ToolID tid, const std::string &action);
106  Glib::RefPtr<Gio::Menu> add_hamburger_menu();
107 
108  Preferences preferences;
109 
110  virtual CanvasPreferences *get_canvas_preferences()
111  {
112  return &preferences.canvas_non_layer;
113  }
114  virtual void apply_preferences();
115 
116  std::unique_ptr<WindowStateStore> state_store = nullptr;
117 
118  virtual void handle_maybe_drag();
119 
120  virtual ActionCatalogItem::Availability get_editor_type_for_action() const = 0;
121  virtual ObjectType get_editor_type() const = 0;
122 
123  void layer_up_down(bool up);
124  void goto_layer(int layer);
125 
126  Gtk::Button *create_action_button(std::pair<ActionID, ToolID> action);
127 
128  void set_action_sensitive(std::pair<ActionID, ToolID>, bool v);
129  bool get_action_sensitive(std::pair<ActionID, ToolID>) const;
130  virtual void update_action_sensitivity();
131 
132  typedef sigc::signal<void> type_signal_action_sensitive;
133  type_signal_action_sensitive signal_action_sensitive()
134  {
135  return s_signal_action_sensitive;
136  }
137 
138  virtual std::string get_hud_text(std::set<SelectableRef> &sel);
139  std::string get_hud_text_for_part(const Part *part);
140  std::string get_hud_text_for_net(const Net *net);
141 
142  void set_monitor_files(const std::set<std::string> &files);
143  void set_monitor_items(const std::set<std::pair<ObjectType, UUID>> &items);
144  virtual void update_monitor()
145  {
146  }
147  void edit_pool_item(ObjectType type, const UUID &uu);
148 
149  void parameter_window_add_polygon_expand(class ParameterWindow *parameter_window);
150 
151  bool read_only = false;
152 
153  void tool_update_data(std::unique_ptr<ToolData> &data);
154 
155 private:
156  void fix_cursor_pos();
157  Glib::RefPtr<Gio::FileMonitor> preferences_monitor;
158  void handle_drag();
159  void update_selection_label();
160  std::string get_tool_settings_filename(ToolID id);
161 
162  void hud_update();
163 
164  std::map<std::string, Glib::RefPtr<Gio::FileMonitor>> file_monitors;
165 
166  void handle_file_changed(const Glib::RefPtr<Gio::File> &file1, const Glib::RefPtr<Gio::File> &file2,
167  Gio::FileMonitorEvent ev);
168 
169  ActionConnection &connect_action(ActionID action_id, ToolID tool_id,
170  std::function<void(const ActionConnection &)> cb);
171 
172  void create_context_menu(Gtk::Menu *parent, const std::set<SelectableRef> &sel);
173 
174  KeySequence2 keys_current;
175  bool handle_action_key(GdkEventKey *ev);
176  void handle_tool_action(const ActionConnection &conn);
177 
178  class LogWindow *log_window = nullptr;
179  std::set<SelectableRef> selection_for_drag_move;
180  Coordf cursor_pos_drag_begin;
181  Coordi cursor_pos_grid_drag_begin;
182 
183  std::map<std::pair<ActionID, ToolID>, bool> action_sensitivity;
184  type_signal_action_sensitive s_signal_action_sensitive;
185 };
186 } // namespace horizon
Definition: warnings_box.hpp:7
Definition: rules_window.hpp:13
Definition: spin_button_dim.hpp:5
a class to store JSON values
Definition: json.hpp:161
Definition: main_window.hpp:7
Definition: preferences.hpp:13
Definition: tool_popover.hpp:9
Definition: parameter_window.hpp:11
Definition: log_window.hpp:6
Definition: property_panels.hpp:7
Definition: canvas_gl.hpp:13
Definition: imp.hpp:27
Definition: imp.hpp:38
Tools use this class to actually access the core.
Definition: cores.hpp:13
Definition: part.hpp:13
Definition: imp_interface.hpp:7
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: action.hpp:89
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: core.hpp:46
Definition: block.cpp:9
Definition: preferences.hpp:57
Definition: net.hpp:16