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.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 
51  std::set<ObjectRef> highlights;
52  virtual void update_highlights(){};
53 
54 protected:
55  MainWindow *main_window;
56  class CanvasGL *canvas;
57  class PropertyPanels *panels;
58  WarningsBox *warnings_box;
59  class ToolPopover *tool_popover;
60  Gtk::Menu *context_menu = nullptr;
61  SpinButtonDim *grid_spin_button;
62  std::unique_ptr<SelectionFilterDialog> selection_filter_dialog;
63 
64  std::unique_ptr<Pool> pool;
65  Cores core;
66  std::unique_ptr<ClipboardManager> clipboard = nullptr;
67  std::unique_ptr<KeySequenceDialog> key_sequence_dialog = nullptr;
68  std::unique_ptr<ImpInterface> imp_interface = nullptr;
69  Glib::RefPtr<Glib::Binding> grid_spacing_binding;
70 
71  std::map<std::pair<ActionID, ToolID>, ActionConnection> action_connections;
72  ActionConnection &connect_action(ToolID tool_id, std::function<void(const ActionConnection &)> cb);
73  ActionConnection &connect_action(ToolID tool_id);
74  ActionConnection &connect_action(ActionID action_id, std::function<void(const ActionConnection &)> cb);
75 
76  class RulesWindow *rules_window = nullptr;
77 
78  zmq::context_t zctx;
79  zmq::socket_t sock_broadcast_rx;
80  zmq::socket_t sock_project;
81  bool sockets_connected = false;
82  bool no_update = false;
83 
84  virtual void canvas_update() = 0;
85  void sc(void);
86  bool handle_key_press(GdkEventKey *key_event);
87  void handle_cursor_move(const Coordi &pos);
88  bool handle_click(GdkEventButton *button_event);
89  bool handle_click_release(GdkEventButton *button_event);
90  bool handle_context_menu(GdkEventButton *button_event);
91  void tool_process(const ToolResponse &resp);
92  void tool_begin(ToolID id);
93  void add_tool_button(ToolID id, const std::string &label, bool left = true);
94  void handle_warning_selected(const Coordi &pos);
95  virtual bool handle_broadcast(const json &j);
96  bool handle_close(GdkEventAny *ev);
97  json send_json(const json &j);
98 
99  bool trigger_action(const std::pair<ActionID, ToolID> &action);
100  bool trigger_action(ActionID aid);
101  bool trigger_action(ToolID tid);
102 
103  void add_tool_action(ToolID tid, const std::string &action);
104  Glib::RefPtr<Gio::Menu> add_hamburger_menu();
105 
106  ImpPreferences preferences;
107  class ImpPreferencesWindow *preferences_window = nullptr;
108 
109  virtual CanvasPreferences *get_canvas_preferences()
110  {
111  return &preferences.canvas_non_layer;
112  }
113 
114  std::unique_ptr<WindowStateStore> state_store = nullptr;
115 
116  virtual void handle_maybe_drag();
117 
118  virtual ActionCatalogItem::Availability get_editor_type_for_action() const = 0;
119 
120  void layer_up_down(bool up);
121  void goto_layer(int layer);
122 
123  Gtk::Button *create_action_button(std::pair<ActionID, ToolID> action);
124 
125  void set_action_sensitive(std::pair<ActionID, ToolID>, bool v);
126  bool get_action_sensitive(std::pair<ActionID, ToolID>) const;
127  virtual void update_action_sensitivity();
128 
129  typedef sigc::signal<void> type_signal_action_sensitive;
130  type_signal_action_sensitive signal_action_sensitive()
131  {
132  return s_signal_action_sensitive;
133  }
134 
135 private:
136  void fix_cursor_pos();
137  void apply_settings();
138  Glib::RefPtr<Gio::FileMonitor> preferences_monitor;
139  void show_preferences_window();
140  void handle_drag();
141  void update_selection_label();
142 
143 
144  ActionConnection &connect_action(ActionID action_id, ToolID tool_id,
145  std::function<void(const ActionConnection &)> cb);
146  KeySequence2 keys_current;
147  bool handle_action_key(GdkEventKey *ev);
148  void handle_tool_action(const ActionConnection &conn);
149 
150  class LogWindow *log_window = nullptr;
151  std::set<SelectableRef> selection_for_drag_move;
152  Coordf cursor_pos_drag_begin;
153  Coordi cursor_pos_grid_drag_begin;
154 
155  std::map<std::pair<ActionID, ToolID>, bool> action_sensitivity;
156  type_signal_action_sensitive s_signal_action_sensitive;
157 };
158 } // namespace horizon
Definition: warnings_box.hpp:7
Definition: rules_window.hpp:11
Definition: spin_button_dim.hpp:5
Definition: preferences_window.hpp:7
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: log_window.hpp:6
Definition: property_panels.hpp:7
Definition: canvas_gl.hpp:10
Definition: imp.hpp:27
Definition: imp.hpp:38
Tools use this class to actually access the core.
Definition: cores.hpp:13
Definition: preferences.hpp:58
Definition: imp_interface.hpp:6
Definition: action.hpp:71
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: core.hpp:126
Definition: block.cpp:7