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 #ifdef G_OS_WIN32
7 #undef ERROR
8 #undef DELETE
9 #undef DUPLICATE
10 #endif
11 #include "nlohmann/json_fwd.hpp"
12 #include "util/editor_process.hpp"
13 #include "util/window_state_store.hpp"
14 #include "util/status_dispatcher.hpp"
15 #include "pool-prj-mgr-process.hpp"
16 #include "project/project.hpp"
17 #include "prj-mgr/prj-mgr_views.hpp"
18 #include "pool-mgr/view_create_pool.hpp"
19 #include "common/common.hpp"
20 
21 namespace horizon {
22 using json = nlohmann::json;
23 
24 class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
25  friend class PoolProjectManagerViewProject;
27 
28 public:
29  PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
32 
34 
35  void open_file_view(const Glib::RefPtr<Gio::File> &file);
36  void prepare_close();
37  bool close_pool_or_project();
38  bool really_close_pool_or_project();
39  void wait_for_all_processes();
40  std::string get_filename() const;
41 
42  PoolProjectManagerProcess *spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
43  const std::vector<std::string> &env = {}, bool read_only = false,
44  bool is_temp = false);
45  PoolProjectManagerProcess *spawn_for_project(PoolProjectManagerProcess::Type type,
46  const std::vector<std::string> &args);
47 
48  std::map<UUID, PoolProjectManagerProcess *> get_processes();
49 
50  class Pool *pool = nullptr;
51  class PoolParametric *pool_parametric = nullptr;
52 
53  typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
54  type_signal_process_exited signal_process_exited()
55  {
56  return s_signal_process_exited;
57  }
58  void reload();
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  void cleanup_pool_cache();
73 
74  enum class ViewMode { OPEN, POOL, DOWNLOAD, 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 handle_download(bool back_to_start = false);
81 
82 private:
83  Glib::RefPtr<Gtk::Builder> builder;
84  Gtk::Stack *stack = nullptr;
85  Gtk::Button *button_open = nullptr;
86  Gtk::Button *button_close = nullptr;
87  Gtk::Button *button_update = nullptr;
88  Gtk::Button *button_download = nullptr;
89  Gtk::Button *button_do_download = nullptr;
90  Gtk::Button *button_cancel = nullptr;
91  Gtk::MenuButton *button_new = nullptr;
92  Gtk::Button *button_create = nullptr;
93  Gtk::Button *button_save = nullptr;
94  Gtk::Spinner *spinner_update = nullptr;
95  Gtk::Revealer *download_revealer = nullptr;
96  Gtk::Label *download_label = nullptr;
97  Gtk::Spinner *download_spinner = nullptr;
98  Gtk::MenuButton *hamburger_menu_button = nullptr;
99 
100  Gtk::Entry *download_gh_username_entry = nullptr;
101  Gtk::Entry *download_gh_repo_entry = nullptr;
102  Gtk::Entry *download_dest_dir_entry = nullptr;
103  Gtk::Button *download_dest_dir_button = nullptr;
104 
105  Gtk::HeaderBar *header = nullptr;
106  Gtk::ListBox *recent_pools_listbox = nullptr;
107  Gtk::ListBox *recent_projects_listbox = nullptr;
108  std::vector<Gtk::ListBox *> recent_listboxes;
109  Gtk::Box *pool_box = nullptr;
110  class PoolNotebook *pool_notebook = nullptr;
111 
112  Gtk::Label *pool_update_status_label = nullptr;
113  Gtk::Revealer *pool_update_status_rev = nullptr;
114  Gtk::Button *pool_update_status_close_button = nullptr;
115  Gtk::ProgressBar *pool_update_progress = nullptr;
116  sigc::connection pool_update_conn;
117 
118  Gtk::InfoBar *info_bar = nullptr;
119  Gtk::Label *info_bar_label = nullptr;
120  Gtk::Button *show_output_button = nullptr;
121 
122  Gtk::InfoBar *info_bar_pool_not_added = nullptr;
123 
124  Gtk::MenuItem *menu_new_pool = nullptr;
125  Gtk::MenuItem *menu_new_project = nullptr;
126 
127  class OutputWindow *output_window = nullptr;
128 
129  std::unique_ptr<Project> project = nullptr;
130  std::string project_filename;
131  bool project_needs_save = false;
132  void save_project();
133  class PartBrowserWindow *part_browser_window = nullptr;
134  class PoolCacheWindow *pool_cache_window = nullptr;
135 
136  ViewMode view_mode = ViewMode::OPEN;
137  void set_view_mode(ViewMode mode);
138 
139  void update_recent_items();
140 
141  void handle_open();
142  void handle_close();
143  void handle_recent();
144  void handle_update();
145  void handle_do_download();
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  void download_thread(std::string gh_username, std::string gh_repo, std::string dest_dir);
156 
157  StatusDispatcher download_status_dispatcher;
158 
159  WindowStateStore state_store;
160 
161  std::map<UUID, PoolProjectManagerProcess> processes;
162  std::map<int, bool> pids_need_save;
163  PoolProjectManagerProcess *find_process(const std::string &filename);
164  PoolProjectManagerProcess *find_top_schematic_process();
165  PoolProjectManagerProcess *find_board_process();
166 
167  const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
168  const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
169 
170  type_signal_process_exited s_signal_process_exited;
171 
172  PoolProjectManagerViewCreateProject view_create_project;
173  PoolProjectManagerViewProject view_project;
174  PoolProjectManagerViewCreatePool view_create_pool;
175 
176  void handle_place_part(const UUID &uu);
177  void handle_assign_part(const UUID &uu);
178 
180  zmq::socket_t sock_mgr;
181  std::string sock_mgr_ep;
182 
183  bool check_pools();
184  bool check_schema_update(const std::string &base_path);
185 
186  bool download_back_to_start = false;
187 
188  bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
189 
190 public:
191  zmq::context_t &zctx;
192  void set_pool_updating(bool v, bool success);
193  void set_pool_update_status_text(const std::string &txt);
194  void set_pool_update_progress(float progress);
195 };
196 }; // namespace horizon
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::PartBrowserWindow
Definition: part_browser_window.hpp:14
horizon::OutputWindow
Definition: output_window.hpp:8
horizon::WindowStateStore
Definition: window_state_store.hpp:20
horizon::PoolProjectManagerAppWindow::ClosePolicy
Definition: pool-prj-mgr-app_win.hpp:60
horizon::PoolProjectManagerProcess
Definition: pool-prj-mgr-process.hpp:6
horizon::PoolProjectManagerViewCreateProject
Definition: prj-mgr_views.hpp:9
horizon::PoolNotebook
Definition: pool_notebook.hpp:24
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::PoolProjectManagerViewProject
Definition: prj-mgr_views.hpp:35
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
horizon::PoolProjectManagerViewCreatePool
Definition: view_create_pool.hpp:8
horizon::PoolCacheWindow
Definition: pool_cache_window.hpp:14
horizon::PoolProjectManagerApplication
Definition: pool-prj-mgr-app.hpp:19
horizon::PoolParametric
Definition: pool_parametric.hpp:10
horizon::PoolProjectManagerAppWindow
Definition: pool-prj-mgr-app_win.hpp:24
horizon::StatusDispatcher
Definition: status_dispatcher.hpp:8