1 #pragma once
2 #include <gtkmm.h>
3 #include "common/common.hpp"
4 #include "pool/unit.hpp"
5 #include "pool/part.hpp"
6 #include "pool/entity.hpp"
7 #include "../pool_notebook.hpp" //for processes
8 #include "util/window_state_store.hpp"
9 
10 namespace horizon {
11 
12 namespace CSV {
13 class Csv;
14 }
15 
16 class PartWizard : public Gtk::Window {
17     friend class PadEditor;
18     friend class GateEditorWizard;
19 
20 public:
21     PartWizard(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, const UUID &pkg_uuid,
22                const std::string &bp, class Pool &po, class PoolProjectManagerAppWindow &aw);
23     static PartWizard *create(const UUID &pkg_uuid, const std::string &pool_base_path, class Pool &po,
24                               class PoolProjectManagerAppWindow &aw);
25     std::vector<std::string> get_files_saved() const;
26     void reload();
27 
28     ~PartWizard();
29 
30 private:
31     const class Package *pkg = nullptr;
32     void set_pkg(const Package *p);
33     std::string pool_base_path;
34     class Pool &pool;
35 
36     Gtk::HeaderBar *header = nullptr;
37     Gtk::Button *button_back = nullptr;
38     Gtk::Button *button_next = nullptr;
39     Gtk::Button *button_finish = nullptr;
40     Gtk::Button *button_select = nullptr;
41     Gtk::Stack *stack = nullptr;
42     class PoolBrowserPackage *browser_package = nullptr;
43     class PreviewCanvas *canvas = nullptr;
44     Gtk::Allocation canvas_alloc;
45 
46     Gtk::ListBox *pads_lb = nullptr;
47     Gtk::ToolButton *button_link_pads = nullptr;
48     Gtk::ToolButton *button_unlink_pads = nullptr;
49     Gtk::ToolButton *button_import_pads = nullptr;
50 
51     Glib::RefPtr<Gtk::SizeGroup> sg_name;
52     Gtk::Box *page_assign = nullptr;
53     Gtk::Box *page_edit = nullptr;
54     Gtk::Box *edit_left_box = nullptr;
55 
56     Gtk::Entry *entity_name_entry = nullptr;
57     Gtk::Button *entity_name_from_mpn_button = nullptr;
58     Gtk::Entry *entity_prefix_entry = nullptr;
59     class TagEntry *entity_tags_entry = nullptr;
60 
61     Gtk::Entry *part_mpn_entry = nullptr;
62     Gtk::Entry *part_value_entry = nullptr;
63     Gtk::Entry *part_manufacturer_entry = nullptr;
64     Gtk::Entry *part_datasheet_entry = nullptr;
65     Gtk::Entry *part_description_entry = nullptr;
66     class TagEntry *part_tags_entry = nullptr;
67     Gtk::Button *part_autofill_button = nullptr;
68 
69     class LocationEntry *entity_location_entry = nullptr;
70     class LocationEntry *part_location_entry = nullptr;
71 
72     Gtk::Grid *steps_grid = nullptr;
73 
74     Part part;
75     Entity entity;
76 
77     class ListColumns : public Gtk::TreeModelColumnRecord {
78     public:
ListColumns()79         ListColumns()
80         {
81             Gtk::TreeModelColumnRecord::add(name);
82         }
83         Gtk::TreeModelColumn<Glib::ustring> name;
84     };
85     ListColumns list_columns;
86 
87     Glib::RefPtr<Gtk::ListStore> gate_name_store;
88     void update_gate_names();
89     void update_pin_warnings();
90     std::map<std::pair<std::string, std::string>, std::set<class PadEditor *>> get_pin_names();
91     void handle_link();
92     void handle_unlink();
93     void handle_import();
94     void update_part();
95 
96     class PadImportItem {
97     public:
98         std::string pin;
99         std::string gate = "Main";
100         std::vector<std::string> alt;
101         Pin::Direction direction = Pin::Direction::INPUT;
102     };
103     void import_pads(const json &j);
104     void import_pads(CSV::Csv &csv);
105     void import_pads(const std::map<std::string, PadImportItem> &items);
106 
107     void create_pad_editors();
108     void autolink_pads();
109     void link_pads(const std::deque<class PadEditor *> &eds);
110     bool frozen = false;
111 
112     enum class Mode { PACKAGE, ASSIGN, EDIT };
113 
114     void handle_next();
115     void handle_back();
116     void handle_finish();
117     void handle_select();
118     void finish();
119 
120     std::string get_rel_part_filename();
121     void update_can_finish();
122     void autofill();
123     void update_steps();
124     bool valid = false;
125     bool mpn_valid = false;
126     bool part_filename_valid = false;
127     bool gates_valid = false;
128     std::vector<std::string> get_filenames();
129     std::vector<std::string> files_saved;
130 
131     Mode mode = Mode::ASSIGN;
132     void set_mode(Mode mo);
133     void prepare_edit();
134     std::map<std::string, Unit> units;
135     std::map<UUID, UUID> symbols;                    // unit UUID -> symbol UUID
136     std::map<UUID, unsigned int> symbol_pins_mapped; // unit UUID -> pins mapped
137     void update_symbol_pins_mapped();
138 
139     std::map<std::string, class PoolProjectManagerProcess *> processes;
140     std::set<UUID> symbols_open;
141 
142     PoolProjectManagerAppWindow &appwin;
143 
144     class LocationEntry *pack_location_entry(const Glib::RefPtr<Gtk::Builder> &x, const std::string &w,
145                                              Gtk::Button **button_other = nullptr);
146 
147     WindowStateStore state_store;
148 };
149 } // namespace horizon
150