From 8ef29aab78ebbf862914eff14b5e111a4b065e9a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 16 Jan 2020 10:20:36 +0100 Subject: [PATCH] Refactoring of DoubleSlider::add_code() --- src/slic3r/GUI/wxExtensions.cpp | 96 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 8e1cd0c6f..f2fed3bf7 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -3652,66 +3652,60 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/) const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; // if on this Z doesn't exist tick auto it = m_ticks.find(TICK_CODE{ tick }); - if (it == m_ticks.end()) + if (it != m_ticks.end()) + return; + + std::string color; + const int extruder = selected_extruder > 0 ? selected_extruder : std::max(1, m_only_extruder); + + if (code == Slic3r::ColorChangeCode) { - std::string color = ""; - if (code == Slic3r::ColorChangeCode) + std::vector colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config(); + + if (m_ticks.empty()) + color = colors[extruder-1]; + else { - std::vector colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config(); - - if (m_ticks.empty()) - color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max(1, m_only_extruder)-1]; - else - { - auto before_tick_it = std::lower_bound(m_ticks.begin(), m_ticks.end(), TICK_CODE{ tick }); - while (before_tick_it != m_ticks.begin()) { - --before_tick_it; - if (before_tick_it->gcode == Slic3r::ColorChangeCode && before_tick_it->extruder == selected_extruder) { - color = before_tick_it->color; - break; - } + auto before_tick_it = std::lower_bound(m_ticks.begin(), m_ticks.end(), TICK_CODE{ tick }); + while (before_tick_it != m_ticks.begin()) { + --before_tick_it; + if (before_tick_it->gcode == Slic3r::ColorChangeCode && before_tick_it->extruder == extruder) { + color = before_tick_it->color; + break; } - - if (color.empty()) - color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max(1, m_only_extruder) - 1]; } - color = get_new_color(color); if (color.empty()) - return; - } - else if (code == Slic3r::PausePrintCode) - { - /* PausePrintCode doesn't need a color, so - * this field is used for save a short message shown on Printer display - * */ - color = get_pause_print_msg(m_pause_print_msg, m_values[tick]); - if (color.empty()) - return; - m_pause_print_msg = color; - } - else if (code.empty()) - { - code = get_custom_code(m_custom_gcode, m_values[tick]); - if (code.empty()) - return; - m_custom_gcode = code; + color = colors[extruder-1]; } - int extruder = 1; - if (m_mode != mmSingleExtruder) { - if (code == Slic3r::ColorChangeCode && selected_extruder >= 0) - extruder = selected_extruder; - else - extruder = get_extruder_for_tick(m_selection == ssLower ? m_lower_value : m_higher_value); - } - - m_ticks.emplace(TICK_CODE{tick, code, extruder, color}); - - wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); - Refresh(); - Update(); + color = get_new_color(color); + if (color.empty()) + return; } + else if (code == Slic3r::PausePrintCode) + { + /* PausePrintCode doesn't need a color, so + * this field is used for save a short message shown on Printer display + * */ + color = get_pause_print_msg(m_pause_print_msg, m_values[tick]); + if (color.empty()) + return; + m_pause_print_msg = color; + } + else if (code.empty()) + { + code = get_custom_code(m_custom_gcode, m_values[tick]); + if (code.empty()) + return; + m_custom_gcode = code; + } + + m_ticks.emplace(TICK_CODE{tick, code, extruder, color}); + + wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); + Refresh(); + Update(); } void DoubleSlider::edit_tick()