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