OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::IMEXFilamentPickerPopover Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/IMEXFilamentPickerPopover.hpp>

Inheritance diagram for Slic3r::GUI::IMEXFilamentPickerPopover:
Collaboration diagram for Slic3r::GUI::IMEXFilamentPickerPopover:

Public Types

using CommitCallback = std::function<void()>

Public Member Functions

 IMEXFilamentPickerPopover (wxWindow *parent, PartPlate *plate, const ConfigOptionInts &pem, int physical_head, CommitCallback on_commit)
void popup_at_cursor ()

Private Member Functions

void OnDismiss () override
void build_row ()
void on_filament_selected (int slot_1_based)

Private Attributes

PartPlate * m_plate
ConfigOptionInts m_pem
int m_physical_head
CommitCallback m_on_commit
wxSizer * m_root_sizer = nullptr

Detailed Description

Member Typedef Documentation

◆ CommitCallback

Constructor & Destructor Documentation

◆ IMEXFilamentPickerPopover()

Slic3r::GUI::IMEXFilamentPickerPopover::IMEXFilamentPickerPopover ( wxWindow * parent,
PartPlate * plate,
const ConfigOptionInts & pem,
int physical_head,
CommitCallback on_commit )
32 : wxPopupTransientWindow(parent, wxBORDER_SIMPLE)
33 , m_plate(plate)
34 , m_pem(pem)
35 , m_physical_head(physical_head)
36 , m_on_commit(std::move(on_commit))
37{
38 m_root_sizer = new wxBoxSizer(wxHORIZONTAL);
39 SetSizer(m_root_sizer);
40
41 build_row();
42
43 m_root_sizer->SetSizeHints(this);
44 SetClientSize(m_root_sizer->ComputeFittingClientSize(this));
45 Layout();
46}
wxSizer * m_root_sizer
Definition IMEXFilamentPickerPopover.hpp:45
PartPlate * m_plate
Definition IMEXFilamentPickerPopover.hpp:37
ConfigOptionInts m_pem
Definition IMEXFilamentPickerPopover.hpp:41
void build_row()
Definition IMEXFilamentPickerPopover.cpp:62
int m_physical_head
Definition IMEXFilamentPickerPopover.hpp:42
CommitCallback m_on_commit
Definition IMEXFilamentPickerPopover.hpp:43

References build_row(), m_on_commit, m_pem, m_physical_head, m_plate, and m_root_sizer.

Here is the call graph for this function:

Member Function Documentation

◆ build_row()

