Code refactoring to mode comparison

This commit is contained in:
YuSanka 2020-01-17 11:38:52 +01:00
parent cc19e9c48f
commit 2259f7b3e8
10 changed files with 126 additions and 93 deletions

View file

@ -1738,7 +1738,7 @@ namespace ProcessLayer
if (custom_gcode != nullptr) { if (custom_gcode != nullptr) {
// Extruder switches are processed by LayerTools, they should be filtered out. // Extruder switches are processed by LayerTools, they should be filtered out.
assert(custom_gcode->gcode != ExtruderChangeCode); assert(custom_gcode->gcode != ToolChangeCode);
const std::string &custom_code = custom_gcode->gcode; const std::string &custom_code = custom_gcode->gcode;
std::string pause_print_msg; std::string pause_print_msg;

View file

@ -478,7 +478,7 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
for (unsigned int i : lt.extruders) for (unsigned int i : lt.extruders)
extruder_printing_above[i] = true; extruder_printing_above[i] = true;
// Skip all custom G-codes above this layer and skip all extruder switches. // Skip all custom G-codes above this layer and skip all extruder switches.
for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && (custom_gcode_it->print_z > lt.print_z + EPSILON || custom_gcode_it->gcode == ExtruderChangeCode); ++ custom_gcode_it); for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && (custom_gcode_it->print_z > lt.print_z + EPSILON || custom_gcode_it->gcode == ToolChangeCode); ++ custom_gcode_it);
if (custom_gcode_it == custom_gcode_per_print_z.gcodes.rend()) if (custom_gcode_it == custom_gcode_per_print_z.gcodes.rend())
// Custom G-codes were processed. // Custom G-codes were processed.
break; break;

View file

