| 1 |
#include "gate_editor.hpp" |
| 2 |
#include "widgets/location_entry.hpp" |
| 3 |
#include "util/util.hpp" |
| 4 |
#include "util/str_util.hpp" |
| 5 |
#include "kicad_symbol_import_wizard.hpp" |
| 6 |
#include "pool-prj-mgr/pool-prj-mgr-app_win.hpp" |
| 7 |
#include "pool/pool.hpp" |
| 8 |
|
| 9 |
namespace horizon { |
| 10 |
|
| 11 |
GateEditorImportWizard::GateEditorImportWizard(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, |
| 12 |
const UUID &g, const UUID &u, KiCadSymbolImportWizard &pa) |
| 13 |
: Gtk::Box(cobject), parent(pa), gate_uu(g), unit_uu(u) |
| 14 |
{ |
| 15 |
x->get_widget("gate_label", gate_label); |
| 16 |
x->get_widget("button_gate_edit_symbol", edit_symbol_button); |
| 17 |
x->get_widget("button_gate_edit_unit", edit_unit_button); |
| 18 |
edit_symbol_button->signal_clicked().connect(sigc::mem_fun(*this, &GateEditorImportWizard::handle_edit_symbol)); |
| 19 |
edit_unit_button->signal_clicked().connect(sigc::mem_fun(*this, &GateEditorImportWizard::handle_edit_unit)); |
| 20 |
|
| 21 |
{ |
| 22 |
Gtk::Button *from_entity_button; |
| 23 |
unit_location_entry = parent.pack_location_entry(x, "gate_unit_location_box", &from_entity_button); |
| 24 |
from_entity_button->set_label("From entity"); |
| 25 |
from_entity_button->signal_clicked().connect([this] { |
| 26 |
auto rel = get_suffixed_filename_from_entity(); |
| 27 |
unit_location_entry->set_filename(Glib::build_filename(parent.pool.get_base_path(), "units", rel)); |
| 28 |
}); |
| 29 |
unit_location_entry->set_filename(Glib::build_filename(parent.pool.get_base_path(), "units")); |
| 30 |
unit_location_entry->signal_changed().connect( |
| 31 |
sigc::mem_fun(parent, &KiCadSymbolImportWizard::update_can_finish)); |
| 32 |
} |
| 33 |
|
| 34 |
{ |
| 35 |
Gtk::Button *from_entity_button; |
| 36 |
symbol_location_entry = parent.pack_location_entry(x, "gate_symbol_location_box", &from_entity_button); |
| 37 |
from_entity_button->set_label("From entity"); |
| 38 |
from_entity_button->signal_clicked().connect([this] { |
| 39 |
auto rel = get_suffixed_filename_from_entity(); |
| 40 |
symbol_location_entry->set_filename(Glib::build_filename(parent.pool.get_base_path(), "symbols", rel)); |
| 41 |
}); |
| 42 |
symbol_location_entry->set_filename(Glib::build_filename(parent.pool.get_base_path(), "symbols")); |
| 43 |
symbol_location_entry->signal_changed().connect( |
| 44 |
sigc::mem_fun(parent, &KiCadSymbolImportWizard::update_can_finish)); |
| 45 |
} |
| 46 |
|
| 47 |
auto &gate = parent.pool.get_entity(parent.entity_uuid)->gates.at(gate_uu); |
| 48 |
gate_label->set_text("Gate " + gate.name); |
| 49 |
} |
| 50 |
|
| 51 |
std::string GateEditorImportWizard::get_suffixed_filename_from_entity() |
| 52 |
{ |
| 53 |
auto rel = parent.get_rel_entity_filename(); |
| 54 |
auto &gate = parent.pool.get_entity(parent.entity_uuid)->gates.at(gate_uu); |
| 55 |
std::string suffix = gate.suffix; |
| 56 |
trim(suffix); |
| 57 |
if (suffix.size() && endswith(rel, ".json")) { |
| 58 |
rel.insert(rel.size() - 5, "-" + suffix); |
| 59 |
} |
| 60 |
return rel; |
| 61 |
} |
| 62 |
|
| 63 |
GateEditorImportWizard *GateEditorImportWizard::create(const UUID &g, const UUID &u, KiCadSymbolImportWizard &pa) |
| 64 |
{ |
| 65 |
GateEditorImportWizard *w; |
| 66 |
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create(); |
| 67 |
x->add_from_resource( |
| 68 |
"/org/horizon-eda/horizon/pool-prj-mgr/pool-mgr/kicad_symbol_import_wizard/kicad_symbol_import_wizard.ui"); |
| 69 |
x->get_widget_derived("gate_editor", w, g, u, pa); |
| 70 |
w->reference(); |
| 71 |
return w; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
void GateEditorImportWizard::handle_edit_unit() |
| 76 |
{ |
| 77 |
std::string filename = parent.pool.get_tmp_filename(ObjectType::UNIT, unit_uu); |
| 78 |
auto proc = parent.appwin.spawn(PoolProjectManagerProcess::Type::UNIT, {filename}); |
| 79 |
if (proc.spawned) { |
| 80 |
parent.processes.emplace(filename, proc.proc); |
| 81 |
proc.proc->signal_exited().connect([this, filename](int status, bool modified) { |
| 82 |
parent.processes.erase(filename); |
| 83 |
parent.update_can_finish(); |
| 84 |
}); |
| 85 |
} |
| 86 |
parent.update_can_finish(); |
| 87 |
} |
| 88 |
|
| 89 |
void GateEditorImportWizard::handle_edit_symbol() |
| 90 |
{ |
| 91 |
std::string filename = parent.pool.get_tmp_filename(ObjectType::SYMBOL, parent.symbols.at(unit_uu)); |
| 92 |
auto proc = parent.appwin.spawn(PoolProjectManagerProcess::Type::IMP_SYMBOL, {filename}); |
| 93 |
if (proc.spawned) { |
| 94 |
parent.processes.emplace(filename, proc.proc); |
| 95 |
proc.proc->signal_exited().connect([this, filename](int status, bool modified) { |
| 96 |
parent.processes.erase(filename); |
| 97 |
parent.update_can_finish(); |
| 98 |
}); |
| 99 |
} |
| 100 |
parent.update_can_finish(); |
| 101 |
} |
| 102 |
|
| 103 |
} // namespace horizon |