Refactoring of DoubleSlider::add_code()

This commit is contained in:
YuSanka 2020-01-16 10:20:36 +01:00
parent 15f873dd74
commit 8ef29aab78

View file

@ -3652,28 +3652,31 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
// if on this Z doesn't exist tick // if on this Z doesn't exist tick
auto it = m_ticks.find(TICK_CODE{ tick }); auto it = m_ticks.find(TICK_CODE{ tick });
if (it == m_ticks.end()) if (it != m_ticks.end())
{ return;
std::string color = "";
std::string color;
const int extruder = selected_extruder > 0 ? selected_extruder : std::max<int>(1, m_only_extruder);
if (code == Slic3r::ColorChangeCode) if (code == Slic3r::ColorChangeCode)
{ {
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config(); std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
if (m_ticks.empty()) if (m_ticks.empty())
color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max<int>(1, m_only_extruder)-1]; color = colors[extruder-1];
else else
{ {
auto before_tick_it = std::lower_bound(m_ticks.begin(), m_ticks.end(), TICK_CODE{ tick }); auto before_tick_it = std::lower_bound(m_ticks.begin(), m_ticks.end(), TICK_CODE{ tick });
while (before_tick_it != m_ticks.begin()) { while (before_tick_it != m_ticks.begin()) {
--before_tick_it; --before_tick_it;
if (before_tick_it->gcode == Slic3r::ColorChangeCode && before_tick_it->extruder == selected_extruder) { if (before_tick_it->gcode == Slic3r::ColorChangeCode && before_tick_it->extruder == extruder) {
color = before_tick_it->color; color = before_tick_it->color;
break; break;
} }
} }
if (color.empty()) if (color.empty())
color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max<int>(1, m_only_extruder) - 1]; color = colors[extruder-1];
} }
color = get_new_color(color); color = get_new_color(color);
@ -3698,21 +3701,12 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
m_custom_gcode = code; m_custom_gcode = code;
} }
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}); m_ticks.emplace(TICK_CODE{tick, code, extruder, color});
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh(); Refresh();
Update(); Update();
} }
}
void DoubleSlider::edit_tick() void DoubleSlider::edit_tick()
{ {