Skip to content

Commit

Permalink
Add fixed parameters in packages and pads
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwilson committed Sep 18, 2024
1 parent 1410512 commit 2ca2e96
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/core/core_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ CorePackage::CorePackage(const std::string &filename, IPool &pool)
: Core(pool, nullptr), package(Package::new_from_file(filename, pool)), m_filename(filename),
m_pictures_dir(Glib::build_filename(Glib::path_get_dirname(filename), "pictures")), rules(package.rules),
grid_settings(package.grid_settings), parameter_program_code(package.parameter_program.get_code()),
parameter_set(package.parameter_set), models(package.models), default_model(package.default_model)
parameter_set(package.parameter_set), parameters_fixed(package.parameters_fixed), models(package.models),
default_model(package.default_model)
{
package.load_pictures(m_pictures_dir);
rebuild("init");
Expand Down Expand Up @@ -261,6 +262,7 @@ const std::string &CorePackage::get_filename() const
void CorePackage::save(const std::string &suffix)
{
package.parameter_set = parameter_set;
package.parameters_fixed = parameters_fixed;
package.parameter_program.set_code(parameter_program_code);
package.models = models;
package.default_model = default_model;
Expand Down
1 change: 1 addition & 0 deletions src/core/core_package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CorePackage : public Core, public virtual IDocumentPackage {
public:
std::string parameter_program_code;
ParameterSet parameter_set;
std::set<ParameterID> parameters_fixed;

std::map<UUID, Package::Model> models;
UUID default_model;
Expand Down
80 changes: 76 additions & 4 deletions src/dialogs/pad_parameter_set_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@

namespace horizon {

static void copy_param(ParameterSet &dest, const ParameterSet &src, const std::set<ParameterID> &parameters_fixed,
ParameterID id)
{
if (src.count(id) && !parameters_fixed.count(id)) {
dest[id] = src.at(id);
}
}

static void copy_param(ParameterSet &dest, const ParameterSet &src, const std::set<ParameterID> &parameters_fixed,
const std::set<ParameterID> &ids)
{
for (const auto id : ids) {
copy_param(dest, src, parameters_fixed, id);
}
}

PadParameterSetWindow::PadParameterSetWindow(Gtk::Window *parent, class ImpInterface *intf,
std::set<class Pad *> &apads, IPool &p, class Package &apkg)
: ToolWindow(parent, intf), pool(p), pkg(apkg), pads(apads)
Expand Down Expand Up @@ -44,7 +60,11 @@ PadParameterSetWindow::PadParameterSetWindow(Gtk::Window *parent, class ImpInter
for (auto &it : pads) {
it->pool_padstack = ps;
it->padstack = *ps;
it->padstack.apply_parameter_set(it->parameter_set);
auto ps_this = it->parameter_set;
copy_param(ps_this, pkg.parameter_set, it->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
it->padstack.apply_parameter_set(ps_this);
}
emit_event(ToolDataWindow::Event::UPDATE);
});
Expand Down Expand Up @@ -79,14 +99,52 @@ void PadParameterSetWindow::load_pad()
delete editor;
editor = Gtk::manage(new ParameterSetEditor(&pad_current->parameter_set, false));
editor->set_has_apply_all_toggle("Apply to all selected pads (Shift+Enter)");
editor->signal_create_extra_widget().connect([this](ParameterID id) {
auto w = Gtk::manage(new Gtk::ToggleButton);
w->set_image_from_icon_name("view-pin", Gtk::ICON_SIZE_BUTTON);
w->set_tooltip_text("Fixed pad parameters cannot be changed by package or board rules");
w->set_active(pad_current->parameters_fixed.count(id));
w->signal_toggled().connect([this, id, w] {
if (w->get_active()) {
pad_current->parameters_fixed.insert(id);
}
else {
pad_current->parameters_fixed.erase(id);
}
if (params_apply_all.count(id)) {
apply_all(id);
for (auto pad : pads) {
auto ps_this = pad->parameter_set;
copy_param(ps_this, pkg.parameter_set, pad->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
pad->padstack.apply_parameter_set(ps_this);
}
}
else {
auto ps_current = pad_current->parameter_set;
copy_param(ps_current, pkg.parameter_set, pad_current->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
pad_current->padstack.apply_parameter_set(ps_current);
}
emit_event(ToolDataWindow::Event::UPDATE);
});
return w;
});
editor->signal_remove_extra_widget().connect([this](ParameterID id) { pad_current->parameters_fixed.erase(id); });
editor->populate();
editor->set_apply_all(params_apply_all);
editor->signal_apply_all_toggled().connect([this](ParameterID id, bool enable) {
if (enable) {
params_apply_all.insert(id);
apply_all(id);
for (auto pad : pads) {
pad->padstack.apply_parameter_set(pad->parameter_set);
auto ps_this = pad->parameter_set;
copy_param(ps_this, pkg.parameter_set, pad->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
pad->padstack.apply_parameter_set(ps_this);
}
emit_event(ToolDataWindow::Event::UPDATE);
}
Expand All @@ -100,7 +158,11 @@ void PadParameterSetWindow::load_pad()
apply_all(id);
}
for (auto pad : pads) {
pad->padstack.apply_parameter_set(pad->parameter_set);
auto ps_this = pad->parameter_set;
copy_param(ps_this, pkg.parameter_set, pad->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
pad->padstack.apply_parameter_set(ps_this);
}
emit_event(ToolDataWindow::Event::UPDATE);
});
Expand All @@ -118,7 +180,11 @@ void PadParameterSetWindow::load_pad()
auto ps = pool.get_padstack(padstack_button->property_selected_uuid());
pad_current->pool_padstack = ps;
pad_current->padstack = *ps;
pad_current->padstack.apply_parameter_set(pad_current->parameter_set);
auto ps_current = pad_current->parameter_set;
copy_param(ps_current, pkg.parameter_set, pad_current->parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
pad_current->padstack.apply_parameter_set(ps_current);
emit_event(ToolDataWindow::Event::UPDATE);
});
box2->pack_start(*padstack_button, true, true, 0);
Expand All @@ -129,6 +195,12 @@ void PadParameterSetWindow::apply_all(ParameterID id)
{
for (auto it : pads) {
it->parameter_set[id] = pad_current->parameter_set.at(id);
if (pad_current->parameters_fixed.count(id)) {
it->parameters_fixed.insert(id);
}
else {
it->parameters_fixed.erase(id);
}
}
}

Expand Down
28 changes: 27 additions & 1 deletion src/imp/imp_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ void ImpPackage::check_alt_pkg()
pool->db.execute("DROP VIEW IF EXISTS pkg_deps");
}

class MyToggleButton : public Gtk::ToggleButton, public Changeable {
public:
MyToggleButton() : Gtk::ToggleButton()
{
signal_toggled().connect([this] { s_signal_changed.emit(); });
}
};

void ImpPackage::construct()
{
ImpLayer::construct_layer_box();
Expand All @@ -188,8 +196,26 @@ void ImpPackage::construct()
footprint_generator_window = FootprintGeneratorWindow::create(main_window, core_package);
footprint_generator_window->signal_generated().connect(sigc::mem_fun(*this, &ImpBase::canvas_update_from_pp));

auto editor = new ParameterSetEditor(&core_package.parameter_set, false);
editor->signal_create_extra_widget().connect([this](ParameterID id) {
auto w = Gtk::manage(new MyToggleButton);
w->set_image_from_icon_name("view-pin", Gtk::ICON_SIZE_BUTTON);
w->set_tooltip_text("Fixed parameters cannot be changed by board rules");
w->set_active(core_package.parameters_fixed.count(id));
w->signal_toggled().connect([this, id, w] {
if (w->get_active()) {
core_package.parameters_fixed.insert(id);
}
else {
core_package.parameters_fixed.erase(id);
}
});
return w;
});
editor->signal_remove_extra_widget().connect([this](ParameterID id) { core_package.parameters_fixed.erase(id); });

parameter_window =
new ParameterWindow(main_window, &core_package.parameter_program_code, &core_package.parameter_set);
new ParameterWindow(main_window, &core_package.parameter_program_code, &core_package.parameter_set, editor);
parameter_window->signal_changed().connect([this] { core_package.set_needs_save(); });
{
auto button = Gtk::manage(new Gtk::Button("Parameters…"));
Expand Down
9 changes: 9 additions & 0 deletions src/package/pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Pad::Pad(const UUID &uu, const json &j, IPool &pool)
if (j.count("parameter_set")) {
parameter_set = parameter_set_from_json(j.at("parameter_set"));
}
if (j.count("parameters_fixed")) {
const json &o = j["parameters_fixed"];
for (const auto &value : o) {
parameters_fixed.insert(parameter_id_from_string(value.get<std::string>()));
}
}
}
Pad::Pad(const UUID &uu, std::shared_ptr<const Padstack> ps) : uuid(uu), pool_padstack(ps), padstack(*ps)
{
Expand All @@ -23,6 +29,9 @@ json Pad::serialize() const
j["placement"] = placement.serialize();
j["name"] = name;
j["parameter_set"] = parameter_set_serialize(parameter_set);
for (const auto &it : parameters_fixed) {
j["parameters_fixed"].push_back(parameter_id_to_string(it));
}

return j;
}
Expand Down
1 change: 1 addition & 0 deletions src/package/pad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Pad {
Placement placement;
std::string name;
ParameterSet parameter_set;
std::set<ParameterID> parameters_fixed;

uuid_ptr<class Net> net = nullptr;
bool is_nc = false;
Expand Down
34 changes: 25 additions & 9 deletions src/pool/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int Package::Model::get_rotation(unsigned int ax) const
}
}

static const unsigned int app_version = 0;
static const unsigned int app_version = 1;

unsigned int Package::get_app_version()
{
Expand Down Expand Up @@ -211,6 +211,12 @@ Package::Package(const UUID &uu, const json &j, IPool &pool)
if (j.count("parameter_set")) {
parameter_set = parameter_set_from_json(j.at("parameter_set"));
}
if (j.count("parameters_fixed")) {
const json &o = j["parameters_fixed"];
for (const auto &value : o) {
parameters_fixed.insert(parameter_id_from_string(value.get<std::string>()));
}
}
if (j.count("alternate_for")) {
alternate_for = pool.get_package(UUID(j.at("alternate_for").get<std::string>()));
}
Expand Down Expand Up @@ -263,8 +269,9 @@ Package::Package(const Package &pkg)
: uuid(pkg.uuid), name(pkg.name), manufacturer(pkg.manufacturer), tags(pkg.tags), junctions(pkg.junctions),
lines(pkg.lines), arcs(pkg.arcs), texts(pkg.texts), pads(pkg.pads), polygons(pkg.polygons),
keepouts(pkg.keepouts), dimensions(pkg.dimensions), pictures(pkg.pictures), parameter_set(pkg.parameter_set),
parameter_program(pkg.parameter_program), grid_settings(pkg.grid_settings), models(pkg.models),
default_model(pkg.default_model), alternate_for(pkg.alternate_for), version(pkg.version), warnings(pkg.warnings)
parameters_fixed(pkg.parameters_fixed), parameter_program(pkg.parameter_program),
grid_settings(pkg.grid_settings), models(pkg.models), default_model(pkg.default_model),
alternate_for(pkg.alternate_for), version(pkg.version), warnings(pkg.warnings)
{
update_refs();
}
Expand All @@ -285,6 +292,7 @@ void Package::operator=(Package const &pkg)
dimensions = pkg.dimensions;
pictures = pkg.pictures;
parameter_set = pkg.parameter_set;
parameters_fixed = pkg.parameters_fixed;
parameter_program = pkg.parameter_program;
grid_settings = pkg.grid_settings;
models = pkg.models;
Expand Down Expand Up @@ -324,23 +332,28 @@ void Package::update_refs()
parameter_program.pkg = this;
}

static void copy_param(ParameterSet &dest, const ParameterSet &src, ParameterID id)
static void copy_param(ParameterSet &dest, const ParameterSet &src, const std::set<ParameterID> &parameters_fixed,
ParameterID id)
{
if (src.count(id))
if (src.count(id) && !parameters_fixed.count(id)) {
dest[id] = src.at(id);
}
}

static void copy_param(ParameterSet &dest, const ParameterSet &src, const std::set<ParameterID> &ids)
static void copy_param(ParameterSet &dest, const ParameterSet &src, const std::set<ParameterID> &parameters_fixed,
const std::set<ParameterID> &ids)
{
for (const auto id : ids) {
copy_param(dest, src, id);
copy_param(dest, src, parameters_fixed, id);
}
}

std::optional<std::string> Package::apply_parameter_set(const ParameterSet &ps)
{
auto ps_this = parameter_set;
copy_param(ps_this, ps, ParameterID::COURTYARD_EXPANSION);
copy_param(ps_this, ps, parameters_fixed,
{ParameterID::COURTYARD_EXPANSION, ParameterID::SOLDER_MASK_EXPANSION,
ParameterID::PASTE_MASK_CONTRACTION, ParameterID::HOLE_SOLDER_MASK_EXPANSION});
{
auto r = parameter_program.run(ps_this);
if (r.has_value()) {
Expand All @@ -350,7 +363,7 @@ std::optional<std::string> Package::apply_parameter_set(const ParameterSet &ps)

for (auto &it : pads) {
auto ps_pad = it.second.parameter_set;
copy_param(ps_pad, ps,
copy_param(ps_pad, ps_this, it.second.parameters_fixed,
{ParameterID::SOLDER_MASK_EXPANSION, ParameterID::PASTE_MASK_CONTRACTION,
ParameterID::HOLE_SOLDER_MASK_EXPANSION});
if (auto r = it.second.padstack.apply_parameter_set(ps_pad)) {
Expand Down Expand Up @@ -447,6 +460,9 @@ json Package::serialize() const
j["tags"] = tags;
j["parameter_program"] = parameter_program.get_code();
j["parameter_set"] = parameter_set_serialize(parameter_set);
for (const auto &it : parameters_fixed) {
j["parameters_fixed"].push_back(parameter_id_to_string(it));
}
if (alternate_for && alternate_for->uuid != uuid)
j["alternate_for"] = (std::string)alternate_for->uuid;
j["models"] = json::object();
Expand Down
1 change: 1 addition & 0 deletions src/pool/package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Package : public ObjectProvider, public LayerProvider {
std::map<UUID, Picture> pictures;

ParameterSet parameter_set;
std::set<ParameterID> parameters_fixed;
MyParameterProgram parameter_program;
PackageRules rules;
GridSettings grid_settings;
Expand Down

0 comments on commit 2ca2e96

Please sign in to comment.