@ -13,7 +13,7 @@ namespace Slic3r {
// Additional Codes which can be set by user using DoubleSlider // Additional Codes which can be set by user using DoubleSlider
static constexpr char ColorChangeCode[] = "M600"; static constexpr char ColorChangeCode[] = "M600";
static constexpr char PausePrintCode[] = "M601"; static constexpr char PausePrintCode[] = "M601";
static constexpr char ExtruderChangeCode[] = "tool_change"; static constexpr char ToolChangeCode[] = "tool_change";
class GCodeWriter { class GCodeWriter {
public: public:

View file

@ -1847,7 +1847,7 @@ std::vector<std::pair<double, unsigned int>> custom_tool_changes(const Model &mo
{ {
std::vector<std::pair<double, unsigned int>> custom_tool_changes; std::vector<std::pair<double, unsigned int>> custom_tool_changes;
for (const Model::CustomGCode &custom_gcode : model.custom_gcode_per_print_z.gcodes) for (const Model::CustomGCode &custom_gcode : model.custom_gcode_per_print_z.gcodes)
if (custom_gcode.gcode == ExtruderChangeCode) { if (custom_gcode.gcode == ToolChangeCode) {
// If extruder count in PrinterSettings was changed, use default (0) extruder for extruders, more than num_extruders // If extruder count in PrinterSettings was changed, use default (0) extruder for extruders, more than num_extruders
custom_tool_changes.emplace_back(custom_gcode.print_z, static_cast<unsigned int>(custom_gcode.extruder > num_extruders ? 1 : custom_gcode.extruder)); custom_tool_changes.emplace_back(custom_gcode.print_z, static_cast<unsigned int>(custom_gcode.extruder > num_extruders ? 1 : custom_gcode.extruder));
} }

View file

@ -763,8 +763,9 @@ public:
double print_z; double print_z;
std::string gcode; std::string gcode;
int extruder; // 0 - "gcode" will be applied for whole print int extruder; // Informative value for ColorChangeCode and ToolChangeCode
// else - "gcode" will be applied only for "extruder" print // "gcode" == ColorChangeCode => M600 will be applied for "extruder" extruder
// "gcode" == ToolChangeCode => for whole print tool will be switched to "extruder" extruder
std::string color; // if gcode is equal to PausePrintCode, std::string color; // if gcode is equal to PausePrintCode,
// this field is used for save a short message shown on Printer display // this field is used for save a short message shown on Printer display
}; };

View file

@ -493,18 +493,18 @@ static bool layer_height_ranges_equal(const t_layer_config_ranges &lr1, const t_
return true; return true;
} }
// Returns true if va == vb when all CustomGCode items that are not ExtruderChangeCode are ignored. // Returns true if va == vb when all CustomGCode items that are not ToolChangeCode are ignored.
static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Model::CustomGCode> &va, const std::vector<Model::CustomGCode> &vb) static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Model::CustomGCode> &va, const std::vector<Model::CustomGCode> &vb)
{ {
auto it_a = va.begin(); auto it_a = va.begin();
auto it_b = vb.begin(); auto it_b = vb.begin();
while (it_a != va.end() && it_b != vb.end()) { while (it_a != va.end() && it_b != vb.end()) {
if (it_a != va.end() && it_a->gcode != ExtruderChangeCode) { if (it_a != va.end() && it_a->gcode != ToolChangeCode) {
// Skip any CustomGCode items, which are not tool changes. // Skip any CustomGCode items, which are not tool changes.
++ it_a; ++ it_a;
continue; continue;
} }
if (it_b != vb.end() && it_b->gcode != ExtruderChangeCode) { if (it_b != vb.end() && it_b->gcode != ToolChangeCode) {
// Skip any CustomGCode items, which are not tool changes. // Skip any CustomGCode items, which are not tool changes.
++ it_b; ++ it_b;
continue; continue;
@ -512,8 +512,8 @@ static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Model
if (it_a == va.end() || it_b == vb.end()) if (it_a == va.end() || it_b == vb.end())
// va or vb contains more Tool Changes than the other. // va or vb contains more Tool Changes than the other.
return true; return true;
assert(it_a->gcode == ExtruderChangeCode); assert(it_a->gcode == ToolChangeCode);
assert(it_b->gcode == ExtruderChangeCode); assert(it_b->gcode == ToolChangeCode);
if (*it_a != *it_b) if (*it_a != *it_b)
// The two Tool Changes differ. // The two Tool Changes differ.
return true; return true;

View file

@ -5263,11 +5263,11 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
const std::string& code = it->gcode; const std::string& code = it->gcode;
// pause print or custom Gcode // pause print or custom Gcode
if (code == PausePrintCode || if (code == PausePrintCode ||
(code != ColorChangeCode && code != ExtruderChangeCode)) (code != ColorChangeCode && code != ToolChangeCode))
return number_tools()-1; // last color item is a gray color for pause print or custom G-code return number_tools()-1; // last color item is a gray color for pause print or custom G-code
// change tool (extruder) // change tool (extruder)
if (code == ExtruderChangeCode) if (code == ToolChangeCode)
return get_color_idx_for_tool_change(it, extruder); return get_color_idx_for_tool_change(it, extruder);
// change color for current extruder // change color for current extruder
if (code == ColorChangeCode) { if (code == ColorChangeCode) {
@ -5289,7 +5289,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
return color_idx; return color_idx;
} }
// change tool (extruder) // change tool (extruder)
if (it->gcode == ExtruderChangeCode) if (it->gcode == ToolChangeCode)
return get_color_idx_for_tool_change(it, extruder); return get_color_idx_for_tool_change(it, extruder);
} }
@ -5333,7 +5333,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
bool is_tool_change = false; bool is_tool_change = false;
while (it_n != color_print_values->begin()) { while (it_n != color_print_values->begin()) {
--it_n; --it_n;
if (it_n->gcode == ExtruderChangeCode) { if (it_n->gcode == ToolChangeCode) {
is_tool_change = true; is_tool_change = true;
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder)) if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder))
return get_m600_color_idx(it); return get_m600_color_idx(it);

View file

@ -597,7 +597,7 @@ void Preview::create_double_slider()
Bind(wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) { Bind(wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) {
Model& model = wxGetApp().plater()->model(); Model& model = wxGetApp().plater()->model();
model.custom_gcode_per_print_z.gcodes = m_slider->GetTicksValues(); model.custom_gcode_per_print_z = m_slider->GetTicksValues();
m_schedule_background_process(); m_schedule_background_process();
update_view_type(false); update_view_type(false);
@ -666,8 +666,11 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min(); bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min();
bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max(); bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max();
std::vector<Model::CustomGCode> &ticks_from_model = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes; // Detect and set manipulation mode for double slider
check_slider_values(ticks_from_model, layers_z); update_double_slider_mode();
Model::CustomGCodeInfo &ticks_info_from_model = wxGetApp().plater()->model().custom_gcode_per_print_z;
check_slider_values(ticks_info_from_model.gcodes, layers_z);
m_slider->SetSliderValues(layers_z); m_slider->SetSliderValues(layers_z);
assert(m_slider->GetMinValue() == 0); assert(m_slider->GetMinValue() == 0);
@ -689,13 +692,9 @@ void Preview::update_double_slider(const std::vector<double>& layers_z, bool kee
} }
m_slider->SetSelectionSpan(idx_low, idx_high); m_slider->SetSelectionSpan(idx_low, idx_high);
m_slider->SetTicksValues(ticks_from_model); m_slider->SetTicksValues(ticks_info_from_model);
bool color_print_enable = (wxGetApp().plater()->printer_technology() == ptFFF); m_slider->EnableTickManipulation(wxGetApp().plater()->printer_technology() == ptFFF);
m_slider->EnableTickManipulation(color_print_enable);
// Detect and set manipulation mode for double slider
update_double_slider_mode();
} }
void Preview::update_double_slider_mode() void Preview::update_double_slider_mode()

View file

@ -2532,9 +2532,10 @@ double DoubleSlider::get_double_value(const SelectedSlider& selection)
} }
using t_custom_code = Slic3r::Model::CustomGCode; using t_custom_code = Slic3r::Model::CustomGCode;
std::vector<t_custom_code> DoubleSlider::GetTicksValues() const Slic3r::Model::CustomGCodeInfo DoubleSlider::GetTicksValues() const
{ {
std::vector<t_custom_code> values; Slic3r::Model::CustomGCodeInfo custom_gcode_per_print_z;
std::vector<t_custom_code>& values = custom_gcode_per_print_z.gcodes;
const int val_size = m_values.size(); const int val_size = m_values.size();
if (!m_values.empty()) if (!m_values.empty())
@ -2544,17 +2545,23 @@ std::vector<t_custom_code> DoubleSlider::GetTicksValues() const
values.emplace_back(t_custom_code{m_values[tick.tick], tick.gcode, tick.extruder, tick.color}); values.emplace_back(t_custom_code{m_values[tick.tick], tick.gcode, tick.extruder, tick.color});
} }
return values; custom_gcode_per_print_z.mode = m_mode;
return custom_gcode_per_print_z;
} }
void DoubleSlider::SetTicksValues(const std::vector<t_custom_code>& heights) void DoubleSlider::SetTicksValues(const Slic3r::Model::CustomGCodeInfo& custom_gcode_per_print_z)
{ {
if (m_values.empty()) if (m_values.empty())
{
m_ticks_mode = m_mode;
return; return;
}
const bool was_empty = m_ticks.empty(); const bool was_empty = m_ticks.empty();
m_ticks.clear(); m_ticks.clear();
const std::vector<t_custom_code>& heights = custom_gcode_per_print_z.gcodes;
for (auto h : heights) { for (auto h : heights) {
auto it = std::lower_bound(m_values.begin(), m_values.end(), h.print_z - epsilon()); auto it = std::lower_bound(m_values.begin(), m_values.end(), h.print_z - epsilon());
@ -2566,7 +2573,9 @@ void DoubleSlider::SetTicksValues(const std::vector<t_custom_code>& heights)
if (!was_empty && m_ticks.empty()) if (!was_empty && m_ticks.empty())
// 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
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event();
m_ticks_mode = custom_gcode_per_print_z.mode;
Refresh(); Refresh();
Update(); Update();
@ -2793,7 +2802,7 @@ void DoubleSlider::draw_ticks(wxDC& dc)
dc.DrawLine(mid + 14, pos/* - 1*/, mid + 9, pos/* - 1*/); dc.DrawLine(mid + 14, pos/* - 1*/, mid + 9, pos/* - 1*/);
// Draw icon for "Pause print" or "Custom Gcode" // Draw icon for "Pause print" or "Custom Gcode"
if (tick.gcode != Slic3r::ColorChangeCode && tick.gcode != Slic3r::ExtruderChangeCode) if (tick.gcode != Slic3r::ColorChangeCode && tick.gcode != Slic3r::ToolChangeCode)
{ {
wxBitmap icon = create_scaled_bitmap(this, tick.gcode == Slic3r::PausePrintCode ? "pause_print" : "edit_gcode"); wxBitmap icon = create_scaled_bitmap(this, tick.gcode == Slic3r::PausePrintCode ? "pause_print" : "edit_gcode");
@ -2827,7 +2836,7 @@ std::string DoubleSlider::get_color_for_color_change_tick(std::set<TICK_CODE>::c
bool is_tool_change = false; bool is_tool_change = false;
while (it_n != m_ticks.begin()) { while (it_n != m_ticks.begin()) {
--it_n; --it_n;
if (it_n->gcode == Slic3r::ExtruderChangeCode) { if (it_n->gcode == Slic3r::ToolChangeCode) {
is_tool_change = true; is_tool_change = true;
if (it_n->extruder == it->extruder) if (it_n->extruder == it->extruder)
return it->color; return it->color;
@ -2863,28 +2872,28 @@ void DoubleSlider::draw_colored_band(wxDC& dc)
}; };
// don't color a band for MultiExtruder mode // don't color a band for MultiExtruder mode
if (m_ticks.empty() || m_mode == mmMultiExtruder) if (m_ticks.empty() || m_mode == t_mode::MultiExtruder)
{ {
draw_band(dc, GetParent()->GetBackgroundColour(), main_band); draw_band(dc, GetParent()->GetBackgroundColour(), main_band);
return; return;
} }
const int default_color_idx = m_mode==mmMultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0; const int default_color_idx = m_mode==t_mode::MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
draw_band(dc, wxColour(Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config()[default_color_idx]), main_band); draw_band(dc, wxColour(Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config()[default_color_idx]), main_band);
std::set<TICK_CODE>::const_iterator tick_it = m_ticks.begin(); std::set<TICK_CODE>::const_iterator tick_it = m_ticks.begin();
while (tick_it != m_ticks.end()) while (tick_it != m_ticks.end())
{ {
if ( (m_mode == mmSingleExtruder && tick_it->gcode == Slic3r::ColorChangeCode ) || if ( (m_mode == t_mode::SingleExtruder && tick_it->gcode == Slic3r::ColorChangeCode ) ||
(m_mode == mmMultiAsSingle && (tick_it->gcode == Slic3r::ExtruderChangeCode || tick_it->gcode == Slic3r::ColorChangeCode)) ) (m_mode == t_mode::MultiAsSingle && (tick_it->gcode == Slic3r::ToolChangeCode || tick_it->gcode == Slic3r::ColorChangeCode)) )
{ {
const wxCoord pos = get_position_from_value(tick_it->tick); const wxCoord pos = get_position_from_value(tick_it->tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) : is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos - 1); main_band.SetBottom(pos - 1);
const std::string clr_str = m_mode == mmSingleExtruder ? tick_it->color : const std::string clr_str = m_mode == t_mode::SingleExtruder ? tick_it->color :
tick_it->gcode == Slic3r::ExtruderChangeCode ? tick_it->gcode == Slic3r::ToolChangeCode ?
get_color_for_tool_change_tick(tick_it) : get_color_for_tool_change_tick(tick_it) :
get_color_for_color_change_tick(tick_it); get_color_for_color_change_tick(tick_it);
@ -2934,7 +2943,7 @@ void DoubleSlider::draw_revert_icon(wxDC& dc)
void DoubleSlider::draw_cog_icon(wxDC& dc) void DoubleSlider::draw_cog_icon(wxDC& dc)
{ {
if (m_mode != mmMultiExtruder) if (m_mode != t_mode::MultiExtruder)
return; return;
int width, height; int width, height;
@ -3046,9 +3055,9 @@ void DoubleSlider::OnLeftDown(wxMouseEvent& event)
if (!m_selection) m_selection = ssHigher; if (!m_selection) m_selection = ssHigher;
m_ticks.clear(); m_ticks.clear();
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event();
} }
else if (is_point_in_rect(pos, m_rect_cog_icon) && m_mode == mmMultiExtruder) { else if (is_point_in_rect(pos, m_rect_cog_icon) && m_mode == t_mode::MultiExtruder) {
// show dialog for set extruder sequence // show dialog for set extruder sequence
m_edit_extruder_sequence = true; m_edit_extruder_sequence = true;
} }
@ -3119,17 +3128,17 @@ wxString DoubleSlider::get_tooltip(IconFocus icon_focus)
{ {
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
const auto tick_code_it = m_ticks.find(TICK_CODE{tick}); const auto tick_code_it = m_ticks.find(TICK_CODE{tick});
tooltip = tick_code_it == m_ticks.end() ? (m_mode == mmMultiAsSingle ? tooltip = tick_code_it == m_ticks.end() ? (m_mode == t_mode::MultiAsSingle ?
_(L("For add change extruder use left mouse button click")) : _(L("For add change extruder use left mouse button click")) :
_(L("For add color change use left mouse button click")) ) + "\n" + _(L("For add color change use left mouse button click")) ) + "\n" +
_(L("For add another code use right mouse button click")) : _(L("For add another code use right mouse button click")) :
tick_code_it->gcode == Slic3r::ColorChangeCode ? ( m_mode == mmSingleExtruder ? tick_code_it->gcode == Slic3r::ColorChangeCode ? ( m_mode == t_mode::SingleExtruder ?
_(L("For Delete color change use left mouse button click\n" _(L("For Delete color change use left mouse button click\n"
"For Edit color use right mouse button click")) : "For Edit color use right mouse button click")) :
from_u8((boost::format(_utf8(L("Delete color change for Extruder %1%"))) % tick_code_it->extruder).str()) ): from_u8((boost::format(_utf8(L("Delete color change for Extruder %1%"))) % tick_code_it->extruder).str()) ):
tick_code_it->gcode == Slic3r::PausePrintCode ? tick_code_it->gcode == Slic3r::PausePrintCode ?
_(L("Delete pause")) : _(L("Delete pause")) :
tick_code_it->gcode == Slic3r::ExtruderChangeCode ? tick_code_it->gcode == Slic3r::ToolChangeCode ?
from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) : from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) :
from_u8((boost::format(_utf8(L("For Delete \"%1%\" code use left mouse button click\n" from_u8((boost::format(_utf8(L("For Delete \"%1%\" code use left mouse button click\n"
"For Edit \"%1%\" code use right mouse button click"))) % tick_code_it->gcode ).str()); "For Edit \"%1%\" code use right mouse button click"))) % tick_code_it->gcode ).str());
@ -3200,7 +3209,7 @@ void DoubleSlider::append_change_extruder_menu_item(wxMenu* menu)
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) + const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
(is_active_extruder ? " (" + _(L("active")) + ")" : ""); (is_active_extruder ? " (" + _(L("active")) + ")" : "");
if (m_mode == mmMultiAsSingle) if (m_mode == t_mode::MultiAsSingle)
append_menu_item(change_extruder_menu, wxID_ANY, item_name, "", append_menu_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { change_extruder(i); }, "", menu, [this, i](wxCommandEvent&) { change_extruder(i); }, "", menu,
[is_active_extruder]() { return !is_active_extruder; }, Slic3r::GUI::wxGetApp().plater()); [is_active_extruder]() { return !is_active_extruder; }, Slic3r::GUI::wxGetApp().plater());
@ -3208,13 +3217,13 @@ void DoubleSlider::append_change_extruder_menu_item(wxMenu* menu)
// [this, i](wxCommandEvent&) { change_extruder(i); }, menu)->Check(i == initial_extruder); // [this, i](wxCommandEvent&) { change_extruder(i); }, menu)->Check(i == initial_extruder);
} }
const wxString change_extruder_menu_name = m_mode == mmMultiAsSingle ? _(L("Change extruder")) : _(L("Change extruder (N/A)")); const wxString change_extruder_menu_name = m_mode == t_mode::MultiAsSingle ? _(L("Change extruder")) : _(L("Change extruder (N/A)"));
wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder"))); wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder")));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(this, "change_extruder")); change_extruder_menu_item->SetBitmap(create_scaled_bitmap(this, "change_extruder"));
Slic3r::GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) { Slic3r::GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) {
enable_menu_item(evt, [this]() {return m_mode == mmMultiAsSingle; }, change_extruder_menu_item, this); }, enable_menu_item(evt, [this]() {return m_mode == t_mode::MultiAsSingle; }, change_extruder_menu_item, this); },
change_extruder_menu_item->GetId()); change_extruder_menu_item->GetId());
} }
} }
@ -3255,13 +3264,13 @@ void DoubleSlider::OnLeftUp(wxMouseEvent& event)
if (m_show_context_menu) if (m_show_context_menu)
{ {
if (m_mode == mmSingleExtruder) if (m_mode == t_mode::SingleExtruder)
add_code(Slic3r::ColorChangeCode); add_code(Slic3r::ColorChangeCode);
else else
{ {
wxMenu menu; wxMenu menu;
if (m_mode == mmMultiAsSingle) if (m_mode == t_mode::MultiAsSingle)
append_change_extruder_menu_item(&menu); append_change_extruder_menu_item(&menu);
else else
append_add_color_change_menu_item(&menu); append_add_color_change_menu_item(&menu);
@ -3335,7 +3344,7 @@ void DoubleSlider::action_tick(const TicksAction action)
return; return;
m_ticks.erase(TICK_CODE{tick}); m_ticks.erase(TICK_CODE{tick});
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event(it->gcode);
Refresh(); Refresh();
Update(); Update();
return; return;
@ -3350,7 +3359,7 @@ void DoubleSlider::action_tick(const TicksAction action)
if (m_suppress_add_code) if (m_suppress_add_code)
return; return;
m_suppress_add_code = true; m_suppress_add_code = true;
if (m_mode == mmSingleExtruder) // if (m_mode != mmMultiExtruder) if (m_mode == t_mode::SingleExtruder) // if (m_mode != t_mode::MultiExtruder)
add_code(Slic3r::ColorChangeCode); add_code(Slic3r::ColorChangeCode);
m_suppress_add_code = false; m_suppress_add_code = false;
return; return;
@ -3444,7 +3453,7 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
m_show_context_menu = true; m_show_context_menu = true;
return; return;
} }
if (it->gcode != Slic3r::ExtruderChangeCode) if (it->gcode != Slic3r::ToolChangeCode)
{ {
// show "Edit" and "Delete" menu on OnRightUp() // show "Edit" and "Delete" menu on OnRightUp()
m_show_edit_menu = true; m_show_edit_menu = true;
@ -3471,14 +3480,14 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
int DoubleSlider::get_extruder_for_tick(int tick) int DoubleSlider::get_extruder_for_tick(int tick)
{ {
int default_initial_extruder = m_mode == mmMultiAsSingle ? m_only_extruder : 0; int default_initial_extruder = m_mode == t_mode::MultiAsSingle ? m_only_extruder : 0;
if (m_ticks.empty()) if (m_ticks.empty())
return default_initial_extruder; return default_initial_extruder;
auto it = m_ticks.lower_bound(TICK_CODE{tick}); auto it = m_ticks.lower_bound(TICK_CODE{tick});
while (it != m_ticks.begin()) { while (it != m_ticks.begin()) {
--it; --it;
if(it->gcode == Slic3r::ExtruderChangeCode) if(it->gcode == Slic3r::ToolChangeCode)
return it->extruder; return it->extruder;
} }
@ -3487,7 +3496,7 @@ int DoubleSlider::get_extruder_for_tick(int tick)
std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick) std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick)
{ {
if (m_mode == mmMultiExtruder) if (m_mode == t_mode::MultiExtruder)
{ {
// #ys_FIXME: get tool ordering from _correct_ place // #ys_FIXME: get tool ordering from _correct_ place
const Slic3r::ToolOrdering& tool_ordering = Slic3r::GUI::wxGetApp().plater()->fff_print().get_tool_ordering(); const Slic3r::ToolOrdering& tool_ordering = Slic3r::GUI::wxGetApp().plater()->fff_print().get_tool_ordering();
@ -3508,7 +3517,7 @@ std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick)
return used_extruders; return used_extruders;
} }
const int default_initial_extruder = m_mode == mmMultiAsSingle ? std::max(m_only_extruder, 1) : 1; const int default_initial_extruder = m_mode == t_mode::MultiAsSingle ? std::max(m_only_extruder, 1) : 1;
if (m_ticks.empty()) if (m_ticks.empty())
return {default_initial_extruder}; return {default_initial_extruder};
@ -3516,7 +3525,7 @@ std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick)
auto it_start = m_ticks.lower_bound(TICK_CODE{tick}); auto it_start = m_ticks.lower_bound(TICK_CODE{tick});
auto it = it_start; auto it = it_start;
if (it == m_ticks.begin() && it->gcode == Slic3r::ExtruderChangeCode) { if (it == m_ticks.begin() && it->gcode == Slic3r::ToolChangeCode) {
used_extruders.emplace(it->extruder); used_extruders.emplace(it->extruder);
if (tick < it->tick) if (tick < it->tick)
used_extruders.emplace(default_initial_extruder); used_extruders.emplace(default_initial_extruder);
@ -3524,7 +3533,7 @@ std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick)
while (it != m_ticks.begin()) { while (it != m_ticks.begin()) {
--it; --it;
if(it->gcode == Slic3r::ExtruderChangeCode) if(it->gcode == Slic3r::ToolChangeCode)
{ {
used_extruders.emplace(it->extruder); used_extruders.emplace(it->extruder);
break; break;
@ -3536,7 +3545,7 @@ std::set<int> DoubleSlider::get_used_extruders_for_tick(int tick)
it = it_start; it = it_start;
while (it != m_ticks.end()) { while (it != m_ticks.end()) {
if(it->gcode == Slic3r::ExtruderChangeCode) if(it->gcode == Slic3r::ToolChangeCode)
used_extruders.emplace(it->extruder); used_extruders.emplace(it->extruder);
++it; ++it;
} }
@ -3554,7 +3563,7 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
if (m_show_context_menu) { if (m_show_context_menu) {
wxMenu menu; wxMenu menu;
if (m_mode == mmSingleExtruder) 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(Slic3r::ColorChangeCode); }, "colorchange_add_m", &menu, [this](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode); }, "colorchange_add_m", &menu,
[](){return true;}, this); [](){return true;}, this);
@ -3703,7 +3712,7 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
m_ticks.emplace(TICK_CODE{tick, code, extruder, color}); m_ticks.emplace(TICK_CODE{tick, code, extruder, color});
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event(code);
Refresh(); Refresh();
Update(); Update();
} }
@ -3741,7 +3750,7 @@ void DoubleSlider::edit_tick()
m_ticks.erase(it); m_ticks.erase(it);
m_ticks.emplace(changed_tick); m_ticks.emplace(changed_tick);
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event(changed_tick.gcode);
} }
} }
@ -3754,9 +3763,9 @@ void DoubleSlider::change_extruder(int extruder)
// if on this Y doesn't exist tick // if on this Y doesn't exist tick
if (m_ticks.find(TICK_CODE{tick}) == m_ticks.end()) if (m_ticks.find(TICK_CODE{tick}) == m_ticks.end())
{ {
m_ticks.emplace(TICK_CODE{tick, Slic3r::ExtruderChangeCode, extruder, extruder == 0 ? "" : colors[extruder-1]}); m_ticks.emplace(TICK_CODE{tick, Slic3r::ToolChangeCode, extruder, extruder == 0 ? "" : colors[extruder-1]});
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); post_ticks_changed_event(Slic3r::ToolChangeCode);
Refresh(); Refresh();
Update(); Update();
} }
@ -3776,7 +3785,7 @@ void DoubleSlider::edit_extruder_sequence()
auto it = m_ticks.begin(); auto it = m_ticks.begin();
while (it != m_ticks.end()) { while (it != m_ticks.end()) {
if (it->gcode == Slic3r::ExtruderChangeCode) if (it->gcode == Slic3r::ToolChangeCode)
it = m_ticks.erase(it); it = m_ticks.erase(it);
else else
++it; ++it;
@ -3792,7 +3801,7 @@ void DoubleSlider::edit_extruder_sequence()
while (tick <= m_max_value) while (tick <= m_max_value)
{ {
int cur_extruder = m_extruders_sequence.extruders[extruder]; int cur_extruder = m_extruders_sequence.extruders[extruder];
m_ticks.emplace(TICK_CODE{tick, Slic3r::ExtruderChangeCode, cur_extruder + 1, colors[cur_extruder]}); m_ticks.emplace(TICK_CODE{tick, Slic3r::ToolChangeCode, cur_extruder + 1, colors[cur_extruder]});
extruder++; extruder++;
if (extruder == extr_cnt) if (extruder == extr_cnt)
@ -3811,6 +3820,42 @@ void DoubleSlider::edit_extruder_sequence()
tick += m_extruders_sequence.interval_by_layers; tick += m_extruders_sequence.interval_by_layers;
} }
post_ticks_changed_event(Slic3r::ToolChangeCode);
}
void DoubleSlider::post_ticks_changed_event(const std::string& gcode /*= ""*/)
{
if ( m_ticks_mode == m_mode ||
(gcode != Slic3r::ColorChangeCode && gcode != Slic3r::ToolChangeCode) )
{
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
return;
}
if (m_ticks_mode == t_mode::SingleExtruder && m_mode == t_mode::MultiAsSingle)
{
}
if (m_ticks_mode == t_mode::SingleExtruder && m_mode == t_mode::MultiExtruder)
{
}
if (m_ticks_mode == t_mode::MultiAsSingle && m_mode == t_mode::SingleExtruder)
{
}
if (m_ticks_mode == t_mode::MultiAsSingle && m_mode == t_mode::MultiExtruder)
{
}
if (m_ticks_mode == t_mode::MultiExtruder && m_mode == t_mode::SingleExtruder)
{
}
if (m_ticks_mode == t_mode::MultiExtruder && m_mode == t_mode::MultiAsSingle)
{
}
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
} }

