| 1 |
#include "pad_editor.hpp" |
| 2 |
#include "part_wizard.hpp" |
| 3 |
#include "util/util.hpp" |
| 4 |
#include "widgets/pin_names_editor.hpp" |
| 5 |
|
| 6 |
namespace horizon { |
| 7 |
void PadEditor::update_names() |
| 8 |
{ |
| 9 |
names.clear(); |
| 10 |
for (auto &it : pads) { |
| 11 |
names.emplace_back(it->name); |
| 12 |
} |
| 13 |
|
| 14 |
std::sort(names.begin(), names.end(), [](const auto &a, const auto &b) { return strcmp_natural(a, b) < 0; }); |
| 15 |
|
| 16 |
{ |
| 17 |
std::stringstream s; |
| 18 |
std::copy(names.begin(), names.end(), std::ostream_iterator<std::string>(s, " ")); |
| 19 |
pad_names_label->set_text(s.str()); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
std::string PadEditor::get_gate_name() |
| 24 |
{ |
| 25 |
return combo_gate_entry->get_text(); |
| 26 |
} |
| 27 |
|
| 28 |
PadEditor::PadEditor(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, const Pad *p, PartWizard *pa) |
| 29 |
: Gtk::Box(cobject), parent(pa), pads({p}) |
| 30 |
{ |
| 31 |
x->get_widget("pad_names", pad_names_label); |
| 32 |
x->get_widget("pin_name", pin_name_entry); |
| 33 |
x->get_widget("pin_direction", dir_combo); |
| 34 |
x->get_widget("combo_gate", combo_gate); |
| 35 |
|
| 36 |
{ |
| 37 |
Gtk::Box *pin_names_box; |
| 38 |
x->get_widget("pin_names_box", pin_names_box); |
| 39 |
pin_names_editor = Gtk::manage(new PinNamesEditor(pin_names)); |
| 40 |
pin_names_box->pack_start(*pin_names_editor, true, true, 0); |
| 41 |
pin_names_editor->show(); |
| 42 |
} |
| 43 |
|
| 44 |
auto propagate = [this](std::function<void(PadEditor *)> fn) { |
| 45 |
auto lb = dynamic_cast<Gtk::ListBox *>(get_ancestor(GTK_TYPE_LIST_BOX)); |
| 46 |
auto this_row = dynamic_cast<Gtk::ListBoxRow *>(get_ancestor(GTK_TYPE_LIST_BOX_ROW)); |
| 47 |
auto rows = lb->get_selected_rows(); |
| 48 |
if (rows.size() > 1 && this_row->is_selected()) { |
| 49 |
for (auto &row : rows) { |
| 50 |
if (auto ed = dynamic_cast<PadEditor *>(row->get_child())) { |
| 51 |
fn(ed); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
parent->sg_pad->add_widget(*pad_names_label); |
| 59 |
parent->sg_pin_name->add_widget(*pin_name_entry); |
| 60 |
parent->sg_direction->add_widget(*dir_combo); |
| 61 |
parent->sg_alt_names->add_widget(*pin_names_editor); |
| 62 |
parent->sg_gate->add_widget(*combo_gate); |
| 63 |
|
| 64 |
for (const auto &it : Pin::direction_names) { |
| 65 |
dir_combo->append(std::to_string(static_cast<int>(it.first)), it.second); |
| 66 |
} |
| 67 |
dir_combo->set_active(0); |
| 68 |
|
| 69 |
dir_combo->signal_changed().connect([this, propagate] { |
| 70 |
propagate([this](PadEditor *ed) { ed->dir_combo->set_active_id(dir_combo->get_active_id()); }); |
| 71 |
}); |
| 72 |
|
| 73 |
|
| 74 |
combo_gate->set_model(parent->gate_name_store); |
| 75 |
combo_gate->set_entry_text_column(parent->list_columns.name); |
| 76 |
combo_gate->set_active(0); |
| 77 |
|
| 78 |
pin_name_entry->signal_changed().connect([this] { parent->update_pin_warnings(); }); |
| 79 |
|
| 80 |
combo_gate_entry = dynamic_cast<Gtk::Entry *>(combo_gate->get_child()); |
| 81 |
combo_gate_entry->signal_changed().connect([this, propagate] { |
| 82 |
parent->update_gate_names(); |
| 83 |
parent->update_pin_warnings(); |
| 84 |
propagate([this](PadEditor *ed) { ed->combo_gate_entry->set_text(combo_gate_entry->get_text()); }); |
| 85 |
}); |
| 86 |
|
| 87 |
update_names(); |
| 88 |
parent->update_pin_warnings(); |
| 89 |
} |
| 90 |
|
| 91 |
PadEditor *PadEditor::create(const Pad *p, PartWizard *pa) |
| 92 |
{ |
| 93 |
PadEditor *w; |
| 94 |
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create(); |
| 95 |
x->add_from_resource( |
| 96 |
"/org/horizon-eda/horizon/pool-prj-mgr/pool-mgr/part_wizard/" |
| 97 |
"part_wizard.ui"); |
| 98 |
x->get_widget_derived("pad_editor", w, p, pa); |
| 99 |
w->reference(); |
| 100 |
return w; |
| 101 |
} |
| 102 |
} // namespace horizon |