Horizon
part_wizard.hpp
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 CSV {
11 class Csv;
12 }
13 
14 namespace horizon {
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 class Package *p,
22  const std::string &bp, class Pool *po, class PoolProjectManagerAppWindow *aw);
23  static PartWizard *create(const class Package *p, 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;
32  std::string pool_base_path;
33  class Pool *pool;
34 
35  Gtk::Button *button_back = nullptr;
36  Gtk::Button *button_next = nullptr;
37  Gtk::Button *button_finish = nullptr;
38  Gtk::Stack *stack = nullptr;
39 
40  Gtk::ListBox *pads_lb = nullptr;
41  Gtk::ToolButton *button_link_pads = nullptr;
42  Gtk::ToolButton *button_unlink_pads = nullptr;
43  Gtk::ToolButton *button_import_pads = nullptr;
44 
45  Glib::RefPtr<Gtk::SizeGroup> sg_name;
46  Gtk::Box *page_assign = nullptr;
47  Gtk::Box *page_edit = nullptr;
48  Gtk::Box *edit_left_box = nullptr;
49 
50  Gtk::Entry *entity_name_entry = nullptr;
51  Gtk::Button *entity_name_from_mpn_button = nullptr;
52  Gtk::Entry *entity_prefix_entry = nullptr;
53  class TagEntry *entity_tags_entry = nullptr;
54 
55  Gtk::Entry *part_mpn_entry = nullptr;
56  Gtk::Entry *part_value_entry = nullptr;
57  Gtk::Entry *part_manufacturer_entry = nullptr;
58  Gtk::Entry *part_datasheet_entry = nullptr;
59  Gtk::Entry *part_description_entry = nullptr;
60  class TagEntry *part_tags_entry = nullptr;
61  Gtk::Button *part_autofill_button = nullptr;
62 
63  class LocationEntry *entity_location_entry = nullptr;
64  class LocationEntry *part_location_entry = nullptr;
65 
66  Gtk::Grid *steps_grid = nullptr;
67 
68  Part part;
69  Entity entity;
70 
71  class ListColumns : public Gtk::TreeModelColumnRecord {
72  public:
73  ListColumns()
74  {
75  Gtk::TreeModelColumnRecord::add(name);
76  }
77  Gtk::TreeModelColumn<Glib::ustring> name;
78  };
79  ListColumns list_columns;
80 
81  Glib::RefPtr<Gtk::ListStore> gate_name_store;
82  void update_gate_names();
83  void update_pin_warnings();
84  std::map<std::pair<std::string, std::string>, std::set<class PadEditor *>> get_pin_names();
85  void handle_link();
86  void handle_unlink();
87  void handle_import();
88  void update_part();
89 
90  class PadImportItem {
91  public:
92  std::string pin;
93  std::string gate = "Main";
94  std::vector<std::string> alt;
95  Pin::Direction direction = Pin::Direction::INPUT;
96  };
97  void import_pads(const json &j);
98  void import_pads(CSV::Csv &csv);
99  void import_pads(const std::map<std::string, PadImportItem> &items);
100 
101  void create_pad_editors();
102  void autolink_pads();
103  void link_pads(const std::deque<class PadEditor *> &eds);
104  bool frozen = false;
105 
106  enum class Mode { ASSIGN, EDIT };
107 
108  void handle_next();
109  void handle_back();
110  void handle_finish();
111  void finish();
112 
113  std::string get_rel_part_filename();
114  void update_can_finish();
115  void autofill();
116  void update_steps();
117  bool valid = false;
118  bool mpn_valid = false;
119  bool part_filename_valid = false;
120  bool gates_valid = false;
121  std::vector<std::string> get_filenames();
122  std::vector<std::string> files_saved;
123 
124  Mode mode = Mode::ASSIGN;
125  void set_mode(Mode mo);
126  void prepare_edit();
127  std::map<std::string, Unit> units;
128  std::map<UUID, UUID> symbols; // unit UUID -> symbol UUID
129  std::map<UUID, unsigned int> symbol_pins_mapped; // unit UUID -> pins mapped
130  void update_symbol_pins_mapped();
131 
132  std::map<std::string, class PoolProjectManagerProcess *> processes;
133  std::set<UUID> symbols_open;
134 
136 
137  class LocationEntry *pack_location_entry(const Glib::RefPtr<Gtk::Builder> &x, const std::string &w,
138  Gtk::Button **button_other = nullptr);
139 
140  WindowStateStore state_store;
141 };
142 } // namespace horizon
horizon::PadEditor
Definition: pad_editor.hpp:8
horizon::LocationEntry
Definition: location_entry.hpp:6
horizon::WindowStateStore
Definition: window_state_store.hpp:20
horizon::TagEntry
Definition: tag_entry.hpp:9
horizon::GateEditorWizard
Definition: gate_editor.hpp:10
horizon::Entity
Definition: entity.hpp:13
horizon::Package
Definition: package.hpp:28
horizon::PartWizard
Definition: part_wizard.hpp:16
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
horizon::Part
Definition: part.hpp:13
CSV::Csv
Definition: csv.hpp:30
horizon::PoolProjectManagerAppWindow
Definition: pool-prj-mgr-app_win.hpp:24