Debian Codegraph @

src/pool-prj-mgr/pool-mgr/part_wizard/gate_editor.cpp

raw
1 #include "gate_editor.hpp"
2 #include "part_wizard.hpp"
3 #include "widgets/location_entry.hpp"
4 #include "util/util.hpp"
5 #include "util/str_util.hpp"
6
7 namespace horizon {
8
9 GateEditorWizard::GateEditorWizard(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, Gate *g,
10 PartWizard *pa)
11 : Gtk::Box(cobject), parent(pa), gate(g)
12 {
13 x->get_widget("gate_label", gate_label);
14 x->get_widget("gate_symbol_label", gate_symbol_label);
15 x->get_widget("gate_edit_symbol", edit_symbol_button);
16 x->get_widget("gate_suffix", suffix_entry);
17 x->get_widget("gate_unit_name", unit_name_entry);
18 x->get_widget("gate_unit_name_from_mpn", unit_name_from_mpn_button);
19 x->get_widget("gate_symbol_name", symbol_name_entry);
20 x->get_widget("gate_symbol_name_from_unit", symbol_name_from_unit_button);
21
22 gate_label->set_text("Gate: " + gate->name);
23
24 unit_name_entry->signal_changed().connect(sigc::mem_fun(parent, &PartWizard::update_can_finish));
25 suffix_entry->signal_changed().connect(sigc::mem_fun(parent, &PartWizard::update_can_finish));
26
27 {
28 Gtk::Button *from_part_button;
29 unit_location_entry = pa->pack_location_entry(x, "gate_unit_location_box", &from_part_button);
30 from_part_button->set_label("From part");
31 from_part_button->signal_clicked().connect([this] {
32 auto rel = get_suffixed_filename_from_part();
33 unit_location_entry->set_filename(Glib::build_filename(parent->pool_base_path, "units", rel));
34 });
35 unit_location_entry->set_filename(Glib::build_filename(parent->pool_base_path, "units"));
36 unit_location_entry->signal_changed().connect(sigc::mem_fun(parent, &PartWizard::update_can_finish));
37 }
38
39 {
40 Gtk::Button *from_part_button;
41 symbol_location_entry = pa->pack_location_entry(x, "gate_symbol_location_box", &from_part_button);
42 from_part_button->set_label("From part");
43 from_part_button->signal_clicked().connect([this] {
44 auto rel = get_suffixed_filename_from_part();
45 symbol_location_entry->set_filename(Glib::build_filename(parent->pool_base_path, "symbols", rel));
46 });
47 symbol_location_entry->set_filename(Glib::build_filename(parent->pool_base_path, "symbols"));
48 symbol_location_entry->signal_changed().connect(sigc::mem_fun(parent, &PartWizard::update_can_finish));
49 }
50
51 unit_name_from_mpn_button->signal_clicked().connect(
52 [this] { unit_name_entry->set_text(parent->part_mpn_entry->get_text() + " " + suffix_entry->get_text()); });
53 symbol_name_from_unit_button->signal_clicked().connect(
54 [this] { symbol_name_entry->set_text(unit_name_entry->get_text()); });
55 }
56
57 std::string GateEditorWizard::get_suffixed_filename_from_part()
58 {
59 auto rel = parent->get_rel_part_filename();
60 std::string suffix = suffix_entry->get_text();
61 trim(suffix);
62 if (suffix.size() && endswith(rel, ".json")) {
63 rel.insert(rel.size() - 5, "-" + suffix);
64 }
65 return rel;
66 }
67
68 void GateEditorWizard::update_symbol_pins(unsigned int n_mapped)
69 {
70 if (n_mapped == 0) {
71 gate_symbol_label->set_text("no pins mapped in symbol");
72 }
73 else if (n_mapped == gate->unit->pins.size()) {
74 gate_symbol_label->set_text("all pins mapped in symbol");
75 }
76 else {
77 gate_symbol_label->set_text(format_m_of_n(n_mapped, gate->unit->pins.size()) + " pins mapped in symbol");
78 }
79 }
80
81 void GateEditorWizard::set_can_edit_symbol_name(bool v)
82 {
83 symbol_name_entry->set_sensitive(v);
84 symbol_name_from_unit_button->set_sensitive(v);
85 }
86
87 GateEditorWizard *GateEditorWizard::create(Gate *g, PartWizard *pa)
88 {
89 GateEditorWizard *w;
90 Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
91 x->add_from_resource(
92 "/org/horizon-eda/horizon/pool-prj-mgr/pool-mgr/part_wizard/"
93 "part_wizard.ui");
94 x->get_widget_derived("gate_editor", w, g, pa);
95 w->reference();
96 return w;
97 }
98 } // namespace horizon