void Slic3r::GUI::IMEXFilamentPickerPopover::build_row ( )
private
63{
64 m_root_sizer->Clear(true);
65
66 m_root_sizer->AddSpacer(10);
67
68 auto* label = new wxStaticText(this, wxID_ANY,
69 wxString::Format("T%d", m_physical_head));
70 m_root_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, 6);
71
72 m_root_sizer->AddSpacer(10);
73
74 std::vector<int> lane_logicals;
75 for (size_t L = 0; L < m_pem.values.size(); ++L)
76 if (m_pem.values[L] == m_physical_head)
77 lane_logicals.push_back((int)L);
78
79 std::vector<wxBitmap*> bmps = get_extruder_color_icons(false /*thin_icon*/);
80
81 auto* choice = new BitmapComboBox(this, wxID_ANY, wxEmptyString,
82 wxDefaultPosition, wxSize(140, -1),
83 0, nullptr, wxCB_READONLY);
84 const int left_pad_px = 8;
85 auto pad_left = [&](const wxBitmap& src) -> wxBitmap {
86 if (!src.IsOk()) return src;
87 wxImage im(src.GetWidth() + left_pad_px, src.GetHeight());
88 im.InitAlpha();
89 unsigned char* a = im.GetAlpha();
90 std::fill(a, a + im.GetWidth() * im.GetHeight(), (unsigned char)0);
91 wxBitmap out(im);
92 wxMemoryDC dc(out);
93 dc.DrawBitmap(src, left_pad_px, 0, true);
94 dc.SelectObject(wxNullBitmap);
95 return out;
96 };
97
98 for (int L : lane_logicals) {
99 const wxString label = wxString::Format(_L("Filament %d"), L + 1);
100 if (L >= 0 && L < (int)bmps.size() && bmps[L] && bmps[L]->IsOk())
101 choice->Append(label, pad_left(*bmps[L]));
102 else
103 choice->Append(label, wxNullBitmap);
104 }
105
106 const auto map = m_plate->get_imex_head_filament_map();
107 auto it = map.find(m_physical_head);
108 int selected_slot_1based = (it != map.end())
109 ? it->second
110 : (lane_logicals.empty() ? -1 : lane_logicals.front() + 1);
111
112 for (int i = 0; i < (int)lane_logicals.size(); ++i) {
113 if (lane_logicals[i] + 1 == selected_slot_1based) {
114 choice->SetSelection(i);
115 break;
116 }
117 }
118
119 choice->Bind(wxEVT_COMBOBOX, [this, lane_logicals, choice](wxCommandEvent&) {
120 int sel = choice->GetSelection();
121 if (sel < 0 || sel >= (int)lane_logicals.size()) return;
122 on_filament_selected(lane_logicals[sel] + 1);
123 // DismissAndNotify(), not Dismiss(): Dismiss() is only PopHandlers()+Hide() and never
124 // reaches OnDismiss(), so destroying from OnDismiss() would miss this path entirely --
125 // which is the one users take on every successful pick.
126 DismissAndNotify();
127 });
128
129 m_root_sizer->Add(choice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
130 m_root_sizer->AddSpacer(4);
131}
#define L(s)
Definition ExtrusionEntity.cpp:25
#define _L(s)
Definition OBJ.cpp:34
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
void on_filament_selected(int slot_1_based)
Definition IMEXFilamentPickerPopover.cpp:133
std::vector< wxBitmap * > get_extruder_color_icons(bool thin_icon)
Definition wxExtensions.cpp:572

References _L, get_extruder_color_icons(), L, m_pem, m_physical_head, m_plate, m_root_sizer, on_filament_selected(), and wxStaticText.

Referenced by IMEXFilamentPickerPopover().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_filament_selected()

void Slic3r::GUI::IMEXFilamentPickerPopover::on_filament_selected ( int slot_1_based)
private
134{
135 auto map = m_plate->get_imex_head_filament_map();
136 // Erase when the user reselects the pem default for this head, so the 3mf
137 // doesn't carry no-op overrides (same invariant as PR3b).
138 const int default_logical = first_filament_for_physical_head(m_pem, m_physical_head);
139 if (default_logical >= 0 && slot_1_based == default_logical + 1)
140 map.erase(m_physical_head);
141 else
142 map[m_physical_head] = slot_1_based;
143 m_plate->set_imex_head_filament_map(map);
145}
int first_filament_for_physical_head(const ConfigOptionInts &pem, int physical)
Definition IMEXHelpers.cpp:213

References Slic3r::first_filament_for_physical_head(), m_on_commit, m_pem, m_physical_head, and m_plate.

Referenced by build_row().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnDismiss()

void Slic3r::GUI::IMEXFilamentPickerPopover::OnDismiss ( )
overrideprivate
55{
56 wxPopupTransientWindow::OnDismiss();
57 // No CallAfter needed: wxPopupTransientWindowBase::Destroy() already defers by appending to
58 // wxPendingDelete, and guards a second call with a wxCHECK rather than double-freeing.
59 Destroy();
60}

◆ popup_at_cursor()

void Slic3r::GUI::IMEXFilamentPickerPopover::popup_at_cursor ( )
49{
50 Position(wxGetMousePosition(), wxSize(0, 0));
51 Popup();
52}

Member Data Documentation

◆ m_on_commit

CommitCallback Slic3r::GUI::IMEXFilamentPickerPopover::m_on_commit
private

◆ m_pem

ConfigOptionInts Slic3r::GUI::IMEXFilamentPickerPopover::m_pem
private

◆ m_physical_head

int Slic3r::GUI::IMEXFilamentPickerPopover::m_physical_head
private

◆ m_plate

PartPlate* Slic3r::GUI::IMEXFilamentPickerPopover::m_plate
private

◆ m_root_sizer

wxSizer* Slic3r::GUI::IMEXFilamentPickerPopover::m_root_sizer = nullptr
private

The documentation for this class was generated from the following files: