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:
parent
d0f21dda4a
commit
d320a03c54
@ -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);
|
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, 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 */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);
|
static bool parse_color(const std::string& scolor, unsigned char* rgb_out);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "wxExtensions.hpp"
|
#include "wxExtensions.hpp"
|
||||||
|
#include "libslic3r/GCode/PreviewData.hpp"
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
#include "GUI_App.hpp"
|
#include "GUI_App.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
@ -322,7 +323,8 @@ 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
|
// 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();
|
post_ticks_changed_event();
|
||||||
|
|
||||||
m_ticks.mode = custom_gcode_per_print_z.mode;
|
if (custom_gcode_per_print_z.mode)
|
||||||
|
m_ticks.mode = custom_gcode_per_print_z.mode;
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
Update();
|
Update();
|
||||||
@ -1169,6 +1171,8 @@ void Control::OnKeyDown(wxKeyEvent &event)
|
|||||||
m_ticks.suppress_minus(true);
|
m_ticks.suppress_minus(true);
|
||||||
delete_current_tick();
|
delete_current_tick();
|
||||||
}
|
}
|
||||||
|
else if (event.GetKeyCode() == WXK_SHIFT)
|
||||||
|
UseDefaultColors(false);
|
||||||
else if (is_horizontal())
|
else if (is_horizontal())
|
||||||
{
|
{
|
||||||
if (key == WXK_LEFT || key == WXK_RIGHT)
|
if (key == WXK_LEFT || key == WXK_RIGHT)
|
||||||
@ -1194,6 +1198,9 @@ void Control::OnKeyUp(wxKeyEvent &event)
|
|||||||
{
|
{
|
||||||
if (event.GetKeyCode() == WXK_CONTROL)
|
if (event.GetKeyCode() == WXK_CONTROL)
|
||||||
m_is_one_layer = false;
|
m_is_one_layer = false;
|
||||||
|
else if (event.GetKeyCode() == WXK_SHIFT)
|
||||||
|
UseDefaultColors(true);
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
Update();
|
Update();
|
||||||
event.Skip();
|
event.Skip();
|
||||||
@ -1278,9 +1285,11 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
|
|||||||
|
|
||||||
// Get used extruders for tick.
|
// Get used extruders for tick.
|
||||||
// Means all extruders(tools) which will be used during printing from current tick to the end
|
// 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
|
// #ys_FIXME: get tool ordering from _correct_ place
|
||||||
const ToolOrdering& tool_ordering = GUI::wxGetApp().plater()->fff_print().get_tool_ordering();
|
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;
|
return used_extruders;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int default_initial_extruder = mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
|
const int default_initial_extruder = e_mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
|
||||||
if (ticks.empty())
|
if (ticks.empty() || e_mode == t_mode::SingleExtruder)
|
||||||
return {default_initial_extruder};
|
return {default_initial_extruder};
|
||||||
|
|
||||||
std::set<int> used_extruders;
|
std::set<int> used_extruders;
|
||||||
@ -1346,10 +1355,13 @@ void Control::OnRightUp(wxMouseEvent& event)
|
|||||||
if (m_show_context_menu) {
|
if (m_show_context_menu) {
|
||||||
wxMenu 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)", "",
|
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
|
||||||
[this](wxCommandEvent&) { add_code_as_tick(ColorChangeCode); }, "colorchange_add_m", &menu,
|
[this](wxCommandEvent&) { add_code_as_tick(ColorChangeCode); }, "colorchange_add_m", &menu,
|
||||||
[](){return true;}, this);
|
[](){return true;}, this);
|
||||||
|
|
||||||
|
UseDefaultColors(false);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
append_change_extruder_menu_item(&menu);
|
append_change_extruder_menu_item(&menu);
|
||||||
@ -1688,9 +1700,18 @@ bool Control::check_ticks_changed_event(const std::string& gcode)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& code, const int extruder)
|
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::vector<std::string> colors = GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||||
std::string color = colors[extruder - 1];
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == t_mode::SingleExtruder)
|
||||||
|
m_use_default_colors = true;
|
||||||
|
|
||||||
ticks.emplace(TickCode{ tick, code, extruder, color });
|
ticks.emplace(TickCode{ tick, code, extruder, color });
|
||||||
return true;
|
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",
|
// We should mark a tick as a "MeaninglessColorChange",
|
||||||
// if it has a ColorChange for unused extruder from current print to end of the print
|
// 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())
|
if (used_extruders_for_tick.find(tick.extruder) == used_extruders_for_tick.end())
|
||||||
return ctMeaninglessColorChange;
|
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",
|
// We should mark a tick as a "MeaninglessToolChange",
|
||||||
// if it has a ToolChange to the same extruder
|
// if it has a ToolChange to the same extruder
|
||||||
|
|
||||||
auto it = ticks.find(tick);
|
auto it = ticks.find(tick);
|
||||||
if (it == ticks.begin())
|
if (it == ticks.begin())
|
||||||
return tick.extruder == std::max<int>(only_extruder, 1) ? ctMeaninglessToolChange : ctNone;
|
return tick.extruder == std::max<int>(only_extruder, 1) ? ctMeaninglessToolChange : ctNone;
|
||||||
|
@ -67,12 +67,14 @@ class TickCodeInfo
|
|||||||
std::string pause_print_msg;
|
std::string pause_print_msg;
|
||||||
bool m_suppress_plus = false;
|
bool m_suppress_plus = false;
|
||||||
bool m_suppress_minus = 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);
|
std::string get_color_for_tick(TickCode tick, const std::string& code, const int extruder);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::set<TickCode> ticks {};
|
std::set<TickCode> ticks {};
|
||||||
t_mode mode = t_mode::SingleExtruder;
|
t_mode mode = t_mode::Undef;
|
||||||
|
|
||||||
bool empty() const { return ticks.empty(); }
|
bool empty() const { return ticks.empty(); }
|
||||||
void set_pause_print_msg(const std::string& message) { pause_print_msg = message; }
|
void set_pause_print_msg(const std::string& message) { pause_print_msg = message; }
|
||||||
@ -88,12 +90,13 @@ public:
|
|||||||
|
|
||||||
// Get used extruders for tick.
|
// Get used extruders for tick.
|
||||||
// Means all extruders(tools) which will be used during printing from current tick to the end
|
// 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_plus (bool suppress) { m_suppress_plus = suppress; }
|
||||||
void suppress_minus(bool suppress) { m_suppress_minus = suppress; }
|
void suppress_minus(bool suppress) { m_suppress_minus = suppress; }
|
||||||
bool suppressed_plus () { return m_suppress_plus; }
|
bool suppressed_plus () { return m_suppress_plus; }
|
||||||
bool suppressed_minus() { return m_suppress_minus; }
|
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 :
|
m_mode = !is_one_extruder_printed_model ? t_mode::MultiExtruder :
|
||||||
only_extruder < 0 ? t_mode::SingleExtruder :
|
only_extruder < 0 ? t_mode::SingleExtruder :
|
||||||
t_mode::MultiAsSingle;
|
t_mode::MultiAsSingle;
|
||||||
|
if (!m_ticks.mode)
|
||||||
|
m_ticks.mode = m_mode;
|
||||||
m_only_extruder = only_extruder;
|
m_only_extruder = only_extruder;
|
||||||
|
|
||||||
|
UseDefaultColors(m_mode == t_mode::SingleExtruder);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
|
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
|
||||||
@ -201,6 +208,7 @@ public:
|
|||||||
void OnLeftUp(wxMouseEvent& event);
|
void OnLeftUp(wxMouseEvent& event);
|
||||||
void OnEnterWin(wxMouseEvent& event) { enter_window(event, true); }
|
void OnEnterWin(wxMouseEvent& event) { enter_window(event, true); }
|
||||||
void OnLeaveWin(wxMouseEvent& event) { enter_window(event, false); }
|
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 OnWheel(wxMouseEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent &event);
|
void OnKeyDown(wxKeyEvent &event);
|
||||||
void OnKeyUp(wxKeyEvent &event);
|
void OnKeyUp(wxKeyEvent &event);
|
||||||
|
@ -591,6 +591,11 @@ void Preview::create_double_slider()
|
|||||||
|
|
||||||
// sizer, m_canvas_widget
|
// sizer, m_canvas_widget
|
||||||
m_canvas_widget->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this);
|
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);
|
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')
|
else if (key == 'S')
|
||||||
m_slider->ChangeOneLayerLock();
|
m_slider->ChangeOneLayerLock();
|
||||||
|
else if (key == WXK_SHIFT)
|
||||||
|
m_slider->UseDefaultColors(false);
|
||||||
else
|
else
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user