Refactoring of DoubleSlider::add_code()
This commit is contained in:
parent
15f873dd74
commit
8ef29aab78
1 changed files with 45 additions and 51 deletions
|
@ -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;
|
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;
|
||||||
|
const int extruder = selected_extruder > 0 ? selected_extruder : std::max<int>(1, m_only_extruder);
|
||||||
|
|
||||||
|
if (code == Slic3r::ColorChangeCode)
|
||||||
{
|
{
|
||||||
std::string color = "";
|
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||||
if (code == Slic3r::ColorChangeCode)
|
|
||||||
|
if (m_ticks.empty())
|
||||||
|
color = colors[extruder-1];
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
auto before_tick_it = std::lower_bound(m_ticks.begin(), m_ticks.end(), TICK_CODE{ tick });
|
||||||
|
while (before_tick_it != m_ticks.begin()) {
|
||||||
if (m_ticks.empty())
|
--before_tick_it;
|
||||||
color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max<int>(1, m_only_extruder)-1];
|
if (before_tick_it->gcode == Slic3r::ColorChangeCode && before_tick_it->extruder == extruder) {
|
||||||
else
|
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 == selected_extruder) {
|
|
||||||
color = before_tick_it->color;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color.empty())
|
|
||||||
color = colors[selected_extruder > 0 ? selected_extruder - 1 : std::max<int>(1, m_only_extruder) - 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
color = get_new_color(color);
|
|
||||||
if (color.empty())
|
if (color.empty())
|
||||||
return;
|
color = colors[extruder-1];
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int extruder = 1;
|
color = get_new_color(color);
|
||||||
if (m_mode != mmSingleExtruder) {
|
if (color.empty())
|
||||||
if (code == Slic3r::ColorChangeCode && selected_extruder >= 0)
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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()
|
void DoubleSlider::edit_tick()
|
||||||
|
|
Loading…
Reference in a new issue