Workaround for extruder editing under OSX

This commit is contained in:
YuSanka 2019-10-02 11:53:50 +02:00
parent a0b46a4019
commit 15902766d0
4 changed files with 77 additions and 1 deletions

View File

@ -788,6 +788,9 @@ void ObjectList::list_manipulation(bool evt_context_menu/* = false*/)
const wxPoint pt = get_mouse_position_in_control(); const wxPoint pt = get_mouse_position_in_control();
HitTest(pt, item, col); HitTest(pt, item, col);
if (m_extruder_editor)
m_extruder_editor->Hide();
/* Note: Under OSX right click doesn't send "selection changed" event. /* Note: Under OSX right click doesn't send "selection changed" event.
* It means that Selection() will be return still previously selected item. * It means that Selection() will be return still previously selected item.
* Thus under OSX we should force UnselectAll(), when item and col are nullptr, * Thus under OSX we should force UnselectAll(), when item and col are nullptr,
@ -836,6 +839,8 @@ void ObjectList::list_manipulation(bool evt_context_menu/* = false*/)
fix_through_netfabb(); fix_through_netfabb();
} }
} }
else if (/*wxOSX &&*/evt_context_menu && title == _("Extruder"))
extruder_editing();
#ifndef __WXMSW__ #ifndef __WXMSW__
GetMainWindow()->SetToolTip(""); // hide tooltip GetMainWindow()->SetToolTip(""); // hide tooltip
@ -877,6 +882,72 @@ void ObjectList::show_context_menu(const bool evt_context_menu)
wxGetApp().plater()->PopupMenu(menu); wxGetApp().plater()->PopupMenu(menu);
} }
void ObjectList::extruder_editing()
{
wxDataViewItem item = GetSelection();
if (!item || !(m_objects_model->GetItemType(item) & (itVolume | itObject)))
return;
std::vector<wxBitmap*> icons = get_extruder_color_icons();
if (icons.empty())
return;
const int column_width = GetColumn(colExtruder)->GetWidth();
wxPoint pos = get_mouse_position_in_control();
pos.y -= 2*GetTextExtent("m").y;
wxWindow* parent = this;//this->GetMainWindow();
if (!m_extruder_editor)
m_extruder_editor = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString,
pos, wxSize(column_width, -1),
0, nullptr, wxCB_READONLY);
else
{
m_extruder_editor->SetPosition(pos);
m_extruder_editor->Clear();
m_extruder_editor->Show();
}
int i = 0;
for (wxBitmap* bmp : icons) {
if (i == 0) {
m_extruder_editor->Append(_(L("default")), *bmp);
++i;
}
m_extruder_editor->Append(wxString::Format("%d", i), *bmp);
++i;
}
m_extruder_editor->SetSelection(m_objects_model->GetExtruderNumber(item));
auto set_extruder = [this, item]()
{
const int selection = m_extruder_editor->GetSelection();
if (selection >= 0)
m_objects_model->SetExtruder(m_extruder_editor->GetString(selection), item);
m_extruder_editor->Hide();
};
// to avoid event propagation to other sidebar items
m_extruder_editor->Bind(wxEVT_COMBOBOX, [set_extruder](wxCommandEvent& evt)
{
set_extruder();
evt.StopPropagation();
});
m_extruder_editor->Bind(wxEVT_KILL_FOCUS, [set_extruder](wxFocusEvent& evt)
{
set_extruder();
evt.Skip();
});
}
void ObjectList::copy() void ObjectList::copy()
{ {
// if (m_selection_mode & smLayer) // if (m_selection_mode & smLayer)

View File

@ -140,6 +140,8 @@ private:
DynamicPrintConfig *m_config {nullptr}; DynamicPrintConfig *m_config {nullptr};
std::vector<ModelObject*> *m_objects{ nullptr }; std::vector<ModelObject*> *m_objects{ nullptr };
wxBitmapComboBox *m_extruder_editor { nullptr };
std::vector<wxBitmap*> m_bmp_vector; std::vector<wxBitmap*> m_bmp_vector;
t_layer_config_ranges m_layer_config_ranges_cache; t_layer_config_ranges m_layer_config_ranges_cache;
@ -210,6 +212,7 @@ public:
void selection_changed(); void selection_changed();
void show_context_menu(const bool evt_context_menu); void show_context_menu(const bool evt_context_menu);
void extruder_editing();
#ifndef __WXOSX__ #ifndef __WXOSX__
void key_event(wxKeyEvent& event); void key_event(wxKeyEvent& event);
#endif /* __WXOSX__ */ #endif /* __WXOSX__ */

View File

@ -449,7 +449,7 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr; Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
static std::vector<wxBitmap*> get_extruder_color_icons() /*static*/ std::vector<wxBitmap*> get_extruder_color_icons()
{ {
// Create the bitmap with color bars. // Create the bitmap with color bars.
std::vector<wxBitmap*> bmps; std::vector<wxBitmap*> bmps;

View File

@ -55,6 +55,8 @@ int em_unit(wxWindow* win);
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name,
const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false); const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false);
std::vector<wxBitmap*> get_extruder_color_icons();
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
{ {
static const unsigned int DefaultWidth; static const unsigned int DefaultWidth;