Skip to content

Commit

Permalink
part wizard: show package preview
Browse files Browse the repository at this point in the history
closes #566
  • Loading branch information
carrotIndustries committed Feb 9, 2021
1 parent 781301f commit 18e1299
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 227 deletions.
8 changes: 1 addition & 7 deletions src/canvas/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,20 +1210,14 @@ void Canvas::render(const Package &pkg, bool interactive, bool smashed, bool omi
object_ref_pop();
}
}
else if (interactive) {
else {
for (const auto &it : pkg.pads) {
object_ref_push(ObjectType::PAD, it.second.uuid);
render_pad_overlay(it.second);
render(it.second);
object_ref_pop();
}
}
else {
for (const auto &it : pkg.pads) {
render_pad_overlay(it.second);
render(it.second);
}
}
for (const auto &it : pkg.polygons) {
if (omit_silkscreen && BoardLayers::is_silkscreen(it.second.layer))
continue;
Expand Down
5 changes: 4 additions & 1 deletion src/pool-prj-mgr/pool-mgr/part_wizard/pad_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class PadEditor : public Gtk::Box {
PadEditor(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &x, const class Pad *p, class PartWizard *pa);
static PadEditor *create(const class Pad *p, PartWizard *pa);
std::string get_gate_name();

const std::set<const Pad *> get_pads() const
{
return pads;
}

private:
class PartWizard *parent;
Expand Down
37 changes: 36 additions & 1 deletion src/pool-prj-mgr/pool-mgr/part_wizard/part_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "widgets/tag_entry.hpp"
#include "widgets/pool_browser_package.hpp"
#include "widgets/preview_canvas.hpp"
#include "canvas/canvas_gl.hpp"

namespace horizon {
LocationEntry *PartWizard::pack_location_entry(const Glib::RefPtr<Gtk::Builder> &x, const std::string &w,
Expand Down Expand Up @@ -77,6 +78,39 @@ PartWizard::PartWizard(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder>
x->get_widget("part_autofill", part_autofill_button);
x->get_widget("steps_grid", steps_grid);

{
Gtk::Box *canvas_box;
GET_WIDGET(canvas_box);
canvas = Gtk::manage(new PreviewCanvas(pool, true));
canvas->show();
canvas->signal_size_allocate().connect([this](const auto &alloc) {
if (!(alloc == canvas_alloc)) {
float pad = 1_mm;
auto bb = pad_bbox(canvas->get_canvas().get_bbox(true), pad);
canvas->get_canvas().zoom_to_bbox(bb);
canvas_alloc = alloc;
}
});
canvas_box->pack_start(*canvas, true, true, 0);
}

pads_lb->signal_selected_rows_changed().connect([this] {
std::set<UUID> pads_selected;
for (auto row : pads_lb->get_selected_rows()) {
auto ed = dynamic_cast<PadEditor *>(row->get_child());
for (auto pad : ed->get_pads()) {
pads_selected.insert(pad->uuid);
}
}
auto &ca = canvas->get_canvas();
ca.set_flags_all(0, TriangleInfo::FLAG_HIGHLIGHT);
ca.set_highlight_enabled(pads_selected.size());
for (const auto &it : pads_selected) {
ObjectRef ref(ObjectType::PAD, it);
ca.set_flags(ref, TriangleInfo::FLAG_HIGHLIGHT, 0);
}
});

entry_add_sanitizer(entity_name_entry);
entry_add_sanitizer(entity_prefix_entry);
entry_add_sanitizer(part_mpn_entry);
Expand Down Expand Up @@ -229,7 +263,7 @@ void PartWizard::set_mode(PartWizard::Mode mo)

if (mo == Mode::ASSIGN) {
stack->set_visible_child("assign");
header->set_subtitle("Assign pins");
header->set_subtitle("Assign pins to package " + pkg->name);
}
else if (mo == Mode::EDIT) {
prepare_edit();
Expand Down Expand Up @@ -271,6 +305,7 @@ void PartWizard::handle_select()
if (p) {
set_pkg(pool.get_package(p));
set_mode(Mode::ASSIGN);
canvas->load(ObjectType::PACKAGE, pkg->uuid);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/pool-prj-mgr/pool-mgr/part_wizard/part_wizard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class PartWizard : public Gtk::Window {
Gtk::Button *button_select = nullptr;
Gtk::Stack *stack = nullptr;
class PoolBrowserPackage *browser_package = nullptr;
class PreviewCanvas *canvas = nullptr;
Gtk::Allocation canvas_alloc;

Gtk::ListBox *pads_lb = nullptr;
Gtk::ToolButton *button_link_pads = nullptr;
Expand Down
Loading

0 comments on commit 18e1299

Please sign in to comment.