DoubleSlider: Added using of default colors for color changes in SingleExtruder Mode (#3449)

+ added missed input parameter to the BitmapCache::mksolid() which was cause a wrong drawing of the Extruder selector under OSX
This commit is contained in:
YuSanka 2020-02-03 21:27:53 +01:00
parent d0f21dda4a
commit d320a03c54
4 changed files with 51 additions and 13 deletions

View File

@ -35,7 +35,7 @@ public:
wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false, const bool dark_mode = false);
/*static */wxBitmap mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency, bool suppress_scaling = false);
/*static */wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3], bool suppress_scaling = false) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE); }
/*static */wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3], bool suppress_scaling = false) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE, suppress_scaling); }
/*static */wxBitmap mkclear(size_t width, size_t height) { return mksolid(width, height, 0, 0, 0, wxALPHA_TRANSPARENT); }
static bool parse_color(const std::string& scolor, unsigned char* rgb_out);

View File

@ -1,4 +1,5 @@
#include "wxExtensions.hpp"
#include "libslic3r/GCode/PreviewData.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "I18N.hpp"
@ -322,6 +323,7 @@ void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
// Switch to the "Feature type"/"Tool" from the very beginning of a new object slicing after deleting of the old one
post_ticks_changed_event();
if (custom_gcode_per_print_z.mode)
m_ticks.mode = custom_gcode_per_print_z.mode;
Refresh();
@ -1169,6 +1171,8 @@ void Control::OnKeyDown(wxKeyEvent &event)
m_ticks.suppress_minus(true);
delete_current_tick();
}
else if (event.GetKeyCode() == WXK_SHIFT)
UseDefaultColors(false);
else if (is_horizontal())
{
if (key == WXK_LEFT || key == WXK_RIGHT)
@ -1194,6 +1198,9 @@ void Control::OnKeyUp(wxKeyEvent &event)
{
if (event.GetKeyCode() == WXK_CONTROL)
m_is_one_layer = false;
else if (event.GetKeyCode() == WXK_SHIFT)
UseDefaultColors(true);
Refresh();
Update();
event.Skip();
@ -1278,9 +1285,11 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
// Get used extruders for tick.
// Means all extruders(tools) which will be used during printing from current tick to the end
std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z) const
std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z, t_mode force_mode/* = t_mode::Undef*/) const
{
if (mode == t_mode::MultiExtruder)
t_mode e_mode = !force_mode ? mode : force_mode;
if (e_mode == t_mode::MultiExtruder)
{
// #ys_FIXME: get tool ordering from _correct_ place
const ToolOrdering& tool_ordering = GUI::wxGetApp().plater()->fff_print().get_tool_ordering();
@ -1301,8 +1310,8 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
return used_extruders;
}
const int default_initial_extruder = mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
if (ticks.empty())
const int default_initial_extruder = e_mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
if (ticks.empty() || e_mode == t_mode::SingleExtruder)
return {default_initial_extruder};
std::set<int> used_extruders;
@ -1346,10 +1355,13 @@ void Control::OnRightUp(wxMouseEvent& event)
if (m_show_context_menu) {
wxMenu menu;
if (m_mode == t_mode::SingleExtruder)
if (m_mode == t_mode::SingleExtruder) {
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
[this](wxCommandEvent&) { add_code_as_tick(ColorChangeCode); }, "colorchange_add_m", &menu,
[](){return true;}, this);
UseDefaultColors(false);
}
else
{
append_change_extruder_menu_item(&menu);
@ -1688,9 +1700,18 @@ bool Control::check_ticks_changed_event(const std::string& gcode)
return true;
}
std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& code, const int extruder)
{
if (mode == t_mode::SingleExtruder && code == ColorChangeCode && m_use_default_colors)
{
const std::vector<std::string>& colors = GCodePreviewData::ColorPrintColors();
if (ticks.empty())
return colors[0];
m_default_color_idx++;
return colors[m_default_color_idx % colors.size()];
}
std::vector<std::string> colors = GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
std::string color = colors[extruder - 1];
@ -1740,6 +1761,9 @@ bool TickCodeInfo::add_tick(const int tick, std::string& code, const int extrude
return false;
}
if (mode == t_mode::SingleExtruder)
m_use_default_colors = true;
ticks.emplace(TickCode{ tick, code, extruder, color });
return true;
}
@ -1840,7 +1864,7 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
{
// We should mark a tick as a "MeaninglessColorChange",
// if it has a ColorChange for unused extruder from current print to end of the print
std::set<int> used_extruders_for_tick = get_used_extruders_for_tick(tick.tick, only_extruder, print_z);
std::set<int> used_extruders_for_tick = get_used_extruders_for_tick(tick.tick, only_extruder, print_z, out_mode);
if (used_extruders_for_tick.find(tick.extruder) == used_extruders_for_tick.end())
return ctMeaninglessColorChange;
@ -1868,7 +1892,6 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
{
// We should mark a tick as a "MeaninglessToolChange",
// if it has a ToolChange to the same extruder
auto it = ticks.find(tick);
if (it == ticks.begin())
return tick.extruder == std::max<int>(only_extruder, 1) ? ctMeaninglessToolChange : ctNone;

View File

@ -67,12 +67,14 @@ class TickCodeInfo
std::string pause_print_msg;
bool m_suppress_plus = false;
bool m_suppress_minus = false;
bool m_use_default_colors= false;
int m_default_color_idx = 0;
std::string get_color_for_tick(TickCode tick, const std::string& code, const int extruder);
public:
std::set<TickCode> ticks {};
t_mode mode = t_mode::SingleExtruder;
t_mode mode = t_mode::Undef;
bool empty() const { return ticks.empty(); }
void set_pause_print_msg(const std::string& message) { pause_print_msg = message; }
@ -88,12 +90,13 @@ public:
// Get used extruders for tick.
// Means all extruders(tools) which will be used during printing from current tick to the end
std::set<int> get_used_extruders_for_tick(int tick, int only_extruder, double print_z) const;
std::set<int> get_used_extruders_for_tick(int tick, int only_extruder, double print_z, t_mode force_mode = t_mode::Undef) const;
void suppress_plus (bool suppress) { m_suppress_plus = suppress; }
void suppress_minus(bool suppress) { m_suppress_minus = suppress; }
bool suppressed_plus () { return m_suppress_plus; }
bool suppressed_minus() { return m_suppress_minus; }
void set_default_colors(bool default_colors_on) { m_use_default_colors = default_colors_on; }
};
@ -186,7 +189,11 @@ public:
m_mode = !is_one_extruder_printed_model ? t_mode::MultiExtruder :
only_extruder < 0 ? t_mode::SingleExtruder :
t_mode::MultiAsSingle;
if (!m_ticks.mode)
m_ticks.mode = m_mode;
m_only_extruder = only_extruder;
UseDefaultColors(m_mode == t_mode::SingleExtruder);
}
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
@ -201,6 +208,7 @@ public:
void OnLeftUp(wxMouseEvent& event);
void OnEnterWin(wxMouseEvent& event) { enter_window(event, true); }
void OnLeaveWin(wxMouseEvent& event) { enter_window(event, false); }
void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); }
void OnWheel(wxMouseEvent& event);
void OnKeyDown(wxKeyEvent &event);
void OnKeyUp(wxKeyEvent &event);

View File

@ -591,6 +591,11 @@ void Preview::create_double_slider()
// sizer, m_canvas_widget
m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this);
m_canvas_widget->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event) {
if (event.GetKeyCode() == WXK_SHIFT)
m_slider->UseDefaultColors(true);
event.Skip();
});
m_slider->Bind(wxEVT_SCROLL_CHANGED, &Preview::on_sliders_scroll_changed, this);
@ -776,6 +781,8 @@ void Preview::update_double_slider_from_canvas(wxKeyEvent& event)
}
else if (key == 'S')
m_slider->ChangeOneLayerLock();
else if (key == WXK_SHIFT)
m_slider->UseDefaultColors(false);
else
event.Skip();
}