View file

@ -782,6 +782,8 @@ public:
const wxString& name = wxEmptyString); const wxString& name = wxEmptyString);
~DoubleSlider() {} ~DoubleSlider() {}
using t_mode = Slic3r::Model::CustomGCodeInfo::MODE;
/* For exporting GCode in GCodeWriter is used XYZF_NUM(val) = PRECISION(val, 3) for XYZ values. /* For exporting GCode in GCodeWriter is used XYZF_NUM(val) = PRECISION(val, 3) for XYZ values.
* So, let use same value as a permissible error for layer height. * So, let use same value as a permissible error for layer height.
*/ */
@ -805,37 +807,22 @@ public:
// Set low and high slider position. If the span is non-empty, disable the "one layer" mode. // Set low and high slider position. If the span is non-empty, disable the "one layer" mode.
void SetSelectionSpan(const int lower_val, const int higher_val); void SetSelectionSpan(const int lower_val, const int higher_val);
void SetMaxValue(const int max_value); void SetMaxValue(const int max_value);
void SetKoefForLabels(const double koef) { void SetKoefForLabels(const double koef) { m_label_koef = koef; }
m_label_koef = koef; void SetSliderValues(const std::vector<double>& values) { m_values = values; }
}
void SetSliderValues(const std::vector<double>& values) {
m_values = values;
}
void ChangeOneLayerLock(); void ChangeOneLayerLock();
std::vector<Slic3r::Model::CustomGCode> GetTicksValues() const; Slic3r::Model::CustomGCodeInfo GetTicksValues() const;
void SetTicksValues(const std::vector<Slic3r::Model::CustomGCode> &heights); void SetTicksValues(const Slic3r::Model::CustomGCodeInfo &custom_gcode_per_print_z);
void EnableTickManipulation(bool enable = true) { void EnableTickManipulation(bool enable = true) { m_is_enabled_tick_manipulation = enable; }
m_is_enabled_tick_manipulation = enable; void DisableTickManipulation() { EnableTickManipulation(false); }
}
void DisableTickManipulation() {
EnableTickManipulation(false);
}
enum ManipulationMode { void SetManipulationMode(t_mode mode) { m_mode = mode; }
mmSingleExtruder, // single extruder printer preset is selected t_mode GetManipulationMode() const { return m_mode; }
mmMultiAsSingle, // multiple extruder printer preset is selected, but
// this mode works just for Single extruder print
// (For all print from objects settings is used just one extruder)
mmMultiExtruder // multiple extruder printer preset is selected
};
void SetManipulationMode(ManipulationMode mode) { m_mode = mode; }
ManipulationMode GetManipulationMode() const { return m_mode; }
void SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder) void SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder)
{ {
m_mode = !is_one_extruder_printed_model ? mmMultiExtruder : m_mode = !is_one_extruder_printed_model ? t_mode::MultiExtruder :
only_extruder < 0 ? mmSingleExtruder : only_extruder < 0 ? t_mode::SingleExtruder :
mmMultiAsSingle; t_mode::MultiAsSingle;
m_only_extruder = only_extruder; m_only_extruder = only_extruder;
} }
@ -918,7 +905,7 @@ private:
int get_extruder_for_tick(int tick); int get_extruder_for_tick(int tick);
std::set<int> get_used_extruders_for_tick(int tick); std::set<int> get_used_extruders_for_tick(int tick);
void post_ticks_changed_event(const std::string& gcode = "");
void append_change_extruder_menu_item(wxMenu*); void append_change_extruder_menu_item(wxMenu*);
void append_add_color_change_menu_item(wxMenu*); void append_add_color_change_menu_item(wxMenu*);
@ -952,7 +939,7 @@ private:
bool m_show_edit_menu = false; bool m_show_edit_menu = false;
bool m_edit_extruder_sequence = false; bool m_edit_extruder_sequence = false;
bool m_suppress_add_code = false; bool m_suppress_add_code = false;
ManipulationMode m_mode = mmSingleExtruder; t_mode m_mode = t_mode::SingleExtruder;
std::string m_custom_gcode = ""; std::string m_custom_gcode = "";
std::string m_pause_print_msg; std::string m_pause_print_msg;
int m_only_extruder = -1; int m_only_extruder = -1;
@ -986,6 +973,7 @@ private:
std::vector<wxPen*> m_segm_pens; std::vector<wxPen*> m_segm_pens;
std::vector<double> m_values; std::vector<double> m_values;
std::set<TICK_CODE> m_ticks; std::set<TICK_CODE> m_ticks;
t_mode m_ticks_mode;
public: public:
struct ExtrudersSequence struct ExtrudersSequence