Horizon
pool-prj-mgr-app_win.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <memory>
4 #include "util/uuid.hpp"
5 #include <zmq.hpp>
6 #include "util/win32_undef.hpp"
7 #include "nlohmann/json_fwd.hpp"
8 #include "util/editor_process.hpp"
9 #include "util/window_state_store.hpp"
10 #include "pool-prj-mgr-process.hpp"
11 #include "prj-mgr/prj-mgr_views.hpp"
12 #include "pool-mgr/view_create_pool.hpp"
13 #include "common/common.hpp"
14 
15 namespace horizon {
16 using json = nlohmann::json;
17 
18 enum class PoolUpdateStatus;
19 enum class CheckSchemaUpdateResult;
20 
21 class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
22  friend class PoolProjectManagerViewProject;
24 
25 public:
26  PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
29 
31 
32  void open_file_view(const Glib::RefPtr<Gio::File> &file);
33  void prepare_close();
34  bool close_pool_or_project();
35  bool really_close_pool_or_project();
36  void wait_for_all_processes();
37  std::string get_filename() const;
38 
39  enum class SpawnFlags { NONE = 0, READ_ONLY = (1 << 0), TEMP = (1 << 1) };
40 
41  PoolProjectManagerProcess *spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
42  SpawnFlags flags = SpawnFlags::NONE);
43 
44  std::map<UUID, PoolProjectManagerProcess *> get_processes();
45 
46  class Pool *pool = nullptr;
47  class PoolParametric *pool_parametric = nullptr;
48 
49  typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
50  type_signal_process_exited signal_process_exited()
51  {
52  return s_signal_process_exited;
53  }
54 
55  typedef sigc::signal<void, std::string> type_signal_process_saved;
56  type_signal_process_saved signal_process_saved()
57  {
58  return s_signal_process_saved;
59  }
60 
61  class ClosePolicy {
62  public:
63  bool can_close = true;
64  std::string reason;
65  std::vector<UUID> procs_need_save;
66  };
67 
68  ClosePolicy get_close_policy();
69 
70  std::string get_proc_filename(const UUID &uu);
71  void process_save(const UUID &uu);
72  void process_close(const UUID &uu);
73  bool cleanup_pool_cache(Gtk::Window *parent);
74 
75  enum class ViewMode { OPEN, POOL, PROJECT, CREATE_PROJECT, CREATE_POOL };
76  ViewMode get_view_mode() const;
77 
78  UUID get_pool_uuid() const;
79  void pool_notebook_go_to(ObjectType type, const UUID &uu);
80  void open_pool(const std::string &pool_json, ObjectType type = ObjectType::INVALID, const UUID &uu = UUID());
81  void update_pool_cache_status_now();
82  const std::string &get_project_title() const;
83 
84  void pool_update(const std::vector<std::string> &filenames = {});
85 
86  PoolProjectManagerApplication &app;
87 
88 private:
89  Glib::RefPtr<Gtk::Builder> builder;
90  Gtk::Stack *stack = nullptr;
91  Gtk::Button *button_open = nullptr;
92  Gtk::Button *button_close = nullptr;
93  Gtk::Button *button_update = nullptr;
94  Gtk::Button *button_cancel = nullptr;
95  Gtk::MenuButton *button_new = nullptr;
96  Gtk::Button *button_create = nullptr;
97  Gtk::Button *button_save = nullptr;
98  Gtk::MenuButton *hamburger_menu_button = nullptr;
99 
100  Gtk::HeaderBar *header = nullptr;
101  Gtk::ListBox *recent_pools_listbox = nullptr;
102  Gtk::ListBox *recent_projects_listbox = nullptr;
103  std::vector<Gtk::ListBox *> recent_listboxes;
104  Gtk::Box *pool_box = nullptr;
105  class PoolNotebook *pool_notebook = nullptr;
106 
107  Gtk::Label *pool_update_status_label = nullptr;
108  Gtk::Revealer *pool_update_status_rev = nullptr;
109  Gtk::Button *pool_update_status_close_button = nullptr;
110  Gtk::ProgressBar *pool_update_progress = nullptr;
111  sigc::connection pool_update_conn;
112 
113  Gtk::InfoBar *info_bar = nullptr;
114  Gtk::Label *info_bar_label = nullptr;
115  Gtk::Button *show_output_button = nullptr;
116 
117  Gtk::InfoBar *info_bar_pool_not_added = nullptr;
118 
119  Gtk::MenuItem *menu_new_pool = nullptr;
120  Gtk::MenuItem *menu_new_project = nullptr;
121 
122  class OutputWindow *output_window = nullptr;
123 
124  Gtk::InfoBar *info_bar_pool_doc = nullptr;
125 
126  Gtk::InfoBar *info_bar_version = nullptr;
127  Gtk::Label *version_label = nullptr;
128 
129  Gtk::InfoBar *info_bar_gitignore = nullptr;
130 
131  Gtk::InfoBar *info_bar_installation_uuid_mismatch = nullptr;
132 
133  std::unique_ptr<class Project> project;
134  std::string project_filename;
135  bool project_needs_save = false;
136  void save_project();
137  class PartBrowserWindow *part_browser_window = nullptr;
138  void cleanup();
139 #if GTK_CHECK_VERSION(3, 24, 0)
140  static gboolean part_browser_key_pressed(GtkEventControllerKey *controller, guint keyval, guint keycode,
141  GdkModifierType state, gpointer user_data);
142 #endif
143 
144  ViewMode view_mode = ViewMode::OPEN;
145  void set_view_mode(ViewMode mode);
146 
147  void update_recent_items();
148 
149  void handle_open();
150  void handle_close();
151  void handle_recent();
152  void handle_update();
153  void handle_new_project();
154  void handle_new_pool();
155  void handle_create();
156  void handle_cancel();
157  void handle_save();
158  json handle_req(const json &j);
159 
160  bool on_delete_event(GdkEventAny *ev) override;
161 
162  WindowStateStore state_store;
163 
164  std::map<UUID, PoolProjectManagerProcess> processes;
165  std::map<int, bool> pids_need_save;
166  PoolProjectManagerProcess *find_process(const std::string &filename);
167  PoolProjectManagerProcess *find_top_schematic_process();
168  PoolProjectManagerProcess *find_board_process();
169 
170  const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
171  const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
172 
173  type_signal_process_exited s_signal_process_exited;
174  type_signal_process_saved s_signal_process_saved;
175 
176  PoolProjectManagerViewCreateProject view_create_project;
177  PoolProjectManagerViewProject view_project;
178  PoolProjectManagerViewCreatePool view_create_pool;
179 
180  void handle_place_part(const UUID &uu);
181  void handle_assign_part(const UUID &uu);
182 
183  zmq::socket_t sock_mgr;
184  std::string sock_mgr_ep;
185 
186  bool check_pools();
187  void check_schema_update(const std::string &base_path);
188  void check_pool_update(const std::string &base_path);
189 
190  bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
191 
192  void set_version_info(const std::string &s);
193  bool project_read_only = false;
194 
195  bool migrate_project(const std::string &path);
196  std::string project_title;
197 
198  Glib::Dispatcher pool_update_dispatcher;
199  bool in_pool_update_handler = false;
200  std::mutex pool_update_status_queue_mutex;
201  std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_status_queue;
202  std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_error_queue;
203  bool pool_updating = false;
204  void pool_updated(bool success);
205  std::string pool_update_last_file;
206  std::string pool_update_last_info;
207  unsigned int pool_update_n_files = 0;
208  unsigned int pool_update_n_files_last = 0;
209  std::vector<std::string> pool_update_filenames;
210 
211  void pool_update_thread();
212  void handle_pool_update_progress();
213  void set_pool_updating(bool v, bool success);
214  void set_pool_update_status_text(const std::string &txt);
215  void set_pool_update_progress(float progress);
216 
217  std::string get_pool_base_path() const;
218 
219  std::string get_gitignore_filename() const;
220 
221 public:
222  zmq::context_t &zctx;
223 };
224 }; // namespace horizon
Definition: pool_parametric.hpp:10
Definition: pool-prj-mgr-app_win.hpp:61
Definition: pool-prj-mgr-app_win.hpp:21
Definition: pool-prj-mgr-app.hpp:16
Definition: pool-prj-mgr-process.hpp:6
Definition: prj-mgr_views.hpp:8
Definition: prj-mgr_views.hpp:33
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:22
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62